How to use the core-util-is.isObject 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 kaelzhang / node-comment-json / src / stringify.js View on Github external
function stringify (key, holder, gap) {
  let value = holder[key]

  // If the value has a toJSON method, call it to obtain a replacement value.
  if (isObject(value) && isFunction(value.toJSON)) {
    value = value.toJSON(key)
  }

  // If we were called with a replacer function, then call the replacer to
  // obtain a replacement value.
  if (isFunction(replacer)) {
    value = replacer.call(holder, key, value)
  }

  switch (typeof value) {
  case 'string':
    return quote(value)

  case 'number':
    // JSON numbers must be finite. Encode non-finite numbers as null.
    return Number.isFinite(value) ? String(value) : STR_NULL
github caviarjs / caviar / src / base / hookable.js View on Github external
set hooks (hooks) {
    if (!isObject(hooks)) {
      throw error('INVALID_HOOKS', hooks)
    }

    // - Duplicately set hooks
    // - Set hooks after get
    if (this[HOOKS]) {
      throw error('ERR_SET_HOOKS')
    }

    // TODO: check hooks
    // adds default hooks
    this[HOOKS] = this[EXTEND_HOOKS](hooks)
  }
github krakenjs / swaggerize-routes / lib / index.js View on Github external
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) {
            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.');
github kaelzhang / node-comment-json / src / array.js View on Github external
assign (target, source, keys) {
    if (!isObject(target)) {
      throw new TypeError('Cannot convert undefined or null to object')
    }

    if (!isObject(source)) {
      return target
    }

    if (keys === UNDEFINED) {
      keys = Object.keys(source)
    } else if (!isArray(keys)) {
      throw new TypeError('keys must be array or undefined')
    }

    return assign(target, source, keys)
  },
github caviarjs / caviar / src / sandbox / index.js View on Github external
constructor (options) {
    super(options, {
      sandboxEnvironment: new AsyncParallelHook(['sandbox', 'caviarOptions'])
    })

    const {
      env = {},
      stdio = 'inherit',
      preset,
      configFile
    } = options

    this[IS_SANDBOX] = true

    if (!isObject(env)) {
      throw error('INVALID_ENV', env)
    }

    this._env = env
    this._stdio = stdio
    this._preset = preset
    this._configFile = configFile
  }
github krakenjs / adaro / lib / utils.js View on Github external
exports.deepClone = exports.deepCopy = function deepClone(src) {
    var dest = src;

    if (thing.isObject(src)) {
        dest = Array.isArray(src) ? [] : Object.create(Object.getPrototypeOf(src));
        Object.getOwnPropertyNames(src).forEach(function (prop) {
            var descriptor = Object.getOwnPropertyDescriptor(src, prop);
            descriptor.value = deepClone(descriptor.value);
            Object.defineProperty(dest, prop, descriptor);
        });
    }

    return dest;
};
github trygve-lie / twitter-stream-api / lib / main.js View on Github external
var Twitter = module.exports = function (keys, param1, param2)  { 
    var self = this;
    var objectMode = true;
    var options = {};

    if (utils.isBoolean(param1)) {
        objectMode = param1;
    }

    if (utils.isObject(param1)) {
        options = param1;
    }

    if (utils.isObject(param2)) {
        options = param2;
    }

    this.connection = new Connection(keys, options);
    this.streamEndpoint = 'statuses/filter';
    this.streamParams = null;
    
    Readable.call(this, {objectMode: objectMode});
    this.connection.on('data', function (obj) {
        if (!self.push(objectMode ? obj : JSON.stringify(obj))) {
            self.connection.destroy();
        }
    });
github caviarjs / caviar / src / utils.js View on Github external
const checkPlugin = plugin => {
  if (isObject(plugin) && isFunction(plugin.apply)) {
    return plugin
  }

  throw error('CONFIG_LOADER_INVALID_PLUGIN')
}
github caviarjs / caviar / src / config-loader.js View on Github external
constructor (options) {
    if (!isObject(options)) {
      throw error('INVALID_OPTIONS', options)
    }

    const {
      cwd
    } = options

    if (!isString(cwd)) {
      throw error('INVALID_CWD', cwd)
    }

    this._cwd = cwd
    this._paths = null
    this._chain = []
  }
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.');
    }