Util.id Module
Last updated
Was this helpful?
Last updated
Was this helpful?
Import
Returns true if the passed in argument is a string and is in the form of an ObjectID (/^[0-9a-fA-F]{24}$/)
Arguments
id
(String) the string to test
Returns
Boolean
Returns true if the passed in argument is an instance of ObjectID or a string in the form of an ObjectID (/^[0-9a-fA-F]{24}$/).
Arguments
id
(String|ObjectID)
Returns
Boolean
Returns true if all passed in identifiers are equal and valid as ObjectIDs
Arguments
...ids
(String[]|ObjectID[])
Returns
Boolean
Converts a timestamp (in ms), parsable date string or date value to an ObjectID. Useful for comparing ObjectIDs (eg. {_id: {$gt: ids.timestampToId(Date.now()-86400000)}}
)
Arguments
timestamp
(String|Number|Date)
Returns
ObjectID
Converts an ObjectID to a timestamp (in seconds)
Arguments
id
(ObjectID)
Returns
Number
Guarantees return of an ObjectID if the id argument is an ObjectID, a valid string representation, or if the fromObject argument is true and the id argument is a javascript object with a valid _id
property. Returns null otherwise.
Arguments
id
(ObjectID|String|Object)
fromObject
(Boolean) default false. if true, checks for a valid _id
property of the id argument.
Returns
ObjectID
Returns the index of the id argument in the ids array, or -1 if ids is not an array or id is not present.
Arguments
ids
(ObjectID[])
id
(ObjectID|String)
Returns
Number
Returns true if the id argument value is contained in the ids array.
Arguments
ids
(ObjectID[])
id
(ObjectID|String)
Returns
Boolean
Converts the ids argument into an array of ObjectIDs or String representations thereof. Any values that do not qualify are removed from the array. Note the ids argument may be modified inside the function.
Arguments
ids
(ObjectID[])
convertToStrings
(Boolean) If true, converts each valid ObjectID to string.
fnEach
(Function) If present, calls the function for each raw value in the input array ()(id) => { ...; return id; }
), which should return a value that is then passed into getIdOrNull(id)
Returns
ObjectID[]
Returns an array of ObjectIDs with all duplicates removed.
Arguments
ids
(ObjectID[])
Returns
ObjectID[]
Given an array of objects, uses path
to inspect object properties for the first matching id
and returns its index in the array, or -1.
Arguments
objects
(Object[])
path
(String) A dot syntax path to inspect (Uses util.paths.to internally)
id
(ObjectID|String) The identifier to match.
Returns
Number
Given an array of objects, uses path
to inspect object properties for the first matching id
and returns the matching object.
Arguments
objects
(Object[])
path
(String) A dot syntax path to inspect (Uses util.paths.to internally)
id
(ObjectID|String) The identifier to match.
Returns
Object
Returns the values from array
that are not present in the other arrays.
Arguments
objects
(ObjectID[])
...rest
(ObjectID[])
Returns
ObjectID[]
Computes the list of values that are the intersection of all the arrays. Each value in the result is present in each of the arrays.
Arguments
...arrays
(ObjectID[])
Returns
ObjectID[]
Returns true if id
is an instance of ObjectID
Arguments
id
(ObjectID)
Returns
Boolean