es-first-aid
The Fundamental Utilities for ECMAScript.
- Missing utility functions for ECMAScript
- Random numbers/bytes...
- UUIDs
- CRC-32
- Most basic general utility classes for various applications
- Base64 encode/decode
- UTF-8 string encode/decode
- Hex string encode/decode
- ...
API
globalThis.firstAid;
declare const firstAid: FirstAid;
interface Iterable<T> {
[Symbol.iterator](): Iterator<T>;
}
type BufferSource = ArrayBuffer | ArrayBufferView;
type MaybePromise<T> = Promise<T> | T;
interface PromiseComposition<T> extends Promise<Iterable<T>> {
promises: Promise<T>[];
[Symbol.iterator]: () => IterableIterator<T>;
results: () => Promise<T[]>;
rejections: () => Promise<any[]>;
fulfilled: <returnType>(callback: (result: T) => returnType) => PromiseComposition<returnType>;
rejected: <returnType>(callback: (reason: any) => returnType) => PromiseComposition<returnType>;
}
interface SymbolObject {
symbol: symbol;
}
interface FirstAid {
VERSION: string;
firstAid: FirstAid;
constructor: new () => FirstAid;
PromiseComposition: new <T>(... promises: MaybePromise<T>[]) => PromiseComposition<T>;
TypedArray: Function;
isTypedArray: (value: any) => boolean;
MINUS_ZERO: number;
createNullPrototypeObject: () => {};
createReadOnlyProxy: <T>(obj: T) => T;
checkForError: (f: () => void) => boolean;
isRevokedProxy: (value: any) => boolean;
isConstructor: (value: any) => boolean;
toInt32: (value: any) => number;
isInt32: (value: any) => boolean;
toInt: (value: any) => number;
isInt: (value: any) => boolean;
isNull: (value: any) => boolean;
isObject: (value: any) => boolean;
isPropertyKey: (value: any) => boolean;
getCodePoints: (str: string) => Iterable<number>;
encodeString: (str: string) => Uint8Array;
decodeString: (utf8Bytes: BufferSource) => string;
toUint8Array: (buffer: BufferSource) => Uint8Array;
getCopyBuffer: (buffer: BufferSource) => ArrayBuffer;
encodeHex: (buffer: BufferSource) => string;
decodeHex: (hexString: string) => Uint8Array;
encodeBase64: (buffer: BufferSource) => string;
decodeBase64: (base64String: string) => Uint8Array;
crc32: (buffer: BufferSource) => number;
crc32Bytes: (buffer: BufferSource) => Uint8Array;
randomFillInsecure: (buffer: BufferSource) => Uint8Array;
randomFill: (buffer: BufferSource) => Uint8Array;
random: (isInsecure?: boolean) => number;
randomNonZero: (isInsecure?: boolean) => number;
randomNormal: (isInsecure?: boolean) => number;
randomExponential: (isInsecure?: boolean) => number;
randomXenakis: (isInsecure?: boolean) => number;
randomProb: (prob: number, isInsecure?: boolean) => boolean;
getUuidFromBytes: (arr: BufferSource) => string;
getRandomUuid: (isInsecure?: boolean) => string;
validateUuid: (uuid: string) => boolean;
callAsync: <argumentType, returnType>(callback: (... argumentsList: argumentType[]) => MaybePromise<returnType>, thisArgument: any, ... argumentList: argumentType[]) => Promise<returnType>;
toPromise: <T>(value: MaybePromise<T>) => Promise<T>;
getTime: () => number;
encodeJson: (value: any) => Uint8Array;
decodeJson: (bytes: BufferSource) => any;
assert: (assertion: boolean, message?: string) => void;
IdentityConstructor: new <T>(obj: T) => T;
SymbolObject: new (symbol: symbol | SymbolObject) => SymbolObject;
}
License
Copyright © 2021 Menhera.org
Licensed under the Apache 2.0 license.