@cyberalien/svg-utils 0.0.12 → 0.0.13
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Convert hash to a string, usable in CSS for class names and keyframes
|
|
3
3
|
*/
|
|
4
|
-
declare function hashToString(value: number[], hasPrefix?: boolean, limit?: number
|
|
4
|
+
declare function hashToString(value: number[], css: boolean, hasPrefix?: boolean, limit?: number): string;
|
|
5
5
|
export { hashToString };
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
const
|
|
2
|
-
const
|
|
1
|
+
const firstCSSChars = "abcdefghijklmnopqrstuvwxyz";
|
|
2
|
+
const firstIDChars = firstCSSChars + firstCSSChars.toUpperCase();
|
|
3
|
+
const numChars = "0123456789";
|
|
4
|
+
const allCSSChars = firstCSSChars + numChars + "-_";
|
|
5
|
+
const allIDChars = firstIDChars + numChars;
|
|
3
6
|
/**
|
|
4
7
|
* Convert hash to a string, usable in CSS for class names and keyframes
|
|
5
8
|
*/
|
|
6
|
-
function hashToString(value, hasPrefix = true, limit = 8
|
|
7
|
-
const firstChars =
|
|
8
|
-
const chars =
|
|
9
|
+
function hashToString(value, css, hasPrefix = true, limit = 8) {
|
|
10
|
+
const firstChars = css ? firstCSSChars : firstIDChars;
|
|
11
|
+
const chars = css ? allCSSChars : allIDChars;
|
|
9
12
|
const firstLetterRadix = firstChars.length;
|
|
10
13
|
const letterRadix = chars.length;
|
|
11
14
|
const result = [];
|
|
@@ -14,12 +14,12 @@ const uniqueWithPrefixHashes = Object.create(null);
|
|
|
14
14
|
* 9 chars = 113t unique hashes
|
|
15
15
|
*/
|
|
16
16
|
function getUniqueHash(data, options) {
|
|
17
|
-
const { prefix, length, lengths,
|
|
17
|
+
const { prefix, length, lengths, css } = options;
|
|
18
18
|
const str = typeof data === "string" ? data : JSON.stringify(sortObject(data));
|
|
19
19
|
const hasPrefix = !!prefix;
|
|
20
20
|
const values = hashString(str);
|
|
21
|
-
let hash = hashToString(values, hasPrefix, length
|
|
22
|
-
if (lengths?.[hash]) hash = hashToString(values, hasPrefix, lengths[hash]
|
|
21
|
+
let hash = hashToString(values, css, hasPrefix, length);
|
|
22
|
+
if (lengths?.[hash]) hash = hashToString(values, css, hasPrefix, lengths[hash]);
|
|
23
23
|
const cache = hasPrefix ? uniqueWithPrefixHashes : uniqueHashes;
|
|
24
24
|
if (!cache[hash]) cache[hash] = str;
|
|
25
25
|
else if (cache[hash] !== str) {
|
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.13",
|
|
7
7
|
"license": "MIT",
|
|
8
8
|
"bugs": "https://github.com/cyberalien/svg-utils/issues",
|
|
9
9
|
"homepage": "https://cyberalien.dev/",
|