pax_global_header00006660000000000000000000000064132254271310014512gustar00rootroot0000000000000052 comment=b7093c21ec6c9bbfed454d2785909b53cec4bd98 vlq-1.0.0/000077500000000000000000000000001322542713100123125ustar00rootroot00000000000000vlq-1.0.0/.eslintrc.json000066400000000000000000000021411322542713100151040ustar00rootroot00000000000000{ "root": true, "rules": { "indent": [ 2, "tab", { "SwitchCase": 1 } ], "semi": [ 2, "always" ], "keyword-spacing": [ 2, { "before": true, "after": true } ], "space-before-blocks": [ 2, "always" ], "space-before-function-paren": [ 2, "always" ], "no-mixed-spaces-and-tabs": [ 2, "smart-tabs" ], "no-cond-assign": 0, "no-unused-vars": 2, "object-shorthand": [ 2, "always" ], "no-const-assign": 2, "no-class-assign": 2, "no-this-before-super": 2, "no-var": 0, "no-unreachable": 2, "valid-typeof": 2, "quote-props": [ 2, "as-needed" ], "one-var": [ 2, "never" ], "prefer-arrow-callback": 0, "prefer-const": [ 0, { "destructuring": "all" } ], "arrow-spacing": 2, "no-inner-declarations": 0 }, "env": { "es6": true, "browser": true, "node": true, "mocha": true }, "extends": [ "eslint:recommended" ], "parserOptions": { "ecmaVersion": 6, "sourceType": "module" } } vlq-1.0.0/.gitignore000066400000000000000000000000411322542713100142750ustar00rootroot00000000000000.DS_Store tmp* node_modules dist vlq-1.0.0/CHANGELOG.md000066400000000000000000000007731322542713100141320ustar00rootroot00000000000000# changelog ## 1.0.0 * Rewrite in TypeScript, include definitions in package ([#6](https://github.com/Rich-Harris/vlq/pull/6)) ## 0.2.3 * Add LICENSE to npm package ## 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 vlq-1.0.0/LICENSE000066400000000000000000000021321322542713100133150ustar00rootroot00000000000000Copyright (c) 2017 [these people](https://github.com/Rich-Harris/vlq/graphs/contributors) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. vlq-1.0.0/README.md000066400000000000000000000033241322542713100135730ustar00rootroot00000000000000# 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 `vlq-1.0.0/src/000077500000000000000000000000001322542713100131015ustar00rootroot00000000000000vlq-1.0.0/src/vlq.ts000066400000000000000000000027361322542713100142630ustar00rootroot00000000000000let charToInteger: { [char: string]: number } = {}; let integerToChar: { [integer: number]: string } = {}; 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='.split( '' ).forEach( function ( char, i ) { charToInteger[ char ] = i; integerToChar[ i ] = char; }); export function decode ( string: string ): number[] { let result: number[] = []; let shift = 0; let value = 0; for ( let i = 0; i < string.length; i += 1 ) { let integer = charToInteger[ string[i] ]; if ( integer === undefined ) { throw new Error( 'Invalid character (' + string[i] + ')' ); } const hasContinuationBit = integer & 32; integer &= 31; value += integer << shift; if ( hasContinuationBit ) { shift += 5; } else { const shouldNegate = value & 1; value >>= 1; result.push( shouldNegate ? -value : value ); // reset value = shift = 0; } } return result; } export function encode ( value: number | number[] ): string { let result: string; if ( typeof value === 'number' ) { result = encodeInteger( value ); } else { result = ''; for ( let i = 0; i < value.length; i += 1 ) { result += encodeInteger( value[i] ); } } return result; } function encodeInteger ( num: number ): string { let result = ''; if ( num < 0 ) { num = ( -num << 1 ) | 1; } else { num <<= 1; } do { let clamped = num & 31; num >>= 5; if ( num > 0 ) { clamped |= 32; } result += integerToChar[ clamped ]; } while ( num > 0 ); return result; } vlq-1.0.0/test/000077500000000000000000000000001322542713100132715ustar00rootroot00000000000000vlq-1.0.0/test/decode.js000066400000000000000000000004241322542713100150520ustar00rootroot00000000000000var assert = require( 'assert' ), vlq = require( '../' ); var tests = [ [ 'AAAA', [ 0, 0, 0, 0 ] ], [ 'AAgBC', [ 0, 0, 16, 1 ] ] ]; tests.forEach( function ( test ) { assert.deepEqual( vlq.decode( test[0] ), test[1] ); }); console.log( 'all vlq.decode tests passed' ); vlq-1.0.0/test/encode.js000066400000000000000000000004201322542713100150600ustar00rootroot00000000000000var assert = require( 'assert' ), vlq = require( '../' ); var tests = [ [ [ 0, 0, 0, 0 ], 'AAAA' ], [ [ 0, 0, 16, 1 ], 'AAgBC' ] ]; tests.forEach( function ( test ) { assert.equal( vlq.encode( test[0] ), test[1] ); }); console.log( 'all vlq.encode tests passed' ); vlq-1.0.0/test/index.js000066400000000000000000000000561322542713100147370ustar00rootroot00000000000000require( './encode' ); require( './decode' ); vlq-1.0.0/tsconfig.json000066400000000000000000000004311322542713100150170ustar00rootroot00000000000000{ "compilerOptions": { "noImplicitAny": true, "diagnostics": true, "noImplicitThis": true, "noEmitOnError": true, "target": "es5", "lib": ["es5", "es6"], "declaration": true, "outDir": "dist/types" }, "include": [ "src" ], "exclude": [ "node_modules" ] }