How to use the typical.isPlainObject function in typical

To help you get started, we’ve selected a few typical 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 75lb / command-line-args / lib / argv-parser.js View on Github external
* [Symbol.iterator] () {
    const definitions = this.definitions
    const t = require('typical')

    let def
    let value
    let name
    let event
    let singularDefaultSet = false
    let unknownFound = false
    let origArg

    for (let arg of this.argv) {
      if (t.isPlainObject(arg)) {
        origArg = arg.origArg
        arg = arg.arg
      }

      if (unknownFound && this.options.stopAtFirstUnknown) {
        yield { event: 'unknown_value', arg, name: '_unknown', value: undefined }
        continue
      }

      /* handle long or short option */
      if (argvTools.isOption(arg)) {
        def = definitions.get(arg)
        value = undefined
        if (def) {
          value = def.isBoolean() ? true : null
          event = 'set'
github lwsjs / lws / lib / util.js View on Github external
function customiser (previousValue, newValue, key, object, source) {
    /* deep merge plain objects */
    if (t.isPlainObject(previousValue) && t.isPlainObject(newValue)) {
      return assignWith(previousValue, newValue, customiser)
    /* overwrite arrays if the new array has items */
    } else if (Array.isArray(previousValue) && Array.isArray(newValue) && newValue.length) {
      return newValue
    /* ignore incoming arrays if empty */
    } else if (Array.isArray(newValue) && !newValue.length) {
      return previousValue
    } else if (!t.isDefined(previousValue) && Array.isArray(newValue)) {
      return newValue
    }
  }
github 75lb / array-tools / dist / array-tools.js View on Github external
function testValue(value, test){
    if (t.isPlainObject(test)){
        return o.exists(value, test);
    } else if (Array.isArray(test)){
        var tests = test;
        return tests.some(function(test){
            return testValue(value, test);
        });    
    } else if (test instanceof RegExp){
        return test.test(value);
    } else if (typeof test === "function"){
        return test(value);
    } else {
        return test === value;
    }
}
github 75lb / usage-stats / lib / usage-stats-core.js View on Github external
screenView (name, options) {
    if (this._disabled) return this
    options = options || {}
    if (options.hitParams && t.isPlainObject(options.hitParams)) {
      options.hitParams = objToMap(options.hitParams)
    }

    let hit = this._createHit(new Map([
      [ 't', 'screenview' ],
      [ 'cd', name ]
    ]), options)
    if (!hit.has('an')) throw new Error("'an' parameter required (App name)")
    if (!hit.has('cd')) throw new Error("'cd' parameter required (screen name)")
    this._hits.push(hit)
    return hit
  }
github 75lb / usage-stats / lib / usage-stats-core.js View on Github external
exception (options) {
    if (this._disabled) return this
    options = options || {}
    if (options.hitParams && t.isPlainObject(options.hitParams)) {
      options.hitParams = objToMap(options.hitParams)
    }
    let hit = this._createHit(new Map([
      [ 't', 'exception' ]
    ]), options)
    if (t.isDefined(options.exd)) hit.set('exd', options.exd)
    if (t.isDefined(options.exf)) hit.set('exf', options.exf ? 1 : 0)
    this._hits.push(hit)
    return hit
  }
github 75lb / usage-stats / es5 / lib / usage-stats-core.js View on Github external
value: function event(category, action, options) {
      if (this._disabled) return this;
      if (!(category && action)) throw new Error('category and action required');
      options = options || {};
      if (options.hitParams && t.isPlainObject(options.hitParams)) {
        options.hitParams = objToMap(options.hitParams);
      }

      var hit = this._createHit(new Map([['t', 'event'], ['ec', category], ['ea', action]]), options);

      if (t.isDefined(options.el)) hit.set('el', options.el);
      if (t.isDefined(options.ev)) hit.set('ev', options.ev);
      this._hits.push(hit);
      return hit;
    }
  }, {
github 75lb / array-tools / dist / array-tools.js View on Github external
function exists(array, value){
    if (t.isPlainObject(value)){
        var query = value;
        var found = false;
        var index = 0;
        var item;

        while(!found && (item = array[index++])){
            found = o.exists(item, query);
        }
        return found;
    } else {
        return array.indexOf(value) > -1;
    }
}
github 75lb / command-line-usage / es5 / content.js View on Github external
var rows = content.map(function (string) {
            return { column: ansi.format(string) };
          });
          var _table = new Table(rows, {
            padding: defaultPadding,
            maxWidth: 80
          });
          return _table.renderLines();
        } else if (Array.isArray(content) && content.every(t.isPlainObject)) {
          var _table2 = new Table(content.map(function (row) {
            return ansiFormatRow(row);
          }), {
            padding: defaultPadding
          });
          return _table2.renderLines();
        } else if (t.isPlainObject(content)) {
          if (!content.options || !content.data) {
            throw new Error('must have an "options" or "data" property\n' + JSON.stringify(content));
          }
          var options = Object.assign({ padding: defaultPadding }, content.options);

          if (options.columns) {
            options.columns = options.columns.map(function (column) {
              if (column.nowrap) {
                column.noWrap = column.nowrap;
                delete column.nowrap;
              }
              return column;
            });
          }

          var _table3 = new Table(content.data.map(function (row) {
github 75lb / array-tools / dist / array-tools.js View on Github external
arrayify(array).forEach(function(item, index){
        if (t.isPlainObject(query)){
            if(o.exists(item, query)){
                result.push(item);
                toSplice.push(index);
            }
        } else {
            if (query(item)){
                result.push(item);
                toSplice.push(index);
            }
        }
    });
    for (var i = 0; i < toSplice.length; i++){

typical

Isomorphic, functional type-checking for Javascript

MIT
Latest version published 2 months ago

Package Health Score

74 / 100
Full package analysis