Skip to content
browserify transform that converts all const assignments to var assignments.
JavaScript Shell
Latest commit 1b46907 May 21, 2013 Thorsten Lorenz 0.1.1 indicates lack of block scope support
Failed to load latest commit information.
example commandline example May 21, 2013
test adding tests May 21, 2013
.gitignore initial package May 21, 2013
.jshintrc example May 21, 2013
.travis.yml travisified May 21, 2013
LICENSE initial package May 22, 2013
README.md 0.1.1 indicates lack of block scope support May 21, 2013
index.js only replacing if next token is identifier May 21, 2013
package.json

README.md

varify build status

browserify transform that converts all const assignments to var assignments.

npm install varify

Why?

So you can get the benefits of immutable variables with help of lint tools while staying compatible with older browsers that have no const.

Warning

The real const is block scoped, however when replaced with var this feature is lost. So only use varify if you can do without block scope and are only looking for some immutability support that gets compiled out for compatibility.

If you are after block scope, have a look at def.js which provides limited support for that.

Example

Given this JavaScript:

const a = 1;

var keep = { const: 1 };
keep.const = 2;

const foo = function () {
  console.log('some const s should be left unchanged');
};

Running browserify with varify transform:

require('browserify')()
  .transform(require('varify'))
  .add(__dirname + '/sample.js')
  .bundle()
  .pipe(process.stdout);

Outputs:

var a = 1;

var keep = { const: 1 };
keep.const = 2;

var foo = function () {
  console.log('some const s should be left unchanged');
};

Usage from Commandline

browserify -t varify sample.js > bundle.js
Something went wrong with that request. Please try again.