shelving 1.149.0 → 1.149.1

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.
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "state-management",
12
12
  "query-builder"
13
13
  ],
14
- "version": "1.149.0",
14
+ "version": "1.149.1",
15
15
  "repository": "https://github.com/dhoulb/shelving",
16
16
  "author": "Dave Houlbrooke <dave@shax.com>",
17
17
  "license": "0BSD",
@@ -29,7 +29,7 @@ export class StringSchema extends Schema {
29
29
  throw new ValueFeedback("Must be string", unsafeValue);
30
30
  const saneString = this.sanitize(possibleString);
31
31
  if (saneString.length < this.min)
32
- throw new ValueFeedback(saneString.length ? `Minimum ${this.min} characters` : "Required", saneString);
32
+ throw new ValueFeedback(possibleString.length ? `Minimum ${this.min} characters` : "Required", saneString);
33
33
  if (saneString.length > this.max)
34
34
  throw new ValueFeedback(`Maximum ${this.max} characters`, saneString);
35
35
  return saneString;
@@ -12,8 +12,8 @@ export class UUIDSchema extends StringSchema {
12
12
  super({
13
13
  title,
14
14
  ...rest,
15
- min: 36,
16
- max: 36, // 36 chars including hyphens
15
+ min: 32,
16
+ max: 36, // 36 chars including hyphens (which get stripped by sanitize for appearances).
17
17
  });
18
18
  }
19
19
  sanitize(str) {
package/util/uuid.js CHANGED
@@ -1,17 +1,18 @@
1
1
  import { RequiredError } from "../error/RequiredError.js";
2
+ const R_NOT_LOWERCHAR = /[^0-9a-f]/g;
2
3
  /** Return a random UUID (v4) */
3
4
  export function randomUUID() {
4
- return crypto.randomUUID();
5
+ return crypto.randomUUID().replace(R_NOT_LOWERCHAR, "");
5
6
  }
6
7
  /** Convert/validate a unknown value as as UUID. */
7
8
  export function getUUID(value) {
8
9
  if (typeof value !== "string" || !value)
9
10
  return;
10
11
  // Strip any non-hex characters (including existing dashes), then normalize to lowercase.
11
- const cleaned = value.replace(/[^0-9A-Fa-f]/g, "").toLowerCase();
12
+ const cleaned = value.toLowerCase().replace(R_NOT_LOWERCHAR, "");
12
13
  if (cleaned.length !== 32)
13
14
  return;
14
- return `${cleaned.slice(0, 8)}-${cleaned.slice(8, 12)}-${cleaned.slice(12, 16)}-${cleaned.slice(16, 20)}-${cleaned.slice(20)}`;
15
+ return `${cleaned.slice(0, 8)}${cleaned.slice(8, 12)}${cleaned.slice(12, 16)}${cleaned.slice(16, 20)}${cleaned.slice(20)}`;
15
16
  }
16
17
  /** Require a valid UUID. */
17
18
  export function requireUUID(value) {