├── .eslintrc ├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── appveyor.yml ├── package.json ├── rollup.config.js ├── src └── sourcemap-codec.ts ├── test └── test.js └── tsconfig.json /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "rules": { 4 | "indent": [ 2, "tab", { "SwitchCase": 1 } ], 5 | "semi": [ 2, "always" ], 6 | "keyword-spacing": [ 2, { "before": true, "after": true } ], 7 | "space-before-blocks": [ 2, "always" ], 8 | "space-before-function-paren": [ 2, "always" ], 9 | "no-mixed-spaces-and-tabs": [ 2, "smart-tabs" ], 10 | "no-cond-assign": 0, 11 | "no-unused-vars": 2, 12 | "object-shorthand": [ 2, "always" ], 13 | "no-const-assign": 2, 14 | "no-class-assign": 2, 15 | "no-this-before-super": 2, 16 | "no-var": 2, 17 | "no-unreachable": 2, 18 | "valid-typeof": 2, 19 | "quote-props": [ 2, "as-needed" ], 20 | "one-var": [ 2, "never" ], 21 | "prefer-arrow-callback": 2, 22 | "prefer-const": [ 2, { "destructuring": "all" } ], 23 | "arrow-spacing": 2, 24 | "no-inner-declarations": 0 25 | }, 26 | "env": { 27 | "es6": true, 28 | "browser": true, 29 | "node": true, 30 | "mocha": true 31 | }, 32 | "extends": [ 33 | "eslint:recommended", 34 | "plugin:import/errors", 35 | "plugin:import/warnings" 36 | ], 37 | "parserOptions": { 38 | "ecmaVersion": 6, 39 | "sourceType": "module" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | dist 4 | coverage 5 | package-lock.json 6 | .idea 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: 4 | - "6" 5 | - "stable" 6 | env: 7 | global: 8 | - BUILD_TIMEOUT=10000 9 | install: npm install 10 | script: npm test 11 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # sourcemap-codec changelog 2 | 3 | ## 1.4.8 4 | 5 | * Performance boost ([#80](https://github.com/Rich-Harris/sourcemap-codec/pull/80)) 6 | 7 | ## 1.4.7 8 | 9 | * Include .map files in package ([#73](https://github.com/Rich-Harris/sourcemap-codec/issues/73)) 10 | 11 | ## 1.4.6 12 | 13 | * Use arrays instead of typed arrays ([#79](https://github.com/Rich-Harris/sourcemap-codec/pull/79)) 14 | 15 | ## 1.4.5 16 | 17 | * Handle overflow cases ([#78](https://github.com/Rich-Harris/sourcemap-codec/pull/78)) 18 | 19 | ## 1.4.4 20 | 21 | * Use Uint32Array, yikes ([#77](https://github.com/Rich-Harris/sourcemap-codec/pull/77)) 22 | 23 | ## 1.4.3 24 | 25 | * Use Uint16Array to prevent overflow ([#75](https://github.com/Rich-Harris/sourcemap-codec/pull/75)) 26 | 27 | ## 1.4.2 28 | 29 | * GO EVEN FASTER ([#74](https://github.com/Rich-Harris/sourcemap-codec/pull/74)) 30 | 31 | ## 1.4.1 32 | 33 | * GO FASTER ([#71](https://github.com/Rich-Harris/sourcemap-codec/pull/71)) 34 | 35 | ## 1.4.0 36 | 37 | * Add TypeScript declarations ([#70](https://github.com/Rich-Harris/sourcemap-codec/pull/70)) 38 | 39 | ## 1.3.1 40 | 41 | * Update build process, expose `pkg.module` 42 | 43 | ## 1.3.0 44 | 45 | * Update build process 46 | 47 | ## 1.2.1 48 | 49 | * Add dist files to npm package 50 | 51 | ## 1.2.0 52 | 53 | * Add ES6 build 54 | * Update dependencies 55 | * Add test coverage 56 | 57 | ## 1.1.0 58 | 59 | * Fix bug with lines containing single-character segments 60 | * Add tests 61 | 62 | ## 1.0.0 63 | 64 | * First release 65 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License 2 | 3 | Copyright (c) 2015 Rich Harris 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # deprecated — please use [@jridgewell/sourcemap-codec](https://github.com/jridgewell/sourcemap-codec) instead 2 | 3 | --- 4 | 5 | # sourcemap-codec 6 | 7 | Encode/decode the `mappings` property of a [sourcemap](https://docs.google.com/document/d/1U1RGAehQwRypUTovF1KRlpiOFze0b-_2gc6fAH0KY0k/edit). 8 | 9 | 10 | ## Why? 11 | 12 | Sourcemaps are difficult to generate and manipulate, because the `mappings` property – the part that actually links the generated code back to the original source – is encoded using an obscure method called [Variable-length quantity](https://en.wikipedia.org/wiki/Variable-length_quantity). On top of that, each segment in the mapping contains offsets rather than absolute indices, which means that you can't look at a segment in isolation – you have to understand the whole sourcemap. 13 | 14 | This package makes the process slightly easier. 15 | 16 | 17 | ## Installation 18 | 19 | ```bash 20 | npm install sourcemap-codec 21 | ``` 22 | 23 | 24 | ## Usage 25 | 26 | ```js 27 | import { encode, decode } from 'sourcemap-codec'; 28 | 29 | var decoded = decode( ';EAEEA,EAAE,EAAC,CAAE;ECQY,UACC' ); 30 | 31 | assert.deepEqual( decoded, [ 32 | // the first line (of the generated code) has no mappings, 33 | // as shown by the starting semi-colon (which separates lines) 34 | [], 35 | 36 | // the second line contains four (comma-separated) segments 37 | [ 38 | // segments are encoded as you'd expect: 39 | // [ generatedCodeColumn, sourceIndex, sourceCodeLine, sourceCodeColumn, nameIndex ] 40 | 41 | // i.e. the first segment begins at column 2, and maps back to the second column 42 | // of the second line (both zero-based) of the 0th source, and uses the 0th 43 | // name in the `map.names` array 44 | [ 2, 0, 2, 2, 0 ], 45 | 46 | // the remaining segments are 4-length rather than 5-length, 47 | // because they don't map a name 48 | [ 4, 0, 2, 4 ], 49 | [ 6, 0, 2, 5 ], 50 | [ 7, 0, 2, 7 ] 51 | ], 52 | 53 | // the final line contains two segments 54 | [ 55 | [ 2, 1, 10, 19 ], 56 | [ 12, 1, 11, 20 ] 57 | ] 58 | ]); 59 | 60 | var encoded = encode( decoded ); 61 | assert.equal( encoded, ';EAEEA,EAAE,EAAC,CAAE;ECQY,UACC' ); 62 | ``` 63 | 64 | 65 | # License 66 | 67 | MIT 68 | -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | # Test against this version of Node.js 2 | environment: 3 | matrix: 4 | # node.js 5 | - nodejs_version: "stable" 6 | 7 | # Install scripts. (runs after repo cloning) 8 | install: 9 | # Get the latest stable version of Node.js or io.js 10 | - ps: Install-Product node $env:nodejs_version 11 | # install modules 12 | - npm install 13 | 14 | # Post-install test scripts. 15 | test_script: 16 | # Output useful info for debugging. 17 | - node --version 18 | - npm --version 19 | # run tests 20 | - npm test 21 | 22 | # Don't actually build. 23 | build: off 24 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sourcemap-codec", 3 | "version": "1.4.8", 4 | "description": "Encode/decode sourcemap mappings", 5 | "main": "dist/sourcemap-codec.umd.js", 6 | "module": "dist/sourcemap-codec.es.js", 7 | "types": "dist/types/sourcemap-codec.d.ts", 8 | "scripts": { 9 | "test": "mocha", 10 | "build": "rm -rf dist && rollup -c && tsc", 11 | "pretest": "npm run build", 12 | "prepublish": "npm test", 13 | "lint": "eslint src", 14 | "pretest-coverage": "npm run build", 15 | "test-coverage": "rm -rf coverage/* && istanbul cover --report json node_modules/.bin/_mocha -- -u exports -R spec test/test.js", 16 | "posttest-coverage": "remap-istanbul -i coverage/coverage-final.json -o coverage/coverage-remapped.json -b dist && remap-istanbul -i coverage/coverage-final.json -o coverage/coverage-remapped.lcov -t lcovonly -b dist && remap-istanbul -i coverage/coverage-final.json -o coverage/coverage-remapped -t html -b dist", 17 | "ci": "npm run test-coverage && codecov < coverage/coverage-remapped.lcov" 18 | }, 19 | "repository": { 20 | "type": "git", 21 | "url": "https://github.com/Rich-Harris/sourcemap-codec" 22 | }, 23 | "keywords": [ 24 | "sourcemap", 25 | "vlq" 26 | ], 27 | "author": "Rich Harris", 28 | "license": "MIT", 29 | "bugs": { 30 | "url": "https://github.com/Rich-Harris/sourcemap-codec/issues" 31 | }, 32 | "homepage": "https://github.com/Rich-Harris/sourcemap-codec", 33 | "dependencies": {}, 34 | "devDependencies": { 35 | "codecov.io": "^0.1.6", 36 | "console-group": "^0.3.3", 37 | "eslint": "^6.0.1", 38 | "eslint-plugin-import": "^2.18.0", 39 | "istanbul": "^0.4.5", 40 | "mocha": "^6.1.4", 41 | "remap-istanbul": "^0.13.0", 42 | "rollup": "^1.16.4", 43 | "rollup-plugin-node-resolve": "^5.2.0", 44 | "rollup-plugin-typescript": "^1.0.1", 45 | "typescript": "^3.5.2" 46 | }, 47 | "files": [ 48 | "dist/*.js", 49 | "dist/*.js.map", 50 | "dist/**/*.d.ts", 51 | "README.md" 52 | ] 53 | } 54 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import typescript from 'rollup-plugin-typescript'; 2 | import resolve from 'rollup-plugin-node-resolve'; 3 | 4 | const pkg = require( './package.json' ); 5 | 6 | export default { 7 | input: 'src/sourcemap-codec.ts', 8 | plugins: [ 9 | typescript({ 10 | exclude: 'node_modules/**', 11 | typescript: require('typescript') 12 | }), 13 | resolve({ jsnext: true }) 14 | ], 15 | output: [{ 16 | file: pkg.main, 17 | format: 'umd', 18 | name: 'sourcemapCodec', 19 | sourcemap: true 20 | }, { 21 | file: pkg.module, 22 | format: 'es', 23 | sourcemap: true 24 | }] 25 | }; 26 | -------------------------------------------------------------------------------- /src/sourcemap-codec.ts: -------------------------------------------------------------------------------- 1 | export type SourceMapSegment = 2 | | [number] 3 | | [number, number, number, number] 4 | | [number, number, number, number, number]; 5 | export type SourceMapLine = SourceMapSegment[]; 6 | export type SourceMapMappings = SourceMapLine[]; 7 | 8 | const charToInteger: { [charCode: number]: number } = {}; 9 | const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; 10 | 11 | for (let i = 0; i < chars.length; i++) { 12 | charToInteger[chars.charCodeAt(i)] = i; 13 | } 14 | 15 | export function decode(mappings: string): SourceMapMappings { 16 | const decoded: SourceMapMappings = []; 17 | let line: SourceMapLine = []; 18 | const segment: SourceMapSegment = [ 19 | 0, // generated code column 20 | 0, // source file index 21 | 0, // source code line 22 | 0, // source code column 23 | 0, // name index 24 | ]; 25 | 26 | let j = 0; 27 | for (let i = 0, shift = 0, value = 0; i < mappings.length; i++) { 28 | const c = mappings.charCodeAt(i); 29 | 30 | if (c === 44) { // "," 31 | segmentify(line, segment, j); 32 | j = 0; 33 | 34 | } else if (c === 59) { // ";" 35 | segmentify(line, segment, j); 36 | j = 0; 37 | decoded.push(line); 38 | line = []; 39 | segment[0] = 0; 40 | 41 | } else { 42 | let integer = charToInteger[c]; 43 | if (integer === undefined) { 44 | throw new Error('Invalid character (' + String.fromCharCode(c) + ')'); 45 | } 46 | 47 | const hasContinuationBit = integer & 32; 48 | 49 | integer &= 31; 50 | value += integer << shift; 51 | 52 | if (hasContinuationBit) { 53 | shift += 5; 54 | } else { 55 | const shouldNegate = value & 1; 56 | value >>>= 1; 57 | 58 | if (shouldNegate) { 59 | value = value === 0 ? -0x80000000 : -value; 60 | } 61 | 62 | segment[j] += value; 63 | j++; 64 | value = shift = 0; // reset 65 | } 66 | } 67 | } 68 | 69 | segmentify(line, segment, j); 70 | decoded.push(line); 71 | 72 | return decoded; 73 | } 74 | 75 | function segmentify(line: SourceMapSegment[], segment: SourceMapSegment, j: number) { 76 | // This looks ugly, but we're creating specialized arrays with a specific 77 | // length. This is much faster than creating a new array (which v8 expands to 78 | // a capacity of 17 after pushing the first item), or slicing out a subarray 79 | // (which is slow). Length 4 is assumed to be the most frequent, followed by 80 | // length 5 (since not everything will have an associated name), followed by 81 | // length 1 (it's probably rare for a source substring to not have an 82 | // associated segment data). 83 | if (j === 4) line.push([segment[0], segment[1], segment[2], segment[3]]); 84 | else if (j === 5) line.push([segment[0], segment[1], segment[2], segment[3], segment[4]]); 85 | else if (j === 1) line.push([segment[0]]); 86 | } 87 | 88 | export function encode(decoded: SourceMapMappings): string { 89 | let sourceFileIndex = 0; // second field 90 | let sourceCodeLine = 0; // third field 91 | let sourceCodeColumn = 0; // fourth field 92 | let nameIndex = 0; // fifth field 93 | let mappings = ''; 94 | 95 | for (let i = 0; i < decoded.length; i++) { 96 | const line = decoded[i]; 97 | if (i > 0) mappings += ';'; 98 | if (line.length === 0) continue; 99 | 100 | let generatedCodeColumn = 0; // first field 101 | 102 | const lineMappings: string[] = []; 103 | 104 | for (const segment of line) { 105 | let segmentMappings = encodeInteger(segment[0] - generatedCodeColumn); 106 | generatedCodeColumn = segment[0]; 107 | 108 | if (segment.length > 1) { 109 | segmentMappings += 110 | encodeInteger(segment[1] - sourceFileIndex) + 111 | encodeInteger(segment[2] - sourceCodeLine) + 112 | encodeInteger(segment[3] - sourceCodeColumn); 113 | 114 | sourceFileIndex = segment[1]; 115 | sourceCodeLine = segment[2]; 116 | sourceCodeColumn = segment[3]; 117 | } 118 | 119 | if (segment.length === 5) { 120 | segmentMappings += encodeInteger(segment[4] - nameIndex); 121 | nameIndex = segment[4]; 122 | } 123 | 124 | lineMappings.push(segmentMappings); 125 | } 126 | 127 | mappings += lineMappings.join(','); 128 | } 129 | 130 | return mappings; 131 | } 132 | 133 | function encodeInteger(num: number): string { 134 | var result = ''; 135 | num = num < 0 ? (-num << 1) | 1 : num << 1; 136 | do { 137 | var clamped = num & 31; 138 | num >>>= 5; 139 | if (num > 0) { 140 | clamped |= 32; 141 | } 142 | result += chars[clamped]; 143 | } while (num > 0); 144 | 145 | return result; 146 | } 147 | -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | const decode = require('../').decode; 2 | const encode = require('../').encode; 3 | const assert = require('assert'); 4 | 5 | require('console-group').install(); 6 | 7 | describe('sourcemap-codec', () => { 8 | // TODO more tests 9 | let tests = [ 10 | { 11 | encoded: 'AAAA', 12 | decoded: [[[0, 0, 0, 0]]] 13 | }, 14 | { 15 | encoded: ';;;', 16 | decoded: [[], [], [], []] 17 | }, 18 | { 19 | encoded: 'A,AAAA;;AACDE;', 20 | decoded: [ 21 | [[0], [0, 0, 0, 0]], 22 | [], 23 | [[0, 0, 1, -1, 2]], 24 | [] 25 | ] 26 | }, 27 | { 28 | encoded: ';;;;EAEEA,EAAE,EAAC,CAAE;ECQY,UACC', 29 | decoded: [ 30 | [], 31 | [], 32 | [], 33 | [], 34 | [[2, 0, 2, 2, 0], [4, 0, 2, 4], [6, 0, 2, 5], [7, 0, 2, 7]], 35 | [[2, 1, 10, 19], [12, 1, 11, 20]] 36 | ] 37 | }, 38 | { 39 | encoded: "aAAA,IAAIA,eAAW,oCAAoCC,cACpC,aACdC,OAAOC,MAAOH,eAAU,GCFzB,5PAAIA,iBAAW,sBAAsBC,cACtB,aACdC,OAAOC,MAAOH,iBAAU,GCCzBI,IACAC", 40 | decoded: [ 41 | [ 42 | [13, 0, 0, 0], 43 | [17, 0, 0, 4, 0], 44 | [32, 0, 0, 15], 45 | [68, 0, 0, 51, 1], 46 | [82, 0, 1, 15], 47 | [95, 0, 2, 1, 2], 48 | [102, 0, 2, 8, 3], 49 | [108, 0, 2, 15, 0], 50 | [123, 0, 2, 25], 51 | [126, 1, 0, 0], 52 | [-126, 1, 0, 4, 0], 53 | [-109, 1, 0, 15], 54 | [-87, 1, 0, 37, 1], 55 | [-73, 1, 1, 15], 56 | [-60, 1, 2, 1, 2], 57 | [-53, 1, 2, 8, 3], 58 | [-47, 1, 2, 15, 0], 59 | [-30, 1, 2, 25], 60 | [-27, 2, 3, 0, 4], 61 | [-23, 2, 4, 0, 5] 62 | ] 63 | ] 64 | }, 65 | { 66 | encoded: "AAAA,aAEA,IAAIA,eAAiB,oCAAoCC,cACzD,SAASC,IACRC,OAAOC,MAAOJ,eAAgB,GAG/B,IAAIK,iBAAmB,sBAAsBJ,cAC7C,SAASK,IACRH,OAAOC,MAAOC,iBAAkB,GAGjCH,IACAI", 67 | decoded: [ 68 | [ 69 | [0, 0, 0, 0], 70 | [13, 0, 2, 0], 71 | [17, 0, 2, 4, 0], 72 | [32, 0, 2, 21], 73 | [68, 0, 2, 57, 1], 74 | [82, 0, 3, 0], 75 | [91, 0, 3, 9, 2], 76 | [95, 0, 4, 1, 3], 77 | [102, 0, 4, 8, 4], 78 | [108, 0, 4, 15, 0], 79 | [123, 0, 4, 31], 80 | [126, 0, 7, 0], 81 | [130, 0, 7, 4, 5], 82 | [147, 0, 7, 23], 83 | [169, 0, 7, 45, 1], 84 | [183, 0, 8, 0], 85 | [192, 0, 8, 9, 6], 86 | [196, 0, 9, 1, 3], 87 | [203, 0, 9, 8, 4], 88 | [209, 0, 9, 15, 5], 89 | [226, 0, 9, 33], 90 | [229, 0, 12, 0, 2], 91 | [233, 0, 13, 0, 6] 92 | ] 93 | ] 94 | }, 95 | { 96 | encoded: "CAAC,SAAUA,EAAQC,GACC,iBAAZC,SAA0C,oBAAXC,OAAyBF,IAC7C,mBAAXG,QAAyBA,OAAOC,IAAMD,OAAOH,GACnDA,IAHF,CAIEK,EAAM,WAAe,aAEtB,IAAIC,EAAiB,oCAAoCC,cAKzD,IAAIC,EAAmB,sBAAsBD,cAH5CE,OAAOC,MAAOJ,EAAgB,GAK9BG,OAAOC,MAAOF,EAAkB", 97 | decoded: [ 98 | [ 99 | [1, 0, 0, 1], 100 | [10, 0, 0, 11, 0], 101 | [12, 0, 0, 19, 1], 102 | [15, 0, 1, 20], 103 | [32, 0, 1, 8, 2], 104 | [41, 0, 1, 50], 105 | [61, 0, 1, 39, 3], 106 | [68, 0, 1, 64, 1], 107 | [72, 0, 2, 19], 108 | [91, 0, 2, 8, 4], 109 | [99, 0, 2, 33, 4], 110 | [106, 0, 2, 40, 5], 111 | [110, 0, 2, 46, 4], 112 | [117, 0, 2, 53, 1], 113 | [120, 0, 3, 2, 1], 114 | [124, 0, 0, 0], 115 | [125, 0, 4, 2, 6], 116 | [127, 0, 4, 8], 117 | [138, 0, 4, 23], 118 | [151, 0, 6, 1], 119 | [155, 0, 6, 5, 7], 120 | [157, 0, 6, 22], 121 | [193, 0, 6, 58, 8], 122 | [207, 0, 11, 1], 123 | [211, 0, 11, 5, 9], 124 | [213, 0, 11, 24], 125 | [235, 0, 11, 46, 8], 126 | [249, 0, 8, 2, 10], 127 | [256, 0, 8, 9, 11], 128 | [262, 0, 8, 16, 7], 129 | [264, 0, 8, 32], 130 | [267, 0, 13, 2, 10], 131 | [274, 0, 13, 9, 11], 132 | [280, 0, 13, 16, 9], 133 | [282, 0, 13, 34] 134 | ] 135 | ] 136 | }, 137 | { 138 | // Make sure Int16 isn't being used 139 | encoded: "gw+BAAAA,w+BAAAA,w+BAAAA,w+BAAAA", 140 | decoded: [ 141 | [ 142 | [32000,0,0,0,0], 143 | [33000,0,0,0,0], 144 | [34000,0,0,0,0], 145 | [35000,0,0,0,0] 146 | ] 147 | ] 148 | }, 149 | { 150 | // Handle largest 32bit int 151 | encoded: "+/////D", 152 | decoded: [ 153 | [ 154 | [2147483647] 155 | ] 156 | ] 157 | }, 158 | { 159 | // Handle smallest 32bit int 160 | encoded: "B", 161 | decoded: [ 162 | [ 163 | [-2147483648] 164 | ] 165 | ] 166 | } 167 | ]; 168 | 169 | const filtered = tests.filter((test) => { 170 | return test.solo; 171 | }); 172 | 173 | tests = filtered.length ? filtered : tests; 174 | 175 | describe('decode()', () => { 176 | tests.forEach((test, i) => { 177 | it('decodes sample ' + i, () => { 178 | assert.deepEqual(decode(test.encoded), test.decoded); 179 | }); 180 | }); 181 | }); 182 | 183 | describe('encode()', () => { 184 | tests.forEach((test, i) => { 185 | it('encodes sample ' + i, () => { 186 | assert.deepEqual(encode(test.decoded), test.encoded); 187 | }); 188 | }); 189 | }); 190 | }); 191 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "noImplicitAny": true, 4 | "diagnostics": true, 5 | "noImplicitThis": true, 6 | "noEmitOnError": true, 7 | "target": "es5", 8 | "lib": ["es5", "es6"], 9 | "declaration": true, 10 | "outDir": "dist/types" 11 | }, 12 | "include": [ 13 | "src" 14 | ], 15 | "exclude": [ 16 | "node_modules" 17 | ] 18 | } 19 | --------------------------------------------------------------------------------