Transitionning from
underscore
tolodash
.
To do so we use Grasp to refactor using code structure.
$ npm install grasp -g
$ ./underscore_to_lodash --help
./underscore_to_lodash <folder with some js>
Will run all transformations available in `rules`
Operates on a single folder containing javascript code.
All code will be refactored following conversions defined in ./rules
.
./rules
do not change code recursively.
For example, you just applied _.each
→ _.forEach
conversion. And still,
your code contains some _.each
:
_.forEach(ratePlanChargeData.RatePlanChargeTier, function(ratePlanChargeTier) {
_.each(ratePlanChargeTier, function(value, key) { /* Stuff */ });
});
Simply run ./underscore_to_lodash
repetitively until it stops changing code.
⚠ Disable rules for _.omit
and _.pick
⚠
$ chmod u-x rules/omit/* rules/pick/*
It prevents wierd tranformations, such as:
_.omit(o, [[["boomStick"]]])
Reads lines from standard input, then reports their occurrences.
$ cat sample
Kelly
Ash
Kelly
$ cat sample | ./capital.py
1: Ash
2: Kelly
Straight forward name, it installs lodash-migrate in a project for lodash → lodash migrations gone bad.
$ ./install_lodash-migrate <where to install>
Draft of conversions for lodash 3 → lodash 4 migration.
Note: For hackers, not maintained, so far.
You want to refactor some javascript, here is how.
It is just a rule enabling to change a Javascipt call to another using Grasp. Once you make your rule:
- Place it under
rules/
.$ touch rules/my/rule
- Make it executable.
$ chmod u+x rules/my/rule
🚀
You might want to check that your conversion is complete.
That is why after all conversions, underscore_to_lodash
runs some regexes to
ensure nothing is left.
You can add your regex at the end of blacklist
.
So far, calls to .chain
are handled manually.