javascript - use underscore to exclude file and directories -
i have node.js / express application uses i18next localization of site.
currently pulling list hard coded version: https://github.com/tzm/tzm-blade/blob/master/app/config/apps.coffee#l105 make list reading locales
directory , making list that.
i exclude dev
, readme.md
, config.json
being returned , have other directories can return correct country local example using node-cldr library extract language display name per https://github.com/papandreou/node-cldr#cldrextractlanguagedisplaynameslocaleidroot:
☺ node ruby-2.0.0-p195 master 2253522"" > var cldr = require('cldr'); undefined > cldr.extractlanguagedisplaynames('ru').ru; 'русский' >
etc...
so far looking @ reject
http://underscorejs.org/#reject collection don't see how remove these files , directories
fs.readdir "./locales", (err,locales) -> results = [] __.reject locales, (value, index, list) -> console.log value, index, list results.push value console.log results
any advice appreciated on how best using reject
function in underscore.
i'm not familiar coffeescript, here's you'd want (might require fixing up, don't know coffeescript):
exclude = [ 'dev', 'readme.md', 'config.json' ] results = __.reject locales, (value, index, list) -> return exclude.indexof(value) == -1
_.reject returns new list of items iterator returns true for. in case, if item not in exclude list (indexof === -1), function returns true, , item part of list returns.
Comments
Post a Comment