UNPKG

@casual-simulation/aux-common

Version:
72 lines 2.93 kB
/** * Merges the two objects and returns a new object that contains the combination of the two. * This is a sane merge. That means arrays are copied and if nothing needs merging then nothing changes. * @param obj * @param next */ export declare function merge<T1, T2>(first: T1, second: T2): T1 & T2; export declare function merge<T1, T2, T3>(first: T1, second: T2, third: T3): T1 & T2 & T3; export declare function merge<T1, T2, T3, T4>(first: T1, second: T2, third: T3, fourth: T4): T1 & T2 & T3 & T4; /** * Maps all the values of the given object. * @param value The object to map. * @param callback The callback that transforms one value into another. */ export declare function mapValuesDeep(value: any, callback: (v: any) => any): any; /** * Splices the given string and returns the final result. * @param str The string to splice. * @param index The index that the splice should be started at. * @param deleteCount The number of characters to delete. * @param text The text to insert. */ export declare function splice(str: string, index: number, deleteCount: number, text: string): string; export declare function lerp(start: number, end: number, t: number): number; export declare function clamp(value: number, min: number, max: number): number; export declare function normalize(value: number, min: number, max: number): number; export declare function unnormalize(normal: number, min: number, max: number): number; /** * Creates and returns a short 8 character UUID (no dashes). */ export declare function shortUuid(): string; /** * Converts the given string from dot case (dot.case) to camel case (camelCase). * @param dotCase The string to convert. */ export declare function dotCaseToCamelCase(dotCase: string): string; /** * Determines if the given value might represent an email address. * @param value The value to check. */ export declare function mightBeEmailAddress(value: string): boolean; /** * Trims the given value and removes characters that are not valid in a phone number. * Returns null if the value is definitely not a phone number. * @param value The value that should be cleaned. */ export declare function cleanPhoneNumber(value: string): string; /** * Converts the given string into a base64 string. * @param str The string to convert. */ export declare function toBase64String(str: string): string; /** * Converts the given string from a base64 string. * @param base64 */ export declare function fromBase64String(base64: string): string; /** * Tries to parse the given JSON string into a JavaScript Value. * @param json The JSON to parse. */ export declare function tryParseJson(json: string): JsonParseResult; export type JsonParseResult = JsonParseSuccess | JsonParseFailure; export interface JsonParseSuccess { success: true; value: any; } export interface JsonParseFailure { success: false; error: unknown; } //# sourceMappingURL=utils.d.ts.map