@feathersjs/commons package provides a collection of utility functions and helpers that are used throughout the Feathers ecosystem. These utilities offer lightweight alternatives to lodash-style operations and common JavaScript patterns.
Installation
String Utilities
stripSlashes
Removes all leading and trailing slashes from a path string.string
required
The string to strip slashes from
string
The string with leading and trailing slashes removed
Object Utilities
The_ object provides a collection of utility functions for working with objects and arrays.
_.each
Iterates over an object or array and executes a callback for each element.any
required
The object or array to iterate over
(value: any, key: string) => void
required
Function called for each element with value and key/index
_.some
Tests whether at least one element passes the test implemented by the callback.any
required
The object to test
(value: any, key: string) => boolean
required
Function to test each element
boolean
True if at least one element passes the test, false otherwise
_.every
Tests whether all elements pass the test implemented by the callback.any
required
The object to test
(value: any, key: string) => boolean
required
Function to test each element
boolean
True if all elements pass the test, false otherwise
_.keys
Returns an array of the object’s keys.any
required
The object to extract keys from
string[]
Array of object keys
_.values
Returns an array of the object’s values.any
required
The object to extract values from
any[]
Array of object values
_.isMatch
Checks if all properties in the item object match those in the source object.any
required
The source object to check against
any
required
The object with properties to match
boolean
True if all item properties match obj properties
_.isEmpty
Checks if an object has no properties.any
required
The object to check
boolean
True if the object has no keys
_.isObject
Checks if a value is a plain object (not an array or null).any
required
The value to check
boolean
True if the value is a plain object
_.isObjectOrArray
Checks if a value is an object or array (not null).any
required
The value to check
boolean
True if the value is an object or array
_.extend
Shallow merges multiple objects into the first object.any
required
The target object to extend
any[]
Additional objects to merge into the target
any
The extended target object
_.omit
Creates a new object with specified keys removed.any
required
The source object
string[]
required
Keys to omit from the result
any
New object without the specified keys
_.pick
Creates a new object with only the specified keys.any
required
The source object
string[]
required
Keys to include in the result
any
New object with only the specified keys
_.merge
Recursively merges the source object into the target object.any
required
The target object to merge into
any
required
The source object to merge from
any
The merged target object
Promise Utilities
isPromise
Duck-checks if an object looks like a promise.any
required
The value to check
boolean
True if the value has a then method
Symbol Utilities
createSymbol
Creates a symbol usingSymbol.for() if available, otherwise returns the string.
string
required
The name for the symbol
symbol | string
A symbol created with Symbol.for(), or the name string if Symbol is unavailable
Debug Utilities
createDebug
Creates a debug function for a specific namespace.string
required
The namespace for the debug function
DebugFunction
A debug function for the specified namespace
setDebug
Sets a custom debug initializer for all debug instances.DebugInitializer
required
The debug initializer function
noopDebug
A no-operation debug function that does nothing.DebugFunction
A function that does nothing when called