@junobuild/utils 0.0.27 → 0.1.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/dist/browser/index.js +1 -1
- package/dist/browser/index.js.map +4 -4
- package/dist/node/index.mjs +1 -1
- package/dist/node/index.mjs.map +4 -4
- package/dist/types/index.d.ts +0 -3
- package/dist/types/utils/did.utils.d.ts +0 -14
- package/package.json +3 -3
- package/dist/types/utils/debounce.utils.d.ts +0 -7
- package/dist/types/utils/json.utils.d.ts +0 -14
- package/dist/types/utils/null.utils.d.ts +0 -30
package/dist/browser/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import{jsonReplacer as n,jsonReviver as t}from"@dfinity/utils";var a=async r=>{let o=new Blob([JSON.stringify(r,n)],{type:"application/json; charset=utf-8"});return new Uint8Array(await o.arrayBuffer())},i=async r=>{let o=new Blob([r instanceof Uint8Array?r:new Uint8Array(r)],{type:"application/json; charset=utf-8"});return JSON.parse(await o.text(),t)};var p=()=>typeof window<"u";export{i as fromArray,p as isBrowser,a as toArray};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["
|
|
3
|
+
"sources": ["../../src/utils/did.utils.ts", "../../src/utils/env.utils.ts"],
|
|
4
|
+
"sourcesContent": ["import {jsonReplacer, jsonReviver} from '@dfinity/utils';\n\n/**\n * Converts data to a Uint8Array for transmission or storage.\n * @template T\n * @param {T} data - The data to convert.\n * @returns {Promise<Uint8Array>} A promise that resolves to a Uint8Array representation of the data.\n */\nexport const toArray = async <T>(data: T): Promise<Uint8Array> => {\n const blob: Blob = new Blob([JSON.stringify(data, jsonReplacer)], {\n type: 'application/json; charset=utf-8'\n });\n return new Uint8Array(await blob.arrayBuffer());\n};\n\n/**\n * Converts a Uint8Array or number array back to the original data type.\n * @template T\n * @param {(Uint8Array | number[])} data - The array to convert.\n * @returns {Promise<T>} A promise that resolves to the original data.\n */\nexport const fromArray = async <T>(data: Uint8Array | number[]): Promise<T> => {\n const blob: Blob = new Blob([data instanceof Uint8Array ? data : new Uint8Array(data)], {\n type: 'application/json; charset=utf-8'\n });\n return JSON.parse(await blob.text(), jsonReviver);\n};\n", "/**\n * Checks if the current environment is a browser.\n * @returns {boolean} True if the current environment is a browser, false otherwise.\n */\nexport const isBrowser = (): boolean => typeof window !== `undefined`;\n"],
|
|
5
|
+
"mappings": "AAAA,OAAQ,gBAAAA,EAAc,eAAAC,MAAkB,iBAQjC,IAAMC,EAAU,MAAUC,GAAiC,CAChE,IAAMC,EAAa,IAAI,KAAK,CAAC,KAAK,UAAUD,EAAMH,CAAY,CAAC,EAAG,CAChE,KAAM,iCACR,CAAC,EACD,OAAO,IAAI,WAAW,MAAMI,EAAK,YAAY,CAAC,CAChD,EAQaC,EAAY,MAAUF,GAA4C,CAC7E,IAAMC,EAAa,IAAI,KAAK,CAACD,aAAgB,WAAaA,EAAO,IAAI,WAAWA,CAAI,CAAC,EAAG,CACtF,KAAM,iCACR,CAAC,EACD,OAAO,KAAK,MAAM,MAAMC,EAAK,KAAK,EAAGH,CAAW,CAClD,ECtBO,IAAMK,EAAY,IAAe,OAAO,OAAW",
|
|
6
|
+
"names": ["jsonReplacer", "jsonReviver", "toArray", "data", "blob", "fromArray", "isBrowser"]
|
|
7
7
|
}
|
package/dist/node/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { createRequire as topLevelCreateRequire } from 'module';
|
|
2
2
|
const require = topLevelCreateRequire(import.meta.url);
|
|
3
|
-
|
|
3
|
+
import{jsonReplacer as n,jsonReviver as t}from"@dfinity/utils";var a=async r=>{let o=new Blob([JSON.stringify(r,n)],{type:"application/json; charset=utf-8"});return new Uint8Array(await o.arrayBuffer())},i=async r=>{let o=new Blob([r instanceof Uint8Array?r:new Uint8Array(r)],{type:"application/json; charset=utf-8"});return JSON.parse(await o.text(),t)};var p=()=>typeof window<"u";export{i as fromArray,p as isBrowser,a as toArray};
|
|
4
4
|
//# sourceMappingURL=index.mjs.map
|
package/dist/node/index.mjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/utils/
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";;
|
|
6
|
-
"names": ["
|
|
3
|
+
"sources": ["../../src/utils/did.utils.ts", "../../src/utils/env.utils.ts"],
|
|
4
|
+
"sourcesContent": ["import {jsonReplacer, jsonReviver} from '@dfinity/utils';\n\n/**\n * Converts data to a Uint8Array for transmission or storage.\n * @template T\n * @param {T} data - The data to convert.\n * @returns {Promise<Uint8Array>} A promise that resolves to a Uint8Array representation of the data.\n */\nexport const toArray = async <T>(data: T): Promise<Uint8Array> => {\n const blob: Blob = new Blob([JSON.stringify(data, jsonReplacer)], {\n type: 'application/json; charset=utf-8'\n });\n return new Uint8Array(await blob.arrayBuffer());\n};\n\n/**\n * Converts a Uint8Array or number array back to the original data type.\n * @template T\n * @param {(Uint8Array | number[])} data - The array to convert.\n * @returns {Promise<T>} A promise that resolves to the original data.\n */\nexport const fromArray = async <T>(data: Uint8Array | number[]): Promise<T> => {\n const blob: Blob = new Blob([data instanceof Uint8Array ? data : new Uint8Array(data)], {\n type: 'application/json; charset=utf-8'\n });\n return JSON.parse(await blob.text(), jsonReviver);\n};\n", "/**\n * Checks if the current environment is a browser.\n * @returns {boolean} True if the current environment is a browser, false otherwise.\n */\nexport const isBrowser = (): boolean => typeof window !== `undefined`;\n"],
|
|
5
|
+
"mappings": ";;AAAA,OAAQ,gBAAAA,EAAc,eAAAC,MAAkB,iBAQjC,IAAMC,EAAU,MAAUC,GAAiC,CAChE,IAAMC,EAAa,IAAI,KAAK,CAAC,KAAK,UAAUD,EAAMH,CAAY,CAAC,EAAG,CAChE,KAAM,iCACR,CAAC,EACD,OAAO,IAAI,WAAW,MAAMI,EAAK,YAAY,CAAC,CAChD,EAQaC,EAAY,MAAUF,GAA4C,CAC7E,IAAMC,EAAa,IAAI,KAAK,CAACD,aAAgB,WAAaA,EAAO,IAAI,WAAWA,CAAI,CAAC,EAAG,CACtF,KAAM,iCACR,CAAC,EACD,OAAO,KAAK,MAAM,MAAMC,EAAK,KAAK,EAAGH,CAAW,CAClD,ECtBO,IAAMK,EAAY,IAAe,OAAO,OAAW",
|
|
6
|
+
"names": ["jsonReplacer", "jsonReviver", "toArray", "data", "blob", "fromArray", "isBrowser"]
|
|
7
7
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,17 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Converts a value to a nullable array.
|
|
3
|
-
* @template T
|
|
4
|
-
* @param {T} [value] - The value to convert.
|
|
5
|
-
* @returns {([] | [T])} A nullable array containing the value if non-nullish, or an empty array if nullish.
|
|
6
|
-
*/
|
|
7
|
-
export declare const toNullable: <T>(value?: T) => [] | [T];
|
|
8
|
-
/**
|
|
9
|
-
* Extracts a value from a nullable array.
|
|
10
|
-
* @template T
|
|
11
|
-
* @param {([] | [T])} value - The nullable array.
|
|
12
|
-
* @returns {(T | undefined)} The value if present, or undefined if the array is empty.
|
|
13
|
-
*/
|
|
14
|
-
export declare const fromNullable: <T>(value: [] | [T]) => T | undefined;
|
|
15
1
|
/**
|
|
16
2
|
* Converts data to a Uint8Array for transmission or storage.
|
|
17
3
|
* @template T
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@junobuild/utils",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"description": "A collection of utilities and constants for Juno JS libs.",
|
|
5
5
|
"author": "David Dal Busco (https://daviddalbusco.com)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"repository": {
|
|
35
35
|
"type": "git",
|
|
36
36
|
"url": "git+https://github.com/junobuild/juno-js.git",
|
|
37
|
-
"directory": "packages/
|
|
37
|
+
"directory": "packages/utils"
|
|
38
38
|
},
|
|
39
39
|
"bugs": {
|
|
40
40
|
"url": "https://github.com/junobuild/juno-js"
|
|
@@ -52,6 +52,6 @@
|
|
|
52
52
|
],
|
|
53
53
|
"homepage": "https://juno.build",
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"@dfinity/
|
|
55
|
+
"@dfinity/utils": "^2"
|
|
56
56
|
}
|
|
57
57
|
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Creates a debounced function that delays invoking the provided function until after the specified timeout.
|
|
3
|
-
* @param {Function} func - The function to debounce.
|
|
4
|
-
* @param {number} [timeout=300] - The number of milliseconds to delay. Defaults to 300ms if not specified or invalid.
|
|
5
|
-
* @returns {Function} A debounced function.
|
|
6
|
-
*/
|
|
7
|
-
export declare const debounce: (func: Function, timeout?: number) => Function;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A function that alters the behavior of the stringification process for BigInt, Principal, and Uint8Array.
|
|
3
|
-
* @param {string} _key - The key of the value being stringified.
|
|
4
|
-
* @param {unknown} value - The value being stringified.
|
|
5
|
-
* @returns {unknown} The altered value for stringification.
|
|
6
|
-
*/
|
|
7
|
-
export declare const jsonReplacer: (_key: string, value: unknown) => unknown;
|
|
8
|
-
/**
|
|
9
|
-
* A parser that interprets revived BigInt, Principal, and Uint8Array when constructing JavaScript values or objects.
|
|
10
|
-
* @param {string} _key - The key of the value being parsed.
|
|
11
|
-
* @param {unknown} value - The value being parsed.
|
|
12
|
-
* @returns {unknown} The parsed value.
|
|
13
|
-
*/
|
|
14
|
-
export declare const jsonReviver: (_key: string, value: unknown) => unknown;
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Checks if the provided argument is null or undefined.
|
|
3
|
-
* @template T
|
|
4
|
-
* @param {T | undefined | null} argument - The argument to check.
|
|
5
|
-
* @returns {boolean} True if the argument is null or undefined, false otherwise.
|
|
6
|
-
*/
|
|
7
|
-
export declare const isNullish: <T>(argument: T | undefined | null) => argument is undefined | null;
|
|
8
|
-
/**
|
|
9
|
-
* Checks if the provided argument is neither null nor undefined.
|
|
10
|
-
* @template T
|
|
11
|
-
* @param {T | undefined | null} argument - The argument to check.
|
|
12
|
-
* @returns {boolean} True if the argument is neither null nor undefined, false otherwise.
|
|
13
|
-
*/
|
|
14
|
-
export declare const nonNullish: <T>(argument: T | undefined | null) => argument is NonNullable<T>;
|
|
15
|
-
/**
|
|
16
|
-
* Represents an error thrown when a value is null or undefined.
|
|
17
|
-
* @class
|
|
18
|
-
* @extends {Error}
|
|
19
|
-
*/
|
|
20
|
-
export declare class NullishError extends Error {
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Asserts that a value is neither null nor undefined.
|
|
24
|
-
* @template T
|
|
25
|
-
* @param {T} value - The value to check.
|
|
26
|
-
* @param {string} [message] - The optional error message to use if the assertion fails.
|
|
27
|
-
* @throws {NullishError} If the value is null or undefined.
|
|
28
|
-
* @returns {asserts value is NonNullable<T>} Asserts that the value is neither null nor undefined.
|
|
29
|
-
*/
|
|
30
|
-
export declare const assertNonNullish: <T>(value: T, message?: string) => asserts value is NonNullable<T>;
|