atomic-fns 0.2.2 → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -3
- package/package.json +6 -7
- package/src/collections/index.d.ts +658 -0
- package/src/collections/index.js +1068 -0
- package/src/collections/index.ts +1162 -0
- package/src/datetime/index.d.ts +6 -0
- package/src/datetime/index.js +6 -0
- package/src/datetime/index.ts +7 -0
- package/src/{functools.d.ts → functools/index.d.ts} +8 -7
- package/src/functools/index.js +84 -0
- package/src/{functools.ts → functools/index.ts} +9 -7
- package/src/globals/index.d.ts +291 -0
- package/src/globals/index.js +391 -0
- package/src/globals/index.ts +456 -0
- package/src/index.d.ts +8 -7
- package/src/index.js +8 -7
- package/src/index.ts +8 -7
- package/src/itertools/index.d.ts +254 -0
- package/src/itertools/index.js +485 -0
- package/src/itertools/index.ts +511 -0
- package/src/math/index.d.ts +21 -0
- package/src/math/index.js +39 -0
- package/src/math/index.ts +44 -0
- package/src/{operators.d.ts → operators/index.d.ts} +8 -6
- package/src/operators/index.js +171 -0
- package/src/{operators.ts → operators/index.ts} +75 -30
- package/src/random/index.d.ts +42 -0
- package/src/random/index.js +65 -0
- package/src/random/index.ts +66 -0
- package/tests/collections.spec.ts +42 -25
- package/tests/globals.spec.ts +51 -47
- package/tests/itertools.spec.ts +190 -4
- package/tests/operators.spec.ts +1 -26
- package/tests/random.spec.ts +46 -0
- package/tsconfig.json +12 -4
- package/src/collections.d.ts +0 -228
- package/src/collections.js +0 -553
- package/src/collections.ts +0 -641
- package/src/datetime.d.ts +0 -5
- package/src/datetime.js +0 -5
- package/src/datetime.ts +0 -6
- package/src/functools.js +0 -78
- package/src/globals.d.ts +0 -179
- package/src/globals.js +0 -309
- package/src/globals.ts +0 -377
- package/src/itertools.d.ts +0 -20
- package/src/itertools.js +0 -98
- package/src/itertools.ts +0 -116
- package/src/math.d.ts +0 -16
- package/src/math.js +0 -70
- package/src/math.ts +0 -77
- package/src/objects.d.ts +0 -0
- package/src/objects.js +0 -1
- package/src/objects.ts +0 -0
- package/src/operators.js +0 -109
- package/src/random.d.ts +0 -22
- package/src/random.js +0 -48
- package/src/random.ts +0 -53
- package/src/strings.d.ts +0 -0
- package/src/strings.js +0 -1
- package/src/strings.ts +0 -0
- package/src/util.d.ts +0 -0
- package/src/util.js +0 -1
- package/src/util.ts +0 -0
package/tests/globals.spec.ts
CHANGED
|
@@ -1,43 +1,42 @@
|
|
|
1
1
|
import assert from 'assert'
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
bin,
|
|
4
|
+
call,
|
|
5
|
+
chr,
|
|
5
6
|
CustomError,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
False,
|
|
8
|
+
get,
|
|
9
|
+
hash,
|
|
10
|
+
hashCode,
|
|
11
|
+
HASH_KEY,
|
|
12
|
+
hex,
|
|
11
13
|
isArray,
|
|
12
14
|
isArrayLike,
|
|
13
|
-
|
|
14
|
-
isNaN,
|
|
15
|
-
isNull,
|
|
15
|
+
isAsync,
|
|
16
16
|
isBigint,
|
|
17
|
+
isBool,
|
|
18
|
+
isEmpty,
|
|
17
19
|
isFunc,
|
|
20
|
+
isNaN,
|
|
21
|
+
isNull,
|
|
22
|
+
isNumber,
|
|
23
|
+
isObject,
|
|
18
24
|
isPromise,
|
|
25
|
+
isString,
|
|
19
26
|
isSymbol,
|
|
20
|
-
isAsync,
|
|
21
|
-
uniqueId,
|
|
22
|
-
call,
|
|
23
|
-
chr,
|
|
24
|
-
ord,
|
|
25
27
|
keys,
|
|
26
|
-
values,
|
|
27
|
-
round,
|
|
28
|
-
enumerate,
|
|
29
|
-
isEmpty,
|
|
30
|
-
isGenerator,
|
|
31
|
-
hash,
|
|
32
|
-
hashCode,
|
|
33
|
-
HASH_KEY,
|
|
34
|
-
bin,
|
|
35
|
-
hex,
|
|
36
|
-
oct,
|
|
37
28
|
list,
|
|
38
29
|
next,
|
|
39
|
-
|
|
40
|
-
|
|
30
|
+
oct,
|
|
31
|
+
ord,
|
|
32
|
+
round,
|
|
33
|
+
str,
|
|
34
|
+
True,
|
|
35
|
+
type,
|
|
36
|
+
uniqueId,
|
|
37
|
+
values
|
|
38
|
+
} from '../src/globals/index.js'
|
|
39
|
+
import { enumerate } from '../src/itertools/index.js'
|
|
41
40
|
|
|
42
41
|
function cb() {}
|
|
43
42
|
|
|
@@ -71,7 +70,22 @@ describe('globals', () => {
|
|
|
71
70
|
assert(type({}) === 'object')
|
|
72
71
|
assert(type(type) === 'function')
|
|
73
72
|
assert(type(Symbol()) === 'symbol')
|
|
74
|
-
assert(type(new
|
|
73
|
+
assert(type(new Map()) === 'Map')
|
|
74
|
+
assert(type(new WeakMap()) === 'WeakMap')
|
|
75
|
+
assert(type(new Set()) === 'Set')
|
|
76
|
+
assert(type(new WeakSet()) === 'WeakSet')
|
|
77
|
+
assert(type(new Promise(cb)) === 'Promise')
|
|
78
|
+
assert(type(new Int8Array()) === 'Int8Array')
|
|
79
|
+
assert(type(new Uint8Array()) === 'Uint8Array')
|
|
80
|
+
assert(type(new Uint8ClampedArray()) === 'Uint8ClampedArray')
|
|
81
|
+
assert(type(new Int16Array()) === 'Int16Array')
|
|
82
|
+
assert(type(new Uint16Array()) === 'Uint16Array')
|
|
83
|
+
assert(type(new Int32Array()) === 'Int32Array')
|
|
84
|
+
assert(type(new Uint32Array()) === 'Uint32Array')
|
|
85
|
+
assert(type(new Float32Array()) === 'Float32Array')
|
|
86
|
+
assert(type(new Float64Array()) === 'Float64Array')
|
|
87
|
+
assert(type(new ArrayBuffer(8)) === 'ArrayBuffer')
|
|
88
|
+
assert(type(new DataView(new ArrayBuffer(8))) === 'DataView')
|
|
75
89
|
})
|
|
76
90
|
|
|
77
91
|
it('isBool', () => {
|
|
@@ -201,17 +215,6 @@ describe('globals', () => {
|
|
|
201
215
|
assert(round(1.545, 3) === 1.545)
|
|
202
216
|
})
|
|
203
217
|
|
|
204
|
-
it('enumerate', () => {
|
|
205
|
-
let iter = enumerate(['foo', 'bar', 'baz'])
|
|
206
|
-
assert(isGenerator(iter))
|
|
207
|
-
let values = [...iter]
|
|
208
|
-
assert.deepEqual(values, [
|
|
209
|
-
[0, 'foo'],
|
|
210
|
-
[1, 'bar'],
|
|
211
|
-
[2, 'baz']
|
|
212
|
-
])
|
|
213
|
-
})
|
|
214
|
-
|
|
215
218
|
it('next', () => {
|
|
216
219
|
const iter = enumerate([1, 2, 3])
|
|
217
220
|
assert.deepEqual(next(iter), [0, 1])
|
|
@@ -251,15 +254,15 @@ describe('globals', () => {
|
|
|
251
254
|
|
|
252
255
|
it('get', () => {
|
|
253
256
|
const arr = [1, 2, 3]
|
|
254
|
-
assert(get(
|
|
255
|
-
assert(get(
|
|
256
|
-
assert(get(
|
|
257
|
+
assert(get('2', arr) === 3)
|
|
258
|
+
assert(get('3', arr, false) === false)
|
|
259
|
+
assert(get('3', arr, false) === false)
|
|
257
260
|
let obj = { foo: { bar: true } }
|
|
258
261
|
let h = hash(obj)
|
|
259
|
-
assert(get(
|
|
260
|
-
assert(get(
|
|
261
|
-
assert(get(
|
|
262
|
-
assert(get(
|
|
262
|
+
assert(get('foo.bar', obj))
|
|
263
|
+
assert(get(['foo', 'bar'], obj))
|
|
264
|
+
assert(get(HASH_KEY, obj) === h)
|
|
265
|
+
assert(get([HASH_KEY], obj) === h)
|
|
263
266
|
})
|
|
264
267
|
|
|
265
268
|
it('isEmpty', () => {
|
|
@@ -269,6 +272,7 @@ describe('globals', () => {
|
|
|
269
272
|
assert(isEmpty(''))
|
|
270
273
|
assert(isEmpty({}))
|
|
271
274
|
assert(isEmpty(0))
|
|
275
|
+
assert(isEmpty(false))
|
|
272
276
|
assert(!isEmpty(1))
|
|
273
277
|
})
|
|
274
278
|
})
|
package/tests/itertools.spec.ts
CHANGED
|
@@ -1,10 +1,183 @@
|
|
|
1
1
|
import assert from 'assert'
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import {
|
|
3
|
+
accumulate,
|
|
4
|
+
all,
|
|
5
|
+
any,
|
|
6
|
+
chain,
|
|
7
|
+
contains,
|
|
8
|
+
dropWhile,
|
|
9
|
+
enumerate,
|
|
10
|
+
first,
|
|
11
|
+
flatMap,
|
|
12
|
+
icompact,
|
|
13
|
+
ifilter,
|
|
14
|
+
iflatten,
|
|
15
|
+
imap,
|
|
16
|
+
islice,
|
|
17
|
+
itake,
|
|
18
|
+
max,
|
|
19
|
+
min,
|
|
20
|
+
partition,
|
|
21
|
+
range,
|
|
22
|
+
reduce,
|
|
23
|
+
reversed,
|
|
24
|
+
sort,
|
|
25
|
+
sorted,
|
|
26
|
+
sum,
|
|
27
|
+
take,
|
|
28
|
+
takeWhile,
|
|
29
|
+
times,
|
|
30
|
+
zip
|
|
31
|
+
} from '../src/itertools/index.js'
|
|
4
32
|
|
|
5
|
-
|
|
33
|
+
const Falsy = (x) => !x
|
|
6
34
|
|
|
7
35
|
describe('operators', () => {
|
|
36
|
+
it('accumulate', () => {
|
|
37
|
+
assert.deepEqual([...accumulate([1, 2, 3, 4])], [1, 3, 6, 10])
|
|
38
|
+
assert.deepEqual(
|
|
39
|
+
[...accumulate([3, 4, 6, 2, 1, 9, 0, 7, 5, 8], (x, y) => max([x, y]))],
|
|
40
|
+
[3, 4, 6, 6, 6, 9, 9, 9, 9, 9]
|
|
41
|
+
)
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
it('all', () => {
|
|
45
|
+
assert(all([1, true, [], 'test', {}]))
|
|
46
|
+
assert(!all([[], {}, '']))
|
|
47
|
+
assert(all<any>([false, 0, '', null, undefined, NaN], Falsy))
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
it('any', () => {
|
|
51
|
+
assert(any([1, true, [], 'test', {}]))
|
|
52
|
+
assert(!any([0, false, '']))
|
|
53
|
+
assert(any([0, false, ''], Falsy))
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('chain', () => {
|
|
57
|
+
let it = chain([1, 3, 5], [2, 4, 6])
|
|
58
|
+
assert.deepEqual([...it], [1, 3, 5, 2, 4, 6])
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
it('contains', () => {
|
|
62
|
+
assert(contains([4, 7, 1, 9], 1))
|
|
63
|
+
assert(!contains([4, 7, 1, 9], NaN))
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it('dropWhile', () => {
|
|
67
|
+
let it = dropWhile([false, 0, '', true, '', []], Falsy)
|
|
68
|
+
assert.deepEqual([...it], [true, '', []])
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it('enumerate', () => {
|
|
72
|
+
let iter = enumerate(['foo', 'bar', 'baz'])
|
|
73
|
+
let values = [...iter]
|
|
74
|
+
assert.deepEqual(values, [
|
|
75
|
+
[0, 'foo'],
|
|
76
|
+
[1, 'bar'],
|
|
77
|
+
[2, 'baz']
|
|
78
|
+
])
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
it('first', () => {
|
|
82
|
+
assert(first(['foo', 'bar']) === 'foo')
|
|
83
|
+
assert(first([0, 1]) === 0)
|
|
84
|
+
assert(first([1, 1]) === 1)
|
|
85
|
+
})
|
|
86
|
+
|
|
87
|
+
it('flatMap', () => {
|
|
88
|
+
assert.deepEqual(
|
|
89
|
+
[
|
|
90
|
+
...flatMap([
|
|
91
|
+
[1, 2],
|
|
92
|
+
[3, 4]
|
|
93
|
+
])
|
|
94
|
+
],
|
|
95
|
+
[1, 2, 3, 4]
|
|
96
|
+
)
|
|
97
|
+
assert.deepEqual(
|
|
98
|
+
[
|
|
99
|
+
...flatMap(
|
|
100
|
+
[
|
|
101
|
+
[1, 2],
|
|
102
|
+
[3, 4]
|
|
103
|
+
],
|
|
104
|
+
([x, y]) => [x * 2, y * 2]
|
|
105
|
+
)
|
|
106
|
+
],
|
|
107
|
+
[2, 4, 6, 8]
|
|
108
|
+
)
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
it('icompact', () => {
|
|
112
|
+
let it = icompact([false, 0, '', true, '', []])
|
|
113
|
+
assert.deepEqual([...it], [true])
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
it('ifilter', () => {
|
|
117
|
+
let users = [
|
|
118
|
+
{ user: 'barney', age: 36, active: true },
|
|
119
|
+
{ user: 'fred', age: 40, active: false }
|
|
120
|
+
]
|
|
121
|
+
let it = ifilter(users, (x) => !x.active)
|
|
122
|
+
assert.deepEqual([...it], [users[1]])
|
|
123
|
+
})
|
|
124
|
+
|
|
125
|
+
it('iflatten', () => {
|
|
126
|
+
let it = iflatten([
|
|
127
|
+
[0, 1],
|
|
128
|
+
[2, 3]
|
|
129
|
+
])
|
|
130
|
+
assert.deepEqual([...it], [0, 1, 2, 3])
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
it('imap', () => {
|
|
134
|
+
let it = imap([0, 1, 2, 3], (x) => 2 ** x)
|
|
135
|
+
assert.deepEqual([...it], [1, 2, 4, 8])
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
it('islice', () => {
|
|
139
|
+
assert.deepEqual([...islice([1, 2, 3], 1)], [2, 3])
|
|
140
|
+
assert.deepEqual([...islice([1, 2, 3, 4], 2)], [3, 4])
|
|
141
|
+
assert.deepEqual([...islice([1, 2, 3, 4], 1, 3)], [2, 3])
|
|
142
|
+
assert.deepEqual([...islice([1, 2, 3, 4, 5], 0, 4)], [1, 2, 3, 4])
|
|
143
|
+
assert.deepEqual([...islice([1, 2, 3, 4, 5], 0, 4, 2)], [1, 3])
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
it('itake', () => {
|
|
147
|
+
let it = itake(3, [false, 0, '', true, '', []])
|
|
148
|
+
assert.deepEqual([...it], [false, 0, ''])
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
it('take', () => {
|
|
152
|
+
let it = take(3, [false, 0, '', true, '', []])
|
|
153
|
+
assert.deepEqual(it, [false, 0, ''])
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
it('min', () => {
|
|
157
|
+
assert(min([5, 4, 3, 1, 2]) === 1)
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
it('max', () => {
|
|
161
|
+
assert(max([7, 9, 3, 11]) === 11)
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
it('partition', () => {
|
|
165
|
+
let [A, B] = partition([false, 0, '', true, '', []], Falsy)
|
|
166
|
+
assert.deepEqual(A, [false, 0, '', ''])
|
|
167
|
+
assert.deepEqual(B, [true, []])
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
it('range', () => {
|
|
171
|
+
assert.deepEqual([...range(4)], [0, 1, 2, 3])
|
|
172
|
+
assert.deepEqual([...range(5, 9)], [5, 6, 7, 8])
|
|
173
|
+
assert.deepEqual([...range(5, 0, -2)], [5, 3, 1])
|
|
174
|
+
assert.deepEqual([...range(-3)], [])
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
it('reduce', () => {
|
|
178
|
+
assert(reduce([1, 2, 3, 4, 5], (x, y) => x + y, 0) === 15)
|
|
179
|
+
})
|
|
180
|
+
|
|
8
181
|
it('reversed', () => {
|
|
9
182
|
let arr = [3, 2, 1]
|
|
10
183
|
let reverse = reversed(arr)
|
|
@@ -66,11 +239,24 @@ describe('operators', () => {
|
|
|
66
239
|
)
|
|
67
240
|
})
|
|
68
241
|
|
|
242
|
+
it('sum', () => {
|
|
243
|
+
assert(sum([]) === 0)
|
|
244
|
+
assert(sum([1, 2, 3, 4]) === 10)
|
|
245
|
+
assert(sum([1, 2, 3, 4], 5) === 15)
|
|
246
|
+
})
|
|
247
|
+
|
|
69
248
|
it('times', () => {
|
|
70
|
-
let arr =
|
|
249
|
+
let arr = [...times(5, (x) => x)]
|
|
71
250
|
assert.deepEqual(arr, [0, 1, 2, 3, 4])
|
|
72
251
|
})
|
|
73
252
|
|
|
253
|
+
it('takeWhile', () => {
|
|
254
|
+
let arr = [...takeWhile([1, 2, 3, 4], (x) => x < 4)]
|
|
255
|
+
assert.deepEqual(arr, [1, 2, 3])
|
|
256
|
+
arr = [...takeWhile([1, 2, 3, 4, 5], (x) => x)]
|
|
257
|
+
assert.deepEqual(arr, [1, 2, 3, 4, 5])
|
|
258
|
+
})
|
|
259
|
+
|
|
74
260
|
it('zip', () => {
|
|
75
261
|
let users1 = [
|
|
76
262
|
{ user: 'barney', age: 36 },
|
package/tests/operators.spec.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import assert from 'assert'
|
|
2
|
-
import {
|
|
3
|
-
import { bool, id, isinstance, not, all, any, comp, shallowEqual } from '../src/operators.js'
|
|
2
|
+
import { bool, id, isinstance, not, comp, shallowEqual } from '../src/operators/index.js'
|
|
4
3
|
|
|
5
4
|
describe('operators', () => {
|
|
6
5
|
it('id', () => {
|
|
@@ -11,18 +10,6 @@ describe('operators', () => {
|
|
|
11
10
|
assert(id(Object) === Object)
|
|
12
11
|
})
|
|
13
12
|
|
|
14
|
-
it('all', () => {
|
|
15
|
-
assert(all([1, true, [], 'test', {}]))
|
|
16
|
-
assert(!all([[], {}, '']))
|
|
17
|
-
assert(all([[], {}, ''], isEmpty))
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
it('any', () => {
|
|
21
|
-
assert(any([1, true, [], 'test', {}]))
|
|
22
|
-
assert(!any([0, false, '']))
|
|
23
|
-
assert(any([0, false, ''], (x) => !x))
|
|
24
|
-
})
|
|
25
|
-
|
|
26
13
|
it('bool', () => {
|
|
27
14
|
assert(bool(1))
|
|
28
15
|
assert(bool(true))
|
|
@@ -49,17 +36,5 @@ describe('operators', () => {
|
|
|
49
36
|
assert(shallowEqual({}, {}))
|
|
50
37
|
assert(shallowEqual([], []))
|
|
51
38
|
assert(shallowEqual({ test: true }, { test: true }))
|
|
52
|
-
assert(
|
|
53
|
-
shallowEqual(
|
|
54
|
-
{
|
|
55
|
-
value: 42,
|
|
56
|
-
// custom equals implementation will be used
|
|
57
|
-
eq(other) {
|
|
58
|
-
return this.value === other.value
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
{ value: 42 }
|
|
62
|
-
)
|
|
63
|
-
)
|
|
64
39
|
})
|
|
65
40
|
})
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import assert from 'assert'
|
|
2
|
+
import { any, times } from '../src/itertools/index.js'
|
|
3
|
+
import { choice, random, randomInt, sample, shuffle } from '../src/random/index.js'
|
|
4
|
+
|
|
5
|
+
const randomArr = () => [...times(10, (i) => randomInt(i, 71))]
|
|
6
|
+
|
|
7
|
+
describe('random', () => {
|
|
8
|
+
it('choice', () => {
|
|
9
|
+
let arr = randomArr()
|
|
10
|
+
for (let i = 0; i < 10; i++) {
|
|
11
|
+
assert(arr.includes(choice(arr)))
|
|
12
|
+
}
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
it('random', () => {
|
|
16
|
+
for (let i = 1; i <= 10; i++) {
|
|
17
|
+
let r = random(0, i)
|
|
18
|
+
assert(0 <= r && r < i)
|
|
19
|
+
}
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
it('randomInt', () => {
|
|
23
|
+
for (let i = 1; i <= 10; i++) {
|
|
24
|
+
let r = randomInt(0, i)
|
|
25
|
+
assert(0 <= r && r <= i)
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('shuffle', () => {
|
|
30
|
+
let arr = randomArr()
|
|
31
|
+
let copy = arr.slice()
|
|
32
|
+
for (let i = 0; i < 10; i++) {
|
|
33
|
+
assert(shuffle(copy) === copy)
|
|
34
|
+
assert(copy.some((x, i) => x !== arr[i]))
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
it('sample', () => {
|
|
39
|
+
let arr = randomArr()
|
|
40
|
+
for (let i = 0; i < 10; i++) {
|
|
41
|
+
let s = sample(arr, 3)
|
|
42
|
+
assert(s.length === 3)
|
|
43
|
+
assert(s.some((x, i) => x !== arr[i]))
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
})
|
package/tsconfig.json
CHANGED
|
@@ -106,12 +106,20 @@
|
|
|
106
106
|
],
|
|
107
107
|
"typedocOptions": {
|
|
108
108
|
"entryPoints": [
|
|
109
|
-
"src/index.ts"
|
|
109
|
+
"./src/globals/index.ts",
|
|
110
|
+
"./src/collections/index.ts",
|
|
111
|
+
"./src/datetime/index.ts",
|
|
112
|
+
"./src/functools/index.ts",
|
|
113
|
+
"./src/itertools/index.ts",
|
|
114
|
+
"./src/math/index.ts",
|
|
115
|
+
"./src/operators/index.ts",
|
|
116
|
+
"./src/random/index.ts",
|
|
110
117
|
],
|
|
111
118
|
"out": "docs",
|
|
112
119
|
"exclude": [
|
|
113
|
-
"node_modules"
|
|
114
|
-
|
|
115
|
-
|
|
120
|
+
"node_modules"
|
|
121
|
+
],
|
|
122
|
+
"excludeExternals": true,
|
|
123
|
+
"excludePrivate": true,
|
|
116
124
|
}
|
|
117
125
|
}
|
package/src/collections.d.ts
DELETED
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Collections
|
|
3
|
-
* @module
|
|
4
|
-
*/
|
|
5
|
-
import { Function, Iteratee } from './globals.js';
|
|
6
|
-
/**
|
|
7
|
-
* A container type that provides contains().
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* @interface Container
|
|
11
|
-
*/
|
|
12
|
-
export interface Container {
|
|
13
|
-
contains: (x: any) => boolean;
|
|
14
|
-
}
|
|
15
|
-
/**
|
|
16
|
-
* These are the "rich comparison" methods, inspired by Python operators.
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* @interface Comparable
|
|
20
|
-
*/
|
|
21
|
-
export interface Comparable {
|
|
22
|
-
/** x < y: calls this.lt(other) reflection. */
|
|
23
|
-
lt?: (other: any) => boolean;
|
|
24
|
-
/** x ≤ y: calls this.le(other) reflection. */
|
|
25
|
-
le?: (other: any) => boolean;
|
|
26
|
-
/** x == y: calls this.eq(other) reflection. */
|
|
27
|
-
eq: (other: any) => boolean;
|
|
28
|
-
/** x != y: calls this.ne(other) reflection. */
|
|
29
|
-
ne: (other: any) => boolean;
|
|
30
|
-
/** x > y: calls this.gt(other) reflection. */
|
|
31
|
-
gt?: (other: any) => boolean;
|
|
32
|
-
/** x ≥ y: calls this.ge(other) reflection. */
|
|
33
|
-
ge?: (other: any) => boolean;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* A Collection is an iterable container type.
|
|
37
|
-
* This is an abstract base class for user-defined collection types.
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* @abstract
|
|
41
|
-
* @class Collection
|
|
42
|
-
* @implements {Container}
|
|
43
|
-
*/
|
|
44
|
-
export declare abstract class Collection implements Container {
|
|
45
|
-
/**
|
|
46
|
-
* Returns an iterator for the container items
|
|
47
|
-
* @return {Iterator}
|
|
48
|
-
*/
|
|
49
|
-
[Symbol.iterator](): this;
|
|
50
|
-
/**
|
|
51
|
-
* Implements the iterator protocol and returns the next item in the iterable.
|
|
52
|
-
*/
|
|
53
|
-
next(): void;
|
|
54
|
-
/**
|
|
55
|
-
* Adds a new item to the container.
|
|
56
|
-
* @param item
|
|
57
|
-
*/
|
|
58
|
-
add(item: any): void;
|
|
59
|
-
/**
|
|
60
|
-
* Checks if item is present in the container.
|
|
61
|
-
* @param item
|
|
62
|
-
*/
|
|
63
|
-
contains(item: any): boolean;
|
|
64
|
-
/**
|
|
65
|
-
* Returns the total number of elements in the container.
|
|
66
|
-
*/
|
|
67
|
-
size(): number;
|
|
68
|
-
/**
|
|
69
|
-
* Remove the first item from the container where `item == x`
|
|
70
|
-
* @raises ValueError when x is not found
|
|
71
|
-
*/
|
|
72
|
-
remove(x: any): void;
|
|
73
|
-
/**
|
|
74
|
-
* Retrieve and remove the item at index `i`.
|
|
75
|
-
* @returns the item or undefined if not found.
|
|
76
|
-
*/
|
|
77
|
-
pop(i: any): void;
|
|
78
|
-
/**
|
|
79
|
-
* Remove all items from the container
|
|
80
|
-
*/
|
|
81
|
-
clear(): void;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Implements an iterable that allows backward iteration.
|
|
85
|
-
* @interface Reversible
|
|
86
|
-
*/
|
|
87
|
-
export interface Reversible<T = unknown> {
|
|
88
|
-
reversed: () => Iterator<T>;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* A sequence is an iterable type with efficient index-based access.
|
|
92
|
-
*
|
|
93
|
-
*
|
|
94
|
-
* @abstract
|
|
95
|
-
* @class Sequence
|
|
96
|
-
* @extends {Collection}
|
|
97
|
-
* @template T
|
|
98
|
-
*/
|
|
99
|
-
export declare abstract class Sequence<T> extends Collection implements Reversible<T> {
|
|
100
|
-
/**
|
|
101
|
-
* Return the item at the given key or index
|
|
102
|
-
* @param {*} key
|
|
103
|
-
* @memberof Sequence
|
|
104
|
-
*/
|
|
105
|
-
get(key: any): T | undefined;
|
|
106
|
-
/**
|
|
107
|
-
* Set a new value at the given key or index
|
|
108
|
-
*
|
|
109
|
-
* @param {*} key
|
|
110
|
-
* @param {T} val
|
|
111
|
-
* @memberof Sequence
|
|
112
|
-
*/
|
|
113
|
-
set(key: any, val: T): void;
|
|
114
|
-
/**
|
|
115
|
-
* Deletes the given key or index, and its value.
|
|
116
|
-
* Raises ValueError if not key is found.
|
|
117
|
-
*
|
|
118
|
-
* @param {*} key
|
|
119
|
-
* @memberof Sequence
|
|
120
|
-
*/
|
|
121
|
-
delete(key: any): void;
|
|
122
|
-
/**
|
|
123
|
-
* Adds a new item to the end of the sequence.
|
|
124
|
-
*
|
|
125
|
-
* @param {T} x
|
|
126
|
-
* @memberof Sequence
|
|
127
|
-
*/
|
|
128
|
-
append(x: T): void;
|
|
129
|
-
/**
|
|
130
|
-
* Append all the items to the sequence.
|
|
131
|
-
*
|
|
132
|
-
* @param {Iterable<T>} iter
|
|
133
|
-
* @memberof Sequence
|
|
134
|
-
*/
|
|
135
|
-
extend(iter: Iterable<T>): void;
|
|
136
|
-
/**
|
|
137
|
-
* Return the index of x in the sequence, or undefined if not found.
|
|
138
|
-
*
|
|
139
|
-
* @param {T} item
|
|
140
|
-
* @return {(number | undefined)}
|
|
141
|
-
* @memberof Sequence
|
|
142
|
-
*/
|
|
143
|
-
indexOf(item: T): number | undefined;
|
|
144
|
-
size(): number;
|
|
145
|
-
reversed(): Iterator<T>;
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Returns a new immutable Set object with elements from `iterable`. Its contents cannot be altered after it's created.
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
* @class FrozenSet
|
|
152
|
-
* @extends {Set<T>}
|
|
153
|
-
* @template T
|
|
154
|
-
*/
|
|
155
|
-
export declare class FrozenSet<T = any> extends Set<T> {
|
|
156
|
-
constructor(iterable: Iterable<T>);
|
|
157
|
-
add(): this;
|
|
158
|
-
delete(): boolean;
|
|
159
|
-
clear(): this;
|
|
160
|
-
freeze(): Readonly<this>;
|
|
161
|
-
}
|
|
162
|
-
export declare const compact: (...arr: any[]) => any[];
|
|
163
|
-
/**
|
|
164
|
-
* Creates a function that can be used to create named tuple-like objects.
|
|
165
|
-
* @example
|
|
166
|
-
* ```
|
|
167
|
-
* let Point = namedtuple('x', 'y', 'z')
|
|
168
|
-
* let userObj = User(0, 0, 0)
|
|
169
|
-
* // -> {x: 0, y: 0, z: 0}
|
|
170
|
-
* ```
|
|
171
|
-
*
|
|
172
|
-
*
|
|
173
|
-
* @param {...string[]} fields
|
|
174
|
-
* @return
|
|
175
|
-
*/
|
|
176
|
-
export declare function namedtuple(...fields: string[]): (...args: any[]) => {};
|
|
177
|
-
export declare function filter(arr: any, fn?: Iteratee | PropertyKey | Object): any[] | undefined;
|
|
178
|
-
export declare function find(arr: any, fn: Iteratee | PropertyKey | Object): any;
|
|
179
|
-
export declare function findRight(arr: any, fn: Iteratee | PropertyKey | Object): any;
|
|
180
|
-
export declare const matches: (o: any) => (x: any) => boolean;
|
|
181
|
-
export declare function forEach(arr: any[], fn: Iteratee): any;
|
|
182
|
-
export declare function forEach(arr: Object, fn: Iteratee): any;
|
|
183
|
-
export declare function flatten(arr: any, depth?: boolean | number): any;
|
|
184
|
-
export declare function flattenArray(arr: any[], depth?: boolean | number, result?: any[]): any[];
|
|
185
|
-
export declare function flattenObj(o: any, prefix?: string, result?: {}, keepNull?: boolean): {};
|
|
186
|
-
export declare const map: (arr: any, fn: Function | string) => any[] | undefined;
|
|
187
|
-
export declare function pick(obj: any, paths: Iteratee | string[]): {};
|
|
188
|
-
export declare function omit(obj: any, paths: Iteratee | string[]): {};
|
|
189
|
-
export declare function contains(arr: any, y: any): any;
|
|
190
|
-
export declare function indexOf(obj: any, x: any, start?: number): any;
|
|
191
|
-
export declare function lastIndexOf(obj: any, x: any, start?: any): any;
|
|
192
|
-
/**
|
|
193
|
-
* Creates a clone of the given `obj`. If `deep` is `true` it will clone it recursively.
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
* @param {*} obj
|
|
197
|
-
* @param {boolean} [deep=false]
|
|
198
|
-
* @return The clone value
|
|
199
|
-
*/
|
|
200
|
-
export declare function clone(obj: any, deep?: boolean): any;
|
|
201
|
-
export declare function cloneArray(arr: any, deep?: boolean): any;
|
|
202
|
-
export declare function cloneArrayBuffer(arrayBuffer: any): any;
|
|
203
|
-
export declare function cloneTypedArray(typedArray: any, isDeep: any): any;
|
|
204
|
-
export declare function uniq<T = any>(arr: T[], fn?: string | Iteratee): T[];
|
|
205
|
-
export declare function sortedUniq(arr: any, fn?: string | Iteratee): any[];
|
|
206
|
-
/**
|
|
207
|
-
* Recursively merges own and inherited enumerable string keyed properties of source objects into the destination object. Source properties that resolve to `undefined` are skipped if a destination value exists. Array and plain object properties are merged recursively. Other objects and value types are overridden by assignment. Source objects are applied from left to right. Subsequent sources overwrite property assignments of previous sources.
|
|
208
|
-
*
|
|
209
|
-
* Note: this method mutates `obj`
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
* @param {Object} obj
|
|
213
|
-
* @param {...Object} sources
|
|
214
|
-
* @return {Object} The destination object.
|
|
215
|
-
*/
|
|
216
|
-
export declare function merge(obj: any, ...sources: any[]): Object;
|
|
217
|
-
export declare function difference(...args: any[]): Generator<unknown, void, unknown>;
|
|
218
|
-
export declare function intersection(...args: any[]): Generator<any, void, unknown>;
|
|
219
|
-
export declare function union(...args: any[]): Generator<unknown, void, unknown>;
|
|
220
|
-
/**
|
|
221
|
-
* Creates an object composed of keys generated from the results of running each element of `arr` thru `func`. The order of grouped values is determined by the order they occur in `arr`. The corresponding value of each key is an array of elements responsible for generating the key.
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
* @param {(any[] | Object)} arr The collection to iterate over.
|
|
225
|
-
* @param {(Iteratee | PropertyKey)} [func=id] The iteratee to transform keys.
|
|
226
|
-
* @return {Object} Returns the composed aggregate object.
|
|
227
|
-
*/
|
|
228
|
-
export declare function groupBy(arr: any[] | Object, func?: Iteratee | PropertyKey): Object;
|