LogoLogo
  • Introduction
  • Features
  • Getting Started
    • Cortex User Guide
      • Organizations
      • Log in
      • Generate an API key
      • Make your first API request
      • Configure the org settings
      • Set up a data model
        • Create custom objects
        • Add custom properties
      • One-to-many relationships
      • Read and write data
      • Making a Request
      • Handling responses
      • Authentication
      • Two-factor authentication
      • Set third-party cookies
      • Connections
      • Upload files
      • Cortex iOS
      • Get started with Swift
      • Cortex service accounts
      • Cortex developer tools
      • Automated Account Notifications
  • Cortex API
    • Overview
    • Objects
      • Objects Overview
      • Organization
      • Account
      • Connections
      • Notifications
      • Stats
      • Logs
      • Export
      • Events
      • Room
    • Object Definition
      • Object Properties
        • Any
        • Binary
        • Boolean
        • Date
        • Document
        • File
        • Geometry
        • List
        • Number
        • ObjectId
        • Reference
        • String
    • Object Types
    • Access Control
    • Querying
      • Query Operators
      • Property Selection
      • Property Access
    • Aggregating
      • Aggregation Operators
    • Scripting
      • Script Types
      • Script Limits
      • ObjectId
      • CortexObject
        • Accounts
        • Views
      • Cursors
      • Operations
      • Script Modules
        • API Module
        • Base64 Module
        • Cache Module
        • Connections Module
        • Console Module
        • Consts Module
        • Counters Module
        • Crypto Module
        • HTTP Module
        • Logger Module
        • Notifications Module
        • Request Module
        • Response Module
        • SAML Module
        • Schemas Modules
        • Script Module
        • Session Module
        • Util.id Module
        • Util.ip Module
        • Util.paths Module
        • XML Module
        • Developer
        • Config
        • Renderer
        • SFTP
        • FTP
        • DB
          • Cursors
          • Driver
      • Static Methods
        • Accounts
        • Views
        • Cursors
      • Audit
      • Environments
      • HTTP Driver
      • Notifications
        • Firebase Cloud Messaging (FCM)
        • Tencent Push Notification Service Configuration
      • Televisit
      • Transforms
      • Localization
      • Available Javascript Libraries
    • Decorators
      • Runtime
        • Acl
        • As
        • Log
        • Profile
      • Static
        • Env
        • Job
        • Object
        • On
        • Policy
        • Route
        • Transform
        • Trigger
    • Expressions
      • Primer
      • Pipelines
      • Operators
      • Accumulators
      • Variables
      • Conditionals
      • Transforms
      • Triggers
      • On
      • Events
    • Faults
      • Fault Reference
  • Releases
    • Cortex Release Notes
      • Cortex API 2.28.3 (R3.4.6)
      • Cortex API 2.28.1 (R3.4.3)
      • Cortex API 2.27.2 (R3.4.1)
      • Cortex API 2.27.1 (R3.3.5)
      • SQL DB Connector 1.3.4 (R3.3.3)
      • Cortex API 2.26.2 (R3.3.1)
      • Cortex API 2.26.1 (R3.2.2)
      • Cortex API 2.26.0 (R3.2.1)
      • SQL DB Connector 1.3.3
      • Cortex API 2.25.0 (R3.1.1)
      • SQL DB Connector 1.3.2 (R3.1.0)
      • Cortex API 2.24.2 (R3.0.2)
      • SQL DB Connector 1.3.1 (R3.0.0)
      • Cortex API 2.24.1 (R2.3.3)
      • Cortex API 2.24.0 (R2.3.2)
      • SQL DB Connector 1.3.0 (R2.3.0)
      • Cortex API 2.23.0 (R2.2.4)
      • SQL DB Connector 1.2.0 (R2.2.0)
      • Cortex API 2.22.2 (R2.1.2)
      • Cortex API 2.22.1 and SQL DB Connector 1.1.1 (R2.0.1)
      • Cortex API 2.22.0
      • Cortex API 2.21.3
      • Cortex API 2.21.2
      • Cortex Web 4.16.0
      • Cortex Web 4.15.1
      • Cortex API 2.20.1
      • Cortex Web 4.14.0
      • Cortex Renderer 1.3.3
      • Cortex API 2.19.4
      • Cortex API 2.19.3 and Cortex Web 4.13.1
      • Cortex Renderer 1.3.2
      • Cortex API 2.19.1
      • Cortex API 2.18.0
      • Cortex API 2.17.6
      • Cortex API 2.17.5
      • Cortex API 2.17.4
      • Cortex API 2.17.3
      • Cortex API 2.17.2
      • Cortex API 2.17.1
      • Cortex API 2.16.0
      • Cortex API 2.15.9
      • Cortex API 2.15.8-1
      • Cortex 2.15.8
      • Cortex API 2.18.1
      • Cortex API 2.16.1
      • Cortex Renderer 1.3.1
      • Cortex Renderer 1.3.0
      • Cortex Renderer 1.2.2
      • Cortex Renderer 1.2.1
      • Cortex Renderer 1.2.0
    • Third-Party License Attribution

© 2025 Medable, Inc. All rights reserved.

On this page
  • Methods
  • isIdFormat(id)
  • couldBeId(id)
  • equalIds(...ids)
  • timestampToId(timestamp)
  • idToTimestamp(id)
  • getIdOrNull(id, fromObject)
  • indexOfId(ids, id)
  • inIdArray(ids, id)
  • getIdArray(ids, convertToStrings, fnEach)
  • uniqueIdArray(ids)
  • findIdPos(objects, path, id)
  • findIdInArray(objects, path, id)
  • diffIdArrays(array, ...rest)
  • intersectIdArrays(...arrays)
  • isId(id)

Was this helpful?

  1. Cortex API
  2. Scripting
  3. Script Modules

Util.id Module

Last updated 3 years ago

Was this helpful?

Import

import { id } from 'util';

Methods

isIdFormat(id)

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

couldBeId(id)

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

equalIds(...ids)

Returns true if all passed in identifiers are equal and valid as ObjectIDs

Arguments

  • ...ids (String[]|ObjectID[])

Returns

Boolean

timestampToId(timestamp)

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

idToTimestamp(id)

Converts an ObjectID to a timestamp (in seconds)

Arguments

  • id (ObjectID)

Returns

Number

getIdOrNull(id, fromObject)

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

indexOfId(ids, id)

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

inIdArray(ids, id)

Returns true if the id argument value is contained in the ids array.

Arguments

  • ids (ObjectID[])

  • id (ObjectID|String)

Returns

Boolean

getIdArray(ids, convertToStrings, fnEach)

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[]

uniqueIdArray(ids)

Returns an array of ObjectIDs with all duplicates removed.

Arguments

  • ids (ObjectID[])

Returns

ObjectID[]

findIdPos(objects, path, id)

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

findIdInArray(objects, path, id)

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

diffIdArrays(array, ...rest)

Returns the values from array that are not present in the other arrays.

Arguments

  • objects (ObjectID[])

  • ...rest (ObjectID[])

Returns

ObjectID[]

intersectIdArrays(...arrays)

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[]

isId(id)

Returns true if id is an instance of ObjectID

Arguments

  • id (ObjectID)

Returns

Boolean

isIdFormat(id)
couldBeId(id)
equalIds(...ids)
timestampToId(timestamp)
idToTimestamp(id)
getIdOrNull(id, fromObject)
indexOfId(ids, id)
inIdArray(ids, id)
getIdArray(ids, convertToStrings, fnEach)
uniqueIdArray(ids)
lookupId(obj, id)
findIdPos(array, path, id)
findIdInArray(array, path, id, useGetter)
diffIdArrays(array, ...rest)
intersectIdArrays(...arrays)
isId(id)