@sequencemedia/dupe 0.0.0 → 0.0.2
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/index.d.mts +1 -1
- package/index.mjs +47 -3
- package/package.json +16 -15
package/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
type ArrayLiteralType = unknown[] | never[]
|
|
2
2
|
type ObjectLiteralType = Record<PropertyKey, unknown> | Record<PropertyKey, never>
|
|
3
3
|
|
|
4
|
-
type ValueType = string | number | ArrayLiteralType | ObjectLiteralType | null | undefined
|
|
4
|
+
type ValueType = string | number | ArrayLiteralType | ObjectLiteralType | Buffer | null | undefined
|
|
5
5
|
|
|
6
6
|
export default function dupe (v: ValueType | ValueType[]): ValueType | ValueType[]
|
package/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @typedef {Record<PropertyKey, unknown> | Record<PropertyKey, never>} ObjectLiteralType
|
|
5
5
|
*
|
|
6
|
-
* @typedef {string | number | ArrayLiteralType | ObjectLiteralType | null | undefined} ValueType
|
|
6
|
+
* @typedef {string | number | ArrayLiteralType | ObjectLiteralType | Buffer | null | undefined} ValueType
|
|
7
7
|
*
|
|
8
8
|
* @typedef {WeakMap<WeakKey, ArrayLiteralType | ObjectLiteralType>} WeakMapType
|
|
9
9
|
*/
|
|
@@ -21,7 +21,7 @@ function isArray (v) {
|
|
|
21
21
|
* @returns {boolean}
|
|
22
22
|
*/
|
|
23
23
|
function isObject (v) {
|
|
24
|
-
return (v || false) instanceof Object && !Array.isArray(v)
|
|
24
|
+
return (v || false) instanceof Object && !Array.isArray(v) && !Buffer.isBuffer(v)
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
/**
|
|
@@ -37,9 +37,28 @@ function isFunction (v) {
|
|
|
37
37
|
* @returns {boolean}
|
|
38
38
|
*/
|
|
39
39
|
function isPrimitive (v) {
|
|
40
|
-
return !
|
|
40
|
+
return !(
|
|
41
|
+
isObject(v) ||
|
|
42
|
+
isArray(v) ||
|
|
43
|
+
isFunction(v) ||
|
|
44
|
+
isBuffer(v)
|
|
45
|
+
)
|
|
41
46
|
}
|
|
42
47
|
|
|
48
|
+
/**
|
|
49
|
+
* @param {ValueType | ValueType[]} v
|
|
50
|
+
* @returns {boolean}
|
|
51
|
+
*/
|
|
52
|
+
function isBuffer (v) {
|
|
53
|
+
return Buffer.isBuffer(v)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* function isArrayBuffer (v) {
|
|
58
|
+
* return v instanceof ArrayBuffer
|
|
59
|
+
* }
|
|
60
|
+
*/
|
|
61
|
+
|
|
43
62
|
/**
|
|
44
63
|
* @param {ArrayLiteralType} v
|
|
45
64
|
* @param {WeakMapType} weakMap
|
|
@@ -66,6 +85,18 @@ function getObject (v, weakMap) {
|
|
|
66
85
|
return Object.assign(o, Object.fromEntries(Object.entries(v).map(getMapEntries(weakMap))))
|
|
67
86
|
}
|
|
68
87
|
|
|
88
|
+
/**
|
|
89
|
+
* @param {Buffer} v
|
|
90
|
+
* @param {WeakMapType} weakMap
|
|
91
|
+
* @returns {Buffer}
|
|
92
|
+
*/
|
|
93
|
+
function getBuffer (v, weakMap) {
|
|
94
|
+
const b = Buffer.from(v)
|
|
95
|
+
|
|
96
|
+
weakMap.set(v, b)
|
|
97
|
+
return b
|
|
98
|
+
}
|
|
99
|
+
|
|
69
100
|
/**
|
|
70
101
|
* @param {WeakMapType} weakMap
|
|
71
102
|
* @returns {(a: ArrayLiteralType, v: ValueType | ValueType[]) => ArrayLiteralType}
|
|
@@ -96,6 +127,11 @@ function getReduceArray (weakMap) {
|
|
|
96
127
|
a.push(getObject(v, weakMap))
|
|
97
128
|
return a
|
|
98
129
|
}
|
|
130
|
+
|
|
131
|
+
if (isBuffer(v)) {
|
|
132
|
+
a.push(getBuffer(v, weakMap))
|
|
133
|
+
return a
|
|
134
|
+
}
|
|
99
135
|
}
|
|
100
136
|
}
|
|
101
137
|
|
|
@@ -122,6 +158,10 @@ function getMapEntries (weakMap) {
|
|
|
122
158
|
if (isObject(v)) {
|
|
123
159
|
return [k, getObject(v, weakMap)]
|
|
124
160
|
}
|
|
161
|
+
|
|
162
|
+
if (isBuffer(v)) {
|
|
163
|
+
return [k, getBuffer(v, weakMap)]
|
|
164
|
+
}
|
|
125
165
|
}
|
|
126
166
|
}
|
|
127
167
|
|
|
@@ -141,4 +181,8 @@ export default function toDuplicate (v) {
|
|
|
141
181
|
if (isObject(v)) {
|
|
142
182
|
return getObject(v, new WeakMap())
|
|
143
183
|
}
|
|
184
|
+
|
|
185
|
+
if (isBuffer(v)) {
|
|
186
|
+
return getBuffer(v, new WeakMap())
|
|
187
|
+
}
|
|
144
188
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sequencemedia/dupe",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"keywords": [
|
|
5
|
+
"dupe",
|
|
6
|
+
"duplicate",
|
|
7
|
+
"clone",
|
|
8
|
+
"deep clone",
|
|
9
|
+
"deep"
|
|
10
|
+
],
|
|
4
11
|
"main": "./index.mjs",
|
|
5
12
|
"type": "module",
|
|
6
13
|
"types": "./index.d.mts",
|
|
@@ -9,32 +16,26 @@
|
|
|
9
16
|
"email": "sequencemedia@sequencemedia.net",
|
|
10
17
|
"url": "https://sequencemedia.net"
|
|
11
18
|
},
|
|
12
|
-
"keywords": [
|
|
13
|
-
"dupe",
|
|
14
|
-
"duplicate",
|
|
15
|
-
"clone",
|
|
16
|
-
"deep clone",
|
|
17
|
-
"deep"
|
|
18
|
-
],
|
|
19
19
|
"license": "ISC",
|
|
20
20
|
"scripts": {
|
|
21
21
|
"lint": "eslint .",
|
|
22
22
|
"lint:fix": "npm run lint -- --fix",
|
|
23
|
+
"prepare": "husky",
|
|
23
24
|
"test": "cross-env NODE_ENV=test mocha test --recursive"
|
|
24
25
|
},
|
|
25
26
|
"dependencies": {
|
|
26
|
-
"
|
|
27
|
-
"chai": "^5.1.2",
|
|
28
|
-
"D": "^1.0.0",
|
|
29
|
-
"debug": "^4.4.0",
|
|
30
|
-
"mocha": "^11.0.1"
|
|
27
|
+
"debug": "^4.4.0"
|
|
31
28
|
},
|
|
32
29
|
"devDependencies": {
|
|
30
|
+
"chai": "^5.1.2",
|
|
31
|
+
"mocha": "^11.0.1",
|
|
33
32
|
"@babel/core": "^7.26.0",
|
|
34
33
|
"@babel/preset-env": "^7.26.0",
|
|
35
|
-
"@sequencemedia/eslint-config-standard": "^0.2.
|
|
36
|
-
"@sequencemedia/eslint-config-typescript": "^0.1.
|
|
34
|
+
"@sequencemedia/eslint-config-standard": "^0.2.2",
|
|
35
|
+
"@sequencemedia/eslint-config-typescript": "^0.1.2",
|
|
37
36
|
"@types/debug": "^4.1.12",
|
|
37
|
+
"@types/mocha": "^10.0.10",
|
|
38
|
+
"@types/node": "^22.10.1",
|
|
38
39
|
"core-js": "^3.39.0",
|
|
39
40
|
"cross-env": "^7.0.3",
|
|
40
41
|
"eslint": "^9.16.0",
|