object-fingerprint 1.0.2 → 1.1.1
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.js +51 -39
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -11,29 +11,29 @@ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol
|
|
|
11
11
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
12
12
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
13
13
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } /*
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
var _getFingerprint = function _getFingerprint(object) {
|
|
14
|
+
* MIT License
|
|
15
|
+
*
|
|
16
|
+
* Copyright (c) 2023 Massimo Candela <https://massimocandela.com>
|
|
17
|
+
*
|
|
18
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
19
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
20
|
+
* in the Software without restriction, including without limitation the rights
|
|
21
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
22
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
23
|
+
* furnished to do so, subject to the following conditions:
|
|
24
|
+
*
|
|
25
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
26
|
+
* copies or substantial portions of the Software.
|
|
27
|
+
*
|
|
28
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
29
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
30
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
31
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
32
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
33
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
34
|
+
* SOFTWARE.
|
|
35
|
+
*/
|
|
36
|
+
var _getFingerprint = function _getFingerprint(object, algorithm) {
|
|
37
37
|
switch (_typeof(object)) {
|
|
38
38
|
case "object":
|
|
39
39
|
if (object == null) {
|
|
@@ -42,8 +42,12 @@ var _getFingerprint = function _getFingerprint(object) {
|
|
|
42
42
|
return "m:".concat(object.toISOString());
|
|
43
43
|
} else if (object instanceof Date) {
|
|
44
44
|
return "m:".concat((0, _moment["default"])(object).toISOString());
|
|
45
|
+
} else if (Array.isArray(object)) {
|
|
46
|
+
return "a:[".concat(object.map(function (i) {
|
|
47
|
+
return getObjectFingerprint(i, algorithm);
|
|
48
|
+
}), "]");
|
|
45
49
|
} else {
|
|
46
|
-
return "o:".concat(getObjectFingerprint(object));
|
|
50
|
+
return "o:".concat(getObjectFingerprint(object, algorithm));
|
|
47
51
|
}
|
|
48
52
|
case "boolean":
|
|
49
53
|
return "b:".concat(object ? "t" : "f");
|
|
@@ -57,23 +61,31 @@ var _getFingerprint = function _getFingerprint(object) {
|
|
|
57
61
|
return "u";
|
|
58
62
|
}
|
|
59
63
|
};
|
|
60
|
-
var getObjectFingerprint = function getObjectFingerprint(value) {
|
|
61
|
-
var sortedKeys = Object.keys(value).sort();
|
|
62
|
-
var buff = "";
|
|
63
|
-
var _iterator = _createForOfIteratorHelper(sortedKeys),
|
|
64
|
-
_step;
|
|
64
|
+
var getObjectFingerprint = function getObjectFingerprint(value, algorithm) {
|
|
65
65
|
try {
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
var sortedKeys = Object.keys(value).sort();
|
|
67
|
+
var buff = "";
|
|
68
|
+
var _iterator = _createForOfIteratorHelper(sortedKeys),
|
|
69
|
+
_step;
|
|
70
|
+
try {
|
|
71
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
72
|
+
var key = _step.value;
|
|
73
|
+
buff += "".concat(key, "<").concat(index(value[key], algorithm), ">");
|
|
74
|
+
}
|
|
75
|
+
} catch (err) {
|
|
76
|
+
_iterator.e(err);
|
|
77
|
+
} finally {
|
|
78
|
+
_iterator.f();
|
|
69
79
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
_iterator.f();
|
|
80
|
+
return buff;
|
|
81
|
+
} catch (e) {
|
|
82
|
+
return "nn";
|
|
74
83
|
}
|
|
75
|
-
return buff;
|
|
76
84
|
};
|
|
77
|
-
function index(object) {
|
|
78
|
-
|
|
85
|
+
function index(object, algorithm) {
|
|
86
|
+
if (algorithm) {
|
|
87
|
+
return algorithm(_getFingerprint(object, algorithm));
|
|
88
|
+
} else {
|
|
89
|
+
return _crc["default"].str(_getFingerprint(object)).toString(16);
|
|
90
|
+
}
|
|
79
91
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "object-fingerprint",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Simple and fast utility to create short, stable, and deterministic object fingerprints (object hash).",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"bin": "dist/index.js",
|
|
@@ -71,19 +71,19 @@
|
|
|
71
71
|
}
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
|
-
"@babel/cli": "^7.23.
|
|
75
|
-
"@babel/core": "^7.
|
|
76
|
-
"@babel/node": "^7.
|
|
74
|
+
"@babel/cli": "^7.23.9",
|
|
75
|
+
"@babel/core": "^7.24.0",
|
|
76
|
+
"@babel/node": "^7.23.9",
|
|
77
77
|
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
78
78
|
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
|
|
79
|
-
"@babel/plugin-transform-async-to-generator": "^7.
|
|
80
|
-
"@babel/plugin-transform-runtime": "^7.
|
|
81
|
-
"@babel/preset-env": "^7.
|
|
82
|
-
"release-it": "^
|
|
79
|
+
"@babel/plugin-transform-async-to-generator": "^7.23.3",
|
|
80
|
+
"@babel/plugin-transform-runtime": "^7.24.0",
|
|
81
|
+
"@babel/preset-env": "^7.24.0",
|
|
82
|
+
"release-it": "^17.1.1"
|
|
83
83
|
},
|
|
84
84
|
"dependencies": {
|
|
85
85
|
"crc-32": "^1.2.2",
|
|
86
|
-
"moment": "^2.
|
|
86
|
+
"moment": "^2.30.1"
|
|
87
87
|
},
|
|
88
88
|
"resolutions": {}
|
|
89
89
|
}
|