string
Library of helpers for formatting strings.
slugify()β
const slugify: (str) => string = kebabCase;
Defined in: string.ts:283
Alias of kebabCase.
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"
Seeβ
kebabCase
capitalize()β
function capitalize(str): string
Defined in: string.ts:224
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"
escapeMDX()β
function escapeMDX(str): string
Defined in: string.ts:177
Internal
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"
firstUppercase()β
function firstUppercase(str): string
Defined in: string.ts:200
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"
kebabCase()β
function kebabCase(str): string
Defined in: string.ts:267
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"
prune()β
function prune(str, substr): string
Defined in: string.ts:58
Internal
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."
replaceDiacritics()β
function replaceDiacritics(str): string
Defined in: string.ts:27
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β
startCase()β
function startCase(str): string
Defined in: string.ts:246
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"
stringCaseBuilder()β
function stringCaseBuilder(
str,
transformation?,
separator?,
splitter?): string
Defined in: string.ts:100
Internal
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*"
toHTMLUnicode()β
function toHTMLUnicode(char): string
Defined in: string.ts:146
Internal
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: "%"
toString()β
function toString(variable): string
Defined in: string.ts:293
Returns a stringified version of the variable.
Parametersβ
variableβ
unknown
the variable to be transformed.
Returnsβ
string
a string