@weapp-core/shared 1.0.2 → 1.0.3
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/dist/index.cjs +1 -380
- package/dist/index.js +3 -389
- package/package.json +4 -1
package/dist/index.cjs
CHANGED
|
@@ -40,385 +40,6 @@ var init_cjs_shims = __esm({
|
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
-
// ../../node_modules/.pnpm/object-hash@3.0.0/node_modules/object-hash/index.js
|
|
44
|
-
var require_object_hash = __commonJS({
|
|
45
|
-
"../../node_modules/.pnpm/object-hash@3.0.0/node_modules/object-hash/index.js"(exports2, module2) {
|
|
46
|
-
"use strict";
|
|
47
|
-
init_cjs_shims();
|
|
48
|
-
var crypto = require("crypto");
|
|
49
|
-
exports2 = module2.exports = objectHash2;
|
|
50
|
-
function objectHash2(object, options) {
|
|
51
|
-
options = applyDefaults(object, options);
|
|
52
|
-
return hash(object, options);
|
|
53
|
-
}
|
|
54
|
-
exports2.sha1 = function(object) {
|
|
55
|
-
return objectHash2(object);
|
|
56
|
-
};
|
|
57
|
-
exports2.keys = function(object) {
|
|
58
|
-
return objectHash2(object, { excludeValues: true, algorithm: "sha1", encoding: "hex" });
|
|
59
|
-
};
|
|
60
|
-
exports2.MD5 = function(object) {
|
|
61
|
-
return objectHash2(object, { algorithm: "md5", encoding: "hex" });
|
|
62
|
-
};
|
|
63
|
-
exports2.keysMD5 = function(object) {
|
|
64
|
-
return objectHash2(object, { algorithm: "md5", encoding: "hex", excludeValues: true });
|
|
65
|
-
};
|
|
66
|
-
var hashes = crypto.getHashes ? crypto.getHashes().slice() : ["sha1", "md5"];
|
|
67
|
-
hashes.push("passthrough");
|
|
68
|
-
var encodings = ["buffer", "hex", "binary", "base64"];
|
|
69
|
-
function applyDefaults(object, sourceOptions) {
|
|
70
|
-
sourceOptions = sourceOptions || {};
|
|
71
|
-
var options = {};
|
|
72
|
-
options.algorithm = sourceOptions.algorithm || "sha1";
|
|
73
|
-
options.encoding = sourceOptions.encoding || "hex";
|
|
74
|
-
options.excludeValues = sourceOptions.excludeValues ? true : false;
|
|
75
|
-
options.algorithm = options.algorithm.toLowerCase();
|
|
76
|
-
options.encoding = options.encoding.toLowerCase();
|
|
77
|
-
options.ignoreUnknown = sourceOptions.ignoreUnknown !== true ? false : true;
|
|
78
|
-
options.respectType = sourceOptions.respectType === false ? false : true;
|
|
79
|
-
options.respectFunctionNames = sourceOptions.respectFunctionNames === false ? false : true;
|
|
80
|
-
options.respectFunctionProperties = sourceOptions.respectFunctionProperties === false ? false : true;
|
|
81
|
-
options.unorderedArrays = sourceOptions.unorderedArrays !== true ? false : true;
|
|
82
|
-
options.unorderedSets = sourceOptions.unorderedSets === false ? false : true;
|
|
83
|
-
options.unorderedObjects = sourceOptions.unorderedObjects === false ? false : true;
|
|
84
|
-
options.replacer = sourceOptions.replacer || void 0;
|
|
85
|
-
options.excludeKeys = sourceOptions.excludeKeys || void 0;
|
|
86
|
-
if (typeof object === "undefined") {
|
|
87
|
-
throw new Error("Object argument required.");
|
|
88
|
-
}
|
|
89
|
-
for (var i = 0; i < hashes.length; ++i) {
|
|
90
|
-
if (hashes[i].toLowerCase() === options.algorithm.toLowerCase()) {
|
|
91
|
-
options.algorithm = hashes[i];
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
if (hashes.indexOf(options.algorithm) === -1) {
|
|
95
|
-
throw new Error('Algorithm "' + options.algorithm + '" not supported. supported values: ' + hashes.join(", "));
|
|
96
|
-
}
|
|
97
|
-
if (encodings.indexOf(options.encoding) === -1 && options.algorithm !== "passthrough") {
|
|
98
|
-
throw new Error('Encoding "' + options.encoding + '" not supported. supported values: ' + encodings.join(", "));
|
|
99
|
-
}
|
|
100
|
-
return options;
|
|
101
|
-
}
|
|
102
|
-
function isNativeFunction(f) {
|
|
103
|
-
if (typeof f !== "function") {
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
var exp = /^function\s+\w*\s*\(\s*\)\s*{\s+\[native code\]\s+}$/i;
|
|
107
|
-
return exp.exec(Function.prototype.toString.call(f)) != null;
|
|
108
|
-
}
|
|
109
|
-
function hash(object, options) {
|
|
110
|
-
var hashingStream;
|
|
111
|
-
if (options.algorithm !== "passthrough") {
|
|
112
|
-
hashingStream = crypto.createHash(options.algorithm);
|
|
113
|
-
} else {
|
|
114
|
-
hashingStream = new PassThrough();
|
|
115
|
-
}
|
|
116
|
-
if (typeof hashingStream.write === "undefined") {
|
|
117
|
-
hashingStream.write = hashingStream.update;
|
|
118
|
-
hashingStream.end = hashingStream.update;
|
|
119
|
-
}
|
|
120
|
-
var hasher = typeHasher(options, hashingStream);
|
|
121
|
-
hasher.dispatch(object);
|
|
122
|
-
if (!hashingStream.update) {
|
|
123
|
-
hashingStream.end("");
|
|
124
|
-
}
|
|
125
|
-
if (hashingStream.digest) {
|
|
126
|
-
return hashingStream.digest(options.encoding === "buffer" ? void 0 : options.encoding);
|
|
127
|
-
}
|
|
128
|
-
var buf = hashingStream.read();
|
|
129
|
-
if (options.encoding === "buffer") {
|
|
130
|
-
return buf;
|
|
131
|
-
}
|
|
132
|
-
return buf.toString(options.encoding);
|
|
133
|
-
}
|
|
134
|
-
exports2.writeToStream = function(object, options, stream) {
|
|
135
|
-
if (typeof stream === "undefined") {
|
|
136
|
-
stream = options;
|
|
137
|
-
options = {};
|
|
138
|
-
}
|
|
139
|
-
options = applyDefaults(object, options);
|
|
140
|
-
return typeHasher(options, stream).dispatch(object);
|
|
141
|
-
};
|
|
142
|
-
function typeHasher(options, writeTo, context) {
|
|
143
|
-
context = context || [];
|
|
144
|
-
var write = function(str) {
|
|
145
|
-
if (writeTo.update) {
|
|
146
|
-
return writeTo.update(str, "utf8");
|
|
147
|
-
} else {
|
|
148
|
-
return writeTo.write(str, "utf8");
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
return {
|
|
152
|
-
dispatch: function(value) {
|
|
153
|
-
if (options.replacer) {
|
|
154
|
-
value = options.replacer(value);
|
|
155
|
-
}
|
|
156
|
-
var type = typeof value;
|
|
157
|
-
if (value === null) {
|
|
158
|
-
type = "null";
|
|
159
|
-
}
|
|
160
|
-
return this["_" + type](value);
|
|
161
|
-
},
|
|
162
|
-
_object: function(object) {
|
|
163
|
-
var pattern = /\[object (.*)\]/i;
|
|
164
|
-
var objString = Object.prototype.toString.call(object);
|
|
165
|
-
var objType = pattern.exec(objString);
|
|
166
|
-
if (!objType) {
|
|
167
|
-
objType = "unknown:[" + objString + "]";
|
|
168
|
-
} else {
|
|
169
|
-
objType = objType[1];
|
|
170
|
-
}
|
|
171
|
-
objType = objType.toLowerCase();
|
|
172
|
-
var objectNumber = null;
|
|
173
|
-
if ((objectNumber = context.indexOf(object)) >= 0) {
|
|
174
|
-
return this.dispatch("[CIRCULAR:" + objectNumber + "]");
|
|
175
|
-
} else {
|
|
176
|
-
context.push(object);
|
|
177
|
-
}
|
|
178
|
-
if (typeof Buffer !== "undefined" && Buffer.isBuffer && Buffer.isBuffer(object)) {
|
|
179
|
-
write("buffer:");
|
|
180
|
-
return write(object);
|
|
181
|
-
}
|
|
182
|
-
if (objType !== "object" && objType !== "function" && objType !== "asyncfunction") {
|
|
183
|
-
if (this["_" + objType]) {
|
|
184
|
-
this["_" + objType](object);
|
|
185
|
-
} else if (options.ignoreUnknown) {
|
|
186
|
-
return write("[" + objType + "]");
|
|
187
|
-
} else {
|
|
188
|
-
throw new Error('Unknown object type "' + objType + '"');
|
|
189
|
-
}
|
|
190
|
-
} else {
|
|
191
|
-
var keys = Object.keys(object);
|
|
192
|
-
if (options.unorderedObjects) {
|
|
193
|
-
keys = keys.sort();
|
|
194
|
-
}
|
|
195
|
-
if (options.respectType !== false && !isNativeFunction(object)) {
|
|
196
|
-
keys.splice(0, 0, "prototype", "__proto__", "constructor");
|
|
197
|
-
}
|
|
198
|
-
if (options.excludeKeys) {
|
|
199
|
-
keys = keys.filter(function(key) {
|
|
200
|
-
return !options.excludeKeys(key);
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
write("object:" + keys.length + ":");
|
|
204
|
-
var self = this;
|
|
205
|
-
return keys.forEach(function(key) {
|
|
206
|
-
self.dispatch(key);
|
|
207
|
-
write(":");
|
|
208
|
-
if (!options.excludeValues) {
|
|
209
|
-
self.dispatch(object[key]);
|
|
210
|
-
}
|
|
211
|
-
write(",");
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
},
|
|
215
|
-
_array: function(arr, unordered) {
|
|
216
|
-
unordered = typeof unordered !== "undefined" ? unordered : options.unorderedArrays !== false;
|
|
217
|
-
var self = this;
|
|
218
|
-
write("array:" + arr.length + ":");
|
|
219
|
-
if (!unordered || arr.length <= 1) {
|
|
220
|
-
return arr.forEach(function(entry) {
|
|
221
|
-
return self.dispatch(entry);
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
var contextAdditions = [];
|
|
225
|
-
var entries = arr.map(function(entry) {
|
|
226
|
-
var strm = new PassThrough();
|
|
227
|
-
var localContext = context.slice();
|
|
228
|
-
var hasher = typeHasher(options, strm, localContext);
|
|
229
|
-
hasher.dispatch(entry);
|
|
230
|
-
contextAdditions = contextAdditions.concat(localContext.slice(context.length));
|
|
231
|
-
return strm.read().toString();
|
|
232
|
-
});
|
|
233
|
-
context = context.concat(contextAdditions);
|
|
234
|
-
entries.sort();
|
|
235
|
-
return this._array(entries, false);
|
|
236
|
-
},
|
|
237
|
-
_date: function(date) {
|
|
238
|
-
return write("date:" + date.toJSON());
|
|
239
|
-
},
|
|
240
|
-
_symbol: function(sym) {
|
|
241
|
-
return write("symbol:" + sym.toString());
|
|
242
|
-
},
|
|
243
|
-
_error: function(err) {
|
|
244
|
-
return write("error:" + err.toString());
|
|
245
|
-
},
|
|
246
|
-
_boolean: function(bool) {
|
|
247
|
-
return write("bool:" + bool.toString());
|
|
248
|
-
},
|
|
249
|
-
_string: function(string) {
|
|
250
|
-
write("string:" + string.length + ":");
|
|
251
|
-
write(string.toString());
|
|
252
|
-
},
|
|
253
|
-
_function: function(fn) {
|
|
254
|
-
write("fn:");
|
|
255
|
-
if (isNativeFunction(fn)) {
|
|
256
|
-
this.dispatch("[native]");
|
|
257
|
-
} else {
|
|
258
|
-
this.dispatch(fn.toString());
|
|
259
|
-
}
|
|
260
|
-
if (options.respectFunctionNames !== false) {
|
|
261
|
-
this.dispatch("function-name:" + String(fn.name));
|
|
262
|
-
}
|
|
263
|
-
if (options.respectFunctionProperties) {
|
|
264
|
-
this._object(fn);
|
|
265
|
-
}
|
|
266
|
-
},
|
|
267
|
-
_number: function(number) {
|
|
268
|
-
return write("number:" + number.toString());
|
|
269
|
-
},
|
|
270
|
-
_xml: function(xml) {
|
|
271
|
-
return write("xml:" + xml.toString());
|
|
272
|
-
},
|
|
273
|
-
_null: function() {
|
|
274
|
-
return write("Null");
|
|
275
|
-
},
|
|
276
|
-
_undefined: function() {
|
|
277
|
-
return write("Undefined");
|
|
278
|
-
},
|
|
279
|
-
_regexp: function(regex) {
|
|
280
|
-
return write("regex:" + regex.toString());
|
|
281
|
-
},
|
|
282
|
-
_uint8array: function(arr) {
|
|
283
|
-
write("uint8array:");
|
|
284
|
-
return this.dispatch(Array.prototype.slice.call(arr));
|
|
285
|
-
},
|
|
286
|
-
_uint8clampedarray: function(arr) {
|
|
287
|
-
write("uint8clampedarray:");
|
|
288
|
-
return this.dispatch(Array.prototype.slice.call(arr));
|
|
289
|
-
},
|
|
290
|
-
_int8array: function(arr) {
|
|
291
|
-
write("int8array:");
|
|
292
|
-
return this.dispatch(Array.prototype.slice.call(arr));
|
|
293
|
-
},
|
|
294
|
-
_uint16array: function(arr) {
|
|
295
|
-
write("uint16array:");
|
|
296
|
-
return this.dispatch(Array.prototype.slice.call(arr));
|
|
297
|
-
},
|
|
298
|
-
_int16array: function(arr) {
|
|
299
|
-
write("int16array:");
|
|
300
|
-
return this.dispatch(Array.prototype.slice.call(arr));
|
|
301
|
-
},
|
|
302
|
-
_uint32array: function(arr) {
|
|
303
|
-
write("uint32array:");
|
|
304
|
-
return this.dispatch(Array.prototype.slice.call(arr));
|
|
305
|
-
},
|
|
306
|
-
_int32array: function(arr) {
|
|
307
|
-
write("int32array:");
|
|
308
|
-
return this.dispatch(Array.prototype.slice.call(arr));
|
|
309
|
-
},
|
|
310
|
-
_float32array: function(arr) {
|
|
311
|
-
write("float32array:");
|
|
312
|
-
return this.dispatch(Array.prototype.slice.call(arr));
|
|
313
|
-
},
|
|
314
|
-
_float64array: function(arr) {
|
|
315
|
-
write("float64array:");
|
|
316
|
-
return this.dispatch(Array.prototype.slice.call(arr));
|
|
317
|
-
},
|
|
318
|
-
_arraybuffer: function(arr) {
|
|
319
|
-
write("arraybuffer:");
|
|
320
|
-
return this.dispatch(new Uint8Array(arr));
|
|
321
|
-
},
|
|
322
|
-
_url: function(url) {
|
|
323
|
-
return write("url:" + url.toString(), "utf8");
|
|
324
|
-
},
|
|
325
|
-
_map: function(map) {
|
|
326
|
-
write("map:");
|
|
327
|
-
var arr = Array.from(map);
|
|
328
|
-
return this._array(arr, options.unorderedSets !== false);
|
|
329
|
-
},
|
|
330
|
-
_set: function(set) {
|
|
331
|
-
write("set:");
|
|
332
|
-
var arr = Array.from(set);
|
|
333
|
-
return this._array(arr, options.unorderedSets !== false);
|
|
334
|
-
},
|
|
335
|
-
_file: function(file) {
|
|
336
|
-
write("file:");
|
|
337
|
-
return this.dispatch([file.name, file.size, file.type, file.lastModfied]);
|
|
338
|
-
},
|
|
339
|
-
_blob: function() {
|
|
340
|
-
if (options.ignoreUnknown) {
|
|
341
|
-
return write("[blob]");
|
|
342
|
-
}
|
|
343
|
-
throw Error('Hashing Blob objects is currently not supported\n(see https://github.com/puleos/object-hash/issues/26)\nUse "options.replacer" or "options.ignoreUnknown"\n');
|
|
344
|
-
},
|
|
345
|
-
_domwindow: function() {
|
|
346
|
-
return write("domwindow");
|
|
347
|
-
},
|
|
348
|
-
_bigint: function(number) {
|
|
349
|
-
return write("bigint:" + number.toString());
|
|
350
|
-
},
|
|
351
|
-
/* Node.js standard native objects */
|
|
352
|
-
_process: function() {
|
|
353
|
-
return write("process");
|
|
354
|
-
},
|
|
355
|
-
_timer: function() {
|
|
356
|
-
return write("timer");
|
|
357
|
-
},
|
|
358
|
-
_pipe: function() {
|
|
359
|
-
return write("pipe");
|
|
360
|
-
},
|
|
361
|
-
_tcp: function() {
|
|
362
|
-
return write("tcp");
|
|
363
|
-
},
|
|
364
|
-
_udp: function() {
|
|
365
|
-
return write("udp");
|
|
366
|
-
},
|
|
367
|
-
_tty: function() {
|
|
368
|
-
return write("tty");
|
|
369
|
-
},
|
|
370
|
-
_statwatcher: function() {
|
|
371
|
-
return write("statwatcher");
|
|
372
|
-
},
|
|
373
|
-
_securecontext: function() {
|
|
374
|
-
return write("securecontext");
|
|
375
|
-
},
|
|
376
|
-
_connection: function() {
|
|
377
|
-
return write("connection");
|
|
378
|
-
},
|
|
379
|
-
_zlib: function() {
|
|
380
|
-
return write("zlib");
|
|
381
|
-
},
|
|
382
|
-
_context: function() {
|
|
383
|
-
return write("context");
|
|
384
|
-
},
|
|
385
|
-
_nodescript: function() {
|
|
386
|
-
return write("nodescript");
|
|
387
|
-
},
|
|
388
|
-
_httpparser: function() {
|
|
389
|
-
return write("httpparser");
|
|
390
|
-
},
|
|
391
|
-
_dataview: function() {
|
|
392
|
-
return write("dataview");
|
|
393
|
-
},
|
|
394
|
-
_signal: function() {
|
|
395
|
-
return write("signal");
|
|
396
|
-
},
|
|
397
|
-
_fsevent: function() {
|
|
398
|
-
return write("fsevent");
|
|
399
|
-
},
|
|
400
|
-
_tlswrap: function() {
|
|
401
|
-
return write("tlswrap");
|
|
402
|
-
}
|
|
403
|
-
};
|
|
404
|
-
}
|
|
405
|
-
function PassThrough() {
|
|
406
|
-
return {
|
|
407
|
-
buf: "",
|
|
408
|
-
write: function(b) {
|
|
409
|
-
this.buf += b;
|
|
410
|
-
},
|
|
411
|
-
end: function(b) {
|
|
412
|
-
this.buf += b;
|
|
413
|
-
},
|
|
414
|
-
read: function() {
|
|
415
|
-
return this.buf;
|
|
416
|
-
}
|
|
417
|
-
};
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
});
|
|
421
|
-
|
|
422
43
|
// ../../node_modules/.pnpm/isobject@3.0.1/node_modules/isobject/index.js
|
|
423
44
|
var require_isobject = __commonJS({
|
|
424
45
|
"../../node_modules/.pnpm/isobject@3.0.1/node_modules/isobject/index.js"(exports2, module2) {
|
|
@@ -776,7 +397,7 @@ var defuArrayFn = createDefu((object, key, currentValue) => {
|
|
|
776
397
|
});
|
|
777
398
|
|
|
778
399
|
// src/index.ts
|
|
779
|
-
var import_object_hash = __toESM(
|
|
400
|
+
var import_object_hash = __toESM(require("object-hash"), 1);
|
|
780
401
|
var import_get_value = __toESM(require_get_value(), 1);
|
|
781
402
|
var import_set_value = __toESM(require_set_value(), 1);
|
|
782
403
|
function escapeStringRegexp(str) {
|
package/dist/index.js
CHANGED
|
@@ -4,16 +4,10 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
4
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
5
|
var __getProtoOf = Object.getPrototypeOf;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
8
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
9
|
-
}) : x)(function(x) {
|
|
10
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
11
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
12
|
-
});
|
|
13
7
|
var __esm = (fn, res) => function __init() {
|
|
14
8
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
15
9
|
};
|
|
16
|
-
var __commonJS = (cb, mod) => function
|
|
10
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
17
11
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
18
12
|
};
|
|
19
13
|
var __copyProps = (to, from, except, desc) => {
|
|
@@ -40,385 +34,6 @@ var init_esm_shims = __esm({
|
|
|
40
34
|
}
|
|
41
35
|
});
|
|
42
36
|
|
|
43
|
-
// ../../node_modules/.pnpm/object-hash@3.0.0/node_modules/object-hash/index.js
|
|
44
|
-
var require_object_hash = __commonJS({
|
|
45
|
-
"../../node_modules/.pnpm/object-hash@3.0.0/node_modules/object-hash/index.js"(exports, module) {
|
|
46
|
-
"use strict";
|
|
47
|
-
init_esm_shims();
|
|
48
|
-
var crypto = __require("crypto");
|
|
49
|
-
exports = module.exports = objectHash2;
|
|
50
|
-
function objectHash2(object, options) {
|
|
51
|
-
options = applyDefaults(object, options);
|
|
52
|
-
return hash(object, options);
|
|
53
|
-
}
|
|
54
|
-
exports.sha1 = function(object) {
|
|
55
|
-
return objectHash2(object);
|
|
56
|
-
};
|
|
57
|
-
exports.keys = function(object) {
|
|
58
|
-
return objectHash2(object, { excludeValues: true, algorithm: "sha1", encoding: "hex" });
|
|
59
|
-
};
|
|
60
|
-
exports.MD5 = function(object) {
|
|
61
|
-
return objectHash2(object, { algorithm: "md5", encoding: "hex" });
|
|
62
|
-
};
|
|
63
|
-
exports.keysMD5 = function(object) {
|
|
64
|
-
return objectHash2(object, { algorithm: "md5", encoding: "hex", excludeValues: true });
|
|
65
|
-
};
|
|
66
|
-
var hashes = crypto.getHashes ? crypto.getHashes().slice() : ["sha1", "md5"];
|
|
67
|
-
hashes.push("passthrough");
|
|
68
|
-
var encodings = ["buffer", "hex", "binary", "base64"];
|
|
69
|
-
function applyDefaults(object, sourceOptions) {
|
|
70
|
-
sourceOptions = sourceOptions || {};
|
|
71
|
-
var options = {};
|
|
72
|
-
options.algorithm = sourceOptions.algorithm || "sha1";
|
|
73
|
-
options.encoding = sourceOptions.encoding || "hex";
|
|
74
|
-
options.excludeValues = sourceOptions.excludeValues ? true : false;
|
|
75
|
-
options.algorithm = options.algorithm.toLowerCase();
|
|
76
|
-
options.encoding = options.encoding.toLowerCase();
|
|
77
|
-
options.ignoreUnknown = sourceOptions.ignoreUnknown !== true ? false : true;
|
|
78
|
-
options.respectType = sourceOptions.respectType === false ? false : true;
|
|
79
|
-
options.respectFunctionNames = sourceOptions.respectFunctionNames === false ? false : true;
|
|
80
|
-
options.respectFunctionProperties = sourceOptions.respectFunctionProperties === false ? false : true;
|
|
81
|
-
options.unorderedArrays = sourceOptions.unorderedArrays !== true ? false : true;
|
|
82
|
-
options.unorderedSets = sourceOptions.unorderedSets === false ? false : true;
|
|
83
|
-
options.unorderedObjects = sourceOptions.unorderedObjects === false ? false : true;
|
|
84
|
-
options.replacer = sourceOptions.replacer || void 0;
|
|
85
|
-
options.excludeKeys = sourceOptions.excludeKeys || void 0;
|
|
86
|
-
if (typeof object === "undefined") {
|
|
87
|
-
throw new Error("Object argument required.");
|
|
88
|
-
}
|
|
89
|
-
for (var i = 0; i < hashes.length; ++i) {
|
|
90
|
-
if (hashes[i].toLowerCase() === options.algorithm.toLowerCase()) {
|
|
91
|
-
options.algorithm = hashes[i];
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
if (hashes.indexOf(options.algorithm) === -1) {
|
|
95
|
-
throw new Error('Algorithm "' + options.algorithm + '" not supported. supported values: ' + hashes.join(", "));
|
|
96
|
-
}
|
|
97
|
-
if (encodings.indexOf(options.encoding) === -1 && options.algorithm !== "passthrough") {
|
|
98
|
-
throw new Error('Encoding "' + options.encoding + '" not supported. supported values: ' + encodings.join(", "));
|
|
99
|
-
}
|
|
100
|
-
return options;
|
|
101
|
-
}
|
|
102
|
-
function isNativeFunction(f) {
|
|
103
|
-
if (typeof f !== "function") {
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
var exp = /^function\s+\w*\s*\(\s*\)\s*{\s+\[native code\]\s+}$/i;
|
|
107
|
-
return exp.exec(Function.prototype.toString.call(f)) != null;
|
|
108
|
-
}
|
|
109
|
-
function hash(object, options) {
|
|
110
|
-
var hashingStream;
|
|
111
|
-
if (options.algorithm !== "passthrough") {
|
|
112
|
-
hashingStream = crypto.createHash(options.algorithm);
|
|
113
|
-
} else {
|
|
114
|
-
hashingStream = new PassThrough();
|
|
115
|
-
}
|
|
116
|
-
if (typeof hashingStream.write === "undefined") {
|
|
117
|
-
hashingStream.write = hashingStream.update;
|
|
118
|
-
hashingStream.end = hashingStream.update;
|
|
119
|
-
}
|
|
120
|
-
var hasher = typeHasher(options, hashingStream);
|
|
121
|
-
hasher.dispatch(object);
|
|
122
|
-
if (!hashingStream.update) {
|
|
123
|
-
hashingStream.end("");
|
|
124
|
-
}
|
|
125
|
-
if (hashingStream.digest) {
|
|
126
|
-
return hashingStream.digest(options.encoding === "buffer" ? void 0 : options.encoding);
|
|
127
|
-
}
|
|
128
|
-
var buf = hashingStream.read();
|
|
129
|
-
if (options.encoding === "buffer") {
|
|
130
|
-
return buf;
|
|
131
|
-
}
|
|
132
|
-
return buf.toString(options.encoding);
|
|
133
|
-
}
|
|
134
|
-
exports.writeToStream = function(object, options, stream) {
|
|
135
|
-
if (typeof stream === "undefined") {
|
|
136
|
-
stream = options;
|
|
137
|
-
options = {};
|
|
138
|
-
}
|
|
139
|
-
options = applyDefaults(object, options);
|
|
140
|
-
return typeHasher(options, stream).dispatch(object);
|
|
141
|
-
};
|
|
142
|
-
function typeHasher(options, writeTo, context) {
|
|
143
|
-
context = context || [];
|
|
144
|
-
var write = function(str) {
|
|
145
|
-
if (writeTo.update) {
|
|
146
|
-
return writeTo.update(str, "utf8");
|
|
147
|
-
} else {
|
|
148
|
-
return writeTo.write(str, "utf8");
|
|
149
|
-
}
|
|
150
|
-
};
|
|
151
|
-
return {
|
|
152
|
-
dispatch: function(value) {
|
|
153
|
-
if (options.replacer) {
|
|
154
|
-
value = options.replacer(value);
|
|
155
|
-
}
|
|
156
|
-
var type = typeof value;
|
|
157
|
-
if (value === null) {
|
|
158
|
-
type = "null";
|
|
159
|
-
}
|
|
160
|
-
return this["_" + type](value);
|
|
161
|
-
},
|
|
162
|
-
_object: function(object) {
|
|
163
|
-
var pattern = /\[object (.*)\]/i;
|
|
164
|
-
var objString = Object.prototype.toString.call(object);
|
|
165
|
-
var objType = pattern.exec(objString);
|
|
166
|
-
if (!objType) {
|
|
167
|
-
objType = "unknown:[" + objString + "]";
|
|
168
|
-
} else {
|
|
169
|
-
objType = objType[1];
|
|
170
|
-
}
|
|
171
|
-
objType = objType.toLowerCase();
|
|
172
|
-
var objectNumber = null;
|
|
173
|
-
if ((objectNumber = context.indexOf(object)) >= 0) {
|
|
174
|
-
return this.dispatch("[CIRCULAR:" + objectNumber + "]");
|
|
175
|
-
} else {
|
|
176
|
-
context.push(object);
|
|
177
|
-
}
|
|
178
|
-
if (typeof Buffer !== "undefined" && Buffer.isBuffer && Buffer.isBuffer(object)) {
|
|
179
|
-
write("buffer:");
|
|
180
|
-
return write(object);
|
|
181
|
-
}
|
|
182
|
-
if (objType !== "object" && objType !== "function" && objType !== "asyncfunction") {
|
|
183
|
-
if (this["_" + objType]) {
|
|
184
|
-
this["_" + objType](object);
|
|
185
|
-
} else if (options.ignoreUnknown) {
|
|
186
|
-
return write("[" + objType + "]");
|
|
187
|
-
} else {
|
|
188
|
-
throw new Error('Unknown object type "' + objType + '"');
|
|
189
|
-
}
|
|
190
|
-
} else {
|
|
191
|
-
var keys = Object.keys(object);
|
|
192
|
-
if (options.unorderedObjects) {
|
|
193
|
-
keys = keys.sort();
|
|
194
|
-
}
|
|
195
|
-
if (options.respectType !== false && !isNativeFunction(object)) {
|
|
196
|
-
keys.splice(0, 0, "prototype", "__proto__", "constructor");
|
|
197
|
-
}
|
|
198
|
-
if (options.excludeKeys) {
|
|
199
|
-
keys = keys.filter(function(key) {
|
|
200
|
-
return !options.excludeKeys(key);
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
write("object:" + keys.length + ":");
|
|
204
|
-
var self = this;
|
|
205
|
-
return keys.forEach(function(key) {
|
|
206
|
-
self.dispatch(key);
|
|
207
|
-
write(":");
|
|
208
|
-
if (!options.excludeValues) {
|
|
209
|
-
self.dispatch(object[key]);
|
|
210
|
-
}
|
|
211
|
-
write(",");
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
},
|
|
215
|
-
_array: function(arr, unordered) {
|
|
216
|
-
unordered = typeof unordered !== "undefined" ? unordered : options.unorderedArrays !== false;
|
|
217
|
-
var self = this;
|
|
218
|
-
write("array:" + arr.length + ":");
|
|
219
|
-
if (!unordered || arr.length <= 1) {
|
|
220
|
-
return arr.forEach(function(entry) {
|
|
221
|
-
return self.dispatch(entry);
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
var contextAdditions = [];
|
|
225
|
-
var entries = arr.map(function(entry) {
|
|
226
|
-
var strm = new PassThrough();
|
|
227
|
-
var localContext = context.slice();
|
|
228
|
-
var hasher = typeHasher(options, strm, localContext);
|
|
229
|
-
hasher.dispatch(entry);
|
|
230
|
-
contextAdditions = contextAdditions.concat(localContext.slice(context.length));
|
|
231
|
-
return strm.read().toString();
|
|
232
|
-
});
|
|
233
|
-
context = context.concat(contextAdditions);
|
|
234
|
-
entries.sort();
|
|
235
|
-
return this._array(entries, false);
|
|
236
|
-
},
|
|
237
|
-
_date: function(date) {
|
|
238
|
-
return write("date:" + date.toJSON());
|
|
239
|
-
},
|
|
240
|
-
_symbol: function(sym) {
|
|
241
|
-
return write("symbol:" + sym.toString());
|
|
242
|
-
},
|
|
243
|
-
_error: function(err) {
|
|
244
|
-
return write("error:" + err.toString());
|
|
245
|
-
},
|
|
246
|
-
_boolean: function(bool) {
|
|
247
|
-
return write("bool:" + bool.toString());
|
|
248
|
-
},
|
|
249
|
-
_string: function(string) {
|
|
250
|
-
write("string:" + string.length + ":");
|
|
251
|
-
write(string.toString());
|
|
252
|
-
},
|
|
253
|
-
_function: function(fn) {
|
|
254
|
-
write("fn:");
|
|
255
|
-
if (isNativeFunction(fn)) {
|
|
256
|
-
this.dispatch("[native]");
|
|
257
|
-
} else {
|
|
258
|
-
this.dispatch(fn.toString());
|
|
259
|
-
}
|
|
260
|
-
if (options.respectFunctionNames !== false) {
|
|
261
|
-
this.dispatch("function-name:" + String(fn.name));
|
|
262
|
-
}
|
|
263
|
-
if (options.respectFunctionProperties) {
|
|
264
|
-
this._object(fn);
|
|
265
|
-
}
|
|
266
|
-
},
|
|
267
|
-
_number: function(number) {
|
|
268
|
-
return write("number:" + number.toString());
|
|
269
|
-
},
|
|
270
|
-
_xml: function(xml) {
|
|
271
|
-
return write("xml:" + xml.toString());
|
|
272
|
-
},
|
|
273
|
-
_null: function() {
|
|
274
|
-
return write("Null");
|
|
275
|
-
},
|
|
276
|
-
_undefined: function() {
|
|
277
|
-
return write("Undefined");
|
|
278
|
-
},
|
|
279
|
-
_regexp: function(regex) {
|
|
280
|
-
return write("regex:" + regex.toString());
|
|
281
|
-
},
|
|
282
|
-
_uint8array: function(arr) {
|
|
283
|
-
write("uint8array:");
|
|
284
|
-
return this.dispatch(Array.prototype.slice.call(arr));
|
|
285
|
-
},
|
|
286
|
-
_uint8clampedarray: function(arr) {
|
|
287
|
-
write("uint8clampedarray:");
|
|
288
|
-
return this.dispatch(Array.prototype.slice.call(arr));
|
|
289
|
-
},
|
|
290
|
-
_int8array: function(arr) {
|
|
291
|
-
write("int8array:");
|
|
292
|
-
return this.dispatch(Array.prototype.slice.call(arr));
|
|
293
|
-
},
|
|
294
|
-
_uint16array: function(arr) {
|
|
295
|
-
write("uint16array:");
|
|
296
|
-
return this.dispatch(Array.prototype.slice.call(arr));
|
|
297
|
-
},
|
|
298
|
-
_int16array: function(arr) {
|
|
299
|
-
write("int16array:");
|
|
300
|
-
return this.dispatch(Array.prototype.slice.call(arr));
|
|
301
|
-
},
|
|
302
|
-
_uint32array: function(arr) {
|
|
303
|
-
write("uint32array:");
|
|
304
|
-
return this.dispatch(Array.prototype.slice.call(arr));
|
|
305
|
-
},
|
|
306
|
-
_int32array: function(arr) {
|
|
307
|
-
write("int32array:");
|
|
308
|
-
return this.dispatch(Array.prototype.slice.call(arr));
|
|
309
|
-
},
|
|
310
|
-
_float32array: function(arr) {
|
|
311
|
-
write("float32array:");
|
|
312
|
-
return this.dispatch(Array.prototype.slice.call(arr));
|
|
313
|
-
},
|
|
314
|
-
_float64array: function(arr) {
|
|
315
|
-
write("float64array:");
|
|
316
|
-
return this.dispatch(Array.prototype.slice.call(arr));
|
|
317
|
-
},
|
|
318
|
-
_arraybuffer: function(arr) {
|
|
319
|
-
write("arraybuffer:");
|
|
320
|
-
return this.dispatch(new Uint8Array(arr));
|
|
321
|
-
},
|
|
322
|
-
_url: function(url) {
|
|
323
|
-
return write("url:" + url.toString(), "utf8");
|
|
324
|
-
},
|
|
325
|
-
_map: function(map) {
|
|
326
|
-
write("map:");
|
|
327
|
-
var arr = Array.from(map);
|
|
328
|
-
return this._array(arr, options.unorderedSets !== false);
|
|
329
|
-
},
|
|
330
|
-
_set: function(set) {
|
|
331
|
-
write("set:");
|
|
332
|
-
var arr = Array.from(set);
|
|
333
|
-
return this._array(arr, options.unorderedSets !== false);
|
|
334
|
-
},
|
|
335
|
-
_file: function(file) {
|
|
336
|
-
write("file:");
|
|
337
|
-
return this.dispatch([file.name, file.size, file.type, file.lastModfied]);
|
|
338
|
-
},
|
|
339
|
-
_blob: function() {
|
|
340
|
-
if (options.ignoreUnknown) {
|
|
341
|
-
return write("[blob]");
|
|
342
|
-
}
|
|
343
|
-
throw Error('Hashing Blob objects is currently not supported\n(see https://github.com/puleos/object-hash/issues/26)\nUse "options.replacer" or "options.ignoreUnknown"\n');
|
|
344
|
-
},
|
|
345
|
-
_domwindow: function() {
|
|
346
|
-
return write("domwindow");
|
|
347
|
-
},
|
|
348
|
-
_bigint: function(number) {
|
|
349
|
-
return write("bigint:" + number.toString());
|
|
350
|
-
},
|
|
351
|
-
/* Node.js standard native objects */
|
|
352
|
-
_process: function() {
|
|
353
|
-
return write("process");
|
|
354
|
-
},
|
|
355
|
-
_timer: function() {
|
|
356
|
-
return write("timer");
|
|
357
|
-
},
|
|
358
|
-
_pipe: function() {
|
|
359
|
-
return write("pipe");
|
|
360
|
-
},
|
|
361
|
-
_tcp: function() {
|
|
362
|
-
return write("tcp");
|
|
363
|
-
},
|
|
364
|
-
_udp: function() {
|
|
365
|
-
return write("udp");
|
|
366
|
-
},
|
|
367
|
-
_tty: function() {
|
|
368
|
-
return write("tty");
|
|
369
|
-
},
|
|
370
|
-
_statwatcher: function() {
|
|
371
|
-
return write("statwatcher");
|
|
372
|
-
},
|
|
373
|
-
_securecontext: function() {
|
|
374
|
-
return write("securecontext");
|
|
375
|
-
},
|
|
376
|
-
_connection: function() {
|
|
377
|
-
return write("connection");
|
|
378
|
-
},
|
|
379
|
-
_zlib: function() {
|
|
380
|
-
return write("zlib");
|
|
381
|
-
},
|
|
382
|
-
_context: function() {
|
|
383
|
-
return write("context");
|
|
384
|
-
},
|
|
385
|
-
_nodescript: function() {
|
|
386
|
-
return write("nodescript");
|
|
387
|
-
},
|
|
388
|
-
_httpparser: function() {
|
|
389
|
-
return write("httpparser");
|
|
390
|
-
},
|
|
391
|
-
_dataview: function() {
|
|
392
|
-
return write("dataview");
|
|
393
|
-
},
|
|
394
|
-
_signal: function() {
|
|
395
|
-
return write("signal");
|
|
396
|
-
},
|
|
397
|
-
_fsevent: function() {
|
|
398
|
-
return write("fsevent");
|
|
399
|
-
},
|
|
400
|
-
_tlswrap: function() {
|
|
401
|
-
return write("tlswrap");
|
|
402
|
-
}
|
|
403
|
-
};
|
|
404
|
-
}
|
|
405
|
-
function PassThrough() {
|
|
406
|
-
return {
|
|
407
|
-
buf: "",
|
|
408
|
-
write: function(b) {
|
|
409
|
-
this.buf += b;
|
|
410
|
-
},
|
|
411
|
-
end: function(b) {
|
|
412
|
-
this.buf += b;
|
|
413
|
-
},
|
|
414
|
-
read: function() {
|
|
415
|
-
return this.buf;
|
|
416
|
-
}
|
|
417
|
-
};
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
});
|
|
421
|
-
|
|
422
37
|
// ../../node_modules/.pnpm/isobject@3.0.1/node_modules/isobject/index.js
|
|
423
38
|
var require_isobject = __commonJS({
|
|
424
39
|
"../../node_modules/.pnpm/isobject@3.0.1/node_modules/isobject/index.js"(exports, module) {
|
|
@@ -762,9 +377,9 @@ var defuArrayFn = createDefu((object, key, currentValue) => {
|
|
|
762
377
|
});
|
|
763
378
|
|
|
764
379
|
// src/index.ts
|
|
765
|
-
var import_object_hash = __toESM(require_object_hash(), 1);
|
|
766
380
|
var import_get_value = __toESM(require_get_value(), 1);
|
|
767
381
|
var import_set_value = __toESM(require_set_value(), 1);
|
|
382
|
+
import objectHash from "object-hash";
|
|
768
383
|
function escapeStringRegexp(str) {
|
|
769
384
|
return str.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&").replace(/-/g, "\\x2d");
|
|
770
385
|
}
|
|
@@ -791,7 +406,6 @@ function isObject(x) {
|
|
|
791
406
|
return typeof x === "object" && x !== null;
|
|
792
407
|
}
|
|
793
408
|
var export_get = import_get_value.default;
|
|
794
|
-
var export_objectHash = import_object_hash.default;
|
|
795
409
|
var export_set = import_set_value.default;
|
|
796
410
|
export {
|
|
797
411
|
addExtension,
|
|
@@ -801,7 +415,7 @@ export {
|
|
|
801
415
|
escapeStringRegexp,
|
|
802
416
|
export_get as get,
|
|
803
417
|
isObject,
|
|
804
|
-
|
|
418
|
+
objectHash,
|
|
805
419
|
removeExtension,
|
|
806
420
|
export_set as set
|
|
807
421
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weapp-core/shared",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.3",
|
|
5
5
|
"description": "@weapp-core/shared",
|
|
6
6
|
"author": "ice breaker <1324318532@qq.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -28,6 +28,9 @@
|
|
|
28
28
|
"files": [
|
|
29
29
|
"dist"
|
|
30
30
|
],
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"object-hash": "^3.0.0"
|
|
33
|
+
},
|
|
31
34
|
"scripts": {
|
|
32
35
|
"dev": "tsup --watch --sourcemap",
|
|
33
36
|
"build": "tsup",
|