Skip to content

Utility String

Yakov Veromeev edited this page Nov 14, 2022 · 1 revision

Usage

Module: sldt/utilsString Each function is imported as an import member (there is no default export)

import { generateUUID } from "sldt/utilsString";

Functions

Generate UUID

Create a random number and form it as UUID v4 string. Useful for creating the ids in arrays you need to display, or HTML element ids you don't need to name any specific way.

function generateUUID(): string

Check if variable is string

a shortcut for typeof variable === "string", returns true if var is string.

function isString(probableString: any): boolean

In fact, returns typescript's probableString is string, such notation helps in if clauses, because embedded IDE tools will recognize it and hint you with string methods.

if (isString(response)) {
    console.log(response. /// here you'll see the string methods like split and replace
}

Check that the variable is a string and its length more than 0

function isStringFilled(probableString: any): boolean

As well, returns probableString is string to help IDE type system recognize a string.

Checks that the variable is a string and its length more than 0 besides whitespace

function isStringNotBlank(probableString: any): boolean

As well, returns probableString is string to help IDE type system recognize a string.