Skip to content

Commit 15f62c8

Browse files
committed
feat: add arbitrary sizing
BREAKING CHANGE: arbitraries are completely reworked, changes might break
1 parent 544e152 commit 15f62c8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+4471
-4108
lines changed

package-lock.json

+1,849-2,815
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@
4040
"tslib": "^2.6.2"
4141
},
4242
"devDependencies": {
43-
"@skyleague/node-standards": "^5.1.1",
44-
"date-fns": "^3.3.1",
45-
"esbuild": "^0.20.0",
46-
"typescript": "5.3.3"
43+
"@skyleague/node-standards": "^5.1.9",
44+
"date-fns": "^3.6.0",
45+
"esbuild": "^0.20.2",
46+
"typescript": "5.4.2"
4747
},
4848
"engines": {
4949
"node": ">=20"
@@ -62,4 +62,4 @@
6262
"workspaces": [
6363
"docs"
6464
]
65-
}
65+
}

src/array/zip/zip.ts

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ export function* zip<T extends readonly [...Traversable<unknown>[]]>(...xs: [...
2020
return
2121
}
2222

23+
/**
24+
* @deprecated
25+
*/
2326
export function* zipWith<T extends readonly [...unknown[]], R>(f: (...args: [...T]) => R, ...xs: Unzip<[...T]>) {
2427
if (xs.length === 0) {
2528
return

src/async/parallel-limit/parallel-limit.ts

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export function parallelLimit(concurrency: number) {
4646
try {
4747
resolve(await task())
4848
} catch (err) {
49+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
4950
reject(err)
5051
} finally {
5152
next()

src/guard/has-properties-defined/has-properties-defined.spec.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { hasPropertiesDefined } from './has-properties-defined.js'
22

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

56
import { expect, it } from 'vitest'
67

78
it('defined properties are defined', () => {
8-
forAll(tuple(dict(unknown()), float({ min: 0, max: 1 })), ([xs, r]) => {
9+
forAll(tuple(record(unknown()), float({ min: 0, max: 1 })), ([xs, r]) => {
910
const keys = keysOf(xs)
1011
const selectedKeys = collect(take(shuffle(keys), r * keys.length))
1112
return hasPropertiesDefined(selectedKeys)(xs) === all(selectedKeys, (k) => xs[k] !== undefined)

src/iterator/at/at.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('at', () => {
3333

3434
it('ith index on array - index in bounds', () => {
3535
forAll(
36-
integer({ min: 1, max: 50 }).chain((n) => tuple(array(unknown(), { minLength: n }), integer({ min: 0, max: n }))),
36+
integer({ min: 1, max: 50 }).chain((n) => tuple(array(unknown(), { minLength: n }), integer({ min: 0, max: n - 1 }))),
3737
([xs, i]) => {
3838
return at(xs, i) === xs[i]
3939
}

src/iterator/at/at.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export function at<Xs extends any[], N extends number>(
3434
export function at<T, N extends number = number>(xs: Traversable<T>, n: N): Maybe<T>
3535
export function at<T, N extends number = number>(xs: Traversable<T>, n: N): Maybe<T> {
3636
if (isArray<T>(xs)) {
37-
return n >= xs.length ? Nothing : xs[n]!
37+
return (n >= xs.length ? Nothing : xs[n]) as Maybe<T>
3838
}
3939
// slow iterator compatible version
4040
return head(drop(xs, n))

src/object/ensure-values/ensure-values.spec.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { ensureValues } from './ensure-values.js'
22

3-
import { constant, dict, forAll, oneOf, unknown } from '../../random/index.js'
3+
import { constant, forAll, oneOf, unknown } from '../../random/index.js'
4+
import { record } from '../../random/types/record/record.js'
45

56
import { it } from 'vitest'
67

78
it('ensure-values', () => {
8-
forAll(dict(oneOf(constant(undefined), unknown({ undefined: false }))), (x) => {
9+
forAll(record(oneOf(constant(undefined), unknown({ undefined: false }))), (x) => {
910
const config = ensureValues(x)
1011
for (const k of [...Object.keys(x), ...Object.getOwnPropertySymbols(x)] as (keyof typeof x)[]) {
1112
if (x[k] === undefined) {

src/object/entries-of/entries-of.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { entriesOf } from './index.js'
22

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

55
import { expect, it } from 'vitest'
66

77
it('entriesOf === Object.entries', () => {
8-
forAll(dict(unknown()), (o) => {
8+
forAll(record(unknown()), (o) => {
99
expect(entriesOf(o)).toStrictEqual(Object.entries(o))
1010
})
1111
})
@@ -36,7 +36,7 @@ it('entriesOf [1, 2, 3]', () => {
3636
})
3737

3838
it('entriesOf union object and array', () => {
39-
forAll(oneOf(array(string()), dict([integer(), integer()])), (o) => {
39+
forAll(oneOf(array(string()), record([integer(), integer()])), (o) => {
4040
expect(entriesOf(o)).toStrictEqual(Object.entries(o))
4141
})
4242
const _foo: [string, number][] = entriesOf([1, 2, 3])

src/object/from-entries/from-entries.spec.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { fromEntries } from './from-entries.js'
22

33
import { equal } from '../../iterator/index.js'
4-
import { dict, forAll, unknown } from '../../random/index.js'
4+
import { forAll, unknown } from '../../random/index.js'
5+
import { record } from '../../random/types/record/record.js'
56
import { entriesOf } from '../entries-of/index.js'
67

78
import { expect, it } from 'vitest'
89

910
it('fromEntries o entriesOf === identity', () => {
10-
forAll(dict(unknown()), (x) => equal(fromEntries(entriesOf(x)), x))
11+
forAll(record(unknown()), (x) => equal(fromEntries(entriesOf(x)), x))
1112
})
1213

1314
it('infers correct type', () => {

src/object/get-prop/get-prop.spec.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { getProp } from './get-prop.js'
22

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

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

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

3435
it('returns the correct value for existing properties', () => {
35-
forAll(tuple(dict(unknown()), string(), unknown()), ([obj, path, value]) => {
36+
forAll(tuple(record(unknown()), string(), unknown()), ([obj, path, value]) => {
3637
const pathArr = path.split('.')
3738
let current = obj as any
3839
for (const [i, key] of enumerate(pathArr)) {

src/object/has/has.spec.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ import { has } from './index.js'
22

33
import { all } from '../../iterator/index.js'
44
import { keysOf } from '../../object/index.js'
5-
import { forAll, dict, unknown } from '../../random/index.js'
5+
import { forAll, unknown } from '../../random/index.js'
6+
import { record } from '../../random/types/record/record.js'
67

78
import { expect, it } from 'vitest'
89

910
it('all has keysOf o', () => {
10-
forAll(dict(unknown()), (o) => all(keysOf(o), (k) => has(o, k)))
11+
forAll(record(unknown()), (o) => all(keysOf(o), (k) => has(o, k)))
1112
})
1213

1314
it('typing', () => {

src/object/keys-of/keys-of.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { keysOf } from './index.js'
22

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

55
import { expect, it } from 'vitest'
66

77
it('keysOf === Object.keys', () => {
8-
forAll(dict(unknown()), (o) => {
8+
forAll(record(unknown()), (o) => {
99
expect(keysOf(o)).toStrictEqual(Object.keys(o))
1010
})
1111
})
@@ -27,7 +27,7 @@ it('keysOf [1, 2, 3]', () => {
2727
})
2828

2929
it('keysOf union object and array', () => {
30-
forAll(oneOf(array(string()), dict([integer(), integer()])), (o) => {
30+
forAll(oneOf(array(string()), record([integer(), integer()])), (o) => {
3131
expect(keysOf(o)).toStrictEqual(Object.keys(o))
3232
})
3333
const _foo: string[] = keysOf([1, 2, 3])

src/object/merge-deep/merge-deep.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,15 @@ export function mergeDeep<T, U>(source: U, target: T): T | U {
2323
const output: Record<string, unknown> = Object.assign({}, target)
2424
if (isObject(target) && isObject(source)) {
2525
for (const key of Object.keys(source)) {
26-
const obj = source[key]
26+
const obj: any = source[key]
2727
if (isObject(obj)) {
2828
if (!(key in target)) {
2929
Object.assign(output, { [key]: obj })
3030
} else {
3131
output[key] = mergeDeep(obj, target[key])
3232
}
3333
} else {
34+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
3435
Object.assign(output, { [key]: obj })
3536
}
3637
}

src/object/omit/omit.spec.ts

+15-15
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@ import { omitUndefined, omit, omitBy } from './index.js'
33
import type { OmitUndefined } from './omit.js'
44

55
import { all, equal } from '../../iterator/index.js'
6-
import { forAll, dict, unknown, deterministicBoolean } from '../../random/index.js'
6+
import { forAll, record, unknown, deterministicBoolean } from '../../random/index.js'
77
import { keysOf, pickBy } from '../index.js'
88

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

1111
describe('omitUndefined', () => {
1212
it('omitUndefined x === identity, if all values defined', () => {
13-
forAll(dict(unknown({ undefined: false })), (x) => equal(omitUndefined(x), x))
13+
forAll(record(unknown({ undefined: false })), (x) => equal(omitUndefined(x), x))
1414
})
1515

1616
it('key filtered in both filtered and original', () => {
17-
forAll(dict(unknown()), (x) => {
17+
forAll(record(unknown()), (x) => {
1818
const filtered = omitUndefined(x)
1919
return all(keysOf(filtered), (k) => k in x && k in filtered)
2020
})
2121
})
2222

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

4242
describe('omitBy', () => {
4343
it('omitBy false x === identity', () => {
44-
forAll(dict(unknown()), (x) =>
44+
forAll(record(unknown()), (x) =>
4545
equal(
4646
omitBy(x, () => false),
4747
x
@@ -50,11 +50,11 @@ describe('omitBy', () => {
5050
})
5151

5252
it('omitBy false x !== [ref] x', () => {
53-
forAll(dict(unknown()), (x) => omitBy(x, () => false) !== x)
53+
forAll(record(unknown()), (x) => omitBy(x, () => false) !== x)
5454
})
5555

5656
it('omitBy true x == {}', () => {
57-
forAll(dict(unknown()), (x) =>
57+
forAll(record(unknown()), (x) =>
5858
equal(
5959
omitBy(x, () => true),
6060
{}
@@ -63,21 +63,21 @@ describe('omitBy', () => {
6363
})
6464

6565
it('key filtered in both filtered and original', () => {
66-
forAll(dict(unknown()), (x) => {
66+
forAll(record(unknown()), (x) => {
6767
const filtered = omitBy(x, (key) => deterministicBoolean(key))
6868
return all(keysOf(filtered), (k) => k in x && k in filtered)
6969
})
7070
})
7171

7272
it('key filtered if not picked', () => {
73-
forAll(dict(unknown()), (x) => {
73+
forAll(record(unknown()), (x) => {
7474
const filtered = omitBy(x, ([k]) => deterministicBoolean(k))
7575
return all(keysOf(x), (k) => !(deterministicBoolean(k) ? k in filtered : !(k in filtered) && k in x))
7676
})
7777
})
7878

7979
it('omitBy ~ pickBy', () => {
80-
forAll(dict(unknown()), (x) => {
80+
forAll(record(unknown()), (x) => {
8181
const omitted = omitBy(x, ([k]) => deterministicBoolean(k))
8282
const picked = pickBy(x, ([k]) => !deterministicBoolean(k))
8383
return equal(omitted, picked)
@@ -95,26 +95,26 @@ describe('omit', () => {
9595
})
9696

9797
it('omit [] x === identity', () => {
98-
forAll(dict(unknown()), (x) => equal(omit(x, []), x))
98+
forAll(record(unknown()), (x) => equal(omit(x, []), x))
9999
})
100100

101101
it('omit [] x !== [ref] x', () => {
102-
forAll(dict(unknown()), (x) => omit(x, []) !== x)
102+
forAll(record(unknown()), (x) => omit(x, []) !== x)
103103
})
104104

105105
it('omit keysOf x x == {}', () => {
106-
forAll(dict(unknown()), (x) => equal(omit(x, keysOf(x)), {}))
106+
forAll(record(unknown()), (x) => equal(omit(x, keysOf(x)), {}))
107107
})
108108

109109
it('key filtered in both filtered and original', () => {
110-
forAll(dict(unknown()), (x) => {
110+
forAll(record(unknown()), (x) => {
111111
const filtered = omit(x, keysOf(x).filter(deterministicBoolean))
112112
return all(keysOf(filtered), (k) => k in x && k in filtered)
113113
})
114114
})
115115

116116
it('key filtered if not omited', () => {
117-
forAll(dict(unknown()), (x) => {
117+
forAll(record(unknown()), (x) => {
118118
const filtered = omit(x, keysOf(x).filter(deterministicBoolean))
119119
return all(keysOf(x), (k) => (!deterministicBoolean(k) ? k in filtered : !(k in filtered) && k in x))
120120
})

src/object/pick/pick.spec.ts

+11-11
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { pick, pickBy } from './index.js'
22

33
import { isNumber } from '../../guard/index.js'
44
import { all, equal } from '../../iterator/index.js'
5-
import { forAll, dict, unknown, deterministicBoolean } from '../../random/index.js'
5+
import { forAll, record, unknown, deterministicBoolean } from '../../random/index.js'
66
import { keysOf } from '../index.js'
77

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

1919
it('pickBy true x === identity', () => {
20-
forAll(dict(unknown()), (x) =>
20+
forAll(record(unknown()), (x) =>
2121
equal(
2222
pickBy(x, () => true),
2323
x
@@ -26,11 +26,11 @@ describe('pickBy', () => {
2626
})
2727

2828
it('pickBy true x !== [ref] x', () => {
29-
forAll(dict(unknown()), (x) => pickBy(x, () => true) !== x)
29+
forAll(record(unknown()), (x) => pickBy(x, () => true) !== x)
3030
})
3131

3232
it('pickBy false x == {}', () => {
33-
forAll(dict(unknown()), (x) =>
33+
forAll(record(unknown()), (x) =>
3434
equal(
3535
pickBy(x, () => false),
3636
{}
@@ -39,14 +39,14 @@ describe('pickBy', () => {
3939
})
4040

4141
it('key filtered in both filtered and original', () => {
42-
forAll(dict(unknown()), (x) => {
42+
forAll(record(unknown()), (x) => {
4343
const filtered = pickBy(x, (key) => deterministicBoolean(key))
4444
return all(keysOf(filtered), (k) => k in x && k in filtered)
4545
})
4646
})
4747

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

6666
it('pick keysOf x x === identity', () => {
67-
forAll(dict(unknown()), (x) => equal(pick(x, keysOf(x)), x))
67+
forAll(record(unknown()), (x) => equal(pick(x, keysOf(x)), x))
6868
})
6969

7070
it('pick keysOf x x !== [ref] x', () => {
71-
forAll(dict(unknown()), (x) => pick(x, keysOf(x)) !== x)
71+
forAll(record(unknown()), (x) => pick(x, keysOf(x)) !== x)
7272
})
7373

7474
it('pick [] x == {}', () => {
75-
forAll(dict(unknown()), (x) => equal(pick(x, []), {}))
75+
forAll(record(unknown()), (x) => equal(pick(x, []), {}))
7676
})
7777

7878
it('key filtered in both filtered and original', () => {
79-
forAll(dict(unknown()), (x) => {
79+
forAll(record(unknown()), (x) => {
8080
const filtered = pick(x, keysOf(x).filter(deterministicBoolean))
8181
return all(keysOf(filtered), (k) => k in x && k in filtered)
8282
})
8383
})
8484

8585
it('key filtered if not picked', () => {
86-
forAll(dict(unknown()), (x) => {
86+
forAll(record(unknown()), (x) => {
8787
const filtered = pick(x, keysOf(x).filter(deterministicBoolean))
8888
return all(keysOf(x), (k) => (deterministicBoolean(k) ? k in filtered : !(k in filtered) && k in x))
8989
})

0 commit comments

Comments
 (0)