Skip to content

Latest commit

 

History

History
157 lines (72 loc) · 2.82 KB

File metadata and controls

157 lines (72 loc) · 2.82 KB

Home > @asl-19/js-utils

js-utils package

A collection of plain JavaScript utility functions for ASL19 projects.

These functions don’t rely on DOM, React, or React Native APIs.

Functions

Function

Description

asType(value)

Cast an object to a specified data type.

cleanUrlQueryString(url)

Returns a URL with trailing "?" and "&" characters removed.

constructUrl({ path, querySegments, })

Format a root-relative URL based on provided path and query string key-value pairs.

getAbsoluteUrl({ protocolAndHost, rootRelativeUrl, })

Given provided protocol + host string and root-relative URL string returns an absolute (fully-qualified) URL.

getFirstStringOrString(arrayOrString)

Given an array or a string, return its first string element.

getNormalizedQuery({ defaults, query, types, })

Returns a normalized representation of the passed query with default values.

getObjectValueByDotSeparatedKey({ dotSeparatedKey, object, })

Given a provided dot-separated key (e.g. "foo.bar") and object extract the corresponding value.

getRootRelativeUrl(fullyQualifiedUrl)

Given a fully-qualified URL, returns a root-relative URL.

isNullOrWhitespace(input)

Returns true if string is null, an empty string, or a string of whitespace characters.

replaceArabicNumeralsWithPersianNumerals(input)

Replace Arabic (Hindu–Arabic/Western Arabic/Latin) numerals with Persian (Perso-Arabic) numerals.

serverLog({ description, path, statusCode, })

Logs a formatted message based on the provided description, HTTP status code, and path.

underscoreCaseToCamelCase(underscoreCasedString)

Given an underscore-cased string, returns a camel-cased string.