String
Generate string values.
If you want to join several strings together: refer to our combiners section. We have some built-in combiners working exclusively on string values.
hexaString
Hexadecimal string containing characters produced by fc.hexa()
.
Signatures:
fc.hexaString()
— deprecated since v3.22.0 (more details at #5233)fc.hexaString({minLength?, maxLength?, size?})
— deprecated since v3.22.0 (more details at #5233)
with:
minLength?
— default:0
— minimal number of characters (included)maxLength?
— default:0x7fffffff
more — maximal number of characters (included)size?
— default:undefined
more — how large should the generated values be?
Usages:
fc.hexaString();
// Examples of generated values: "251971", "", "a9", "742e6c86e", "39350b163"…
fc.hexaString({ maxLength: 3 });
// Note: Any hexadecimal string containing up to 3 (included) characters
// Examples of generated values: "1", "", "2ef", "2a", "6e3"…
fc.hexaString({ minLength: 3 });
// Note: Any hexadecimal string containing at least 3 (included) characters
// Examples of generated values: "1021a292c2d306", "e4660fd014ae290", "2ef914a5d7ffe9df", "2a212", "05dd1"…
fc.hexaString({ minLength: 4, maxLength: 6 });
// Note: Any hexadecimal string containing between 4 (included) and 6 (included) characters
// Examples of generated values: "b4ccb", "e51d", "b3e093", "383f", "27bd"…
Resources: API reference.
Available since 0.0.1.
string
String containing characters produced by the character generator defined for unit
. By default, unit
defaults to fc.char()
.
Signatures:
fc.string()
fc.string({minLength?, maxLength?, size?, unit?})
with:
unit?
— default:'grapheme-ascii'
— how to generate the characters that will be joined together to create the resulting stringminLength?
— default:0
— minimal number of units (included)maxLength?
— default:0x7fffffff
more — maximal number of units (included)size?
— default:undefined
more — how large should the generated values be?
Usages:
fc.string();
// Examples of generated values: "JT>\"C9k", "h]iD\"27;", "S", "n\\Ye", ""…
fc.string({ maxLength: 3 });
// Note: Any string containing up to 3 (included) characters
// Examples of generated values: "", "ref", "?D", "key", "}"…
fc.string({ minLength: 3 });
// Note: Any string containing at least 3 (included) characters
// Examples of generated values: "Pv-^X_t", "bind", "?DM", "iEjK.b?^O", "}~}S"…
fc.string({ minLength: 4, maxLength: 6 });
// Note: Any string containing between 4 (included) and 6 (included) characters
// Examples of generated values: "Trxlyb", "&&@%4", "s@IO", "0\"zM", "}#\"$"…
fc.string({ unit: 'grapheme' });
// Note: Any string made only of printable graphemes possibly made of multiple code points.
// With 'grapheme', minLength (resp. maxLength) refers to length in terms of graphemes (visual entities).
// As an example, "\u{0061}\u{0300}" has a length of 1 in this context, as it corresponds to the visual entity: "à".
// Examples of generated values: "length", "🡓𑨭", "🚌ᄆॶ🥄ၜ㏹", "key", "callஈcall"…
fc.string({ unit: 'grapheme-composite' });
// Note: Any string made only of printable graphemes.
// With 'grapheme-composite', minLength (resp. maxLength) refers to length in terms of code points (equivalent to visual entities for this type).
// Examples of generated values: "🭃𖼰𱍊alleef", "#", "𝕃ᖺꏪ🪓ሪ㋯𑼓𘠴𑑖", "", "\"isP"…
fc.string({ unit: 'grapheme-ascii' });
// Note: Any string made only of printable ascii characters.
// With 'grapheme-composite', minLength (resp. maxLength) refers to length in terms of code units aka chars (equivalent to code points and visual entities for this type).
// Examples of generated values: "+", "y\\m4", ")H", "}q% b'", "ZvT`W"…
fc.string({ unit: 'binary' });
// Note: Results in strings made of any possible combinations of code points no matter how they join between each others (except half surrogate pairs).
// With 'binary', minLength (resp. maxLength) refers to length in terms of code points (not in terms of visual entities).
// As an example, "\u{0061}\u{0300}" has a length of 2 in this context, even if it corresponds to a single visual entity: "à".
// Examples of generated values: "length", "𒇖ᴣ", "", "𢊊", "key"…
fc.string({ unit: 'binary-ascii' });
// Note: Results in strings made of any possible combinations of ascii characters (in 0000-007F range).
// With 'binary-ascii', minLength (resp. maxLength) refers to length in terms of code units aka chars (equivalent to code points for this type).
// Examples of generated values: "c\\3\f\u0000\u001f\u00047", "M\u0006\fD!U\u000fXss", "", "s\u0000", "\n\u0006tkK"…
fc.string({ unit: fc.constantFrom('Hello', 'World') });
// Note: With a custom arbitrary passed as unit, minLength (resp. maxLength) refers to length in terms of unit values.
// As an example, "HelloWorldHello" has a length of 3 in this context.
// Examples of generated values: "", "Hello", "HelloWorld", "HelloWorldHello", "WorldWorldHelloWorldHelloWorld"…
Resources: API reference.
Available since 0.0.1.
asciiString
ASCII string containing characters produced by fc.ascii()
.
Signatures:
fc.asciiString()
— deprecated since v3.22.0, prefer string (more details at #5233)fc.asciiString({minLength?, maxLength?, size?})
— deprecated since v3.22.0, prefer string (more details at #5233)
with:
minLength?
— default:0
— minimal number of characters (included)maxLength?
— default:0x7fffffff
more — maximal number of characters (included)size?
— default:undefined
more — how large should the generated values be?
Usages:
fc.asciiString();
// Examples of generated values: "\f@D", "hp", "q#dO~?@", "Qad", "5eHqc"…
fc.asciiString({ maxLength: 3 });
// Note: Any ascii string containing up to 3 (included) characters
// Examples of generated values: "6", "", "ty", ",", "k"…
fc.asciiString({ minLength: 3 });
// Note: Any ascii string containing at least 3 (included) characters
// Examples of generated values: "603e", "6W\u001b^tR-\n\n|", "efproto_\u001abhasOw", "$\u001c&\u0000R", "apply"…
fc.asciiString({ minLength: 4, maxLength: 6 });
// Note: Any ascii string containing between 4 (included) and 6 (included) characters
// Examples of generated values: "<&\u001e\u001b ", "bind", "dnGn\\2", "& % !", "__defi"…
Resources: API reference.
Available since 0.0.1.
unicodeString
Unicode string containing characters produced by fc.unicode()
.
Signatures:
fc.unicodeString()
— deprecated since v3.22.0, prefer string (more details at #5233)fc.unicodeString({minLength?, maxLength?, size?})
— deprecated since v3.22.0, prefer string (more details at #5233)
with:
minLength?
— default:0
— minimal number of characters (included)maxLength?
— default:0x7fffffff
more — maximal number of characters (included)size?
— default:undefined
more — how large should the generated values be?
Usages:
fc.unicodeString();
// Examples of generated values: ",", "뇇ⷍ돠", "", "穿ﺥ羊汉ힸ౨", "穙셣킲햗䊢鏶눏"…
fc.unicodeString({ maxLength: 3 });
// Note: Any unicode (from BMP-plan) string containing up to 3 (included) characters
// Examples of generated values: "", "꙰", "툌", "㮟", "a"…
fc.unicodeString({ minLength: 3 });
// Note: Any unicode (from BMP-plan) string containing at least 3 (included) characters
// Examples of generated values: "떚碱縢鰷釬ڤ撙", "竑૱toS", "꙰ꁺ蜱⫄ั", "__d", "툌뀪凛瞸㾡끴"…
fc.unicodeString({ minLength: 4, maxLength: 6 });
// Note: Any unicode (from BMP-plan) string containing between 4 (included) and 6 (included) characters
// Examples of generated values: "뿐噻⪃嫿垈", "ڣۡ觌뱇", "apply", "톥薦", "namea"…
Resources: API reference.
Available since 0.0.11.
string16bits
String containing characters produced by fc.char16bits()
.
Be aware that the generated string might appear invalid regarding the unicode standard as it might contain incomplete pairs of surrogate.
Signatures:
fc.string16bits()
— deprecated since v3.22.0 (more details at #5233)fc.string16bits({minLength?, maxLength?, size?})
— deprecated since v3.22.0 (more details at #5233)
with:
minLength?
— default:0
— minimal number of characters (included)maxLength?
— default:0x7fffffff
more — maximal number of characters (included)size?
— default:undefined
more — how large should the generated values be?
Usages:
fc.string16bits();
// Examples of generated values: "", "沉蹻!쯼&)噕", "獏", "嚷爇邏䨫Ꝺ䟌", "ۆ딛楯씺"…
fc.string16bits({ maxLength: 3 });
// Note: Any string (not really legal ones sometimes) containing up to 3 (included) characters
// Examples of generated values: "", "ꃷ", "톽va", "뿤䵎悧", ""…
fc.string16bits({ minLength: 3 });
// Note: Any string (not really legal ones sometimes) containing at least 3 (included) characters
// Examples of generated values: "㝟佷㟧譽먔", "ꃷꢒ", "톽valueOf", "key", "app"…
fc.string16bits({ minLength: 4, maxLength: 6 });
// Note: Any string (not really legal ones sometimes) containing between 4 (included) and 6 (included) characters
// Examples of generated values: "apply", "鹽\udc68鯻שּׂ", "땺\uda2f熑鉈뗻", "__def", "㓐줫曧ᒢ"…
Resources: API reference.
Available since 0.0.11.
fullUnicodeString
Unicode string containing characters produced by fc.fullUnicode()
.
Signatures:
fc.fullUnicodeString()
— deprecated since v3.22.0, prefer string (more details at #5233)fc.fullUnicodeString({minLength?, maxLength?, size?})
— deprecated since v3.22.0, prefer string (more details at #5233)
with:
minLength?
— default:0
— minimal number of characters (included)maxLength?
— default:0x7fffffff
more — maximal number of characters (included)size?
— default:undefined
more — how large should the generated values be?
Be aware that the length is considered in terms of the number of glyphs in the string and not the number of UTF-16 characters. As a consequence generatedString.length
might be greater than the asked maximal length but [...generatedString].length
will not and always be in the required range
Usages:
fc.fullUnicodeString();
// Examples of generated values: "", "涫", "", "", ""…
fc.fullUnicodeString({ maxLength: 3 });
// Note: Any unicode string containing up to 3 (included) code-points
// Examples of generated values: "", "", "", "", ""…
fc.fullUnicodeString({ minLength: 3 });
// Note: Any unicode string containing at least 3 (included) code-points
// Examples of generated values: "", "bind", "in", "%4propertyIs", ""…
fc.fullUnicodeString({ minLength: 4, maxLength: 6 });
// Note: Any unicode string containing between 4 (included) and 6 (included) code-points
// Examples of generated values: "call", "𨤎", "乀", ",valu", "𫅰𪂀"…
Resources: API reference.
Available since 0.0.11.