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

Compare commits

..

No commits in common. "9cfc7812d57fe973f93a296a9a642e82895e5e19" and "4add117c1359abcaeac8d514c7b9162b7f008547" have entirely different histories.

7 changed files with 12 additions and 45 deletions

10
package-lock.json generated
View File

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

View File

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

View File

@ -50,27 +50,11 @@ const getAllSafeRanges = rangeSize => {
const allSafeRanges = getAllSafeRanges(1 << 8)
const paddingRange = allSafeRanges.shift()
const paddingBlockStart = String.fromCodePoint(paddingRange)
const paddingBlockStart = String.fromCodePoint(allSafeRanges.shift())
const blockStarts = allSafeRanges.slice(0, 1 << 8).map(x => String.fromCodePoint(x)).join('')
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 }
export { safeCodePoint, paddingBlockStart, blockStarts }
// 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, pairStrings } from './gen'
import { paddingBlockStart, blockStarts, safeCodePoint } from './gen'
describe('gen', () => {
it('generates the correct padding block', () => {
@ -47,11 +47,4 @@ describe('gen', () => {
}
})
})
it('generates the right pair strings', () => {
expect(pairStrings).toEqual([
'㐀䳿一黿ꄀꏿꔀꗿ𐘀𐛿𒀀𒋿𓀀𓏿𔐀𔗿𖠀𖧿𠀀𨗿',
'ᔀᗿ'
])
})
})

View File

@ -6,8 +6,6 @@
<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,6 +34,7 @@ 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('failure cases', () => {
describe.only('failure cases', () => {
const badFileNames = glob.sync('./node_modules/base65536-test/data/bad/**/*.txt')
badFileNames.forEach(fileName => {
@ -73,13 +73,4 @@ 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')
})
})