import { inject, injectable } from 'inversify'; import { ServiceIdentifiers } from '../../container/ServiceIdentifiers'; import { IIdentifierNamesGenerator } from '../../interfaces/generators/identifier-names-generators/IIdentifierNamesGenerator'; import { IOptions } from '../../interfaces/options/IOptions'; import { IRandomGenerator } from '../../interfaces/utils/IRandomGenerator'; @injectable() export abstract class AbstractIdentifierNamesGenerator implements IIdentifierNamesGenerator { /** * @type {string} */ protected readonly identifiersPrefix: string; /** * @type {IOptions} */ protected readonly options: IOptions; /** * @type {IRandomGenerator} */ protected readonly randomGenerator: IRandomGenerator; /** * @param {IRandomGenerator} randomGenerator * @param {IOptions} options */ constructor ( @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator, @inject(ServiceIdentifiers.IOptions) options: IOptions ) { this.randomGenerator = randomGenerator; this.options = options; this.identifiersPrefix = this.options.identifiersPrefix === true ? this.randomGenerator.getRandomString(3) : this.options.identifiersPrefix || ''; } /** * @param {number} length * @returns {string} */ public abstract generate (length: number): string; }