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

eastasianwidth

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eastasianwidth - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

34

eastasianwidth.js

@@ -271,6 +271,12 @@ var eaw = {};

// Split a string considering surrogate-pairs.
function stringToArray(string) {
return string.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]|[^\uD800-\uDFFF]/g) || [];
}
eaw.length = function(string) {
var characters = stringToArray(string);
var len = 0;
for (var i = 0; i < string.length; i++) {
len = len + this.characterLength(string.charAt(i));
for (var i = 0; i < characters.length; i++) {
len = len + this.characterLength(characters[i]);
}

@@ -281,13 +287,27 @@ return len;

eaw.slice = function(text, start, end) {
textLen = eaw.length(text)
start = start ? start : 0;
end = end ? end : 1;
if (start < 0) {
start = textLen + start;
}
if (end < 0) {
end = textLen + end;
}
var result = '';
for (var i = 0; i < text.length; i++) {
var char = text.charAt(i);
var eawLen = eaw.length(result + char);
if (eawLen >= 1 + start && eawLen < 1 + end) {
result += char
var eawLen = 0;
var chars = stringToArray(text);
for (var i = 0; i < chars.length; i++) {
var char = chars[i];
var charLen = eaw.length(char);
if (eawLen >= start - (charLen == 2 ? 1 : 0)) {
if (eawLen + charLen <= end) {
result += char;
} else {
break;
}
}
eawLen += charLen;
}
return result;
};
{
"name": "eastasianwidth",
"version": "0.1.1",
"version": "0.2.0",
"description": "Get East Asian Width from a character.",
"main": "eastasianwidth.js",
"files": [
"eastasianwidth.js"
],
"scripts": {

@@ -7,0 +10,0 @@ "test": "mocha"

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