Skip to content

Commit

Permalink
-> v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Oct 16, 2021
1 parent caa9d19 commit 258252e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 22 deletions.
18 changes: 11 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
# changelog

## 2.0.0

- Convert package to ESM, add `pkg.exports` ([#16](https://github.com/Rich-Harris/vlq/pull/16))

## 1.0.1

* Handle overflow cases ([#9](https://github.com/Rich-Harris/vlq/pull/9))
- Handle overflow cases ([#9](https://github.com/Rich-Harris/vlq/pull/9))

## 1.0.0

* Rewrite in TypeScript, include definitions in package ([#6](https://github.com/Rich-Harris/vlq/pull/6))
- Rewrite in TypeScript, include definitions in package ([#6](https://github.com/Rich-Harris/vlq/pull/6))

## 0.2.3

* Add LICENSE to npm package
- Add LICENSE to npm package

## 0.2.2

* Expose `pkg.module`, not `jsnext:main`
- 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
- 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`
- Author as ES6 module, accessible to ES6-aware systems via the `jsnext:main` field in `package.json`

## 0.1.0

* First release
- First release
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2017 [these people](https://github.com/Rich-Harris/vlq/graphs/contributors)
Copyright (c) 2017-2021 [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:

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"author": "Rich Harris",
"repository": "https://github.com/Rich-Harris/vlq",
"license": "MIT",
"version": "1.0.1",
"version": "2.0.0",
"type": "module",
"exports": {
"./package.json": "./package.json",
Expand Down
26 changes: 13 additions & 13 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
/** @type {Record<string, number>} */
let charToInteger = {};
let char_to_integer = {};

/** @type {Record<number, string>} */
let integerToChar = {};
let integer_to_char = {};

'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
.split('')
.forEach(function (char, i) {
charToInteger[char] = i;
integerToChar[i] = char;
char_to_integer[char] = i;
integer_to_char[i] = char;
});

/** @param {string} string */
Expand All @@ -20,24 +20,24 @@ export function decode(string) {
let value = 0;

for (let i = 0; i < string.length; i += 1) {
let integer = charToInteger[string[i]];
let integer = char_to_integer[string[i]];

if (integer === undefined) {
throw new Error('Invalid character (' + string[i] + ')');
}

const hasContinuationBit = integer & 32;
const has_continuation_bit = integer & 32;

integer &= 31;
value += integer << shift;

if (hasContinuationBit) {
if (has_continuation_bit) {
shift += 5;
} else {
const shouldNegate = value & 1;
const should_negate = value & 1;
value >>>= 1;

if (shouldNegate) {
if (should_negate) {
result.push(value === 0 ? -0x80000000 : -value);
} else {
result.push(value);
Expand All @@ -54,19 +54,19 @@ export function decode(string) {
/** @param {number | number[]} value */
export function encode(value) {
if (typeof value === 'number') {
return encodeInteger(value);
return encode_integer(value);
}

let result = '';
for (let i = 0; i < value.length; i += 1) {
result += encodeInteger(value[i]);
result += encode_integer(value[i]);
}

return result;
}

/** @param {number} num */
function encodeInteger(num) {
function encode_integer(num) {
let result = '';

if (num < 0) {
Expand All @@ -83,7 +83,7 @@ function encodeInteger(num) {
clamped |= 32;
}

result += integerToChar[clamped];
result += integer_to_char[clamped];
} while (num > 0);

return result;
Expand Down

0 comments on commit 258252e

Please sign in to comment.