Spaces:
Running
Running
Download node_modules/@hapi/hoek/lib/utils.js from k-l-lambda/lotus: direct link, hf CLI and curl.
- Browser
- Download file 1.18 kB
-
https://huggingface.co/spaces/k-l-lambda/lotus/resolve/main/node_modules/%40hapi/hoek/lib/utils.js
- Command line
-
hf download hf://spaces/k-l-lambda/lotus/node_modules/@hapi/hoek/lib/utils.js
-
curl -L -o utils.js https://huggingface.co/spaces/k-l-lambda/lotus/resolve/main/node_modules/%40hapi/hoek/lib/utils.js
1.18 kB
| ; | |
| const Reach = require('./reach'); | |
| const internals = {}; | |
| exports.keys = function (obj, options = {}) { | |
| return options.symbols !== false ? Reflect.ownKeys(obj) : Object.getOwnPropertyNames(obj); // Defaults to true | |
| }; | |
| exports.store = function (source, keys) { | |
| const storage = new Map(); | |
| for (let i = 0; i < keys.length; ++i) { | |
| const key = keys[i]; | |
| const value = Reach(source, key); | |
| if (typeof value === 'object' || | |
| typeof value === 'function') { | |
| storage.set(key, value); | |
| internals.reachSet(source, key, undefined); | |
| } | |
| } | |
| return storage; | |
| }; | |
| exports.restore = function (copy, source, storage) { | |
| for (const [key, value] of storage) { | |
| internals.reachSet(copy, key, value); | |
| internals.reachSet(source, key, value); | |
| } | |
| }; | |
| internals.reachSet = function (obj, key, value) { | |
| const path = Array.isArray(key) ? key : key.split('.'); | |
| let ref = obj; | |
| for (let i = 0; i < path.length; ++i) { | |
| const segment = path[i]; | |
| if (i + 1 === path.length) { | |
| ref[segment] = value; | |
| } | |
| ref = ref[segment]; | |
| } | |
| }; | |