How to use the core-util-is.isArray function in core-util-is

To help you get started, we’ve selected a few core-util-is 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 webtorrent / webtorrent / lib / bittorrent-dht / index.js View on Github external
if (!message.t || (bops.to(message.t) !== self.requestId.toString())) {
    console.log('wrong message requestId: ', bops.to(message.t), self.requestId.toString(), host, port)
    return
  }

  // Mark that we've seen this node (the one we received data from)
  self.nodes[addr] = true

  var r = message && message.r

  if (r && bops.is(r.nodes)) {
    // console.log('got nodes')
    parseNodeInfo(r.nodes).forEach(self._handleNode.bind(self))
  }
  if (r && is.isArray(r.values)) {
    // console.log('got peers')
    parsePeerInfo(r.values).forEach(self._handlePeer.bind(self))
  }
}
github kaelzhang / node-comment-json / src / stringify.js View on Github external
// that can replace values, or an array of strings that will select the keys.
  // A default replacer method can be provided. Use of the space parameter can
  // produce text that is more easily readable.

  // If the space parameter is a number, make an indent string containing that
  // many spaces.
  const indent_ = get_indent(space)

  if (!indent_) {
    return JSON.stringify(value, replacer_)
  }

  // ~~If there is a replacer, it must be a function or an array.
  // Otherwise, throw an error.~~
  // vanilla `JSON.parse` allow invalid replacer
  if (!isFunction(replacer_) && !isArray(replacer_)) {
    replacer_ = null
  }

  replacer = replacer_
  indent = indent_

  const str = stringify('', {'': value}, EMPTY)

  clean()

  return isObject(value)
    ? process_comments(value, PREFIX_BEFORE_ALL, EMPTY).trimLeft()
      + str
      + process_comments(value, PREFIX_AFTER_ALL, EMPTY).trimRight()
    : str
}
github krakenjs / swaggerize-routes / lib / index.js View on Github external
assert.ok(thing.isArray(options.schemas), 'Expected schemas option to be an array.');
    }

    if ('handlers' in options) {
        assert.ok(thing.isString(options.handlers) || thing.isObject(options.handlers), 'Expected handlers to be a string or an object.');
        assert.ok(!thing.isString(options.handlers) || options.handlers.length, 'Expected handlers to be a non-empty string.');
    }

    options.basedir = options.basedir || path.dirname(caller());

    schemas = {
        '#': swaggerSchema
    };

    // Map and validate API against schemas
    if (thing.isArray(options.schemas)) {
        options.schemas.forEach(function (schema) {
            assert.ok(thing.isObject(schema), 'Expected schema option to be an object.');
            assert.ok(thing.isString(schema.name), 'Expected schema name to be a string.');
            assert.ok(schema.name && schema.name !== '#', 'Schema name can not be base schema.');
            assert.ok(thing.isString(schema.schema) || thing.isObject(schema.schema), 'Expected schema to to an object.');

            if (thing.isString(schema.schema)) {
                schema.schema = require(path.resolve(options.basedir, schema.schema));
            }

            schemas[schema.name] = schema.schema;
        });
    }

    enjoi(swaggerSchema, schemas).validate(options.api, function (error) {
        assert.ifError(error);
github krakenjs / swaggerize-routes / lib / index.js View on Github external
function swaggerize(options) {
    var schemas;

    assert.ok(thing.isObject(options), 'Expected options to be an object.');
    assert.ok(thing.isObject(options.api), 'Expected an api definition.');

    if ('basedir' in options) {
        assert.ok(thing.isString(options.basedir), 'Expected basedir to be a string.');
        assert.ok(options.basedir.length, 'Expected basedir to be a non-empty string.');
    }

    if ('schemas' in options) {
        assert.ok(thing.isArray(options.schemas), 'Expected schemas option to be an array.');
    }

    if ('handlers' in options) {
        assert.ok(thing.isString(options.handlers) || thing.isObject(options.handlers), 'Expected handlers to be a string or an object.');
        assert.ok(!thing.isString(options.handlers) || options.handlers.length, 'Expected handlers to be a non-empty string.');
    }

    options.basedir = options.basedir || path.dirname(caller());

    schemas = {
        '#': swaggerSchema
    };

    // Map and validate API against schemas
    if (thing.isArray(options.schemas)) {
        options.schemas.forEach(function (schema) {
github krakenjs / meddleware / index.js View on Github external
modulePath = util.tryResolve(config.name) || util.tryResolve(path.resolve(root, config.name));

    // If modulePath was not resolved lookup with config.name for meaningful error message.
    module = require(modulePath || config.name);

    // First, look for a factory method
    factory = module[config.method];
    if (!thing.isFunction(factory)) {
        // Then, check if the module itself is a factory
        factory = module;
        if (!thing.isFunction(factory)) {
            throw new Error('Unable to locate middleware in ' + config.name);
        }
    }

    args = thing.isArray(config['arguments']) ? config['arguments'] : [];
    return factory.apply(module, args);
}
github caviarjs / caviar / src / base / caviar.js View on Github external
const normalizePlugin = plugin => {
  if (!isArray(plugin)) {
    plugin = [plugin]
  }

  const [
    rawFactory,
    rawCondition
  ] = plugin

  return [
    normalizeFactory(rawFactory),
    normalizeCondition(rawCondition)
  ]
}
github basicallydan / interfake / lib / route.js View on Github external
this.request.url = new RegExp(this.request.url.pattern);
	}

	if (util.isString(this.request.url)) {
		path = url.parse(this.request.url, true);
		this.request.url = path.pathname;
		this.setQueryStrings(path.query);
	}

	if (this.afterResponse && util.isArray(this.afterResponse.endpoints)) {
		this.afterResponse.endpoints = (this.afterResponse.endpoints || []).map(function (descriptor) {
			return new Route(descriptor);
		});
	}

	if (this.afterResponse && util.isArray(this.afterResponse.modifications)) {
		this.afterResponse.modifications = (this.afterResponse.modifications || []).map(function (descriptor) {
			return {
				routeDescriptor: descriptor.request,
				body: descriptor.response.body,
				echo: descriptor.response.echo,
				code: descriptor.response.code,
				delay: descriptor.response.delay,
				responseHeaders: descriptor.response.headers
			};
		}.bind(this));
	}

	if (!this.afterResponse) {
		this.afterResponse = {
			endpoints: [],
			modifications: []
github kaelzhang / skema / packages / skema / src / inspect.js View on Github external
const inspectSkemaObject = object =>
  Object.keys(object[SHAPE]).reduce((ret, key) => {
    ret[key] = inspect(object[key])
    return ret
  }, isArray(object)
    ? []
    : {}
  )
github krakenjs / swaggerize-routes / lib / buildroutes.js View on Github external
function buildSecurity(options, securityDefinitions, routeSecurity) {
    var security = {};
    var basedir = options.basedir;

    if (!securityDefinitions || !routeSecurity || !thing.isArray(routeSecurity)) {
        return undefined;
    }

    routeSecurity.forEach(function (definition) {
        Object.keys(definition).forEach(function (defName) {
            assert.ok(securityDefinitions[defName], 'Unrecognized security definition (' + defName + ')');

            security[defName] = {};
            //The value of security scheme is a list of scope names required for the execution
            security[defName].scopes = definition[defName];

            security[defName].scopes.forEach(function (scope) {
                assert.ok(thing.isString(scope) && Object.keys(securityDefinitions[defName].scopes).indexOf(scope) > -1, 'Unrecognized scope (' + scope + ').');
            });

            if (options.security) {
github krakenjs / swaggerize-routes / lib / expressroutes.js View on Github external
routes.forEach(function (route) {
        var args, path;

        path = utils.convertPath(route.path);
        args = [options.api.resourcePath + utils.prefix(path, '/')];

        if (thing.isArray(route.handler)) {
            if (route.handler.length > 1) {
                Array.prototype.push.apply(route.before, route.handler.slice(0, route.handler.length - 1));
            }
            route.handler = route.handler[route.handler.length - 1];
        }

        Array.prototype.push.apply(args, route.before);
        args.push(route.handler);
        router[route.method].apply(router, args);
    });
}