StringArrayHexadecimalNumericStringIndexNode.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. import { inject, injectable } from 'inversify';
  2. import * as ESTree from 'estree';
  3. import { IOptions } from '../../../interfaces/options/IOptions';
  4. import { IRandomGenerator } from '../../../interfaces/utils/IRandomGenerator';
  5. import { ServiceIdentifiers } from '../../../container/ServiceIdentifiers';
  6. import { AbstractStringArrayIndexNode } from './AbstractStringArrayIndexNode';
  7. import { NodeFactory } from '../../../node/NodeFactory';
  8. import { NumberUtils } from '../../../utils/NumberUtils';
  9. @injectable()
  10. export class StringArrayHexadecimalNumericStringIndexNode extends AbstractStringArrayIndexNode {
  11. /**
  12. * @param {IRandomGenerator} randomGenerator
  13. * @param {IOptions} options
  14. */
  15. public constructor (
  16. @inject(ServiceIdentifiers.IRandomGenerator) randomGenerator: IRandomGenerator,
  17. @inject(ServiceIdentifiers.IOptions) options: IOptions
  18. ) {
  19. super(randomGenerator, options);
  20. }
  21. /**
  22. * @param {number} index
  23. * @returns {Expression}
  24. */
  25. public getNode (index: number): ESTree.Expression {
  26. const hexadecimalIndex: string = NumberUtils.toHex(index);
  27. return NodeFactory.literalNode(hexadecimalIndex);
  28. }
  29. }