Options
All
  • Public
  • Public/Protected
  • All
Menu

Holds state on already used names and provides new names if there are naming conflicts.

Hierarchy

  • UniqueNameFinder

Index

Constructors

constructor

  • new UniqueNameFinder(separator?: Separator, usedNames?: string[]): UniqueNameFinder
  • Creates an instance of UniqueNameFinder.

    Parameters

    • Default value separator: Separator = "_"

      The separator to be used

    • Default value usedNames: string[] = []

      Sets the already used names considered in the finding process. Reserved TS keywords are always checked.

    Returns UniqueNameFinder

Methods

addToUsedNames

  • addToUsedNames(...names: string[]): this

findUniqueName

  • findUniqueName(name: string, caseSensitive?: boolean): string
  • Find a unique name by appending a suffix of the form this.separator\d+ if necessary. If the name is already unique nothing is appended.

    Parameters

    • name: string

      The name to get a unique name from.

    • Default value caseSensitive: boolean = true

      Whether to check the already used names in a case sensitive manner.

    Returns string

    A unique name

findUniqueNameWithSuffixes

  • findUniqueNameWithSuffixes(name: string, suffixes: string[], caseSensitive?: boolean): string[]
  • Find a unique name by appending a suffix of the form this.separator\d+ if necessary. If the name is already unique nothing is appended. The suffixes are a list of strings appended to the name and these build names are also checked for uniqueness.

    Parameters

    • name: string

      The name to get a unique name from

    • suffixes: string[]

      Additional name suffixed to be considered

    • Default value caseSensitive: boolean = true

      Whether to check the already used names in a case sensitive manner.

    Returns string[]

    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.