@acusti/uniquify
Version:
Generate a unique string (e.g. for filenames or url slugs) using an incremental counter
26 lines (25 loc) • 1.11 kB
TypeScript
type GenericObject = Record<string, unknown>;
type Items = Array<GenericObject | null | undefined> | Array<null | string | undefined>;
type StringKeyPath = Array<string>;
/**
* Escapes the RegExp special characters "^", "$", "\\", ".", "*", "+", "?", "(", ")", "[", "]", "{", "}", and "|" in `str`.
*
* @param {string} str The string to escape.
* @returns {string} Returns the escaped string.
*
* @example
* escapeRegExp('[uniquify](https://github.com/acusti/uikit/tree/main/packages/uniquify)'); // returns '\[uniquify\]\(https://github\.com/acusti/uikit/tree/main/packages/uniquify\)'
*/
export declare const escapeRegExp: (str: string) => string;
declare const uniquify: ({ caseSensitive, identify1AsCounter, isSuffixOptional, items, propertyPath, propertyPathAlternate, separator, suffix, value, }: {
caseSensitive?: boolean;
identify1AsCounter?: boolean;
isSuffixOptional?: boolean;
items: Items;
propertyPath?: StringKeyPath;
propertyPathAlternate?: StringKeyPath;
separator?: string;
suffix?: string;
value: string;
}) => string;
export default uniquify;