0.0.6 • Published 4 years ago

@awai/toolbox v0.0.6

Weekly downloads
12
License
-
Repository
-
Last release
4 years ago

AWAI Toolbox

Set of tools you'll always need. So, just npm install --save @awai/toolbox and have it always at hand.

Resources

Str

Set of helper constants and methods for text processing.

Accessors

AccessorDescription
emptyEmpty string
englishLettersOrderedOrdered set of lowercase English letters

Methods

MethodDescription
capitalize(str: string)Return a copy of the string with its first character capitalized and the rest lowercased
isAlpha(str: string)Return true if all characters in the string are alpha only
isControl(char: string)Return true if char is ASCII control symbol
isDomainName(str: string)Return true if string looks like a valid domain name
isEmail(str: string)Return true if string is a valid email address
isIp(str: string)Return true if string is a valid IP address
isLower(str: string)Return true if all characters in the string are lowercase
isNullOrEmpty(str: string)Return true if a specified string is null or empty
isNullOrWhiteSpace(str: string)Return true if a specified string is null, empty, or consists only of white-space characters
isNumber(str: string)Return true if all characters in the string are digits only
isUpper(str: string)Return true if all characters in the string are uppercase
parseNumBool(str: string)Try to find number or boolean value in a provided string and return converted value
random(size: number, alphaLower, alphaUpper, decimal)Generate alpha numeric random sequence string
splitLines(str: string)Return an array of the lines in the string, breaking at line boundaries
swapCase(str: string)Return a copy of the string with uppercase characters converted to lowercase and vice versa
wrapInHtmlTag(str: string, term: string, tagName: string, tagClasses: string[])Return source text with "term" wrapped by specified HTML tag

Arr

Provides a set of helper methods for arrays.

Accessors

AccessorDescription
englishLettersOrderedOrdered set of lowercase English letters
englishLettersUppercaseOrderedOrdered set of upercase English letters

Methods

MethodDescription
bytesToFloat(bytes: Uint8Array)Convert array of bytes into array of floats within range 0.0, 1.0
first(arr: Array)Return the first element of a specified array
isNullOrEmpty(arr: Array)Return true if a specified array is null or empty
last(arr: Array)Return the last element of a specified array
range(size: number, start: number)Return array filled by range of integers
removeEmptyStrings(arr: string[])Remove empty string elements from string array
shuffle(arr: Array)Shuffle the array by method Fisher–Yates
stringToCharArray(str: string)Convert string into array of chars

Random

Provides a set of helper methods to generate cryptographically strong random values.

Methods (RandomBytesProvider)

MethodDescription
nextBytes(size: number)Return array of random bytes
nextBytesAsync(size: number)Return promise that resolves to array of random bytes

Methods (Rnd)

MethodDescription
nextFloat(qty: number)Return a random floating-point number or array of random floating-point numbers that is greater than or equal to 0.0, and less than 1.0
nextFloatAsync(qty: number)Return a promise that resolves to random floating-point number or array of random floating-point numbers that is greater than or equal to 0.0, and less than 1.0
nextInt(min: number, max: number, qty: number)Return a random integer or array of random integers that is within a specified range
nextIntAsync(min: number, max: number, qty: number)Return a promise that resolves to random integer or array of random integers that is within a specified range

Url

The Url class is used to parse or create from 0 the URL. It gives you different property accessors that allow you easily access or set parts of the URL. Create the Url instance with the uri string or empty to construct it from zero.

Methods

MethodDescription
isUrl(value: string)Return true if provided value can be parsed as valid URI
toString()Return string representation of the whole URL
toURL()Return URL object

Accessors

AccessorDescription
protocolIANA-registered scheme or protocol
domainName of the domain or IP address
portIP port number
usernameUsername for HTTP Authentication
passwordPassword for HTTP Authentication
pathStringRoute path in form /route/path
pathParamsRoute path as array of its parts
pathRoute path in form /route/path
queryParamsMap of query params as a key - value. Values are parsed as strings, numbers and booleans
hashFragmentHash fragment
isSslReturn true if SSL is used

Running unit tests

Run nx test toolbox to execute the unit tests via Jest.