Returns a random string
Arg | Type | Default | Description |
---|---|---|---|
length | integer | 10 | Length of the random string |
import {generateRandomString} from "lkt-string-tools";
const str1 = generateRandomString();
const str2 = generateRandomString(14);
Removes HTML tags from input
except if defined in allowed
Arg | Type | Default | Description |
---|---|---|---|
input | string | String to be cleaned | |
allowed | string | The format is like following: <a><b><c> (only tags in lowercase) |
import {stripTags} from "lkt-string-tools";
const str1 = stripTags('<span>Hello world</span>', ''); // Returns "Hello world"
const str2 = stripTags('<span>Hello world</span>', '<span>'); // Returns "<span>Hello world</span>"
Convert input
to HTML entities
Arg | Type | Default | Description |
---|---|---|---|
input | string | String to be converted |
import {htmlEntities} from "lkt-string-tools";
const str1 = htmlEntities('lorem ipsum dolor sit amet');
Replaces all occurrences of search
in target
with replacement
Arg | Type | Default | Description |
---|---|---|---|
target | string | String which will be used to replace occurrences | |
search | string | Search pattern | |
replacement | string | Replacement |
import {replaceAll} from "lkt-string-tools";
const str1 = replaceAll('hey you!', 'h', 'H'); // Returns "Hey you!"
Replaces all whitespaces which only has one occurrence at a time in target
with replacement
Arg | Type | Default | Description |
---|---|---|---|
target | string | String which will be used to replace occurrences | |
replacement | string | Replacement |
import {replaceSingleWhiteSpaces} from "lkt-string-tools";
const str1 = replaceSingleWhiteSpaces('hey you!', '_'); // Returns: "hey_you!"
Removes starting and ending whitespaces from target
Arg | Type | Default | Description |
---|---|---|---|
target | string | String to be trimmed | |
value | string | '' | Search string |
import {trim} from "lkt-string-tools";
const str1 = trim(' lorem ipsum ') // Returns: "lorem ipsum"
Checks if a string has content of it's empty
Arg | Type | Default | Description |
---|---|---|---|
target | string | String to check |
import {isFilled} from "lkt-string-tools";
if (isFilled('lorem')) {
//do something
}
Checks if a string is base64 encoded image
Arg | Type | Default | Description |
---|---|---|---|
target | string | String to check |
import {isBase64Image} from "lkt-string-tools";
if (isBase64Image('lorem')) {
//do something
}
Convert from kebab case to camel case
Arg | Type | Default | Description |
---|---|---|---|
target | string | String to convert |
import {kebabCaseToCamelCase} from "lkt-string-tools";
console.log(kebabCaseToCamelCase('lorem-ipsum-dolor-sit-amet'))
Converts first letter to uppercase
Arg | Type | Default | Description |
---|---|---|---|
target | string | String to convert |
import {ucfirst} from "lkt-string-tools";
console.log(ucfirst('lorem ipsum'))
Format a number
Arg | Type | Default | Description |
---|---|---|---|
number | Number | Number to format | |
decimals | integer | Amount of decimals | |
decimalPoint | string | Decimal point separator | |
thousandsSeparator | string | Thousands point separator | |
removeDecimalsIfZero | boolean | true | Prevents returning results like "123.00" and returns "123" |
import {formatNumber} from "lkt-string-tools";
console.log(formatNumber(20, 2, '.', ',')) // 20.00
console.log(formatNumber(2000, 4, '.', ','))// 2,000.0000
Checks if a given var is string
Arg | Type | Default | Description |
---|---|---|---|
target | any | Var to check |
import {isString} from "lkt-string-tools";
console.log(isString('lorem-ipsum-dolor-sit-amet'))
Checks if a given string content has email format
Arg | Type | Default | Description |
---|---|---|---|
target | string | String to check |
import {isEmail} from "lkt-string-tools";
console.log(isEmail('lorem ipsum'))
Cast to string
Arg | Type | Default | Description |
---|---|---|---|
target | any | Data to convert to string |
import {toString} from "lkt-string-tools";
console.log(toString(20))
Creates a copy of the string without the reference to the original var.
Arg | Type | Default | Description |
---|---|---|---|
target | string | String to clone |
import {cloneString} from "lkt-string-tools";
console.log(cloneString('my awesome string'))
Decodes and url encoded string
Arg | Type | Default | Description |
---|---|---|---|
target | string | String to decode |
import {decodeUrl} from "lkt-string-tools";
console.log(decodeUrl('lorem-ipsum-dolor-sit-amet'))
Removes invalid chars to retrieve a nice url slug
Arg | Type | Default | Description |
---|---|---|---|
target | string | String to clean |
import {getUrlSlug} from "lkt-string-tools";
console.log(getUrlSlug('lorem ipsum'))
Encodes to UTF8
Arg | Type | Default | Description |
---|---|---|---|
target | string | String to encode |
import {utf8Encode} from "lkt-string-tools";
console.log(utf8Encode('lorem-ipsum-dolor-sit-amet'))
Decodes from UTF8
Arg | Type | Default | Description |
---|---|---|---|
target | string | String to decode |
import {utf8Decode} from "lkt-string-tools";
console.log(utf8Decode('lorem ipsum'))