Comparing version 0.2.3 to 1.0.0
# changelog | ||
## 1.0.0 | ||
* Rewrite in TypeScript, include definitions in package ([#6](https://github.com/Rich-Harris/vlq/pull/6)) | ||
## 0.2.3 | ||
@@ -4,0 +8,0 @@ |
130
dist/vlq.js
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(factory((global.vlq = global.vlq || {}))); | ||
(factory((global.vlq = {}))); | ||
}(this, (function (exports) { 'use strict'; | ||
@@ -9,77 +9,61 @@ | ||
var integerToChar = {}; | ||
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='.split( '' ).forEach( function ( char, i ) { | ||
charToInteger[ char ] = i; | ||
integerToChar[ i ] = char; | ||
'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 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 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; | ||
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; | ||
} | ||
@@ -86,0 +70,0 @@ |
@@ -7,17 +7,20 @@ { | ||
"license": "MIT", | ||
"version": "0.2.3", | ||
"version": "1.0.0", | ||
"main": "dist/vlq.js", | ||
"module": "src/vlq.js", | ||
"module": "dist/vlq.es.js", | ||
"types": "dist/types/vlq.d.ts", | ||
"files": [ | ||
"README.md", | ||
"LICENSE", | ||
"src/vlq.js", | ||
"dist/vlq.js" | ||
"dist/*.js", | ||
"dist/**/*.d.ts" | ||
], | ||
"devDependencies": { | ||
"eslint": "^3.19.0", | ||
"rollup": "^0.41.6" | ||
"rollup": "^0.53.3", | ||
"rollup-plugin-typescript": "^0.8.1", | ||
"typescript": "^2.6.2" | ||
}, | ||
"scripts": { | ||
"build": "rollup src/vlq.js -n vlq -f umd > dist/vlq.js", | ||
"build": "rollup -c && tsc", | ||
"lint": "eslint src", | ||
@@ -24,0 +27,0 @@ "test": "node test", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
7746
7
136
1
4