How to use the hoek.clone function in hoek

To help you get started, we’ve selected a few hoek examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / hoek / hoek-tests.ts View on Github external
*/

// clone(obj)

let nestedObj = {
    w: /^something$/ig,
    x: {
        a: [1, 2, 3],
        b: 123456,
        c: new Date()
    },
    y: 'y',
    z: new Date()
};

let copy = Hoek.clone(nestedObj);

copy.x.b = 100;

console.log(copy.y);        // results in 'y'
console.log(nestedObj.x.b); // results in 123456
console.log(copy.x.b);      // results in 100

// cloneWithShallow(obj, keys)

nestedObj = {
    w: /^something$/ig,
    x: {
        a: [1, 2, 3],
        b: 123456,
        c: new Date()
    },
github arangodb / arangodb / js / node / node_modules / joi / lib / errors.js View on Github external
internals.annotate = function () {

    var obj = Hoek.clone(this._object || {});

    var lookup = {};
    var el = this.details.length;
    for (var e = el - 1; e >= 0; --e) {        // Reverse order to process deepest child first
        var pos = el - e;
        var error = this.details[e];
        var path = error.path.split('.');
        var ref = obj;
        for (var i = 0, il = path.length; i < il && ref; ++i) {
            var seg = path[i];
            if (i + 1 < il) {
                ref = ref[seg];
            }
            else {
                var value = ref[seg];
                if (value !== undefined) {
github glennjones / hapi-swagger / lib / index-old.js View on Github external
handler: function (request, reply) {


            var requestSettings = Hoek.clone(settings);
            requestSettings.log = request.server.log.bind(request.server);

            // get protocol and host from request
            var protocol = request.headers['x-forwarded-proto'] ||
              request.server.info.protocol ||
              'http';
            var host = request.headers['x-forwarded-host'] || request.headers.host;
            var urlConfig = {
              protocol: protocol,
              host: host
            };

            // Treat protocol and host as defaults, and override with requestSettings
            var baseUrlConfig = Hoek.applyToDefaults(
              urlConfig,
              Url.parse(requestSettings.basePath)
github nakardo / good-slack / test / index.js View on Github external
server.listen(0, 'localhost', () => {

            const reporter = new GoodSlack({
                url: internals.getUri(server),
                host: 'localhost'
            });

            const event = Hoek.clone(internals.events.response);
            event.timestamp = now;
            event.statusCode = 404;

            stream.pipe(reporter);
            stream.push(event);
            stream.push(event);
        });
    });
github hapijs / hawk / test / message.js View on Github external
credentialsFunc('123456', function (err, credentials) {

            var creds = Hoek.clone(credentials);
            creds.algorithm = 'blah';
            var auth = Hawk.client.message('example.com', 8080, 'some message', { credentials: creds });
            expect(auth).to.not.exist();
            done();
        });
    });
github graalvm / graaljs / deps / npm / node_modules / request / node_modules / hawk / lib / client.js View on Github external
exports.authenticate = function (res, credentials, artifacts, options, callback) {

    artifacts = Hoek.clone(artifacts);
    options = options || {};

    let wwwAttributes = null;
    let serverAuthAttributes = null;

    const finalize = function (err) {

        if (callback) {
            const headers = {
                'www-authenticate': wwwAttributes,
                'server-authorization': serverAuthAttributes
            };

            return callback(err, headers);
        }
github flaviuse / mern-authentication / client / node_modules / joi / lib / types / object / index.js View on Github external
}
            }
        }

        if (this._inner.children &&
            !shallow) {

            description.children = {};
            for (let i = 0; i < this._inner.children.length; ++i) {
                const child = this._inner.children[i];
                description.children[child.key] = child.schema.describe();
            }
        }

        if (this._inner.dependencies.length) {
            description.dependencies = Hoek.clone(this._inner.dependencies);
        }

        if (this._inner.patterns.length) {
            description.patterns = [];

            for (let i = 0; i < this._inner.patterns.length; ++i) {
                const pattern = this._inner.patterns[i];
                if (pattern.regex) {
                    description.patterns.push({ regex: pattern.regex.toString(), rule: pattern.rule.describe() });
                }
                else {
                    description.patterns.push({ schema: pattern.schema.describe(), rule: pattern.rule.describe() });
                }
            }
        }
github krakenjs / levee / lib / stats.js View on Github external
snapshot: function snapshot() {
        var counts, samples;

        counts = Hoek.clone(this._counts);
        samples = this._samples;

        return {
            counts: counts,
            samples: Object.keys(samples).reduce(function (obj, prop) {
                var data;

                data = samples[prop];

                obj[prop] = {
                    average: avg(data),
                    count: data.length
                };

                return obj;
            }, {})
github flaviuse / mern-authentication / client / node_modules / joi / lib / types / any / index.js View on Github external
let args;

            if (state.parent !== null &&
                this._flags.default.length > 0) {

                args = [Hoek.clone(state.parent), options];
            }

            const defaultValue = internals._try(this._flags.default, args);
            finalValue = defaultValue.value;
            if (defaultValue.error) {
                errors.push(this.createError('any.default', { error: defaultValue.error }, state, options));
            }
        }
        else {
            finalValue = Hoek.clone(this._flags.default);
        }

        if (errors.length &&
            typeof this._flags.error === 'function' &&
            (
                !this._flags.selfError ||
                errors.some((e) => state.path.length === e.path.length)
            )
        ) {
            const change = this._flags.error.call(this, errors);

            if (typeof change === 'string') {
                errors = [this.createOverrideError('override', { reason: errors }, state, options, change)];
            }
            else {
                errors = [].concat(change)
github hapijs / joi / lib / any.js View on Github external
clone() {

        const obj = Object.create(Object.getPrototypeOf(this));

        obj.isJoi = true;
        obj._type = this._type;
        obj._settings = internals.concatSettings(this._settings);
        obj._valids = Hoek.clone(this._valids);
        obj._invalids = Hoek.clone(this._invalids);
        obj._tests = this._tests.slice();
        obj._refs = this._refs.slice();
        obj._flags = Hoek.clone(this._flags);

        obj._description = this._description;
        obj._unit = this._unit;
        obj._notes = this._notes.slice();
        obj._tags = this._tags.slice();
        obj._examples = this._examples.slice();
        obj._meta = this._meta.slice();

        obj._inner = {};
        const inners = Object.keys(this._inner);
        for (let i = 0; i < inners.length; ++i) {
            const key = inners[i];
            obj._inner[key] = this._inner[key] ? this._inner[key].slice() : null;
        }

        return obj;