UNPKG

@voiceflow/common

Version:

Junk drawer of utility functions

16 lines (15 loc) 572 B
import ObjectId from 'bson-objectid'; import cuid from 'cuid'; import { deepMap, deepMapKeys } from './object/index.js'; export { cuid }; export const objectID = () => new ObjectId().toHexString(); export const remapObjectIDs = (object, lookupMap) => { const map = lookupMap instanceof Map ? lookupMap : new Map(Object.entries(lookupMap)); const mapping = (value) => { if (typeof value === 'string' && map.has(value)) { return map.get(value); } return value; }; return deepMapKeys(deepMap(object, mapping), mapping); };