diff options
| author | Priyansh <[email protected]> | 2020-12-22 17:49:59 +0530 |
|---|---|---|
| committer | Priyansh <[email protected]> | 2020-12-22 17:49:59 +0530 |
| commit | e93da8b04da86773247aadb1cbb1912e4f4526b2 (patch) | |
| tree | eb4ef3203a92ed3dbd2252ddb1ea23bd2d670c98 /node_modules/utf8-byte-length | |
| parent | a5743c293dcb435e4b159a4df791f8955a4110ec (diff) | |
| download | styx-e93da8b04da86773247aadb1cbb1912e4f4526b2.tar.xz styx-e93da8b04da86773247aadb1cbb1912e4f4526b2.zip | |
Rewriting Project
Diffstat (limited to 'node_modules/utf8-byte-length')
| -rw-r--r-- | node_modules/utf8-byte-length/.gitmodules | 3 | ||||
| -rw-r--r-- | node_modules/utf8-byte-length/.npmignore | 1 | ||||
| -rw-r--r-- | node_modules/utf8-byte-length/.travis.yml | 12 | ||||
| -rw-r--r-- | node_modules/utf8-byte-length/AUTHORS | 2 | ||||
| -rw-r--r-- | node_modules/utf8-byte-length/README.md | 28 | ||||
| -rw-r--r-- | node_modules/utf8-byte-length/browser.js | 47 | ||||
| -rw-r--r-- | node_modules/utf8-byte-length/index.js | 8 | ||||
| -rw-r--r-- | node_modules/utf8-byte-length/package.json | 64 | ||||
| -rw-r--r-- | node_modules/utf8-byte-length/test.js | 67 |
9 files changed, 232 insertions, 0 deletions
diff --git a/node_modules/utf8-byte-length/.gitmodules b/node_modules/utf8-byte-length/.gitmodules new file mode 100644 index 0000000..d496220 --- /dev/null +++ b/node_modules/utf8-byte-length/.gitmodules @@ -0,0 +1,3 @@ +[submodule "vendor/big-list-of-naughty-strings"] + path = vendor/big-list-of-naughty-strings + url = https://github.com/minimaxir/big-list-of-naughty-strings.git diff --git a/node_modules/utf8-byte-length/.npmignore b/node_modules/utf8-byte-length/.npmignore new file mode 100644 index 0000000..48b8bf9 --- /dev/null +++ b/node_modules/utf8-byte-length/.npmignore @@ -0,0 +1 @@ +vendor/ diff --git a/node_modules/utf8-byte-length/.travis.yml b/node_modules/utf8-byte-length/.travis.yml new file mode 100644 index 0000000..1e25a8c --- /dev/null +++ b/node_modules/utf8-byte-length/.travis.yml @@ -0,0 +1,12 @@ +language: node_js +node_js: + - "0.10" + - "0.12" + - "1" + - "2" + - "3" + - "4" + - "5" + - "node" +before_install: + - npm install -g npm diff --git a/node_modules/utf8-byte-length/AUTHORS b/node_modules/utf8-byte-length/AUTHORS new file mode 100644 index 0000000..6212900 --- /dev/null +++ b/node_modules/utf8-byte-length/AUTHORS @@ -0,0 +1,2 @@ +Carl Xiong <[email protected]> +Parsha Pourkhomami <[email protected]> diff --git a/node_modules/utf8-byte-length/README.md b/node_modules/utf8-byte-length/README.md new file mode 100644 index 0000000..a232c12 --- /dev/null +++ b/node_modules/utf8-byte-length/README.md @@ -0,0 +1,28 @@ +# utf8-byte-length [](http://travis-ci.org/parshap/utf8-byte-length) + +Get the utf8 byte length of a string, taking into account multi-byte +characters and surrogate pairs. + +By default, this module defers to `Buffer.byteLength`. A browser +implementation is also provided that doesn't use `Buffer.byteLength` +minimize build size. + +## Example + +```js +var getLength = require("utf8-byte-length") +console.log(truncate("a☃", 2)) // a = 1 byte, ☃ = 3 bytes +// -> 4 +``` + +## API + +### `var getLength = require("utf8-byte-length")` + +*When using browserify or webpack*, this automatically resolves to an +implementation that does not use `Buffer.byteLength`. + +### `getLength(string)` + +Returns the byte length of `string`. Throws an error if `string` is not +a string. diff --git a/node_modules/utf8-byte-length/browser.js b/node_modules/utf8-byte-length/browser.js new file mode 100644 index 0000000..a093731 --- /dev/null +++ b/node_modules/utf8-byte-length/browser.js @@ -0,0 +1,47 @@ +'use strict'; + +function isHighSurrogate(codePoint) { + return codePoint >= 0xd800 && codePoint <= 0xdbff; +} + +function isLowSurrogate(codePoint) { + return codePoint >= 0xdc00 && codePoint <= 0xdfff; +} + +// Truncate string by size in bytes +module.exports = function getByteLength(string) { + if (typeof string !== "string") { + throw new Error("Input must be string"); + } + + var charLength = string.length; + var byteLength = 0; + var codePoint = null; + var prevCodePoint = null; + for (var i = 0; i < charLength; i++) { + codePoint = string.charCodeAt(i); + // handle 4-byte non-BMP chars + // low surrogate + if (isLowSurrogate(codePoint)) { + // when parsing previous hi-surrogate, 3 is added to byteLength + if (prevCodePoint != null && isHighSurrogate(prevCodePoint)) { + byteLength += 1; + } + else { + byteLength += 3; + } + } + else if (codePoint <= 0x7f ) { + byteLength += 1; + } + else if (codePoint >= 0x80 && codePoint <= 0x7ff) { + byteLength += 2; + } + else if (codePoint >= 0x800 && codePoint <= 0xffff) { + byteLength += 3; + } + prevCodePoint = codePoint; + } + + return byteLength; +}; diff --git a/node_modules/utf8-byte-length/index.js b/node_modules/utf8-byte-length/index.js new file mode 100644 index 0000000..921ea6a --- /dev/null +++ b/node_modules/utf8-byte-length/index.js @@ -0,0 +1,8 @@ +"use strict"; + +module.exports = function getByteLength(string) { + if (typeof string !== "string") { + throw new Error("Input must be string"); + } + return Buffer.byteLength(string, "utf8"); +}; diff --git a/node_modules/utf8-byte-length/package.json b/node_modules/utf8-byte-length/package.json new file mode 100644 index 0000000..9d7c019 --- /dev/null +++ b/node_modules/utf8-byte-length/package.json @@ -0,0 +1,64 @@ +{ + "_from": "utf8-byte-length@^1.0.1", + "_id": "[email protected]", + "_inBundle": false, + "_integrity": "sha1-9F8VDExm7uloGGUFq5P8u4rWv2E=", + "_location": "/utf8-byte-length", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "utf8-byte-length@^1.0.1", + "name": "utf8-byte-length", + "escapedName": "utf8-byte-length", + "rawSpec": "^1.0.1", + "saveSpec": null, + "fetchSpec": "^1.0.1" + }, + "_requiredBy": [ + "/truncate-utf8-bytes" + ], + "_resolved": "https://registry.npmjs.org/utf8-byte-length/-/utf8-byte-length-1.0.4.tgz", + "_shasum": "f45f150c4c66eee968186505ab93fcbb8ad6bf61", + "_spec": "utf8-byte-length@^1.0.1", + "_where": "/Users/lucifer/Documents/styx/node_modules/truncate-utf8-bytes", + "author": { + "name": "Carl Xiong", + "email": "[email protected]" + }, + "browser": "browser.js", + "bugs": { + "url": "https://github.com/parshap/utf8-byte-length/issues" + }, + "bundleDependencies": false, + "contributors": [ + { + "name": "Carl Xiong", + "email": "[email protected]" + }, + { + "name": "Parsha Pourkhomami", + "email": "[email protected]" + } + ], + "deprecated": false, + "description": "Get utf8 byte length of string", + "devDependencies": { + "tape": "^4.2.2" + }, + "homepage": "https://github.com/parshap/utf8-byte-length#readme", + "keywords": [ + "utf8" + ], + "license": "WTFPL", + "main": "index.js", + "name": "utf8-byte-length", + "repository": { + "type": "git", + "url": "git+https://github.com/parshap/utf8-byte-length.git" + }, + "scripts": { + "test": "tape test.js" + }, + "version": "1.0.4" +} diff --git a/node_modules/utf8-byte-length/test.js b/node_modules/utf8-byte-length/test.js new file mode 100644 index 0000000..4f3cdbc --- /dev/null +++ b/node_modules/utf8-byte-length/test.js @@ -0,0 +1,67 @@ +"use strict"; + +var test = require("tape"); +var getLength = require("./index"); +var browserGetLength = require("./browser"); + +function repeat(string, times) { + return new Array(times + 1).join(string); +} + +// Test writing files to the fs +// + +try { + var blns = require("./vendor/big-list-of-naughty-strings/blns.json"); +} +catch (err) { + console.error("Error: Cannot load file './vendor/big-list-of-naughty-strings/blns.json'"); + console.error(); + console.error("Make sure you've initialized git submodules by running"); + console.error(); + console.error(" git submodule update --init"); + console.error(); + process.exit(1); +} + + +// 8-byte, 4-character string +var THUMB = "👍🏽"; + +// Tests run against both implementations +[getLength, browserGetLength].forEach(function(getLength) { + // Strings with known lengths + [ + ["", 0], + ["a", 1], + ["☃", 3], + ["a☃", 4], + [repeat("a", 250) + '\uD800\uDC00', 254], + [repeat("a", 251) + '\uD800\uDC00', 255], + [repeat("a", 252) + '\uD800\uDC00', 256], + [THUMB, 8], + [THUMB[0], 3], + [THUMB[1], 3], + [THUMB[2], 3], + [THUMB[3], 3], + [THUMB.slice(0, 2), 4], + [THUMB.slice(2, 4), 4], + [THUMB.slice(1, 3), 6], + ].forEach(function(desc) { + var string = desc[0]; + var length = desc[1]; + test(JSON.stringify(string) + "=" + length, function(t) { + t.equal(getLength(string), length); + t.end(); + }); + }); + + // Make sure result matches Buffer.byteLength for various strings + blns.forEach(function(str) { + test(JSON.stringify(str), function(t) { + t.equal(getLength(str), Buffer.byteLength(str)); + t.end(); + }); + }); +}); + |
