This commit is contained in:
chrosey
2017-09-13 07:52:34 +02:00
parent a1f16c37f4
commit 2340b0226b
24621 changed files with 2912161 additions and 149 deletions
+17
View File
@@ -0,0 +1,17 @@
# changelog
## 0.2.2
* Expose `pkg.module`, not `jsnext:main`
## 0.2.1
* Performance boost - vlq no longer checks that you've passed a number or an array into `vlq.encode()`, making it significantly faster
## 0.2.0
* Author as ES6 module, accessible to ES6-aware systems via the `jsnext:main` field in `package.json`
## 0.1.0
* First release
Generated Vendored
+73
View File
@@ -0,0 +1,73 @@
# vlq.js
Convert integers to a Base64-encoded VLQ string, and vice versa. No dependencies, works in node.js or browsers, supports AMD.
## Why would you want to do that?
Sourcemaps are the most likely use case. Mappings from original source to generated content are encoded as a sequence of VLQ strings.
## What is a VLQ string?
A [variable-length quantity](http://en.wikipedia.org/wiki/Variable-length_quantity) is a compact way of encoding large integers in text (i.e. in situations where you can't transmit raw binary data). An integer represented as digits will always take up more space than the equivalent VLQ representation:
| Integer | VLQ |
| :------------------ | :--------- |
| 0 | A |
| 1 | C |
| -1 | D |
| 123 | 2H |
| 123456789 | qxmvrH |
| 123456789123456789 | gxvh6sB |
## Installation
```bash
npm install vlq
```
...or...
```bash
bower install vlq
```
...or grab the vlq.js file and include it with a `<script src='vlq.js'>` tag.
## Usage
### Encoding
`vlq.encode` accepts an integer, or an array of integers, and returns a string:
```js
vlq.encode( 123 ); // '2H';
vlq.encode([ 123, 456, 789 ]); // '2HwcqxB'
```
### Decoding
`vlq.decode` accepts a string and always returns an array:
```js
vlq.decode( '2H' ); // [ 123 ]
vlq.decode( '2HwcqxB' ); // [ 123, 456, 789 ]
```
## Using vlq.js with sourcemaps
[See here for an example of using vlq.js with sourcemaps.](https://github.com/Rich-Harris/vlq/tree/master/sourcemaps)
## Credits
Adapted from [murzwin.com/base64vlq.html](http://murzwin.com/base64vlq.html) by Alexander Pavlov.
## License
MIT.
+91
View File
@@ -0,0 +1,91 @@
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(factory((global.vlq = global.vlq || {})));
}(this, (function (exports) { 'use strict';
var charToInteger = {};
var integerToChar = {};
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='.split( '' ).forEach( function ( char, i ) {
charToInteger[ char ] = i;
integerToChar[ i ] = char;
});
function decode ( string ) {
var result = [];
var shift = 0;
var value = 0;
for ( var i = 0; i < string.length; i += 1 ) {
var integer = charToInteger[ string[i] ];
if ( integer === undefined ) {
throw new Error( 'Invalid character (' + string[i] + ')' );
}
var hasContinuationBit = integer & 32;
integer &= 31;
value += integer << shift;
if ( hasContinuationBit ) {
shift += 5;
} else {
var shouldNegate = value & 1;
value >>= 1;
result.push( shouldNegate ? -value : value );
// reset
value = shift = 0;
}
}
return result;
}
function encode ( value ) {
var result;
if ( typeof value === 'number' ) {
result = encodeInteger( value );
} else {
result = '';
for ( var i = 0; i < value.length; i += 1 ) {
result += encodeInteger( value[i] );
}
}
return result;
}
function encodeInteger ( num ) {
var result = '';
if ( num < 0 ) {
num = ( -num << 1 ) | 1;
} else {
num <<= 1;
}
do {
var clamped = num & 31;
num >>= 5;
if ( num > 0 ) {
clamped |= 32;
}
result += integerToChar[ clamped ];
} while ( num > 0 );
return result;
}
exports.decode = decode;
exports.encode = encode;
Object.defineProperty(exports, '__esModule', { value: true });
})));
+96
View File
@@ -0,0 +1,96 @@
{
"_args": [
[
{
"raw": "vlq@^0.2.1",
"scope": null,
"escapedName": "vlq",
"name": "vlq",
"rawSpec": "^0.2.1",
"spec": ">=0.2.1 <0.3.0",
"type": "range"
},
"c:\\xampp\\htdocs\\laravel\\node_modules\\magic-string"
]
],
"_from": "vlq@>=0.2.1 <0.3.0",
"_id": "vlq@0.2.2",
"_inCache": true,
"_location": "/vlq",
"_nodeVersion": "7.8.0",
"_npmOperationalInternal": {
"host": "packages-18-east.internal.npmjs.com",
"tmp": "tmp/vlq-0.2.2.tgz_1492045338584_0.668944044271484"
},
"_npmUser": {
"name": "rich_harris",
"email": "richard.a.harris@gmail.com"
},
"_npmVersion": "4.2.0",
"_phantomChildren": {},
"_requested": {
"raw": "vlq@^0.2.1",
"scope": null,
"escapedName": "vlq",
"name": "vlq",
"rawSpec": "^0.2.1",
"spec": ">=0.2.1 <0.3.0",
"type": "range"
},
"_requiredBy": [
"/magic-string"
],
"_resolved": "https://registry.npmjs.org/vlq/-/vlq-0.2.2.tgz",
"_shasum": "e316d5257b40b86bb43cb8d5fea5d7f54d6b0ca1",
"_shrinkwrap": null,
"_spec": "vlq@^0.2.1",
"_where": "c:\\xampp\\htdocs\\laravel\\node_modules\\magic-string",
"author": {
"name": "Rich Harris"
},
"bugs": {
"url": "https://github.com/Rich-Harris/vlq/issues"
},
"dependencies": {},
"description": "Generate, and decode, base64 VLQ mappings for source maps and other uses",
"devDependencies": {
"eslint": "^3.19.0",
"rollup": "^0.41.6"
},
"directories": {},
"dist": {
"shasum": "e316d5257b40b86bb43cb8d5fea5d7f54d6b0ca1",
"tarball": "https://registry.npmjs.org/vlq/-/vlq-0.2.2.tgz"
},
"files": [
"README.md",
"src/vlq.js",
"dist/vlq.js"
],
"gitHead": "a208af958037eeea3b0978b1a353c77e837a4ac8",
"homepage": "https://github.com/Rich-Harris/vlq#readme",
"license": "MIT",
"main": "dist/vlq.js",
"maintainers": [
{
"name": "rich_harris",
"email": "richard.a.harris@gmail.com"
}
],
"module": "src/vlq.js",
"name": "vlq",
"optionalDependencies": {},
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "git+https://github.com/Rich-Harris/vlq.git"
},
"scripts": {
"build": "rollup src/vlq.js -n vlq -f umd > dist/vlq.js",
"lint": "eslint src",
"prepublish": "npm test",
"pretest": "npm run build",
"test": "node test"
},
"version": "0.2.2"
}
+78
View File
@@ -0,0 +1,78 @@
var charToInteger = {};
var integerToChar = {};
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='.split( '' ).forEach( function ( char, i ) {
charToInteger[ char ] = i;
integerToChar[ i ] = char;
});
export function decode ( string ) {
var result = [];
var shift = 0;
var value = 0;
for ( var i = 0; i < string.length; i += 1 ) {
var integer = charToInteger[ string[i] ];
if ( integer === undefined ) {
throw new Error( 'Invalid character (' + string[i] + ')' );
}
var hasContinuationBit = integer & 32;
integer &= 31;
value += integer << shift;
if ( hasContinuationBit ) {
shift += 5;
} else {
var shouldNegate = value & 1;
value >>= 1;
result.push( shouldNegate ? -value : value );
// reset
value = shift = 0;
}
}
return result;
}
export function encode ( value ) {
var result;
if ( typeof value === 'number' ) {
result = encodeInteger( value );
} else {
result = '';
for ( var i = 0; i < value.length; i += 1 ) {
result += encodeInteger( value[i] );
}
}
return result;
}
function encodeInteger ( num ) {
var result = '';
if ( num < 0 ) {
num = ( -num << 1 ) | 1;
} else {
num <<= 1;
}
do {
var clamped = num & 31;
num >>= 5;
if ( num > 0 ) {
clamped |= 32;
}
result += integerToChar[ clamped ];
} while ( num > 0 );
return result;
}