Compare commits

..

No commits in common. "f7dbe708882d4c87cdd40dc012fc076be099c761" and "8055f6203e599dbfaaadfe7f470c813f9fba47c0" have entirely different histories.

5 changed files with 1245 additions and 1442 deletions

View File

@ -53,7 +53,7 @@ const uint8Array3 = decodeL(l) // Uint8Array [ 3, 192 ]
Load this file in the browser to gain access to a `base1` global. Load this file in the browser to gain access to a `base1` global.
```html ```html
<script src="https://unpkg.com/base1@1/dist/iife/base1.js" crossorigin></script> <script src="https://unpkg.com/base1" crossorigin></script>
<script> <script>
console.log(base1.decode('AAAAAAAAAAAAAAAAAAAAAAAAAA')) console.log(base1.decode('AAAAAAAAAAAAAAAAAAAAAAAAAA'))
</script> </script>

2693
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +1,6 @@
{ {
"name": "base1", "name": "base1",
"version": "1.0.3", "version": "1.0.1",
"description": "Convert binary data to Base1", "description": "Convert binary data to Base1",
"homepage": "https://github.com/qntm/base1", "homepage": "https://github.com/qntm/base1",
"repository": { "repository": {
@ -9,6 +9,7 @@
}, },
"module": "dist/es6/base1.js", "module": "dist/es6/base1.js",
"main": "dist/cjs/base1.js", "main": "dist/cjs/base1.js",
"browser": "dist/iife/base1.js",
"keywords": [ "keywords": [
"base64", "base64",
"base1", "base1",

View File

@ -23,15 +23,11 @@ export const encode = uint8Array => {
} }
export const decodeL = l => { export const decodeL = l => {
if (typeof l !== 'bigint' || l < 0n) {
throw Error('This is not a non-negative BigInt')
}
const bytes = [] const bytes = []
while (l > 0n) { while (l > 0n) {
l -= 1n l -= 1n
bytes.push(Number(l % 256n)) bytes.push(Number(l % 256n))
l /= 256n // rounds down l /= 256n
} }
bytes.reverse() bytes.reverse()

View File

@ -39,11 +39,6 @@ describe('base1', () => {
}) })
describe('decodeL', () => { describe('decodeL', () => {
it('wants a non-negative BigInt', () => {
expect(() => decodeL(8)).toThrowError('This is not a non-negative BigInt')
expect(() => decodeL(-1n)).toThrowError('This is not a non-negative BigInt')
})
it('works', () => { it('works', () => {
expect(decodeL(0n)).toEqual(Uint8Array.from([])) expect(decodeL(0n)).toEqual(Uint8Array.from([]))
expect(decodeL(1n)).toEqual(Uint8Array.from([0])) expect(decodeL(1n)).toEqual(Uint8Array.from([0]))