string
Library of helpers for formatting strings.
capitalize()β
function capitalize(str): string
Returns a string in lowercase excepted for the 1st character capitalized using firstUppercase.
Parametersβ
strβ
Maybe
<string
>
the string to be transformed.
Returnsβ
string
a capitalized string, or an empty string if str
is not a valid string.
Exampleβ
import { capitalize } from "@graphql-markdown/utils/string";
capitalize("the quick Brown Fox");
// Expected result: "The quick brown fox"
Defined inβ
string.ts:224
escapeMDX()β
function escapeMDX(str): string
Returns a string with MDX special characters converted to HTML unicode using toHTMLUnicode.
Characters within code notation should not be converted.
List of special characters: {
, <
, >
, }
Parametersβ
strβ
unknown
the string to be transformed.
Returnsβ
string
a string with MDX special characters replaced by HTML unicode equivalents.
Exampleβ
import { escapeMDX } from "@graphql-markdown/utils/string";
escapeMDX("{MDX} <special> characters");
// Expected result: "{MDX} <special> characters"
escapeMDX("`{MDX}` `<special>` characters");
// Expected result: "`{MDX}` `<special>` characters"
Defined inβ
string.ts:177
firstUppercase()β
function firstUppercase(str): string
Returns a string with the 1st character in uppercase.
Parametersβ
strβ
Maybe
<string
>
the string to be transformed.
Returnsβ
string
a string with the 1st character in uppercase, or an empty string if str
is not a valid string.
Exampleβ
import { firstUppercase } from "@graphql-markdown/utils/string";
firstUppercase("the quick Brown Fox");
// Expected result: "The quick Brown Fox"
Defined inβ
string.ts:200
kebabCase()β
function kebabCase(str): string
Returns a lowercase string with -
as replacement for non alphanum characters using stringCaseBuilder.
Parametersβ
strβ
Maybe
<string
>
the string to be transformed.
Returnsβ
string
a string converted to start case, or an empty string if str
is not a valid string.
Exampleβ
import { kebabCase } from "@graphql-markdown/utils/string";
kebabCase("The quick brown Fox");
// Expected result: "the-quick-brown-fox"
Defined inβ
string.ts:267
prune()β
function prune(str, substr): string
Returns a string pruned on both start and end, similar to trim()
but with any substring.
Parametersβ
strβ
Maybe
<string
>
the string to be pruned.
substrβ
string
= ""
the substring to be removed from str
.
Returnsβ
string
a pruned string, or an empty string if str
is not a valid string.
Exampleβ
import { prune } from "@graphql-markdown/utils/string";
const text = "**The quick brown fox jumps over the lazy dog.**";
prune(text, "**");
// Expected result: "The quick brown fox jumps over the lazy dog."
Defined inβ
string.ts:58
replaceDiacritics()β
function replaceDiacritics(str): string
Replaces diacritics by non-diacritic equivalent characters.
Parametersβ
strβ
Maybe
<string
>
the string to be transformed.
Returnsβ
string
a string with diacritic characters replaced, or an empty string if str
is not a valid string.
Exampleβ
import { replaceDiacritics } from "@graphql-markdown/utils/string";
replaceDiacritics("ΓΓ©ΓͺΕ"); // Expected result: "Aees"
Seeβ
Defined inβ
string.ts:27
slugify()β
function slugify(str): string
Alias of kebabCase.
Parametersβ
strβ
Maybe
<string
>
the string to be transformed.
Returnsβ
string
a string converted to start case, or an empty string if str
is not a valid string.
Aliasβ
Exampleβ
import { kebabCase } from "@graphql-markdown/utils/string";
kebabCase("The quick brown Fox");
// Expected result: "the-quick-brown-fox"
Defined inβ
string.ts:282
startCase()β
function startCase(str): string
Applies firstUppercase using stringCaseBuilder to every word of a string with space
character as separator.
Parametersβ
strβ
Maybe
<string
>
the string to be transformed.
Returnsβ
string
a string converted to start case, or an empty string if str
is not a valid string.
Exampleβ
import { startCase } from "@graphql-markdown/utils/string";
startCase("the quick Brown Fox");
// Expected result: "The Quick Brown Fox"
Defined inβ
string.ts:246
stringCaseBuilder()β
function stringCaseBuilder(
str,
transformation?,
separator?,
splitter?): string
Returns a string after applying a transformation function.
By default splitter
expression will split the string into words, where non-alphanum chars are considered as word separators.
separator
will be used for joining the words back together.
prune using separator
is applied to the result of the transformation.
Parametersβ
strβ
Maybe
<string
>
the string to be transformed.
transformation?β
Maybe
<(word
) => string
>
optional transformation callback function.
separator?β
string
optional character separator for word-based transformation.
splitter?β
optional regex or string rule for splitting string into word.
string
| RegExp
Returnsβ
string
a transformed string, or an empty string if str
is not a valid string.
Exampleβ
import { stringCaseBuilder } from "@graphql-markdown/utils/string";
const text = "The quick brown fox jumps over the lazy dog.";
const transformation = (word: string): string => `*${word}*`
stringCaseBuilder(text, transformation, " ");
// Expected result: "*The* *quick* *brown* *fox* *jumps* *over* *the* *lazy* *dog*"
Defined inβ
string.ts:100
toHTMLUnicode()β
function toHTMLUnicode(char): string
Converts a character to its equivalent HTML unicode representation �
.
Parametersβ
charβ
Maybe
<string
>
the character to be transformed.
Returnsβ
string
a HTML unicode representation of char
, or an empty string if char
is not a valid string.
Exampleβ
import { toHTMLUnicode } from "@graphql-markdown/utils/string";
toHTMLUnicode("%"); // Expected result: "%"
Defined inβ
string.ts:146
toString()β
function toString(variable): string
Returns a stringified version of the variable.
Parametersβ
variableβ
unknown
the variable to be transformed.
Returnsβ
string
a string
Defined inβ
string.ts:292