@handy-common-utils/misc-utils
Version:
Miscellaneous utilities
75 lines • 5.57 kB
TypeScript
/**
* Make a "normal" (BASE64) string URL/path safe.
* @param base64Input A (BASE64) string which could be null or undefined.
* @param replacements A string containing replacement characters for "/", "+", and "=".
* If omitted, default value of '_-=' would be used.
* @returns URL/path safe version of the (BASE64) input string, or the original input if it is null or undefined.
*/
export declare function urlSafe<T extends string | undefined | null>(base64Input: T, replacements?: string): T;
/**
* Encode an unsigned 32-bit integer into BASE64 string.
* @param ui32 A 32-bit integer number which could also be null or undefined.
* It must be a valid unsigned 32-bit integer. Behavior is undefined when the value is anything other than an unsigned 32-bit integer.
* If you don't care about loosing precision, you can convert a number by doing `n >>> 0` (See https://stackoverflow.com/questions/22335853/hack-to-convert-javascript-number-to-uint32)
* @returns BASE64 string representing the integer input, or the original input if it is null or undefined.
*/
export declare function base64FromUInt32<T extends number | undefined | null>(ui32: T): Exclude<T, number> | string;
/**
* Encode an unsigned 32-bit integer into BASE64 string without trailing '='.
* @param ui32 A 32-bit integer number which could also be null or undefined.
* It must be a valid unsigned 32-bit integer. Behavior is undefined when the value is anything other than an unsigned 32-bit integer.
* If you don't care about loosing precision, you can convert a number by doing `n >>> 0` (See https://stackoverflow.com/questions/22335853/hack-to-convert-javascript-number-to-uint32)
* @returns BASE64 string without trailing '=' representing the integer input, or the original input if it is null or undefined.
*/
export declare function shortBase64FromUInt32<T extends number | undefined | null>(ui32: T): Exclude<T, number> | string;
/**
* Encode an unsigned 32-bit integer into URL/path safe BASE64 string.
* @param ui32 A 32-bit integer number which could also be null or undefined.
* It must be a valid unsigned 32-bit integer. Behavior is undefined when the value is anything other than an unsigned 32-bit integer.
* If you don't care about loosing precision, you can convert a number by doing `n >>> 0` (See https://stackoverflow.com/questions/22335853/hack-to-convert-javascript-number-to-uint32)
* @param replacements A string containing replacement characters for "/", "+", and "=".
* If omitted, default value of '_-=' would be used.
* @returns URL/path safe BASE64 string representing the integer input, or the original input if it is null or undefined.
*/
export declare function base64UrlFromUInt32<T extends number | undefined | null>(ui32: T, replacements?: string): Exclude<T, number> | string;
/**
* Encode an unsigned 32-bit integer into URL/path safe BASE64 string without trailing '='.
* @param ui32 A 32-bit integer number which could also be null or undefined.
* It must be a valid unsigned 32-bit integer. Behavior is undefined when the value is anything other than an unsigned 32-bit integer.
* If you don't care about loosing precision, you can convert a number by doing `n >>> 0` (See https://stackoverflow.com/questions/22335853/hack-to-convert-javascript-number-to-uint32)
* @param replacements A string containing replacement characters for "/" and "+".
* If omitted, default value of '_-' would be used.
* @returns URL/path safe BASE64 string without trailing '=' representing the integer input, or the original input if it is null or undefined.
*/
export declare function shortBase64UrlFromUInt32<T extends number | undefined | null>(ui32: T, replacements?: string): Exclude<T, number> | string;
/**
* Generate a strong (using crypto.randomFillSync(...)) random string that is URL/path safe.
* In the generated string, approximately every 6 characters represent randomly generated 32 bits.
* For example, if you need 128 bits of randomness, you just need to generate a string containing 24 characters.
* @param len length of the string to be generated
* @returns the random string
*/
export declare function generateRandomString(len: number): string;
/**
* Generate a weak (using Math.random()) random string that is URL/path safe.
* In the generated string, approximately every 6 characters represent randomly generated 32 bits.
* For example, if you need 128 bits of randomness, you just need to generate a string containing 24 characters.
* @param len length of the string to be generated
* @returns the random string
*/
export declare function generateRandomStringQuickly(len: number): string;
/**
* Escape a string literal for using it inside of RegExp.
* (From: https://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex)
* @param text the string literal to be escaped
* @returns escaped string that can be used inside of RegExp, or an empty string if the input is null or undefined
*/
export declare function escapeForRegExp(text: string | undefined | null): string;
/**
* Escape replacement string for using it inside of RegExp replacement parameter.
* (From: https://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex)
* @param text the replacement string to be escaped, or an empty string if the input is null or undefined
* @returns escaped replacement string that can be used inside of RegExp replacement parameter
*/
export declare function escapeForRegExpReplacement(text: string | undefined | null): string;
//# sourceMappingURL=codec.d.ts.map