How to use the hoek.deepEqual 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
let defaults1 = {
    server: {
        host: "localhost",
        port: 8000
    },
    name: 'example'
};

let options2 = { server: { port: 8080 } };

let config1 = Hoek.applyToDefaultsWithShallow(defaults1, options2, ['server']); // results in { server: { port: 8080 }, name: 'example' }

// deepEqual(b, a, [options])

Hoek.deepEqual({ a: [1, 2], b: 'string', c: { d: true } }, { a: [1, 2], b: 'string', c: { d: true } }); //results in true
Hoek.deepEqual(Object.create(null), {}, { prototype: false }); //results in true
Hoek.deepEqual(Object.create(null), {}); //results in false

// unique(array, key)

let array = [1, 2, 2, 3, 3, 4, 5, 6];

let newArray = Hoek.unique(array);    // results in [1,2,3,4,5,6]

let array1 = [{ id: 1 }, { id: 1 }, { id: 2 }];

let newArray1 = Hoek.unique(array1, "id");  // results in [{id: 1}, {id: 2}]

// mapToObject(array, key)

array = [1, 2, 3];
let newObject = Hoek.mapToObject(array);   // results in {"1": true, "2": true, "3": true}
github haowen737 / koa-swapi / lib / swagger / parameters.js View on Github external
// convert an object definition
    if (item.$ref) {
      item.schema.$ref = item.$ref
      // item.schema.type = 'object'; // should have to do this but causes validations issues
      delete item.$ref
    }

    // reinstate x-alternatives at parameter level
    if (schemaObj['x-alternatives']) {
      item['x-alternatives'] = schemaObj['x-alternatives']
      delete item.schema['x-alternatives']
    }

    item = Utilities.removeProps(item, this.allowedProps)
    if (!Hoek.deepEqual(item.schema, { 'type': 'object' }, { prototype: false })) {
      // Clean up item shallow level properties and schema nested properties
      item = Utilities.deleteEmptyProperties(item)
      item.schema = Utilities.deleteEmptyProperties(item.schema)

      out.push(item)
    }

    // if its an array of parameters
  } else {
    // console.log('b', JSON.stringify(schemaObj) + '\n');

    // object to array
    const keys = Object.keys(schemaObj.properties)
    keys.forEach((element, index) => {
      let key = keys[index]
      let item = schemaObj.properties[key]
github glennjones / hapi-swagger / lib / parameters.js View on Github external
// convert an object definition
        if (item.$ref) {
            item.schema.$ref = item.$ref;
            // item.schema.type = 'object'; // should have to do this but causes validations issues
            delete item.$ref;
        }

        // reinstate x-alternatives at parameter level
        if (schemaObj['x-alternatives']) {
            item['x-alternatives'] = schemaObj['x-alternatives'];
            delete item.schema['x-alternatives'];
        }

        item = Utilities.removeProps(item, this.allowedProps);
        if (!Hoek.deepEqual(item.schema, { type: 'object' }, { prototype: false })) {
            // Clean up item shallow level properties and schema nested properties
            item = Utilities.deleteEmptyProperties(item);
            item.schema = Utilities.deleteEmptyProperties(item.schema);

            out.push(item);
        }

        // if its an array of parameters
    } else {
        //console.log('b', JSON.stringify(schemaObj) + '\n');

        // object to array
        const keys = Object.keys(schemaObj.properties);
        keys.forEach((element, index) => {
            let key = keys[index];
            let item = schemaObj.properties[key];
github glennjones / hapi-swagger / lib / index-old.js View on Github external
internals.validatorsToModelName = function (name, params, models) {

    // if no name create a signature
    if (!name) {
        name = 'model_' + ShortId.generate();
    }

    // need to either create new object or comparision
    var model = internals.createModel(name, params, models);

    // find existing model by this name
    var foundModel = models[name];
    if (foundModel) {

        // deep compare object
        if(Hoek.deepEqual(foundModel, model)){
            // return existing id
            return foundModel.id;
        }else{
            // create new model with alt name, to stop reuse of model
            model.id = 'model_' + ShortId.generate();
            models[model.id] = model;
        }
    }else{
        // create new model
        models[name] = model;
    }

    return model.id;
};
github arangodb / arangodb / js / node / node_modules / joi / lib / array.js View on Github external
boolean: {},
            object: [],
            function: []
        };

        for (var i = 0, il = value.length; i < il; ++i) {
            var item = value[i];
            var type = typeof item;
            var records = found[type];

            // All available types are supported, so it's not possible to reach 100% coverage without ignoring this line.
            // I still want to keep the test for future js versions with new types (eg. Symbol).
            if (/* $lab:coverage:off$ */ records /* $lab:coverage:on$ */) {
                if (Array.isArray(records)) {
                    for (var r = 0, rl = records.length; r < rl; ++r) {
                        if (Hoek.deepEqual(records[r], item)) {
                            return Errors.create('array.unique', { pos: i, value: item }, state, options);
                        }
                    }

                    records.push(item);
                }
                else {
                    if (records[item]) {
                        return Errors.create('array.unique', { pos: i, value: item }, state, options);
                    }

                    records[item] = true;
                }
            }
        }
    });
github ozum / joi18n / node_modules / hapi / lib / connection.js View on Github external
internals.cors = function (route, connection, plugin) {

    var settings = route.settings.cors;
    if (route.method === 'options' ||
        Hoek.deepEqual(this.settings.routes.cors, settings)) {

        return;
    }

    var path = route.path;
    if (this._corsPaths[path]) {
        Hoek.assert(Hoek.deepEqual(this._corsPaths[path], settings), 'Cannot add multiple routes with different CORS options on different methods:', route.method.toUpperCase(), path);
        return;
    }

    if (!settings) {
        return;
    }

    this._corsPaths[path] = Hoek.clone(settings);

    this._route({
        path: path,
        method: 'options',
        config: {
            auth: false,                         // Override any defaults
            cors: settings,
            handler: function (request, reply) {
github haowen737 / koa-swapi / lib / swagger / definitions.js View on Github external
definition = internals.formatProperty(definition)

  // remove required if its not an array
  // if (definition.required && !Array.isArray(definition.required)) {
  //    delete definition.required;
  // }

  // remove unneeded properties
  delete definition.name

  // find existing definition by this definitionName
  let foundDefinition = currentCollection[definitionName]
  if (foundDefinition) {
    // deep compare objects
    if (Hoek.deepEqual(foundDefinition, definition)) {
      // return existing definitionName if existing object is exactly the same
      out = definitionName
    } else {
      // create new definition
      out = internals.append(definitionName, definition, currentCollection, true, settings)
    }
  } else {
    // create new definition
    out = internals.append(definitionName, definition, currentCollection, false, settings)
  }

  return out
}
github blockstack / blockstack-browser / native / windows / BlockstackBrowser / Resources / corsproxy-https / node_modules / hapi / lib / connection.js View on Github external
internals.cors = function (route, connection, plugin) {

    var settings = route.settings.cors;
    if (route.method === 'options' ||
        Hoek.deepEqual(this.settings.routes.cors, settings)) {

        return;
    }

    var path = route.path;
    if (this._corsPaths[path]) {
        Hoek.assert(Hoek.deepEqual(this._corsPaths[path], settings), 'Cannot add multiple routes with different CORS options on different methods:', route.method.toUpperCase(), path);
        return;
    }

    if (!settings) {
        return;
    }

    this._corsPaths[path] = Hoek.clone(settings);

    this._route({
        path: path,
        method: 'options',
        config: {
            auth: false,                         // Override any defaults
            cors: settings,
            handler: function (request, reply) {
github ozum / joi18n / node_modules / hapi / lib / connection.js View on Github external
internals.cors = function (route, connection, plugin) {

    var settings = route.settings.cors;
    if (route.method === 'options' ||
        Hoek.deepEqual(this.settings.routes.cors, settings)) {

        return;
    }

    var path = route.path;
    if (this._corsPaths[path]) {
        Hoek.assert(Hoek.deepEqual(this._corsPaths[path], settings), 'Cannot add multiple routes with different CORS options on different methods:', route.method.toUpperCase(), path);
        return;
    }

    if (!settings) {
        return;
    }

    this._corsPaths[path] = Hoek.clone(settings);
github blockstack / blockstack-browser / native / windows / BlockstackBrowser / Resources / corsproxy-https / node_modules / hapi / lib / connection.js View on Github external
internals.cors = function (route, connection, plugin) {

    var settings = route.settings.cors;
    if (route.method === 'options' ||
        Hoek.deepEqual(this.settings.routes.cors, settings)) {

        return;
    }

    var path = route.path;
    if (this._corsPaths[path]) {
        Hoek.assert(Hoek.deepEqual(this._corsPaths[path], settings), 'Cannot add multiple routes with different CORS options on different methods:', route.method.toUpperCase(), path);
        return;
    }

    if (!settings) {
        return;
    }

    this._corsPaths[path] = Hoek.clone(settings);