stuff
This commit is contained in:
3
buildfiles/node_modules/truncate-utf8-bytes/.gitmodules
generated
vendored
Normal file
3
buildfiles/node_modules/truncate-utf8-bytes/.gitmodules
generated
vendored
Normal file
@ -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
|
1
buildfiles/node_modules/truncate-utf8-bytes/.npmignore
generated
vendored
Normal file
1
buildfiles/node_modules/truncate-utf8-bytes/.npmignore
generated
vendored
Normal file
@ -0,0 +1 @@
|
||||
vendor/
|
12
buildfiles/node_modules/truncate-utf8-bytes/.travis.yml
generated
vendored
Normal file
12
buildfiles/node_modules/truncate-utf8-bytes/.travis.yml
generated
vendored
Normal file
@ -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
|
2
buildfiles/node_modules/truncate-utf8-bytes/AUTHORS
generated
vendored
Normal file
2
buildfiles/node_modules/truncate-utf8-bytes/AUTHORS
generated
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
Carl Xiong <xiongc05@gmail.com>
|
||||
Parsha Pourkhomami <parshap@gmail.com>
|
27
buildfiles/node_modules/truncate-utf8-bytes/README.md
generated
vendored
Normal file
27
buildfiles/node_modules/truncate-utf8-bytes/README.md
generated
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
# truncate-utf8-bytes [](http://travis-ci.org/parshap/truncate-utf8-bytes)
|
||||
|
||||
Truncate a string to the given length in bytes. Correctly handles
|
||||
multi-byte characters and surrogate pairs.
|
||||
|
||||
A browser implementation that doesn't use `Buffer.byteLength` is
|
||||
provided to minimize build size.
|
||||
|
||||
## Example
|
||||
|
||||
```js
|
||||
var truncate = require("truncate-utf8-bytes")
|
||||
var str = "a☃" // a = 1 byte, ☃ = 3 bytes
|
||||
console.log(truncate(str, 2))
|
||||
// -> "a"
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### `var truncate = require("truncate-utf8-bytes")`
|
||||
|
||||
*When using browserify or webpack*, this automatically resolves to an
|
||||
implementation that does not use `Buffer.byteLength`.
|
||||
|
||||
### `truncate(string, length)`
|
||||
|
||||
Returns `string` truncated to at most `length` bytes in length.
|
5
buildfiles/node_modules/truncate-utf8-bytes/browser.js
generated
vendored
Normal file
5
buildfiles/node_modules/truncate-utf8-bytes/browser.js
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
var truncate = require("./lib/truncate");
|
||||
var getLength = require("utf8-byte-length/browser");
|
||||
module.exports = truncate.bind(null, getLength);
|
5
buildfiles/node_modules/truncate-utf8-bytes/index.js
generated
vendored
Normal file
5
buildfiles/node_modules/truncate-utf8-bytes/index.js
generated
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
'use strict';
|
||||
|
||||
var truncate = require("./lib/truncate");
|
||||
var getLength = Buffer.byteLength.bind(Buffer);
|
||||
module.exports = truncate.bind(null, getLength);
|
43
buildfiles/node_modules/truncate-utf8-bytes/lib/truncate.js
generated
vendored
Normal file
43
buildfiles/node_modules/truncate-utf8-bytes/lib/truncate.js
generated
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
'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 truncate(getLength, string, byteLength) {
|
||||
if (typeof string !== "string") {
|
||||
throw new Error("Input must be string");
|
||||
}
|
||||
|
||||
var charLength = string.length;
|
||||
var curByteLength = 0;
|
||||
var codePoint;
|
||||
var segment;
|
||||
|
||||
for (var i = 0; i < charLength; i += 1) {
|
||||
codePoint = string.charCodeAt(i);
|
||||
segment = string[i];
|
||||
|
||||
if (isHighSurrogate(codePoint) && isLowSurrogate(string.charCodeAt(i + 1))) {
|
||||
i += 1;
|
||||
segment += string[i];
|
||||
}
|
||||
|
||||
curByteLength += getLength(segment);
|
||||
|
||||
if (curByteLength === byteLength) {
|
||||
return string.slice(0, i + 1);
|
||||
}
|
||||
else if (curByteLength > byteLength) {
|
||||
return string.slice(0, i - segment.length + 1);
|
||||
}
|
||||
}
|
||||
|
||||
return string;
|
||||
};
|
||||
|
68
buildfiles/node_modules/truncate-utf8-bytes/package.json
generated
vendored
Normal file
68
buildfiles/node_modules/truncate-utf8-bytes/package.json
generated
vendored
Normal file
@ -0,0 +1,68 @@
|
||||
{
|
||||
"_from": "truncate-utf8-bytes@^1.0.0",
|
||||
"_id": "truncate-utf8-bytes@1.0.2",
|
||||
"_inBundle": false,
|
||||
"_integrity": "sha1-QFkjkJWS1W94pYGENLC3hInKXys=",
|
||||
"_location": "/truncate-utf8-bytes",
|
||||
"_phantomChildren": {},
|
||||
"_requested": {
|
||||
"type": "range",
|
||||
"registry": true,
|
||||
"raw": "truncate-utf8-bytes@^1.0.0",
|
||||
"name": "truncate-utf8-bytes",
|
||||
"escapedName": "truncate-utf8-bytes",
|
||||
"rawSpec": "^1.0.0",
|
||||
"saveSpec": null,
|
||||
"fetchSpec": "^1.0.0"
|
||||
},
|
||||
"_requiredBy": [
|
||||
"/sanitize-filename"
|
||||
],
|
||||
"_resolved": "https://registry.npmjs.org/truncate-utf8-bytes/-/truncate-utf8-bytes-1.0.2.tgz",
|
||||
"_shasum": "405923909592d56f78a5818434b0b78489ca5f2b",
|
||||
"_spec": "truncate-utf8-bytes@^1.0.0",
|
||||
"_where": "/home/shihaam/www/freezer.shihaam.me/node_modules/sanitize-filename",
|
||||
"author": {
|
||||
"name": "Carl Xiong",
|
||||
"email": "xiongc05@gmail.com"
|
||||
},
|
||||
"browser": "browser.js",
|
||||
"bugs": {
|
||||
"url": "https://github.com/parshap/truncate-utf8-bytes/issues"
|
||||
},
|
||||
"bundleDependencies": false,
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Carl Xiong",
|
||||
"email": "xiongc05@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "Parsha Pourkhomami",
|
||||
"email": "parshap@gmail.com"
|
||||
}
|
||||
],
|
||||
"dependencies": {
|
||||
"utf8-byte-length": "^1.0.1"
|
||||
},
|
||||
"deprecated": false,
|
||||
"description": "Truncate string to given length in bytes",
|
||||
"devDependencies": {
|
||||
"tape": "^4.2.2"
|
||||
},
|
||||
"homepage": "https://github.com/parshap/truncate-utf8-bytes#readme",
|
||||
"keywords": [
|
||||
"truncate",
|
||||
"utf8"
|
||||
],
|
||||
"license": "WTFPL",
|
||||
"main": "index.js",
|
||||
"name": "truncate-utf8-bytes",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/parshap/truncate-utf8-bytes.git"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "tape test.js"
|
||||
},
|
||||
"version": "1.0.2"
|
||||
}
|
75
buildfiles/node_modules/truncate-utf8-bytes/test.js
generated
vendored
Normal file
75
buildfiles/node_modules/truncate-utf8-bytes/test.js
generated
vendored
Normal file
@ -0,0 +1,75 @@
|
||||
"use strict";
|
||||
|
||||
var test = require("tape");
|
||||
var truncate = require("./");
|
||||
var browserTruncate = require("./browser");
|
||||
|
||||
function isHighSurrogate(codePoint) {
|
||||
return codePoint >= 0xd800 && codePoint <= 0xdbff;
|
||||
}
|
||||
|
||||
function repeat(string, times) {
|
||||
return new Array(times + 1).join(string);
|
||||
}
|
||||
|
||||
function assertLengths(t, string, charLength, byteLength) {
|
||||
t.equal(string.length, charLength);
|
||||
t.equal(Buffer.byteLength(string), byteLength);
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
// Run tests against both implementations
|
||||
[truncate, browserTruncate].forEach(function(truncate) {
|
||||
test("strings", function(t) {
|
||||
assertLengths(t, truncate("a☃", 2), 1, 1);
|
||||
assertLengths(t, truncate(repeat("a", 250) + '\uD800\uDC00', 255), 252, 254);
|
||||
assertLengths(t, truncate(repeat("a", 251) + '\uD800\uDC00', 255), 253, 255);
|
||||
assertLengths(t, truncate(repeat("a", 252) + '\uD800\uDC00', 255), 252, 252);
|
||||
assertLengths(t, truncate(repeat("a", 253) + '\uD800\uDC00', 255), 253, 253);
|
||||
assertLengths(t, truncate(repeat("a", 254) + '\uD800\uDC00', 255), 254, 254);
|
||||
assertLengths(t, truncate(repeat("a", 255) + '\uD800\uDC00', 255), 255, 255);
|
||||
t.end();
|
||||
});
|
||||
|
||||
// Truncate various strings
|
||||
[].concat(
|
||||
[
|
||||
repeat("a", 300),
|
||||
repeat("a", 252) + '\uD800\uDC00',
|
||||
repeat("a", 251) + '\uD800\uDC00',
|
||||
repeat("a", 253) + '\uD800\uDC00',
|
||||
],
|
||||
blns
|
||||
).forEach(function(str) {
|
||||
test(JSON.stringify(str), function(t) {
|
||||
var i = 0;
|
||||
t.equals(truncate(str, 0), "");
|
||||
// Truncate string one byte at a time
|
||||
while (true) {
|
||||
var truncated = truncate(str, i);
|
||||
t.ok(Buffer.byteLength(truncated) <= i);
|
||||
t.ok( ! isHighSurrogate(truncated[truncated.length - 1]));
|
||||
if (truncated === str) {
|
||||
break;
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
t.end();
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user