How to use the hoek.contain 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
array = [1, 2, 3];
let newObject = Hoek.mapToObject(array);   // results in {"1": true, "2": true, "3": true}

array1 = [{ id: 1 }, { id: 2 }];
newObject = Hoek.mapToObject(array1, "id"); // results in {"1": true, "2": true}

// intersect(array1, array2)

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

let newArray2 = Hoek.intersect(array, array2); // results in [1]

// contain(ref, values, [options])

Hoek.contain('aaa', 'a', { only: true });                           // true
Hoek.contain([{ a: 1 }], [{ a: 1 }], { deep: true });               // true
Hoek.contain([1, 2, 2], [1, 2], { once: true });                    // false
Hoek.contain({ a: 1, b: 2, c: 3 }, { a: 1, d: 4 }, { part: true }); // true

// flatten(array, [target])

let array3 = [1, [2, 3]];

let flattenedArray = Hoek.flatten(array); // results in [1, 2, 3]

array3 = [1, [2, 3]];
let target1 = [4, [5]];

flattenedArray = Hoek.flatten(array3, target1); // results in [4, [5], 1, 2, 3]

// reach(obj, chain, [options])
github bakjs / bak / packages / logging / lib / good / good-sentry.js View on Github external
_write (_data, encoding, cb) {
    let {tags = [], data = {}} = _data

    // Don't report logs without error or message
    if (!data.error && !data.message) return cb()

    // Normalize event tags - if its a string then wrap in an array, default to an empty array
    if (typeof tags === 'string') tags = [tags]

    // Log level
    let level = 'debug'
    if (hoek.contain(tags, ['fatal'], {part: true})) {
      level = 'fatal'
    } else if (hoek.contain(tags, ['err', 'error'], {part: true})) {
      level = 'error'
    } else if (hoek.contain(tags, ['warn', 'warning'], {part: true})) {
      level = 'warning'
    } else if (hoek.contain(tags, ['info'], {part: true})) {
      level = 'info'
    }

    // Filter-out level tags and keep others
    // Then convert array to mapping for sentry api compatibility
    let sentry_tags = tags.filter(
      tag => ['fatal', 'error', 'err', 'warning', 'warn', 'info', 'debug'].indexOf(tag) === -1
    ).reduce((acc, curr) => {
      let split = curr.split(':', 2)
      acc[split[0]] = split[1] || true
      return acc
    }, {})

    // Additional data
github hapijs / joi / lib / types / string / index.js View on Github external
ip(ipOptions = {}) {

        let regex = internals.ipRegex;
        Hoek.assert(typeof ipOptions === 'object', 'options must be an object');

        if (ipOptions.cidr) {
            Hoek.assert(typeof ipOptions.cidr === 'string', 'cidr must be a string');
            ipOptions.cidr = ipOptions.cidr.toLowerCase();

            Hoek.assert(Hoek.contain(internals.cidrPresences, ipOptions.cidr), 'cidr must be one of ' + internals.cidrPresences.join(', '));

            // If we only received a `cidr` setting, create a regex for it. But we don't need to create one if `cidr` is "optional" since that is the default
            if (!ipOptions.version && ipOptions.cidr !== 'optional') {
                regex = Ip.createIpRegex(['ipv4', 'ipv6', 'ipvfuture'], ipOptions.cidr);
            }
        }
        else {

            // Set our default cidr strategy
            ipOptions.cidr = 'optional';
        }

        let versions;
        if (ipOptions.version) {
            if (!Array.isArray(ipOptions.version)) {
                ipOptions.version = [ipOptions.version];
github hapijs / joi / lib / types / string / index.js View on Github external
ip(ipOptions) {

        let regex = internals.ipRegex;
        ipOptions = ipOptions || {};
        Hoek.assert(typeof ipOptions === 'object', 'options must be an object');

        if (ipOptions.cidr) {
            Hoek.assert(typeof ipOptions.cidr === 'string', 'cidr must be a string');
            ipOptions.cidr = ipOptions.cidr.toLowerCase();

            Hoek.assert(Hoek.contain(internals.cidrPresences, ipOptions.cidr), 'cidr must be one of ' + internals.cidrPresences.join(', '));

            // If we only received a `cidr` setting, create a regex for it. But we don't need to create one if `cidr` is "optional" since that is the default
            if (!ipOptions.version && ipOptions.cidr !== 'optional') {
                regex = Ip.createIpRegex(['ipv4', 'ipv6', 'ipvfuture'], ipOptions.cidr);
            }
        }
        else {

            // Set our default cidr strategy
            ipOptions.cidr = 'optional';
        }

        let versions;
        if (ipOptions.version) {
            if (!Array.isArray(ipOptions.version)) {
                ipOptions.version = [ipOptions.version];
github synapsestudios / oidc-platform / api / src / application / webhook / webhook-service.js View on Github external
async trigger(event, resource) {
    Hoek.assert(Hoek.contain(this.events, event), new Error(`WebhookService:trigger - ${event} is an invalid event`));

    if (!webhookConfig) return; // webhooks disabled

    try {
      // get the webhooks for this event
      const webhookCollection = await bookshelf.model('webhook')
        .query(q => {
          q.join('SIP_webhook_event', 'SIP_webhook.id', '=', 'SIP_webhook_event.webhook_id');
          q.where('SIP_webhook_event.event', event);
        }).fetchAll({withRelated: 'client'});

      // enqueue the webhook payload for each webhook
      webhookCollection.forEach(webhook => {
        const client = webhook.related('client');
        queue.enqueue({
          url: webhook.get('url'),
github flaviuse / mern-authentication / client / node_modules / joi / lib / types / string / index.js View on Github external
normalize(form = 'NFC') {

        Hoek.assert(Hoek.contain(internals.normalizationForms, form), 'normalization form must be one of ' + internals.normalizationForms.join(', '));

        const obj = this._test('normalize', form, function (value, state, options) {

            if (options.convert ||
                value === value.normalize(form)) {

                return value;
            }

            return this.createError('string.normalize', { value, form }, state, options);
        });

        obj._flags.normalize = form;
        return obj;
    }
github hapijs / joi / lib / types / string / index.js View on Github external
normalize(form = 'NFC') {

        Hoek.assert(Hoek.contain(internals.normalizationForms, form), 'normalization form must be one of ' + internals.normalizationForms.join(', '));

        const obj = this._test('normalize', form, function (value, state, options) {

            if (options.convert ||
                value === value.normalize(form)) {

                return value;
            }

            return this.createError('string.normalize', { value, form }, state, options);
        });

        obj._flags.normalize = form;
        return obj;
    }
github jsynowiec / good-sentry / src / index.js View on Github external
level: ((tags = []) => {
        if (hoek.contain(tags, ['fatal'], { part: true })) {
          return 'fatal';
        }
        if (hoek.contain(tags, ['err', 'error'], { part: true })) {
          return 'error';
        }
        if (hoek.contain(tags, ['warn', 'warning'], { part: true })) {
          return 'warning';
        }
        if (hoek.contain(tags, ['info'], { part: true })) {
          return 'info';
        }

        return 'debug';
      })(tags),
      tags: tags
github daviddias / simple-raytracer / node_modules / code / lib / index.js View on Github external
internals.addMethod(['include', 'includes', 'contain', 'contains'], function (value) {

    return this.assert(Hoek.contain(this._ref, value, this._flags), 'include ' + internals.display(value));
});
github hks-epod / paydash / lib / versioning.js View on Github external
server.ext('onRequest', (request, reply) => {
        //First check for custom header
        let requestedVersion = _extractVersionFromCustomHeader(request, options);

        //If no version check accept header
        if (!requestedVersion) {
            requestedVersion = _extractVersionFromAcceptHeader(request, options);
        }

        //If passive mode skips the rest for non versioned routes
        if (options.passiveMode === true && !requestedVersion) {
            return reply.continue();
        }

        //If there was a version by now check if it is valid
        if (requestedVersion && !Hoek.contain(options.validVersions, requestedVersion)) {
            return reply(
                Boom.badRequest(
                    'Invalid api-version! Valid values: ' + options.validVersions.join()
                )
            );
        }

        //If there was no version by now use the default version
        if (!requestedVersion) {
            requestedVersion = options.defaultVersion;
        }

        const versionedPath =
            options.basePath +
            'v' +
            requestedVersion +