Skip to Content
DocumentationGuidesUtility Functions

Utility Functions

A collection of utility functions built on Lodash  for common data manipulation and validation tasks. They work on any array of objects - not just records pulled from ARM collections.

// Sample data used in the examples below const addresses = [ { id: 1, attributes: { kind: 'office', label: 'My Office' } }, { id: 2, attributes: { kind: 'school', label: 'My School' } }, { id: 3, attributes: { kind: 'school', label: "My Brother's School" } }, ]

Data retrieval and manipulation

MethodDescription
findBy(objects, findProperties)First element matching the given properties
findIndexBy(objects, findIndexProperties)Index of the first element matching the given properties
filterBy(objects, filterProperties)All elements matching the given properties
uniqBy(objects, uniqByProperty)New array with duplicates removed, by a property
uniq(values)New array with duplicate primitive values removed
groupBy(objects, groupByProperty)Groups objects into arrays keyed by a property
mapBy(objects, mapByProperty)New array of just one property from each object
firstObject(objects)First element, or undefined if empty
lastObject(objects)Last element, or undefined if empty
mergeObjects(objects, otherObjects)Combines two arrays into one, removing duplicate entries
chunkObjects(objects, chunkSize)Splits an array into smaller arrays of a given size
sortBy(objects, sortProperties)Sorts by one or more 'property:direction' descriptors
sum(objects)Sum of an array of numbers
sumBy(objects, sumByProperty)Sum of a numeric property across an array of objects
ARM.findBy(addresses, { id: 1 }) // the record with id 1 ARM.filterBy(addresses, { attributes: { kind: 'school' } }) // ids 2 and 3 ARM.groupBy(addresses, 'attributes.kind') // { office: [...], school: [...] } ARM.sortBy(addresses, ['id:desc']) // ordered 3, 2, 1 ARM.sumBy( [ { id: 1, name: 'Banana', price: 100 }, { id: 2, name: 'Apple', price: 200 }, { id: 3, name: 'Orange', price: 300 }, ], 'price', ) // 600

ajax(config) - a raw Axios request using ARM’s base configuration - is covered in Request Functions, since it shares the same request pipeline as query/findAll/etc.

Data validation and comparison

MethodDescription
isEmpty(value)true for null, undefined, '', [], or {}
isPresent(value)The opposite of isEmpty
isEqual(value, other)Deep comparison between two values
isNumber(value)true if the value is a number
isNil(value)true if null or undefined
isNull(value)true if null
isGte(value, other)value >= other
isGt(value, other)value > other
isLte(value, other)value <= other
isLt(value, other)value < other
Last updated on