Skip to content
Helpers
Import any of these function from @zurich/dev-utils
.
ts
import { sum } from '@zurich/dev-utils/helpers';
const sum_of_values = sum([1, 2, 3]); // 6
Transformers
General
getLoremPicsum
getLoremPicsum
: Generates a random image URL from Picsum with the specified size.
setToArray
setToArray
: Converts aSet
to anarray
.
parseNumber
parseNumber
: Parses the given value into a number.
parseBoolean
parseBoolean
: Parses the given value and returns a boolean representation.
chunkMultiline
chunkMultiline
: Splits a multilinestring
into an array of strings, where eachstring
has a maximum length ofmaxLength
.
findShortestWord
findShortestWord
: Finds the shortest word in a given string.
findLongestWord
findLongestWord
: Finds the longest word in a given string.
For Boolean
We provide also some common boolean operators as functions:
not
not
: Toggles a boolean value.
nor
nor
: Performs the NOR operation on two boolean values.
nand
nand
: Performs the NAND operation on two boolean values.
xor
xor
: Performs the XOR operation on two boolean values.
For Numbers
Some common operations with collections of numbers:
sum
sum
: Calculates the sum of all numbers in an array.
sumIf
sumIf
: Sums up the numbers in an array that satisfy a given condition.
avg
avg
: Calculates the average of an array of numbers
avgIf
avgIf
: Calculates the average of the numbers in an array that satisfy a given condition.
For Arrays
scrutinize
scrutinize
: Filters an array based on a given predicate function.
mapValue
mapValue
: Maps the values of a specific key from an array of objects.
doubleLoop
doubleLoop
: Executes a callback function for each item in an array of objects, where each object has an array property.
tripleLoop
tripleLoop
: Executes a triple loop over an array of objects and invokes a callback function for each iteration.
arrayToSet
arrayToSet
: Converts anarray
to aSet
.
getRandomItem
getRandomItem
: Returns a random item of a given array.
sortAlphabetically
sortAlphabetically
: Sorts an array ofstrings
alphabetically, in ascending or descending order.
sortNumerically
sortNumerically
: Sorts an array ofnumbers
in ascending or descending order.
sortObjectsAlphabetically
sortObjectsAlphabetically
: Sorts an array of objects alphabetically based on a specified key.
sortObjectsNumerically
sortObjectsNumerically
: Sorts an array of objects numerically based on a specified key.
sortByLength
sortByLength
:
insertElement
insertElement
: Inserts an element at a certain position in an array without modifying the original array.
shuffle
shuffle
: Shuffles the elements of an array randomly.
For Objects
objectKeys
objectKeys
: Returns an array of keys from the given object.
objectValues
objectValues
: Returns an array of values from the given object.
objectEntries
objectEntries
: Returns an array of entries from the given object.
objectToMap
objectToMap
: Converts an object to a Map.
For Maps
mapValuesToArray
mapValuesToArray
: Converts the values of aMap
to an array.
mapKeysToArray
mapKeysToArray
: Returns an array containing all the keys from a givenMap
.
mapEntriesToArray
mapEntriesToArray
: Converts aMap
object to an array of key-value pairs.
mapToObject
mapToObject
: Converts aMap
to an object.
setInMapIfNotExists
setInMapIfNotExists
: Sets a key-value pair in aMap
if the key does not already exist.
returnAMergeWith
returnAMergeWith
: Merges two maps and returns a new map.
putArrayItemsInMap
putArrayItemsInMap
: Puts array items in a Map.
mergeMaps
mergeMaps
: Merges two maps into a newMap
.
fromMapOfSetsToMapsOfArrays
fromMapOfSetsToMapsOfArrays
: Converts aMap
ofSets
to aMap
ofArrays
.
mapFromArray
mapFromArray
: Creates aMap
from an array of items, using a key handler function to determine the keys.
mapFromArrayWithValues
mapFromArrayWithValues
: Creates a newMap
object from an array by applying a transformation function to each item.
mapOfArraysFromArray
mapOfArraysFromArray
: Creates aMap
of arrays from an input array, using a key handler function.
mergeMapsOfArrays
mergeMapsOfArrays
: Merges two maps of arrays into a single map of arrays. The resulting map contains unique values from both input maps.
For Date
isWeekend
isWeekend
: Checks if a given date falls on a weekend.
daysDiff
daysDiff
: Calculates the difference in days between two dates.
today
today
: Returns the current date as an ISO formatted string.
timeStamp
timeStamp
: Returns the current time as a clock time string.
toISOStringDate
toISOStringDate
: Converts a date to an ISO formatted date string.
toISODate
toISODate
: Converts a date to an ISO formatted string.
isISODate
isISODate
: Checks if a given string is in the ISO date format (YYYY-MM-DD)
toISOTime
toISOTime
: Converts a date to an ISO formatted time string.
isISOTime
isISOTime
: Checks if the given string is in ISO time format (HH:mm.sss).
isISODateTime
isISODateTime
: Checks if the given string is in ISO 8601 date-time format.
parseUSDateToISODate
parseUSDateToISODate
: Converts a date string from US format (MM/DD/YYYY) to ISO format (YYYY-MM-DD)
toClockTime
toClockTime
: Converts a date to a clock time string.
getDayName
getDayName
: Gets the name of the day of the week for a given date.
getMonthName
getMonthName
: Gets the name of the month for a given date.
getWeekNumber
getWeekNumber
: Calculates the ISO week number for a given date.
getWeekFormat
getWeekFormat
: Returns a string representing the week format of the given date.
isWeekFormat
isWeekFormat
: Checks if a given date string is in the "YYYY-Www" week format.C
getMonthFormat
getMonthFormat
: Returns the month and year in ISO format (YYYY-MM) from a given Date object.
isMonthFormat
isMonthFormat
: Checks if the given date string is in the format of "YYYY-MM"
parseDateToHTMLFormat
parseDateToHTMLFormat
: Parses a date string into a specific HTML date format
String processors
capitalize
capitalize
: Converts first character ofstring
literal type to uppercase.
uncapitalize
uncapitalize
: Converts first character ofstring
literal type to lowercase.
kebabCase
kebabCase
: Converts astring
to kebab case.
pascalCase
pascalCase
: Converts astring
to pascal case.
snakeCase
snakeCase
: Converts astring
to snake case.
camelCase
camelCase
: Converts astring
to camel case.
upper
upper
: Converts astring
to uppercase.
lower
lower
: Converts astring
to lowercase.
removeAll
removeAll
: Removes all occurrences of a targetstring
from the inputstring
.
replaceAll
replaceAll
: Replaces all occurrences of a targetstring
with a replacementstring
in a givenstring
.
first
first
: Returns the first element of astring
after splitting it by a separator.
last
last
: Returns the last part of astring
after a specified separator.
removeExtension
removeExtension
: Removes the file extension from a givenstring
.
reverse
reverse
: Reverses astring
.
underscorePerSpace
underscorePerSpace
: Replaces all underscores (_
) in the given text with spaces.
spacePerUnderScore
spacePerUnderScore
: Replaces all spaces in the given text with underscores (_
).
hyphenPerSpace
hyphenPerSpace
: Replaces all hyphens (-
) in the given text with spaces.
spacePerHyphen
spacePerHyphen
: Replaces all spaces in the given text with hyphens (-
).
truncateString
truncateString
: Truncates a string to a specified length and appends ellipsis if necessary.
truncateStringMiddle
truncateStringMiddle
: Truncates a string by replacing the middle portion with ellipsis.
DOM manipulators
toggleAttribute
toggleAttribute
: Toggles the value of an attribute on an HTML element.
bindInputChange
bindInputChange
: Binds an input element's change event to a callback function.
Generators
createArray
createArray
: Creates an array with a givenlength
using a parser.
createCountArray
createCountArray
: Creates an array with a givenlength
and each item indicating its position.
randomNumber
randomNumber
: Generates a random number between the specified minimum and maximum values (inclusive).
randomString
randomString
: Generates a random string of the specified length.
randomColor
randomColor
: Generates a random color in hexadecimal format.
randomBoolean
randomBoolean
: Generates a random boolean value..
getLoremIpsumWords
getLoremIpsumWords
: Returns the given amount of words from the Lorem ipsum text with a maximum of 200 words.
Comparison
objectsAreEqual
objectsAreEqual
: Checks if two objects are equal by comparing their stringified representations.
arraysAreEqual
arraysAreEqual
: Checks if two arrays are equal by comparing their stringified representations.
Casters
trueTypeOf
trueTypeOf
: Determines the true type of the given object.
isBoolean
isBoolean
: Checks if a value is a boolean.
isString
isString
: Checks if the provided value is astring
.
isChar
isChar
: Checks if the provided value is a single characterstring
.
isOneOf
isOneOf
: Checks if a value is one of the specified values.
isHTTP_URL
isHTTP_URL
: Checks if a givenstring
is a valid HTTP URL.
isNotEmptyString
isNotEmptyString
: Checks if astring
is not empty.
isNumber
isNumber
: Checks if the provided value is a number.
isEven
isEven
: Checks if a number is even.
isObject
isObject
: Checks if the given value is an object.
isEmptyObject
isEmptyObject
: Checks if the given object is an empty object.
isDictOfStrings
isDictOfStrings
: Checks if the given object is a dictionary (object
) where all values of typestring
.
isDictOfNumbers
isDictOfNumbers
: Checks if the given object is a dictionary (object
) with values of typenumber
.
isDictOfBooleans
isDictOfBooleans
: Checks if the given object is a dictionary (object
) with values of typeboolean
.
isDictOfObjects
isDictOfObjects
: Checks if the given object is a dictionary (object
) with values of typeobject
.
isDictOfArrays
isDictOfArrays
: Checks if the given object is a dictionary (object
) with values of typearray
.
isPrimitive
isPrimitive
: Checks if a value is a primitive type (string
,number
,boolean
, ornull
).
isNullish
isNullish
: Checks if a value is a nullish type (undefined
ornull
).
isNonNullablePrimitive
isNonNullablePrimitive
: Checks if a value is a primitive type (string
,number
, orboolean
).
isMap
isMap
: Checks if the provided value is an instance ofMap
.
isObjectKeyMap
isObjectKeyMap
: Checks if the given map is aMap
where the keys are objects.
isStringKeyMap
isStringKeyMap
: Checks if the provided value is aMap
withstring
keys.
isNumberKeyMap
isNumberKeyMap
: Checks if the provided value is aMap
withnumber
keys.
isStringOrNumberKeyMap
isStringOrNumberKeyMap
: Checks if the provided value is aMap
withstring
ornumber
keys.
isArray
isArray
: Checks if the provided value is an array.
isEmptyArray
isEmptyArray
: Checks if the provided value is an array and empty.
isArrayOfNumbers
isArrayOfNumbers
: Checks if the given array is an array of numbers.
isArrayOfStrings
isArrayOfStrings
: Checks if the given value is an array of strings.
isArrayOfObjects
isArrayOfObjects
: Checks if the given array is an array of objects.
isArrayOfBooleans
isArrayOfBooleans
: Checks if the given array is an array of booleans.
isMatrix
isMatrix
: Checks if the given array is a matrix. A matrix is defined as a two-dimensional array where each element is an array.
Promises
reducePromisedItems
reducePromisedItems
: This function reduces promised items.
mergePromises
mergePromises
: Merges an array of promises into a single promise that resolves to an array of values.
countPromises
countPromises
: Counts the resolved values of an array of promises and returns the sum.
awaitResolved
awaitResolved
: Waits for multiple promises to resolve and returns an array of resolved values.
awaitRejected
awaitRejected
: Returns an array of rejected reasons from an array of promises.
awaitClassified
awaitClassified
: Waits for multiple promises to settle and classifies the results intoresolved
andrejected
arrays.
Other
inferTypeOfArray
inferTypeOfArray
: Infers the types of elements in an array, returning a list with the types.
sleep
sleep
: Asynchronously pauses the execution for the specified amount of time.