Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented lodash mixin to handle the case where the undefined value…
…s were being tested against
- Loading branch information
Showing
2 changed files
with
38 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
declare module _ { | ||
interface LoDashStatic { | ||
compactObject<T>(object:T, removeFunctions?:boolean):T; | ||
} | ||
} | ||
|
||
namespace common.libs { | ||
|
||
/** | ||
* lodash_mixins.ts | ||
* Add mixins (additional functions) to lodash. Call them with _.[fn_name](params) | ||
* See http://lodash.com/docs#mixin for more info | ||
*/ | ||
|
||
_.mixin({ | ||
|
||
/** | ||
* Get an object with all falsy values removed | ||
* @returns {Object} | ||
* @param object | ||
* @param removeFunctions | ||
*/ | ||
compactObject : (object:Object, removeFunctions:boolean = false):Object => { | ||
var clone = _.clone(object); | ||
_.each(clone, function(value, key) { | ||
if(!value || removeFunctions && _.isFunction(value)) { | ||
delete clone[key]; | ||
} | ||
}); | ||
return clone; | ||
} | ||
|
||
|
||
}); | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters