Created
January 20, 2017 19:44
-
-
Save jhyland87/e866ed8f99669f27bab15e975ec0687f 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
const _ = require( 'lodash' ) | |
let aliases = [ | |
"alias", | |
[ | |
" aliases ", | |
[ | |
"idk", | |
"TEST ", | |
123 | |
], | |
{ | |
"a": 12 | |
} | |
], | |
false, | |
null, | |
null, | |
true, | |
[ | |
"IDK", | |
function(){}, | |
zomg => false | |
] | |
] | |
const _aliases = _.chain( aliases ) | |
.thru( val => { | |
if ( _.isArray( val ) ) | |
return val | |
if ( _.isString( val ) ) | |
return [ val ] | |
return | |
}) | |
.flattenDeep() | |
.map( val => _.isString( val ) ? val : null ) | |
.map( _.trim ) | |
.map( _.toLower ) | |
.compact() | |
.sortedUniq() | |
.value() | |
// Result: ["alias", "aliases", "idk", "test", "idk"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment