• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In
Build has been canceled!

rackai / domql / #431

16 Feb 2022 03:27AM UTC coverage: 3.504% (-65.5%) from 68.987%
#431

push

web-flow
Merge pull request #66 from rackai/dependabot/npm_and_yarn/eslint-plugin-jest-25.3.2

Bump eslint-plugin-jest from 24.7.0 to 25.3.2

8 of 543 branches covered (1.47%)

Branch coverage included in aggregate %.

33 of 627 relevant lines covered (5.26%)

0.09 hits per line

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

23.98
/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 isNode = obj => {
1✔
27
  return (
×
28
    typeof window.Node === 'object'
×
29
      ? obj instanceof window.Node
30
      : obj && typeof obj === 'object' && typeof obj.nodeType === 'number' && typeof obj.nodeName === 'string'
×
31
  )
32
}
33

34
export const isHtmlElement = obj => {
1✔
35
  return (
×
36
    typeof window.HTMLElement === 'object'
×
37
      ? obj instanceof window.HTMLElement // DOM2
38
      : obj && typeof obj === 'object' && obj !== null && obj.nodeType === 1 && typeof obj.nodeName === 'string'
×
39
  )
40
}
41

42
export const isDefined = arg => {
1✔
43
  return isObject(arg) ||
×
44
    isObjectLike(arg) ||
45
    isString(arg) ||
46
    isNumber(arg) ||
47
    isFunction(arg) ||
48
    isArray(arg) ||
49
    isObjectLike(arg)
50
}
51

52
export const exec = (param, element, state) => {
1✔
53
  if (isFunction(param)) return param(element, state || element.state)
×
54
  return param
×
55
}
56

57
export const map = (obj, extention, element) => {
1✔
58
  for (const e in extention) {
×
59
    obj[e] = exec(extention[e], element)
×
60
  }
61
}
62

63
export const merge = (element, obj) => {
1✔
64
  for (const e in obj) {
×
65
    const elementProp = element[e]
×
66
    const objProp = obj[e]
×
67
    if (elementProp === undefined) {
×
68
      element[e] = objProp
×
69
    }
70
  }
71
  return element
×
72
}
73

74
export const deepMerge = (element, proto) => {
1✔
75
  // console.groupCollapsed('deepMerge:')
76
  for (const e in proto) {
×
77
    const elementProp = element[e]
×
78
    const protoProp = proto[e]
×
79
    // const cachedProps = cache.props
80
    if (e === 'parent' || e === 'props') continue
×
81
    if (elementProp === undefined) {
×
82
      element[e] = protoProp
×
83
    } else if (isObjectLike(elementProp) && isObject(protoProp)) {
×
84
      deepMerge(elementProp, protoProp)
×
85
    }
86
  }
87
  // console.groupEnd('deepMerge:')
88
  return element
×
89
}
90

91
export const clone = obj => {
1✔
92
  const o = {}
×
93
  for (const prop in obj) {
×
94
    if (prop === 'node') continue
×
95
    o[prop] = obj[prop]
×
96
  }
97
  return o
×
98
}
99

100
/**
101
 * Deep cloning of object
102
 */
103
export const deepClone = (obj, excluding = ['parent', 'node', '__element', '__root']) => {
1!
104
  const o = {}
×
105
  for (const prop in obj) {
×
106
    if (excluding.indexOf(prop) > -1) continue
×
107
    let objProp = obj[prop]
×
108
    if (prop === 'proto' && isArray(objProp)) {
×
109
      objProp = mergeArray(objProp)
×
110
    }
111
    if (isObjectLike(objProp)) {
×
112
      o[prop] = deepClone(objProp)
×
113
    } else o[prop] = objProp
×
114
  }
115
  return o
×
116
}
117

118
/**
119
 * Overwrites object properties with another
120
 */
121
export const overwrite = (element, params, options) => {
1✔
122
  const changes = {}
×
123

124
  for (const e in params) {
×
125
    if (e === 'props') continue
×
126

127
    const elementProp = element[e]
×
128
    const paramsProp = params[e]
×
129

130
    if (paramsProp) {
×
131
      element.__cached[e] = changes[e] = elementProp
×
132
      element[e] = paramsProp
×
133
    }
134

135
    if (options.cleanExec) delete element.__exec[e]
×
136
  }
137

138
  return changes
×
139
}
140

141
/**
142
 * Overwrites DEEPly object properties with another
143
 */
144
export const overwriteDeep = (obj, params, excluding = ['node', '__root']) => {
1✔
145
  for (const e in params) {
2✔
146
    if (excluding.indexOf(e) > -1) continue
4!
147
    const objProp = obj[e]
4✔
148
    const paramsProp = params[e]
4✔
149
    if (isObjectLike(objProp) && isObjectLike(paramsProp)) {
4✔
150
      overwriteDeep(objProp, paramsProp)
1✔
151
    } else if (paramsProp !== undefined) {
3!
152
      obj[e] = paramsProp
3✔
153
    }
154
  }
155
  return obj
2✔
156
}
157

158
/**
159
 * Overwrites object properties with another
160
 */
161
export const mergeIfExisted = (a, b) => {
1✔
162
  if (isObjectLike(a) && isObjectLike(b)) return deepMerge(a, b)
×
163
  return a || b
×
164
}
165

166
/**
167
 * Merges array prototypes
168
 */
169
export const mergeArray = (arr) => {
1✔
170
  return arr.reduce((a, c) => deepMerge(a, deepClone(c)), {})
×
171
}
172

173
/**
174
 * Merges array prototypes
175
 */
176
export const mergeAndCloneIfArray = obj => {
1✔
177
  return isArray(obj) ? mergeArray(obj) : deepClone(obj)
×
178
}
179

180
/**
181
 * Overwrites object properties with another
182
 */
183
export const flattenRecursive = (param, prop, stack = []) => {
1!
184
  const objectized = mergeAndCloneIfArray(param)
×
185
  stack.push(objectized)
×
186

187
  const protoOfProto = objectized[prop]
×
188
  if (protoOfProto) flattenRecursive(protoOfProto, prop, stack)
×
189

190
  delete objectized[prop]
×
191

192
  return stack
×
193
}
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