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 +1 -1
- package/util/base64.d.ts +4 -4
- package/util/base64.js +6 -6
- package/util/buffer.d.ts +8 -0
- package/util/buffer.js +24 -0
- package/util/index.d.ts +1 -0
- package/util/index.js +1 -0
- package/util/validate.d.ts +1 -1
- package/util/validate.js +3 -3
package/package.json
CHANGED
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
|
|
2
|
+
export declare function encodeBase64(str: string): string;
|
|
3
3
|
/** Decode a string from Base64 (strips `=` padding on the end). */
|
|
4
|
-
export declare function
|
|
4
|
+
export declare function decodeBase64(b64: string): string;
|
|
5
5
|
/** Encode a string to URL-safe Base64 */
|
|
6
|
-
export declare function
|
|
6
|
+
export declare function encodeBase64Url(str: string): string;
|
|
7
7
|
/** Decode a string from URL-safe Base64. */
|
|
8
|
-
export declare function
|
|
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
|
|
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
|
|
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
|
|
11
|
-
return
|
|
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
|
|
15
|
-
return
|
|
14
|
+
export function decodeBase64Url(b64) {
|
|
15
|
+
return decodeBase64(b64.replace(/-/g, "+").replace(/_/g, "/"));
|
|
16
16
|
}
|
package/util/buffer.d.ts
ADDED
|
@@ -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
package/util/index.js
CHANGED
package/util/validate.d.ts
CHANGED
|
@@ -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>(
|
|
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(
|
|
12
|
+
export function getValid(value, validator, ErrorConstructor = ValueError) {
|
|
13
13
|
try {
|
|
14
|
-
return validator.validate(
|
|
14
|
+
return validator.validate(value);
|
|
15
15
|
}
|
|
16
16
|
catch (thrown) {
|
|
17
17
|
if (thrown instanceof Feedback)
|
|
18
|
-
throw new ErrorConstructor(
|
|
18
|
+
throw new ErrorConstructor(thrown.message, { received: value, cause: thrown, caller: getValid });
|
|
19
19
|
throw thrown;
|
|
20
20
|
}
|
|
21
21
|
}
|