@junobuild/utils 0.0.2

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 David Dal Busco
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,17 @@
1
+ [![npm][npm-badge]][npm-badge-url]
2
+ [![license][npm-license]][npm-license-url]
3
+
4
+ [npm-badge]: https://img.shields.io/npm/v/@junobuild/utils
5
+ [npm-badge-url]: https://www.npmjs.com/package/@junobuild/utils
6
+ [npm-license]: https://img.shields.io/npm/l/@junobuild/utils
7
+ [npm-license-url]: https://github.com/deckgo/junobuild/blob/main/webcomponents/core/LICENSE
8
+
9
+ # Juno JavaScript utils
10
+
11
+ A collection of utilities and constants for Juno JS libs.
12
+
13
+ ## License
14
+
15
+ MIT © [David Dal Busco](mailto:david.dalbusco@outlook.com)
16
+
17
+ [juno]: https://juno.build
@@ -0,0 +1,2 @@
1
+ var t=n=>n==null,o=n=>!t(n),e=class extends Error{},s=(n,r)=>{if(t(n))throw new e(r)};var a=n=>o(n)?[n]:[],u=n=>n?.[0],T=async n=>{let r=new Blob([JSON.stringify(n)],{type:"application/json; charset=utf-8"});return new Uint8Array(await r.arrayBuffer())},p=async n=>{let r=new Blob([n instanceof Uint8Array?n:new Uint8Array(n)],{type:"application/json; charset=utf-8"});return JSON.parse(await r.text())};export{e as NullishError,s as assertNonNullish,p as fromArray,u as fromNullable,t as isNullish,o as nonNullish,T as toArray,a as toNullable};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/null.utils.ts", "../../src/utils/did.utils.ts"],
4
+ "sourcesContent": ["/** Is null or undefined */\nexport const isNullish = <T>(argument: T | undefined | null): argument is undefined | null =>\n argument === null || argument === undefined;\n\n/** Not null and not undefined */\nexport const nonNullish = <T>(argument: T | undefined | null): argument is NonNullable<T> =>\n !isNullish(argument);\n\nexport class NullishError extends Error {}\n\nexport const assertNonNullish: <T>(\n value: T,\n message?: string\n) => asserts value is NonNullable<T> = <T>(value: T, message?: string): void => {\n if (isNullish(value)) {\n throw new NullishError(message);\n }\n};\n", "import {nonNullish} from './null.utils';\n\nexport const toNullable = <T>(value?: T): [] | [T] => {\n return nonNullish(value) ? [value] : [];\n};\n\nexport const fromNullable = <T>(value: [] | [T]): T | undefined => {\n return value?.[0];\n};\n\nexport const toArray = async <T>(data: T): Promise<Uint8Array> => {\n const blob: Blob = new Blob([JSON.stringify(data)], {\n type: 'application/json; charset=utf-8'\n });\n return new Uint8Array(await blob.arrayBuffer());\n};\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());\n};\n"],
5
+ "mappings": "AACO,IAAMA,EAAgBC,GAC3BA,GAAa,KAGFC,EAAiBD,GAC5B,CAACD,EAAUC,CAAQ,EAERE,EAAN,cAA2B,KAAM,CAAC,EAE5BC,EAG0B,CAAIC,EAAUC,IAA2B,CAC9E,GAAIN,EAAUK,CAAK,EACjB,MAAM,IAAIF,EAAaG,CAAO,CAElC,ECfO,IAAMC,EAAiBC,GACrBC,EAAWD,CAAK,EAAI,CAACA,CAAK,EAAI,CAAC,EAG3BE,EAAmBF,GACvBA,IAAQ,CAAC,EAGLG,EAAU,MAAUC,GAAiC,CAChE,IAAMC,EAAa,IAAI,KAAK,CAAC,KAAK,UAAUD,CAAI,CAAC,EAAG,CAClD,KAAM,iCACR,CAAC,EACD,OAAO,IAAI,WAAW,MAAMC,EAAK,YAAY,CAAC,CAChD,EAEaC,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,CAAC,CACrC",
6
+ "names": ["isNullish", "argument", "nonNullish", "NullishError", "assertNonNullish", "value", "message", "toNullable", "value", "nonNullish", "fromNullable", "toArray", "data", "blob", "fromArray"]
7
+ }
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ export * from './browser/index.js';
@@ -0,0 +1,4 @@
1
+ import { createRequire as topLevelCreateRequire } from 'module';
2
+ const require = topLevelCreateRequire(import.meta.url);
3
+ var t=n=>n==null,o=n=>!t(n),e=class extends Error{},s=(n,r)=>{if(t(n))throw new e(r)};var a=n=>o(n)?[n]:[],u=n=>n?.[0],T=async n=>{let r=new Blob([JSON.stringify(n)],{type:"application/json; charset=utf-8"});return new Uint8Array(await r.arrayBuffer())},p=async n=>{let r=new Blob([n instanceof Uint8Array?n:new Uint8Array(n)],{type:"application/json; charset=utf-8"});return JSON.parse(await r.text())};export{e as NullishError,s as assertNonNullish,p as fromArray,u as fromNullable,t as isNullish,o as nonNullish,T as toArray,a as toNullable};
4
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/utils/null.utils.ts", "../../src/utils/did.utils.ts"],
4
+ "sourcesContent": ["/** Is null or undefined */\nexport const isNullish = <T>(argument: T | undefined | null): argument is undefined | null =>\n argument === null || argument === undefined;\n\n/** Not null and not undefined */\nexport const nonNullish = <T>(argument: T | undefined | null): argument is NonNullable<T> =>\n !isNullish(argument);\n\nexport class NullishError extends Error {}\n\nexport const assertNonNullish: <T>(\n value: T,\n message?: string\n) => asserts value is NonNullable<T> = <T>(value: T, message?: string): void => {\n if (isNullish(value)) {\n throw new NullishError(message);\n }\n};\n", "import {nonNullish} from './null.utils';\n\nexport const toNullable = <T>(value?: T): [] | [T] => {\n return nonNullish(value) ? [value] : [];\n};\n\nexport const fromNullable = <T>(value: [] | [T]): T | undefined => {\n return value?.[0];\n};\n\nexport const toArray = async <T>(data: T): Promise<Uint8Array> => {\n const blob: Blob = new Blob([JSON.stringify(data)], {\n type: 'application/json; charset=utf-8'\n });\n return new Uint8Array(await blob.arrayBuffer());\n};\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());\n};\n"],
5
+ "mappings": ";;AACO,IAAMA,EAAgBC,GAC3BA,GAAa,KAGFC,EAAiBD,GAC5B,CAACD,EAAUC,CAAQ,EAERE,EAAN,cAA2B,KAAM,CAAC,EAE5BC,EAG0B,CAAIC,EAAUC,IAA2B,CAC9E,GAAIN,EAAUK,CAAK,EACjB,MAAM,IAAIF,EAAaG,CAAO,CAElC,ECfO,IAAMC,EAAiBC,GACrBC,EAAWD,CAAK,EAAI,CAACA,CAAK,EAAI,CAAC,EAG3BE,EAAmBF,GACvBA,IAAQ,CAAC,EAGLG,EAAU,MAAUC,GAAiC,CAChE,IAAMC,EAAa,IAAI,KAAK,CAAC,KAAK,UAAUD,CAAI,CAAC,EAAG,CAClD,KAAM,iCACR,CAAC,EACD,OAAO,IAAI,WAAW,MAAMC,EAAK,YAAY,CAAC,CAChD,EAEaC,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,CAAC,CACrC",
6
+ "names": ["isNullish", "argument", "nonNullish", "NullishError", "assertNonNullish", "value", "message", "toNullable", "value", "nonNullish", "fromNullable", "toArray", "data", "blob", "fromArray"]
7
+ }
@@ -0,0 +1,2 @@
1
+ export * from './utils/did.utils';
2
+ export * from './utils/null.utils';
@@ -0,0 +1,4 @@
1
+ export declare const toNullable: <T>(value?: T | undefined) => [] | [T];
2
+ export declare const fromNullable: <T>(value: [] | [T]) => T | undefined;
3
+ export declare const toArray: <T>(data: T) => Promise<Uint8Array>;
4
+ export declare const fromArray: <T>(data: Uint8Array | number[]) => Promise<T>;
@@ -0,0 +1,7 @@
1
+ /** Is null or undefined */
2
+ export declare const isNullish: <T>(argument: T | null | undefined) => argument is null | undefined;
3
+ /** Not null and not undefined */
4
+ export declare const nonNullish: <T>(argument: T | null | undefined) => argument is NonNullable<T>;
5
+ export declare class NullishError extends Error {
6
+ }
7
+ export declare const assertNonNullish: <T>(value: T, message?: string) => asserts value is NonNullable<T>;
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@junobuild/utils",
3
+ "version": "0.0.2",
4
+ "description": "A collection of utilities and constants for Juno JS libs.",
5
+ "author": "David Dal Busco (https://daviddalbusco.com)",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "main": "dist/node/index.mjs",
9
+ "module": "dist/browser/index.js",
10
+ "types": "dist/types/index.d.ts",
11
+ "files": [
12
+ "dist",
13
+ "README.md",
14
+ "LICENSE"
15
+ ],
16
+ "scripts": {
17
+ "rmdir": "node ../../scripts/rmdir.mjs",
18
+ "ts-declaration": "tsc --emitDeclarationOnly --outDir dist/types",
19
+ "build": "npm run rmdir && mkdir -p dist && node esbuild.mjs && npm run ts-declaration",
20
+ "prepack": "npm run build"
21
+ },
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "git+https://github.com/buildwithjuno/juno-js.git",
25
+ "directory": "packages/core"
26
+ },
27
+ "bugs": {
28
+ "url": "https://github.com/buildwithjuno/juno-js"
29
+ },
30
+ "keywords": [
31
+ "blockchain-as-a-service",
32
+ "baas",
33
+ "dapps",
34
+ "dapps-development",
35
+ "internet computer",
36
+ "smart-contracts",
37
+ "web3",
38
+ "utilities",
39
+ "utils"
40
+ ],
41
+ "homepage": "https://juno.build",
42
+ "dependencies": {},
43
+ "peerDependencies": {}
44
+ }