shelving 1.136.0 → 1.137.0

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.136.0",
14
+ "version": "1.137.0",
15
15
  "repository": "https://github.com/dhoulb/shelving",
16
16
  "author": "Dave Houlbrooke <dave@shax.com>",
17
17
  "license": "0BSD",
package/util/base64.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  /** Encode a string to Base64 (with no `=` padding on the end). */
2
- export declare function base64Encode(str: string): string;
2
+ export declare function encodeBase64(str: string): string;
3
3
  /** Decode a string from Base64 (strips `=` padding on the end). */
4
- export declare function base64Decode(b64: string): string;
4
+ export declare function decodeBase64(b64: string): string;
5
5
  /** Encode a string to URL-safe Base64 */
6
- export declare function base64UrlEncode(str: string): string;
6
+ export declare function encodeBase64Url(str: string): string;
7
7
  /** Decode a string from URL-safe Base64. */
8
- export declare function base64UrlDecode(b64: string): string;
8
+ export declare function decodeBase64Url(b64: string): string;
package/util/base64.js CHANGED
@@ -1,16 +1,16 @@
1
1
  /** Encode a string to Base64 (with no `=` padding on the end). */
2
- export function base64Encode(str) {
2
+ export function encodeBase64(str) {
3
3
  return btoa(str).replace(/=+$/, "");
4
4
  }
5
5
  /** Decode a string from Base64 (strips `=` padding on the end). */
6
- export function base64Decode(b64) {
6
+ export function decodeBase64(b64) {
7
7
  return atob(b64.replace(/=+$/, ""));
8
8
  }
9
9
  /** Encode a string to URL-safe Base64 */
10
- export function base64UrlEncode(str) {
11
- return base64Encode(str).replace(/\+/g, "-").replace(/\//g, "_");
10
+ export function encodeBase64Url(str) {
11
+ return encodeBase64(str).replace(/\+/g, "-").replace(/\//g, "_");
12
12
  }
13
13
  /** Decode a string from URL-safe Base64. */
14
- export function base64UrlDecode(b64) {
15
- return base64Decode(b64.replace(/-/g, "+").replace(/_/g, "/"));
14
+ export function decodeBase64Url(b64) {
15
+ return decodeBase64(b64.replace(/-/g, "+").replace(/_/g, "/"));
16
16
  }
@@ -0,0 +1,8 @@
1
+ /** Detect if an unknown value is an `ArrayBuffer` (not a view like `Uint8Array` or `Float32Array` etc). */
2
+ export declare function isBuffer(value: unknown): value is ArrayBuffer;
3
+ /** Detect if an unknown value is an `ArrayBuffer` view like `Uint8Array` or `Float32Array` etc. */
4
+ export declare function isBufferView(value: unknown): value is ArrayBufferView;
5
+ /** Encode a string as a `Uint8Array` */
6
+ export declare function encodeBufferView(str: string): Uint8Array;
7
+ /** Encode `Uint8Array` to a string. */
8
+ export declare function decodeBufferView(buffer: ArrayBuffer | ArrayBufferView): string;
package/util/buffer.js ADDED
@@ -0,0 +1,24 @@
1
+ import { ValueError } from "../error/ValueError.js";
2
+ /** Detect if an unknown value is an `ArrayBuffer` (not a view like `Uint8Array` or `Float32Array` etc). */
3
+ export function isBuffer(value) {
4
+ return value instanceof ArrayBuffer;
5
+ }
6
+ /** Detect if an unknown value is an `ArrayBuffer` view like `Uint8Array` or `Float32Array` etc. */
7
+ export function isBufferView(value) {
8
+ return ArrayBuffer.isView(value);
9
+ }
10
+ /** Encode a string as a `Uint8Array` */
11
+ export function encodeBufferView(str) {
12
+ return new TextEncoder().encode(str);
13
+ }
14
+ /** Encode `Uint8Array` to a string. */
15
+ export function decodeBufferView(buffer) {
16
+ try {
17
+ return new TextDecoder("utf-8", { fatal: true }).decode(buffer);
18
+ }
19
+ catch (thrown) {
20
+ if (thrown instanceof TypeError)
21
+ throw new ValueError(thrown.message, { received: buffer, caller: decodeBufferView });
22
+ throw thrown;
23
+ }
24
+ }
package/util/index.d.ts CHANGED
@@ -2,6 +2,7 @@ export * from "./array.js";
2
2
  export * from "./async.js";
3
3
  export * from "./base64.js";
4
4
  export * from "./boolean.js";
5
+ export * from "./buffer.js";
5
6
  export * from "./callback.js";
6
7
  export * from "./class.js";
7
8
  export * from "./color.js";
package/util/index.js CHANGED
@@ -2,6 +2,7 @@ export * from "./array.js";
2
2
  export * from "./async.js";
3
3
  export * from "./base64.js";
4
4
  export * from "./boolean.js";
5
+ export * from "./buffer.js";
5
6
  export * from "./callback.js";
6
7
  export * from "./class.js";
7
8
  export * from "./color.js";
@@ -29,7 +29,7 @@ export type ValidatorsType<T> = {
29
29
  readonly [K in keyof T]: ValidatorType<T[K]>;
30
30
  };
31
31
  /** Get value that validates against a given `Validator`, or throw `ValueError` */
32
- export declare function getValid<T>(unsafeValue: unknown, validator: Validator<T>, ErrorConstructor?: Constructor<BaseError, [string, BaseErrorOptions]>): T;
32
+ export declare function getValid<T>(value: unknown, validator: Validator<T>, ErrorConstructor?: Constructor<BaseError, [string, BaseErrorOptions]>): T;
33
33
  /**
34
34
  * Validate an iterable set of items with a validator.
35
35
  *
package/util/validate.js CHANGED
@@ -9,13 +9,13 @@ import { isIterable } from "./iterate.js";
9
9
  import { getNull } from "./null.js";
10
10
  import { getUndefined } from "./undefined.js";
11
11
  /** Get value that validates against a given `Validator`, or throw `ValueError` */
12
- export function getValid(unsafeValue, validator, ErrorConstructor = ValueError) {
12
+ export function getValid(value, validator, ErrorConstructor = ValueError) {
13
13
  try {
14
- return validator.validate(unsafeValue);
14
+ return validator.validate(value);
15
15
  }
16
16
  catch (thrown) {
17
17
  if (thrown instanceof Feedback)
18
- throw new ErrorConstructor("Invalid value", { cause: thrown, caller: getValid });
18
+ throw new ErrorConstructor(thrown.message, { received: value, cause: thrown, caller: getValid });
19
19
  throw thrown;
20
20
  }
21
21
  }