refactor filters and corresponding tests

This commit is contained in:
harttle
2016-10-24 00:05:17 +08:00
parent 300c3710c6
commit 365a047736
10 changed files with 358 additions and 242 deletions
+25 -1
View File
@@ -1,5 +1,29 @@
function isString(value){
/*
* Checks if value is classified as a String primitive or object.
* @param {any} value The value to check.
* @return {Boolean} Returns true if value is a string, else false.
*/
function isString(value) {
return value instanceof String || typeof value === 'string';
}
/*
* Iterates over own enumerable string keyed properties of an object and invokes iteratee for each property.
* The iteratee is invoked with three arguments: (value, key, object).
* Iteratee functions may exit iteration early by explicitly returning false.
* @param {Object} object The object to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @return {Object} Returs object.
*/
function forOwn(object, iteratee) {
object = object || {};
for (var k in object) {
if (object.hasOwnProperty(k)) {
if (iteratee(object[k], k, object) === false) break;
}
}
return object;
}
exports.isString = isString;
exports.forOwn = forOwn;