@based/utils 1.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.
Files changed (78) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +360 -0
  3. package/dist/src/base64.d.ts +2 -0
  4. package/dist/src/base64.js +74 -0
  5. package/dist/src/base64.js.map +1 -0
  6. package/dist/src/deepCopy.d.ts +4 -0
  7. package/dist/src/deepCopy.js +21 -0
  8. package/dist/src/deepCopy.js.map +1 -0
  9. package/dist/src/deepEqual.d.ts +2 -0
  10. package/dist/src/deepEqual.js +88 -0
  11. package/dist/src/deepEqual.js.map +1 -0
  12. package/dist/src/deepMerge.d.ts +2 -0
  13. package/dist/src/deepMerge.js +131 -0
  14. package/dist/src/deepMerge.js.map +1 -0
  15. package/dist/src/deflate.d.ts +1 -0
  16. package/dist/src/deflate.js +20 -0
  17. package/dist/src/deflate.js.map +1 -0
  18. package/dist/src/encoder/decode.d.ts +3 -0
  19. package/dist/src/encoder/decode.js +79 -0
  20. package/dist/src/encoder/decode.js.map +1 -0
  21. package/dist/src/encoder/encode.d.ts +3 -0
  22. package/dist/src/encoder/encode.js +103 -0
  23. package/dist/src/encoder/encode.js.map +1 -0
  24. package/dist/src/encoder/index.d.ts +10 -0
  25. package/dist/src/encoder/index.js +55 -0
  26. package/dist/src/encoder/index.js.map +1 -0
  27. package/dist/src/fastPrng.d.ts +1 -0
  28. package/dist/src/fastPrng.js +7 -0
  29. package/dist/src/fastPrng.js.map +1 -0
  30. package/dist/src/getType.d.ts +2 -0
  31. package/dist/src/getType.js +4 -0
  32. package/dist/src/getType.js.map +1 -0
  33. package/dist/src/index.d.ts +22 -0
  34. package/dist/src/index.js +23 -0
  35. package/dist/src/index.js.map +1 -0
  36. package/dist/src/isEmptyObject.d.ts +3 -0
  37. package/dist/src/isEmptyObject.js +7 -0
  38. package/dist/src/isEmptyObject.js.map +1 -0
  39. package/dist/src/isObject.d.ts +1 -0
  40. package/dist/src/isObject.js +4 -0
  41. package/dist/src/isObject.js.map +1 -0
  42. package/dist/src/isWinterTimeInEurope.d.ts +1 -0
  43. package/dist/src/isWinterTimeInEurope.js +25 -0
  44. package/dist/src/isWinterTimeInEurope.js.map +1 -0
  45. package/dist/src/longTimeOut.d.ts +1 -0
  46. package/dist/src/longTimeOut.js +20 -0
  47. package/dist/src/longTimeOut.js.map +1 -0
  48. package/dist/src/padding.d.ts +2 -0
  49. package/dist/src/padding.js +15 -0
  50. package/dist/src/padding.js.map +1 -0
  51. package/dist/src/path.d.ts +3 -0
  52. package/dist/src/path.js +41 -0
  53. package/dist/src/path.js.map +1 -0
  54. package/dist/src/query.d.ts +11 -0
  55. package/dist/src/query.js +142 -0
  56. package/dist/src/query.js.map +1 -0
  57. package/dist/src/queued.d.ts +113 -0
  58. package/dist/src/queued.js +126 -0
  59. package/dist/src/queued.js.map +1 -0
  60. package/dist/src/randomString.d.ts +12 -0
  61. package/dist/src/randomString.js +36 -0
  62. package/dist/src/randomString.js.map +1 -0
  63. package/dist/src/readStream.d.ts +5 -0
  64. package/dist/src/readStream.js +62 -0
  65. package/dist/src/readStream.js.map +1 -0
  66. package/dist/src/retry.d.ts +11 -0
  67. package/dist/src/retry.js +26 -0
  68. package/dist/src/retry.js.map +1 -0
  69. package/dist/src/timestamp.d.ts +1 -0
  70. package/dist/src/timestamp.js +71 -0
  71. package/dist/src/timestamp.js.map +1 -0
  72. package/dist/src/uint8.d.ts +31 -0
  73. package/dist/src/uint8.js +305 -0
  74. package/dist/src/uint8.js.map +1 -0
  75. package/dist/src/wait.d.ts +2 -0
  76. package/dist/src/wait.js +4 -0
  77. package/dist/src/wait.js.map +1 -0
  78. package/package.json +39 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 SAULX
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,360 @@
1
+ # utils
2
+
3
+ Saulx utils package
4
+
5
+ ## deepEqual
6
+
7
+ Compare objects
8
+
9
+ ```javascript
10
+ import { stringHash } from '@based/utils'
11
+ console.log(deepEqual({ a: { b: true } }, { a: { b: true } })) // true
12
+ ```
13
+
14
+ ## deepCopy
15
+
16
+ Create a deepcopy of objects
17
+
18
+ ```javascript
19
+ import { deepCopy } from '@based/utils'
20
+ console.log(deepCopy({ x: true }))
21
+ ```
22
+
23
+ ## deepMerge
24
+
25
+ Merge an object into another object, arrays are treated as new values
26
+
27
+ ```javascript
28
+ import { deepMerge } from '@based/utils'
29
+
30
+ const a = { x: { a: { c: true, x: [1, 2] } } }
31
+ const b = { y: true }
32
+ const c = { x: { a: { b: true, x: ['bla'] } } }
33
+
34
+ console.log(deepMerge(a, b))
35
+
36
+ console.log(deepMerge(a, b, c))
37
+
38
+ /*
39
+ Logs
40
+ {
41
+ x: { a: { b: true, c: true, x: ['bla']}},
42
+ y: true
43
+ }
44
+ */
45
+ ```
46
+
47
+ ## deepMergeArrays
48
+
49
+ Merge an object into another object, arrays are treated as objects
50
+
51
+ ```javascript
52
+ import { deepMergeArrays } from '@based/utils'
53
+ const a = { x: { a: { c: true, x: [1, 2, 3] } } }
54
+ const b = { y: true }
55
+ const c = { x: { a: { b: true, x: ['bla'] } } }
56
+
57
+ console.log(deepMergeArrays(a, b))
58
+
59
+ console.log(deepMergeArrays(a, b, c))
60
+
61
+ /*
62
+ Logs
63
+ {
64
+ x: { a: { b: true, c: true, x: ['bla', 2, 3]}},
65
+ y: true
66
+ }
67
+ */
68
+ ```
69
+
70
+ ## isObject
71
+
72
+ Checks if a variable is an object and not an array
73
+
74
+ ```javascript
75
+ import { isObject } from '@based/utils'
76
+ console.log(isObject({ x: true })) // true
77
+ console.log(isObject([1, 2, 3])) // false
78
+ ```
79
+
80
+ ## wait
81
+
82
+ Timeout in a promise, default is 100ms
83
+
84
+ ```javascript
85
+ import { wait } from '@based/utils'
86
+
87
+ const somethingAsync = async () => {
88
+ await wait() // 100ms
89
+ console.log('after 100ms')
90
+ await wait(1000)
91
+ console.log('after 1100ms')
92
+ }
93
+
94
+ somethingAsync()
95
+ ```
96
+
97
+ ## serializeQuery
98
+
99
+ Convert an object to a query string
100
+
101
+ ```javascript
102
+ import { serializeQuery } from '@based/utils'
103
+ const object = { bla: true, a: [1, 2, 3], b: { a: 1 }, c: ['a', 'b', 'c'] }
104
+ const queryString = serializeQuery(object)
105
+ console.log(queryString) // bla&a=[1,2,3]&b={"a":1}&c=a,b,c
106
+ ```
107
+
108
+ ## parseQuery
109
+
110
+ Convert a query string to an object
111
+
112
+ ```javascript
113
+ import { parseQuery } from '@based/utils'
114
+ const result = parseQuery('bla&a=[1,2,3]&b={"a":1}&c=a,b,c')
115
+ console.log(result) // { bla:true, a:[1,2,3], b:{a:1}, c:['a','b','c'] }
116
+ ```
117
+
118
+ ## readStream
119
+
120
+ Sink a read stream into a promise
121
+
122
+ ```javascript
123
+ import { readStream } from '@based/utils'
124
+ import fs from 'fs'
125
+
126
+ const aReadStream = fs.createReadStream('somefile')
127
+ const myResult = await readStream(aReadStream)
128
+ ```
129
+
130
+ ## toEnvVar
131
+
132
+ Convert a string to an env-variable safe name
133
+
134
+ ```javascript
135
+ import { toEnvVar } from '@based/utils'
136
+ const x = toEnvVar('@based/bla-bla-bla$_!')
137
+ console.log(x) // BASED_BLA_BLA_BLA
138
+ ```
139
+
140
+ ## stringToUtf8
141
+
142
+ Convert a string to a utf-8 Uint8 array
143
+
144
+ ```javascript
145
+ import { stringToUtf8 } from '@based/utils'
146
+ const utf8 = stringToUtf8('hello')
147
+ console.log(utf8) // [ 104, 101, 108, 108, 111 ]
148
+ ```
149
+
150
+ ## utf8ToString
151
+
152
+ Convert a utf8 Uint8 array to a string
153
+
154
+ ```javascript
155
+ import { utf8ToString } from '@based/utils'
156
+ // hello in utf-8
157
+ const utf8 = new Uint8Array([104, 101, 108, 108, 111])
158
+ const x = utf8ToString(utf8)
159
+ console.log(x) // hello
160
+ ```
161
+
162
+ ## encodeBase64
163
+
164
+ Convert utf-8 Uint8 array to a base64 string, allows converting 16byte chars.
165
+ (vs btoa where its not supported)
166
+
167
+ ```javascript
168
+ import { encodeBase64 } from '@based/utils'
169
+ // hello in utf-8
170
+ const utf8 = new Uint8Array([104, 101, 108, 108, 111])
171
+ const b64 = encodeBase64(utf8)
172
+ console.log(b64) // aGVsbG8=
173
+ ```
174
+
175
+ ## decodeBase64
176
+
177
+ Decode a base64 string to a utf-8 Uint8 array
178
+ (vs atob where its not supported)
179
+
180
+ ```javascript
181
+ import { decodeBase64 } from '@based/utils'
182
+ const utf8 = decodeBase64('aGVsbG8=)
183
+ console.log(b64) // [104, 101, 108, 108, 111]
184
+ ```
185
+
186
+ ## createEncoder
187
+
188
+ Create an encoder similair to `encodeUri` / `decodeUri` but with specific strings
189
+ Will use `[a-z]` and `[0-9]` as encoded variables
190
+
191
+ ```javascript
192
+ import { createEncoder } from '@based/utils'
193
+ const { encode, decode } = createEncoder(['🥹'], ['@'])
194
+ console.log(encode('hello 🥹')) // "hello @a"
195
+ ```
196
+
197
+ Can be used with larger strings
198
+
199
+ ```javascript
200
+ import { createEncoder } from '@based/utils'
201
+ const { encode, decode } = createEncoder(['hello'], ['@'])
202
+ console.log(encode('hello 🥹')) // "@a 🥹"
203
+ ```
204
+
205
+ ## padLeft
206
+
207
+ Add padding to a string
208
+
209
+ ```javascript
210
+ import { padLeft } from '@based/utils'
211
+ console.log(padLeft('a', 4, 'b')) // "bbba"
212
+ const y = padRight('a', 4, 'b')
213
+ t.is(y, 'abbb')
214
+ ```
215
+
216
+ ## padRight
217
+
218
+ Add padding to a string
219
+
220
+ ```javascript
221
+ import { padLeft } from '@based/utils'
222
+ console.log(padRight('a', 4, 'b')) // "abbb"
223
+ ```
224
+
225
+ ## queued
226
+
227
+ Pass any async function and queue it based on the arguments, also shares the function execution for the same args
228
+
229
+ _Accepts 10 arguments maximum_
230
+
231
+ ```javascript
232
+ import { queued, wait } from '@based/utils'
233
+
234
+ const myFn = queued(async (a: string) => {
235
+ await wait(1000)
236
+ return a + '!'
237
+ })
238
+
239
+ // will execute bla first then x
240
+ await Promise.all([
241
+ myFn('bla'),
242
+ myFn('x')
243
+ myFn('bla') // bla will be shared
244
+ ])
245
+ ```
246
+
247
+ ```javascript
248
+ import { queued, wait } from '@based/utils'
249
+
250
+ const myFn = queued(async (a: string) => {
251
+ await wait(1000)
252
+ return a + '!'
253
+ }, {
254
+ dedup: (a) => {
255
+ // choose the value to use for dedup (to share results)
256
+ return a
257
+ },
258
+ concurrency: 10 // max concurrency of 10
259
+ })
260
+
261
+ // will execute all at the same time (scince concurrency is 10)
262
+ // will only execute 'bla' once since it has the same arguments used in id
263
+ await Promise.all([
264
+ myFn('bla'),
265
+ myFn('x')
266
+ myFn('bla') // bla will be shared
267
+ ])
268
+ ```
269
+
270
+ ## getType
271
+
272
+ Returns a string with the operand/type of the javascrit primitive. Adds 'null' and 'array'.
273
+
274
+ ```javascript
275
+ getType('') // -> "string"
276
+ getType('this is a string') // -> "string"
277
+ getType(123) // -> "number"
278
+ getType(12.3) // -> "number"
279
+ getType(-12.3) // -> "number"
280
+ getType(-123) // -> "number"
281
+ getType(BigInt('1')) // -> "bigint"
282
+ getType(true) // -> "boolean"
283
+ getType(false) // -> "boolean"
284
+ getType(undefined) // -> "undefined"
285
+ getType({ a: 'wawa' }) // -> "object"
286
+ getType(() => {}) // -> "function"
287
+ getType([1, 2, 3]) // -> "array"
288
+ getType(null) // -> "null"
289
+ ```
290
+
291
+ ## walker
292
+
293
+ Generic structure walker. By default walks objects.
294
+
295
+ ```javascript
296
+ const result = []
297
+ await walk(objectToWalk, async (item, info) => {
298
+ result.push({
299
+ value: item,
300
+ name: info.name, // property name
301
+ path: info.path, // slash separated path in object
302
+ type: info.type, // operand type
303
+ })
304
+ }) // returns void
305
+ ```
306
+
307
+ By configuring the options you can walk any kind of structure
308
+
309
+ ```javascript
310
+ await walk(
311
+ objectToWalk, // starting target
312
+ itemFn, // function to run for each matched item
313
+ options: {
314
+ // check types for details
315
+ listFn, // function to list each path. Should return a list of items.
316
+ itemMatchFn, // function to choose which items to run itemFn on
317
+ recureseFn, // function to choose wchich items to recurse on
318
+ targetValidationFn, // function to validate starting path
319
+ previousPath, // prefix to add to paths
320
+ }
321
+ )
322
+ ```
323
+
324
+ ## nonRecursiveWalker
325
+
326
+ Generic object walker that does not use recursion.
327
+
328
+ ```javascript
329
+ const obj = {
330
+ a1: {
331
+ a1b1: {
332
+ a1b1c1: 'a1b1c1',
333
+ a1b1c2: {
334
+ a1b1c2d1: 'a1b1c2d1',
335
+ },
336
+ },
337
+ },
338
+ a2: 'a2',
339
+ a3: {
340
+ a3b1: 'a3b1',
341
+ },
342
+ }
343
+
344
+ nonRecursiveWalker(
345
+ obj, // Object to walk
346
+ (
347
+ target, // reference to matched property
348
+ path, // path as a string[]
349
+ type, // 0 for property, 1 for object
350
+ ) => {
351
+ if (path.join('.') === 'a1.a1b1') {
352
+ console.log('Object found type is 1')
353
+ }
354
+ if (path.join('.') === 'a2') {
355
+ console.log('Property found type is 0')
356
+ }
357
+ },
358
+ true, // also match objects
359
+ )
360
+ ```
@@ -0,0 +1,2 @@
1
+ export declare const decodeBase64: (base64String: string, nBlocksSize?: number) => Uint8Array;
2
+ export declare const encodeBase64: (utf8Array: Uint8Array) => string;
@@ -0,0 +1,74 @@
1
+ const b64ToUint6 = (nChr) => {
2
+ return nChr > 64 && nChr < 91
3
+ ? nChr - 65
4
+ : nChr > 96 && nChr < 123
5
+ ? nChr - 71
6
+ : nChr > 47 && nChr < 58
7
+ ? nChr + 4
8
+ : nChr === 43
9
+ ? 62
10
+ : nChr === 47
11
+ ? 63
12
+ : 0;
13
+ };
14
+ const uint6ToB64 = (nUint6) => {
15
+ return nUint6 < 26
16
+ ? nUint6 + 65
17
+ : nUint6 < 52
18
+ ? nUint6 + 71
19
+ : nUint6 < 62
20
+ ? nUint6 - 4
21
+ : nUint6 === 62
22
+ ? 43
23
+ : nUint6 === 63
24
+ ? 47
25
+ : 65;
26
+ };
27
+ export const decodeBase64 = (base64String, nBlocksSize) => {
28
+ // Only necessary if the base64 includes whitespace such as line breaks
29
+ const sB64Enc = base64String.replace(/[^A-Za-z0-9+/]/g, '');
30
+ const nInLen = sB64Enc.length;
31
+ const nOutLen = nBlocksSize
32
+ ? Math.ceil(((nInLen * 3 + 1) >> 2) / nBlocksSize) * nBlocksSize
33
+ : (nInLen * 3 + 1) >> 2;
34
+ const taBytes = new Uint8Array(nOutLen);
35
+ let nMod3;
36
+ let nMod4;
37
+ let nUint24 = 0;
38
+ let nOutIdx = 0;
39
+ for (let nInIdx = 0; nInIdx < nInLen; nInIdx++) {
40
+ nMod4 = nInIdx & 3;
41
+ nUint24 |= b64ToUint6(sB64Enc.charCodeAt(nInIdx)) << (6 * (3 - nMod4));
42
+ if (nMod4 === 3 || nInLen - nInIdx === 1) {
43
+ nMod3 = 0;
44
+ while (nMod3 < 3 && nOutIdx < nOutLen) {
45
+ taBytes[nOutIdx] = (nUint24 >>> ((16 >>> nMod3) & 24)) & 255;
46
+ nMod3++;
47
+ nOutIdx++;
48
+ }
49
+ nUint24 = 0;
50
+ }
51
+ }
52
+ return taBytes;
53
+ };
54
+ export const encodeBase64 = (utf8Array) => {
55
+ let nMod3 = 2;
56
+ let sB64Enc = '';
57
+ const nLen = utf8Array.length;
58
+ let nUint24 = 0;
59
+ for (let nIdx = 0; nIdx < nLen; nIdx++) {
60
+ nMod3 = nIdx % 3;
61
+ // To break your base64 into several 80-character lines, add:
62
+ // if (nIdx > 0 && ((nIdx * 4) / 3) % 76 === 0) {
63
+ // sB64Enc += "\r\n";
64
+ // }
65
+ nUint24 |= utf8Array[nIdx] << ((16 >>> nMod3) & 24);
66
+ if (nMod3 === 2 || utf8Array.length - nIdx === 1) {
67
+ sB64Enc += String.fromCodePoint(uint6ToB64((nUint24 >>> 18) & 63), uint6ToB64((nUint24 >>> 12) & 63), uint6ToB64((nUint24 >>> 6) & 63), uint6ToB64(nUint24 & 63));
68
+ nUint24 = 0;
69
+ }
70
+ }
71
+ return (sB64Enc.substring(0, sB64Enc.length - 2 + nMod3) +
72
+ (nMod3 === 2 ? '' : nMod3 === 1 ? '=' : '=='));
73
+ };
74
+ //# sourceMappingURL=base64.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base64.js","sourceRoot":"","sources":["../../src/base64.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,GAAG,CAAC,IAAY,EAAU,EAAE;IAC1C,OAAO,IAAI,GAAG,EAAE,IAAI,IAAI,GAAG,EAAE;QAC3B,CAAC,CAAC,IAAI,GAAG,EAAE;QACX,CAAC,CAAC,IAAI,GAAG,EAAE,IAAI,IAAI,GAAG,GAAG;YACzB,CAAC,CAAC,IAAI,GAAG,EAAE;YACX,CAAC,CAAC,IAAI,GAAG,EAAE,IAAI,IAAI,GAAG,EAAE;gBACxB,CAAC,CAAC,IAAI,GAAG,CAAC;gBACV,CAAC,CAAC,IAAI,KAAK,EAAE;oBACb,CAAC,CAA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,SAAS,CAAC,MAAM,GAAG,IAAI,KAAK,CAAC,EAAE,CAAC;YACjD,OAAO,IAAI,MAAM,CAAC,aAAa,CAC7B,UAAU,CAAC,CAAC,OAAO,KAAK,EAAE,CAAC,GAAG,EAAE,CAAC,EACjC,UAAU,CAAC,CAAC,OAAO,KAAK,EAAE,CAAC,GAAG,EAAE,CAAC,EACjC,UAAU,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,GAAG,EAAE,CAAC,EAChC,UAAU,CAAC,OAAO,GAAG,EAAE,CAAC,CACzB,CAAA;YACD,OAAO,GAAG,CAAC,CAAA;QACb,CAAC;IACH,CAAC;IACD,OAAO,CACL,OAAO,CAAC,SAAS,CAAC,CAAC,EAAE,OAAO,CAAC,MAAM,GAAG,CAAC,GAAG,KAAK,CAAC;QAChD,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAC9C,CAAA;AACH,CAAC,CAAA"}
@@ -0,0 +1,4 @@
1
+ declare const deepCopy: <T extends {
2
+ [key: string]: any | undefined;
3
+ } | (any | undefined)[]>(a: T) => T;
4
+ export default deepCopy;
@@ -0,0 +1,21 @@
1
+ const deepCopy = (a) => {
2
+ const r = (Array.isArray(a) ? [] : {});
3
+ for (const k in a) {
4
+ if (a[k] !== null && typeof a[k] === 'object') {
5
+ // @ts-ignore
6
+ if ('buffer' in a[k] && a[k].buffer instanceof ArrayBuffer) {
7
+ r[k] = a[k];
8
+ }
9
+ else {
10
+ // @ts-ignore
11
+ r[k] = deepCopy(a[k]);
12
+ }
13
+ }
14
+ else {
15
+ r[k] = a[k];
16
+ }
17
+ }
18
+ return r;
19
+ };
20
+ export default deepCopy;
21
+ //# sourceMappingURL=deepCopy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deepCopy.js","sourceRoot":"","sources":["../../src/deepCopy.ts"],"names":[],"mappings":"AAAA,MAAM,QAAQ,GAAG,CAGf,CAAI,EACD,EAAE;IACL,MAAM,CAAC,GAAS,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;IAC5C,KAAK,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;QAClB,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE,CAAC;YAC9C,aAAa;YACb,IAAI,QAAQ,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,YAAY,WAAW,EAAE,CAAC;gBAC3D,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;YACb,CAAC;iBAAM,CAAC;gBACN,aAAa;gBACb,CAAC,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;YACvB,CAAC;QACH,CAAC;aAAM,CAAC;YACN,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;QACb,CAAC;IACH,CAAC;IACD,OAAO,CAAC,CAAA;AACV,CAAC,CAAA;AAED,eAAe,QAAQ,CAAA"}
@@ -0,0 +1,2 @@
1
+ declare const deepEqual: (a: any, b: any) => boolean;
2
+ export default deepEqual;
@@ -0,0 +1,88 @@
1
+ const deepEqual = (a, b) => {
2
+ const typeA = typeof a;
3
+ const typeB = typeof b;
4
+ if (a === b)
5
+ return true;
6
+ if (typeA !== typeB)
7
+ return false;
8
+ if (a === null || b === null)
9
+ return false;
10
+ if (typeA !== 'object') {
11
+ if (typeA === 'function') {
12
+ if (a.toString() !== b.toString()) {
13
+ return false;
14
+ }
15
+ }
16
+ else if (a !== b) {
17
+ return false;
18
+ }
19
+ }
20
+ else {
21
+ if (Array.isArray(a)) {
22
+ if (Array.isArray(b)) {
23
+ const len = a.length;
24
+ if (len !== b.length) {
25
+ return false;
26
+ }
27
+ for (let i = 0; i < len; i++) {
28
+ const t = typeof a[i];
29
+ if (typeof b[i] !== t) {
30
+ return false;
31
+ }
32
+ else if (t === 'object') {
33
+ if (!deepEqual(a[i], b[i])) {
34
+ return false;
35
+ }
36
+ }
37
+ }
38
+ }
39
+ else {
40
+ return false;
41
+ }
42
+ }
43
+ if (a.checksum || b.checksum) {
44
+ if (a.checksum !== b.checksum) {
45
+ return false;
46
+ }
47
+ else {
48
+ return true;
49
+ }
50
+ }
51
+ let cnt = 0;
52
+ for (let key in a) {
53
+ if (!a.hasOwnProperty(key))
54
+ continue;
55
+ if (!b.hasOwnProperty(key))
56
+ return false;
57
+ const k = b[key];
58
+ const k1 = a[key];
59
+ if (k === void 0 && k1 !== void 0) {
60
+ return false;
61
+ }
62
+ const t = typeof k;
63
+ if (t !== typeof k1) {
64
+ return false;
65
+ }
66
+ else if (k && t === 'object') {
67
+ if (!deepEqual(k1, k)) {
68
+ return false;
69
+ }
70
+ }
71
+ else if (k !== k1) {
72
+ return false;
73
+ }
74
+ cnt++;
75
+ }
76
+ for (const _key in b) {
77
+ if (!b.hasOwnProperty(_key))
78
+ continue;
79
+ cnt--;
80
+ if (cnt < 0) {
81
+ return false;
82
+ }
83
+ }
84
+ }
85
+ return true;
86
+ };
87
+ export default deepEqual;
88
+ //# sourceMappingURL=deepEqual.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deepEqual.js","sourceRoot":"","sources":["../../src/deepEqual.ts"],"names":[],"mappings":"AAAA,MAAM,SAAS,GAAG,CAAC,CAAM,EAAE,CAAM,EAAW,EAAE;IAC5C,MAAM,KAAK,GAAG,OAAO,CAAC,CAAA;IACtB,MAAM,KAAK,GAAG,OAAO,CAAC,CAAA;IACtB,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAA;IACxB,IAAI,KAAK,KAAK,KAAK;QAAE,OAA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G,CAAC,EAAE,CAAC;gBACZ,OAAO,KAAK,CAAA;YACd,CAAC;QACH,CAAC;IACH,CAAC;IACD,OAAO,IAAI,CAAA;AACb,CAAC,CAAA;AAED,eAAe,SAAS,CAAA"}
@@ -0,0 +1,2 @@
1
+ export declare function deepMergeArrays(target: any, ...sources: any[]): any;
2
+ export declare function deepMerge(target: any, ...sources: any[]): any;