Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ entirely since some characters like the new colored emojis are three bytes
instead of two bytes. Sometimes even more! `"👍🏽".length` returns `4` which is
totally wrong (hint: it should be 1!). ES6's `Array.from` tried to solve this,
but that even fails: `Array.from("👍🏽")` returns `["👍", "🏽"]` which is
incorrect. This library tries to tackle all these problems with a mega RegExp.
[Read More Here](https://mathiasbynens.be/notes/javascript-unicode).
incorrect. This library tries to tackle all these problems with [`Intl.Segmenter`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Segmenter).

## Features

Expand Down
14 changes: 7 additions & 7 deletions benchmark/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ const str = 'Iñtërnâtiônàlizætiøn☃👍🏽💩😊💪🏼😻';

// add tests
suite
.add('Stringz .length (accruate)', function() {
.add('Stringz .length (accurate)', function () {
return Stringz.length(str);
})
.add('Lodash .toArray (accruate)', function() {
.add('Lodash .toArray (accurate)', function () {
return _.toArray(str).length;
})
.add('Emoji Aware .split (inaccurate)', function() {
.add('Emoji Aware .split (inaccurate)', function () {
return EmojiAware.split(str).length;
})
.add('Spliddit .length (inaccurate)', function() {
.add('Spliddit .length (inaccurate)', function () {
return Spliddit(str).length;
})
.add('UTF8 Length (inaccurate)', function() {
.add('UTF8 Length (inaccurate)', function () {
return Bytes(str);
})
// add listeners
.on('cycle', function(event) {
.on('cycle', function (event) {
console.log(String(event.target));
})
.on('complete', function() {
.on('complete', function () {
console.log('Fastest is ' + this.filter('fastest').map('name'));
})
// run async
Expand Down
8 changes: 7 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
module.exports = {
export default {
roots: ['<rootDir>/src'],
transform: {
'^.+\\.tsx?$': 'ts-jest'
},
extensionsToTreatAsEsm: ['.ts', '.tsx'],
globals: {
'ts-jest': {
useESM: true
}
}
};
Loading