---
name: "up.util"
area: "API"
kind: "module"
parent: "API reference"
url: "https://unpoly.com/api/up.util"
---
<nav aria-label="Unpoly docs">[All docs](https://unpoly.com/index.md) · [API reference](https://unpoly.com/api.md)</nav>

# `up.util`

Helper functions for basic JavaScript values.

Most functions are predicates like [`up.util.isPresent()`](https://unpoly.com/api/up.util.isPresent.md) or [`up.util.isBlank()`](https://unpoly.com/api/up.util.isBlank.md), or list helpers like [`up.util.uniq()`](https://unpoly.com/api/up.util.uniq.md), [`up.util.reject()`](https://unpoly.com/api/up.util.reject.md) and [`up.util.pick()`](https://unpoly.com/api/up.util.pick.md). They are similar to [Lodash](https://lodash.com/), but feature parity is not a goal. The module also parses the formats used in Unpoly's attributes: [`up.util.parseRelaxedJSON()`](https://unpoly.com/api/up.util.parseRelaxedJSON.md) reads [Relaxed JSON](https://unpoly.com/api/relaxed-json.md), and [`up.util.normalizeURL()`](https://unpoly.com/api/up.util.normalizeURL.md) and [`up.util.parseURL()`](https://unpoly.com/api/up.util.parseURL.md) work with URLs.

<nav aria-label="Guides">

- [Learn: Relaxed JSON](https://unpoly.com/api/relaxed-json.md)

</nav>

---

## Features {#features}

- ### [up.util.assign(target, ...sources)](https://unpoly.com/api/up.util.assign.md) (JavaScript function) (deprecated)

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

- ### [up.util.compact(list)](https://unpoly.com/api/up.util.compact.md) (JavaScript function)

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

- ### [up.util.contains(value, subValue)](https://unpoly.com/api/up.util.contains.md) (JavaScript function)

  Returns whether the given value contains another value.

- ### [up.util.copy(object)](https://unpoly.com/api/up.util.copy.md) (JavaScript function)

  Returns a shallow copy of the given value.

- ### [up.util.copy.key](https://unpoly.com/api/up.util.copy.key.md) (JavaScript property)

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

- ### [up.util.each(list, block)](https://unpoly.com/api/up.util.each.md) (JavaScript function)

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

- ### [up.util.escapeHTML(string)](https://unpoly.com/api/up.util.escapeHTML.md) (JavaScript function)

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

- ### [up.util.evalOption(value, ...args)](https://unpoly.com/api/up.util.evalOption.md) (JavaScript function)

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

- ### [up.util.every(list, tester)](https://unpoly.com/api/up.util.every.md) (JavaScript function)

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

- ### [up.util.except(object, ...keys)](https://unpoly.com/api/up.util.except.md) (JavaScript function) (deprecated)

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

- ### [up.util.filter(list, tester)](https://unpoly.com/api/up.util.filter.md) (JavaScript function)

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

- ### [up.util.find(list, tester)](https://unpoly.com/api/up.util.find.md) (JavaScript function)

  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.

- ### [up.util.findResult(list, tester)](https://unpoly.com/api/up.util.findResult.md) (JavaScript function)

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

- ### [up.util.flatMap(list, mapping)](https://unpoly.com/api/up.util.flatMap.md) (JavaScript function)

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

- ### [up.util.flatten(array)](https://unpoly.com/api/up.util.flatten.md) (JavaScript function)

  Flattens the given `array` a single depth level.

- ### [up.util.isArray(value)](https://unpoly.com/api/up.util.isArray.md) (JavaScript function)

  Returns whether the given argument is an array.

- ### [up.util.isBlank(value)](https://unpoly.com/api/up.util.isBlank.md) (JavaScript function)

  Returns whether the given argument is considered to be blank.

- ### [up.util.isBlank.key](https://unpoly.com/api/up.util.isBlank.key.md) (JavaScript property)

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

- ### [up.util.isBoolean(value)](https://unpoly.com/api/up.util.isBoolean.md) (JavaScript function)

  Returns whether the given argument is a boolean value.

- ### [up.util.isDefined(value)](https://unpoly.com/api/up.util.isDefined.md) (JavaScript function)

  Returns whether the given argument is not `undefined`.

- ### [up.util.isElement(value)](https://unpoly.com/api/up.util.isElement.md) (JavaScript function)

  Returns whether the given argument is a DOM element.

- ### [up.util.isEqual(a, b)](https://unpoly.com/api/up.util.isEqual.md) (JavaScript function)

  Returns whether the two arguments are equal by value.

- ### [up.util.isEqual.key](https://unpoly.com/api/up.util.isEqual.key.md) (JavaScript property)

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

- ### [up.util.isFunction(value)](https://unpoly.com/api/up.util.isFunction.md) (JavaScript function)

  Returns whether the given argument is a function.

- ### [up.util.isGiven(value)](https://unpoly.com/api/up.util.isGiven.md) (JavaScript function)

  Returns whether the given argument is neither `undefined` nor `null`.

- ### [up.util.isJQuery(value)](https://unpoly.com/api/up.util.isJQuery.md) (JavaScript function)

  Returns whether the given argument is a jQuery collection.

- ### [up.util.isList(value)](https://unpoly.com/api/up.util.isList.md) (JavaScript function)

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

- ### [up.util.isMissing(value)](https://unpoly.com/api/up.util.isMissing.md) (JavaScript function)

  Returns whether the given argument is either `undefined` or `null`.

- ### [up.util.isNull(object)](https://unpoly.com/api/up.util.isNull.md) (JavaScript function)

  Returns whether the given argument is `null`.

- ### [up.util.isNumber(value)](https://unpoly.com/api/up.util.isNumber.md) (JavaScript function)

  Returns whether the given argument is a number.

- ### [up.util.isObject(value)](https://unpoly.com/api/up.util.isObject.md) (JavaScript function)

  Returns whether the given argument is an object.

- ### [up.util.isPresent(value)](https://unpoly.com/api/up.util.isPresent.md) (JavaScript function)

  Returns whether the given argument is not blank.

- ### [up.util.isPromise(value)](https://unpoly.com/api/up.util.isPromise.md) (JavaScript function)

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

- ### [up.util.isString(value)](https://unpoly.com/api/up.util.isString.md) (JavaScript function)

  Returns whether the given argument is a string.

- ### [up.util.isUndefined(value)](https://unpoly.com/api/up.util.isUndefined.md) (JavaScript function)

  Returns whether the given argument is `undefined`.

- ### [up.util.last(array)](https://unpoly.com/api/up.util.last.md) (JavaScript function)

  Returns the last element of the given array or string.

- ### [up.util.map(list, block)](https://unpoly.com/api/up.util.map.md) (JavaScript function)

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

- ### [up.util.mapObject(array, mapping)](https://unpoly.com/api/up.util.mapObject.md) (JavaScript function)

  Creates an object from the given array and mapping function.

- ### [up.util.merge(...sources)](https://unpoly.com/api/up.util.merge.md) (JavaScript function)

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

- ### [up.util.microtask(task)](https://unpoly.com/api/up.util.microtask.md) (JavaScript function) (deprecated)

  Pushes the given function to the JavaScript microtask queue.

- ### [up.util.noop()](https://unpoly.com/api/up.util.noop.md) (JavaScript function)

  A function that does nothing.

- ### [up.util.normalizeURL(url, [options])](https://unpoly.com/api/up.util.normalizeURL.md) (JavaScript function)

  Returns a normalized version of the given URL string.

- ### [up.util.omit(object, keys)](https://unpoly.com/api/up.util.omit.md) (JavaScript function)

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

- ### [up.util.only(object, ...keys)](https://unpoly.com/api/up.util.only.md) (JavaScript function) (deprecated)

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

- ### [up.util.parseNumber(value)](https://unpoly.com/api/up.util.parseNumber.md) (JavaScript function) (experimental)

  Parses the given value and returns a number.

- ### [up.util.parseRelaxedJSON(text)](https://unpoly.com/api/up.util.parseRelaxedJSON.md) (JavaScript function) (experimental)

  Parses a string of relaxed JSON into a JavaScript value.

- ### [up.util.parseURL(the)](https://unpoly.com/api/up.util.parseURL.md) (JavaScript function)

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

- ### [up.util.pick(object, keys)](https://unpoly.com/api/up.util.pick.md) (JavaScript function)

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

- ### [up.util.pickBy(object, tester)](https://unpoly.com/api/up.util.pickBy.md) (JavaScript function) (experimental)

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

- ### [up.util.pluckKey(object, key)](https://unpoly.com/api/up.util.pluckKey.md) (JavaScript function)

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

- ### [up.util.presence(value, [tester])](https://unpoly.com/api/up.util.presence.md) (JavaScript function)

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

- ### [up.util.reject(list, tester)](https://unpoly.com/api/up.util.reject.md) (JavaScript function)

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

- ### [up.util.remove(array, element)](https://unpoly.com/api/up.util.remove.md) (JavaScript function)

  Removes the given element from the given array.

- ### [up.util.some(list, tester)](https://unpoly.com/api/up.util.some.md) (JavaScript function)

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

- ### [up.util.task(callback)](https://unpoly.com/api/up.util.task.md) (JavaScript function)

  Schedules a function to the JavaScript task queue (also "macrotask queue").

- ### [up.util.timer(millis, callback)](https://unpoly.com/api/up.util.timer.md) (JavaScript function)

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

- ### [up.util.times(count, block)](https://unpoly.com/api/up.util.times.md) (JavaScript function) (deprecated)

  Calls the given function for the given number of times.

- ### [up.util.toArray(value)](https://unpoly.com/api/up.util.toArray.md) (JavaScript function)

  Converts the given array-like value into an array.

- ### [up.util.uniq(array)](https://unpoly.com/api/up.util.uniq.md) (JavaScript function)

  Returns the given array without duplicates.

- ### [up.util.uniqBy(array)](https://unpoly.com/api/up.util.uniqBy.md) (JavaScript function) (experimental)

  This function is like `uniq`, except that the given function is invoked for each element to generate the value for which uniqueness is computed.

- ### [up.util.values(object)](https://unpoly.com/api/up.util.values.md) (JavaScript function) (deprecated)

  Returns an array of values of the given object.

- ### [up.util.wrapList(value)](https://unpoly.com/api/up.util.wrapList.md) (JavaScript function)

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

