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", "glob": "^7.1.6",
"jest": "^26.4.0", "jest": "^26.4.0",
"rollup": "^2.26.3", "rollup": "^2.26.3",
"safe-code-point": "^1.0.0", "safe-code-point": "^2.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,24 +18,26 @@
// 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, { generalCategory } from 'safe-code-point' import SafeCodePoint from 'safe-code-point'
const safeRange = (min, max) => { // 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++) { 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 (
generalCategory(codePoint, '8.0') !== 'Lo' || safeCodePoint.generalCategory(codePoint) !== 'Lo' ||
!safeCodePoint(codePoint, '8.0') !safeCodePoint(codePoint)
) { ) {
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)) {
@ -43,13 +45,20 @@ const getAllSafeRanges = rangeSize => {
} }
} }
return allSafeRanges return allSafeRanges
} }
const allSafeRanges = getAllSafeRanges(1 << 8) 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 // 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,15 +1,22 @@
/* eslint-env jest */ /* eslint-env jest */
import { eastAsianWidth } from 'safe-code-point' import gen from './gen'
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(paddingBlockStart).toBe('ᔀ') expect(generated.paddingBlockStart).toBe('ᔀ')
}) })
it('generates the correct blocks', () => { 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, // 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 = [...blockStarts].map(x => x.codePointAt(0)) const allBlockStarts = [...generated.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++) {
@ -44,7 +51,7 @@ describe('gen', () => {
neutralBlockStart <= codePoint && neutralBlockStart <= codePoint &&
codePoint < neutralBlockStart + (1 << 8) codePoint < neutralBlockStart + (1 << 8)
) )
expect(eastAsianWidth(codePoint, '8.0')).toBe(isInNeutralBlock ? 'N' : 'W') expect(generated.safeCodePoint.eastAsianWidth(codePoint)).toBe(isInNeutralBlock ? 'N' : 'W')
} }
}) })
}) })