JAVASCRIPT
String Utilities
All samples are using Ink.requireModules
, please read how to use it at Ink.requireModules section
Function name | Description |
---|---|
.escape(c) | Escapes a unicode character. |
.escapeText(txt, [whiteList]) | Escapes unicode characters in a string as unicode character entities (\x## , where the ## are hex digits). |
.evalJSON(strJSON, sanitize) | Eval a JSON - We recommend you Ink.Util.Json |
.htmlEntitiesDecode(string) | Decodes string from HTML entities. |
.htmlEntitiesEncode(string) | Encodes string into HTML entities. |
.htmlEscapeUnsafe(str) | Escapes unsafe html chars as HTML entities |
.isJSON(str) | Checks if a string is a valid JSON object (string encoded) |
.normalizeWhitespace(str) | Normalizes whitespace in string. |
.packetize(str, maxLen) | Splits a string into smaller chunks |
.removeAccentedChars(string) | Removes all accented characters from a string. |
.shortString(str, n) | Truncates a string without breaking words. Inserts an ellipsis HTML entity at the end of the string if it's too long. |
.strcmp(str1, str2) | Compares two strings. |
.stripTags(string, allowed) | Strips HTML tags from strings |
.substrCount(haystack, needle) | Count the number of occurrences of a specific needle in a haystack |
.toUnicode(str) | Converts string to unicode. |
.trim(string) | Trims whitespace from strings |
.truncateString(str, length) | Truncates a string, breaking words and adding ... at the end. |
.ucFirst(string, [firstWordOnly]) | Capitalizes a word. |
.unescape(es) | Unescapes a unicode character escape sequence |
.unescapeText(txt) | Removes unicode entities (in the format "\x##" or "\u####", where "#" is a hexadecimal digit) |
.utf8Decode(string) | Decodes a string from UTF-8. |
.utf8Encode(string) | Encode a string to UTF-8. |
Property name | Description |
---|---|
.escapedCharRegex | Regex to check escaped strings |
Escapes a unicode character.
c
Character to escapeCode
Escapes unicode characters in a string as unicode character entities (\x##
, where the ##
are hex digits).
txt
String with characters outside the ASCII printable range (32 < charCode < 127)whiteList
Whitelist of characters which should NOT be escapedCode
Eval a JSON - We recommend you Ink.Util.Json
strJSON
JSON string to evalsanitize
Flag to sanitize inputDecodes string from HTML entities.
string
String to be decodedCode
Encodes string into HTML entities.
string
Input string.Code
Escapes unsafe html chars as HTML entities
str
String to escapeCode
Checks if a string is a valid JSON object (string encoded)
str
String to checkNormalizes whitespace in string.
String is trimmed and sequences of whitespaces are collapsed.
str
String to normalizeCode
Splits a string into smaller chunks
str
String to dividemaxLen
Maximum chunk size (in characters)Code
Removes all accented characters from a string.
string
String to remove accents fromCode
Truncates a string without breaking words. Inserts an ellipsis HTML entity at the end of the string if it's too long.
str
String to truncaten
Number of chars of the short stringCode
Compares two strings.
str1
First Stringstr2
Second StringCode
Strips HTML tags from strings
string
String to strip tags from.allowed
Comma separated list of allowed tags.Code
Count the number of occurrences of a specific needle in a haystack
haystack
String to search inneedle
String to search forCode
Converts string to unicode.
str
String to convertCode
Trims whitespace from strings
string
String to be trimmedCode
Truncates a string, breaking words and adding ... at the end.
str
String to truncatelength
Limit for the returned string, ellipsis included.Code
Capitalizes a word.
If param as more than one word, it converts first letter of all words that have more than 2 letters
string
String to capitalize.firstWordOnly
falseFlag to capitalize only the first word.Code
Unescapes a unicode character escape sequence
es
Escape sequenceCode
Removes unicode entities (in the format "\x##" or "\u####", where "#" is a hexadecimal digit)
txt
Text you intend to remove unicode character entities.Code
Decodes a string from UTF-8.
string
String to be decodedEncode a string to UTF-8.
string
String to be encodedRegex
Regex to check escaped strings