Edit this page

API Utility functions
module up.util

The up.util module contains functions to facilitate the work with basic JavaScript values like lists, strings or functions.

You will recognize many functions form other utility libraries like Lodash. While feature parity with Lodash is not a goal of up.util, you might find it sufficient to not include another library in your asset bundle.


Guides

Features

All features

JS
up.util.assign(target, sources...) deprecated

Merge the own properties of one or more sources into the target object.

JS
up.util.compact(list) stable

Returns all elements from the given list that are neither null or undefined.

JS
up.util.contains(value, subValue) stable

Returns whether the given value contains another value.

JS
up.util.copy(object) stable

Returns a shallow copy of the given value.

JS
up.util.copy.key experimental

This property contains the name of a method that user-defined classes may implement to hook into the up.util.copy() protocol.

JS
up.util.each(list, block) stable

Calls the given function for each element (and, optional, index) of the given list or iterator.

JS
up.util.escapeHTML(string) stable

Escapes the given string of HTML by replacing control chars with their HTML entities.

JS
up.util.evalOption(value, ...args) experimental

If the given value is a function, calls the function with the given args. Otherwise it just returns value.

JS
up.util.every(list, tester) experimental

Returns whether the given function returns a truthy value for all elements in the given list or iterator.

JS
up.util.except(object, ...keys) deprecated

Returns a copy of the given object that contains all except the given keys.

JS
up.util.filter(list, tester) stable

Returns all elements from the given list that return a truthy value when passed to the given function.

JS
up.util.find(list, tester) stable

Passes each element in the given array-like value to the given function. Returns the first element for which the function returns a truthy value.

JS
up.util.findResult(list, tester) experimental

Consecutively calls the given function which each element in the given list. Returns the first truthy return value.

JS
up.util.flatMap(list, mapping) experimental

Maps each element using a mapping function, then flattens the result into a new array.

JS
up.util.flatten(array) experimental

Flattens the given array a single depth level.

JS
up.util.isArray(object) stable

Returns whether the given argument is an array.

JS
up.util.isBlank(value) stable

Return whether the given argument is considered to be blank.

JS
up.util.isBlank.key experimental

This property contains the name of a method that user-defined classes may implement to hook into the up.util.isBlank() protocol.

JS
up.util.isBoolean(object) stable

Returns whether the given argument is a boolean value.

JS
up.util.isDefined(object) stable

Returns whether the given argument is not undefined.

JS
up.util.isElement(object) stable

Returns whether the given argument is a DOM element.

JS
up.util.isEqual(a, b) experimental

Returns whether the two arguments are equal by value.

JS
up.util.isEqual.key experimental

This property contains the name of a method that user-defined classes may implement to hook into the up.util.isEqual() protocol.

JS
up.util.isFunction(object) stable

Returns whether the given argument is a function.

JS
up.util.isGiven(object) stable

Returns whether the given argument is neither undefined nor null.

JS
up.util.isJQuery(object) stable

Returns whether the given argument is a jQuery collection.

JS
up.util.isList(value) stable

Returns whether the given argument is an array-like value.

JS
up.util.isMissing(object) stable

Returns whether the given argument is either undefined or null.

JS
up.util.isNull(object) stable

Returns whether the given argument is null.

JS
up.util.isNumber(object) stable

Returns whether the given argument is a number.

JS
up.util.isObject(object) stable

Returns whether the given argument is an object.

JS
up.util.isPresent(object) stable

Returns whether the given argument is not blank.

JS
up.util.isPromise(object) stable

Returns whether the given argument is an object with a then method.

JS
up.util.isString(object) stable

Returns whether the given argument is a string.

JS
up.util.isUndefined(object) stable

Returns whether the given argument is undefined.

JS
up.util.last(array) stable

Returns the last element of the given array or string.

JS
up.util.map(list, block) stable

Translate all items in a list to new array of items.

JS
up.util.merge(sources...) stable

Creates a new object by merging together the properties from the given objects.

JS
up.util.microtask(task) experimental

Pushes the given function to the JavaScript microtask queue.

JS
up.util.noop() experimental

A function that does nothing.

JS
up.util.normalizeURL(the, [options]) experimental

Returns a normalized version of the given URL string.

JS
up.util.omit(object, keys) stable

Returns a copy of the given object that contains all except the given keys.

JS
up.util.only(object, ...keys) deprecated

Returns a copy of the given object that only contains the given keys.

JS
up.util.parseURL(the) stable

Parses the given URL into components such as hostname and path.

JS
up.util.pick(object, keys) stable

Returns a copy of the given object that only contains the given keys.

JS
up.util.pickBy(object, tester) experimental

Returns a copy of the given object that only contains properties that pass the given tester function.

JS
up.util.pluckKey(object, key) experimental

Deletes the property with the given key from the given object and returns its value.

JS
up.util.presence(value, [tester]) stable

Returns the given argument if the argument is present, otherwise returns undefined.

JS
up.util.reject(list, tester) stable

Returns all elements from the given array-like value that do not return a truthy value when passed to the given function.

JS
up.util.remove(array, element) stable

Removes the given element from the given array.

JS
up.util.some(list, tester) stable

Returns whether the given function returns a truthy value for any element in the given array-like value.

JS
up.util.task(block) stable

Pushes the given function to the JavaScript task queue (also "macrotask queue").

JS
up.util.timer(millis, callback) stable

Waits for the given number of milliseconds, the runs the given callback.

JS
up.util.times(count, block) deprecated

Calls the given function for the given number of times.

JS
up.util.toArray(object) stable

Converts the given array-like value into an array.

JS
up.util.uniq(array) stable

Returns the given array without duplicates.

JS
up.util.uniqBy(array) experimental

This function is like uniq, accept that the given function is invoked for each element to generate the value for which uniquness is computed.

JS
up.util.values(object) deprecated

Returns an array of values of the given object.

JS
up.util.wrapList(value) experimental

Returns the given value if it is array-like, otherwise returns an array with the given value as its only element.