@junobuild/utils
Version:
A collection of utilities and constants for Juno JS libs.
8 lines (7 loc) • 1.94 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../src/utils/did.utils.ts", "../../src/utils/env.utils.ts"],
"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"],
"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",
"names": ["jsonReplacer", "jsonReviver", "toArray", "data", "blob", "fromArray", "isBrowser"]
}