Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

graphemesplit

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphemesplit - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

77

generate.js
const fs = require('fs')
const https = require('https')
const stream = require('stream')
const es = require('event-stream')
const linesStream = require('@orisano/lines-stream')
const UnicodeTrieBuilder = require('unicode-trie/builder')

@@ -10,12 +11,21 @@

function parseLine() {
return es.through(function write(line) {
const body = line.split('#')[0]
if (body.trim().length === 0) return;
const [rawRange, type] = body.split(';').map(x => x.trim())
const range = rawRange.split('..').map(x => parseInt(x, 16))
if (range.length > 1) {
this.emit('data', {start: range[0], end: range[1], type})
} else {
this.emit('data', {start: range[0], end: range[0], type})
}
return new stream.Transform({
decodeStrings: false,
readableObjectMode: true,
transform(line, encoding, callback) {
const body = line.split('#')[0]
if (body.trim().length === 0) {
callback()
return
}
const [rawRange, type] = body.split(';').map(x => x.trim())
const range = rawRange.split('..').map(x => parseInt(x, 16))
if (range.length > 1) {
this.push({start: range[0], end: range[1], type})
} else {
this.push({start: range[0], end: range[0], type})
}
callback()
},
})

@@ -34,12 +44,13 @@ }

res
.pipe(es.split())
.pipe(parseLine())
.on('data', ({start, end, type}) => {
trie.setRange(start, end, types[type])
})
.on('end', () => {
fs.writeFileSync('./typeTrie.json', JSON.stringify({
data: trie.toBuffer().toString('base64'),
}))
})
.setEncoding('utf8')
.pipe(linesStream())
.pipe(parseLine())
.on('data', ({start, end, type}) => {
trie.setRange(start, end, types[type])
})
.on('end', () => {
fs.writeFileSync('./typeTrie.json', JSON.stringify({
data: trie.toBuffer().toString('base64'),
}))
})
})

@@ -54,14 +65,16 @@

}
const trie = new UnicodeTrieBuilder()
res
.pipe(es.split())
.pipe(parseLine())
.on('data', ({start, end, type}) => {
if (type === 'Extended_Pictographic') trie.setRange(start, end, types.Extended_Pictographic)
})
.on('end', () => {
fs.writeFileSync('./extPict.json', JSON.stringify({
data: trie.toBuffer().toString('base64'),
}))
})
})
.setEncoding('utf8')
.pipe(linesStream())
.pipe(parseLine())
.on('data', ({start, end, type}) => {
if (type === 'Extended_Pictographic') trie.setRange(start, end, types.Extended_Pictographic)
})
.on('end', () => {
fs.writeFileSync('./extPict.json', JSON.stringify({
data: trie.toBuffer().toString('base64'),
}))
})
})
{
"name": "graphemesplit",
"version": "2.0.0",
"version": "2.0.1",
"main": "index.js",

@@ -9,3 +9,3 @@ "author": "Nao YONASHIRO",

"devDependencies": {
"event-stream": "^3.3.4"
"@orisano/lines-stream": "^0.1.2"
},

@@ -12,0 +12,0 @@ "dependencies": {

# graphemesplit
A JavaScript implementation of the Unicode 10.0 grapheme cluster breaking algorithm. ([UAX #29](http://www.unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries))
A JavaScript implementation of the Unicode 11.0 grapheme cluster breaking algorithm. ([UAX #29](http://www.unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries))

@@ -25,1 +25,3 @@ ## Installation

[GraphemeBreakTest.txt](https://www.unicode.org/Public/UNIDATA/auxiliary/GraphemeBreakTest.txt)
[emoji-data.txt](https://unicode.org/Public/emoji/11.0/emoji-data.txt)
const assert = require('assert')
const https = require('https')
const stream = require('stream')
const es = require('event-stream')
const linesStream = require('@orisano/lines-stream')

@@ -16,4 +17,10 @@ const graphemesplit = require('./')

res
.pipe(es.split())
.pipe(es.through(function write(line) {
.pipe(linesStream())
.pipe(new stream.Transform({
decodeStrings: false,
readableObjectMode: true,
transform(line, encoding, callback) {
callback()
if (line.trim().length === 0) return

@@ -24,15 +31,16 @@ const [body, description] = line.split('#')

const graphemeClusters = test
.split('÷')
.filter(x => x.length > 0)
.map(x => {
const codePoints = x.split('×')
.map(y => parseInt(y.trim(), 16))
return String.fromCodePoint(...codePoints)
})
this.emit('data', {expected: graphemeClusters, description})
}))
.on('data', ({expected, description}) => {
const got = graphemesplit(expected.join(''))
assert.deepStrictEqual(got, expected, `unexpected grapheme clusters. expected: ${expected}, but got: ${got} # ${description}`)
})
})
.split('÷')
.filter(x => x.length > 0)
.map(x => {
const codePoints = x.split('×')
.map(y => parseInt(y.trim(), 16))
return String.fromCodePoint(...codePoints)
})
this.push({expected: graphemeClusters, description})
}
}))
.on('data', ({expected, description}) => {
const got = graphemesplit(expected.join(''))
assert.deepStrictEqual(got, expected, `unexpected grapheme clusters. expected: ${expected}, but got: ${got} # ${description}`)
})
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc