@laserware/arcade

Array

removeAtIndex

Removes the item at the specified index from the specified items array.

sortBy

Sorts the specified items by the specified field.

toReversed

Creates a copy of the specified array of items with the items reversed.

toSorted

Creates a copy of the specified array of items sorted by the optional compareFunc. This is done because the native sort function mutates the array.

uniq

Removes any duplicate values from the specified items array.

Collection

Iteratee

Function that iterates over the specified object item and returns the key.

appendToGroup

Appends a value to the dict entry associated with the specified key. If the key is not present in the dict, add it as an array containing value. The object is mutated for performance reasons, and the mutated dict is returned.

groupBy

Groups the specified items array by the specified property.

keyBy

Converts a collection of items to keyed by the specified field name.

searchWithin

Returns an array of values in which the specified fieldName value matches the specified searchTerm in the specified collection.

sumBy

Sums the values of the specified field in the specified collection of objects.

Date

DateFormatMaskOption
Mask Description
d Day of the month as digits; no leading zero for single-digit days.
dd Day of the month as digits; leading zero for single-digit days.
ddd Day of the week as a three-letter abbreviation.
DDD "Ysd", "Tdy" or "Tmw" if date lies within these three days. Else fall back to ddd.
dddd Day of the week as its full name.
DDDD "Yesterday", "Today" or "Tomorrow" if date lies within these three days. Else fall back to dddd.
m Month as digits; no leading zero for single-digit months.
mm Month as digits; leading zero for single-digit months.
mmm Month as a three-letter abbreviation.
mmmm Month as its full name.
yy Year as last two digits; leading zero for years less than 10.
yyyy Year represented by four digits.
h Hours; no leading zero for single-digit hours (12-hour clock).
hh Hours; leading zero for single-digit hours (12-hour clock).
H Hours; no leading zero for single-digit hours (24-hour clock).
HH Hours; leading zero for single-digit hours (24-hour clock).
M Minutes; no leading zero for single-digit minutes.
MM Minutes; leading zero for single-digit minutes.
N ISO 8601 numeric representation of the day of the week.
o GMT/UTC timezone offset, e.g. -0500 or +0230.
p GMT/UTC timezone offset, e.g. -05:00 or +02:30.
s Seconds; no leading zero for single-digit seconds.
ss Seconds; leading zero for single-digit seconds.
S The date's ordinal suffix (st, nd, rd, or th). Works well with d.
l Milliseconds; gives 3 digits.
L Milliseconds; gives 2 digits.
t Lowercase, single-character time marker string: a or p.
tt Lowercase, two-character time marker string: am or pm.
T Uppercase, single-character time marker string: A or P.
TT Uppercase, two-character time marker string: AM or PM.
W ISO 8601 week number of the year, e.g. 4, 42.
WW ISO 8601 week number of the year, leading zero for single-digit, e.g. 04, 42
Z US timezone abbreviation, e.g. EST or MDT. For non-US timezones, the GMT/UTC offset is returned, e.g. GMT-0500.
'...', "..." Literal character sequence. Surrounding quotes are removed.
dateFormat

Formats the specified date using the specified format mask.

Events

TypedEventTarget

Used to add type safety to event listeners on a class that extends EventTarget. See the example below for additional details.

TypedEventListenerObject

An object that can be passed to the listener parameter of TypedEventTarget.addEventListener and TypedEventTarget.removeEventListener.

TypedEventListener

A function that can be passed to the listener parameter of TypedEventTarget.addEventListener and TypedEventTarget.removeEventListener.

TypedEventListenerOrEventListenerObject

File System

joinFilePath

Joins the specified file pathElements based on the host platform path separator.

splitFilePath

Splits the specified filePath into separate elements based on the host platform path separator.

Function

debounce

Creates a debounced function that only invokes func at most once per every delay milliseconds (or once per browser frame).

noop

Does nothing. Useful for initializing function variables or properties before assigning values. Note that it returns any instead of void and accepts arbitrary arguments so TypeScript doesn't freak out.

throttle

Creates a throttled function that only invokes func at most once per every delay milliseconds (or once per browser frame). See this article for additional details.

Number

asNumber

Attempts to extract the numeric value from the specified value. This function will always return a number. If a number cannot be extracted from the value, returns the specified fallback.

clamp

Clamps specified value within the inclusive lower and upper bounds.

gte

Checks if the specified value is greater than or equal to the specified other value.

isValidNumber

Checks if the specified value is a valid number. If the value is NaN, returns false.

lte

Checks if the specified value is less than or equal to the specified other value.

randomNumber

Returns a random integer between the minimum and maximum specified values.

round

Rounds the specified value to the specified precision.

toNumber

Attempts to coerce the specified value to a number. If the value cannot be coerced to a valid number, returns the specified fallback value.

Object

entriesOf

Creates an array of [key, value] pairs for the specified dict. The purpose of this function is to allow an override for the type of the object key since TypeScript defaults to only allowing a string, number, or symbol (but it could be an enum).

isEqual

Returns true if the specified left and right values are deeply equal.

isPlainObject

Checks if the specified value is a plain object.

keysOf

Gets the keys of the specified dict as an array that won't throw a TypeScript error if you try to loop through them and access values from the corresponding dict.

omit

Removes the specified key from the specified dict and returns a copy of the updated object.

toEntries

Creates an array of [key, value] pairs for the specified dict. The purpose of this function is to allow an override for the type of the object key since TypeScript defaults to only allowing a string (but it could be a string enum).

Platform

Platform

Possible platforms for the host. Note that Linux encompasses several different distros. But for the purposes of this library, we only need to know the specific OS distro.

getPlatform

Gets the current OS/platform that the application is running on.

isPlatform

Checks if the specified platform matches the host.

Runtime

Runtime

Runtime environment in which the code is executing.

getRuntime

Gets the current JavaScript runtime in which the application is running.

isRunningIn

Checks if the program is running in the specified runtime.

isRuntime

Checks if the specified runtime matches the host.

String

camelCase

Transforms the specified string value to camelCase.

capitalize

Capitalizes the first letter of the specified value and returns the result.

dedent

Strips indentation from multi-line template strings.

kebabCase

Converts the specified value to kebab-case.

Terminal

TerminalStyle

Terminal style that can be applied to a string before logging.

TerminalStyleFormatter

Callback that takes an input string and returns the result with formatting applied.

TerminalStyles

Object with key of terminal style and value of the corresponding formatter callback to apply style to an input.

terminalStyles

Object with terminal style formatters. Use this if you don't need to programmatically set whether terminal styles should be enabled.

createTerminalStyles

Creates a terminal styles formatter object dynamically and returns an object with formatter functions for applying formatting to an input. This is provided in the event that you need to explicitly enable or disable terminal colors programmatically.

Types

AnyDict

Object with key of DictKey and any value.

AnyFunc

Function that takes any variable arguments and returns any value.

AnyPlainObject

Any plain object with key/value pair of type any.

Dict

Key/value pair with key of valid DictKey.

DictKey

Valid key type for an object (i.e. dictionary).

KeysOf

Extracts the string keys of the specified object into an array.

Maybe

Represents a value that could be of type T or null or undefined.

OneOrManyOf

Type is either a single item or array of items of type T.

Primitive

Represents primitive values (i.e. booleans, numbers, and strings).

WithNullValues

Adds null as the possible type for the fields in the specified type.

WithUndefinedValues

Adds undefined as the possible type for the fields in the specified type.

Utility

cast

Forces the specified value to be the specified type T to get around annoying TypeScript idiosyncrasies.

isEmpty

Checks if the specified value is empty.

isNil

Checks if the specified value is null or undefined.

isNotNil

Checks if the specified value is not null and not undefined.

pause

Pauses execution for the specified duration.

toBoolean

Converts the specified value to a boolean (note that it is case-insensitive).

uuid

Generates a V4 UUID using the Node.js crypto.randomUUID function or the browser's crypto.randomUUID function. The correct one to use is determined automatically.