1
0
mirror of https://github.com/qntm/base65536 synced 2025-12-24 05:34:42 +01:00

Compare commits

..

No commits in common. "b041f53463f4704bf1a6380c6ea9a32a5fb5d05b" and "3b9d85e1a61f63a075447bc9745bb0f78fa8eec5" have entirely different histories.

4 changed files with 7267 additions and 17 deletions

7251
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -11,11 +11,11 @@
"main": "src/index.js", "main": "src/index.js",
"types": "typings/index.d.ts", "types": "typings/index.d.ts",
"scripts": { "scripts": {
"unit": "c8 --100 mocha", "mocha": "c8 --100 mocha",
"standard": "standard", "standard": "standard",
"tag": "node -e \"require('child_process').spawn('git', ['tag', `v${require('./package.json').version}`], { stdio: 'inherit' })\"", "tag": "node -e \"require('child_process').spawn('git', ['tag', `v${require('./package.json').version}`], { stdio: 'inherit' })\"",
"tag-and-publish": "npm run tag && git push --tags && npm publish && npm version patch --no-git-tag-version && git add . && git commit -m \"Bump patch\" && git push", "tag-and-publish": "npm run tag && git push --tags && npm publish && npm version patch --no-git-tag-version && git add . && git commit -m \"Bump patch\" && git push",
"test": "npm run standard && npm run unit" "test": "npm run standard && npm run mocha"
}, },
"keywords": [ "keywords": [
"base64", "base64",

View File

@ -1,14 +1,14 @@
import assert from 'node:assert/strict' import assert from 'node:assert'
import { describe, it } from 'mocha' import { describe, it } from 'mocha'
import { paddingBlockStart, blockStarts, safeCodePoint, pairStrings } from '../scripts/gen.js' import { paddingBlockStart, blockStarts, safeCodePoint, pairStrings } from '../scripts/gen.js'
describe('gen', () => { describe('gen', () => {
it('generates the correct padding block', () => { it('generates the correct padding block', () => {
assert.equal(paddingBlockStart, 'ᔀ') assert.strictEqual(paddingBlockStart, 'ᔀ')
}) })
it('generates the correct blocks', () => { it('generates the correct blocks', () => {
assert.equal(blockStarts, assert.strictEqual(blockStarts,
'㐀㔀㘀㜀㠀㤀㨀㬀㰀㴀㸀㼀䀀䄀䈀䌀' + '㐀㔀㘀㜀㠀㤀㨀㬀㰀㴀㸀㼀䀀䄀䈀䌀' +
'䐀䔀䘀䜀䠀䤀䨀䬀䰀一伀倀儀刀匀吀' + '䐀䔀䘀䜀䠀䤀䨀䬀䰀一伀倀儀刀匀吀' +
'唀嘀圀堀夀娀嬀尀崀帀开怀愀戀挀搀' + '唀嘀圀堀夀娀嬀尀崀帀开怀愀戀挀搀' +
@ -43,13 +43,13 @@ describe('gen', () => {
neutralBlockStart <= codePoint && neutralBlockStart <= codePoint &&
codePoint < neutralBlockStart + (1 << 8) codePoint < neutralBlockStart + (1 << 8)
) )
assert.equal(safeCodePoint.eastAsianWidth(codePoint), isInNeutralBlock ? 'N' : 'W') assert.strictEqual(safeCodePoint.eastAsianWidth(codePoint), isInNeutralBlock ? 'N' : 'W')
} }
}) })
}) })
it('generates the right pair strings', () => { it('generates the right pair strings', () => {
assert.deepEqual(pairStrings, [ assert.deepStrictEqual(pairStrings, [
'㐀䳿一黿ꄀꏿꔀꗿ𐘀𐛿𒀀𒋿𓀀𓏿𔐀𔗿𖠀𖧿𠀀𨗿', '㐀䳿一黿ꄀꏿꔀꗿ𐘀𐛿𒀀𒋿𓀀𓏿𔐀𔗿𖠀𖧿𠀀𨗿',
'ᔀᗿ' 'ᔀᗿ'
]) ])

View File

@ -1,5 +1,4 @@
import assert from 'node:assert/strict' import assert from 'node:assert'
import fs from 'node:fs' import fs from 'node:fs'
import { describe, it } from 'mocha' import { describe, it } from 'mocha'
import { globSync } from 'glob' import { globSync } from 'glob'
@ -16,10 +15,10 @@ describe('base65536', () => {
it(caseName, () => { it(caseName, () => {
const uint8Array = new Uint8Array(fs.readFileSync(caseName + '.bin')) const uint8Array = new Uint8Array(fs.readFileSync(caseName + '.bin'))
const text = fs.readFileSync(caseName + '.txt', 'utf8') const text = fs.readFileSync(caseName + '.txt', 'utf8')
assert.equal(encode(uint8Array), text) assert.strictEqual(encode(uint8Array), text)
assert.deepEqual(decode(text), uint8Array) assert.deepStrictEqual(decode(text), uint8Array)
forms.forEach(form => { forms.forEach(form => {
assert.equal(text.normalize(form), text) assert.strictEqual(text.normalize(form), text)
}) })
}) })
}) })
@ -53,7 +52,7 @@ describe('base65536', () => {
uint8Array[i] = fillUint8 uint8Array[i] = fillUint8
} }
assert.deepEqual(uint8Array, decode(encode(uint8Array))) assert.deepStrictEqual(uint8Array, decode(encode(uint8Array)))
}) })
}) })
} }
@ -65,7 +64,7 @@ describe('base65536', () => {
const str = encode(uint8Array) const str = encode(uint8Array)
const uint8Array2 = decode(str) const uint8Array2 = decode(str)
const ascii2 = String.fromCharCode(...uint8Array2) const ascii2 = String.fromCharCode(...uint8Array2)
assert.equal(ascii2, 'some ASCII text') assert.strictEqual(ascii2, 'some ASCII text')
}) })
it('bug', () => { it('bug', () => {
@ -74,11 +73,11 @@ describe('base65536', () => {
const str = encode(uint8Array) const str = encode(uint8Array)
const uint8Array2 = decode(str) const uint8Array2 = decode(str)
const ascii2 = String.fromCharCode(...uint8Array2) const ascii2 = String.fromCharCode(...uint8Array2)
assert.equal(ascii2, 'what the heck is up') assert.strictEqual(ascii2, 'what the heck is up')
}) })
it('round trip to demonstrate padding behaviour', () => { it('round trip to demonstrate padding behaviour', () => {
assert.deepEqual(encode(Uint8Array.from([0x00, 0x01, 0x02])), '㔀ᔂ') assert.deepStrictEqual(encode(Uint8Array.from([0x00, 0x01, 0x02])), '㔀ᔂ')
assert.deepEqual(decode('㔀ᔂ'), Uint8Array.from([0x00, 0x01, 0x02])) assert.deepStrictEqual(decode('㔀ᔂ'), Uint8Array.from([0x00, 0x01, 0x02]))
}) })
}) })