Skip to content

@technobuddha > library > Programming > Escaping

Function: escapeGraphQL()

ts
function escapeGraphQL(input: string): string;

Defined in: escape-graph-ql.ts:31

Escape a string for use in GraphQL

CharacterHexEscape Sequence
Backspace0x08\b
Tab0x09\t
Newline0x0a\n
Form Feed0x0c\f
Carriage Return0x0d\r
Double Quote0x22\"
Single Quote0x27\'
Backslash0x5c\\
Control Characters0x00-0x1f, 0x7f-0x9f\unnnn

Parameters

ParameterTypeDescription
inputstringThe string to escape

Returns

string

the escaped string

Example

typescript
escapeGraphQL('Hello\nWorld'); // "Hello\\nWorld"
escapeGraphQL('"\\');          // "\\\"\\\\"
escapeGraphQL('\b');           // "\\b"
escapeGraphQL('\u20ac');       // "\\u20ac"