Skip to content

AirVantage/_-

Repository files navigation

_⚰

Transitionning from underscore to lodash.

To do so we use Grasp to refactor using code structure.

How does it work?

Prerequisites

$ npm install grasp -g

Run

$ ./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.

Run several times

Code transformations are not recursive

./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 */ });
});
Solution

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"]]])

Helper scripts

capital.py

Reads lines from standard input, then reports their occurrences.

$ cat sample
Kelly
Ash
Kelly
$ cat sample | ./capital.py
1: Ash
2: Kelly

install_lodash-migrate

Straight forward name, it installs lodash-migrate in a project for lodash → lodash migrations gone bad.

$ ./install_lodash-migrate <where to install>

lodash3_to_lodash4

Draft of conversions for lodash 3 → lodash 4 migration.

Note: For hackers, not maintained, so far.

Hack

You want to refactor some javascript, here is how.

Conversions

It is just a rule enabling to change a Javascipt call to another using Grasp. Once you make your rule:

  1. Place it under rules/.
    • $ touch rules/my/rule
  2. Make it executable.
    • $ chmod u+x rules/my/rule

🚀

Checks

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.

Limitations

So far, calls to .chain are handled manually.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published