interface-forge - v2.5.0
    Preparing search index...

    Class StringModule

    Module to generate string related entries.

    For a string containing just A-Z characters, use alpha(). To add digits too, use alphanumeric(). If you only want punctuation marks/symbols, use symbol(). For a full set of ASCII characters, use sample(). For a custom set of characters, use fromCharacters().

    For strings of base-ten digits, use numeric(). For other bases, use binary(), octal(), or hexadecimal()).

    You can generate standard ID strings using uuid() or nanoid().

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    Methods

    • Generating a string consisting of letters in the English alphabet.

      Parameters

      • Optionaloptions:
            | number
            | {
                casing?: Casing;
                exclude?: string
                | readonly LiteralUnion<AlphaChar, string>[];
                length?: number | { max: number; min: number };
            }

        Either the length of the string to generate or the optional options object.

        • number
        • {
              casing?: Casing;
              exclude?: string | readonly LiteralUnion<AlphaChar, string>[];
              length?: number | { max: number; min: number };
          }
          • Optionalcasing?: Casing

            The casing of the characters.

            'mixed'
            
          • Optionalexclude?: string | readonly LiteralUnion<AlphaChar, string>[]

            An array with characters which should be excluded in the generated string.

            []
            
          • Optionallength?: number | { max: number; min: number }

            The length of the string to generate either as a fixed length or as a length range.

            1
            

      Returns string

      faker.string.alpha() // 'b'
      faker.string.alpha(10) // 'fEcAaCVbaR'
      faker.string.alpha({ length: { min: 5, max: 10 } }) // 'HcVrCf'
      faker.string.alpha({ casing: 'lower' }) // 'r'
      faker.string.alpha({ exclude: ['W'] }) // 'Z'
      faker.string.alpha({ length: 5, casing: 'upper', exclude: ['A'] }) // 'DTCIC'

      8.0.0

    • Generating a string consisting of alpha characters and digits.

      Parameters

      • Optionaloptions:
            | number
            | {
                casing?: Casing;
                exclude?: string
                | readonly LiteralUnion<AlphaNumericChar, string>[];
                length?: number | { max: number; min: number };
            }

        Either the length of the string to generate or the optional options object.

        • number
        • {
              casing?: Casing;
              exclude?: string | readonly LiteralUnion<AlphaNumericChar, string>[];
              length?: number | { max: number; min: number };
          }
          • Optionalcasing?: Casing

            The casing of the characters.

            'mixed'
            
          • Optionalexclude?: string | readonly LiteralUnion<AlphaNumericChar, string>[]

            An array of characters and digits which should be excluded in the generated string.

            []
            
          • Optionallength?: number | { max: number; min: number }

            The length of the string to generate either as a fixed length or as a length range.

            1
            

      Returns string

      faker.string.alphanumeric() // '2'
      faker.string.alphanumeric(5) // '3e5V7'
      faker.string.alphanumeric({ length: { min: 5, max: 10 } }) // 'muaApG'
      faker.string.alphanumeric({ casing: 'upper' }) // 'A'
      faker.string.alphanumeric({ exclude: ['W'] }) // 'r'
      faker.string.alphanumeric({ length: 5, exclude: ["a"] }) // 'x1Z7f'

      8.0.0

    • Returns a binary string.

      Parameters

      • Optionaloptions: { length?: number | { max: number; min: number }; prefix?: string }

        The optional options object.

        • Optionallength?: number | { max: number; min: number }

          The length of the string (excluding the prefix) to generate either as a fixed length or as a length range.

          1
          
        • Optionalprefix?: string

          Prefix for the generated number.

          '0b'
          

      Returns string

      faker.number.binary(): For generating a binary number (within a range).

      faker.string.binary() // '0b1'
      faker.string.binary({ length: 10 }) // '0b1101011011'
      faker.string.binary({ length: { min: 5, max: 10 } }) // '0b11101011'
      faker.string.binary({ prefix: '0b' }) // '0b1'
      faker.string.binary({ length: 10, prefix: 'bin_' }) // 'bin_1101011011'

      8.0.0

    • Generates a string from the given characters.

      Parameters

      • characters: string | readonly string[]

        The characters to use for the string. Can be a string or an array of characters. If it is an array, then each element is treated as a single character even if it is a string with multiple characters.

      • Optionallength: number | { max: number; min: number }

        The length of the string to generate either as a fixed length or as a length range. Defaults to 1.

        • number
        • { max: number; min: number }
          • max: number

            The maximum length of the string to generate.

          • min: number

            The minimum length of the string to generate.

      Returns string

      faker.string.fromCharacters('abc') // 'c'
      faker.string.fromCharacters(['a', 'b', 'c']) // 'a'
      faker.string.fromCharacters('abc', 10) // 'cbbbacbacb'
      faker.string.fromCharacters('abc', { min: 5, max: 10 }) // 'abcaaaba'

      8.0.0

    • Returns a hexadecimal string.

      Parameters

      • Optionaloptions: {
            casing?: Casing;
            length?: number | { max: number; min: number };
            prefix?: string;
        }

        The optional options object.

        • Optionalcasing?: Casing

          Casing of the generated number.

          'mixed'
          
        • Optionallength?: number | { max: number; min: number }

          The length of the string (excluding the prefix) to generate either as a fixed length or as a length range.

          1
          
        • Optionalprefix?: string

          Prefix for the generated number.

          '0x'
          

      Returns string

      faker.string.hexadecimal() // '0xB'
      faker.string.hexadecimal({ length: 10 }) // '0xaE13d044cB'
      faker.string.hexadecimal({ length: { min: 5, max: 10 } }) // '0x7dEf7FCD'
      faker.string.hexadecimal({ prefix: '0x' }) // '0xE'
      faker.string.hexadecimal({ casing: 'lower' }) // '0xf'
      faker.string.hexadecimal({ length: 10, prefix: '#' }) // '#f12a974eB1'
      faker.string.hexadecimal({ length: 10, casing: 'upper' }) // '0xE3F38014FB'
      faker.string.hexadecimal({ casing: 'lower', prefix: '' }) // 'd'
      faker.string.hexadecimal({ length: 10, casing: 'mixed', prefix: '0x' }) // '0xAdE330a4D1'

      8.0.0

    • Generates a Nano ID.

      Parameters

      • Optionallength: number | { max: number; min: number }

        The length of the string to generate either as a fixed length or as a length range. Defaults to 21.

        • number
        • { max: number; min: number }
          • max: number

            The maximum length of the Nano ID to generate.

          • min: number

            The minimum length of the Nano ID to generate.

      Returns string

      faker.string.nanoid() // ptL0KpX_yRMI98JFr6B3n
      faker.string.nanoid(10) // VsvwSdm_Am
      faker.string.nanoid({ min: 13, max: 37 }) // KIRsdEL9jxVgqhBDlm

      8.0.0

    • Generates a given length string of digits.

      Parameters

      • Optionaloptions:
            | number
            | {
                allowLeadingZeros?: boolean;
                exclude?: string
                | readonly LiteralUnion<NumericChar, string>[];
                length?: number | { max: number; min: number };
            }

        Either the length of the string to generate or the optional options object.

        • number
        • {
              allowLeadingZeros?: boolean;
              exclude?: string | readonly LiteralUnion<NumericChar, string>[];
              length?: number | { max: number; min: number };
          }
          • OptionalallowLeadingZeros?: boolean

            Whether leading zeros are allowed or not.

            true
            
          • Optionalexclude?: string | readonly LiteralUnion<NumericChar, string>[]

            An array of digits which should be excluded in the generated string.

            []
            
          • Optionallength?: number | { max: number; min: number }

            The length of the string to generate either as a fixed length or as a length range.

            1
            

      Returns string

      faker.number.int(): For generating a number (within a range).

      faker.string.numeric() // '2'
      faker.string.numeric(5) // '31507'
      faker.string.numeric(42) // '06434563150765416546479875435481513188548'
      faker.string.numeric({ length: { min: 5, max: 10 } }) // '197089478'
      faker.string.numeric({ length: 42, allowLeadingZeros: false }) // '72564846278453876543517840713421451546115'
      faker.string.numeric({ length: 6, exclude: ['0'] }) // '943228'

      8.0.0

    • Returns an octal string.

      Parameters

      • Optionaloptions: { length?: number | { max: number; min: number }; prefix?: string }

        The optional options object.

        • Optionallength?: number | { max: number; min: number }

          The length of the string (excluding the prefix) to generate either as a fixed length or as a length range.

          1
          
        • Optionalprefix?: string

          Prefix for the generated number.

          '0o'
          

      Returns string

      faker.number.octal(): For generating an octal number (within a range).

      faker.string.octal() // '0o3'
      faker.string.octal({ length: 10 }) // '0o1526216210'
      faker.string.octal({ length: { min: 5, max: 10 } }) // '0o15263214'
      faker.string.octal({ prefix: '0o' }) // '0o7'
      faker.string.octal({ length: 10, prefix: 'oct_' }) // 'oct_1542153414'

      8.0.0

    • Returns a string containing UTF-16 chars between 33 and 125 (! to }).

      Parameters

      • Optionallength: number | { max: number; min: number }

        The length of the string (excluding the prefix) to generate either as a fixed length or as a length range. Defaults to 10.

        • number
        • { max: number; min: number }
          • max: number

            The maximum length of the string to generate.

          • min: number

            The minimum length of the string to generate.

      Returns string

      faker.string.sample() // 'Zo!.:*e>wR'
      faker.string.sample(5) // '6Bye8'
      faker.string.sample({ min: 5, max: 10 }) // 'FeKunG'

      8.0.0

    • Returns a string containing only special characters from the following list:

      ! " # $ % & ' ( ) * + , - . / : ; < = > ? @ [ \ ] ^ _ ` { | } ~
      

      Parameters

      • Optionallength: number | { max: number; min: number }

        The length of the string to generate either as a fixed length or as a length range. Defaults to 1.

        • number
        • { max: number; min: number }
          • max: number

            The maximum length of the string to generate.

          • min: number

            The minimum length of the string to generate.

      Returns string

      faker.string.symbol() // '$'
      faker.string.symbol(5) // '#*!.~'
      faker.string.symbol({ min: 5, max: 10 }) // ')|@*>^+'

      8.0.0

    • Parameters

      • Optionaloptions: { refDate?: string | number | Date }

        The optional options object.

        • OptionalrefDate?: string | number | Date

          The date to use as reference point for the newly generated ULID encoded timestamp. The encoded timestamp is represented by the first 10 characters of the result.

          faker.defaultRefDate()
          

      Returns string

      faker.string.ulid() // '01ARZ3NDEKTSV4RRFFQ69G5FAV'
      faker.string.ulid({ refDate: '2020-01-01T00:00:00.000Z' }) // '01DXF6DT00CX9QNNW7PNXQ3YR8'

      9.1.0

    • Returns a UUID v4 (Universally Unique Identifier).

      Returns string

      faker.string.uuid() // '4136cd0b-d90b-4af7-b485-5d1ded8db252'
      

      8.0.0