@sap-cloud-sdk/util
Version:
SAP Cloud SDK for JavaScript general utilities
72 lines (71 loc) • 4.26 kB
TypeScript
/**
* Holds state on already used names and provides new names if there are naming conflicts.
*/
export declare class UniqueNameGenerator {
private indexSeparator;
private static readonly MAXIMUM_NUMBER_OF_SUFFIX;
private static getNameForComparison;
private usedNames;
/**
* Creates an instance of UniqueNameGenerator.
* @param indexSeparator - The separator to be used when adding an index.
* @param usedNames - Sets the already used names considered in the finding process.
*/
constructor(indexSeparator?: string, usedNames?: readonly string[]);
/**
* Adds the name(s) to the already used names.
* @param names - Names to be added.
*/
addToUsedNames(...names: string[]): void;
/**
* Generate a unique name by appending an index separated by the `indexSeparator` if necessary, e.g. if `MyName` is already taken `MyName_1` will be found by default.
* If the name is already unique nothing is appended.
* @param name - The name to get a unique name from.
* @param caseSensitive - Whether to check the already used names in a case sensitive manner.
* @returns A unique name.
*/
generateUniqueName(name: string, caseSensitive?: boolean): string;
/**
* Generate a unique name by appending an index separated by the `indexSeparator` if necessary, e.g. if `MyName` is already taken `MyName_1` will be found by default.
* The generated name is added to the used names.
* If the name is already unique nothing is appended.
* @param name - The name to get a unique name from.
* @param caseSensitive - Whether to check the already used names in a case sensitive manner.
* @returns A unique name.
*/
generateAndSaveUniqueName(name: string, caseSensitive?: boolean): string;
/**
* Generate unique names by appending an index separated by the `indexSeparator` if necessary, while respecting the given suffixes.
* If the name is already unique nothing is appended.
* Each given suffix is appended to the unique name in the result.
* The resulting names are also checked for uniqueness.
* All names in the result have the same number suffix.
* @example if `MyName` and `MyName_1MySuffix` is already taken, `[MyName_2, MyName_2MySuffix]` will be generated by default.
* @param name - The name to get a unique name from.
* @param suffixes - Additional name of suffixes to be considered for the finding process, as well as the output.
* @param caseSensitive - Whether to check the already used names in a case sensitive manner.
* @returns A list of unique names. The length of this array is one plus the number of suffixes provided. The first entry corresponds to the given name.
*/
generateUniqueNamesWithSuffixes(name: string, suffixes: string[], caseSensitive?: boolean): string[];
/**
* Generate unique names by appending an index separated by the `indexSeparator` if necessary, while respecting the given suffixes.
* If the name is already unique nothing is appended.
* The generated names are added to the used names.
* Each given suffix is appended to the unique name in the result.
* The resulting names are also checked for uniqueness.
* All names in the result have the same number suffix.
* @example if `MyName` and `MyName_1MySuffix` is already taken, `[MyName_2, MyName_2MySuffix]` will be generated by default.
* @param name - The name to get a unique name from.
* @param suffixes - Additional name of suffixes to be considered for the finding process, as well as the output.
* @param caseSensitive - Whether to check the already used names in a case sensitive manner.
* @returns A list of unique names. The length of this array is one plus the number of suffixes provided. The first entry corresponds to the given name.
*/
generateAndSaveUniqueNamesWithSuffixes(name: string, suffixes: string[], caseSensitive?: boolean): string[];
private getUsedNamesForComparison;
private areNamesUsed;
private generateNamesWithIndexAndSuffixes;
private generateNamesWithSuffixes;
private getUsedNamesStartingWith;
private getUniqueIndex;
private getNameWithoutIndex;
}