Scalar functions
string
Commentary
added in 0.0.5
Generates strings which may be templated with #{}
, containing the names of local identifiers 1, variables 2, or Java Datafaker expressions 3 (Datafaker version 2.4.1
). Local identifiers will be resolved first, then vars, then Faker expressions.
Datafaker functions that take parameters must be invoked with single quotes and no spaces, as in #{Date.birthday '2','4'}
. 4
You may occasionally want to change the shape of the strings Datafaker generates. The string
function supports a handful of transforms. 5
By default, strings are generated with a locale configured for United States English, but you can override this. 6
Faker expressions and values
Use any of these expressions in the form of #{expr}
. Where applicable, links are supplied to the literal value list within the Datafaker project.
- Address.countyByZipCode †
- Address.countyByZipCode †
- Address.fullAddress †
- Address.cityName †
- Address.citySuffix †
- Address.zipCodeByState †
- Address.streetSuffix †
- Address.streetPrefix †
- Address.latitude †
- Address.timeZone †
- Address.stateAbbr †
- Address.streetName †
- Address.buildingNumber †
- Address.firstName †
- Address.state †
- Address.zipCode †
- Address.streetAddress †
- Address.streetAddressNumber †
- Address.countryCode †
- Address.country †
- Address.lastName †
- Address.city †
- Address.longitude †
- Address.secondaryAddress †
- Address.cityPrefix †
- Ancient.primordial †
- Ancient.god †
- Ancient.hero †
- Ancient.titan †
- Animal.name †
- App.version †
- App.name †
- App.author †
- AquaTeenHungerForce.character †
- Artist.name †
- Avatar.image †
- Aviation.aircraft †
- Aviation.METAR †
- Aviation.airport †
- BackToTheFuture.character †
- BackToTheFuture.date †
- BackToTheFuture.quote †
- Beer.style †
- Beer.name †
- Beer.malt †
- Beer.hop †
- Beer.yeast †
- Book.genre †
- Book.title †
- Book.author †
- Book.publisher †
- Bool.bool
- Buffy.celebrities †
- Buffy.episodes †
- Buffy.quotes †
- Buffy.bigBads †
- Buffy.characters †
- Business.creditCardNumber †
- Business.creditCardType †
- Business.creditCardExpiry †
- Cat.registry †
- Cat.name †
- Cat.breed †
- ChuckNorris.fact †
- Code.imei †
- Code.ean8 †
- Code.gtin8 †
- Code.isbnGs1 †
- Code.isbn10 †
- Code.asin †
- Code.ean13
- Code.gtin13
- Code.isbnRegistrant
- Code.isbn13
- Code.isbnGroup
- Color.name †
- Color.hex
- Commerce.promotionCode †
- Commerce.material †
- Commerce.department †
- Commerce.price
- Commerce.productName †
- Commerce.color †
- Company.profession †
- Company.industry †
- Company.catchPhrase †
- Company.buzzword †
- Company.suffix †
- Company.logo †
- Company.name †
- Company.bs †
- Company.url †
- Country.capital †
- Country.countryCode2 †
- Country.name †
- Country.flag †
- Country.countryCode3 †
- Country.currencyCode †
- Country.currency †
- Crypto.md5
- Crypto.sha256
- Crypto.sha1
- Crypto.sha512
- Currency.code †
- Currency.name †
- Date.birthday
- Date.future
- Date.between
- Date.past
- Demographic.maritalStatus †
- Demographic.race †
- Demographic.demonym †
- Demographic.sex †
- Demographic.educationalAttainment †
- Dog.memePhrase †
- Dog.breed †
- Dog.name †
- Dog.sound †
- Dog.age †
- Dog.coatLength †
- Dog.gender †
- Dog.size †
- DragonBall.character †
- Dune.saying †
- Dune.character †
- Dune.planet †
- Dune.title †
- Dune.quote †
- Educator.university †
- Educator.campus †
- Educator.secondarySchool †
- Educator.course †
- ElderScrolls.quote †
- ElderScrolls.city †
- ElderScrolls.lastName †
- ElderScrolls.region †
- ElderScrolls.firstName †
- ElderScrolls.dragon †
- ElderScrolls.creature †
- ElderScrolls.race †
- Esports.game †
- Esports.league †
- Esports.event †
- Esports.player †
- Esports.team †
- File.fileName
- File.mimeType †
- File.extension †
- Finance.bic †
- Finance.iban †
- Finance.creditCard †
- Food.dish †
- Food.spice †
- Food.ingredient †
- Food.vegetable †
- Food.measurement †
- Food.fruit †
- Food.sushi †
- Friends.location †
- Friends.character †
- Friends.quote †
- FunnyName.name †
- GameOfThrones.quote †
- GameOfThrones.city †
- GameOfThrones.character †
- GameOfThrones.house †
- GameOfThrones.dragon †
- Hacker.adjective †
- Hacker.noun †
- Hacker.verb †
- Hacker.ingverb †
- Hacker.abbreviation †
- HarryPotter.location †
- HarryPotter.book †
- HarryPotter.house †
- HarryPotter.character †
- HarryPotter.spell †
- HarryPotter.quote †
- Hipster.word †
- HitchhikersGuideToTheGalaxy.location †
- HitchhikersGuideToTheGalaxy.planet †
- HitchhikersGuideToTheGalaxy.specie †
- HitchhikersGuideToTheGalaxy.marvinQuote †
- HitchhikersGuideToTheGalaxy.quote †
- HitchhikersGuideToTheGalaxy.starship †
- HitchhikersGuideToTheGalaxy.character †
- Hobbit.thorinsCompany †
- Hobbit.location †
- Hobbit.quote †
- Hobbit.character †
- HowIMetYourMother.catchPhrase †
- HowIMetYourMother.quote †
- HowIMetYourMother.character †
- HowIMetYourMother.highFive †
- IdNumber.valid †
- IdNumber.invalid †
- IdNumber.invalidSvSeSsn
- IdNumber.ssnValid
- IdNumber.validSvSeSsn
- Internet.domainSuffix †
- Internet.image †
- Internet.avatar †
- Internet.ipV4Cidr †
- Internet.publicIpV4Address †
- Internet.domainName †
- Internet.password †
- Internet.ipV6Cidr †
- Internet.userAgentAny †
- Internet.emailAddress †
- Internet.safeEmailAddress †
- Internet.macAddress †
- Internet.privateIpV4Address †
- Internet.ipV6Address †
- Internet.url †
- Internet.ipV4Address †
- Internet.domainWord †
- Internet.uuid †
- Internet.slug †
- Job.seniority †
- Job.field †
- Job.title †
- Job.keySkills †
- Job.position †
- LeagueOfLegends.location †
- LeagueOfLegends.champion †
- LeagueOfLegends.masteries †
- LeagueOfLegends.quote †
- LeagueOfLegends.rank †
- LeagueOfLegends.summonerSpell †
- Lebowski.character †
- Lebowski.actor †
- Lebowski.quote †
- LordOfTheRings.character †
- LordOfTheRings.location †
- Lorem.sentence
- Lorem.sentences
- Lorem.character
- Lorem.characters
- Lorem.paragraphs
- Lorem.paragraph
- Lorem.fixedString
- Lorem.word
- Lorem.words †
- Matz.quote †
- Medical.hospitalName †
- Medical.medicineName †
- Medical.symptoms †
- Medical.diseaseName †
- Music.key †
- Music.instrument †
- Music.genre †
- Music.chord †
- Name.title †
- Name.name †
- Name.suffix †
- Name.lastName †
- Name.nameWithMiddle †
- Name.fullName †
- Name.firstName †
- Name.prefix †
- Name.username †
- Name.bloodGroup †
- Nation.flag †
- Nation.language †
- Nation.nationality †
- Nation.capitalCity †
- Number.randomNumber
- Number.randomDouble
- Number.digits
- Number.digit
- Number.randomDigitNotZero
- Number.numberBetween
- Number.randomDigit
- Overwatch.quote †
- Overwatch.location †
- Overwatch.hero †
- PhoneNumber.extension
- PhoneNumber.cellPhone †
- PhoneNumber.subscriberNumber †
- PhoneNumber.phoneNumber †
- Pokemon.location †
- Pokemon.name †
- PrincessBride.quote †
- PrincessBride.character †
- ProgrammingLanguage.name †
- ProgrammingLanguage.creator †
- Relationships.spouse †
- Relationships.inLaw †
- Relationships.sibling †
- Relationships.extended †
- Relationships.parent †
- Relationships.any †
- Relationships.direct †
- RickAndMorty.quote †
- RickAndMorty.character †
- RickAndMorty.location †
- Robin.quote †
- RockBand.name †
- Shakespeare.asYouLikeItQuote †
- Shakespeare.hamletQuote †
- Shakespeare.kingRichardIIIQuote †
- Shakespeare.romeoAndJulietQuote †
- SlackEmoji.emoji †
- SlackEmoji.celebration †
- SlackEmoji.nature †
- SlackEmoji.objectsAndSymbols †
- SlackEmoji.foodAndDrink †
- SlackEmoji.activity †
- SlackEmoji.custom †
- SlackEmoji.travelAndPlaces †
- SlackEmoji.people †
- Space.nasaSpaceCraft †
- Space.galaxy †
- Space.meteorite †
- Space.star †
- Space.agencyAbbreviation †
- Space.constellation †
- Space.company †
- Space.nebula †
- Space.distanceMeasurement †
- Space.moon †
- Space.agency †
- Space.starCluster †
- Space.planet †
- StarTrek.location †
- StarTrek.villain †
- StarTrek.character †
- StarTrek.specie †
- Stock.nyseSymbol †
- Stock.nsdqSymbol †
- Superhero.descriptor †
- Superhero.name †
- Superhero.power †
- Superhero.suffix †
- Superhero.prefix †
- Team.name †
- Team.creature †
- Team.state †
- Team.sport †
- TwinPeaks.character †
- TwinPeaks.location †
- TwinPeaks.quote †
- University.suffix †
- University.name †
- University.prefix †
- Weather.temperatureFahrenheit †
- Weather.temperatureCelsius †
- Weather.description †
- Witcher.quote †
- Witcher.character †
- Witcher.witcher †
- Witcher.monster †
- Witcher.school †
- Witcher.location †
- Yoda.quote †
- Zelda.character †
- Zelda.game †
Examples
Generating string values
Use any of the valid Datafaker expressions in #{}
.
{
"_gen": "string",
"expr": "#{Name.fullName}"
}
[
"Ms. Shakira McLaughlin",
"Miss Marshall Von",
"Tiffani Schaden",
"Frederick Schoen",
"Melda Cartwright"
]
Referring to local names
Use names
to make a map of identifiers to expressions. These identifiers can be used inside of expr
and are generally useful for destructuring an object to put specific values into a string.
Local names are given preference over Datafaker expressions.
{
"topic": "sandbox",
"vars": {
"profile": {
"age": {
"_gen": "normalDistribution",
"mean": 40,
"sd": 10,
"decimals": 0
}
}
},
"value": {
"_gen": "string",
"names": {
"age": {
"_gen": "var",
"var": "profile",
"path": [
"age"
]
}
},
"expr": "I am #{age} years old"
}
}
[
"I am 48 years old",
"I am 41 years old",
"I am 35 years old",
"I am 31 years old",
"I am 38 years old"
]
Referring to vars
Refer to variables defined in vars
or varsOnce
. These are given preference over Datafaker expressions, but both can be resolved in the same string.
{
"topic": "sandbox",
"vars": {
"n": {
"_gen": "uniformDistribution",
"bounds": [
1,
10
],
"decimals": 0
}
},
"value": {
"_gen": "string",
"expr": "The magic number is #{n}"
}
}
[
"The magic number is 9",
"The magic number is 8",
"The magic number is 1",
"The magic number is 2",
"The magic number is 5"
]
Calling Datafaker functions
Some Datafaker expressions are functions that take parameters. When there's a first-class ShadowTraffic alternative function, you should use they're much less finicky to use. But if you have to, invoke them with single quotes, commas between parameters, and no spaces.
{
"_gen": "string",
"expr": "#{Date.birthday '2','4'}"
}
[
"2022-10-19 05:19:49.883949332",
"2021-03-28 21:32:48.976335815",
"2020-11-22 02:00:53.351956934",
"2021-08-28 09:20:43.833683576",
"2022-03-02 04:23:50.082862648"
]
Transforming strings
Use case
to change the casing of generated strings, choosing one of lower
, upper
, or capitalized
.
You can also abbreviate a string by specifying length
or remove a substring with removeSubstring
.
{
"lower": {
"_gen": "string",
"expr": "#{Name.fullName}",
"case": "lower"
},
"upper": {
"_gen": "string",
"expr": "#{Name.fullName}",
"case": "upper"
},
"capitalized": {
"_gen": "string",
"expr": "#{Name.fullName}",
"case": "capitalized"
},
"shortened": {
"_gen": "string",
"expr": "#{Name.fullName}",
"length": 3
},
"scrubbed": {
"_gen": "string",
"expr": "#{Name.firstName}-#{Name.lastName}",
"removeSubstring": "-"
}
}
[
{
"lower": "huey jaskolski",
"upper": "VIOLA MURRAY",
"capitalized": "Mr. tony denesik",
"shortened": "Rud",
"scrubbed": "LiaChamplin"
},
{
"lower": "synthia beatty",
"upper": "MR. SHELBY FERRY",
"capitalized": "Ofelia prosacco",
"shortened": "Dr.",
"scrubbed": "ColleenJast"
}
]
Overriding the locale
Change the locale (default United States/English) by setting locale
: first parameter is language, second is region. This example overrides the loclae to Great Britain/English so that county names reflect the region.
{
"_gen": "string",
"locale": [
"en",
"gb"
],
"expr": "#{Address.county}"
}
[
"Gwynedd County",
"East Sussex",
"Dorset",
"Cornwall",
"Warwickshire"
]
Specification
JSON schema
{
"type": "object",
"properties": {
"expr": {
"type": "string"
},
"names": {
"type": "object"
},
"case": {
"type": "string",
"enum": [
"lower",
"upper",
"capitalized"
]
},
"length": {
"type": "integer",
"minimum": 0
},
"locale": {
"type": "array",
"minItems": 2,
"maxItems": 2,
"items": {
"type": "string"
}
}
},
"required": [
"expr"
]
}