atomic-fns 0.2.0 → 0.2.2

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.
@@ -25,13 +25,18 @@ describe('collections', () => {
25
25
  assert(!contains([4, 7, 1, 9], NaN))
26
26
  })
27
27
 
28
- it('clone', () => {
28
+ it('clone array', () => {
29
29
  let arr = [4, 7, 1, 9]
30
30
  assert.deepEqual(clone(arr), arr)
31
31
  let target = { user: 'fred', age: 40, active: false }
32
32
  assert.deepEqual(clone(target), target)
33
33
  })
34
34
 
35
+ it('clone object', () => {
36
+ let target = { user: 'fred', age: 40, active: false }
37
+ assert.deepEqual(clone(target), target)
38
+ })
39
+
35
40
  it('difference', () => {
36
41
  let a = [1, 2, 5]
37
42
  let b = [3, 4, 5]
@@ -56,11 +61,27 @@ describe('collections', () => {
56
61
  { user: 'barney', age: 36, active: true },
57
62
  { user: 'fred', age: 40, active: false }
58
63
  ]
59
- assert.deepEqual(filter(users, { age: 36 }), [users[0]])
60
64
  assert.deepEqual(
61
65
  filter(users, (o) => o.active),
62
66
  [users[0]]
63
67
  )
68
+ })
69
+
70
+ it('filter matches', () => {
71
+ assert(filter(null) == undefined)
72
+ let users = [
73
+ { user: 'barney', age: 36, active: true },
74
+ { user: 'fred', age: 40, active: false }
75
+ ]
76
+ assert.deepEqual(filter(users, { age: 36 }), [users[0]])
77
+ })
78
+
79
+ it('filter property', () => {
80
+ assert(filter(null) == undefined)
81
+ let users = [
82
+ { user: 'barney', age: 36, active: true },
83
+ { user: 'fred', age: 40, active: false }
84
+ ]
64
85
  assert.deepEqual(filter(users, 'active'), [users[0]])
65
86
  })
66
87
 
@@ -69,8 +90,22 @@ describe('collections', () => {
69
90
  { user: 'barney', age: 36, active: true },
70
91
  { user: 'fred', age: 40, active: false }
71
92
  ]
72
- assert(find(users, { age: 36 }) === users[0])
73
93
  assert(find(users, (o) => o.active) === users[0])
94
+ })
95
+
96
+ it('find matches', () => {
97
+ let users = [
98
+ { user: 'barney', age: 36, active: true },
99
+ { user: 'fred', age: 40, active: false }
100
+ ]
101
+ assert(find(users, { age: 36 }) === users[0])
102
+ })
103
+
104
+ it('find property', () => {
105
+ let users = [
106
+ { user: 'barney', age: 36, active: true },
107
+ { user: 'fred', age: 40, active: false }
108
+ ]
74
109
  assert(find(users, 'active') === users[0])
75
110
  })
76
111
 
@@ -81,7 +116,23 @@ describe('collections', () => {
81
116
  { user: 'barney', age: 36, active: true }
82
117
  ]
83
118
  assert(findRight(users, { age: 36 }) === users[2])
84
- assert(findRight(users, (o) => o.active) === users[2])
119
+ })
120
+
121
+ it('findRight matches', () => {
122
+ let users = [
123
+ { user: 'barney', age: 36, active: true },
124
+ { user: 'fred', age: 40, active: false },
125
+ { user: 'barney', age: 36, active: true }
126
+ ]
127
+ assert(findRight(users, { age: 36 }) === users[2])
128
+ })
129
+
130
+ it('findRight property', () => {
131
+ let users = [
132
+ { user: 'barney', age: 36, active: true },
133
+ { user: 'fred', age: 40, active: false },
134
+ { user: 'barney', age: 36, active: true }
135
+ ]
85
136
  assert(findRight(users, 'active') === users[2])
86
137
  })
87
138
 
@@ -90,7 +141,8 @@ describe('collections', () => {
90
141
  { user: 'barney', age: 36, active: true },
91
142
  { user: 'fred', age: 40, active: false }
92
143
  ]
93
- let result = [] as any[]
144
+ let result = []
145
+ // @ts-expect-error
94
146
  forEach(users, (value, key) => result.push([key, value]))
95
147
  assert.deepEqual(
96
148
  result,
@@ -100,15 +152,19 @@ describe('collections', () => {
100
152
 
101
153
  it('forEach object key', () => {
102
154
  let target = { user: 'fred', age: 40, active: false }
103
- let objs = [] as any[]
155
+ let objs = []
156
+ // @ts-expect-error
104
157
  forEach(target, (value, key) => objs.push([key, value]))
105
158
  assert.deepEqual(objs, Object.entries(target))
106
159
  })
107
160
 
108
- it('flattenArray', () => {
161
+ it('flatten', () => {
109
162
  let data = flatten([1, 2, [3, 4], 5])
110
163
  assert.deepEqual(data, [1, 2, 3, 4, 5])
111
- data = flatten([1, 2, [3, [4]], [5]], true)
164
+ })
165
+
166
+ it('flattenDeep', () => {
167
+ let data = flatten([1, 2, [3, [4]], [5]], true)
112
168
  assert.deepEqual(data, [1, 2, 3, 4, 5])
113
169
  })
114
170
 
@@ -174,9 +230,21 @@ describe('collections', () => {
174
230
  )
175
231
  })
176
232
 
233
+ it('pickBy', () => {
234
+ let target = { user: 'fred', age: 40, active: false }
235
+ assert.deepEqual(
236
+ pick(target, (x) => x >= 40),
237
+ { age: 40 }
238
+ )
239
+ })
240
+
177
241
  it('omit', () => {
178
242
  let target = { user: 'fred', age: 40, active: false }
179
243
  assert.deepEqual(omit(target, ['age', 'active']), { user: 'fred' })
244
+ })
245
+
246
+ it('omitBy', () => {
247
+ let target = { user: 'fred', age: 40, active: false }
180
248
  assert.deepEqual(
181
249
  omit(target, (x) => !x),
182
250
  { user: 'fred', age: 40 }
@@ -193,7 +261,11 @@ describe('collections', () => {
193
261
  let arr = [4, 7, 1, 1, 9, 4, 7]
194
262
  let distinct = uniq(arr)
195
263
  assert.deepEqual(distinct, [4, 7, 1, 9])
196
- distinct = uniq(arr, (x) => x * 2)
264
+ })
265
+
266
+ it('uniqBy', () => {
267
+ let arr = [4, 7, 1, 1, 9, 4, 7]
268
+ let distinct = uniq(arr, (x) => x * 2)
197
269
  assert.deepEqual(distinct, [8, 14, 2, 18])
198
270
  })
199
271
  })
@@ -47,9 +47,11 @@ describe('globals', () => {
47
47
  assert.equal(err.message, 'custom')
48
48
  })
49
49
 
50
+ it('True', () => assert(True() === true))
51
+
52
+ it('False', () => assert(False() === false))
53
+
50
54
  it('type', () => {
51
- assert(True())
52
- assert(!False())
53
55
  assert(type(null) === 'null')
54
56
  assert(type(undefined) === 'undefined')
55
57
  assert(type(true) === 'boolean')
@@ -70,35 +72,71 @@ describe('globals', () => {
70
72
  assert(type(type) === 'function')
71
73
  assert(type(Symbol()) === 'symbol')
72
74
  assert(type(new Promise(cb)) === 'promise')
75
+ })
76
+
77
+ it('isBool', () => {
73
78
  assert(isBool(true))
74
79
  assert(isBool(Boolean()))
75
80
  assert(!isBool(''))
76
81
  assert(!isBool({}))
77
82
  assert(!isBool(undefined))
83
+ })
84
+
85
+ it('isObject', () => {
78
86
  assert(isObject({}))
79
87
  assert(!isObject(''))
80
88
  assert(!isObject([]))
89
+ })
90
+
91
+ it('isString', () => {
81
92
  assert(isString(''))
82
93
  assert(!isString([]))
94
+ })
95
+
96
+ it('isArray', () => {
83
97
  assert(isArray([]))
84
98
  assert(isArrayLike([]))
85
99
  assert(!isArray(''))
86
100
  assert(!isArrayLike(''))
101
+ })
102
+
103
+ it('isFunc', () => {
87
104
  assert(isFunc(cb))
88
105
  assert(!isFunc([]))
106
+ })
107
+
108
+ it('isAsync', () => {
89
109
  assert(isAsync(async function () {}))
90
110
  assert(isAsync(async () => {}))
91
111
  assert(!isAsync(cb))
112
+ })
113
+
114
+ it('isNaN', () => {
92
115
  assert(isNaN(NaN))
116
+ })
117
+
118
+ it('isNumber', () => {
93
119
  assert(!isNumber(NaN))
94
120
  assert(isNumber(42))
95
121
  assert(isNumber(Number(42)))
96
122
  assert(isNumber(Number('42')))
97
123
  assert(isNumber(parseFloat('42.0')))
124
+ })
125
+
126
+ it('isBigInt', () => {
98
127
  assert(isBigint(42n))
99
128
  assert(isBigint(BigInt('42')))
129
+ })
130
+
131
+ it('isPromise', () => {
100
132
  assert(isPromise(new Promise(cb)))
133
+ })
134
+
135
+ it('isSymbol', () => {
101
136
  assert(isSymbol(Symbol()))
137
+ })
138
+
139
+ it('isNull', () => {
102
140
  assert(isNull(null))
103
141
  assert(isNull(undefined))
104
142
  assert(!isNull(''))
@@ -15,17 +15,21 @@ describe('operators', () => {
15
15
  it('sort', () => {
16
16
  let arr = [3, 2, 1]
17
17
  assert.deepEqual(sort(arr), [1, 2, 3])
18
- arr = [3, 1, 2]
18
+ })
19
+
20
+ it('sort reversed', () => {
21
+ let arr = [3, 1, 2]
19
22
  assert.deepEqual(sort(arr, true), [3, 2, 1])
20
23
  })
21
24
 
22
25
  it('sorted', () => {
23
26
  let arr = [3, 2, 1]
24
- let sort = sorted(arr)
25
- arr.sort()
26
- assert.deepEqual(sort, arr)
27
- // reversed order
27
+ assert.deepEqual(sorted(arr), arr.sort())
28
+ // sorted in reverse
28
29
  assert.deepEqual(sorted([3, 1, 2], true), [3, 2, 1])
30
+ })
31
+
32
+ it('sorted by key', () => {
29
33
  let users = [
30
34
  { user: 'fred', age: 40 },
31
35
  { user: 'barney', age: 36 }
@@ -46,7 +50,13 @@ describe('operators', () => {
46
50
  { user: 'barney', age: 36 }
47
51
  ]
48
52
  )
49
- // using custom compare
53
+ })
54
+
55
+ it('sorted with custom compare', () => {
56
+ let users = [
57
+ { user: 'fred', age: 40 },
58
+ { user: 'barney', age: 36 }
59
+ ]
50
60
  assert.deepEqual(
51
61
  sorted(users, false, (x, y) => (x.user <= y.user ? -1 : 1)),
52
62
  [
@@ -71,10 +81,7 @@ describe('operators', () => {
71
81
  { user: 'barney', age: 36 }
72
82
  ]
73
83
 
74
- let results = [] as any
75
- for (const t of zip(users1, users2)) {
76
- results.push(t)
77
- }
84
+ let results = [...zip(users1, users2)]
78
85
 
79
86
  let [first1, first2] = results[0]
80
87
  assert(first1 === users1[0])
@@ -3,6 +3,14 @@ import { isEmpty } from '../src/globals.js'
3
3
  import { bool, id, isinstance, not, all, any, comp, shallowEqual } from '../src/operators.js'
4
4
 
5
5
  describe('operators', () => {
6
+ it('id', () => {
7
+ assert(id(true) === true)
8
+ assert(id(false) === false)
9
+ assert(id(3.0) === 3.0)
10
+ assert(id('') === '')
11
+ assert(id(Object) === Object)
12
+ })
13
+
6
14
  it('all', () => {
7
15
  assert(all([1, true, [], 'test', {}]))
8
16
  assert(!all([[], {}, '']))
@@ -29,11 +37,6 @@ describe('operators', () => {
29
37
  assert(comp(4, 3) === 1)
30
38
  })
31
39
 
32
- it('id', () => {
33
- let x = Math.random()
34
- assert(id(x) === x)
35
- })
36
-
37
40
  it('isinstance', () => {
38
41
  assert(isinstance([], Array))
39
42
  assert(isinstance(Array(), Array))
package/tsconfig.json CHANGED
@@ -9,9 +9,10 @@
9
9
  // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
10
10
  // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
11
11
  /* Language and Environment */
12
- "target": "ESNext", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
12
+ "target": "ES2022", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
13
13
  "lib": [
14
14
  "ESNext",
15
+ "ES2022",
15
16
  "DOM"
16
17
  ], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
17
18
  // "jsx": "preserve", /* Specify what JSX code is generated. */
@@ -95,6 +96,9 @@
95
96
  // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
96
97
  "skipLibCheck": true /* Skip type checking all .d.ts files. */
97
98
  },
99
+ "exclude": [
100
+ "**/*.spec.ts"
101
+ ],
98
102
  "references": [
99
103
  {
100
104
  "path": "./tsconfig.node.json"
@@ -104,6 +108,10 @@
104
108
  "entryPoints": [
105
109
  "src/index.ts"
106
110
  ],
107
- "out": "docs"
111
+ "out": "docs",
112
+ "exclude": [
113
+ "node_modules",
114
+ "tests/*.spec.ts"
115
+ ]
108
116
  }
109
117
  }