object-fingerprint 1.0.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/.babelrc ADDED
@@ -0,0 +1,20 @@
1
+ {
2
+ "presets": [
3
+ "@babel/preset-env"
4
+ ],
5
+ "plugins": [
6
+ "@babel/plugin-proposal-class-properties",
7
+ "@babel/plugin-transform-async-to-generator",
8
+ "@babel/plugin-proposal-object-rest-spread"
9
+ ],
10
+
11
+ "ignore": [
12
+ "./node_modules",
13
+ "./assets",
14
+ "./view",
15
+ "./tests",
16
+ "./logs",
17
+ "./dist",
18
+ "./build"
19
+ ]
20
+ }
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Massimo Candela <https://massimocandela.com>
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,26 @@
1
+ ## object-fingerprint
2
+
3
+ Just see example:
4
+
5
+ ```js
6
+ import fingerprint from "object-fingerprint";
7
+
8
+ const myObject1 = {
9
+ key1: "pizza",
10
+ key2: ["an", "array"]
11
+ };
12
+
13
+ const myObject1 = {
14
+ key2: ["an", "array"],
15
+ key1: "pizza"
16
+ };
17
+
18
+ const myObject3 = {
19
+ key2: ["array", "an"],
20
+ key1: "pizza"
21
+ };
22
+
23
+ fingerprint(myObject1); // 6afe6f0e
24
+ fingerprint(myObject2); // 6afe6f0e
25
+ fingerprint(myObject3); // -409427c2
26
+ ```
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = fingerprint;
7
+ var _moment = _interopRequireDefault(require("moment"));
8
+ var _crc = _interopRequireDefault(require("crc-32"));
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
10
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
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
+ 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
+ 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
+ * 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) {
37
+ switch (_typeof(object)) {
38
+ case "object":
39
+ if (object == null) {
40
+ return "o:null";
41
+ } else if (object._isAMomentObject) {
42
+ return "m:".concat(object.toISOString());
43
+ } else if (object instanceof Date) {
44
+ return "m:".concat((0, _moment["default"])(object).toISOString());
45
+ } else {
46
+ return "o:".concat(getObjectFingerprint(object));
47
+ }
48
+ case "boolean":
49
+ return "b:".concat(object ? "t" : "f");
50
+ case "function":
51
+ throw new Error("You cannot pass a function as data item");
52
+ case "number":
53
+ return "n:".concat(object.toString());
54
+ case "string":
55
+ return "s:".concat(object);
56
+ case "undefined":
57
+ return "u";
58
+ }
59
+ };
60
+ var getObjectFingerprint = function getObjectFingerprint(value) {
61
+ var sortedKeys = Object.keys(value).sort();
62
+ var buff = "";
63
+ var _iterator = _createForOfIteratorHelper(sortedKeys),
64
+ _step;
65
+ try {
66
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
67
+ var key = _step.value;
68
+ buff += "".concat(key, "<").concat(fingerprint(value[key]), ">");
69
+ }
70
+ } catch (err) {
71
+ _iterator.e(err);
72
+ } finally {
73
+ _iterator.f();
74
+ }
75
+ return buff;
76
+ };
77
+ function fingerprint(object) {
78
+ return _crc["default"].str(_getFingerprint(object)).toString(16);
79
+ }
package/package.json ADDED
@@ -0,0 +1,89 @@
1
+ {
2
+ "name": "object-fingerprint",
3
+ "version": "1.0.1",
4
+ "description": "Simple and fast utility to create short, stable, and deterministic object fingerprints (object hash).",
5
+ "main": "dist/index.js",
6
+ "bin": "dist/index.js",
7
+ "scripts": {
8
+ "babel": "node_modules/.bin/babel",
9
+ "compile": "rm -rf dist/ && mkdir -p dist/compiled && ./node_modules/.bin/babel src -d dist/compiled",
10
+ "release": "dotenv release-it"
11
+ },
12
+ "author": {
13
+ "name": "Massimo Candela",
14
+ "url": "https://massimocandela.com"
15
+ },
16
+ "license": "MIT",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/massimocandela/object-fingerprint"
20
+ },
21
+ "keywords": [
22
+ "object",
23
+ "hash",
24
+ "fingerprint"
25
+ ],
26
+ "release-it": {
27
+ "hooks": {
28
+ "before:init": [
29
+ "npm ci"
30
+ ],
31
+ "after:bump": [
32
+ "npm run compile"
33
+ ],
34
+ "after:release": [
35
+ "echo Successfully released ${name} v${version} to ${repo.repository}.",
36
+ "rm -r dist/"
37
+ ]
38
+ },
39
+ "git": {
40
+ "changelog": "git log --pretty=format:\"* %s (%h)\" ${from}...${to}",
41
+ "requireCleanWorkingDir": true,
42
+ "requireBranch": "main",
43
+ "requireUpstream": true,
44
+ "requireCommits": false,
45
+ "addUntrackedFiles": false,
46
+ "commit": true,
47
+ "commitMessage": "Release v${version}",
48
+ "commitArgs": [],
49
+ "tag": true,
50
+ "tagName": null,
51
+ "tagAnnotation": "Release v${version}",
52
+ "tagArgs": [],
53
+ "push": true,
54
+ "pushArgs": [
55
+ "--follow-tags"
56
+ ],
57
+ "pushRepo": ""
58
+ },
59
+ "gitlab": {
60
+ "release": false
61
+ },
62
+ "npm": {
63
+ "publish": true
64
+ },
65
+ "github": {
66
+ "release": true,
67
+ "releaseName": "v${version}",
68
+ "tokenRef": "GITHUB_TOKEN",
69
+ "origin": null,
70
+ "skipChecks": false
71
+ }
72
+ },
73
+ "devDependencies": {
74
+ "@babel/cli": "^7.23.0",
75
+ "@babel/core": "^7.23.2",
76
+ "@babel/node": "^7.22.19",
77
+ "@babel/plugin-proposal-class-properties": "^7.18.6",
78
+ "@babel/plugin-proposal-object-rest-spread": "^7.20.7",
79
+ "@babel/plugin-transform-async-to-generator": "^7.22.5",
80
+ "@babel/plugin-transform-runtime": "^7.23.2",
81
+ "@babel/preset-env": "^7.23.2",
82
+ "release-it": "^16.2.1"
83
+ },
84
+ "dependencies": {
85
+ "crc-32": "^1.2.2",
86
+ "moment": "^2.29.4"
87
+ },
88
+ "resolutions": {}
89
+ }