@cyberalien/svg-utils 0.1.3 → 0.1.4

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,7 +1,7 @@
1
1
  interface UniqueHashOptions {
2
2
  prefix?: string;
3
3
  css: boolean;
4
- length: number;
4
+ length: number | ((content: string) => number);
5
5
  lengths?: Record<string, number>;
6
6
  throwOnCollision?: boolean;
7
7
  }
@@ -24,7 +24,8 @@ function getUniqueHash(data, options) {
24
24
  const str = typeof data === "string" ? data : JSON.stringify(sortObject(data));
25
25
  const hasPrefix = !!prefix;
26
26
  const values = hashString(str);
27
- let hash = hashToString(values, css, hasPrefix, length);
27
+ const defaultLength = typeof length === "function" ? length(str) : length;
28
+ let hash = hashToString(values, css, hasPrefix, defaultLength);
28
29
  if (lengths?.[hash]) hash = hashToString(values, css, hasPrefix, lengths[hash]);
29
30
  const cache = hasPrefix ? uniqueWithPrefixHashes : uniqueHashes;
30
31
  const result = `${prefix}${hash}`;
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.1.3",
6
+ "version": "0.1.4",
7
7
  "license": "MIT",
8
8
  "bugs": "https://github.com/cyberalien/svg-utils/issues",
9
9
  "homepage": "https://cyberalien.dev/",