UNPKG

@authup/kit

Version:

A Package containing general (context independent) utilities.

116 lines 4.62 kB
//#region src/constants.d.ts declare enum DecisionStrategy { /** * One or more positive */ AFFIRMATIVE = "affirmative", /** * All positive */ UNANIMOUS = "unanimous", /** * More positive than negative */ CONSENSUS = "consensus" } declare enum EnvironmentName { PRODUCTION = "production", TEST = "test", DEVELOPMENT = "development" } //#endregion //#region src/array.d.ts declare function toArray<T>(input?: T | T[]): T[]; declare function toStringArray<T>(input?: T | T[]): string[]; declare function toArrayElement<T>(input?: T | T[]): T | undefined; //#endregion //#region src/array-buffer.d.ts declare function arrayBufferToBase64(buffer: ArrayBuffer): string; //#endregion //#region src/base64.d.ts declare function base64ToArrayBuffer(base64: string): ArrayBuffer; /** * @see https://thewoods.blog/base64url/ * * @param input */ declare function base64URLEncode(input: string): string; /** * @see https://thewoods.blog/base64url/ * * @param value */ declare function base64URLDecode(value: string): string; //#endregion //#region src/bcrypt.d.ts /** * Check if an input string might be a bcrypt hash. * * @see https://stackoverflow.com/questions/5393803/can-someone-explain-how-bcrypt-verifies-a-hash * @param input */ declare function isBCryptHash(input: string): boolean; //#endregion //#region src/has-own-property.d.ts declare function hasOwnProperty<X extends {}, Y extends PropertyKey>(obj: X, prop: Y): obj is X & Record<Y, unknown>; declare function isPropertySet<X extends Record<string, any>, K extends keyof X>(obj: X, prop: K): boolean; //#endregion //#region src/is-simple-match.d.ts declare function isSimpleMatch(value: string, pattern: string | string[]): boolean; //#endregion //#region src/nanoid.d.ts declare function createNanoID(alphabet?: string): string; declare function createNanoID(len?: number): string; declare function createNanoID(alphabet?: string, len?: number): string; //#endregion //#region src/types.d.ts type ObjectLiteral = Record<string | number, any>; type Result<T> = { success: true; data: T; } | { success: false; error: Error; }; type ObjectRequired<T extends ObjectLiteral, Key extends keyof T> = Pick<T, Key> & Partial<Omit<T, Key>>; type ObjectOptional<T extends ObjectLiteral, Key extends keyof T> = ObjectRequired<T, Exclude<keyof T, Key>>; //#endregion //#region src/object.d.ts declare function isObject(input: unknown): input is Record<string, any>; declare function extendObject<T extends Record<string, any>>(target: T, source: Partial<T>): T; declare function flattenObject(input: Record<string, any>): Record<string, any>; declare function removeObjectProperty<T extends ObjectLiteral>(input: Partial<T>, key: keyof T): void; declare function omitObjectProperties<T extends ObjectLiteral>(input: Record<string, any>, excludeKeys: (keyof T)[]): T; //#endregion //#region src/pick.d.ts type PickRecord<T extends Record<string, any>, S extends keyof T> = { [K in S]: K extends keyof T ? T[K] : never }; declare function pickRecord<T extends Record<string, any>, K extends keyof T>(data: T, keys: K[]): PickRecord<T, K>; type OmitRecord<T extends Record<string, any>, S extends keyof T> = { [K in Exclude<keyof T, S>]: T[K] }; declare function omitRecord<T extends Record<string, any>, K extends keyof T>(data: T, keys: K[]): OmitRecord<T, K>; //#endregion //#region src/scalar.d.ts declare function isScalar(value: unknown): value is string | number | boolean | null | undefined; //#endregion //#region src/serialize.d.ts declare function serialize(input: unknown): string; declare function deserialize<T = any>(input: any): T; //#endregion //#region src/template.d.ts declare function template(str: string, data: Record<string, any>, regex?: RegExp): string; //#endregion //#region src/uuid.d.ts declare function isUUID(input: string): boolean; //#endregion //#region src/url.d.ts declare function makeURLPublicAccessible(url: string): string; //#endregion //#region src/wait.d.ts /** * Wait for x ms. * * @param ms */ declare function wait(ms: number): Promise<void>; //#endregion export { DecisionStrategy, EnvironmentName, ObjectLiteral, ObjectOptional, ObjectRequired, Result, arrayBufferToBase64, base64ToArrayBuffer, base64URLDecode, base64URLEncode, createNanoID, deserialize, extendObject, flattenObject, hasOwnProperty, isBCryptHash, isObject, isPropertySet, isScalar, isSimpleMatch, isUUID, makeURLPublicAccessible, omitObjectProperties, omitRecord, pickRecord, removeObjectProperty, serialize, template, toArray, toArrayElement, toStringArray, wait }; //# sourceMappingURL=index.d.mts.map