@cyberalien/svg-utils 0.0.5 → 0.0.6
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.
|
@@ -5,7 +5,7 @@ const letterRadix = 38;
|
|
|
5
5
|
/**
|
|
6
6
|
* Convert hash to a string, usable in CSS for class names and keyframes
|
|
7
7
|
*/
|
|
8
|
-
function
|
|
8
|
+
function hashToString(value, limit = 8, hasPrefix = false) {
|
|
9
9
|
const result = [];
|
|
10
10
|
let num = value.shift() ?? 0;
|
|
11
11
|
if (!hasPrefix) {
|
|
@@ -24,4 +24,4 @@ function hashToCSSString(value, limit = 8, hasPrefix = false) {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
export {
|
|
27
|
+
export { hashToString };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Hash an object, make sure hash is unique
|
|
3
3
|
*/
|
|
4
|
-
declare function
|
|
5
|
-
export {
|
|
4
|
+
declare function getUniqueHash(data: unknown, hasPrefix?: boolean, size?: number): string;
|
|
5
|
+
export { getUniqueHash };
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { sortObject } from "../misc/sort-object.js";
|
|
2
2
|
import { hashString } from "./hash.js";
|
|
3
|
-
import {
|
|
3
|
+
import { hashToString } from "./stringify.js";
|
|
4
4
|
|
|
5
5
|
const uniqueHashes = Object.create(null);
|
|
6
6
|
const uniqueWithPrefixHashes = Object.create(null);
|
|
7
7
|
/**
|
|
8
8
|
* Hash an object, make sure hash is unique
|
|
9
9
|
*/
|
|
10
|
-
function
|
|
11
|
-
const str = JSON.stringify(sortObject(data));
|
|
12
|
-
const hash =
|
|
10
|
+
function getUniqueHash(data, hasPrefix = false, size = 8) {
|
|
11
|
+
const str = typeof data === "string" ? data : JSON.stringify(sortObject(data));
|
|
12
|
+
const hash = hashToString(hashString(str), size, hasPrefix);
|
|
13
13
|
const cache = hasPrefix ? uniqueWithPrefixHashes : uniqueHashes;
|
|
14
14
|
if (!cache[hash]) cache[hash] = str;
|
|
15
15
|
else if (cache[hash] !== str) {
|
|
@@ -20,4 +20,4 @@ function uniqueCSSHash(data, hasPrefix = false) {
|
|
|
20
20
|
return hash;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
export {
|
|
23
|
+
export { getUniqueHash };
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"type": "module",
|
|
4
4
|
"description": "Common functions for working with SVG used by various packages.",
|
|
5
5
|
"author": "Vjacheslav Trushkin",
|
|
6
|
-
"version": "0.0.
|
|
6
|
+
"version": "0.0.6",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"bugs": "https://github.com/cyberalien/svg-utils/issues",
|
|
9
9
|
"homepage": "https://cyberalien.dev/",
|