-
Notifications
You must be signed in to change notification settings - Fork 19
/
utils.js
48 lines (45 loc) · 965 Bytes
/
utils.js
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
function blockParams(params, ids) {
params.path = ids
return params
}
function extend(obj /* , ...source */) {
for (let i = 1; i < arguments.length; i++) {
for (const key in arguments[i]) {
if (Object.prototype.hasOwnProperty.call(arguments[i], key)) {
obj[key] = arguments[i][key]
}
}
}
return obj
}
function appendContextPath(contextPath, id) {
return (contextPath ? `${contextPath}.` : '') + id
}
function createFrame(object) {
const frame = extend({}, object)
frame._parent = object
return frame
}
function isEmpty(value) {
if (!value && value !== 0) {
return true
} if (Array.isArray(value) && value.length === 0) {
return true
}
return false
}
function isPromise(value) {
return (
typeof value === 'object'
&& value !== null
&& typeof value.then === 'function'
)
}
module.exports = {
blockParams,
extend,
appendContextPath,
createFrame,
isEmpty,
isPromise
}