MCPcopy
hub / github.com/faker-js/faker / hexadecimal

Method hexadecimal

src/modules/string/index.ts:472–546  ·  view source on GitHub ↗

* Returns a [hexadecimal](https://en.wikipedia.org/wiki/Hexadecimal) string. * * @param options The optional options object. * @param options.length The length of the string (excluding the prefix) to generate either as a fixed length or as a length range. Defaults to `1`. * @param option

(
    options: {
      /**
       * The length of the string (excluding the prefix) to generate either as a fixed length or as a length range.
       *
       * @default 1
       */
      length?:
        | number
        | {
            /**
             * The minimum length of the string (excluding the prefix) to generate.
             */
            min: number;
            /**
             * The maximum length of the string (excluding the prefix) to generate.
             */
            max: number;
          };
      /**
       * Casing of the generated number.
       *
       * @default 'mixed'
       */
      casing?: Casing;
      /**
       * Prefix for the generated number.
       *
       * @default '0x'
       */
      prefix?: string;
    } = {}
  )

Source from the content-addressed store, hash-verified

470 * @since 8.0.0
471 */
472 hexadecimal(
473 options: {
474 /**
475 * The length of the string (excluding the prefix) to generate either as a fixed length or as a length range.
476 *
477 * @default 1
478 */
479 length?:
480 | number
481 | {
482 /**
483 * The minimum length of the string (excluding the prefix) to generate.
484 */
485 min: number;
486 /**
487 * The maximum length of the string (excluding the prefix) to generate.
488 */
489 max: number;
490 };
491 /**
492 * Casing of the generated number.
493 *
494 * @default 'mixed'
495 */
496 casing?: Casing;
497 /**
498 * Prefix for the generated number.
499 *
500 * @default '0x'
501 */
502 prefix?: string;
503 } = {}
504 ): string {
505 const { casing = 'mixed', prefix = '0x' } = options;
506 const length = this.faker.helpers.rangeToNumber(options.length ?? 1);
507 if (length <= 0) {
508 return prefix;
509 }
510
511 let wholeString = this.fromCharacters(
512 [
513 '0',
514 '1',
515 '2',
516 '3',
517 '4',
518 '5',
519 '6',
520 '7',
521 '8',
522 '9',
523 'a',
524 'b',
525 'c',
526 'd',
527 'e',
528 'f',
529 'A',

Callers 6

string.spec.tsFile · 0.80
mongodbObjectIdMethod · 0.80
commitShaMethod · 0.80
rgbMethod · 0.80
ethereumAddressMethod · 0.80
ipv6Method · 0.80

Calls 2

fromCharactersMethod · 0.95
rangeToNumberMethod · 0.80

Tested by

no test coverage detected