1
0
mirror of https://github.com/qntm/base65536 synced 2026-03-29 19:44:45 +02:00

Compare commits

..

2 Commits

Author SHA1 Message Date
qntm
9cfc7812d5 4.0.2 2021-09-12 13:54:22 +01:00
dependabot[bot]
97beffcf49
Bump axios from 0.21.1 to 0.21.4 (#49)
* Bump axios from 0.21.1 to 0.21.4

Bumps [axios](https://github.com/axios/axios) from 0.21.1 to 0.21.4.
- [Release notes](https://github.com/axios/axios/releases)
- [Changelog](https://github.com/axios/axios/blob/master/CHANGELOG.md)
- [Commits](https://github.com/axios/axios/compare/v0.21.1...v0.21.4)

---
updated-dependencies:
- dependency-name: axios
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

* Fix bad pair strings!

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: qntm <qntm@users.noreply.github.com>
2021-09-12 13:53:48 +01:00
7 changed files with 45 additions and 12 deletions

10
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "base65536",
"version": "4.0.1",
"version": "4.0.2",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -2197,12 +2197,12 @@
"dev": true
},
"axios": {
"version": "0.21.1",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz",
"integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==",
"version": "0.21.4",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz",
"integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==",
"dev": true,
"requires": {
"follow-redirects": "^1.10.0"
"follow-redirects": "^1.14.0"
}
},
"babel-jest": {

View File

@ -1,6 +1,6 @@
{
"name": "base65536",
"version": "4.0.1",
"version": "4.0.2",
"description": "Unicode's answer to Base64",
"homepage": "https://github.com/qntm/base65536",
"repository": {

View File

@ -50,11 +50,27 @@ const getAllSafeRanges = rangeSize => {
const allSafeRanges = getAllSafeRanges(1 << 8)
const paddingBlockStart = String.fromCodePoint(allSafeRanges.shift())
const paddingRange = allSafeRanges.shift()
const paddingBlockStart = String.fromCodePoint(paddingRange)
const blockStarts = allSafeRanges.slice(0, 1 << 8).map(x => String.fromCodePoint(x)).join('')
export { safeCodePoint, paddingBlockStart, blockStarts }
const combinedRanges = allSafeRanges.slice(0, 1 << 8).map(start => [start, start + (1 << 8) - 1])
let i = 0
while (i in combinedRanges) {
if (i + 1 in combinedRanges && combinedRanges[i][1] + 1 === combinedRanges[i + 1][0]) {
combinedRanges.splice(i, 2, [combinedRanges[i][0], combinedRanges[i + 1][1]])
} else {
i++
}
}
const pairStrings = [
combinedRanges.map(([start, end]) => String.fromCodePoint(start) + String.fromCodePoint(end)).join(''),
String.fromCodePoint(paddingRange) + String.fromCodePoint(paddingRange + (1 << 8) - 1)
]
export { safeCodePoint, paddingBlockStart, blockStarts, pairStrings }
// There are now implementations of
// Base65536 in numerous programming languages beyond the original JavaScript,

View File

@ -1,6 +1,6 @@
/* eslint-env jest */
import { paddingBlockStart, blockStarts, safeCodePoint } from './gen'
import { paddingBlockStart, blockStarts, safeCodePoint, pairStrings } from './gen'
describe('gen', () => {
it('generates the correct padding block', () => {
@ -47,4 +47,11 @@ describe('gen', () => {
}
})
})
it('generates the right pair strings', () => {
expect(pairStrings).toEqual([
'㐀䳿一黿ꄀꏿꔀꗿ𐘀𐛿𒀀𒋿𓀀𓏿𔐀𔗿𖠀𖧿𠀀𨗿',
'ᔀᗿ'
])
})
})

View File

@ -6,6 +6,8 @@
<script type="module">
import { encode, decode } from '../src/index.js'
const encoded = encode(new TextEncoder('utf-8').encode('what the heck is up'))
const uint8Array = new Uint8Array([119, 104, 97, 116, 32, 116, 104, 101, 32, 104, 101, 99, 107, 32, 105, 115, 32, 117, 112])
console.log(encode(uint8Array))
const decoded = new TextDecoder('utf-8').decode(decode(encoded))
document.querySelector('.root').appendChild(document.createTextNode(decoded))
</script>

View File

@ -15,7 +15,7 @@ const BITS_PER_BYTE = 8
// Compressed representation of inclusive-exclusive ranges of characters used in this encoding.
const pairStrings = [
'㐀䳿一黿ꄀꏿꔀꗿ𐘀<EFBFBD>𒀀<EFBFBD>𓀀<EFBFBD>𔐀<EFBFBD>𖠀<EFBFBD>𠀀<EFBFBD>',
'㐀䳿一黿ꄀꏿꔀꗿ𐘀𐛿𒀀𒋿𓀀𓏿𔐀𔗿𖠀𖧿𠀀𨗿',
'ᔀᗿ'
]
@ -34,7 +34,6 @@ pairStrings.forEach((pairString, r) => {
// SPECIAL CASE: flip the bytes around, because Base65536 was constructed to take the bytes
// in the wrong order originally
const z = numZBits === BITS_PER_CHAR ? 256 * (z2 % 256) + (z2 >> 8) : z2
lookupE[numZBits][z] = chr
lookupD[chr] = [numZBits, z]
z2++

View File

@ -31,7 +31,7 @@ describe('base65536', () => {
})
})
describe.only('failure cases', () => {
describe('failure cases', () => {
const badFileNames = glob.sync('./node_modules/base65536-test/data/bad/**/*.txt')
badFileNames.forEach(fileName => {
@ -73,4 +73,13 @@ describe('base65536', () => {
const ascii2 = String.fromCharCode(...uint8Array2)
expect(ascii2).toBe('some ASCII text')
})
it('bug', () => {
const ascii = 'what the heck is up'
const uint8Array = Uint8Array.from(ascii, chr => chr.charCodeAt(0))
const str = encode(uint8Array)
const uint8Array2 = decode(str)
const ascii2 = String.fromCharCode(...uint8Array2)
expect(ascii2).toBe('what the heck is up')
})
})