Get unlimited public & private packages + team-based management with npm Teams.Learn more »

rename-variables

0.1.1 • Public • Published

rename-variables

Safely rename JS variables

Installation

With your favorite package manager:

  • packin: packin add rename-variables
  • component: component install jkroso/rename-variables
  • npm: npm install rename-variables

then in your app:

var rename = require('rename-variables')

API

rename(node, from, to)

Recursively renames all identifiers with the name from within node to to. It will abort once it reaches a scope where from is shadowed.

var parse = require('esprima').parse
rename(parse('var a = 1'), 'a', 'b') // => parse('var b = 1')
rename(parse('a;var a'), 'a', 'b') // => parse('b;var b')
rename(parse('function a(a){a}'), 'a', 'b') // => parse('function b(a){a}')
rename(parse('try{a}catch(a){a}'), 'a', 'b') // => parse('try{b}catch(a){a}')

Install

npm i rename-variables

DownloadsWeekly Downloads

1

Version

0.1.1

License

MIT

Last publish

Collaborators

  • avatar