-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathutils.js
More file actions
37 lines (29 loc) · 806 Bytes
/
utils.js
File metadata and controls
37 lines (29 loc) · 806 Bytes
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
// @ts-check
/** api same as ramda */
const map = fn => list => list.map(fn)
/** api same as ramda */
const filter = fn => list => list.filter(fn)
/** api same as ramda */
const values = obj => Object.keys(obj).map(key => obj[key])
/** api same as ramda */
const length = strOrArray => (strOrArray != null ? strOrArray.length : 0)
/** api same as ramda */
const isString = x => x != null && x.constructor === String
/** api same as ramda */
const compose = (...fnlist) => data =>
[...fnlist, data].reduceRight((prev, fn) => fn(prev))
/** api same as ramda */
const mapObjIndexed = fn => obj => {
const acc = {}
Object.keys(obj).forEach(key => (acc[key] = fn(obj[key], key, obj)))
return acc
}
module.exports = {
mapObjIndexed,
compose,
map,
filter,
values,
isString,
length
}