Giter Club home page Giter Club logo

codemods's Introduction

codemods

A collection of codemods for performing automated code refactoring.

Usage

These codemods require jscodeshift so let's start by installing that.

npm install -g jscodeshift

Then check out this repo.

git clone https://github.com/kevinbarabash/codemods

Finally, run one of the codemods on your code.

jscodeshift -t /path/to/transforms/transform.js /path/to/your/code

Transforms

Multiple transforms are grouped into a single codemod. Some transforms output ES2016+ code. Please check the output and verify that the code will work for you before committing changes.

array.js

  • _.head(x) -> x[0]
  • _.head(x, n) -> x.slice(n)
  • _.first (alias for _.head)
  • _.tail(x) -> x.slice(1)
  • _.tail(x, n) -> x.slice(n)
  • _.rest (alias for _.tail)
  • _.last(x) -> x[x.length - 1]
  • _.last(x, n) -> x.slice(x.length - n)

function.js

  • _.bind(fn, obj, ...x) -> fn.bind(obj, ...x)
  • _.partial(fn, a, b); -> (...args) => fn(a, b, ...args)

object.js

  • _.clone(x) -> { ...x }
  • _.extend({}, x, y) -> { ...x, ...y }
  • _.extend(obj, x, y) -> Object.assign(obj, x, y)
  • _.keys(x) -> Object.keys(x)
  • _.pairs(x) -> Object.entries(x)
  • _.values(x) -> Object.values(x)

util.js

  • _.isArray(x) -> Array.isArray(x)
  • _.isBoolean(x) -> typeof(x) === 'boolean'
  • _.isFinite(x) -> Number.isFinite(x)
  • _.isFunction(x) -> typeof(x) === 'function'
  • _.isNull(x) -> x === null
  • _.isString(x) -> typeof(x) === 'string'
  • _.isUndefined(x) -> typeof(x) === 'undefined'

codemods's People

Contributors

kevinbarabash avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

forivall

codemods's Issues

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.