Repository navigation
Expand file tree
/
Copy pathtest.js
More file actions
82 lines (71 loc) · 1.64 KB
/
Copy pathtest.js
File metadata and controls
82 lines (71 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import assert from 'node:assert/strict'
import test from 'node:test'
import {mapz} from './index.js'
test('mapz(options?)', function () {
assert.deepEqual(
mapz(fn)([1, 2, 3]),
[null, 'Hi, 2.', 'Hi, 3.'],
'should map values'
)
assert.deepEqual(
mapz(fn, {gapless: true})([1, 2, 3]),
['Hi, 2.', 'Hi, 3.'],
'should ignore gaps in `gapless: true` mode'
)
assert.deepEqual(
mapz(fn, {gapless: true})([1, 2, 3]),
['Hi, 2.', 'Hi, 3.'],
'should ignore gaps in `gapless: true` mode'
)
assert.deepEqual(
mapz(parentsList)([1, 2, 3]),
[3, 3, 3],
'should pass a parent'
)
assert.deepEqual(
mapz(parentsList, {key: 'foo'})([1, 2, 3]),
[0, 0, 0],
'should not pass a parent if a `key` is given and an array passed'
)
assert.deepEqual(
mapz(parentsList, 'foo')([1, 2, 3]),
[0, 0, 0],
'should support a key instead of `options`'
)
assert.deepEqual(
mapz(parentsObject, {key: 'foo'})({
foo: [1, 2, 3],
value: 'x'
}),
['x', 'x', 'x'],
'should pass a parent if a `key` is given and an object passed'
)
})
/**
* @param {number} value
* @returns {string|null}
*/
function fn(value) {
return value > 1 ? 'Hi, ' + value + '.' : null
}
/**
* @param {number} value
* @param {Array<number>|null} parent
* @returns {number}
*/
function parentsList(value, parent) {
return parent ? parent.length : 0
}
/**
* @typedef Parent
* @property {Array<number>} foo
* @property {string} value
*/
/**
* @param {number} value
* @param {Parent|null} parent
* @returns {string}
*/
function parentsObject(value, parent) {
return parent ? parent.value : 'y'
}