@domql/utils 2.5.187 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/array.js +26 -13
- package/cache.js +4 -0
- package/component.js +10 -227
- package/cookie.js +27 -24
- package/dist/cjs/array.js +30 -16
- package/dist/cjs/cache.js +26 -0
- package/dist/cjs/component.js +16 -226
- package/dist/cjs/cookie.js +19 -24
- package/dist/cjs/element.js +137 -0
- package/dist/cjs/events.js +37 -0
- package/dist/cjs/extends.js +351 -0
- package/dist/cjs/function.js +2 -4
- package/dist/cjs/if.js +30 -0
- package/dist/cjs/index.js +25 -15
- package/dist/cjs/key.js +6 -1
- package/dist/cjs/keys.js +178 -0
- package/dist/cjs/log.js +1 -2
- package/dist/cjs/methods.js +305 -0
- package/dist/cjs/object.js +89 -237
- package/dist/cjs/props.js +220 -0
- package/dist/cjs/scope.js +28 -0
- package/dist/cjs/state.js +175 -0
- package/dist/cjs/string.js +27 -16
- package/dist/cjs/types.js +2 -4
- package/dist/cjs/update.js +42 -0
- package/dist/esm/array.js +30 -16
- package/dist/esm/cache.js +6 -0
- package/dist/esm/component.js +17 -245
- package/dist/esm/cookie.js +19 -24
- package/dist/esm/element.js +135 -0
- package/dist/esm/events.js +17 -0
- package/dist/esm/extends.js +349 -0
- package/dist/esm/function.js +2 -4
- package/dist/esm/if.js +10 -0
- package/dist/esm/index.js +10 -0
- package/dist/esm/key.js +6 -1
- package/dist/esm/keys.js +158 -0
- package/dist/esm/log.js +1 -2
- package/dist/esm/methods.js +285 -0
- package/dist/esm/object.js +90 -239
- package/dist/esm/props.js +216 -0
- package/dist/esm/scope.js +8 -0
- package/dist/esm/state.js +185 -0
- package/dist/esm/string.js +27 -16
- package/dist/esm/types.js +2 -4
- package/dist/esm/update.js +22 -0
- package/element.js +149 -0
- package/env.js +5 -2
- package/events.js +17 -0
- package/extends.js +425 -0
- package/if.js +14 -0
- package/index.js +10 -0
- package/key.js +6 -0
- package/keys.js +157 -0
- package/log.js +4 -1
- package/methods.js +315 -0
- package/node.js +21 -13
- package/object.js +121 -235
- package/package.json +3 -3
- package/props.js +249 -0
- package/scope.js +8 -0
- package/state.js +208 -0
- package/string.js +66 -30
- package/update.js +27 -0
package/array.js
CHANGED
|
@@ -20,8 +20,6 @@ export const removeFromArray = (arr, index) => {
|
|
|
20
20
|
throw new Error('Invalid index')
|
|
21
21
|
}
|
|
22
22
|
arr.splice(index, 1)
|
|
23
|
-
} else if (isArray(index)) {
|
|
24
|
-
index.forEach(idx => removeFromArray(arr, idx))
|
|
25
23
|
} else {
|
|
26
24
|
throw new Error('Invalid index')
|
|
27
25
|
}
|
|
@@ -29,7 +27,7 @@ export const removeFromArray = (arr, index) => {
|
|
|
29
27
|
}
|
|
30
28
|
|
|
31
29
|
export const swapItemsInArray = (arr, i, j) => {
|
|
32
|
-
[arr[i], arr[j]] = [arr[j], arr[i]]
|
|
30
|
+
;[arr[i], arr[j]] = [arr[j], arr[i]]
|
|
33
31
|
}
|
|
34
32
|
|
|
35
33
|
export const joinArrays = (...arrays) => {
|
|
@@ -39,15 +37,11 @@ export const joinArrays = (...arrays) => {
|
|
|
39
37
|
/**
|
|
40
38
|
* Merges array extendtypes
|
|
41
39
|
*/
|
|
42
|
-
export const
|
|
43
|
-
return arr.reduce(
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
* Merges array extends
|
|
48
|
-
*/
|
|
49
|
-
export const mergeAndCloneIfArray = obj => {
|
|
50
|
-
return isArray(obj) ? mergeArray(obj) : deepClone(obj)
|
|
40
|
+
export const unstackArrayOfObjects = (arr, exclude = []) => {
|
|
41
|
+
return arr.reduce(
|
|
42
|
+
(a, c) => deepMerge(a, deepClone(c, { exclude }), exclude),
|
|
43
|
+
{}
|
|
44
|
+
)
|
|
51
45
|
}
|
|
52
46
|
|
|
53
47
|
export const cutArrayBeforeValue = (arr, value) => {
|
|
@@ -105,7 +99,10 @@ export const reorderArrayByValues = (array, valueToMove, insertBeforeValue) => {
|
|
|
105
99
|
const indexToInsertBefore = newArray.indexOf(insertBeforeValue) // Find the index to insert before
|
|
106
100
|
if (indexToMove !== -1 && indexToInsertBefore !== -1) {
|
|
107
101
|
const removedItem = newArray.splice(indexToMove, 1)[0] // Remove the item to move
|
|
108
|
-
const insertIndex =
|
|
102
|
+
const insertIndex =
|
|
103
|
+
indexToInsertBefore < indexToMove
|
|
104
|
+
? indexToInsertBefore
|
|
105
|
+
: indexToInsertBefore + 1 // Adjust insert index
|
|
109
106
|
newArray.splice(insertIndex, 0, removedItem) // Insert the removed item before the specified value
|
|
110
107
|
}
|
|
111
108
|
return newArray
|
|
@@ -140,3 +137,19 @@ export const checkIfStringIsInArray = (string, arr) => {
|
|
|
140
137
|
if (!string) return
|
|
141
138
|
return arr.filter(v => string.includes(v)).length
|
|
142
139
|
}
|
|
140
|
+
|
|
141
|
+
export const removeDuplicatesInArray = arr => {
|
|
142
|
+
if (!isArray(arr)) return arr
|
|
143
|
+
return [...new Set(arr)]
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export const addProtoToArray = (state, proto) => {
|
|
147
|
+
for (const key in proto) {
|
|
148
|
+
Object.defineProperty(state, key, {
|
|
149
|
+
value: proto[key],
|
|
150
|
+
enumerable: false, // Set this to true if you want the method to appear in for...in loops
|
|
151
|
+
configurable: true, // Set this to true if you want to allow redefining/removing the property later
|
|
152
|
+
writable: true // Set this to true if you want to allow changing the function later
|
|
153
|
+
})
|
|
154
|
+
}
|
|
155
|
+
}
|
package/cache.js
ADDED
package/component.js
CHANGED
|
@@ -1,243 +1,26 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { isArray, isFunction, isObject, isString } from './types.js'
|
|
3
|
+
import { createExtendsFromKeys } from './extends.js'
|
|
4
|
+
import { isString } from './types.js'
|
|
6
5
|
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
export const checkIfKeyIsComponent = (key) => {
|
|
6
|
+
export const matchesComponentNaming = key => {
|
|
10
7
|
const isFirstKeyString = isString(key)
|
|
11
8
|
if (!isFirstKeyString) return
|
|
12
9
|
const firstCharKey = key.slice(0, 1)
|
|
13
10
|
return /^[A-Z]*$/.test(firstCharKey)
|
|
14
11
|
}
|
|
15
12
|
|
|
16
|
-
export const checkIfKeyIsProperty = (key) => {
|
|
17
|
-
const isFirstKeyString = isString(key)
|
|
18
|
-
if (!isFirstKeyString) return
|
|
19
|
-
const firstCharKey = key.slice(0, 1)
|
|
20
|
-
return /^[a-z]*$/.test(firstCharKey)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const addAdditionalExtend = (newExtend, element) => {
|
|
24
|
-
if (!newExtend) return element
|
|
25
|
-
const { extend: elementExtend } = element
|
|
26
|
-
const originalArray = isArray(elementExtend) ? elementExtend : [elementExtend]
|
|
27
|
-
const receivedArray = isArray(newExtend) ? newExtend : [newExtend]
|
|
28
|
-
const extend = joinArrays(receivedArray, originalArray)
|
|
29
|
-
return { ...element, extend }
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export const checkIfSugar = (element, parent, key) => {
|
|
33
|
-
const {
|
|
34
|
-
extend,
|
|
35
|
-
props,
|
|
36
|
-
childExtend,
|
|
37
|
-
extends: extendProps,
|
|
38
|
-
childExtends,
|
|
39
|
-
childProps,
|
|
40
|
-
children,
|
|
41
|
-
on,
|
|
42
|
-
$collection,
|
|
43
|
-
$stateCollection,
|
|
44
|
-
$propsCollection
|
|
45
|
-
} = element
|
|
46
|
-
const hasComponentAttrs = extend || childExtend || props || on || $collection || $stateCollection || $propsCollection
|
|
47
|
-
if (hasComponentAttrs && (childProps || extendProps || children || childExtends)) {
|
|
48
|
-
const logErr = (parent || element)?.error
|
|
49
|
-
if (logErr) logErr.call(element, 'Sugar component includes params for builtin components', { verbose: true })
|
|
50
|
-
}
|
|
51
|
-
return !hasComponentAttrs || childProps || extendProps || children || childExtends
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export const extractComponentKeyFromKey = (key) => {
|
|
55
|
-
return key.includes('+')
|
|
56
|
-
? key.split('+') // get array of componentKeys
|
|
57
|
-
: key.includes('_')
|
|
58
|
-
? [key.split('_')[0]] // get component key split _
|
|
59
|
-
: key.includes('.') && !checkIfKeyIsComponent(key.split('.')[1])
|
|
60
|
-
? [key.split('.')[0]] // get component key split .
|
|
61
|
-
: [key]
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export const extendizeByKey = (element, parent, key) => {
|
|
65
|
-
const { context } = parent
|
|
66
|
-
const { tag, extend, childExtends } = element
|
|
67
|
-
const isSugar = checkIfSugar(element, parent, key)
|
|
68
|
-
const extendFromKey = extractComponentKeyFromKey(key)
|
|
69
|
-
const isExtendKeyComponent = context && context.components[extendFromKey]
|
|
70
|
-
if (element === isExtendKeyComponent) return element
|
|
71
|
-
else if (isSugar) {
|
|
72
|
-
const newElem = addAdditionalExtend(element.extends, {
|
|
73
|
-
extend: extendFromKey,
|
|
74
|
-
tag,
|
|
75
|
-
props: { ...element }
|
|
76
|
-
})
|
|
77
|
-
if (newElem.props.data) {
|
|
78
|
-
newElem.data = newElem.props.data
|
|
79
|
-
delete newElem.props.data
|
|
80
|
-
}
|
|
81
|
-
if (newElem.props.state) {
|
|
82
|
-
newElem.state = newElem.props.state
|
|
83
|
-
delete newElem.props.state
|
|
84
|
-
}
|
|
85
|
-
if (newElem.props.attr) {
|
|
86
|
-
newElem.attr = newElem.props.attr
|
|
87
|
-
delete newElem.props.attr
|
|
88
|
-
}
|
|
89
|
-
if (newElem.props.if) {
|
|
90
|
-
newElem.if = newElem.props.if
|
|
91
|
-
delete newElem.props.if
|
|
92
|
-
}
|
|
93
|
-
if (childExtends) newElem.childExtend = childExtends
|
|
94
|
-
return newElem
|
|
95
|
-
} else if (!extend || extend === true) {
|
|
96
|
-
return {
|
|
97
|
-
...element,
|
|
98
|
-
tag,
|
|
99
|
-
extend: extendFromKey
|
|
100
|
-
}
|
|
101
|
-
} else if (extend) {
|
|
102
|
-
return addAdditionalExtend(extendFromKey, element)
|
|
103
|
-
} else if (isFunction(element)) {
|
|
104
|
-
return {
|
|
105
|
-
extend: extendFromKey,
|
|
106
|
-
tag,
|
|
107
|
-
props: { ...exec(element, parent) }
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
13
|
export function getCapitalCaseKeys (obj) {
|
|
113
14
|
return Object.keys(obj).filter(key => /^[A-Z]/.test(key))
|
|
114
15
|
}
|
|
115
16
|
|
|
116
|
-
export
|
|
117
|
-
|
|
118
|
-
if (!childElems.length) return element
|
|
119
|
-
|
|
120
|
-
for (const i in childElems) {
|
|
121
|
-
const childKey = childElems[i]
|
|
122
|
-
const childElem = element[childKey]
|
|
123
|
-
const newChild = element.props[childKey]
|
|
124
|
-
|
|
125
|
-
const assignChild = (val) => {
|
|
126
|
-
element[childKey] = val
|
|
127
|
-
delete element.props[childKey]
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
if (newChild?.ignoreExtend) continue
|
|
131
|
-
if (newChild === null) assignChild(null)
|
|
132
|
-
else if (!childElem) assignChild(deepClone(newChild))
|
|
133
|
-
else {
|
|
134
|
-
const isSugarChildElem = checkIfSugar(childElem, parent, key)
|
|
135
|
-
if (isSugarChildElem) continue
|
|
136
|
-
assignChild({
|
|
137
|
-
extend: element[childKey],
|
|
138
|
-
props: newChild
|
|
139
|
-
})
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export const applyKeyComponentAsExtend = (element, parent, key) => {
|
|
145
|
-
return extendizeByKey(element, parent, key) || element
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
export const applyComponentFromContext = (element, parent, options) => {
|
|
149
|
-
const { context } = element
|
|
150
|
-
|
|
151
|
-
if (!context || !context.components) return
|
|
152
|
-
|
|
153
|
-
const { components } = context
|
|
154
|
-
const { extend } = element
|
|
155
|
-
const execExtend = exec(extend, element)
|
|
156
|
-
if (isString(execExtend)) {
|
|
157
|
-
const componentExists = components[execExtend] || components['smbls.' + execExtend]
|
|
158
|
-
if (componentExists) element.extend = componentExists
|
|
159
|
-
else {
|
|
160
|
-
if ((ENV === 'test' || ENV === 'development') && options.verbose) {
|
|
161
|
-
console.warn(execExtend, 'is not in library', components, element)
|
|
162
|
-
console.warn('replacing with ', {})
|
|
163
|
-
}
|
|
164
|
-
element.extend = {}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export const isVariant = (param) => {
|
|
170
|
-
if (!isString(param)) return
|
|
171
|
-
const firstCharKey = param.slice(0, 1)
|
|
172
|
-
// return (firstCharKey === '.' || firstCharKey === '$')
|
|
173
|
-
return (firstCharKey === '.')
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
export const hasVariantProp = (element) => {
|
|
177
|
-
const { props } = element
|
|
178
|
-
if (isObject(props) && isString(props.variant)) return true
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
export const getChildrenComponentsByKey = (key, el) => {
|
|
182
|
-
if (key === el.key || el.__ref.__componentKey === key) {
|
|
183
|
-
return el
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
// Check if the prop is "extend" and it's either a string or an array
|
|
187
|
-
if (el.extend) {
|
|
188
|
-
// Add the value of the extend key to the result array
|
|
189
|
-
const foundString = isString(el.extend) && el.extend === key
|
|
190
|
-
const foundInArray = isArray(el.extend) && el.extend.filter(v => v === key).length
|
|
191
|
-
if (foundString || foundInArray) return el
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
if (el.parent && el.parent.childExtend) {
|
|
195
|
-
// Add the value of the extend key to the result array
|
|
196
|
-
const foundString = isString(el.parent.childExtend) && el.parent.childExtend === key
|
|
197
|
-
const foundInArray = isArray(el.parent.childExtend) && el.parent.childExtend.filter(v => v === key).length
|
|
198
|
-
if (foundString || foundInArray) return el
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
export const getExtendsInElement = (obj) => {
|
|
203
|
-
let result = []
|
|
204
|
-
|
|
205
|
-
function traverse (o) {
|
|
206
|
-
for (const key in o) {
|
|
207
|
-
if (Object.hasOwnProperty.call(o, key)) {
|
|
208
|
-
// Check if the key starts with a capital letter and exclude keys like @mobileL, $propsCollection
|
|
209
|
-
if (checkIfKeyIsComponent(key)) {
|
|
210
|
-
result.push(key)
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
// Check if the key is "extend" and it's either a string or an array
|
|
214
|
-
if (key === 'extend' || key === 'extends') {
|
|
215
|
-
// Add the value of the extend key to the result array
|
|
216
|
-
if (typeof o[key] === 'string') {
|
|
217
|
-
result.push(o[key])
|
|
218
|
-
} else if (Array.isArray(o[key])) {
|
|
219
|
-
result = result.concat(o[key])
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// If the property is an object, traverse it
|
|
224
|
-
if (typeof o[key] === 'object' && o[key] !== null) {
|
|
225
|
-
traverse(o[key])
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
traverse(obj)
|
|
232
|
-
return result
|
|
17
|
+
export function getSpreadChildren (obj) {
|
|
18
|
+
return Object.keys(obj).filter(key => /^\d+$/.test(key))
|
|
233
19
|
}
|
|
234
20
|
|
|
235
|
-
export
|
|
236
|
-
const {
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
} else ref.contentElementKey = 'content'
|
|
241
|
-
if (contentElementKey !== 'content') opts.contentElementKey = 'content'
|
|
242
|
-
return ref.contentElementKey
|
|
21
|
+
export function isContextComponent (element, parent, passedKey) {
|
|
22
|
+
const { context } = parent || {}
|
|
23
|
+
const [extendsKey] = createExtendsFromKeys(passedKey)
|
|
24
|
+
const key = passedKey || extendsKey
|
|
25
|
+
return context?.components?.[key] || context?.pages?.[key]
|
|
243
26
|
}
|
package/cookie.js
CHANGED
|
@@ -3,19 +3,18 @@
|
|
|
3
3
|
import { isUndefined } from './types.js'
|
|
4
4
|
import { document } from './globals.js'
|
|
5
5
|
|
|
6
|
-
export const isMobile = (() =>
|
|
7
|
-
? false
|
|
8
|
-
: /Mobi/.test(navigator.userAgent))()
|
|
6
|
+
export const isMobile = (() =>
|
|
7
|
+
typeof navigator === 'undefined' ? false : /Mobi/.test(navigator.userAgent))()
|
|
9
8
|
|
|
10
9
|
export const setCookie = (cname, cvalue, exdays = 365) => {
|
|
11
10
|
if (isUndefined(document) || isUndefined(document.cookie)) return
|
|
12
11
|
const d = new Date()
|
|
13
|
-
d.setTime(d.getTime() +
|
|
12
|
+
d.setTime(d.getTime() + exdays * 24 * 60 * 60 * 1000)
|
|
14
13
|
const expires = `expires=${d.toUTCString()}`
|
|
15
14
|
document.cookie = `${cname}=${cvalue};${expires};path=/`
|
|
16
15
|
}
|
|
17
16
|
|
|
18
|
-
export const getCookie =
|
|
17
|
+
export const getCookie = cname => {
|
|
19
18
|
if (isUndefined(document) || isUndefined(document.cookie)) return
|
|
20
19
|
const name = `${cname}=`
|
|
21
20
|
const decodedCookie = decodeURIComponent(document.cookie)
|
|
@@ -28,29 +27,34 @@ export const getCookie = (cname) => {
|
|
|
28
27
|
return ''
|
|
29
28
|
}
|
|
30
29
|
|
|
31
|
-
export const removeCookie =
|
|
30
|
+
export const removeCookie = cname => {
|
|
32
31
|
if (isUndefined(document) || isUndefined(document.cookie)) return
|
|
33
32
|
document.cookie = cname + '=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'
|
|
34
33
|
}
|
|
35
|
-
|
|
36
34
|
/**
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
35
|
+
* Load item from the localStorage
|
|
36
|
+
*
|
|
37
|
+
* @param key -- string to identify the storage item
|
|
38
|
+
* @returns {*} -- parsed data or undefined
|
|
39
|
+
*/
|
|
41
40
|
export function getLocalStorage (key) {
|
|
42
|
-
|
|
41
|
+
if (!window.localStorage) {
|
|
42
|
+
return undefined
|
|
43
|
+
}
|
|
43
44
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
45
|
+
const item = window.localStorage.getItem(key)
|
|
46
|
+
|
|
47
|
+
if (item === null) {
|
|
48
|
+
return undefined
|
|
48
49
|
}
|
|
49
50
|
|
|
50
|
-
|
|
51
|
-
return
|
|
51
|
+
try {
|
|
52
|
+
return JSON.parse(item)
|
|
53
|
+
} catch (e) {
|
|
54
|
+
return undefined
|
|
52
55
|
}
|
|
53
56
|
}
|
|
57
|
+
|
|
54
58
|
/**
|
|
55
59
|
* Save the data to window.localStorage
|
|
56
60
|
*
|
|
@@ -58,11 +62,10 @@ export function getLocalStorage (key) {
|
|
|
58
62
|
* @param data - the data to save
|
|
59
63
|
*/
|
|
60
64
|
export function setLocalStorage (key, data) {
|
|
61
|
-
if (data
|
|
62
|
-
|
|
63
|
-
window.localStorage.setItem(key, JSON.stringify(data))
|
|
64
|
-
} else {
|
|
65
|
-
window.localStorage.setItem(key, data)
|
|
66
|
-
}
|
|
65
|
+
if (!window.localStorage || data === undefined || data === null) {
|
|
66
|
+
return
|
|
67
67
|
}
|
|
68
|
+
|
|
69
|
+
const value = typeof data === 'object' ? JSON.stringify(data) : data
|
|
70
|
+
window.localStorage.setItem(key, value)
|
|
68
71
|
}
|
package/dist/cjs/array.js
CHANGED
|
@@ -19,6 +19,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
19
19
|
var array_exports = {};
|
|
20
20
|
__export(array_exports, {
|
|
21
21
|
addItemAfterEveryElement: () => addItemAfterEveryElement,
|
|
22
|
+
addProtoToArray: () => addProtoToArray,
|
|
22
23
|
arrayContainsOtherArray: () => arrayContainsOtherArray,
|
|
23
24
|
arraysEqual: () => arraysEqual,
|
|
24
25
|
checkIfStringIsInArray: () => checkIfStringIsInArray,
|
|
@@ -28,13 +29,13 @@ __export(array_exports, {
|
|
|
28
29
|
filterArraysFast: () => filterArraysFast,
|
|
29
30
|
getFrequencyInArray: () => getFrequencyInArray,
|
|
30
31
|
joinArrays: () => joinArrays,
|
|
31
|
-
|
|
32
|
-
mergeArray: () => mergeArray,
|
|
32
|
+
removeDuplicatesInArray: () => removeDuplicatesInArray,
|
|
33
33
|
removeFromArray: () => removeFromArray,
|
|
34
34
|
removeValueFromArray: () => removeValueFromArray,
|
|
35
35
|
removeValueFromArrayAll: () => removeValueFromArrayAll,
|
|
36
36
|
reorderArrayByValues: () => reorderArrayByValues,
|
|
37
|
-
swapItemsInArray: () => swapItemsInArray
|
|
37
|
+
swapItemsInArray: () => swapItemsInArray,
|
|
38
|
+
unstackArrayOfObjects: () => unstackArrayOfObjects
|
|
38
39
|
});
|
|
39
40
|
module.exports = __toCommonJS(array_exports);
|
|
40
41
|
var import_object = require("./object.js");
|
|
@@ -48,31 +49,29 @@ const getFrequencyInArray = (arr, value) => {
|
|
|
48
49
|
}, 0);
|
|
49
50
|
};
|
|
50
51
|
const removeFromArray = (arr, index) => {
|
|
51
|
-
if ((0, import_types.isString)(index))
|
|
52
|
-
index = parseInt(index);
|
|
52
|
+
if ((0, import_types.isString)(index)) index = parseInt(index);
|
|
53
53
|
if ((0, import_types.isNumber)(index)) {
|
|
54
54
|
if (index < 0 || index >= arr.length || isNaN(index)) {
|
|
55
55
|
throw new Error("Invalid index");
|
|
56
56
|
}
|
|
57
57
|
arr.splice(index, 1);
|
|
58
|
-
} else if ((0, import_types.isArray)(index)) {
|
|
59
|
-
index.forEach((idx) => removeFromArray(arr, idx));
|
|
60
58
|
} else {
|
|
61
59
|
throw new Error("Invalid index");
|
|
62
60
|
}
|
|
63
61
|
return arr;
|
|
64
62
|
};
|
|
65
63
|
const swapItemsInArray = (arr, i, j) => {
|
|
64
|
+
;
|
|
66
65
|
[arr[i], arr[j]] = [arr[j], arr[i]];
|
|
67
66
|
};
|
|
68
67
|
const joinArrays = (...arrays) => {
|
|
69
68
|
return [].concat(...arrays);
|
|
70
69
|
};
|
|
71
|
-
const
|
|
72
|
-
return arr.reduce(
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
70
|
+
const unstackArrayOfObjects = (arr, exclude = []) => {
|
|
71
|
+
return arr.reduce(
|
|
72
|
+
(a, c) => (0, import_object.deepMerge)(a, (0, import_object.deepClone)(c, { exclude }), exclude),
|
|
73
|
+
{}
|
|
74
|
+
);
|
|
76
75
|
};
|
|
77
76
|
const cutArrayBeforeValue = (arr, value) => {
|
|
78
77
|
const index = arr.indexOf(value);
|
|
@@ -82,8 +81,7 @@ const cutArrayBeforeValue = (arr, value) => {
|
|
|
82
81
|
return arr;
|
|
83
82
|
};
|
|
84
83
|
const cutArrayAfterValue = (arr, value) => {
|
|
85
|
-
if (!(0, import_types.isArray)(arr))
|
|
86
|
-
return;
|
|
84
|
+
if (!(0, import_types.isArray)(arr)) return;
|
|
87
85
|
const index = arr.indexOf(value);
|
|
88
86
|
if (index !== -1) {
|
|
89
87
|
return arr.slice(index + 1);
|
|
@@ -142,7 +140,23 @@ const filterArraysFast = (sourceArr, excludeArr) => {
|
|
|
142
140
|
return sourceArr.filter((item) => !excludeSet.has(item));
|
|
143
141
|
};
|
|
144
142
|
const checkIfStringIsInArray = (string, arr) => {
|
|
145
|
-
if (!string)
|
|
146
|
-
return;
|
|
143
|
+
if (!string) return;
|
|
147
144
|
return arr.filter((v) => string.includes(v)).length;
|
|
148
145
|
};
|
|
146
|
+
const removeDuplicatesInArray = (arr) => {
|
|
147
|
+
if (!(0, import_types.isArray)(arr)) return arr;
|
|
148
|
+
return [...new Set(arr)];
|
|
149
|
+
};
|
|
150
|
+
const addProtoToArray = (state, proto) => {
|
|
151
|
+
for (const key in proto) {
|
|
152
|
+
Object.defineProperty(state, key, {
|
|
153
|
+
value: proto[key],
|
|
154
|
+
enumerable: false,
|
|
155
|
+
// Set this to true if you want the method to appear in for...in loops
|
|
156
|
+
configurable: true,
|
|
157
|
+
// Set this to true if you want to allow redefining/removing the property later
|
|
158
|
+
writable: true
|
|
159
|
+
// Set this to true if you want to allow changing the function later
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var cache_exports = {};
|
|
20
|
+
__export(cache_exports, {
|
|
21
|
+
OPTIONS: () => OPTIONS,
|
|
22
|
+
cache: () => cache
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(cache_exports);
|
|
25
|
+
const cache = {};
|
|
26
|
+
const OPTIONS = {};
|