Skip to main content

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: "&#x007B;MDX&#x007D; &#x003C;special&#x003E; 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​

StackOverflow source.

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 &#x0000.

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: "&#x0025;"

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