12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- 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;
- }
|