@cyberalien/svg-utils 0.0.5 → 0.0.7

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.
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Convert hash to a string, usable in CSS for class names and keyframes
3
+ */
4
+ declare function hashToString(value: number[], hasPrefix?: boolean, limit?: number): string;
5
+ export { hashToString };
@@ -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 hashToCSSString(value, limit = 8, hasPrefix = false) {
8
+ function hashToString(value, hasPrefix = true, limit = 8) {
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 { hashToCSSString };
27
+ export { hashToString };
@@ -1,5 +1,5 @@
1
1
  /**
2
2
  * Hash an object, make sure hash is unique
3
3
  */
4
- declare function uniqueCSSHash(data: unknown, hasPrefix?: boolean): string;
5
- export { uniqueCSSHash };
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 { hashToCSSString } from "./css.js";
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 uniqueCSSHash(data, hasPrefix = false) {
11
- const str = JSON.stringify(sortObject(data));
12
- const hash = hashToCSSString(hashString(str), 6, hasPrefix);
10
+ function getUniqueHash(data, hasPrefix = true, size = 8) {
11
+ const str = typeof data === "string" ? data : JSON.stringify(sortObject(data));
12
+ const hash = hashToString(hashString(str), hasPrefix, size);
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 { uniqueCSSHash };
23
+ export { getUniqueHash };
@@ -3,7 +3,6 @@ interface ParseSVGOptions {
3
3
  useSelfClosing?: boolean;
4
4
  numberTemplate?: string;
5
5
  prettyPrint?: boolean | string;
6
- sortAttributes?: boolean;
7
6
  }
8
7
  /**
9
8
  * Convert parsed XML content to string
@@ -1,8 +1,7 @@
1
1
  const defaultOptions = {
2
2
  useSelfClosing: true,
3
3
  numberTemplate: ` {key}="{value}"`,
4
- prettyPrint: false,
5
- sortAttributes: false
4
+ prettyPrint: false
6
5
  };
7
6
  function assertNever(v) {}
8
7
  /**
@@ -20,9 +19,7 @@ function stringifyXMLContent(root, options) {
20
19
  const nl = prettyPrint === false ? "" : "\n";
21
20
  const add = (node, depth) => {
22
21
  output += tabs(depth) + "<" + node.tag;
23
- const keys = Object.keys(node.attribs);
24
- if (fullOptions.sortAttributes) keys.sort();
25
- for (const key of keys) {
22
+ for (const key in node.attribs) {
26
23
  const value = node.attribs[key];
27
24
  switch (typeof value) {
28
25
  case "string":
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.5",
6
+ "version": "0.0.7",
7
7
  "license": "MIT",
8
8
  "bugs": "https://github.com/cyberalien/svg-utils/issues",
9
9
  "homepage": "https://cyberalien.dev/",
@@ -1,5 +0,0 @@
1
- /**
2
- * Convert hash to a string, usable in CSS for class names and keyframes
3
- */
4
- declare function hashToCSSString(value: number[], limit?: number, hasPrefix?: boolean): string;
5
- export { hashToCSSString };