@cyberalien/svg-utils 0.0.11 → 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): string;
4
+ declare function hashToString(value: number[], css: boolean, hasPrefix?: boolean, limit?: number): string;
5
5
  export { hashToString };
@@ -1,11 +1,16 @@
1
- const firstChars = "abcdefghijklmnopqrstuvwxyz";
2
- const chars = firstChars + "0123456789_-";
3
- const firstLetterRadix = 26;
4
- const letterRadix = 38;
1
+ const firstCSSChars = "abcdefghijklmnopqrstuvwxyz";
2
+ const firstIDChars = firstCSSChars + firstCSSChars.toUpperCase();
3
+ const numChars = "0123456789";
4
+ const allCSSChars = firstCSSChars + numChars + "-_";
5
+ const allIDChars = firstIDChars + numChars;
5
6
  /**
6
7
  * Convert hash to a string, usable in CSS for class names and keyframes
7
8
  */
8
- function hashToString(value, hasPrefix = true, limit = 8) {
9
+ function hashToString(value, css, hasPrefix = true, limit = 8) {
10
+ const firstChars = css ? firstCSSChars : firstIDChars;
11
+ const chars = css ? allCSSChars : allIDChars;
12
+ const firstLetterRadix = firstChars.length;
13
+ const letterRadix = chars.length;
9
14
  const result = [];
10
15
  let num = value.shift() ?? 0;
11
16
  if (!hasPrefix) {
@@ -1,6 +1,7 @@
1
1
  interface Options {
2
2
  prefix?: string;
3
3
  length: number;
4
+ css: boolean;
4
5
  lengths?: Record<string, number>;
5
6
  }
6
7
  /**
@@ -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 } = options;
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.11",
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/",