MCPcopy Create free account
hub / github.com/node-modules/utility / dig

Function dig

src/optimize.ts:34–51  ·  view source on GitHub ↗
(obj?: any, ...keys: string[])

Source from the content-addressed store, hash-verified

32 * avoid if (a && a.b && a.b.c)
33 */
34export function dig(obj?: any, ...keys: string[]) {
35 if (!obj) {
36 return;
37 }
38 if (keys.length === 0) {
39 return obj;
40 }
41
42 let value = obj[keys[0]];
43 for (let i = 1; i < keys.length; i++) {
44 if (!value) {
45 break;
46 }
47 value = value[keys[i]];
48 }
49
50 return value;
51}
52
53/**
54 * optimize arguments to array

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected