How to use is-plain-object - 10 common examples

To help you get started, we’ve selected a few is-plain-object 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 dwightjack / vue-types / es / utils.js View on Github external
}

    if (isArray(typeToCheck.type)) {
      valid = typeToCheck.type.some(function (type) {
        return validateType(type, value, true);
      });
      expectedType = typeToCheck.type.map(function (type) {
        return getType(type);
      }).join(' or ');
    } else {
      expectedType = getType(typeToCheck);

      if (expectedType === 'Array') {
        valid = isArray(value);
      } else if (expectedType === 'Object') {
        valid = isPlainObject(value);
      } else if (expectedType === 'String' || expectedType === 'Number' || expectedType === 'Boolean' || expectedType === 'Function') {
        valid = getNativeType(value) === expectedType;
      } else {
        valid = value instanceof typeToCheck.type;
      }
    }
  }

  if (!valid) {
    silent === false && warn(namePrefix + "value \"" + value + "\" should be of type \"" + expectedType + "\"");
    return false;
  }

  if (hasOwn.call(typeToCheck, 'validator') && isFunction(typeToCheck.validator)) {
    // swallow warn
    var oldWarn;
github react-kit / hookstore / packages / hookstore / src / utils.js View on Github external
function checkModel(model) {
  invariant(isPlainObject(model), 'model should be plain object!');

  const { name, state, actions /* , middlewares */ } = model;

  invariant(name, 'model name is required!');
  invariant(typeof name === 'string', 'model name should be string!');

  if (state) invariant(isPlainObject(state), 'model state should be plain object!');

  if (actions) invariant(isPlainObject(actions), `model actions should be plain object!`);

  // if (middlewares) checkMiddlewares(middlewares);
}
github GameDistribution / GD-HTML5 / src / components / VideoAd.js View on Github external
tnl_content_category: this.category.toLowerCase()
            });

            // Send ad request event
            this.eventBus.broadcast("AD_REQUEST", {
              message: data.tnl_ad_pos
            });

            // Custom Ad Vast Url
            if (isPlainObject(this.options.vast)) {
              return resolve(this._createCustomAdVastUrl(this.options.vast, { tnl_keys: data }));
            }
            else if (options && options.retry_on_success && isPlainObject(this.options.retry_on_success) && isPlainObject(this.options.retry_on_success.vast)) {
              return resolve(this._createCustomAdVastUrl(this.options.retry_on_success.vast, { tnl_keys: data }));
            }
            else if (options && options.retry_on_failure && isPlainObject(this.options.retry_on_failure) && isPlainObject(this.options.retry_on_failure.vast)) {
              return resolve(this._createCustomAdVastUrl(this.options.retry_on_failure.vast, { tnl_keys: data }));
            }

            // Make the request for a VAST tag from the Prebid.js wrapper.
            // Get logging from the wrapper using: ?idhbgd_debug=true
            // To get a copy of the current config: copy(idhbgd.getConfig());
            window.idhbgd.que.push(() => {
              window.idhbgd.setAdserverTargeting(data);
              window.idhbgd.setDfpAdUnitCode(unit);
              window.idhbgd.setRefererUrl(encodeURIComponent(this.parentURL));

              // This is to add a flag, which if set to false;
              // non-personalized ads get requested from DFP and a no-consent
              // string - BOa7h6KOa7h6KCLABBENCDAAAAAjyAAA - is sent to all SSPs.
              // If set to true, then the wrapper will continue as if no consent was given.
              // This is only for Google, as google is not part of the IAB group.
github reixs / reixs / src / reixs.js View on Github external
set(value) {
        if (isPlainObject(value)) {
            Reixs.global.globalParams = value
        } else {
            throw new Error('The argument passed in must be a literal object')
        }
    }
})
github alibaba / vanex / src / plugin / index.js View on Github external
use(plugin) {
        invariant(
            isPlainObject(plugin),
            "plugin.use: plugin should be plain object"
        );
        const hooks = this.hooks;

        for (const key in plugin) {
            if (Object.prototype.hasOwnProperty.call(plugin, key)) {
                invariant(
                    hooks[key],
                    `plugin.use: unknown plugin property: ${key}`
                );
                if (["extraEnhancers", "form"].includes(key)) {
                    hooks[key] = plugin[key];
                } else {
                    hooks[key].push(plugin[key]);
                }
            }
github mariocasciaro / object-path-immutable / esm / object-path-immutable.js View on Github external
function _deepMerge (dest, src) {
  if (dest !== src && isPlainObject(dest) && isPlainObject(src)) {
    var merged = {};
    for (var key in dest) {
      if (_hasOwnProperty.call(dest, key)) {
        if (_hasOwnProperty.call(src, key)) {
          merged[key] = _deepMerge(dest[key], src[key]);
        } else {
          merged[key] = dest[key];
        }
      }
    }

    for (key in src) {
      if (_hasOwnProperty.call(src, key)) {
        merged[key] = _deepMerge(dest[key], src[key]);
      }
    }
github dwightjack / vue-types / es / utils.js View on Github external
export function validateType(type, value, silent) {
  if (silent === void 0) {
    silent = false;
  }

  var typeToCheck = type;
  var valid = true;
  var expectedType;

  if (!isPlainObject(type)) {
    typeToCheck = {
      type: type
    };
  }

  var namePrefix = typeToCheck._vueTypes_name ? typeToCheck._vueTypes_name + ' - ' : '';

  if (hasOwn.call(typeToCheck, 'type') && typeToCheck.type !== null) {
    if (typeToCheck.type === undefined) {
      throw new TypeError("[VueTypes error]: Setting type to undefined is not allowed.");
    }

    if (!typeToCheck.required && value === undefined) {
      return valid;
    }
github dwightjack / vue-types / src / utils.js View on Github external
value(def) {
      if (def === undefined && !this.default) {
        return this
      }
      if (!isFunction(def) && !validateType(this, def)) {
        warn(`${this._vueTypes_name} - invalid default value: "${def}"`, def)
        return this
      }
      if (isArray(def)) {
        this.default = () => [...def]
      } else if (isPlainObject(def)) {
        this.default = () => Object.assign({}, def)
      } else {
        this.default = def
      }
      return this
    },
    enumerable: false,
github christianalfoni / proxy-state-tree / src / proxify.js View on Github external
function proxify(tree, value, path) {
  if (value) {
    if (value[IS_PROXY]) {
      return value;
    } else if (Array.isArray(value)) {
      return createArrayProxy(tree, value, path);
    } else if (isPlainObject(value)) {
      return createObjectProxy(tree, value, path);
    }
  }
  return value;
}
github octokit / request.js / lib / request.js View on Github external
function request (requestOptions) {
  if (isPlainObject(requestOptions.body) || Array.isArray(requestOptions.body)) {
    requestOptions.body = JSON.stringify(requestOptions.body)
  }

  let headers = {}
  let status
  let url

  const fetch = (requestOptions.request && requestOptions.request.fetch) || nodeFetch

  return fetch(requestOptions.url, Object.assign({
    method: requestOptions.method,
    body: requestOptions.body,
    headers: requestOptions.headers,
    redirect: requestOptions.redirect
  }, requestOptions.request))

is-plain-object

Returns true if an object was created by the `Object` constructor, or Object.create(null).

MIT
Latest version published 4 years ago

Package Health Score

71 / 100
Full package analysis

Popular is-plain-object functions