Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/thlorenz/varify
browserify transform that converts all const assignments to var assignments.
https://github.com/thlorenz/varify
Last synced: 2 months ago
JSON representation
browserify transform that converts all const assignments to var assignments.
- Host: GitHub
- URL: https://github.com/thlorenz/varify
- Owner: thlorenz
- License: mit
- Created: 2013-05-22T01:57:18.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2017-03-10T16:21:39.000Z (almost 8 years ago)
- Last Synced: 2024-10-18T01:09:17.039Z (3 months ago)
- Language: JavaScript
- Size: 7.81 KB
- Stars: 10
- Watchers: 3
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# varify [![build status](https://secure.travis-ci.org/thlorenz/varify.png)](http://travis-ci.org/thlorenz/varify)
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](https://github.com/olov/defs) which provides
[limited](https://github.com/olov/defs#loop-closures-limitation) support for that.## Example
Given this JavaScript:
```js
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:
```js
require('browserify')()
.transform(require('varify'))
.add(__dirname + '/sample.js')
.bundle()
.pipe(process.stdout);
```Outputs:
```js
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