lodash-node is amazing. I recently converted a bunch of small projects from code like this:
var _ = ;_;_;_;
To code like this:
var _map = ;var _each = ;var _pluck = ;;;;
This module helps you do that. Give it a file and it will find what lodash methods you are using (using lodash-finder) and then write another version of your file with only the methods you need.
npm install lodash-replacer -g
- Then in a project run
lodash-replacer -f index.js
lodash-replacerwill write a file
_index.jswith the new var declarations at the top of the file and all calls to lodash functions replaced with the individual methods.
-f, --fileThe file to run lodash-replacer on
-t, --typeThe type of individual lodash modules you want:
-v, --verboseLog output during replacing
This module is pretty naive at the moment. It uses regex. It fit my use case since my projects were all pretty simple. It could be made more robust with the use of an AST parser and some more options. But for now this works OK for me, but if you'd like to see more, I will happily accept pull requests.
- Use AST parsing
- Add option to recursively walk a directory and replace in all files
- Add option to replace file inline