rename-variables
v0.1.1
Published
Safely rename JS variables
Downloads
11
Readme
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}')