Comparing version 0.2.5 to 0.2.6
@@ -1244,4 +1244,24 @@ #Comb | ||
comb(obj).values(); //["b", "d", "f"] | ||
``` | ||
``` | ||
###`pick` | ||
Pick certain key/value pairs from a hash | ||
``` | ||
var ob = {a: "a", b: "b", c: "c"}; | ||
comb(obj).pick(["a", "b"]); //{a: "a", b:'b'} | ||
comb(obj).pick("c"); //{c: "c"}; | ||
``` | ||
###`omit` | ||
Omit certain key/value pairs from a hash | ||
``` | ||
var ob = {a: "a", b: "b", c: "c"}; | ||
comb(obj).omit(["a", "b"]); //{c: "c"} | ||
comb(obj).omit("c"); //{a: "a", b: "b"}; | ||
``` | ||
###`toArray` | ||
@@ -1248,0 +1268,0 @@ |
@@ -0,1 +1,12 @@ | ||
# 0.2.6 | ||
* Added new methods to `comb.hash` | ||
* `pick` - pick only certain key/value pairs from an object | ||
* `omit` - omit certain key/value pairs from an object | ||
# 0.2.5 | ||
* Fixed the additions of weekdays on dates that span weekends. … | ||
* new Date(2013, 11, 19, 0, 0, 0) + 3 weekdays should be tuesday not Sunday | ||
# 0.2.4 | ||
@@ -2,0 +13,0 @@ |
@@ -5,4 +5,14 @@ var comb = exports, | ||
isArguments = misc.isArguments, | ||
pSlice = Array.prototype.slice; | ||
pSlice = Array.prototype.slice, | ||
pToString = Object.prototype.toString, | ||
_baseArray, _baseString; | ||
function baseArray() { | ||
return _baseArray || (_baseArray = require("./array").array); | ||
} | ||
function baseString() { | ||
return _baseString || (_baseString = require("./string")); | ||
} | ||
//taken from node js assert.js | ||
@@ -320,4 +330,76 @@ //https://github.com/joyent/node/blob/master/lib/assert.js | ||
/** | ||
* Returns a new hash with the specified keys omitted from the hash. | ||
* | ||
* ``` | ||
* var obj = {a: "a", b: "b", c: "c"}; | ||
* | ||
* //as a function | ||
* comb.hash.omit(obj, ["a", "b"]); //{c: "c"} | ||
* comb.hash.omit(obj, "c"); //{a: "a", b: "b"}; | ||
* | ||
* //as a monad | ||
* comb(obj).omit(["a", "b"]); //{c: "c"} | ||
* comb(obj).omit("c"); //{a: "a", b: "b"}; | ||
* | ||
* ``` | ||
* | ||
* @param {Object} hash The hash to omit values from | ||
* @param {Array|String} omitted the keys to omit. | ||
* @returns {Object} a new Object with the keys omitted | ||
* @memberOf comb.hash | ||
*/ | ||
function omit(hash, omitted) { | ||
if (!isHash(hash)) { | ||
throw new TypeError("expected object got ", pToString.call(hash)); | ||
} | ||
if (baseString().isString(omitted)) { | ||
omitted = [omitted]; | ||
} | ||
var objKeys = baseArray().difference(Object.keys(hash), omitted), key, ret = {}; | ||
for (var i = 0, len = objKeys.length; i < len; ++i) { | ||
key = objKeys[i]; | ||
ret[key] = hash[key]; | ||
} | ||
return ret; | ||
} | ||
/** | ||
* Returns a new hash with the specified keys omitted from the hash. | ||
* | ||
* ``` | ||
* var obj = {a: "a", b: "b", c: "c"}; | ||
* | ||
* //as a function | ||
* comb.hash.pick(obj, ["a", "b"]); //{a: "a", b:'b'} | ||
* comb.hash.pick(obj, "c"); //{c: "c"}; | ||
* | ||
* //as a monad | ||
* comb(obj).pick(["a", "b"]); //{a: "a", b:'b'} | ||
* comb(obj).pick("c"); //{c: "c"}; | ||
* | ||
* ``` | ||
* | ||
* @param {Object} hash The hash to pick values from | ||
* @param {Array|String} picked the keys to pick. | ||
* @returns {Object} a new Object with only the keys specified | ||
* @memberOf comb.hash | ||
*/ | ||
function pick(hash, picked) { | ||
if (!isHash(hash)) { | ||
throw new TypeError("expected object got ", pToString.call(hash)); | ||
} | ||
if (baseString().isString(picked)) { | ||
picked = [picked]; | ||
} | ||
var objKeys = baseArray().intersect(Object.keys(hash), picked), key, ret = {}; | ||
for (var i = 0, len = objKeys.length; i < len; ++i) { | ||
key = objKeys[i]; | ||
ret[key] = hash[key]; | ||
} | ||
return ret; | ||
} | ||
/** | ||
* Loops through each k/v in a hash. | ||
@@ -473,7 +555,9 @@ * | ||
comb.hash = { | ||
forEach:forEach, | ||
filter:filter, | ||
invert:invert, | ||
values:values, | ||
toArray:toArray | ||
forEach: forEach, | ||
omit: omit, | ||
pick: pick, | ||
filter: filter, | ||
invert: invert, | ||
values: values, | ||
toArray: toArray | ||
}; | ||
@@ -480,0 +564,0 @@ |
@@ -24,3 +24,6 @@ var base = require("../base"), | ||
"values", | ||
"toArray" | ||
"toArray", | ||
"omit", | ||
"pick", | ||
"keys" | ||
]; | ||
@@ -27,0 +30,0 @@ |
@@ -700,3 +700,3 @@ var define = require("./define").define, | ||
* }, | ||
* funciton(err){ | ||
* function(err){ | ||
* | ||
@@ -703,0 +703,0 @@ * } console.error(err); |
{ | ||
"name": "comb", | ||
"description": "A framework for node", | ||
"version": "0.2.5", | ||
"version": "0.2.6", | ||
"keywords": ["OO", "Object Oriented", "Collections", "Tree", "HashTable", "Pool", "Logging", "Promise", "Promises", "Proxy"], | ||
@@ -6,0 +6,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2887914
11625