Esempio n. 1
0
cache = map(cache, function(decl) {
  forOwn(decl, function(value, key) {
    var orig = value;
    var mixin = ':root .' + key
    if (cache.hasOwnProperty(mixin)) {
      var params = value.replace(/\s*/g,'').split(',');

      var copy = JSON.stringify(cache[mixin],0,2);

      params.forEach(function(arg, i) {
        copy = copy.replace('$'+i, arg === 'default' ? '$-' : arg)
      })
      copy = JSON.parse(copy)

      decl = extend(copy, decl)
      decl = map(decl, function(v, k, i) {
        var startRe = /^(\$.*\?\s*)/;
        var endRe = /(\s*\?.*$)/;
        return startRe.test(v)
          ? v.replace(startRe, '')
          : v.replace(endRe, '')
      });
    }
  });
  return decl;
})
Esempio n. 2
0
module.exports = function (template) {
  if (template == null || typeOf(template) !== 'object') {
    debug.err('`template` must be an object.');
  }

  forOwn(template, function (value, key) {
    if (key == null || typeof key !== 'string') {
      debug.err('template `key` must be a string.');
    }

    if (value == null || typeOf(value) === 'object') {
      debug.err('template `value` must be an object.');
    }

    if (!hasOwn(value, 'path')) {
      debug.err('template `value` must have a `path` property.');
    }

    if (!hasOwn(value, 'content')) {
      debug.err('template `value` must have a `content` property.');
    }

    if (!hasOwn(value, 'options')) {
      debug.err('template `value` must have an `options` property.');
    }
  });
};
Esempio n. 3
0
module.exports = function omit(obj, keys) {
  if (!isObject(obj)) return {};

  keys = [].concat.apply([], [].slice.call(arguments, 1));
  var last = keys[keys.length - 1];
  var res = {}, fn;

  if (typeof last === 'function') {
    fn = keys.pop();
  }

  var isFunction = typeof fn === 'function';
  if (!keys.length && !isFunction) {
    return obj;
  }

  forOwn(obj, function(value, key) {
    if (keys.indexOf(key) === -1) {

      if (!isFunction) {
        res[key] = value;
      } else if (fn(value, key, obj)) {
        res[key] = value;
      }
    }
  });
  return res;
};
module.exports = function omit(obj, props) {
  if (obj == null || !isObject(obj)) {
    return {};
  }

  if (props == null) {
    return obj;
  }

  if (typeof props === 'string') {
    props = [].slice.call(arguments, 1);
  }

  var o = {};

  if (!Object.keys(obj).length) {
    return o;
  }

  forOwn(obj, function (value, key) {
    if (props.indexOf(key) === -1) {
      o[key] = value;
    }
  });
  return o;
};
Esempio n. 5
0
 base.register(scaffold.name, function(app) {
   forOwn(scaffold.targets, function(target, key) {
     app.task(target.name, function(cb) {
       base.each(target, cb);
     });
   });
 });
Esempio n. 6
0
 each(slice(arguments, 1), function(obj) {
   if (isObject(obj)) {
     forOwn(obj, function(val, key) {
       if (target[key] == null) {
         target[key] = val;
       }
     });
   }
 });
Esempio n. 7
0
function matchObject(o, value) {
  var res = true;
  forOwn(value, function (val, key) {
    if (!deepMatches(o[key], val)) {
      // Return false to break out of forOwn early
      return (res = false);
    }
  });
  return res;
}
Esempio n. 8
0
function toGroup(groups, prop) {
  forOwn(groups, function(val, key) {
    if (!Array.isArray(val)) {
      groups[key] = toGroup(val, prop, key);
    } else {
      groups[key] = groupBy(val, prop, key);
    }
  });
  return groups;
}
Esempio n. 9
0
function eachValue(groups, obj, val) {
  if (Array.isArray(val)) {
    val.forEach(function(key) {
      union(groups, key, obj);
    });
  } else {
    forOwn(val, function(v, key) {
      union(groups, key, obj);
    });
  }
}
Esempio n. 10
0
 function copy(o, current) {
   forOwn(current, function (value, key) {
     var val = o[key];
     // add the missing property, or allow a null property to be updated
     if (val == null) {
       o[key] = value;
     } else if (isObject(val) && isObject(value)) {
       defaultsDeep(val, value);
     }
   });
 }
Esempio n. 11
0
module.exports = function some(obj, cb, thisArg) {
  cb = iterator(cb, thisArg);
  var result = false;

  forOwn(obj, function (val, key) {
    if (cb(val, key, obj)) {
      result = true;
      return false; // break
    }
  });
  return result;
};
Esempio n. 12
0
 it('should get the current items on the views', function () {
   var views = new Views(createOptions());
   views.set('foo', createView({path: 'foo', content: 'foo'}, {collection: views}));
   views.set('bar', createView({path: 'bar', content: 'bar'}, {collection: views}));
   views.set('baz', createView({path: 'baz', content: 'baz'}, {collection: views}));
   views.set('bang', createView({path: 'bang', content: 'bang'}, {collection: views}));
   var items = views.items;
   assert.deepEqual(Object.keys(items), ['foo', 'bar', 'baz', 'bang']);
   forOwn(items, function (item, key) {
     assert.deepEqual(item, views.get(key));
   });
 });
Esempio n. 13
0
 it('should get the current items on the collection', function () {
   var collection = new Collection();
   collection.set('foo', createItem({name: 'foo', content: 'foo'}, {collection: collection}));
   collection.set('bar', createItem({name: 'bar', content: 'bar'}, {collection: collection}));
   collection.set('baz', createItem({name: 'baz', content: 'baz'}, {collection: collection}));
   collection.set('bang', createItem({name: 'bang', content: 'bang'}, {collection: collection}));
   var items = collection.items;
   assert.deepEqual(Object.keys(items), ['foo', 'bar', 'baz', 'bang']);
   forOwn(items, function (item, key) {
     assert.deepEqual(item, collection.get(key));
   });
 });
Esempio n. 14
0
describe('markdown-utils', function() {
  //ignore .list, because it's WIP
  mdu = filter(mdu, ['*', '!list']);
  forOwn(mdu, function(fn, name) {
    it('should render: `' + name + '`', function(done) {
      var fixture = readFixture(name);
      var actual = fn.apply(fn, fixture);
      var expected = readExpected(name);
      actual.should.equal(expected);
      done();
    });
  });
});
Esempio n. 15
0
module.exports = function omit(obj, keys) {
    if (!isObject(obj)) return {};
    if (!keys) return obj;

    keys = Array.isArray(keys) ? keys : [keys];
    var res = {};

    forOwn(obj, function (value, key) {
        if (keys.indexOf(key) === -1) {
            res[key] = value;
        }
    });
    return res;
};
Esempio n. 16
0
 it('should set the items on the collection', function () {
   var collection = new Collection();
   var items = {};
   items.foo = createItem({name: 'foo', content: 'foo'}, {collection: collection});
   items.bar = createItem({name: 'bar', content: 'bar'}, {collection: collection});
   items.baz = createItem({name: 'baz', content: 'baz'}, {collection: collection});
   items.bang = createItem({name: 'bang', content: 'bang'}, {collection: collection});
   collection.items = items;
   assert.deepEqual(Object.keys(items), ['foo', 'bar', 'baz', 'bang']);
   assert.deepEqual(Object.keys(collection), ['foo', 'bar', 'baz', 'bang']);
   forOwn(items, function (item, key) {
     assert.deepEqual(item, collection.get(key));
   });
 });
Esempio n. 17
0
module.exports = function reduce(o, fn, acc, thisArg) {
  var first = arguments.length > 2;

  if (o && !Object.keys(o).length && !first) {
    return null;
  }

  forOwn(o, function (value, key, orig) {
    if (!first) {
      acc = value;
      first = true;
    } else {
      acc = fn.call(thisArg, acc, value, key, orig);
    }
  });
  return acc;
};
Esempio n. 18
0
describe('dateformat([now], [mask])', function() {
  forOwn(dateFormat.masks, function(value, key) {
    it('should format `' + key + '` mask', function(done) {
      var expected = expects[key];
      var actual = dateFormat(now, key);

      actual.should.equal(expected);
      done();
    });
  });
  it('should use `default` mask, when `mask` is empty', function(done) {
    var expected = expects['default'];
    var actual = dateFormat(now);

    actual.should.equal(expected);
    done();
  });
});
Esempio n. 19
0
module.exports = function deepMixin(o, objects) {
  if (!o || !objects) { return o || {}; }

  var len = arguments.length - 1;

  function copy(value, key) {
    var obj = this[key];
    if (isObject(value) && isObject(obj)) {
      deepMixin(obj, value);
    } else {
      this[key] = value;
    }
  }

  for (var i = 0; i < len; i++) {
    var obj = arguments[i + 1];

    if (isObject(obj)) {
      forIn(obj, copy, o);
    }
  }
  return o;
};
Esempio n. 20
0
module.exports = function mixIn(o) {
  var args = [].slice.call(arguments);
  var len = args.length;

  if (o == null) {
    return {};
  }

  if (len === 0) {
    return o;
  }

  function copy(value, key) {
    this[key] = value;
  }

  for (var i = 0; i < len; i++) {
    var obj = args[i];
    if (obj != null) {
      forOwn(obj, copy, o);
    }
  }
  return o;
};
Esempio n. 21
0
  forOwn(fixtures, function (args, name) {
    if (typeof cb == 'function') {
      args = cb(args);
    }

    args = Array.isArray(args) ? args : [args];

    var lead = '';
    if (options.showArgs) {
      lead = ' - ' + util.inspect(args, null, 2).replace(/[\s\n]+/g, ' ');
    }

    var benchmark = new Benchmark.Suite(name, {
      name: name,
      onStart: function () {
        console.log(chalk.gray('#%s: %s'), ++i, name, lead);
      },
      onComplete: function () {
        cursor.write('\n');
      }
    });

    forOwn(add, function (fn, fnName) {
      benchmark.add(fnName, {
        onCycle: function onCycle(event) {
          cursor.horizontalAbsolute();
          cursor.eraseLine();
          cursor.write('  ' + event.target);
        },
        onComplete: function () {
          if (options.result) {
            var res = fn.apply(null, args);
            var msg = chalk.bold('%j');
            if (!hasValues(res)) {
              msg = chalk.red('%j');
            }
            console.log(chalk.gray('  result: ') + msg, res);
          } else {
            cursor.write('\n');
          }
        },
        fn: function () {
          fn.apply(thisArg, args);
          return;
        }
      });

      if (options.sample) {
        console.log('> ' + fnName + ':\n  %j', fn.apply(null, options.sample));
      }
    });

    benchmark.on('complete', function () {
      if (Object.keys(add).length > 1) {
        var fastest = chalk.bold(this.filter('fastest').pluck('name'));
        console.log(chalk.gray('  fastest is ') + fastest);
      }
    });

    benchmark.run();
  });