Compare commits

..

No commits in common. "0d936eab753485d2036a1eda521a5376f562fe42" and "e375e2dcaeb0c85e98f068d178c5f10375fa4288" have entirely different histories.

3 changed files with 30 additions and 46 deletions

View File

@ -40,7 +40,7 @@
"glob": "^7.1.6", "glob": "^7.1.6",
"jest": "^26.4.0", "jest": "^26.4.0",
"rollup": "^2.26.3", "rollup": "^2.26.3",
"safe-code-point": "^2.0.0", "safe-code-point": "^1.0.0",
"standard": "^14.3.3", "standard": "^14.3.3",
"start-server-and-test": "^1.11.3" "start-server-and-test": "^1.11.3"
}, },

View File

@ -18,26 +18,24 @@
// transplanted into `base65536` for use. It is kept here for historical reasons // transplanted into `base65536` for use. It is kept here for historical reasons
// and to ensure reproducibility. // and to ensure reproducibility.
import SafeCodePoint from 'safe-code-point' import safeCodePoint, { generalCategory } from 'safe-code-point'
// Well these ergonomics are dreadful huh const safeRange = (min, max) => {
export default () => SafeCodePoint('8.0.0').then(safeCodePoint => {
const safeRange = (min, max) => {
for (let codePoint = min; codePoint < max; codePoint++) { for (let codePoint = min; codePoint < max; codePoint++) {
// Code points were chosen entirely from the "Letter, other" general // Code points were chosen entirely from the "Letter, other" general
// category, for reasons which I no longer recall. Unicode 8.0 was current // category, for reasons which I no longer recall. Unicode 8.0 was current
// at the time. // at the time.
if ( if (
safeCodePoint.generalCategory(codePoint) !== 'Lo' || generalCategory(codePoint, '8.0') !== 'Lo' ||
!safeCodePoint(codePoint) !safeCodePoint(codePoint, '8.0')
) { ) {
return false return false
} }
} }
return true return true
} }
const getAllSafeRanges = rangeSize => { const getAllSafeRanges = rangeSize => {
const allSafeRanges = [] const allSafeRanges = []
for (let codePoint = 0; codePoint < (1 << 16) + (1 << 20); codePoint += rangeSize) { for (let codePoint = 0; codePoint < (1 << 16) + (1 << 20); codePoint += rangeSize) {
if (safeRange(codePoint, codePoint + rangeSize)) { if (safeRange(codePoint, codePoint + rangeSize)) {
@ -45,20 +43,13 @@ export default () => SafeCodePoint('8.0.0').then(safeCodePoint => {
} }
} }
return allSafeRanges return allSafeRanges
} }
const allSafeRanges = getAllSafeRanges(1 << 8) const allSafeRanges = getAllSafeRanges(1 << 8)
const paddingBlockStart = String.fromCodePoint(allSafeRanges.shift()) export const paddingBlockStart = String.fromCodePoint(allSafeRanges.shift())
const blockStarts = allSafeRanges.slice(0, 1 << 8).map(x => String.fromCodePoint(x)).join('') export const blockStarts = allSafeRanges.slice(0, 1 << 8).map(x => String.fromCodePoint(x)).join('')
return {
safeCodePoint,
paddingBlockStart,
blockStarts
}
})
// There are now implementations of // There are now implementations of
// Base65536 in numerous programming languages beyond the original JavaScript, // Base65536 in numerous programming languages beyond the original JavaScript,

View File

@ -1,22 +1,15 @@
/* eslint-env jest */ /* eslint-env jest */
import gen from './gen' import { eastAsianWidth } from 'safe-code-point'
import { paddingBlockStart, blockStarts } from './gen'
describe('gen', () => { describe('gen', () => {
let generated
beforeAll(() =>
gen().then(g => {
generated = g
})
)
it('generates the correct padding block', () => { it('generates the correct padding block', () => {
expect(generated.paddingBlockStart).toBe('ᔀ') expect(paddingBlockStart).toBe('ᔀ')
}) })
it('generates the correct blocks', () => { it('generates the correct blocks', () => {
expect(generated.blockStarts).toBe( expect(blockStarts).toBe(
'㐀㔀㘀㜀㠀㤀㨀㬀㰀㴀㸀㼀䀀䄀䈀䌀' + '㐀㔀㘀㜀㠀㤀㨀㬀㰀㴀㸀㼀䀀䄀䈀䌀' +
'䐀䔀䘀䜀䠀䤀䨀䬀䰀一伀倀儀刀匀吀' + '䐀䔀䘀䜀䠀䤀䨀䬀䰀一伀倀儀刀匀吀' +
'唀嘀圀堀夀娀嬀尀崀帀开怀愀戀挀搀' + '唀嘀圀堀夀娀嬀尀崀帀开怀愀戀挀搀' +
@ -41,7 +34,7 @@ describe('gen', () => {
// 243 of the blocks are 'W' (wide), the other 13 + 1 are 'N' (neutral, // 243 of the blocks are 'W' (wide), the other 13 + 1 are 'N' (neutral,
// which in effect is narrow). This is significant when considering // which in effect is narrow). This is significant when considering
// rendering and wrapping. // rendering and wrapping.
const allBlockStarts = [...generated.blockStarts].map(x => x.codePointAt(0)) const allBlockStarts = [...blockStarts].map(x => x.codePointAt(0))
const neutralBlockStarts = [...'ᔀꔀ𐘀𒀀𒄀𒈀𓀀𓄀𓈀𓌀𔐀𔔀𖠀𖤀'].map(x => x.codePointAt(0)) const neutralBlockStarts = [...'ᔀꔀ𐘀𒀀𒄀𒈀𓀀𓄀𓈀𓌀𔐀𔔀𖠀𖤀'].map(x => x.codePointAt(0))
allBlockStarts.forEach(blockStart => { allBlockStarts.forEach(blockStart => {
for (let i = 0; i < 1 << 8; i++) { for (let i = 0; i < 1 << 8; i++) {
@ -51,7 +44,7 @@ describe('gen', () => {
neutralBlockStart <= codePoint && neutralBlockStart <= codePoint &&
codePoint < neutralBlockStart + (1 << 8) codePoint < neutralBlockStart + (1 << 8)
) )
expect(generated.safeCodePoint.eastAsianWidth(codePoint)).toBe(isInNeutralBlock ? 'N' : 'W') expect(eastAsianWidth(codePoint, '8.0')).toBe(isInNeutralBlock ? 'N' : 'W')
} }
}) })
}) })