How to use the hoek.shallow 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
});
// Results in
// {
//     person: {
//         address: {
//             lineOne: '123 main street',
//             lineTwo: 'PO Box 1234',
//             region: 'CA'
//         }
//     },
//     title: 'Warehouse'
// }

// shallow(obj)

let shallow = Hoek.shallow({ a: { b: 1 } });

// stringify(obj)

let a: any = {};
a.b = a;
Hoek.stringify(a);      // Returns '[Cannot display object: Converting circular structure to JSON]'

// Timer

let timerObj = new Hoek.Timer();
console.log("Time is now: " + timerObj.ts);
console.log("Elapsed time from initialization: " + timerObj.elapsed() + 'milliseconds');

// Bench

let benchObj = new Hoek.Bench();
github blockstack / blockstack-browser / native / windows / BlockstackBrowser / Resources / corsproxy-https / node_modules / hapi / lib / plugin.js View on Github external
item.options = options;

        var plugins = register, items, [register, item]
    */

    var registrations = [];
    plugins = [].concat(plugins);
    for (var i = 0, il = plugins.length; i < il; ++i) {
        var plugin = plugins[i];

        if (typeof plugin === 'function') {
            if (!plugin.register) {                                 // plugin is register() function
                plugin = { register: plugin };
            }
            else {
                plugin = Hoek.shallow(plugin);                      // Convert function to object
            }
        }

        if (plugin.register.register) {                             // Required plugin
            plugin.register = plugin.register.register;
        }

        plugin = Schema.apply('plugin', plugin);

        var attributes = plugin.register.attributes;
        var registration = {
            register: plugin.register,
            name: attributes.name || attributes.pkg.name,
            version: attributes.version || attributes.pkg.version,
            multiple: attributes.multiple,
            pluginOptions: plugin.options,
github ozum / joi18n / node_modules / hapi / lib / connection.js View on Github external
internals.Connection.prototype.inject = function (options, callback) {

    var settings = options;
    if (typeof settings === 'string') {
        settings = { url: settings };
    }

    if (!settings.authority ||
        settings.credentials ||
        settings.allowInternals !== undefined) {        // Can be false

        settings = Hoek.shallow(settings);              // options can be reused
        delete settings.credentials;
        delete settings.artifacts;                      // Cannot appear without credentials
        delete settings.allowInternals;

        settings.authority = settings.authority || (this.info.host + ':' + this.info.port);
    }

    var needle = this._dispatch({
        credentials: options.credentials,
        artifacts: options.artifacts,
        allowInternals: options.allowInternals
    });

    Shot.inject(needle, settings, function (res) {

        if (res.raw.res._hapi) {
github hapijs / hapi / lib / connection.js View on Github external
if (!callback) {
        return new Promise((resolve, reject) => this.inject(options, (res) => resolve(res)));
    }

    let settings = options;
    if (typeof settings === 'string') {
        settings = { url: settings };
    }

    if (!settings.authority ||
        settings.credentials ||
        settings.app ||
        settings.plugins ||
        settings.allowInternals !== undefined) {        // Can be false

        settings = Hoek.shallow(settings);              // options can be reused
        delete settings.credentials;
        delete settings.artifacts;                      // Cannot appear without credentials
        delete settings.app;
        delete settings.plugins;
        delete settings.allowInternals;

        settings.authority = settings.authority || (this.info.host + ':' + this.info.port);
    }

    const needle = this._dispatch({
        credentials: options.credentials,
        artifacts: options.artifacts,
        allowInternals: options.allowInternals,
        app: options.app,
        plugins: options.plugins
    });
github ozum / hapi-locale / node_modules / hapi / lib / server.js View on Github external
async inject(options) {

        let settings = options;
        if (typeof settings === 'string') {
            settings = { url: settings };
        }

        if (!settings.authority ||
            settings.credentials ||
            settings.app ||
            settings.plugins ||
            settings.allowInternals !== undefined) {        // Can be false

            settings = Hoek.shallow(settings);              // options can be reused
            delete settings.credentials;
            delete settings.artifacts;                      // Cannot appear without credentials
            delete settings.app;
            delete settings.plugins;
            delete settings.allowInternals;

            settings.authority = settings.authority || (this._core.info.host + ':' + this._core.info.port);
        }

        const needle = this._core._dispatch({
            credentials: options.credentials,
            artifacts: options.artifacts,
            allowInternals: options.allowInternals,
            app: options.app,
            plugins: options.plugins
        });
github ozum / joi18n / node_modules / hapi / lib / plugin.js View on Github external
internals.Plugin.prototype._ext = function (event) {

    event = Hoek.shallow(event);
    event.plugin = this;
    var type = event.type;

    if (!this.root._extensions[type]) {

        // Realm route extensions

        if (event.options.sandbox === 'plugin') {
            Hoek.assert(this.realm._extensions[type], 'Unknown event type', type);
            return this.realm._extensions[type].add(event);
        }

        // Connection route extensions

        return this._apply('ext', Connection.prototype._ext, [event]);
    }
github hapijs / hapi / lib / plugin.js View on Github external
internals.Plugin.prototype._ext = function (event) {

    event = Hoek.shallow(event);
    event.plugin = this;
    const type = event.type;

    if (!this.root._extensions.server[type]) {

        // Realm route extensions

        if (event.options.sandbox === 'plugin') {
            Hoek.assert(this.realm._extensions[type], 'Unknown event type', type);
            return this.realm._extensions[type].add(event);
        }

        // Connection route extensions

        Hoek.assert(this.root._extensions.route[type], 'Unknown event type', type);
        return this.root._extensions.route[type].add(event);
github ozum / joi18n / node_modules / hapi / lib / connection.js View on Github external
internals.Connection.prototype._route = function (configs, plugin) {

    configs = [].concat(configs);
    for (var i = 0, il = configs.length; i < il; ++i) {
        var config = configs[i];

        if (Array.isArray(config.method)) {
            for (var m = 0, ml = config.method.length; m < ml; ++m) {
                var method = config.method[m];

                var settings = Hoek.shallow(config);
                settings.method = method;
                this._addRoute(settings, plugin);
            }
        }
        else {
            this._addRoute(config, plugin);
        }
    }
};
github hapijs / hapi / lib / connection.js View on Github external
internals.Connection.prototype._route = function (configs, plugin) {

    configs = [].concat(configs);
    for (let i = 0; i < configs.length; ++i) {
        const config = configs[i];

        if (Array.isArray(config.method)) {
            for (let j = 0; j < config.method.length; ++j) {
                const method = config.method[j];

                const settings = Hoek.shallow(config);
                settings.method = method;
                this._addRoute(settings, plugin);
            }
        }
        else {
            this._addRoute(config, plugin);
        }
    }
};
github ozum / hapi-locale / node_modules / hapi / lib / server.js View on Github external
route(options) {

        Hoek.assert(typeof options === 'object', 'Invalid route options');

        options = [].concat(options);
        for (let i = 0; i < options.length; ++i) {
            const config = options[i];

            if (Array.isArray(config.method)) {
                for (let j = 0; j < config.method.length; ++j) {
                    const method = config.method[j];

                    const settings = Hoek.shallow(config);
                    settings.method = method;
                    this._addRoute(settings, this);
                }
            }
            else {
                this._addRoute(config, this);
            }
        }
    }