Compare commits

...

2 Commits

Author SHA1 Message Date
qntm 0d936eab75
Delete package-lock.json 2020-09-07 20:04:54 +01:00
dependabot[bot] 9bfe378e16
Bump safe-code-point from 1.0.0 to 2.0.0 (#37)
* Bump safe-code-point from 1.0.0 to 2.0.0

Bumps [safe-code-point](https://github.com/qntm/safe-code-point) from 1.0.0 to 2.0.0.
- [Release notes](https://github.com/qntm/safe-code-point/releases)
- [Commits](https://github.com/qntm/safe-code-point/commits)

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

* Use asinine asynchronous safe-code-point API

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: qntm <qntm@users.noreply.github.com>
2020-09-07 20:04:00 +01:00
3 changed files with 46 additions and 30 deletions

View File

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

View File

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

View File

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