Last active
November 9, 2017 08:33
-
-
Save sharmaabhinav/c0c93025c59ab501dbc97f907f722179 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var _ = {pick} | |
function pick (object, identifierStr) { | |
var path = identifierStr.split('.') | |
if (path.length === 1 ) { | |
return object[path[0]] | |
} | |
var [first, ...rest] = path | |
return pick(object[first], rest.join('.')) | |
} | |
const flatten = (arr) => arr.reduce((acc, val) => acc.concat(val), []) | |
function keys (object, path) { | |
var object_keys = [] | |
for (var key of Object.keys(object)) { | |
object_keys = object_keys.concat([`${path}.${key}`]) | |
if (typeof object[key] === 'object') { | |
object_keys = object_keys.concat(keys(object[key], `${path}.${key}`)) | |
} | |
} | |
return object_keys | |
} | |
function mixin( sourceObj, targetObj ) { | |
for (var key in sourceObj) { | |
targetObj[key] = sourceObj[key]; | |
} | |
return targetObj; | |
} | |
function isNull (val){ | |
return !val && typeof val === 'object' | |
} | |
// pollyfill for isNaN | |
if (!Number.isNaN) { | |
Number.isNaN = function(n) { | |
return ( | |
typeof n === "number" && | |
window.isNaN( n ) | |
); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment