GithubHelp home page GithubHelp logo

lodash-replacer's Introduction

lodash-replacer

NPM Build Status

lodash-node is amazing. I recently converted a bunch of small projects from code like this:

var _ = require('lodash');
_.each(/* ... code ... */);
_.map(/* ... code ... */);
_.pluck(/* ... code ... */);

To code like this:

var _map = require('lodash-node/modern/collections/map');
var _each = require('lodash-node/modern/collections/forEach');
var _pluck = require('lodash-node/modern/collections/map');
_each(/* ... code ... */);
_map(/* ... code ... */);
_pluck(/* ... code ... */);

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.

Usage

  1. npm install lodash-replacer -g
  2. Then in a project run lodash-replacer -f index.js
  3. lodash-replacer will write a file _index.js with the new var declarations at the top of the file and all calls to lodash functions replaced with the individual methods.

API

  • -f, --file The file to run lodash-replacer on
  • -t, --type The type of individual lodash modules you want: modern, comapt or underscore
  • -v, --verbose Log output during replacing

Warning

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.

TODO

  • Use AST parsing
  • Add option to recursively walk a directory and replace in all files
  • Add option to replace file inline

lodash-replacer's People

Contributors

lukekarrys avatar mathiasbynens avatar

Stargazers

Cameron Taylor avatar Héctor Cerón Figueroa avatar Oliver Joseph Ash avatar Oleksii Bobyriev avatar

Watchers

Cameron Taylor avatar  avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.