Skip to content

Instantly share code, notes, and snippets.

@jhyland87
Created January 20, 2017 19:44
Show Gist options
  • Save jhyland87/e866ed8f99669f27bab15e975ec0687f to your computer and use it in GitHub Desktop.
Save jhyland87/e866ed8f99669f27bab15e975ec0687f to your computer and use it in GitHub Desktop.
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