• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rackai / domql / #313

22 Oct 2021 01:27PM UTC coverage: 3.391% (-63.9%) from 67.331%
#313

push

nikoloza
added packages

8 of 528 branches covered (1.52%)

Branch coverage included in aggregate %.

31 of 622 relevant lines covered (4.98%)

0.09 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

25.32
/src/utils/object.js
1
'use strict'
2

3
import nodes from '../element/nodes'
4

5
export const isTagRegistered = arg => nodes.body.indexOf(arg)
1✔
6

7
export const isObject = arg => {
1✔
8
  if (arg === null) return false
×
9
  return (typeof arg === 'object') && (arg.constructor === Object)
×
10
}
11

12
export const isString = arg => typeof arg === 'string'
1✔
13

14
export const isNumber = arg => typeof arg === 'number'
1✔
15

16
export const isFunction = arg => typeof arg === 'function'
1✔
17

18
export const isArray = arg => Array.isArray(arg)
1✔
19

20
export const isObjectLike = arg => {
1✔
21
  if (arg === null) return false
5!
22
  // if (isArray(arg)) return false
23
  return (typeof arg === 'object')
5✔
24
}
25

26
export const isDefined = arg => {
1✔
27
  return isObject(arg) ||
×
28
    isObjectLike(arg) ||
29
    isString(arg) ||
30
    isNumber(arg) ||
31
    isFunction(arg) ||
32
    isArray(arg) ||
33
    isObjectLike(arg)
34
}
35

36
export const exec = (param, element, state) => {
1✔
37
  if (isFunction(param)) return param(element, state || element.state)
×
38
  return param
×
39
}
40

41
export const map = (obj, extention, element) => {
1✔
42
  for (const e in extention) {
×
43
    obj[e] = exec(extention[e], element)
×
44
  }
45
}
46

47
export const merge = (element, obj) => {
1✔
48
  for (const e in obj) {
×
49
    const elementProp = element[e]
×
50
    const objProp = obj[e]
×
51
    if (elementProp === undefined) {
×
52
      element[e] = objProp
×
53
    }
54
  }
55
  return element
×
56
}
57

58
export const deepMerge = (element, proto) => {
1✔
59
  // console.groupCollapsed('deepMerge:')
60
  for (const e in proto) {
×
61
    const elementProp = element[e]
×
62
    const protoProp = proto[e]
×
63
    // const cachedProps = cache.props
64
    if (e === 'parent' || e === 'props') continue
×
65
    if (elementProp === undefined) {
×
66
      element[e] = protoProp
×
67
    } else if (isObjectLike(elementProp) && isObject(protoProp)) {
×
68
      deepMerge(elementProp, protoProp)
×
69
    }
70
  }
71
  // console.groupEnd('deepMerge:')
72
  return element
×
73
}
74

75
export const clone = obj => {
1✔
76
  const o = {}
×
77
  for (const prop in obj) {
×
78
    if (prop === 'node') continue
×
79
    o[prop] = obj[prop]
×
80
  }
81
  return o
×
82
}
83

84
/**
85
 * Deep cloning of object
86
 */
87
export const deepClone = (obj, excluding = ['parent', 'node', '__element', '__root']) => {
1!
88
  const o = {}
×
89
  for (const prop in obj) {
×
90
    if (excluding.indexOf(prop) > -1) continue
×
91
    let objProp = obj[prop]
×
92
    if (prop === 'proto' && isArray(objProp)) {
×
93
      objProp = mergeArray(objProp)
×
94
    }
95
    if (isObjectLike(objProp)) {
×
96
      o[prop] = deepClone(objProp)
×
97
    } else o[prop] = objProp
×
98
  }
99
  return o
×
100
}
101

102
/**
103
 * Overwrites object properties with another
104
 */
105
export const overwrite = (element, params, options) => {
1✔
106
  const changes = {}
×
107

108
  for (const e in params) {
×
109
    if (e === 'props') continue
×
110

111
    const elementProp = element[e]
×
112
    const paramsProp = params[e]
×
113

114
    if (paramsProp) {
×
115
      element.__cached[e] = changes[e] = elementProp
×
116
      element[e] = paramsProp
×
117
    }
118

119
    if (options.cleanExec) delete element.__exec[e]
×
120
  }
121

122
  return changes
×
123
}
124

125
/**
126
 * Overwrites DEEPly object properties with another
127
 */
128
export const overwriteDeep = (obj, params, excluding = ['node', '__root']) => {
1✔
129
  for (const e in params) {
2✔
130
    if (excluding.indexOf(e) > -1) continue
4!
131
    const objProp = obj[e]
4✔
132
    const paramsProp = params[e]
4✔
133
    if (isObjectLike(objProp) && isObjectLike(paramsProp)) {
4✔
134
      overwriteDeep(objProp, paramsProp)
1✔
135
    } else if (paramsProp !== undefined) {
3!
136
      obj[e] = paramsProp
3✔
137
    }
138
  }
139
  return obj
2✔
140
}
141

142
/**
143
 * Overwrites object properties with another
144
 */
145
export const mergeIfExisted = (a, b) => {
1✔
146
  if (isObjectLike(a) && isObjectLike(b)) return deepMerge(a, b)
×
147
  return a || b
×
148
}
149

150
/**
151
 * Merges array prototypes
152
 */
153
export const mergeArray = (arr) => {
1✔
154
  return arr.reduce((a, c) => deepMerge(a, deepClone(c)), {})
×
155
}
156

157
/**
158
 * Merges array prototypes
159
 */
160
export const mergeAndCloneIfArray = obj => {
1✔
161
  return isArray(obj) ? mergeArray(obj) : deepClone(obj)
×
162
}
163

164
/**
165
 * Overwrites object properties with another
166
 */
167
export const flattenRecursive = (param, prop, stack = []) => {
1!
168
  const objectized = mergeAndCloneIfArray(param)
×
169
  stack.push(objectized)
×
170

171
  const protoOfProto = objectized[prop]
×
172
  if (protoOfProto) flattenRecursive(protoOfProto, prop, stack)
×
173

174
  delete objectized[prop]
×
175

176
  return stack
×
177
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc