npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

esformatter-rename

v1.0.0

Published

Esformatter plugin to rename variables, parameters, and labels

Downloads

14

Readme

esformatter-rename Build status

Esformatter plugin to rename variables, parameters, and labels

This was built to make comprehending deobfuscated scripts easier (e.g. rename a to jQuery). It is based off its sister project esformatter-phonetic which renames variables to pronouncable equivalents (also good for deobfuscating scripts).

Features:

  • Supports ES6 arrow functions (e.g. (a) => a + 1)
  • Supports let (e.g. let a = 1;)
  • Supports destructured variables (e.g. var {a, b} = obj;)

Getting Started

Install the module with: npm install esformatter-rename

Then, register it as a plugin and format your JS:

// Load and register our plugin
var esformatter = require('esformatter');
var esformatterRename = require('esformatter-rename');
esformatter.register(esformatterRename);

// Format our code
esformatter.format([
  'function myFn() {',
    'var a = \'hello\';',
    'console.log(a);',
  '}'
].join('\n'), {
  rename: {
    variables: {
      a: 'hello'
    }
  }
});
/*
function myFn() {
  var hello = 'hello';
  console.log(hello);
}
*/

Alternatively, load it via format or .esformatter:

{
  plugins: [
    'esformatter-rename'
  ]
}

Documentation

esformatter-rename exposes exports.transform for consumption by esformatter.

Options

We provide the following options to configure esformatter-rename during transformation. These should be stored under rename in your esformatter options.

  • variables Object - Key value pairing of original variable name to new name
    • For example variables: {hello: 'world'} will rename all hello variables to world variables
      • function hello() { console.log('hai'); } -> function world() { console.log('hai'); }
    • If you are potentially doing something dangerous (e.g. renaming an undeclared variable), we will warn you/skip it since it can have global reprecussions)
      • These warnings can be ignored and actions can be taken via the related option
  • labels Object - Key value pairing of origin label name to new name
    • For example labels: {loop1: 'myLoop'} will rename all loop1 labels to myLoop
      • loop1: while (true) { break loop1; } -> myLoop: while (true) { break myLoop; }
  • renameTopLevel Boolean - Allow for renaming of top level variables (i.e. anything declared with a var in the global scope)
    • If true, renaming is allowed. If false, it is not and a warning is logged.
    • By default, this is false.
  • renameUndeclared Boolean - Allow for renaming of undeclared variables (e.g. variable referenced without a var)
    • If true, renaming is allowed. If false, it is not and a warning is logged.
    • By default, this is false.
  • ignoreWith Boolean - Allow for renaming of variables that were referenced at least once in a with
    • For example var obj = {}; var hello; with (obj) { hello(); } will not allow renaming of hello
    • If true, renaming is allowed. If false, it is not and a warning is logged.
    • By default, this is false.

Examples

Renaming jQuery

In this example, we will rest jQuery from its normal convention of $ to the full name jQuery.

Script before renaming:

console.log($('#main').text());

Formatter options:

{
  rename: {
    variables: {
      '$': 'jQuery'
    },
    renameUndeclared: true
  }
}

Script after renaming:

console.log(jQuery('#main').text());

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint via grunt and test via npm test.

Donating

Support this project and others by twolfson via gratipay.

Support via Gratipay

Unlicense

As of Nov 13 2014, Todd Wolfson has released this repository and its contents to the public domain.

It has been released under the UNLICENSE.