Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add arbitrary sizing #122

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4,664 changes: 1,849 additions & 2,815 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
"tslib": "^2.6.2"
},
"devDependencies": {
"@skyleague/node-standards": "^5.1.1",
"date-fns": "^3.3.1",
"esbuild": "^0.20.0",
"typescript": "5.3.3"
"@skyleague/node-standards": "^5.1.9",
"date-fns": "^3.6.0",
"esbuild": "^0.20.2",
"typescript": "5.4.2"
},
"engines": {
"node": ">=20"
Expand All @@ -62,4 +62,4 @@
"workspaces": [
"docs"
]
}
}
3 changes: 3 additions & 0 deletions src/array/zip/zip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export function* zip<T extends readonly [...Traversable<unknown>[]]>(...xs: [...
return
}

/**
* @deprecated
*/
export function* zipWith<T extends readonly [...unknown[]], R>(f: (...args: [...T]) => R, ...xs: Unzip<[...T]>) {
if (xs.length === 0) {
return
Expand Down
1 change: 1 addition & 0 deletions src/async/parallel-limit/parallel-limit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export function parallelLimit(concurrency: number) {
try {
resolve(await task())
} catch (err) {
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
reject(err)
} finally {
next()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { hasPropertiesDefined } from './has-properties-defined.js'

import { all, collect, dict, float, forAll, keysOf, shuffle, take, tuple, unknown } from '../../index.js'
import { all, collect, float, forAll, keysOf, shuffle, take, tuple, unknown } from '../../index.js'
import { record } from '../../random/types/record/record.js'

import { expect, it } from 'vitest'

it('defined properties are defined', () => {
forAll(tuple(dict(unknown()), float({ min: 0, max: 1 })), ([xs, r]) => {
forAll(tuple(record(unknown()), float({ min: 0, max: 1 })), ([xs, r]) => {
const keys = keysOf(xs)
const selectedKeys = collect(take(shuffle(keys), r * keys.length))
return hasPropertiesDefined(selectedKeys)(xs) === all(selectedKeys, (k) => xs[k] !== undefined)
Expand Down
2 changes: 1 addition & 1 deletion src/iterator/at/at.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('at', () => {

it('ith index on array - index in bounds', () => {
forAll(
integer({ min: 1, max: 50 }).chain((n) => tuple(array(unknown(), { minLength: n }), integer({ min: 0, max: n }))),
integer({ min: 1, max: 50 }).chain((n) => tuple(array(unknown(), { minLength: n }), integer({ min: 0, max: n - 1 }))),
([xs, i]) => {
return at(xs, i) === xs[i]
}
Expand Down
2 changes: 1 addition & 1 deletion src/iterator/at/at.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function at<Xs extends any[], N extends number>(
export function at<T, N extends number = number>(xs: Traversable<T>, n: N): Maybe<T>
export function at<T, N extends number = number>(xs: Traversable<T>, n: N): Maybe<T> {
if (isArray<T>(xs)) {
return n >= xs.length ? Nothing : xs[n]!
return (n >= xs.length ? Nothing : xs[n]) as Maybe<T>
}
// slow iterator compatible version
return head(drop(xs, n))
Expand Down
5 changes: 3 additions & 2 deletions src/object/ensure-values/ensure-values.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { ensureValues } from './ensure-values.js'

import { constant, dict, forAll, oneOf, unknown } from '../../random/index.js'
import { constant, forAll, oneOf, unknown } from '../../random/index.js'
import { record } from '../../random/types/record/record.js'

import { it } from 'vitest'

it('ensure-values', () => {
forAll(dict(oneOf(constant(undefined), unknown({ undefined: false }))), (x) => {
forAll(record(oneOf(constant(undefined), unknown({ undefined: false }))), (x) => {
const config = ensureValues(x)
for (const k of [...Object.keys(x), ...Object.getOwnPropertySymbols(x)] as (keyof typeof x)[]) {
if (x[k] === undefined) {
Expand Down
6 changes: 3 additions & 3 deletions src/object/entries-of/entries-of.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { entriesOf } from './index.js'

import { forAll, dict, unknown, string, array, oneOf, integer } from '../../random/index.js'
import { forAll, record, unknown, string, array, oneOf, integer } from '../../random/index.js'

import { expect, it } from 'vitest'

it('entriesOf === Object.entries', () => {
forAll(dict(unknown()), (o) => {
forAll(record(unknown()), (o) => {
expect(entriesOf(o)).toStrictEqual(Object.entries(o))
})
})
Expand Down Expand Up @@ -36,7 +36,7 @@ it('entriesOf [1, 2, 3]', () => {
})

it('entriesOf union object and array', () => {
forAll(oneOf(array(string()), dict([integer(), integer()])), (o) => {
forAll(oneOf(array(string()), record([integer(), integer()])), (o) => {
expect(entriesOf(o)).toStrictEqual(Object.entries(o))
})
const _foo: [string, number][] = entriesOf([1, 2, 3])
Expand Down
5 changes: 3 additions & 2 deletions src/object/from-entries/from-entries.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { fromEntries } from './from-entries.js'

import { equal } from '../../iterator/index.js'
import { dict, forAll, unknown } from '../../random/index.js'
import { forAll, unknown } from '../../random/index.js'
import { record } from '../../random/types/record/record.js'
import { entriesOf } from '../entries-of/index.js'

import { expect, it } from 'vitest'

it('fromEntries o entriesOf === identity', () => {
forAll(dict(unknown()), (x) => equal(fromEntries(entriesOf(x)), x))
forAll(record(unknown()), (x) => equal(fromEntries(entriesOf(x)), x))
})

it('infers correct type', () => {
Expand Down
5 changes: 3 additions & 2 deletions src/object/get-prop/get-prop.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { getProp } from './get-prop.js'

import { Nothing, dict, enumerate, forAll, isObject, string, tuple, unknown } from '../../index.js'
import { Nothing, enumerate, forAll, isObject, string, tuple, unknown } from '../../index.js'
import { record } from '../../random/types/record/record.js'

import { it, expect, assertType } from 'vitest'

Expand Down Expand Up @@ -32,7 +33,7 @@ it('returns undefined for non-existent properties', () => {
})

it('returns the correct value for existing properties', () => {
forAll(tuple(dict(unknown()), string(), unknown()), ([obj, path, value]) => {
forAll(tuple(record(unknown()), string(), unknown()), ([obj, path, value]) => {
const pathArr = path.split('.')
let current = obj as any
for (const [i, key] of enumerate(pathArr)) {
Expand Down
5 changes: 3 additions & 2 deletions src/object/has/has.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import { has } from './index.js'

import { all } from '../../iterator/index.js'
import { keysOf } from '../../object/index.js'
import { forAll, dict, unknown } from '../../random/index.js'
import { forAll, unknown } from '../../random/index.js'
import { record } from '../../random/types/record/record.js'

import { expect, it } from 'vitest'

it('all has keysOf o', () => {
forAll(dict(unknown()), (o) => all(keysOf(o), (k) => has(o, k)))
forAll(record(unknown()), (o) => all(keysOf(o), (k) => has(o, k)))
})

it('typing', () => {
Expand Down
6 changes: 3 additions & 3 deletions src/object/keys-of/keys-of.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { keysOf } from './index.js'

import { forAll, dict, unknown, string, array, oneOf, integer } from '../../random/index.js'
import { forAll, record, unknown, string, array, oneOf, integer } from '../../random/index.js'

import { expect, it } from 'vitest'

it('keysOf === Object.keys', () => {
forAll(dict(unknown()), (o) => {
forAll(record(unknown()), (o) => {
expect(keysOf(o)).toStrictEqual(Object.keys(o))
})
})
Expand All @@ -27,7 +27,7 @@ it('keysOf [1, 2, 3]', () => {
})

it('keysOf union object and array', () => {
forAll(oneOf(array(string()), dict([integer(), integer()])), (o) => {
forAll(oneOf(array(string()), record([integer(), integer()])), (o) => {
expect(keysOf(o)).toStrictEqual(Object.keys(o))
})
const _foo: string[] = keysOf([1, 2, 3])
Expand Down
3 changes: 2 additions & 1 deletion src/object/merge-deep/merge-deep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ export function mergeDeep<T, U>(source: U, target: T): T | U {
const output: Record<string, unknown> = Object.assign({}, target)
if (isObject(target) && isObject(source)) {
for (const key of Object.keys(source)) {
const obj = source[key]
const obj: any = source[key]
if (isObject(obj)) {
if (!(key in target)) {
Object.assign(output, { [key]: obj })
} else {
output[key] = mergeDeep(obj, target[key])
}
} else {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
Object.assign(output, { [key]: obj })
}
}
Expand Down
30 changes: 15 additions & 15 deletions src/object/omit/omit.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ import { omitUndefined, omit, omitBy } from './index.js'
import type { OmitUndefined } from './omit.js'

import { all, equal } from '../../iterator/index.js'
import { forAll, dict, unknown, deterministicBoolean } from '../../random/index.js'
import { forAll, record, unknown, deterministicBoolean } from '../../random/index.js'
import { keysOf, pickBy } from '../index.js'

import { expect, describe, it } from 'vitest'

describe('omitUndefined', () => {
it('omitUndefined x === identity, if all values defined', () => {
forAll(dict(unknown({ undefined: false })), (x) => equal(omitUndefined(x), x))
forAll(record(unknown({ undefined: false })), (x) => equal(omitUndefined(x), x))
})

it('key filtered in both filtered and original', () => {
forAll(dict(unknown()), (x) => {
forAll(record(unknown()), (x) => {
const filtered = omitUndefined(x)
return all(keysOf(filtered), (k) => k in x && k in filtered)
})
})

it('key in filtered if not omitted', () => {
forAll(dict(unknown()), (x) => {
forAll(record(unknown()), (x) => {
const filtered = omitUndefined(x)
return all(keysOf(x), (k) => (x[k] !== undefined ? k in filtered : !(k in filtered) && k in x))
})
Expand All @@ -41,7 +41,7 @@ describe('omitUndefined', () => {

describe('omitBy', () => {
it('omitBy false x === identity', () => {
forAll(dict(unknown()), (x) =>
forAll(record(unknown()), (x) =>
equal(
omitBy(x, () => false),
x
Expand All @@ -50,11 +50,11 @@ describe('omitBy', () => {
})

it('omitBy false x !== [ref] x', () => {
forAll(dict(unknown()), (x) => omitBy(x, () => false) !== x)
forAll(record(unknown()), (x) => omitBy(x, () => false) !== x)
})

it('omitBy true x == {}', () => {
forAll(dict(unknown()), (x) =>
forAll(record(unknown()), (x) =>
equal(
omitBy(x, () => true),
{}
Expand All @@ -63,21 +63,21 @@ describe('omitBy', () => {
})

it('key filtered in both filtered and original', () => {
forAll(dict(unknown()), (x) => {
forAll(record(unknown()), (x) => {
const filtered = omitBy(x, (key) => deterministicBoolean(key))
return all(keysOf(filtered), (k) => k in x && k in filtered)
})
})

it('key filtered if not picked', () => {
forAll(dict(unknown()), (x) => {
forAll(record(unknown()), (x) => {
const filtered = omitBy(x, ([k]) => deterministicBoolean(k))
return all(keysOf(x), (k) => !(deterministicBoolean(k) ? k in filtered : !(k in filtered) && k in x))
})
})

it('omitBy ~ pickBy', () => {
forAll(dict(unknown()), (x) => {
forAll(record(unknown()), (x) => {
const omitted = omitBy(x, ([k]) => deterministicBoolean(k))
const picked = pickBy(x, ([k]) => !deterministicBoolean(k))
return equal(omitted, picked)
Expand All @@ -95,26 +95,26 @@ describe('omit', () => {
})

it('omit [] x === identity', () => {
forAll(dict(unknown()), (x) => equal(omit(x, []), x))
forAll(record(unknown()), (x) => equal(omit(x, []), x))
})

it('omit [] x !== [ref] x', () => {
forAll(dict(unknown()), (x) => omit(x, []) !== x)
forAll(record(unknown()), (x) => omit(x, []) !== x)
})

it('omit keysOf x x == {}', () => {
forAll(dict(unknown()), (x) => equal(omit(x, keysOf(x)), {}))
forAll(record(unknown()), (x) => equal(omit(x, keysOf(x)), {}))
})

it('key filtered in both filtered and original', () => {
forAll(dict(unknown()), (x) => {
forAll(record(unknown()), (x) => {
const filtered = omit(x, keysOf(x).filter(deterministicBoolean))
return all(keysOf(filtered), (k) => k in x && k in filtered)
})
})

it('key filtered if not omited', () => {
forAll(dict(unknown()), (x) => {
forAll(record(unknown()), (x) => {
const filtered = omit(x, keysOf(x).filter(deterministicBoolean))
return all(keysOf(x), (k) => (!deterministicBoolean(k) ? k in filtered : !(k in filtered) && k in x))
})
Expand Down
22 changes: 11 additions & 11 deletions src/object/pick/pick.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { pick, pickBy } from './index.js'

import { isNumber } from '../../guard/index.js'
import { all, equal } from '../../iterator/index.js'
import { forAll, dict, unknown, deterministicBoolean } from '../../random/index.js'
import { forAll, record, unknown, deterministicBoolean } from '../../random/index.js'
import { keysOf } from '../index.js'

import { expect, describe, it } from 'vitest'
Expand All @@ -17,7 +17,7 @@ describe('pickBy', () => {
})

it('pickBy true x === identity', () => {
forAll(dict(unknown()), (x) =>
forAll(record(unknown()), (x) =>
equal(
pickBy(x, () => true),
x
Expand All @@ -26,11 +26,11 @@ describe('pickBy', () => {
})

it('pickBy true x !== [ref] x', () => {
forAll(dict(unknown()), (x) => pickBy(x, () => true) !== x)
forAll(record(unknown()), (x) => pickBy(x, () => true) !== x)
})

it('pickBy false x == {}', () => {
forAll(dict(unknown()), (x) =>
forAll(record(unknown()), (x) =>
equal(
pickBy(x, () => false),
{}
Expand All @@ -39,14 +39,14 @@ describe('pickBy', () => {
})

it('key filtered in both filtered and original', () => {
forAll(dict(unknown()), (x) => {
forAll(record(unknown()), (x) => {
const filtered = pickBy(x, (key) => deterministicBoolean(key))
return all(keysOf(filtered), (k) => k in x && k in filtered)
})
})

it('key filtered if not picked', () => {
forAll(dict(unknown()), (x) => {
forAll(record(unknown()), (x) => {
const filtered = pickBy(x, ([k]) => deterministicBoolean(k))
return all(keysOf(x), (k) => (deterministicBoolean(k) ? k in filtered : !(k in filtered) && k in x))
})
Expand All @@ -64,26 +64,26 @@ describe('pick', () => {
})

it('pick keysOf x x === identity', () => {
forAll(dict(unknown()), (x) => equal(pick(x, keysOf(x)), x))
forAll(record(unknown()), (x) => equal(pick(x, keysOf(x)), x))
})

it('pick keysOf x x !== [ref] x', () => {
forAll(dict(unknown()), (x) => pick(x, keysOf(x)) !== x)
forAll(record(unknown()), (x) => pick(x, keysOf(x)) !== x)
})

it('pick [] x == {}', () => {
forAll(dict(unknown()), (x) => equal(pick(x, []), {}))
forAll(record(unknown()), (x) => equal(pick(x, []), {}))
})

it('key filtered in both filtered and original', () => {
forAll(dict(unknown()), (x) => {
forAll(record(unknown()), (x) => {
const filtered = pick(x, keysOf(x).filter(deterministicBoolean))
return all(keysOf(filtered), (k) => k in x && k in filtered)
})
})

it('key filtered if not picked', () => {
forAll(dict(unknown()), (x) => {
forAll(record(unknown()), (x) => {
const filtered = pick(x, keysOf(x).filter(deterministicBoolean))
return all(keysOf(x), (k) => (deterministicBoolean(k) ? k in filtered : !(k in filtered) && k in x))
})
Expand Down
Loading
Loading