代码上传
This commit is contained in:
parent
a4dc343d8b
commit
e30fd49b0b
|
@ -0,0 +1,32 @@
|
||||||
|
基于`bgwd666`的[deploy](https://github.com/bgwd666/deploy)发布脚本做了一些适合我自己的修改,在此万分感谢.
|
||||||
|
|
||||||
|
### 使用方法:
|
||||||
|
|
||||||
|
1. 拉取代码
|
||||||
|
```
|
||||||
|
|
||||||
|
npx degit https://github.com/KeiferJu/auto-deploy.git deploy
|
||||||
|
|
||||||
|
cd deploy
|
||||||
|
|
||||||
|
npm install
|
||||||
|
```
|
||||||
|
|
||||||
|
2. 配置使用
|
||||||
|
|
||||||
|
在项目package.json中配置命令:
|
||||||
|
```
|
||||||
|
...
|
||||||
|
|
||||||
|
"scripts": {
|
||||||
|
...
|
||||||
|
"deploy": "node ./deploy/upload.js"
|
||||||
|
},
|
||||||
|
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
然后在`deploy/config.js`里面配置上自己服务器信息,执行命令就可以部署了:
|
||||||
|
```
|
||||||
|
npm run deploy
|
||||||
|
```
|
|
@ -2,6 +2,8 @@ module.exports = Object.freeze({
|
||||||
development: {//测试
|
development: {//测试
|
||||||
SERVER_PATH: '172.17.60.20', // ssh地址 服务器地址
|
SERVER_PATH: '172.17.60.20', // ssh地址 服务器地址
|
||||||
SSH_USER: 'root', // ssh 用户名
|
SSH_USER: 'root', // ssh 用户名
|
||||||
|
//方式一 用秘钥登录服务器(推荐), private 本机私钥文件地址(需要在服务器用户目录 一般是 /root/.ssh/authorized_keys 配置公钥 并该文件权限为 600, (.ssh文件夹一般默认隐藏)
|
||||||
|
// PRIVATE_KEY: 'C:/Users/Html5/.ssh/id_rsa',
|
||||||
PASSWORD: '123456', //方式二 用密码连接服务器
|
PASSWORD: '123456', //方式二 用密码连接服务器
|
||||||
PATH: '/var/local', // 需要上传的服务器目录地址 如 /usr/local/nginx/html
|
PATH: '/var/local', // 需要上传的服务器目录地址 如 /usr/local/nginx/html
|
||||||
OUTPUT_PATH: 'docs/__sapper__/export/smx-svelma' // 需要上传文件夹路径,默认dist
|
OUTPUT_PATH: 'docs/__sapper__/export/smx-svelma' // 需要上传文件夹路径,默认dist
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
../mkdirp/bin/cmd.js
|
|
@ -0,0 +1 @@
|
||||||
|
../shelljs/bin/shjs
|
|
@ -0,0 +1,21 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE
|
|
@ -0,0 +1,16 @@
|
||||||
|
# Installation
|
||||||
|
> `npm install --save @types/color-name`
|
||||||
|
|
||||||
|
# Summary
|
||||||
|
This package contains type definitions for color-name ( https://github.com/colorjs/color-name ).
|
||||||
|
|
||||||
|
# Details
|
||||||
|
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/color-name
|
||||||
|
|
||||||
|
Additional Details
|
||||||
|
* Last updated: Wed, 13 Feb 2019 16:16:48 GMT
|
||||||
|
* Dependencies: none
|
||||||
|
* Global values: none
|
||||||
|
|
||||||
|
# Credits
|
||||||
|
These definitions were written by Junyoung Clare Jang <https://github.com/Ailrun>.
|
|
@ -0,0 +1,161 @@
|
||||||
|
// Type definitions for color-name 1.1
|
||||||
|
// Project: https://github.com/colorjs/color-name
|
||||||
|
// Definitions by: Junyoung Clare Jang <https://github.com/Ailrun>
|
||||||
|
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tuple of Red, Green, and Blue
|
||||||
|
* @example
|
||||||
|
* // Red = 55, Green = 70, Blue = 0
|
||||||
|
* const rgb: RGB = [55, 70, 0];
|
||||||
|
*/
|
||||||
|
export type RGB = [number, number, number];
|
||||||
|
|
||||||
|
export const aliceblue: RGB;
|
||||||
|
export const antiquewhite: RGB;
|
||||||
|
export const aqua: RGB;
|
||||||
|
export const aquamarine: RGB;
|
||||||
|
export const azure: RGB;
|
||||||
|
export const beige: RGB;
|
||||||
|
export const bisque: RGB;
|
||||||
|
export const black: RGB;
|
||||||
|
export const blanchedalmond: RGB;
|
||||||
|
export const blue: RGB;
|
||||||
|
export const blueviolet: RGB;
|
||||||
|
export const brown: RGB;
|
||||||
|
export const burlywood: RGB;
|
||||||
|
export const cadetblue: RGB;
|
||||||
|
export const chartreuse: RGB;
|
||||||
|
export const chocolate: RGB;
|
||||||
|
export const coral: RGB;
|
||||||
|
export const cornflowerblue: RGB;
|
||||||
|
export const cornsilk: RGB;
|
||||||
|
export const crimson: RGB;
|
||||||
|
export const cyan: RGB;
|
||||||
|
export const darkblue: RGB;
|
||||||
|
export const darkcyan: RGB;
|
||||||
|
export const darkgoldenrod: RGB;
|
||||||
|
export const darkgray: RGB;
|
||||||
|
export const darkgreen: RGB;
|
||||||
|
export const darkgrey: RGB;
|
||||||
|
export const darkkhaki: RGB;
|
||||||
|
export const darkmagenta: RGB;
|
||||||
|
export const darkolivegreen: RGB;
|
||||||
|
export const darkorange: RGB;
|
||||||
|
export const darkorchid: RGB;
|
||||||
|
export const darkred: RGB;
|
||||||
|
export const darksalmon: RGB;
|
||||||
|
export const darkseagreen: RGB;
|
||||||
|
export const darkslateblue: RGB;
|
||||||
|
export const darkslategray: RGB;
|
||||||
|
export const darkslategrey: RGB;
|
||||||
|
export const darkturquoise: RGB;
|
||||||
|
export const darkviolet: RGB;
|
||||||
|
export const deeppink: RGB;
|
||||||
|
export const deepskyblue: RGB;
|
||||||
|
export const dimgray: RGB;
|
||||||
|
export const dimgrey: RGB;
|
||||||
|
export const dodgerblue: RGB;
|
||||||
|
export const firebrick: RGB;
|
||||||
|
export const floralwhite: RGB;
|
||||||
|
export const forestgreen: RGB;
|
||||||
|
export const fuchsia: RGB;
|
||||||
|
export const gainsboro: RGB;
|
||||||
|
export const ghostwhite: RGB;
|
||||||
|
export const gold: RGB;
|
||||||
|
export const goldenrod: RGB;
|
||||||
|
export const gray: RGB;
|
||||||
|
export const green: RGB;
|
||||||
|
export const greenyellow: RGB;
|
||||||
|
export const grey: RGB;
|
||||||
|
export const honeydew: RGB;
|
||||||
|
export const hotpink: RGB;
|
||||||
|
export const indianred: RGB;
|
||||||
|
export const indigo: RGB;
|
||||||
|
export const ivory: RGB;
|
||||||
|
export const khaki: RGB;
|
||||||
|
export const lavender: RGB;
|
||||||
|
export const lavenderblush: RGB;
|
||||||
|
export const lawngreen: RGB;
|
||||||
|
export const lemonchiffon: RGB;
|
||||||
|
export const lightblue: RGB;
|
||||||
|
export const lightcoral: RGB;
|
||||||
|
export const lightcyan: RGB;
|
||||||
|
export const lightgoldenrodyellow: RGB;
|
||||||
|
export const lightgray: RGB;
|
||||||
|
export const lightgreen: RGB;
|
||||||
|
export const lightgrey: RGB;
|
||||||
|
export const lightpink: RGB;
|
||||||
|
export const lightsalmon: RGB;
|
||||||
|
export const lightseagreen: RGB;
|
||||||
|
export const lightskyblue: RGB;
|
||||||
|
export const lightslategray: RGB;
|
||||||
|
export const lightslategrey: RGB;
|
||||||
|
export const lightsteelblue: RGB;
|
||||||
|
export const lightyellow: RGB;
|
||||||
|
export const lime: RGB;
|
||||||
|
export const limegreen: RGB;
|
||||||
|
export const linen: RGB;
|
||||||
|
export const magenta: RGB;
|
||||||
|
export const maroon: RGB;
|
||||||
|
export const mediumaquamarine: RGB;
|
||||||
|
export const mediumblue: RGB;
|
||||||
|
export const mediumorchid: RGB;
|
||||||
|
export const mediumpurple: RGB;
|
||||||
|
export const mediumseagreen: RGB;
|
||||||
|
export const mediumslateblue: RGB;
|
||||||
|
export const mediumspringgreen: RGB;
|
||||||
|
export const mediumturquoise: RGB;
|
||||||
|
export const mediumvioletred: RGB;
|
||||||
|
export const midnightblue: RGB;
|
||||||
|
export const mintcream: RGB;
|
||||||
|
export const mistyrose: RGB;
|
||||||
|
export const moccasin: RGB;
|
||||||
|
export const navajowhite: RGB;
|
||||||
|
export const navy: RGB;
|
||||||
|
export const oldlace: RGB;
|
||||||
|
export const olive: RGB;
|
||||||
|
export const olivedrab: RGB;
|
||||||
|
export const orange: RGB;
|
||||||
|
export const orangered: RGB;
|
||||||
|
export const orchid: RGB;
|
||||||
|
export const palegoldenrod: RGB;
|
||||||
|
export const palegreen: RGB;
|
||||||
|
export const paleturquoise: RGB;
|
||||||
|
export const palevioletred: RGB;
|
||||||
|
export const papayawhip: RGB;
|
||||||
|
export const peachpuff: RGB;
|
||||||
|
export const peru: RGB;
|
||||||
|
export const pink: RGB;
|
||||||
|
export const plum: RGB;
|
||||||
|
export const powderblue: RGB;
|
||||||
|
export const purple: RGB;
|
||||||
|
export const rebeccapurple: RGB;
|
||||||
|
export const red: RGB;
|
||||||
|
export const rosybrown: RGB;
|
||||||
|
export const royalblue: RGB;
|
||||||
|
export const saddlebrown: RGB;
|
||||||
|
export const salmon: RGB;
|
||||||
|
export const sandybrown: RGB;
|
||||||
|
export const seagreen: RGB;
|
||||||
|
export const seashell: RGB;
|
||||||
|
export const sienna: RGB;
|
||||||
|
export const silver: RGB;
|
||||||
|
export const skyblue: RGB;
|
||||||
|
export const slateblue: RGB;
|
||||||
|
export const slategray: RGB;
|
||||||
|
export const slategrey: RGB;
|
||||||
|
export const snow: RGB;
|
||||||
|
export const springgreen: RGB;
|
||||||
|
export const steelblue: RGB;
|
||||||
|
export const tan: RGB;
|
||||||
|
export const teal: RGB;
|
||||||
|
export const thistle: RGB;
|
||||||
|
export const tomato: RGB;
|
||||||
|
export const turquoise: RGB;
|
||||||
|
export const violet: RGB;
|
||||||
|
export const wheat: RGB;
|
||||||
|
export const white: RGB;
|
||||||
|
export const whitesmoke: RGB;
|
||||||
|
export const yellow: RGB;
|
||||||
|
export const yellowgreen: RGB;
|
|
@ -0,0 +1,52 @@
|
||||||
|
{
|
||||||
|
"_from": "@types/color-name@^1.1.1",
|
||||||
|
"_id": "@types/color-name@1.1.1",
|
||||||
|
"_inBundle": false,
|
||||||
|
"_integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==",
|
||||||
|
"_location": "/@types/color-name",
|
||||||
|
"_phantomChildren": {},
|
||||||
|
"_requested": {
|
||||||
|
"type": "range",
|
||||||
|
"registry": true,
|
||||||
|
"raw": "@types/color-name@^1.1.1",
|
||||||
|
"name": "@types/color-name",
|
||||||
|
"escapedName": "@types%2fcolor-name",
|
||||||
|
"scope": "@types",
|
||||||
|
"rawSpec": "^1.1.1",
|
||||||
|
"saveSpec": null,
|
||||||
|
"fetchSpec": "^1.1.1"
|
||||||
|
},
|
||||||
|
"_requiredBy": [
|
||||||
|
"/ansi-styles"
|
||||||
|
],
|
||||||
|
"_resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz",
|
||||||
|
"_shasum": "1c1261bbeaa10a8055bbc5d8ab84b7b2afc846a0",
|
||||||
|
"_spec": "@types/color-name@^1.1.1",
|
||||||
|
"_where": "/Users/keiferju/code/Lingtu/smx-svelma/upload/node_modules/ansi-styles",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/DefinitelyTyped/DefinitelyTyped/issues"
|
||||||
|
},
|
||||||
|
"bundleDependencies": false,
|
||||||
|
"contributors": [
|
||||||
|
{
|
||||||
|
"name": "Junyoung Clare Jang",
|
||||||
|
"url": "https://github.com/Ailrun"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"dependencies": {},
|
||||||
|
"deprecated": false,
|
||||||
|
"description": "TypeScript definitions for color-name",
|
||||||
|
"homepage": "https://github.com/DefinitelyTyped/DefinitelyTyped#readme",
|
||||||
|
"license": "MIT",
|
||||||
|
"main": "",
|
||||||
|
"name": "@types/color-name",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/DefinitelyTyped/DefinitelyTyped.git"
|
||||||
|
},
|
||||||
|
"scripts": {},
|
||||||
|
"typeScriptVersion": "2.0",
|
||||||
|
"types": "index",
|
||||||
|
"typesPublisherContentHash": "e22c6881e2dcf766e32142cbb82d9acf9c08258bdf0da8e76c8a448d1be44ac7",
|
||||||
|
"version": "1.1.1"
|
||||||
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
/**
|
||||||
|
Create an error from multiple errors.
|
||||||
|
*/
|
||||||
|
declare class AggregateError extends Error implements Iterable<Error> {
|
||||||
|
readonly name: 'AggregateError';
|
||||||
|
|
||||||
|
/**
|
||||||
|
@param errors - If a string, a new `Error` is created with the string as the error message. If a non-Error object, a new `Error` is created with all properties from the object copied over.
|
||||||
|
@returns An Error that is also an [`Iterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators#Iterables) for the individual errors.
|
||||||
|
|
||||||
|
@example
|
||||||
|
```
|
||||||
|
import AggregateError = require('aggregate-error');
|
||||||
|
|
||||||
|
const error = new AggregateError([new Error('foo'), 'bar', {message: 'baz'}]);
|
||||||
|
|
||||||
|
throw error;
|
||||||
|
|
||||||
|
// AggregateError:
|
||||||
|
// Error: foo
|
||||||
|
// at Object.<anonymous> (/Users/sindresorhus/dev/aggregate-error/example.js:3:33)
|
||||||
|
// Error: bar
|
||||||
|
// at Object.<anonymous> (/Users/sindresorhus/dev/aggregate-error/example.js:3:13)
|
||||||
|
// Error: baz
|
||||||
|
// at Object.<anonymous> (/Users/sindresorhus/dev/aggregate-error/example.js:3:13)
|
||||||
|
// at AggregateError (/Users/sindresorhus/dev/aggregate-error/index.js:19:3)
|
||||||
|
// at Object.<anonymous> (/Users/sindresorhus/dev/aggregate-error/example.js:3:13)
|
||||||
|
// at Module._compile (module.js:556:32)
|
||||||
|
// at Object.Module._extensions..js (module.js:565:10)
|
||||||
|
// at Module.load (module.js:473:32)
|
||||||
|
// at tryModuleLoad (module.js:432:12)
|
||||||
|
// at Function.Module._load (module.js:424:3)
|
||||||
|
// at Module.runMain (module.js:590:10)
|
||||||
|
// at run (bootstrap_node.js:394:7)
|
||||||
|
// at startup (bootstrap_node.js:149:9)
|
||||||
|
|
||||||
|
|
||||||
|
for (const individualError of error) {
|
||||||
|
console.log(individualError);
|
||||||
|
}
|
||||||
|
//=> [Error: foo]
|
||||||
|
//=> [Error: bar]
|
||||||
|
//=> [Error: baz]
|
||||||
|
```
|
||||||
|
*/
|
||||||
|
constructor(errors: ReadonlyArray<Error | {[key: string]: any} | string>);
|
||||||
|
|
||||||
|
[Symbol.iterator](): IterableIterator<Error>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export = AggregateError;
|
|
@ -0,0 +1,47 @@
|
||||||
|
'use strict';
|
||||||
|
const indentString = require('indent-string');
|
||||||
|
const cleanStack = require('clean-stack');
|
||||||
|
|
||||||
|
const cleanInternalStack = stack => stack.replace(/\s+at .*aggregate-error\/index.js:\d+:\d+\)?/g, '');
|
||||||
|
|
||||||
|
class AggregateError extends Error {
|
||||||
|
constructor(errors) {
|
||||||
|
if (!Array.isArray(errors)) {
|
||||||
|
throw new TypeError(`Expected input to be an Array, got ${typeof errors}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
errors = [...errors].map(error => {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error !== null && typeof error === 'object') {
|
||||||
|
// Handle plain error objects with message property and/or possibly other metadata
|
||||||
|
return Object.assign(new Error(error.message), error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Error(error);
|
||||||
|
});
|
||||||
|
|
||||||
|
let message = errors
|
||||||
|
.map(error => {
|
||||||
|
// The `stack` property is not standardized, so we can't assume it exists
|
||||||
|
return typeof error.stack === 'string' ? cleanInternalStack(cleanStack(error.stack)) : String(error);
|
||||||
|
})
|
||||||
|
.join('\n');
|
||||||
|
message = '\n' + indentString(message, 4);
|
||||||
|
super(message);
|
||||||
|
|
||||||
|
this.name = 'AggregateError';
|
||||||
|
|
||||||
|
Object.defineProperty(this, '_errors', {value: errors});
|
||||||
|
}
|
||||||
|
|
||||||
|
* [Symbol.iterator]() {
|
||||||
|
for (const error of this._errors) {
|
||||||
|
yield error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = AggregateError;
|
|
@ -0,0 +1,9 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -0,0 +1,73 @@
|
||||||
|
{
|
||||||
|
"_from": "aggregate-error@^3.0.0",
|
||||||
|
"_id": "aggregate-error@3.0.1",
|
||||||
|
"_inBundle": false,
|
||||||
|
"_integrity": "sha512-quoaXsZ9/BLNae5yiNoUz+Nhkwz83GhWwtYFglcjEQB2NDHCIpApbqXxIFnm4Pq/Nvhrsq5sYJFyohrrxnTGAA==",
|
||||||
|
"_location": "/aggregate-error",
|
||||||
|
"_phantomChildren": {},
|
||||||
|
"_requested": {
|
||||||
|
"type": "range",
|
||||||
|
"registry": true,
|
||||||
|
"raw": "aggregate-error@^3.0.0",
|
||||||
|
"name": "aggregate-error",
|
||||||
|
"escapedName": "aggregate-error",
|
||||||
|
"rawSpec": "^3.0.0",
|
||||||
|
"saveSpec": null,
|
||||||
|
"fetchSpec": "^3.0.0"
|
||||||
|
},
|
||||||
|
"_requiredBy": [
|
||||||
|
"/p-map"
|
||||||
|
],
|
||||||
|
"_resolved": "https://registry.npmjs.org/aggregate-error/-/aggregate-error-3.0.1.tgz",
|
||||||
|
"_shasum": "db2fe7246e536f40d9b5442a39e117d7dd6a24e0",
|
||||||
|
"_spec": "aggregate-error@^3.0.0",
|
||||||
|
"_where": "/Users/keiferju/code/Lingtu/smx-svelma/upload/node_modules/p-map",
|
||||||
|
"author": {
|
||||||
|
"name": "Sindre Sorhus",
|
||||||
|
"email": "sindresorhus@gmail.com",
|
||||||
|
"url": "sindresorhus.com"
|
||||||
|
},
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/sindresorhus/aggregate-error/issues"
|
||||||
|
},
|
||||||
|
"bundleDependencies": false,
|
||||||
|
"dependencies": {
|
||||||
|
"clean-stack": "^2.0.0",
|
||||||
|
"indent-string": "^4.0.0"
|
||||||
|
},
|
||||||
|
"deprecated": false,
|
||||||
|
"description": "Create an error from multiple errors",
|
||||||
|
"devDependencies": {
|
||||||
|
"ava": "^2.4.0",
|
||||||
|
"tsd": "^0.7.1",
|
||||||
|
"xo": "^0.25.3"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"index.js",
|
||||||
|
"index.d.ts"
|
||||||
|
],
|
||||||
|
"homepage": "https://github.com/sindresorhus/aggregate-error#readme",
|
||||||
|
"keywords": [
|
||||||
|
"aggregate",
|
||||||
|
"error",
|
||||||
|
"combine",
|
||||||
|
"multiple",
|
||||||
|
"many",
|
||||||
|
"collection",
|
||||||
|
"iterable",
|
||||||
|
"iterator"
|
||||||
|
],
|
||||||
|
"license": "MIT",
|
||||||
|
"name": "aggregate-error",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/sindresorhus/aggregate-error.git"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "xo && ava && tsd"
|
||||||
|
},
|
||||||
|
"version": "3.0.1"
|
||||||
|
}
|
|
@ -0,0 +1,61 @@
|
||||||
|
# aggregate-error [](https://travis-ci.org/sindresorhus/aggregate-error)
|
||||||
|
|
||||||
|
> Create an error from multiple errors
|
||||||
|
|
||||||
|
|
||||||
|
## Install
|
||||||
|
|
||||||
|
```
|
||||||
|
$ npm install aggregate-error
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```js
|
||||||
|
const AggregateError = require('aggregate-error');
|
||||||
|
|
||||||
|
const error = new AggregateError([new Error('foo'), 'bar', {message: 'baz'}]);
|
||||||
|
|
||||||
|
throw error;
|
||||||
|
/*
|
||||||
|
AggregateError:
|
||||||
|
Error: foo
|
||||||
|
at Object.<anonymous> (/Users/sindresorhus/dev/aggregate-error/example.js:3:33)
|
||||||
|
Error: bar
|
||||||
|
at Object.<anonymous> (/Users/sindresorhus/dev/aggregate-error/example.js:3:13)
|
||||||
|
Error: baz
|
||||||
|
at Object.<anonymous> (/Users/sindresorhus/dev/aggregate-error/example.js:3:13)
|
||||||
|
at AggregateError (/Users/sindresorhus/dev/aggregate-error/index.js:19:3)
|
||||||
|
at Object.<anonymous> (/Users/sindresorhus/dev/aggregate-error/example.js:3:13)
|
||||||
|
at Module._compile (module.js:556:32)
|
||||||
|
at Object.Module._extensions..js (module.js:565:10)
|
||||||
|
at Module.load (module.js:473:32)
|
||||||
|
at tryModuleLoad (module.js:432:12)
|
||||||
|
at Function.Module._load (module.js:424:3)
|
||||||
|
at Module.runMain (module.js:590:10)
|
||||||
|
at run (bootstrap_node.js:394:7)
|
||||||
|
at startup (bootstrap_node.js:149:9)
|
||||||
|
*/
|
||||||
|
|
||||||
|
for (const individualError of error) {
|
||||||
|
console.log(individualError);
|
||||||
|
}
|
||||||
|
//=> [Error: foo]
|
||||||
|
//=> [Error: bar]
|
||||||
|
//=> [Error: baz]
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
|
### AggregateError(errors)
|
||||||
|
|
||||||
|
Returns an `Error` that is also an [`Iterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators#Iterables) for the individual errors.
|
||||||
|
|
||||||
|
#### errors
|
||||||
|
|
||||||
|
Type: `Array<Error|Object|string>`
|
||||||
|
|
||||||
|
If a string, a new `Error` is created with the string as the error message.<br>
|
||||||
|
If a non-Error object, a new `Error` is created with all properties from the object copied over.
|
|
@ -0,0 +1,248 @@
|
||||||
|
/// <reference types="node"/>
|
||||||
|
import {LiteralUnion} from 'type-fest';
|
||||||
|
|
||||||
|
declare namespace ansiEscapes {
|
||||||
|
interface ImageOptions {
|
||||||
|
/**
|
||||||
|
The width is given as a number followed by a unit, or the word `'auto'`.
|
||||||
|
|
||||||
|
- `N`: N character cells.
|
||||||
|
- `Npx`: N pixels.
|
||||||
|
- `N%`: N percent of the session's width or height.
|
||||||
|
- `auto`: The image's inherent size will be used to determine an appropriate dimension.
|
||||||
|
*/
|
||||||
|
readonly width?: LiteralUnion<'auto', number | string>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
The height is given as a number followed by a unit, or the word `'auto'`.
|
||||||
|
|
||||||
|
- `N`: N character cells.
|
||||||
|
- `Npx`: N pixels.
|
||||||
|
- `N%`: N percent of the session's width or height.
|
||||||
|
- `auto`: The image's inherent size will be used to determine an appropriate dimension.
|
||||||
|
*/
|
||||||
|
readonly height?: LiteralUnion<'auto', number | string>;
|
||||||
|
|
||||||
|
readonly preserveAspectRatio?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface AnnotationOptions {
|
||||||
|
/**
|
||||||
|
Nonzero number of columns to annotate.
|
||||||
|
|
||||||
|
Default: The remainder of the line.
|
||||||
|
*/
|
||||||
|
readonly length?: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Starting X coordinate.
|
||||||
|
|
||||||
|
Must be used with `y` and `length`.
|
||||||
|
|
||||||
|
Default: The cursor position
|
||||||
|
*/
|
||||||
|
readonly x?: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Starting Y coordinate.
|
||||||
|
|
||||||
|
Must be used with `x` and `length`.
|
||||||
|
|
||||||
|
Default: Cursor position.
|
||||||
|
*/
|
||||||
|
readonly y?: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Create a "hidden" annotation.
|
||||||
|
|
||||||
|
Annotations created this way can be shown using the "Show Annotations" iTerm command.
|
||||||
|
*/
|
||||||
|
readonly isHidden?: boolean;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare const ansiEscapes: {
|
||||||
|
/**
|
||||||
|
Set the absolute position of the cursor. `x0` `y0` is the top left of the screen.
|
||||||
|
*/
|
||||||
|
cursorTo(x: number, y?: number): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Set the position of the cursor relative to its current position.
|
||||||
|
*/
|
||||||
|
cursorMove(x: number, y?: number): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Move cursor up a specific amount of rows.
|
||||||
|
|
||||||
|
@param count - Count of rows to move up. Default is `1`.
|
||||||
|
*/
|
||||||
|
cursorUp(count?: number): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Move cursor down a specific amount of rows.
|
||||||
|
|
||||||
|
@param count - Count of rows to move down. Default is `1`.
|
||||||
|
*/
|
||||||
|
cursorDown(count?: number): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Move cursor forward a specific amount of rows.
|
||||||
|
|
||||||
|
@param count - Count of rows to move forward. Default is `1`.
|
||||||
|
*/
|
||||||
|
cursorForward(count?: number): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Move cursor backward a specific amount of rows.
|
||||||
|
|
||||||
|
@param count - Count of rows to move backward. Default is `1`.
|
||||||
|
*/
|
||||||
|
cursorBackward(count?: number): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Move cursor to the left side.
|
||||||
|
*/
|
||||||
|
cursorLeft: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Save cursor position.
|
||||||
|
*/
|
||||||
|
cursorSavePosition: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Restore saved cursor position.
|
||||||
|
*/
|
||||||
|
cursorRestorePosition: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Get cursor position.
|
||||||
|
*/
|
||||||
|
cursorGetPosition: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Move cursor to the next line.
|
||||||
|
*/
|
||||||
|
cursorNextLine: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Move cursor to the previous line.
|
||||||
|
*/
|
||||||
|
cursorPrevLine: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Hide cursor.
|
||||||
|
*/
|
||||||
|
cursorHide: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Show cursor.
|
||||||
|
*/
|
||||||
|
cursorShow: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Erase from the current cursor position up the specified amount of rows.
|
||||||
|
|
||||||
|
@param count - Count of rows to erase.
|
||||||
|
*/
|
||||||
|
eraseLines(count: number): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Erase from the current cursor position to the end of the current line.
|
||||||
|
*/
|
||||||
|
eraseEndLine: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Erase from the current cursor position to the start of the current line.
|
||||||
|
*/
|
||||||
|
eraseStartLine: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Erase the entire current line.
|
||||||
|
*/
|
||||||
|
eraseLine: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Erase the screen from the current line down to the bottom of the screen.
|
||||||
|
*/
|
||||||
|
eraseDown: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Erase the screen from the current line up to the top of the screen.
|
||||||
|
*/
|
||||||
|
eraseUp: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Erase the screen and move the cursor the top left position.
|
||||||
|
*/
|
||||||
|
eraseScreen: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Scroll display up one line.
|
||||||
|
*/
|
||||||
|
scrollUp: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Scroll display down one line.
|
||||||
|
*/
|
||||||
|
scrollDown: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Clear the terminal screen. (Viewport)
|
||||||
|
*/
|
||||||
|
clearScreen: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Clear the whole terminal, including scrollback buffer. (Not just the visible part of it)
|
||||||
|
*/
|
||||||
|
clearTerminal: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Output a beeping sound.
|
||||||
|
*/
|
||||||
|
beep: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Create a clickable link.
|
||||||
|
|
||||||
|
[Supported terminals.](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda) Use [`supports-hyperlinks`](https://github.com/jamestalmage/supports-hyperlinks) to detect link support.
|
||||||
|
*/
|
||||||
|
link(text: string, url: string): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Display an image.
|
||||||
|
|
||||||
|
_Currently only supported on iTerm2 >=3_
|
||||||
|
|
||||||
|
See [term-img](https://github.com/sindresorhus/term-img) for a higher-level module.
|
||||||
|
|
||||||
|
@param buffer - Buffer of an image. Usually read in with `fs.readFile()`.
|
||||||
|
*/
|
||||||
|
image(buffer: Buffer, options?: ansiEscapes.ImageOptions): string;
|
||||||
|
|
||||||
|
iTerm: {
|
||||||
|
/**
|
||||||
|
[Inform iTerm2](https://www.iterm2.com/documentation-escape-codes.html) of the current directory to help semantic history and enable [Cmd-clicking relative paths](https://coderwall.com/p/b7e82q/quickly-open-files-in-iterm-with-cmd-click).
|
||||||
|
|
||||||
|
@param cwd - Current directory. Default: `process.cwd()`.
|
||||||
|
*/
|
||||||
|
setCwd(cwd?: string): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
An annotation looks like this when shown:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
See the [iTerm Proprietary Escape Codes documentation](https://iterm2.com/documentation-escape-codes.html) for more information.
|
||||||
|
|
||||||
|
@param message - The message to display within the annotation. The `|` character is disallowed and will be stripped.
|
||||||
|
@returns An escape code which will create an annotation when printed in iTerm2.
|
||||||
|
*/
|
||||||
|
annotation(message: string, options?: ansiEscapes.AnnotationOptions): string;
|
||||||
|
};
|
||||||
|
|
||||||
|
// TODO: remove this in the next major version
|
||||||
|
default: typeof ansiEscapes;
|
||||||
|
};
|
||||||
|
|
||||||
|
export = ansiEscapes;
|
|
@ -0,0 +1,157 @@
|
||||||
|
'use strict';
|
||||||
|
const ansiEscapes = module.exports;
|
||||||
|
// TODO: remove this in the next major version
|
||||||
|
module.exports.default = ansiEscapes;
|
||||||
|
|
||||||
|
const ESC = '\u001B[';
|
||||||
|
const OSC = '\u001B]';
|
||||||
|
const BEL = '\u0007';
|
||||||
|
const SEP = ';';
|
||||||
|
const isTerminalApp = process.env.TERM_PROGRAM === 'Apple_Terminal';
|
||||||
|
|
||||||
|
ansiEscapes.cursorTo = (x, y) => {
|
||||||
|
if (typeof x !== 'number') {
|
||||||
|
throw new TypeError('The `x` argument is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof y !== 'number') {
|
||||||
|
return ESC + (x + 1) + 'G';
|
||||||
|
}
|
||||||
|
|
||||||
|
return ESC + (y + 1) + ';' + (x + 1) + 'H';
|
||||||
|
};
|
||||||
|
|
||||||
|
ansiEscapes.cursorMove = (x, y) => {
|
||||||
|
if (typeof x !== 'number') {
|
||||||
|
throw new TypeError('The `x` argument is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
let ret = '';
|
||||||
|
|
||||||
|
if (x < 0) {
|
||||||
|
ret += ESC + (-x) + 'D';
|
||||||
|
} else if (x > 0) {
|
||||||
|
ret += ESC + x + 'C';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (y < 0) {
|
||||||
|
ret += ESC + (-y) + 'A';
|
||||||
|
} else if (y > 0) {
|
||||||
|
ret += ESC + y + 'B';
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
};
|
||||||
|
|
||||||
|
ansiEscapes.cursorUp = (count = 1) => ESC + count + 'A';
|
||||||
|
ansiEscapes.cursorDown = (count = 1) => ESC + count + 'B';
|
||||||
|
ansiEscapes.cursorForward = (count = 1) => ESC + count + 'C';
|
||||||
|
ansiEscapes.cursorBackward = (count = 1) => ESC + count + 'D';
|
||||||
|
|
||||||
|
ansiEscapes.cursorLeft = ESC + 'G';
|
||||||
|
ansiEscapes.cursorSavePosition = isTerminalApp ? '\u001B7' : ESC + 's';
|
||||||
|
ansiEscapes.cursorRestorePosition = isTerminalApp ? '\u001B8' : ESC + 'u';
|
||||||
|
ansiEscapes.cursorGetPosition = ESC + '6n';
|
||||||
|
ansiEscapes.cursorNextLine = ESC + 'E';
|
||||||
|
ansiEscapes.cursorPrevLine = ESC + 'F';
|
||||||
|
ansiEscapes.cursorHide = ESC + '?25l';
|
||||||
|
ansiEscapes.cursorShow = ESC + '?25h';
|
||||||
|
|
||||||
|
ansiEscapes.eraseLines = count => {
|
||||||
|
let clear = '';
|
||||||
|
|
||||||
|
for (let i = 0; i < count; i++) {
|
||||||
|
clear += ansiEscapes.eraseLine + (i < count - 1 ? ansiEscapes.cursorUp() : '');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (count) {
|
||||||
|
clear += ansiEscapes.cursorLeft;
|
||||||
|
}
|
||||||
|
|
||||||
|
return clear;
|
||||||
|
};
|
||||||
|
|
||||||
|
ansiEscapes.eraseEndLine = ESC + 'K';
|
||||||
|
ansiEscapes.eraseStartLine = ESC + '1K';
|
||||||
|
ansiEscapes.eraseLine = ESC + '2K';
|
||||||
|
ansiEscapes.eraseDown = ESC + 'J';
|
||||||
|
ansiEscapes.eraseUp = ESC + '1J';
|
||||||
|
ansiEscapes.eraseScreen = ESC + '2J';
|
||||||
|
ansiEscapes.scrollUp = ESC + 'S';
|
||||||
|
ansiEscapes.scrollDown = ESC + 'T';
|
||||||
|
|
||||||
|
ansiEscapes.clearScreen = '\u001Bc';
|
||||||
|
|
||||||
|
ansiEscapes.clearTerminal = process.platform === 'win32' ?
|
||||||
|
`${ansiEscapes.eraseScreen}${ESC}0f` :
|
||||||
|
// 1. Erases the screen (Only done in case `2` is not supported)
|
||||||
|
// 2. Erases the whole screen including scrollback buffer
|
||||||
|
// 3. Moves cursor to the top-left position
|
||||||
|
// More info: https://www.real-world-systems.com/docs/ANSIcode.html
|
||||||
|
`${ansiEscapes.eraseScreen}${ESC}3J${ESC}H`;
|
||||||
|
|
||||||
|
ansiEscapes.beep = BEL;
|
||||||
|
|
||||||
|
ansiEscapes.link = (text, url) => {
|
||||||
|
return [
|
||||||
|
OSC,
|
||||||
|
'8',
|
||||||
|
SEP,
|
||||||
|
SEP,
|
||||||
|
url,
|
||||||
|
BEL,
|
||||||
|
text,
|
||||||
|
OSC,
|
||||||
|
'8',
|
||||||
|
SEP,
|
||||||
|
SEP,
|
||||||
|
BEL
|
||||||
|
].join('');
|
||||||
|
};
|
||||||
|
|
||||||
|
ansiEscapes.image = (buffer, options = {}) => {
|
||||||
|
let ret = `${OSC}1337;File=inline=1`;
|
||||||
|
|
||||||
|
if (options.width) {
|
||||||
|
ret += `;width=${options.width}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.height) {
|
||||||
|
ret += `;height=${options.height}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (options.preserveAspectRatio === false) {
|
||||||
|
ret += ';preserveAspectRatio=0';
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret + ':' + buffer.toString('base64') + BEL;
|
||||||
|
};
|
||||||
|
|
||||||
|
ansiEscapes.iTerm = {
|
||||||
|
setCwd: (cwd = process.cwd()) => `${OSC}50;CurrentDir=${cwd}${BEL}`,
|
||||||
|
|
||||||
|
annotation: (message, options = {}) => {
|
||||||
|
let ret = `${OSC}1337;`;
|
||||||
|
|
||||||
|
const hasX = typeof options.x !== 'undefined';
|
||||||
|
const hasY = typeof options.y !== 'undefined';
|
||||||
|
if ((hasX || hasY) && !(hasX && hasY && typeof options.length !== 'undefined')) {
|
||||||
|
throw new Error('`x`, `y` and `length` must be defined when `x` or `y` is defined');
|
||||||
|
}
|
||||||
|
|
||||||
|
message = message.replace(/\|/g, '');
|
||||||
|
|
||||||
|
ret += options.isHidden ? 'AddHiddenAnnotation=' : 'AddAnnotation=';
|
||||||
|
|
||||||
|
if (options.length > 0) {
|
||||||
|
ret +=
|
||||||
|
(hasX ?
|
||||||
|
[message, options.length, options.x, options.y] :
|
||||||
|
[options.length, message]).join('|');
|
||||||
|
} else {
|
||||||
|
ret += message;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret + BEL;
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,9 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -0,0 +1,89 @@
|
||||||
|
{
|
||||||
|
"_from": "ansi-escapes@^4.2.1",
|
||||||
|
"_id": "ansi-escapes@4.3.1",
|
||||||
|
"_inBundle": false,
|
||||||
|
"_integrity": "sha512-JWF7ocqNrp8u9oqpgV+wH5ftbt+cfvv+PTjOvKLT3AdYly/LmORARfEVT1iyjwN+4MqE5UmVKoAdIBqeoCHgLA==",
|
||||||
|
"_location": "/ansi-escapes",
|
||||||
|
"_phantomChildren": {},
|
||||||
|
"_requested": {
|
||||||
|
"type": "range",
|
||||||
|
"registry": true,
|
||||||
|
"raw": "ansi-escapes@^4.2.1",
|
||||||
|
"name": "ansi-escapes",
|
||||||
|
"escapedName": "ansi-escapes",
|
||||||
|
"rawSpec": "^4.2.1",
|
||||||
|
"saveSpec": null,
|
||||||
|
"fetchSpec": "^4.2.1"
|
||||||
|
},
|
||||||
|
"_requiredBy": [
|
||||||
|
"/inquirer"
|
||||||
|
],
|
||||||
|
"_resolved": "https://registry.npmjs.org/ansi-escapes/-/ansi-escapes-4.3.1.tgz",
|
||||||
|
"_shasum": "a5c47cc43181f1f38ffd7076837700d395522a61",
|
||||||
|
"_spec": "ansi-escapes@^4.2.1",
|
||||||
|
"_where": "/Users/keiferju/code/Lingtu/smx-svelma/upload/node_modules/inquirer",
|
||||||
|
"author": {
|
||||||
|
"name": "Sindre Sorhus",
|
||||||
|
"email": "sindresorhus@gmail.com",
|
||||||
|
"url": "https://sindresorhus.com"
|
||||||
|
},
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/sindresorhus/ansi-escapes/issues"
|
||||||
|
},
|
||||||
|
"bundleDependencies": false,
|
||||||
|
"dependencies": {
|
||||||
|
"type-fest": "^0.11.0"
|
||||||
|
},
|
||||||
|
"deprecated": false,
|
||||||
|
"description": "ANSI escape codes for manipulating the terminal",
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/node": "^13.7.7",
|
||||||
|
"ava": "^2.1.0",
|
||||||
|
"tsd": "^0.11.0",
|
||||||
|
"xo": "^0.25.3"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"index.js",
|
||||||
|
"index.d.ts"
|
||||||
|
],
|
||||||
|
"funding": "https://github.com/sponsors/sindresorhus",
|
||||||
|
"homepage": "https://github.com/sindresorhus/ansi-escapes#readme",
|
||||||
|
"keywords": [
|
||||||
|
"ansi",
|
||||||
|
"terminal",
|
||||||
|
"console",
|
||||||
|
"cli",
|
||||||
|
"string",
|
||||||
|
"tty",
|
||||||
|
"escape",
|
||||||
|
"escapes",
|
||||||
|
"formatting",
|
||||||
|
"shell",
|
||||||
|
"xterm",
|
||||||
|
"log",
|
||||||
|
"logging",
|
||||||
|
"command-line",
|
||||||
|
"text",
|
||||||
|
"vt100",
|
||||||
|
"sequence",
|
||||||
|
"control",
|
||||||
|
"code",
|
||||||
|
"codes",
|
||||||
|
"cursor",
|
||||||
|
"iterm",
|
||||||
|
"iterm2"
|
||||||
|
],
|
||||||
|
"license": "MIT",
|
||||||
|
"name": "ansi-escapes",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/sindresorhus/ansi-escapes.git"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "xo && ava && tsd"
|
||||||
|
},
|
||||||
|
"version": "4.3.1"
|
||||||
|
}
|
|
@ -0,0 +1,245 @@
|
||||||
|
# ansi-escapes [](https://travis-ci.org/sindresorhus/ansi-escapes)
|
||||||
|
|
||||||
|
> [ANSI escape codes](http://www.termsys.demon.co.uk/vtansi.htm) for manipulating the terminal
|
||||||
|
|
||||||
|
## Install
|
||||||
|
|
||||||
|
```
|
||||||
|
$ npm install ansi-escapes
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```js
|
||||||
|
const ansiEscapes = require('ansi-escapes');
|
||||||
|
|
||||||
|
// Moves the cursor two rows up and to the left
|
||||||
|
process.stdout.write(ansiEscapes.cursorUp(2) + ansiEscapes.cursorLeft);
|
||||||
|
//=> '\u001B[2A\u001B[1000D'
|
||||||
|
```
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
|
### cursorTo(x, y?)
|
||||||
|
|
||||||
|
Set the absolute position of the cursor. `x0` `y0` is the top left of the screen.
|
||||||
|
|
||||||
|
### cursorMove(x, y?)
|
||||||
|
|
||||||
|
Set the position of the cursor relative to its current position.
|
||||||
|
|
||||||
|
### cursorUp(count)
|
||||||
|
|
||||||
|
Move cursor up a specific amount of rows. Default is `1`.
|
||||||
|
|
||||||
|
### cursorDown(count)
|
||||||
|
|
||||||
|
Move cursor down a specific amount of rows. Default is `1`.
|
||||||
|
|
||||||
|
### cursorForward(count)
|
||||||
|
|
||||||
|
Move cursor forward a specific amount of columns. Default is `1`.
|
||||||
|
|
||||||
|
### cursorBackward(count)
|
||||||
|
|
||||||
|
Move cursor backward a specific amount of columns. Default is `1`.
|
||||||
|
|
||||||
|
### cursorLeft
|
||||||
|
|
||||||
|
Move cursor to the left side.
|
||||||
|
|
||||||
|
### cursorSavePosition
|
||||||
|
|
||||||
|
Save cursor position.
|
||||||
|
|
||||||
|
### cursorRestorePosition
|
||||||
|
|
||||||
|
Restore saved cursor position.
|
||||||
|
|
||||||
|
### cursorGetPosition
|
||||||
|
|
||||||
|
Get cursor position.
|
||||||
|
|
||||||
|
### cursorNextLine
|
||||||
|
|
||||||
|
Move cursor to the next line.
|
||||||
|
|
||||||
|
### cursorPrevLine
|
||||||
|
|
||||||
|
Move cursor to the previous line.
|
||||||
|
|
||||||
|
### cursorHide
|
||||||
|
|
||||||
|
Hide cursor.
|
||||||
|
|
||||||
|
### cursorShow
|
||||||
|
|
||||||
|
Show cursor.
|
||||||
|
|
||||||
|
### eraseLines(count)
|
||||||
|
|
||||||
|
Erase from the current cursor position up the specified amount of rows.
|
||||||
|
|
||||||
|
### eraseEndLine
|
||||||
|
|
||||||
|
Erase from the current cursor position to the end of the current line.
|
||||||
|
|
||||||
|
### eraseStartLine
|
||||||
|
|
||||||
|
Erase from the current cursor position to the start of the current line.
|
||||||
|
|
||||||
|
### eraseLine
|
||||||
|
|
||||||
|
Erase the entire current line.
|
||||||
|
|
||||||
|
### eraseDown
|
||||||
|
|
||||||
|
Erase the screen from the current line down to the bottom of the screen.
|
||||||
|
|
||||||
|
### eraseUp
|
||||||
|
|
||||||
|
Erase the screen from the current line up to the top of the screen.
|
||||||
|
|
||||||
|
### eraseScreen
|
||||||
|
|
||||||
|
Erase the screen and move the cursor the top left position.
|
||||||
|
|
||||||
|
### scrollUp
|
||||||
|
|
||||||
|
Scroll display up one line.
|
||||||
|
|
||||||
|
### scrollDown
|
||||||
|
|
||||||
|
Scroll display down one line.
|
||||||
|
|
||||||
|
### clearScreen
|
||||||
|
|
||||||
|
Clear the terminal screen. (Viewport)
|
||||||
|
|
||||||
|
### clearTerminal
|
||||||
|
|
||||||
|
Clear the whole terminal, including scrollback buffer. (Not just the visible part of it)
|
||||||
|
|
||||||
|
### beep
|
||||||
|
|
||||||
|
Output a beeping sound.
|
||||||
|
|
||||||
|
### link(text, url)
|
||||||
|
|
||||||
|
Create a clickable link.
|
||||||
|
|
||||||
|
[Supported terminals.](https://gist.github.com/egmontkob/eb114294efbcd5adb1944c9f3cb5feda) Use [`supports-hyperlinks`](https://github.com/jamestalmage/supports-hyperlinks) to detect link support.
|
||||||
|
|
||||||
|
### image(filePath, options?)
|
||||||
|
|
||||||
|
Display an image.
|
||||||
|
|
||||||
|
*Currently only supported on iTerm2 >=3*
|
||||||
|
|
||||||
|
See [term-img](https://github.com/sindresorhus/term-img) for a higher-level module.
|
||||||
|
|
||||||
|
#### input
|
||||||
|
|
||||||
|
Type: `Buffer`
|
||||||
|
|
||||||
|
Buffer of an image. Usually read in with `fs.readFile()`.
|
||||||
|
|
||||||
|
#### options
|
||||||
|
|
||||||
|
Type: `object`
|
||||||
|
|
||||||
|
##### width
|
||||||
|
##### height
|
||||||
|
|
||||||
|
Type: `string | number`
|
||||||
|
|
||||||
|
The width and height are given as a number followed by a unit, or the word "auto".
|
||||||
|
|
||||||
|
- `N`: N character cells.
|
||||||
|
- `Npx`: N pixels.
|
||||||
|
- `N%`: N percent of the session's width or height.
|
||||||
|
- `auto`: The image's inherent size will be used to determine an appropriate dimension.
|
||||||
|
|
||||||
|
##### preserveAspectRatio
|
||||||
|
|
||||||
|
Type: `boolean`\
|
||||||
|
Default: `true`
|
||||||
|
|
||||||
|
### iTerm.setCwd(path?)
|
||||||
|
|
||||||
|
Type: `string`\
|
||||||
|
Default: `process.cwd()`
|
||||||
|
|
||||||
|
[Inform iTerm2](https://www.iterm2.com/documentation-escape-codes.html) of the current directory to help semantic history and enable [Cmd-clicking relative paths](https://coderwall.com/p/b7e82q/quickly-open-files-in-iterm-with-cmd-click).
|
||||||
|
|
||||||
|
### iTerm.annotation(message, options?)
|
||||||
|
|
||||||
|
Creates an escape code to display an "annotation" in iTerm2.
|
||||||
|
|
||||||
|
An annotation looks like this when shown:
|
||||||
|
|
||||||
|
<img src="https://user-images.githubusercontent.com/924465/64382136-b60ac700-cfe9-11e9-8a35-9682e8dc4b72.png" width="500">
|
||||||
|
|
||||||
|
See the [iTerm Proprietary Escape Codes documentation](https://iterm2.com/documentation-escape-codes.html) for more information.
|
||||||
|
|
||||||
|
#### message
|
||||||
|
|
||||||
|
Type: `string`
|
||||||
|
|
||||||
|
The message to display within the annotation.
|
||||||
|
|
||||||
|
The `|` character is disallowed and will be stripped.
|
||||||
|
|
||||||
|
#### options
|
||||||
|
|
||||||
|
Type: `object`
|
||||||
|
|
||||||
|
##### length
|
||||||
|
|
||||||
|
Type: `number`\
|
||||||
|
Default: The remainder of the line
|
||||||
|
|
||||||
|
Nonzero number of columns to annotate.
|
||||||
|
|
||||||
|
##### x
|
||||||
|
|
||||||
|
Type: `number`\
|
||||||
|
Default: Cursor position
|
||||||
|
|
||||||
|
Starting X coordinate.
|
||||||
|
|
||||||
|
Must be used with `y` and `length`.
|
||||||
|
|
||||||
|
##### y
|
||||||
|
|
||||||
|
Type: `number`\
|
||||||
|
Default: Cursor position
|
||||||
|
|
||||||
|
Starting Y coordinate.
|
||||||
|
|
||||||
|
Must be used with `x` and `length`.
|
||||||
|
|
||||||
|
##### isHidden
|
||||||
|
|
||||||
|
Type: `boolean`\
|
||||||
|
Default: `false`
|
||||||
|
|
||||||
|
Create a "hidden" annotation.
|
||||||
|
|
||||||
|
Annotations created this way can be shown using the "Show Annotations" iTerm command.
|
||||||
|
|
||||||
|
## Related
|
||||||
|
|
||||||
|
- [ansi-styles](https://github.com/chalk/ansi-styles) - ANSI escape codes for styling strings in the terminal
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
<div align="center">
|
||||||
|
<b>
|
||||||
|
<a href="https://tidelift.com/subscription/pkg/npm-ansi-escapes?utm_source=npm-ansi-escapes&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
|
||||||
|
</b>
|
||||||
|
<br>
|
||||||
|
<sub>
|
||||||
|
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
||||||
|
</sub>
|
||||||
|
</div>
|
|
@ -0,0 +1,37 @@
|
||||||
|
declare namespace ansiRegex {
|
||||||
|
interface Options {
|
||||||
|
/**
|
||||||
|
Match only the first ANSI escape.
|
||||||
|
|
||||||
|
@default false
|
||||||
|
*/
|
||||||
|
onlyFirst: boolean;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Regular expression for matching ANSI escape codes.
|
||||||
|
|
||||||
|
@example
|
||||||
|
```
|
||||||
|
import ansiRegex = require('ansi-regex');
|
||||||
|
|
||||||
|
ansiRegex().test('\u001B[4mcake\u001B[0m');
|
||||||
|
//=> true
|
||||||
|
|
||||||
|
ansiRegex().test('cake');
|
||||||
|
//=> false
|
||||||
|
|
||||||
|
'\u001B[4mcake\u001B[0m'.match(ansiRegex());
|
||||||
|
//=> ['\u001B[4m', '\u001B[0m']
|
||||||
|
|
||||||
|
'\u001B[4mcake\u001B[0m'.match(ansiRegex({onlyFirst: true}));
|
||||||
|
//=> ['\u001B[4m']
|
||||||
|
|
||||||
|
'\u001B]8;;https://github.com\u0007click\u001B]8;;\u0007'.match(ansiRegex());
|
||||||
|
//=> ['\u001B]8;;https://github.com\u0007', '\u001B]8;;\u0007']
|
||||||
|
```
|
||||||
|
*/
|
||||||
|
declare function ansiRegex(options?: ansiRegex.Options): RegExp;
|
||||||
|
|
||||||
|
export = ansiRegex;
|
|
@ -0,0 +1,10 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
module.exports = ({onlyFirst = false} = {}) => {
|
||||||
|
const pattern = [
|
||||||
|
'[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)',
|
||||||
|
'(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))'
|
||||||
|
].join('|');
|
||||||
|
|
||||||
|
return new RegExp(pattern, onlyFirst ? undefined : 'g');
|
||||||
|
};
|
|
@ -0,0 +1,9 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -0,0 +1,87 @@
|
||||||
|
{
|
||||||
|
"_from": "ansi-regex@^5.0.0",
|
||||||
|
"_id": "ansi-regex@5.0.0",
|
||||||
|
"_inBundle": false,
|
||||||
|
"_integrity": "sha512-bY6fj56OUQ0hU1KjFNDQuJFezqKdrAyFdIevADiqrWHwSlbmBNMHp5ak2f40Pm8JTFyM2mqxkG6ngkHO11f/lg==",
|
||||||
|
"_location": "/ansi-regex",
|
||||||
|
"_phantomChildren": {},
|
||||||
|
"_requested": {
|
||||||
|
"type": "range",
|
||||||
|
"registry": true,
|
||||||
|
"raw": "ansi-regex@^5.0.0",
|
||||||
|
"name": "ansi-regex",
|
||||||
|
"escapedName": "ansi-regex",
|
||||||
|
"rawSpec": "^5.0.0",
|
||||||
|
"saveSpec": null,
|
||||||
|
"fetchSpec": "^5.0.0"
|
||||||
|
},
|
||||||
|
"_requiredBy": [
|
||||||
|
"/strip-ansi"
|
||||||
|
],
|
||||||
|
"_resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz",
|
||||||
|
"_shasum": "388539f55179bf39339c81af30a654d69f87cb75",
|
||||||
|
"_spec": "ansi-regex@^5.0.0",
|
||||||
|
"_where": "/Users/keiferju/code/Lingtu/smx-svelma/upload/node_modules/strip-ansi",
|
||||||
|
"author": {
|
||||||
|
"name": "Sindre Sorhus",
|
||||||
|
"email": "sindresorhus@gmail.com",
|
||||||
|
"url": "sindresorhus.com"
|
||||||
|
},
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/chalk/ansi-regex/issues"
|
||||||
|
},
|
||||||
|
"bundleDependencies": false,
|
||||||
|
"deprecated": false,
|
||||||
|
"description": "Regular expression for matching ANSI escape codes",
|
||||||
|
"devDependencies": {
|
||||||
|
"ava": "^2.4.0",
|
||||||
|
"tsd": "^0.9.0",
|
||||||
|
"xo": "^0.25.3"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"index.js",
|
||||||
|
"index.d.ts"
|
||||||
|
],
|
||||||
|
"homepage": "https://github.com/chalk/ansi-regex#readme",
|
||||||
|
"keywords": [
|
||||||
|
"ansi",
|
||||||
|
"styles",
|
||||||
|
"color",
|
||||||
|
"colour",
|
||||||
|
"colors",
|
||||||
|
"terminal",
|
||||||
|
"console",
|
||||||
|
"cli",
|
||||||
|
"string",
|
||||||
|
"tty",
|
||||||
|
"escape",
|
||||||
|
"formatting",
|
||||||
|
"rgb",
|
||||||
|
"256",
|
||||||
|
"shell",
|
||||||
|
"xterm",
|
||||||
|
"command-line",
|
||||||
|
"text",
|
||||||
|
"regex",
|
||||||
|
"regexp",
|
||||||
|
"re",
|
||||||
|
"match",
|
||||||
|
"test",
|
||||||
|
"find",
|
||||||
|
"pattern"
|
||||||
|
],
|
||||||
|
"license": "MIT",
|
||||||
|
"name": "ansi-regex",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/chalk/ansi-regex.git"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "xo && ava && tsd",
|
||||||
|
"view-supported": "node fixtures/view-codes.js"
|
||||||
|
},
|
||||||
|
"version": "5.0.0"
|
||||||
|
}
|
|
@ -0,0 +1,78 @@
|
||||||
|
# ansi-regex [](https://travis-ci.org/chalk/ansi-regex)
|
||||||
|
|
||||||
|
> Regular expression for matching [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code)
|
||||||
|
|
||||||
|
|
||||||
|
## Install
|
||||||
|
|
||||||
|
```
|
||||||
|
$ npm install ansi-regex
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```js
|
||||||
|
const ansiRegex = require('ansi-regex');
|
||||||
|
|
||||||
|
ansiRegex().test('\u001B[4mcake\u001B[0m');
|
||||||
|
//=> true
|
||||||
|
|
||||||
|
ansiRegex().test('cake');
|
||||||
|
//=> false
|
||||||
|
|
||||||
|
'\u001B[4mcake\u001B[0m'.match(ansiRegex());
|
||||||
|
//=> ['\u001B[4m', '\u001B[0m']
|
||||||
|
|
||||||
|
'\u001B[4mcake\u001B[0m'.match(ansiRegex({onlyFirst: true}));
|
||||||
|
//=> ['\u001B[4m']
|
||||||
|
|
||||||
|
'\u001B]8;;https://github.com\u0007click\u001B]8;;\u0007'.match(ansiRegex());
|
||||||
|
//=> ['\u001B]8;;https://github.com\u0007', '\u001B]8;;\u0007']
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
|
### ansiRegex(options?)
|
||||||
|
|
||||||
|
Returns a regex for matching ANSI escape codes.
|
||||||
|
|
||||||
|
#### options
|
||||||
|
|
||||||
|
Type: `object`
|
||||||
|
|
||||||
|
##### onlyFirst
|
||||||
|
|
||||||
|
Type: `boolean`<br>
|
||||||
|
Default: `false` *(Matches any ANSI escape codes in a string)*
|
||||||
|
|
||||||
|
Match only the first ANSI escape.
|
||||||
|
|
||||||
|
|
||||||
|
## FAQ
|
||||||
|
|
||||||
|
### Why do you test for codes not in the ECMA 48 standard?
|
||||||
|
|
||||||
|
Some of the codes we run as a test are codes that we acquired finding various lists of non-standard or manufacturer specific codes. We test for both standard and non-standard codes, as most of them follow the same or similar format and can be safely matched in strings without the risk of removing actual string content. There are a few non-standard control codes that do not follow the traditional format (i.e. they end in numbers) thus forcing us to exclude them from the test because we cannot reliably match them.
|
||||||
|
|
||||||
|
On the historical side, those ECMA standards were established in the early 90's whereas the VT100, for example, was designed in the mid/late 70's. At that point in time, control codes were still pretty ungoverned and engineers used them for a multitude of things, namely to activate hardware ports that may have been proprietary. Somewhere else you see a similar 'anarchy' of codes is in the x86 architecture for processors; there are a ton of "interrupts" that can mean different things on certain brands of processors, most of which have been phased out.
|
||||||
|
|
||||||
|
|
||||||
|
## Maintainers
|
||||||
|
|
||||||
|
- [Sindre Sorhus](https://github.com/sindresorhus)
|
||||||
|
- [Josh Junon](https://github.com/qix-)
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
<div align="center">
|
||||||
|
<b>
|
||||||
|
<a href="https://tidelift.com/subscription/pkg/npm-ansi-regex?utm_source=npm-ansi-regex&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
|
||||||
|
</b>
|
||||||
|
<br>
|
||||||
|
<sub>
|
||||||
|
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
||||||
|
</sub>
|
||||||
|
</div>
|
|
@ -0,0 +1,197 @@
|
||||||
|
import * as cssColors from 'color-name';
|
||||||
|
|
||||||
|
declare namespace ansiStyles {
|
||||||
|
interface ColorConvert {
|
||||||
|
/**
|
||||||
|
The RGB color space.
|
||||||
|
|
||||||
|
@param red - (`0`-`255`)
|
||||||
|
@param green - (`0`-`255`)
|
||||||
|
@param blue - (`0`-`255`)
|
||||||
|
*/
|
||||||
|
rgb(red: number, green: number, blue: number): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
The RGB HEX color space.
|
||||||
|
|
||||||
|
@param hex - A hexadecimal string containing RGB data.
|
||||||
|
*/
|
||||||
|
hex(hex: string): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
@param keyword - A CSS color name.
|
||||||
|
*/
|
||||||
|
keyword(keyword: keyof typeof cssColors): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
The HSL color space.
|
||||||
|
|
||||||
|
@param hue - (`0`-`360`)
|
||||||
|
@param saturation - (`0`-`100`)
|
||||||
|
@param lightness - (`0`-`100`)
|
||||||
|
*/
|
||||||
|
hsl(hue: number, saturation: number, lightness: number): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
The HSV color space.
|
||||||
|
|
||||||
|
@param hue - (`0`-`360`)
|
||||||
|
@param saturation - (`0`-`100`)
|
||||||
|
@param value - (`0`-`100`)
|
||||||
|
*/
|
||||||
|
hsv(hue: number, saturation: number, value: number): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
The HSV color space.
|
||||||
|
|
||||||
|
@param hue - (`0`-`360`)
|
||||||
|
@param whiteness - (`0`-`100`)
|
||||||
|
@param blackness - (`0`-`100`)
|
||||||
|
*/
|
||||||
|
hwb(hue: number, whiteness: number, blackness: number): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Use a [4-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4-bit) to set text color.
|
||||||
|
*/
|
||||||
|
ansi(ansi: number): string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Use an [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set text color.
|
||||||
|
*/
|
||||||
|
ansi256(ansi: number): string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface CSPair {
|
||||||
|
/**
|
||||||
|
The ANSI terminal control sequence for starting this style.
|
||||||
|
*/
|
||||||
|
readonly open: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
The ANSI terminal control sequence for ending this style.
|
||||||
|
*/
|
||||||
|
readonly close: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ColorBase {
|
||||||
|
readonly ansi: ColorConvert;
|
||||||
|
readonly ansi256: ColorConvert;
|
||||||
|
readonly ansi16m: ColorConvert;
|
||||||
|
|
||||||
|
/**
|
||||||
|
The ANSI terminal control sequence for ending this color.
|
||||||
|
*/
|
||||||
|
readonly close: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Modifier {
|
||||||
|
/**
|
||||||
|
Resets the current color chain.
|
||||||
|
*/
|
||||||
|
readonly reset: CSPair;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Make text bold.
|
||||||
|
*/
|
||||||
|
readonly bold: CSPair;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Emitting only a small amount of light.
|
||||||
|
*/
|
||||||
|
readonly dim: CSPair;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Make text italic. (Not widely supported)
|
||||||
|
*/
|
||||||
|
readonly italic: CSPair;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Make text underline. (Not widely supported)
|
||||||
|
*/
|
||||||
|
readonly underline: CSPair;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Inverse background and foreground colors.
|
||||||
|
*/
|
||||||
|
readonly inverse: CSPair;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Prints the text, but makes it invisible.
|
||||||
|
*/
|
||||||
|
readonly hidden: CSPair;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Puts a horizontal line through the center of the text. (Not widely supported)
|
||||||
|
*/
|
||||||
|
readonly strikethrough: CSPair;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ForegroundColor {
|
||||||
|
readonly black: CSPair;
|
||||||
|
readonly red: CSPair;
|
||||||
|
readonly green: CSPair;
|
||||||
|
readonly yellow: CSPair;
|
||||||
|
readonly blue: CSPair;
|
||||||
|
readonly cyan: CSPair;
|
||||||
|
readonly magenta: CSPair;
|
||||||
|
readonly white: CSPair;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Alias for `blackBright`.
|
||||||
|
*/
|
||||||
|
readonly gray: CSPair;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Alias for `blackBright`.
|
||||||
|
*/
|
||||||
|
readonly grey: CSPair;
|
||||||
|
|
||||||
|
readonly blackBright: CSPair;
|
||||||
|
readonly redBright: CSPair;
|
||||||
|
readonly greenBright: CSPair;
|
||||||
|
readonly yellowBright: CSPair;
|
||||||
|
readonly blueBright: CSPair;
|
||||||
|
readonly cyanBright: CSPair;
|
||||||
|
readonly magentaBright: CSPair;
|
||||||
|
readonly whiteBright: CSPair;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface BackgroundColor {
|
||||||
|
readonly bgBlack: CSPair;
|
||||||
|
readonly bgRed: CSPair;
|
||||||
|
readonly bgGreen: CSPair;
|
||||||
|
readonly bgYellow: CSPair;
|
||||||
|
readonly bgBlue: CSPair;
|
||||||
|
readonly bgCyan: CSPair;
|
||||||
|
readonly bgMagenta: CSPair;
|
||||||
|
readonly bgWhite: CSPair;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Alias for `bgBlackBright`.
|
||||||
|
*/
|
||||||
|
readonly bgGray: CSPair;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Alias for `bgBlackBright`.
|
||||||
|
*/
|
||||||
|
readonly bgGrey: CSPair;
|
||||||
|
|
||||||
|
readonly bgBlackBright: CSPair;
|
||||||
|
readonly bgRedBright: CSPair;
|
||||||
|
readonly bgGreenBright: CSPair;
|
||||||
|
readonly bgYellowBright: CSPair;
|
||||||
|
readonly bgBlueBright: CSPair;
|
||||||
|
readonly bgCyanBright: CSPair;
|
||||||
|
readonly bgMagentaBright: CSPair;
|
||||||
|
readonly bgWhiteBright: CSPair;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare const ansiStyles: {
|
||||||
|
readonly modifier: ansiStyles.Modifier;
|
||||||
|
readonly color: ansiStyles.ForegroundColor & ansiStyles.ColorBase;
|
||||||
|
readonly bgColor: ansiStyles.BackgroundColor & ansiStyles.ColorBase;
|
||||||
|
readonly codes: ReadonlyMap<number, number>;
|
||||||
|
} & ansiStyles.BackgroundColor & ansiStyles.ForegroundColor & ansiStyles.Modifier;
|
||||||
|
|
||||||
|
export = ansiStyles;
|
|
@ -0,0 +1,163 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const wrapAnsi16 = (fn, offset) => (...args) => {
|
||||||
|
const code = fn(...args);
|
||||||
|
return `\u001B[${code + offset}m`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const wrapAnsi256 = (fn, offset) => (...args) => {
|
||||||
|
const code = fn(...args);
|
||||||
|
return `\u001B[${38 + offset};5;${code}m`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const wrapAnsi16m = (fn, offset) => (...args) => {
|
||||||
|
const rgb = fn(...args);
|
||||||
|
return `\u001B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const ansi2ansi = n => n;
|
||||||
|
const rgb2rgb = (r, g, b) => [r, g, b];
|
||||||
|
|
||||||
|
const setLazyProperty = (object, property, get) => {
|
||||||
|
Object.defineProperty(object, property, {
|
||||||
|
get: () => {
|
||||||
|
const value = get();
|
||||||
|
|
||||||
|
Object.defineProperty(object, property, {
|
||||||
|
value,
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
|
||||||
|
return value;
|
||||||
|
},
|
||||||
|
enumerable: true,
|
||||||
|
configurable: true
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/** @type {typeof import('color-convert')} */
|
||||||
|
let colorConvert;
|
||||||
|
const makeDynamicStyles = (wrap, targetSpace, identity, isBackground) => {
|
||||||
|
if (colorConvert === undefined) {
|
||||||
|
colorConvert = require('color-convert');
|
||||||
|
}
|
||||||
|
|
||||||
|
const offset = isBackground ? 10 : 0;
|
||||||
|
const styles = {};
|
||||||
|
|
||||||
|
for (const [sourceSpace, suite] of Object.entries(colorConvert)) {
|
||||||
|
const name = sourceSpace === 'ansi16' ? 'ansi' : sourceSpace;
|
||||||
|
if (sourceSpace === targetSpace) {
|
||||||
|
styles[name] = wrap(identity, offset);
|
||||||
|
} else if (typeof suite === 'object') {
|
||||||
|
styles[name] = wrap(suite[targetSpace], offset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return styles;
|
||||||
|
};
|
||||||
|
|
||||||
|
function assembleStyles() {
|
||||||
|
const codes = new Map();
|
||||||
|
const styles = {
|
||||||
|
modifier: {
|
||||||
|
reset: [0, 0],
|
||||||
|
// 21 isn't widely supported and 22 does the same thing
|
||||||
|
bold: [1, 22],
|
||||||
|
dim: [2, 22],
|
||||||
|
italic: [3, 23],
|
||||||
|
underline: [4, 24],
|
||||||
|
inverse: [7, 27],
|
||||||
|
hidden: [8, 28],
|
||||||
|
strikethrough: [9, 29]
|
||||||
|
},
|
||||||
|
color: {
|
||||||
|
black: [30, 39],
|
||||||
|
red: [31, 39],
|
||||||
|
green: [32, 39],
|
||||||
|
yellow: [33, 39],
|
||||||
|
blue: [34, 39],
|
||||||
|
magenta: [35, 39],
|
||||||
|
cyan: [36, 39],
|
||||||
|
white: [37, 39],
|
||||||
|
|
||||||
|
// Bright color
|
||||||
|
blackBright: [90, 39],
|
||||||
|
redBright: [91, 39],
|
||||||
|
greenBright: [92, 39],
|
||||||
|
yellowBright: [93, 39],
|
||||||
|
blueBright: [94, 39],
|
||||||
|
magentaBright: [95, 39],
|
||||||
|
cyanBright: [96, 39],
|
||||||
|
whiteBright: [97, 39]
|
||||||
|
},
|
||||||
|
bgColor: {
|
||||||
|
bgBlack: [40, 49],
|
||||||
|
bgRed: [41, 49],
|
||||||
|
bgGreen: [42, 49],
|
||||||
|
bgYellow: [43, 49],
|
||||||
|
bgBlue: [44, 49],
|
||||||
|
bgMagenta: [45, 49],
|
||||||
|
bgCyan: [46, 49],
|
||||||
|
bgWhite: [47, 49],
|
||||||
|
|
||||||
|
// Bright color
|
||||||
|
bgBlackBright: [100, 49],
|
||||||
|
bgRedBright: [101, 49],
|
||||||
|
bgGreenBright: [102, 49],
|
||||||
|
bgYellowBright: [103, 49],
|
||||||
|
bgBlueBright: [104, 49],
|
||||||
|
bgMagentaBright: [105, 49],
|
||||||
|
bgCyanBright: [106, 49],
|
||||||
|
bgWhiteBright: [107, 49]
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Alias bright black as gray (and grey)
|
||||||
|
styles.color.gray = styles.color.blackBright;
|
||||||
|
styles.bgColor.bgGray = styles.bgColor.bgBlackBright;
|
||||||
|
styles.color.grey = styles.color.blackBright;
|
||||||
|
styles.bgColor.bgGrey = styles.bgColor.bgBlackBright;
|
||||||
|
|
||||||
|
for (const [groupName, group] of Object.entries(styles)) {
|
||||||
|
for (const [styleName, style] of Object.entries(group)) {
|
||||||
|
styles[styleName] = {
|
||||||
|
open: `\u001B[${style[0]}m`,
|
||||||
|
close: `\u001B[${style[1]}m`
|
||||||
|
};
|
||||||
|
|
||||||
|
group[styleName] = styles[styleName];
|
||||||
|
|
||||||
|
codes.set(style[0], style[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.defineProperty(styles, groupName, {
|
||||||
|
value: group,
|
||||||
|
enumerable: false
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.defineProperty(styles, 'codes', {
|
||||||
|
value: codes,
|
||||||
|
enumerable: false
|
||||||
|
});
|
||||||
|
|
||||||
|
styles.color.close = '\u001B[39m';
|
||||||
|
styles.bgColor.close = '\u001B[49m';
|
||||||
|
|
||||||
|
setLazyProperty(styles.color, 'ansi', () => makeDynamicStyles(wrapAnsi16, 'ansi16', ansi2ansi, false));
|
||||||
|
setLazyProperty(styles.color, 'ansi256', () => makeDynamicStyles(wrapAnsi256, 'ansi256', ansi2ansi, false));
|
||||||
|
setLazyProperty(styles.color, 'ansi16m', () => makeDynamicStyles(wrapAnsi16m, 'rgb', rgb2rgb, false));
|
||||||
|
setLazyProperty(styles.bgColor, 'ansi', () => makeDynamicStyles(wrapAnsi16, 'ansi16', ansi2ansi, true));
|
||||||
|
setLazyProperty(styles.bgColor, 'ansi256', () => makeDynamicStyles(wrapAnsi256, 'ansi256', ansi2ansi, true));
|
||||||
|
setLazyProperty(styles.bgColor, 'ansi16m', () => makeDynamicStyles(wrapAnsi16m, 'rgb', rgb2rgb, true));
|
||||||
|
|
||||||
|
return styles;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make the export immutable
|
||||||
|
Object.defineProperty(module, 'exports', {
|
||||||
|
enumerable: true,
|
||||||
|
get: assembleStyles
|
||||||
|
});
|
|
@ -0,0 +1,9 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -0,0 +1,89 @@
|
||||||
|
{
|
||||||
|
"_from": "ansi-styles@^4.1.0",
|
||||||
|
"_id": "ansi-styles@4.2.1",
|
||||||
|
"_inBundle": false,
|
||||||
|
"_integrity": "sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==",
|
||||||
|
"_location": "/ansi-styles",
|
||||||
|
"_phantomChildren": {},
|
||||||
|
"_requested": {
|
||||||
|
"type": "range",
|
||||||
|
"registry": true,
|
||||||
|
"raw": "ansi-styles@^4.1.0",
|
||||||
|
"name": "ansi-styles",
|
||||||
|
"escapedName": "ansi-styles",
|
||||||
|
"rawSpec": "^4.1.0",
|
||||||
|
"saveSpec": null,
|
||||||
|
"fetchSpec": "^4.1.0"
|
||||||
|
},
|
||||||
|
"_requiredBy": [
|
||||||
|
"/chalk"
|
||||||
|
],
|
||||||
|
"_resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.1.tgz",
|
||||||
|
"_shasum": "90ae75c424d008d2624c5bf29ead3177ebfcf359",
|
||||||
|
"_spec": "ansi-styles@^4.1.0",
|
||||||
|
"_where": "/Users/keiferju/code/Lingtu/smx-svelma/upload/node_modules/chalk",
|
||||||
|
"author": {
|
||||||
|
"name": "Sindre Sorhus",
|
||||||
|
"email": "sindresorhus@gmail.com",
|
||||||
|
"url": "sindresorhus.com"
|
||||||
|
},
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/chalk/ansi-styles/issues"
|
||||||
|
},
|
||||||
|
"bundleDependencies": false,
|
||||||
|
"dependencies": {
|
||||||
|
"@types/color-name": "^1.1.1",
|
||||||
|
"color-convert": "^2.0.1"
|
||||||
|
},
|
||||||
|
"deprecated": false,
|
||||||
|
"description": "ANSI escape codes for styling strings in the terminal",
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/color-convert": "^1.9.0",
|
||||||
|
"ava": "^2.3.0",
|
||||||
|
"svg-term-cli": "^2.1.1",
|
||||||
|
"tsd": "^0.11.0",
|
||||||
|
"xo": "^0.25.3"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"index.js",
|
||||||
|
"index.d.ts"
|
||||||
|
],
|
||||||
|
"funding": "https://github.com/chalk/ansi-styles?sponsor=1",
|
||||||
|
"homepage": "https://github.com/chalk/ansi-styles#readme",
|
||||||
|
"keywords": [
|
||||||
|
"ansi",
|
||||||
|
"styles",
|
||||||
|
"color",
|
||||||
|
"colour",
|
||||||
|
"colors",
|
||||||
|
"terminal",
|
||||||
|
"console",
|
||||||
|
"cli",
|
||||||
|
"string",
|
||||||
|
"tty",
|
||||||
|
"escape",
|
||||||
|
"formatting",
|
||||||
|
"rgb",
|
||||||
|
"256",
|
||||||
|
"shell",
|
||||||
|
"xterm",
|
||||||
|
"log",
|
||||||
|
"logging",
|
||||||
|
"command-line",
|
||||||
|
"text"
|
||||||
|
],
|
||||||
|
"license": "MIT",
|
||||||
|
"name": "ansi-styles",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/chalk/ansi-styles.git"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"screenshot": "svg-term --command='node screenshot' --out=screenshot.svg --padding=3 --width=55 --height=3 --at=1000 --no-cursor",
|
||||||
|
"test": "xo && ava && tsd"
|
||||||
|
},
|
||||||
|
"version": "4.2.1"
|
||||||
|
}
|
|
@ -0,0 +1,158 @@
|
||||||
|
# ansi-styles [](https://travis-ci.org/chalk/ansi-styles)
|
||||||
|
|
||||||
|
> [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors_and_Styles) for styling strings in the terminal
|
||||||
|
|
||||||
|
You probably want the higher-level [chalk](https://github.com/chalk/chalk) module for styling your strings.
|
||||||
|
|
||||||
|
<img src="screenshot.svg" width="900">
|
||||||
|
|
||||||
|
## Install
|
||||||
|
|
||||||
|
```
|
||||||
|
$ npm install ansi-styles
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```js
|
||||||
|
const style = require('ansi-styles');
|
||||||
|
|
||||||
|
console.log(`${style.green.open}Hello world!${style.green.close}`);
|
||||||
|
|
||||||
|
|
||||||
|
// Color conversion between 16/256/truecolor
|
||||||
|
// NOTE: If conversion goes to 16 colors or 256 colors, the original color
|
||||||
|
// may be degraded to fit that color palette. This means terminals
|
||||||
|
// that do not support 16 million colors will best-match the
|
||||||
|
// original color.
|
||||||
|
console.log(style.bgColor.ansi.hsl(120, 80, 72) + 'Hello world!' + style.bgColor.close);
|
||||||
|
console.log(style.color.ansi256.rgb(199, 20, 250) + 'Hello world!' + style.color.close);
|
||||||
|
console.log(style.color.ansi16m.hex('#abcdef') + 'Hello world!' + style.color.close);
|
||||||
|
```
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
|
Each style has an `open` and `close` property.
|
||||||
|
|
||||||
|
## Styles
|
||||||
|
|
||||||
|
### Modifiers
|
||||||
|
|
||||||
|
- `reset`
|
||||||
|
- `bold`
|
||||||
|
- `dim`
|
||||||
|
- `italic` *(Not widely supported)*
|
||||||
|
- `underline`
|
||||||
|
- `inverse`
|
||||||
|
- `hidden`
|
||||||
|
- `strikethrough` *(Not widely supported)*
|
||||||
|
|
||||||
|
### Colors
|
||||||
|
|
||||||
|
- `black`
|
||||||
|
- `red`
|
||||||
|
- `green`
|
||||||
|
- `yellow`
|
||||||
|
- `blue`
|
||||||
|
- `magenta`
|
||||||
|
- `cyan`
|
||||||
|
- `white`
|
||||||
|
- `blackBright` (alias: `gray`, `grey`)
|
||||||
|
- `redBright`
|
||||||
|
- `greenBright`
|
||||||
|
- `yellowBright`
|
||||||
|
- `blueBright`
|
||||||
|
- `magentaBright`
|
||||||
|
- `cyanBright`
|
||||||
|
- `whiteBright`
|
||||||
|
|
||||||
|
### Background colors
|
||||||
|
|
||||||
|
- `bgBlack`
|
||||||
|
- `bgRed`
|
||||||
|
- `bgGreen`
|
||||||
|
- `bgYellow`
|
||||||
|
- `bgBlue`
|
||||||
|
- `bgMagenta`
|
||||||
|
- `bgCyan`
|
||||||
|
- `bgWhite`
|
||||||
|
- `bgBlackBright` (alias: `bgGray`, `bgGrey`)
|
||||||
|
- `bgRedBright`
|
||||||
|
- `bgGreenBright`
|
||||||
|
- `bgYellowBright`
|
||||||
|
- `bgBlueBright`
|
||||||
|
- `bgMagentaBright`
|
||||||
|
- `bgCyanBright`
|
||||||
|
- `bgWhiteBright`
|
||||||
|
|
||||||
|
## Advanced usage
|
||||||
|
|
||||||
|
By default, you get a map of styles, but the styles are also available as groups. They are non-enumerable so they don't show up unless you access them explicitly. This makes it easier to expose only a subset in a higher-level module.
|
||||||
|
|
||||||
|
- `style.modifier`
|
||||||
|
- `style.color`
|
||||||
|
- `style.bgColor`
|
||||||
|
|
||||||
|
###### Example
|
||||||
|
|
||||||
|
```js
|
||||||
|
console.log(style.color.green.open);
|
||||||
|
```
|
||||||
|
|
||||||
|
Raw escape codes (i.e. without the CSI escape prefix `\u001B[` and render mode postfix `m`) are available under `style.codes`, which returns a `Map` with the open codes as keys and close codes as values.
|
||||||
|
|
||||||
|
###### Example
|
||||||
|
|
||||||
|
```js
|
||||||
|
console.log(style.codes.get(36));
|
||||||
|
//=> 39
|
||||||
|
```
|
||||||
|
|
||||||
|
## [256 / 16 million (TrueColor) support](https://gist.github.com/XVilka/8346728)
|
||||||
|
|
||||||
|
`ansi-styles` uses the [`color-convert`](https://github.com/Qix-/color-convert) package to allow for converting between various colors and ANSI escapes, with support for 256 and 16 million colors.
|
||||||
|
|
||||||
|
The following color spaces from `color-convert` are supported:
|
||||||
|
|
||||||
|
- `rgb`
|
||||||
|
- `hex`
|
||||||
|
- `keyword`
|
||||||
|
- `hsl`
|
||||||
|
- `hsv`
|
||||||
|
- `hwb`
|
||||||
|
- `ansi`
|
||||||
|
- `ansi256`
|
||||||
|
|
||||||
|
To use these, call the associated conversion function with the intended output, for example:
|
||||||
|
|
||||||
|
```js
|
||||||
|
style.color.ansi.rgb(100, 200, 15); // RGB to 16 color ansi foreground code
|
||||||
|
style.bgColor.ansi.rgb(100, 200, 15); // RGB to 16 color ansi background code
|
||||||
|
|
||||||
|
style.color.ansi256.hsl(120, 100, 60); // HSL to 256 color ansi foreground code
|
||||||
|
style.bgColor.ansi256.hsl(120, 100, 60); // HSL to 256 color ansi foreground code
|
||||||
|
|
||||||
|
style.color.ansi16m.hex('#C0FFEE'); // Hex (RGB) to 16 million color foreground code
|
||||||
|
style.bgColor.ansi16m.hex('#C0FFEE'); // Hex (RGB) to 16 million color background code
|
||||||
|
```
|
||||||
|
|
||||||
|
## Related
|
||||||
|
|
||||||
|
- [ansi-escapes](https://github.com/sindresorhus/ansi-escapes) - ANSI escape codes for manipulating the terminal
|
||||||
|
|
||||||
|
## Maintainers
|
||||||
|
|
||||||
|
- [Sindre Sorhus](https://github.com/sindresorhus)
|
||||||
|
- [Josh Junon](https://github.com/qix-)
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
<div align="center">
|
||||||
|
<b>
|
||||||
|
<a href="https://tidelift.com/subscription/pkg/npm-ansi-styles?utm_source=npm-ansi-styles&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
|
||||||
|
</b>
|
||||||
|
<br>
|
||||||
|
<sub>
|
||||||
|
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
||||||
|
</sub>
|
||||||
|
</div>
|
|
@ -0,0 +1,19 @@
|
||||||
|
Copyright (c) 2011 Mark Cavage, All rights reserved.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE
|
|
@ -0,0 +1,50 @@
|
||||||
|
node-asn1 is a library for encoding and decoding ASN.1 datatypes in pure JS.
|
||||||
|
Currently BER encoding is supported; at some point I'll likely have to do DER.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
Mostly, if you're *actually* needing to read and write ASN.1, you probably don't
|
||||||
|
need this readme to explain what and why. If you have no idea what ASN.1 is,
|
||||||
|
see this: ftp://ftp.rsa.com/pub/pkcs/ascii/layman.asc
|
||||||
|
|
||||||
|
The source is pretty much self-explanatory, and has read/write methods for the
|
||||||
|
common types out there.
|
||||||
|
|
||||||
|
### Decoding
|
||||||
|
|
||||||
|
The following reads an ASN.1 sequence with a boolean.
|
||||||
|
|
||||||
|
var Ber = require('asn1').Ber;
|
||||||
|
|
||||||
|
var reader = new Ber.Reader(Buffer.from([0x30, 0x03, 0x01, 0x01, 0xff]));
|
||||||
|
|
||||||
|
reader.readSequence();
|
||||||
|
console.log('Sequence len: ' + reader.length);
|
||||||
|
if (reader.peek() === Ber.Boolean)
|
||||||
|
console.log(reader.readBoolean());
|
||||||
|
|
||||||
|
### Encoding
|
||||||
|
|
||||||
|
The following generates the same payload as above.
|
||||||
|
|
||||||
|
var Ber = require('asn1').Ber;
|
||||||
|
|
||||||
|
var writer = new Ber.Writer();
|
||||||
|
|
||||||
|
writer.startSequence();
|
||||||
|
writer.writeBoolean(true);
|
||||||
|
writer.endSequence();
|
||||||
|
|
||||||
|
console.log(writer.buffer);
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
npm install asn1
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
MIT.
|
||||||
|
|
||||||
|
## Bugs
|
||||||
|
|
||||||
|
See <https://github.com/joyent/node-asn1/issues>.
|
|
@ -0,0 +1,13 @@
|
||||||
|
// Copyright 2011 Mark Cavage <mcavage@gmail.com> All rights reserved.
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
|
||||||
|
newInvalidAsn1Error: function (msg) {
|
||||||
|
var e = new Error();
|
||||||
|
e.name = 'InvalidAsn1Error';
|
||||||
|
e.message = msg || '';
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
|
@ -0,0 +1,27 @@
|
||||||
|
// Copyright 2011 Mark Cavage <mcavage@gmail.com> All rights reserved.
|
||||||
|
|
||||||
|
var errors = require('./errors');
|
||||||
|
var types = require('./types');
|
||||||
|
|
||||||
|
var Reader = require('./reader');
|
||||||
|
var Writer = require('./writer');
|
||||||
|
|
||||||
|
|
||||||
|
// --- Exports
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
|
||||||
|
Reader: Reader,
|
||||||
|
|
||||||
|
Writer: Writer
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
for (var t in types) {
|
||||||
|
if (types.hasOwnProperty(t))
|
||||||
|
module.exports[t] = types[t];
|
||||||
|
}
|
||||||
|
for (var e in errors) {
|
||||||
|
if (errors.hasOwnProperty(e))
|
||||||
|
module.exports[e] = errors[e];
|
||||||
|
}
|
|
@ -0,0 +1,262 @@
|
||||||
|
// Copyright 2011 Mark Cavage <mcavage@gmail.com> All rights reserved.
|
||||||
|
|
||||||
|
var assert = require('assert');
|
||||||
|
var Buffer = require('safer-buffer').Buffer;
|
||||||
|
|
||||||
|
var ASN1 = require('./types');
|
||||||
|
var errors = require('./errors');
|
||||||
|
|
||||||
|
|
||||||
|
// --- Globals
|
||||||
|
|
||||||
|
var newInvalidAsn1Error = errors.newInvalidAsn1Error;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// --- API
|
||||||
|
|
||||||
|
function Reader(data) {
|
||||||
|
if (!data || !Buffer.isBuffer(data))
|
||||||
|
throw new TypeError('data must be a node Buffer');
|
||||||
|
|
||||||
|
this._buf = data;
|
||||||
|
this._size = data.length;
|
||||||
|
|
||||||
|
// These hold the "current" state
|
||||||
|
this._len = 0;
|
||||||
|
this._offset = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.defineProperty(Reader.prototype, 'length', {
|
||||||
|
enumerable: true,
|
||||||
|
get: function () { return (this._len); }
|
||||||
|
});
|
||||||
|
|
||||||
|
Object.defineProperty(Reader.prototype, 'offset', {
|
||||||
|
enumerable: true,
|
||||||
|
get: function () { return (this._offset); }
|
||||||
|
});
|
||||||
|
|
||||||
|
Object.defineProperty(Reader.prototype, 'remain', {
|
||||||
|
get: function () { return (this._size - this._offset); }
|
||||||
|
});
|
||||||
|
|
||||||
|
Object.defineProperty(Reader.prototype, 'buffer', {
|
||||||
|
get: function () { return (this._buf.slice(this._offset)); }
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads a single byte and advances offset; you can pass in `true` to make this
|
||||||
|
* a "peek" operation (i.e., get the byte, but don't advance the offset).
|
||||||
|
*
|
||||||
|
* @param {Boolean} peek true means don't move offset.
|
||||||
|
* @return {Number} the next byte, null if not enough data.
|
||||||
|
*/
|
||||||
|
Reader.prototype.readByte = function (peek) {
|
||||||
|
if (this._size - this._offset < 1)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var b = this._buf[this._offset] & 0xff;
|
||||||
|
|
||||||
|
if (!peek)
|
||||||
|
this._offset += 1;
|
||||||
|
|
||||||
|
return b;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Reader.prototype.peek = function () {
|
||||||
|
return this.readByte(true);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads a (potentially) variable length off the BER buffer. This call is
|
||||||
|
* not really meant to be called directly, as callers have to manipulate
|
||||||
|
* the internal buffer afterwards.
|
||||||
|
*
|
||||||
|
* As a result of this call, you can call `Reader.length`, until the
|
||||||
|
* next thing called that does a readLength.
|
||||||
|
*
|
||||||
|
* @return {Number} the amount of offset to advance the buffer.
|
||||||
|
* @throws {InvalidAsn1Error} on bad ASN.1
|
||||||
|
*/
|
||||||
|
Reader.prototype.readLength = function (offset) {
|
||||||
|
if (offset === undefined)
|
||||||
|
offset = this._offset;
|
||||||
|
|
||||||
|
if (offset >= this._size)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var lenB = this._buf[offset++] & 0xff;
|
||||||
|
if (lenB === null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if ((lenB & 0x80) === 0x80) {
|
||||||
|
lenB &= 0x7f;
|
||||||
|
|
||||||
|
if (lenB === 0)
|
||||||
|
throw newInvalidAsn1Error('Indefinite length not supported');
|
||||||
|
|
||||||
|
if (lenB > 4)
|
||||||
|
throw newInvalidAsn1Error('encoding too long');
|
||||||
|
|
||||||
|
if (this._size - offset < lenB)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
this._len = 0;
|
||||||
|
for (var i = 0; i < lenB; i++)
|
||||||
|
this._len = (this._len << 8) + (this._buf[offset++] & 0xff);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// Wasn't a variable length
|
||||||
|
this._len = lenB;
|
||||||
|
}
|
||||||
|
|
||||||
|
return offset;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses the next sequence in this BER buffer.
|
||||||
|
*
|
||||||
|
* To get the length of the sequence, call `Reader.length`.
|
||||||
|
*
|
||||||
|
* @return {Number} the sequence's tag.
|
||||||
|
*/
|
||||||
|
Reader.prototype.readSequence = function (tag) {
|
||||||
|
var seq = this.peek();
|
||||||
|
if (seq === null)
|
||||||
|
return null;
|
||||||
|
if (tag !== undefined && tag !== seq)
|
||||||
|
throw newInvalidAsn1Error('Expected 0x' + tag.toString(16) +
|
||||||
|
': got 0x' + seq.toString(16));
|
||||||
|
|
||||||
|
var o = this.readLength(this._offset + 1); // stored in `length`
|
||||||
|
if (o === null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
this._offset = o;
|
||||||
|
return seq;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Reader.prototype.readInt = function () {
|
||||||
|
return this._readTag(ASN1.Integer);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Reader.prototype.readBoolean = function () {
|
||||||
|
return (this._readTag(ASN1.Boolean) === 0 ? false : true);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Reader.prototype.readEnumeration = function () {
|
||||||
|
return this._readTag(ASN1.Enumeration);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Reader.prototype.readString = function (tag, retbuf) {
|
||||||
|
if (!tag)
|
||||||
|
tag = ASN1.OctetString;
|
||||||
|
|
||||||
|
var b = this.peek();
|
||||||
|
if (b === null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if (b !== tag)
|
||||||
|
throw newInvalidAsn1Error('Expected 0x' + tag.toString(16) +
|
||||||
|
': got 0x' + b.toString(16));
|
||||||
|
|
||||||
|
var o = this.readLength(this._offset + 1); // stored in `length`
|
||||||
|
|
||||||
|
if (o === null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if (this.length > this._size - o)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
this._offset = o;
|
||||||
|
|
||||||
|
if (this.length === 0)
|
||||||
|
return retbuf ? Buffer.alloc(0) : '';
|
||||||
|
|
||||||
|
var str = this._buf.slice(this._offset, this._offset + this.length);
|
||||||
|
this._offset += this.length;
|
||||||
|
|
||||||
|
return retbuf ? str : str.toString('utf8');
|
||||||
|
};
|
||||||
|
|
||||||
|
Reader.prototype.readOID = function (tag) {
|
||||||
|
if (!tag)
|
||||||
|
tag = ASN1.OID;
|
||||||
|
|
||||||
|
var b = this.readString(tag, true);
|
||||||
|
if (b === null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
var values = [];
|
||||||
|
var value = 0;
|
||||||
|
|
||||||
|
for (var i = 0; i < b.length; i++) {
|
||||||
|
var byte = b[i] & 0xff;
|
||||||
|
|
||||||
|
value <<= 7;
|
||||||
|
value += byte & 0x7f;
|
||||||
|
if ((byte & 0x80) === 0) {
|
||||||
|
values.push(value);
|
||||||
|
value = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
value = values.shift();
|
||||||
|
values.unshift(value % 40);
|
||||||
|
values.unshift((value / 40) >> 0);
|
||||||
|
|
||||||
|
return values.join('.');
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Reader.prototype._readTag = function (tag) {
|
||||||
|
assert.ok(tag !== undefined);
|
||||||
|
|
||||||
|
var b = this.peek();
|
||||||
|
|
||||||
|
if (b === null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if (b !== tag)
|
||||||
|
throw newInvalidAsn1Error('Expected 0x' + tag.toString(16) +
|
||||||
|
': got 0x' + b.toString(16));
|
||||||
|
|
||||||
|
var o = this.readLength(this._offset + 1); // stored in `length`
|
||||||
|
if (o === null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if (this.length > 4)
|
||||||
|
throw newInvalidAsn1Error('Integer too long: ' + this.length);
|
||||||
|
|
||||||
|
if (this.length > this._size - o)
|
||||||
|
return null;
|
||||||
|
this._offset = o;
|
||||||
|
|
||||||
|
var fb = this._buf[this._offset];
|
||||||
|
var value = 0;
|
||||||
|
|
||||||
|
for (var i = 0; i < this.length; i++) {
|
||||||
|
value <<= 8;
|
||||||
|
value |= (this._buf[this._offset++] & 0xff);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((fb & 0x80) === 0x80 && i !== 4)
|
||||||
|
value -= (1 << (i * 8));
|
||||||
|
|
||||||
|
return value >> 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// --- Exported API
|
||||||
|
|
||||||
|
module.exports = Reader;
|
|
@ -0,0 +1,36 @@
|
||||||
|
// Copyright 2011 Mark Cavage <mcavage@gmail.com> All rights reserved.
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
EOC: 0,
|
||||||
|
Boolean: 1,
|
||||||
|
Integer: 2,
|
||||||
|
BitString: 3,
|
||||||
|
OctetString: 4,
|
||||||
|
Null: 5,
|
||||||
|
OID: 6,
|
||||||
|
ObjectDescriptor: 7,
|
||||||
|
External: 8,
|
||||||
|
Real: 9, // float
|
||||||
|
Enumeration: 10,
|
||||||
|
PDV: 11,
|
||||||
|
Utf8String: 12,
|
||||||
|
RelativeOID: 13,
|
||||||
|
Sequence: 16,
|
||||||
|
Set: 17,
|
||||||
|
NumericString: 18,
|
||||||
|
PrintableString: 19,
|
||||||
|
T61String: 20,
|
||||||
|
VideotexString: 21,
|
||||||
|
IA5String: 22,
|
||||||
|
UTCTime: 23,
|
||||||
|
GeneralizedTime: 24,
|
||||||
|
GraphicString: 25,
|
||||||
|
VisibleString: 26,
|
||||||
|
GeneralString: 28,
|
||||||
|
UniversalString: 29,
|
||||||
|
CharacterString: 30,
|
||||||
|
BMPString: 31,
|
||||||
|
Constructor: 32,
|
||||||
|
Context: 128
|
||||||
|
};
|
|
@ -0,0 +1,317 @@
|
||||||
|
// Copyright 2011 Mark Cavage <mcavage@gmail.com> All rights reserved.
|
||||||
|
|
||||||
|
var assert = require('assert');
|
||||||
|
var Buffer = require('safer-buffer').Buffer;
|
||||||
|
var ASN1 = require('./types');
|
||||||
|
var errors = require('./errors');
|
||||||
|
|
||||||
|
|
||||||
|
// --- Globals
|
||||||
|
|
||||||
|
var newInvalidAsn1Error = errors.newInvalidAsn1Error;
|
||||||
|
|
||||||
|
var DEFAULT_OPTS = {
|
||||||
|
size: 1024,
|
||||||
|
growthFactor: 8
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// --- Helpers
|
||||||
|
|
||||||
|
function merge(from, to) {
|
||||||
|
assert.ok(from);
|
||||||
|
assert.equal(typeof (from), 'object');
|
||||||
|
assert.ok(to);
|
||||||
|
assert.equal(typeof (to), 'object');
|
||||||
|
|
||||||
|
var keys = Object.getOwnPropertyNames(from);
|
||||||
|
keys.forEach(function (key) {
|
||||||
|
if (to[key])
|
||||||
|
return;
|
||||||
|
|
||||||
|
var value = Object.getOwnPropertyDescriptor(from, key);
|
||||||
|
Object.defineProperty(to, key, value);
|
||||||
|
});
|
||||||
|
|
||||||
|
return to;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// --- API
|
||||||
|
|
||||||
|
function Writer(options) {
|
||||||
|
options = merge(DEFAULT_OPTS, options || {});
|
||||||
|
|
||||||
|
this._buf = Buffer.alloc(options.size || 1024);
|
||||||
|
this._size = this._buf.length;
|
||||||
|
this._offset = 0;
|
||||||
|
this._options = options;
|
||||||
|
|
||||||
|
// A list of offsets in the buffer where we need to insert
|
||||||
|
// sequence tag/len pairs.
|
||||||
|
this._seq = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.defineProperty(Writer.prototype, 'buffer', {
|
||||||
|
get: function () {
|
||||||
|
if (this._seq.length)
|
||||||
|
throw newInvalidAsn1Error(this._seq.length + ' unended sequence(s)');
|
||||||
|
|
||||||
|
return (this._buf.slice(0, this._offset));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Writer.prototype.writeByte = function (b) {
|
||||||
|
if (typeof (b) !== 'number')
|
||||||
|
throw new TypeError('argument must be a Number');
|
||||||
|
|
||||||
|
this._ensure(1);
|
||||||
|
this._buf[this._offset++] = b;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Writer.prototype.writeInt = function (i, tag) {
|
||||||
|
if (typeof (i) !== 'number')
|
||||||
|
throw new TypeError('argument must be a Number');
|
||||||
|
if (typeof (tag) !== 'number')
|
||||||
|
tag = ASN1.Integer;
|
||||||
|
|
||||||
|
var sz = 4;
|
||||||
|
|
||||||
|
while ((((i & 0xff800000) === 0) || ((i & 0xff800000) === 0xff800000 >> 0)) &&
|
||||||
|
(sz > 1)) {
|
||||||
|
sz--;
|
||||||
|
i <<= 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sz > 4)
|
||||||
|
throw newInvalidAsn1Error('BER ints cannot be > 0xffffffff');
|
||||||
|
|
||||||
|
this._ensure(2 + sz);
|
||||||
|
this._buf[this._offset++] = tag;
|
||||||
|
this._buf[this._offset++] = sz;
|
||||||
|
|
||||||
|
while (sz-- > 0) {
|
||||||
|
this._buf[this._offset++] = ((i & 0xff000000) >>> 24);
|
||||||
|
i <<= 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Writer.prototype.writeNull = function () {
|
||||||
|
this.writeByte(ASN1.Null);
|
||||||
|
this.writeByte(0x00);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Writer.prototype.writeEnumeration = function (i, tag) {
|
||||||
|
if (typeof (i) !== 'number')
|
||||||
|
throw new TypeError('argument must be a Number');
|
||||||
|
if (typeof (tag) !== 'number')
|
||||||
|
tag = ASN1.Enumeration;
|
||||||
|
|
||||||
|
return this.writeInt(i, tag);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Writer.prototype.writeBoolean = function (b, tag) {
|
||||||
|
if (typeof (b) !== 'boolean')
|
||||||
|
throw new TypeError('argument must be a Boolean');
|
||||||
|
if (typeof (tag) !== 'number')
|
||||||
|
tag = ASN1.Boolean;
|
||||||
|
|
||||||
|
this._ensure(3);
|
||||||
|
this._buf[this._offset++] = tag;
|
||||||
|
this._buf[this._offset++] = 0x01;
|
||||||
|
this._buf[this._offset++] = b ? 0xff : 0x00;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Writer.prototype.writeString = function (s, tag) {
|
||||||
|
if (typeof (s) !== 'string')
|
||||||
|
throw new TypeError('argument must be a string (was: ' + typeof (s) + ')');
|
||||||
|
if (typeof (tag) !== 'number')
|
||||||
|
tag = ASN1.OctetString;
|
||||||
|
|
||||||
|
var len = Buffer.byteLength(s);
|
||||||
|
this.writeByte(tag);
|
||||||
|
this.writeLength(len);
|
||||||
|
if (len) {
|
||||||
|
this._ensure(len);
|
||||||
|
this._buf.write(s, this._offset);
|
||||||
|
this._offset += len;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Writer.prototype.writeBuffer = function (buf, tag) {
|
||||||
|
if (typeof (tag) !== 'number')
|
||||||
|
throw new TypeError('tag must be a number');
|
||||||
|
if (!Buffer.isBuffer(buf))
|
||||||
|
throw new TypeError('argument must be a buffer');
|
||||||
|
|
||||||
|
this.writeByte(tag);
|
||||||
|
this.writeLength(buf.length);
|
||||||
|
this._ensure(buf.length);
|
||||||
|
buf.copy(this._buf, this._offset, 0, buf.length);
|
||||||
|
this._offset += buf.length;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Writer.prototype.writeStringArray = function (strings) {
|
||||||
|
if ((!strings instanceof Array))
|
||||||
|
throw new TypeError('argument must be an Array[String]');
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
strings.forEach(function (s) {
|
||||||
|
self.writeString(s);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// This is really to solve DER cases, but whatever for now
|
||||||
|
Writer.prototype.writeOID = function (s, tag) {
|
||||||
|
if (typeof (s) !== 'string')
|
||||||
|
throw new TypeError('argument must be a string');
|
||||||
|
if (typeof (tag) !== 'number')
|
||||||
|
tag = ASN1.OID;
|
||||||
|
|
||||||
|
if (!/^([0-9]+\.){3,}[0-9]+$/.test(s))
|
||||||
|
throw new Error('argument is not a valid OID string');
|
||||||
|
|
||||||
|
function encodeOctet(bytes, octet) {
|
||||||
|
if (octet < 128) {
|
||||||
|
bytes.push(octet);
|
||||||
|
} else if (octet < 16384) {
|
||||||
|
bytes.push((octet >>> 7) | 0x80);
|
||||||
|
bytes.push(octet & 0x7F);
|
||||||
|
} else if (octet < 2097152) {
|
||||||
|
bytes.push((octet >>> 14) | 0x80);
|
||||||
|
bytes.push(((octet >>> 7) | 0x80) & 0xFF);
|
||||||
|
bytes.push(octet & 0x7F);
|
||||||
|
} else if (octet < 268435456) {
|
||||||
|
bytes.push((octet >>> 21) | 0x80);
|
||||||
|
bytes.push(((octet >>> 14) | 0x80) & 0xFF);
|
||||||
|
bytes.push(((octet >>> 7) | 0x80) & 0xFF);
|
||||||
|
bytes.push(octet & 0x7F);
|
||||||
|
} else {
|
||||||
|
bytes.push(((octet >>> 28) | 0x80) & 0xFF);
|
||||||
|
bytes.push(((octet >>> 21) | 0x80) & 0xFF);
|
||||||
|
bytes.push(((octet >>> 14) | 0x80) & 0xFF);
|
||||||
|
bytes.push(((octet >>> 7) | 0x80) & 0xFF);
|
||||||
|
bytes.push(octet & 0x7F);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var tmp = s.split('.');
|
||||||
|
var bytes = [];
|
||||||
|
bytes.push(parseInt(tmp[0], 10) * 40 + parseInt(tmp[1], 10));
|
||||||
|
tmp.slice(2).forEach(function (b) {
|
||||||
|
encodeOctet(bytes, parseInt(b, 10));
|
||||||
|
});
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
this._ensure(2 + bytes.length);
|
||||||
|
this.writeByte(tag);
|
||||||
|
this.writeLength(bytes.length);
|
||||||
|
bytes.forEach(function (b) {
|
||||||
|
self.writeByte(b);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Writer.prototype.writeLength = function (len) {
|
||||||
|
if (typeof (len) !== 'number')
|
||||||
|
throw new TypeError('argument must be a Number');
|
||||||
|
|
||||||
|
this._ensure(4);
|
||||||
|
|
||||||
|
if (len <= 0x7f) {
|
||||||
|
this._buf[this._offset++] = len;
|
||||||
|
} else if (len <= 0xff) {
|
||||||
|
this._buf[this._offset++] = 0x81;
|
||||||
|
this._buf[this._offset++] = len;
|
||||||
|
} else if (len <= 0xffff) {
|
||||||
|
this._buf[this._offset++] = 0x82;
|
||||||
|
this._buf[this._offset++] = len >> 8;
|
||||||
|
this._buf[this._offset++] = len;
|
||||||
|
} else if (len <= 0xffffff) {
|
||||||
|
this._buf[this._offset++] = 0x83;
|
||||||
|
this._buf[this._offset++] = len >> 16;
|
||||||
|
this._buf[this._offset++] = len >> 8;
|
||||||
|
this._buf[this._offset++] = len;
|
||||||
|
} else {
|
||||||
|
throw newInvalidAsn1Error('Length too long (> 4 bytes)');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Writer.prototype.startSequence = function (tag) {
|
||||||
|
if (typeof (tag) !== 'number')
|
||||||
|
tag = ASN1.Sequence | ASN1.Constructor;
|
||||||
|
|
||||||
|
this.writeByte(tag);
|
||||||
|
this._seq.push(this._offset);
|
||||||
|
this._ensure(3);
|
||||||
|
this._offset += 3;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Writer.prototype.endSequence = function () {
|
||||||
|
var seq = this._seq.pop();
|
||||||
|
var start = seq + 3;
|
||||||
|
var len = this._offset - start;
|
||||||
|
|
||||||
|
if (len <= 0x7f) {
|
||||||
|
this._shift(start, len, -2);
|
||||||
|
this._buf[seq] = len;
|
||||||
|
} else if (len <= 0xff) {
|
||||||
|
this._shift(start, len, -1);
|
||||||
|
this._buf[seq] = 0x81;
|
||||||
|
this._buf[seq + 1] = len;
|
||||||
|
} else if (len <= 0xffff) {
|
||||||
|
this._buf[seq] = 0x82;
|
||||||
|
this._buf[seq + 1] = len >> 8;
|
||||||
|
this._buf[seq + 2] = len;
|
||||||
|
} else if (len <= 0xffffff) {
|
||||||
|
this._shift(start, len, 1);
|
||||||
|
this._buf[seq] = 0x83;
|
||||||
|
this._buf[seq + 1] = len >> 16;
|
||||||
|
this._buf[seq + 2] = len >> 8;
|
||||||
|
this._buf[seq + 3] = len;
|
||||||
|
} else {
|
||||||
|
throw newInvalidAsn1Error('Sequence too long');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Writer.prototype._shift = function (start, len, shift) {
|
||||||
|
assert.ok(start !== undefined);
|
||||||
|
assert.ok(len !== undefined);
|
||||||
|
assert.ok(shift);
|
||||||
|
|
||||||
|
this._buf.copy(this._buf, start + shift, start, start + len);
|
||||||
|
this._offset += shift;
|
||||||
|
};
|
||||||
|
|
||||||
|
Writer.prototype._ensure = function (len) {
|
||||||
|
assert.ok(len);
|
||||||
|
|
||||||
|
if (this._size - this._offset < len) {
|
||||||
|
var sz = this._size * this._options.growthFactor;
|
||||||
|
if (sz - this._offset < len)
|
||||||
|
sz += len;
|
||||||
|
|
||||||
|
var buf = Buffer.alloc(sz);
|
||||||
|
|
||||||
|
this._buf.copy(buf, 0, 0, this._offset);
|
||||||
|
this._buf = buf;
|
||||||
|
this._size = sz;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// --- Exported API
|
||||||
|
|
||||||
|
module.exports = Writer;
|
|
@ -0,0 +1,20 @@
|
||||||
|
// Copyright 2011 Mark Cavage <mcavage@gmail.com> All rights reserved.
|
||||||
|
|
||||||
|
// If you have no idea what ASN.1 or BER is, see this:
|
||||||
|
// ftp://ftp.rsa.com/pub/pkcs/ascii/layman.asc
|
||||||
|
|
||||||
|
var Ber = require('./ber/index');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// --- Exported API
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
|
||||||
|
Ber: Ber,
|
||||||
|
|
||||||
|
BerReader: Ber.Reader,
|
||||||
|
|
||||||
|
BerWriter: Ber.Writer
|
||||||
|
|
||||||
|
};
|
|
@ -0,0 +1,75 @@
|
||||||
|
{
|
||||||
|
"_from": "asn1@~0.2.0",
|
||||||
|
"_id": "asn1@0.2.4",
|
||||||
|
"_inBundle": false,
|
||||||
|
"_integrity": "sha512-jxwzQpLQjSmWXgwaCZE9Nz+glAG01yF1QnWgbhGwHI5A6FRIEY6IVqtHhIepHqI7/kyEyQEagBC5mBEFlIYvdg==",
|
||||||
|
"_location": "/asn1",
|
||||||
|
"_phantomChildren": {},
|
||||||
|
"_requested": {
|
||||||
|
"type": "range",
|
||||||
|
"registry": true,
|
||||||
|
"raw": "asn1@~0.2.0",
|
||||||
|
"name": "asn1",
|
||||||
|
"escapedName": "asn1",
|
||||||
|
"rawSpec": "~0.2.0",
|
||||||
|
"saveSpec": null,
|
||||||
|
"fetchSpec": "~0.2.0"
|
||||||
|
},
|
||||||
|
"_requiredBy": [
|
||||||
|
"/ssh2-streams"
|
||||||
|
],
|
||||||
|
"_resolved": "https://registry.npmjs.org/asn1/-/asn1-0.2.4.tgz",
|
||||||
|
"_shasum": "8d2475dfab553bb33e77b54e59e880bb8ce23136",
|
||||||
|
"_spec": "asn1@~0.2.0",
|
||||||
|
"_where": "/Users/keiferju/code/Lingtu/smx-svelma/upload/node_modules/ssh2-streams",
|
||||||
|
"author": {
|
||||||
|
"name": "Joyent",
|
||||||
|
"url": "joyent.com"
|
||||||
|
},
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/joyent/node-asn1/issues"
|
||||||
|
},
|
||||||
|
"bundleDependencies": false,
|
||||||
|
"contributors": [
|
||||||
|
{
|
||||||
|
"name": "Mark Cavage",
|
||||||
|
"email": "mcavage@gmail.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "David Gwynne",
|
||||||
|
"email": "loki@animata.net"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Yunong Xiao",
|
||||||
|
"email": "yunong@joyent.com"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Alex Wilson",
|
||||||
|
"email": "alex.wilson@joyent.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"dependencies": {
|
||||||
|
"safer-buffer": "~2.1.0"
|
||||||
|
},
|
||||||
|
"deprecated": false,
|
||||||
|
"description": "Contains parsers and serializers for ASN.1 (currently BER only)",
|
||||||
|
"devDependencies": {
|
||||||
|
"eslint": "2.13.1",
|
||||||
|
"eslint-plugin-joyent": "~1.3.0",
|
||||||
|
"faucet": "0.0.1",
|
||||||
|
"istanbul": "^0.3.6",
|
||||||
|
"tape": "^3.5.0"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/joyent/node-asn1#readme",
|
||||||
|
"license": "MIT",
|
||||||
|
"main": "lib/index.js",
|
||||||
|
"name": "asn1",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git://github.com/joyent/node-asn1.git"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "tape ./test/ber/*.test.js"
|
||||||
|
},
|
||||||
|
"version": "0.2.4"
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
test
|
||||||
|
.gitignore
|
||||||
|
.travis.yml
|
||||||
|
Makefile
|
||||||
|
example.js
|
|
@ -0,0 +1,21 @@
|
||||||
|
(MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2013 Julian Gruber <julian@juliangruber.com>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
|
@ -0,0 +1,91 @@
|
||||||
|
# balanced-match
|
||||||
|
|
||||||
|
Match balanced string pairs, like `{` and `}` or `<b>` and `</b>`. Supports regular expressions as well!
|
||||||
|
|
||||||
|
[](http://travis-ci.org/juliangruber/balanced-match)
|
||||||
|
[](https://www.npmjs.org/package/balanced-match)
|
||||||
|
|
||||||
|
[](https://ci.testling.com/juliangruber/balanced-match)
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
Get the first matching pair of braces:
|
||||||
|
|
||||||
|
```js
|
||||||
|
var balanced = require('balanced-match');
|
||||||
|
|
||||||
|
console.log(balanced('{', '}', 'pre{in{nested}}post'));
|
||||||
|
console.log(balanced('{', '}', 'pre{first}between{second}post'));
|
||||||
|
console.log(balanced(/\s+\{\s+/, /\s+\}\s+/, 'pre { in{nest} } post'));
|
||||||
|
```
|
||||||
|
|
||||||
|
The matches are:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ node example.js
|
||||||
|
{ start: 3, end: 14, pre: 'pre', body: 'in{nested}', post: 'post' }
|
||||||
|
{ start: 3,
|
||||||
|
end: 9,
|
||||||
|
pre: 'pre',
|
||||||
|
body: 'first',
|
||||||
|
post: 'between{second}post' }
|
||||||
|
{ start: 3, end: 17, pre: 'pre', body: 'in{nest}', post: 'post' }
|
||||||
|
```
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
|
### var m = balanced(a, b, str)
|
||||||
|
|
||||||
|
For the first non-nested matching pair of `a` and `b` in `str`, return an
|
||||||
|
object with those keys:
|
||||||
|
|
||||||
|
* **start** the index of the first match of `a`
|
||||||
|
* **end** the index of the matching `b`
|
||||||
|
* **pre** the preamble, `a` and `b` not included
|
||||||
|
* **body** the match, `a` and `b` not included
|
||||||
|
* **post** the postscript, `a` and `b` not included
|
||||||
|
|
||||||
|
If there's no match, `undefined` will be returned.
|
||||||
|
|
||||||
|
If the `str` contains more `a` than `b` / there are unmatched pairs, the first match that was closed will be used. For example, `{{a}` will match `['{', 'a', '']` and `{a}}` will match `['', 'a', '}']`.
|
||||||
|
|
||||||
|
### var r = balanced.range(a, b, str)
|
||||||
|
|
||||||
|
For the first non-nested matching pair of `a` and `b` in `str`, return an
|
||||||
|
array with indexes: `[ <a index>, <b index> ]`.
|
||||||
|
|
||||||
|
If there's no match, `undefined` will be returned.
|
||||||
|
|
||||||
|
If the `str` contains more `a` than `b` / there are unmatched pairs, the first match that was closed will be used. For example, `{{a}` will match `[ 1, 3 ]` and `{a}}` will match `[0, 2]`.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
With [npm](https://npmjs.org) do:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm install balanced-match
|
||||||
|
```
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
(MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2013 Julian Gruber <julian@juliangruber.com>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
|
@ -0,0 +1,59 @@
|
||||||
|
'use strict';
|
||||||
|
module.exports = balanced;
|
||||||
|
function balanced(a, b, str) {
|
||||||
|
if (a instanceof RegExp) a = maybeMatch(a, str);
|
||||||
|
if (b instanceof RegExp) b = maybeMatch(b, str);
|
||||||
|
|
||||||
|
var r = range(a, b, str);
|
||||||
|
|
||||||
|
return r && {
|
||||||
|
start: r[0],
|
||||||
|
end: r[1],
|
||||||
|
pre: str.slice(0, r[0]),
|
||||||
|
body: str.slice(r[0] + a.length, r[1]),
|
||||||
|
post: str.slice(r[1] + b.length)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function maybeMatch(reg, str) {
|
||||||
|
var m = str.match(reg);
|
||||||
|
return m ? m[0] : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
balanced.range = range;
|
||||||
|
function range(a, b, str) {
|
||||||
|
var begs, beg, left, right, result;
|
||||||
|
var ai = str.indexOf(a);
|
||||||
|
var bi = str.indexOf(b, ai + 1);
|
||||||
|
var i = ai;
|
||||||
|
|
||||||
|
if (ai >= 0 && bi > 0) {
|
||||||
|
begs = [];
|
||||||
|
left = str.length;
|
||||||
|
|
||||||
|
while (i >= 0 && !result) {
|
||||||
|
if (i == ai) {
|
||||||
|
begs.push(i);
|
||||||
|
ai = str.indexOf(a, i + 1);
|
||||||
|
} else if (begs.length == 1) {
|
||||||
|
result = [ begs.pop(), bi ];
|
||||||
|
} else {
|
||||||
|
beg = begs.pop();
|
||||||
|
if (beg < left) {
|
||||||
|
left = beg;
|
||||||
|
right = bi;
|
||||||
|
}
|
||||||
|
|
||||||
|
bi = str.indexOf(b, i + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
i = ai < bi && ai >= 0 ? ai : bi;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (begs.length) {
|
||||||
|
result = [ left, right ];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
|
@ -0,0 +1,77 @@
|
||||||
|
{
|
||||||
|
"_from": "balanced-match@^1.0.0",
|
||||||
|
"_id": "balanced-match@1.0.0",
|
||||||
|
"_inBundle": false,
|
||||||
|
"_integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=",
|
||||||
|
"_location": "/balanced-match",
|
||||||
|
"_phantomChildren": {},
|
||||||
|
"_requested": {
|
||||||
|
"type": "range",
|
||||||
|
"registry": true,
|
||||||
|
"raw": "balanced-match@^1.0.0",
|
||||||
|
"name": "balanced-match",
|
||||||
|
"escapedName": "balanced-match",
|
||||||
|
"rawSpec": "^1.0.0",
|
||||||
|
"saveSpec": null,
|
||||||
|
"fetchSpec": "^1.0.0"
|
||||||
|
},
|
||||||
|
"_requiredBy": [
|
||||||
|
"/brace-expansion"
|
||||||
|
],
|
||||||
|
"_resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz",
|
||||||
|
"_shasum": "89b4d199ab2bee49de164ea02b89ce462d71b767",
|
||||||
|
"_spec": "balanced-match@^1.0.0",
|
||||||
|
"_where": "/Users/keiferju/code/Lingtu/smx-svelma/upload/node_modules/brace-expansion",
|
||||||
|
"author": {
|
||||||
|
"name": "Julian Gruber",
|
||||||
|
"email": "mail@juliangruber.com",
|
||||||
|
"url": "http://juliangruber.com"
|
||||||
|
},
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/juliangruber/balanced-match/issues"
|
||||||
|
},
|
||||||
|
"bundleDependencies": false,
|
||||||
|
"dependencies": {},
|
||||||
|
"deprecated": false,
|
||||||
|
"description": "Match balanced character pairs, like \"{\" and \"}\"",
|
||||||
|
"devDependencies": {
|
||||||
|
"matcha": "^0.7.0",
|
||||||
|
"tape": "^4.6.0"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/juliangruber/balanced-match",
|
||||||
|
"keywords": [
|
||||||
|
"match",
|
||||||
|
"regexp",
|
||||||
|
"test",
|
||||||
|
"balanced",
|
||||||
|
"parse"
|
||||||
|
],
|
||||||
|
"license": "MIT",
|
||||||
|
"main": "index.js",
|
||||||
|
"name": "balanced-match",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git://github.com/juliangruber/balanced-match.git"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"bench": "make bench",
|
||||||
|
"test": "make test"
|
||||||
|
},
|
||||||
|
"testling": {
|
||||||
|
"files": "test/*.js",
|
||||||
|
"browsers": [
|
||||||
|
"ie/8..latest",
|
||||||
|
"firefox/20..latest",
|
||||||
|
"firefox/nightly",
|
||||||
|
"chrome/25..latest",
|
||||||
|
"chrome/canary",
|
||||||
|
"opera/12..latest",
|
||||||
|
"opera/next",
|
||||||
|
"safari/5.1..latest",
|
||||||
|
"ipad/6.0..latest",
|
||||||
|
"iphone/6.0..latest",
|
||||||
|
"android-browser/4.2..latest"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"version": "1.0.0"
|
||||||
|
}
|
|
@ -0,0 +1,13 @@
|
||||||
|
# Contributing
|
||||||
|
|
||||||
|
This repository uses [cr.joyent.us](https://cr.joyent.us) (Gerrit) for new
|
||||||
|
changes. Anyone can submit changes. To get started, see the [cr.joyent.us user
|
||||||
|
guide](https://github.com/joyent/joyent-gerrit/blob/master/docs/user/README.md).
|
||||||
|
This repo does not use GitHub pull requests.
|
||||||
|
|
||||||
|
See the [Joyent Engineering
|
||||||
|
Guidelines](https://github.com/joyent/eng/blob/master/docs/index.md) for general
|
||||||
|
best practices expected in this repository.
|
||||||
|
|
||||||
|
If you're changing something non-trivial or user-facing, you may want to submit
|
||||||
|
an issue first.
|
|
@ -0,0 +1,66 @@
|
||||||
|
The Blowfish portions are under the following license:
|
||||||
|
|
||||||
|
Blowfish block cipher for OpenBSD
|
||||||
|
Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Implementation advice by David Mazieres <dm@lcs.mit.edu>.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions
|
||||||
|
are met:
|
||||||
|
1. Redistributions of source code must retain the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer.
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
notice, this list of conditions and the following disclaimer in the
|
||||||
|
documentation and/or other materials provided with the distribution.
|
||||||
|
3. The name of the author may not be used to endorse or promote products
|
||||||
|
derived from this software without specific prior written permission.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
The bcrypt_pbkdf portions are under the following license:
|
||||||
|
|
||||||
|
Copyright (c) 2013 Ted Unangst <tedu@openbsd.org>
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and distribute this software for any
|
||||||
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
|
copyright notice and this permission notice appear in all copies.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Performance improvements (Javascript-specific):
|
||||||
|
|
||||||
|
Copyright 2016, Joyent Inc
|
||||||
|
Author: Alex Wilson <alex.wilson@joyent.com>
|
||||||
|
|
||||||
|
Permission to use, copy, modify, and distribute this software for any
|
||||||
|
purpose with or without fee is hereby granted, provided that the above
|
||||||
|
copyright notice and this permission notice appear in all copies.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
@ -0,0 +1,45 @@
|
||||||
|
Port of the OpenBSD `bcrypt_pbkdf` function to pure Javascript. `npm`-ified
|
||||||
|
version of [Devi Mandiri's port](https://github.com/devi/tmp/blob/master/js/bcrypt_pbkdf.js),
|
||||||
|
with some minor performance improvements. The code is copied verbatim (and
|
||||||
|
un-styled) from Devi's work.
|
||||||
|
|
||||||
|
This product includes software developed by Niels Provos.
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
|
### `bcrypt_pbkdf.pbkdf(pass, passlen, salt, saltlen, key, keylen, rounds)`
|
||||||
|
|
||||||
|
Derive a cryptographic key of arbitrary length from a given password and salt,
|
||||||
|
using the OpenBSD `bcrypt_pbkdf` function. This is a combination of Blowfish and
|
||||||
|
SHA-512.
|
||||||
|
|
||||||
|
See [this article](http://www.tedunangst.com/flak/post/bcrypt-pbkdf) for
|
||||||
|
further information.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
|
||||||
|
* `pass`, a Uint8Array of length `passlen`
|
||||||
|
* `passlen`, an integer Number
|
||||||
|
* `salt`, a Uint8Array of length `saltlen`
|
||||||
|
* `saltlen`, an integer Number
|
||||||
|
* `key`, a Uint8Array of length `keylen`, will be filled with output
|
||||||
|
* `keylen`, an integer Number
|
||||||
|
* `rounds`, an integer Number, number of rounds of the PBKDF to run
|
||||||
|
|
||||||
|
### `bcrypt_pbkdf.hash(sha2pass, sha2salt, out)`
|
||||||
|
|
||||||
|
Calculate a Blowfish hash, given SHA2-512 output of a password and salt. Used as
|
||||||
|
part of the inner round function in the PBKDF.
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
|
||||||
|
* `sha2pass`, a Uint8Array of length 64
|
||||||
|
* `sha2salt`, a Uint8Array of length 64
|
||||||
|
* `out`, a Uint8Array of length 32, will be filled with output
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
This source form is a 1:1 port from the OpenBSD `blowfish.c` and `bcrypt_pbkdf.c`.
|
||||||
|
As a result, it retains the original copyright and license. The two files are
|
||||||
|
under slightly different (but compatible) licenses, and are here combined in
|
||||||
|
one file. For each of the full license texts see `LICENSE`.
|
|
@ -0,0 +1,556 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var crypto_hash_sha512 = require('tweetnacl').lowlevel.crypto_hash;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is a 1:1 port from the OpenBSD blowfish.c and bcrypt_pbkdf.c. As a
|
||||||
|
* result, it retains the original copyright and license. The two files are
|
||||||
|
* under slightly different (but compatible) licenses, and are here combined in
|
||||||
|
* one file.
|
||||||
|
*
|
||||||
|
* Credit for the actual porting work goes to:
|
||||||
|
* Devi Mandiri <me@devi.web.id>
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The Blowfish portions are under the following license:
|
||||||
|
*
|
||||||
|
* Blowfish block cipher for OpenBSD
|
||||||
|
* Copyright 1997 Niels Provos <provos@physnet.uni-hamburg.de>
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Implementation advice by David Mazieres <dm@lcs.mit.edu>.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions
|
||||||
|
* are met:
|
||||||
|
* 1. Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* 3. The name of the author may not be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||||
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||||
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||||
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||||
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The bcrypt_pbkdf portions are under the following license:
|
||||||
|
*
|
||||||
|
* Copyright (c) 2013 Ted Unangst <tedu@openbsd.org>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Performance improvements (Javascript-specific):
|
||||||
|
*
|
||||||
|
* Copyright 2016, Joyent Inc
|
||||||
|
* Author: Alex Wilson <alex.wilson@joyent.com>
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
* copyright notice and this permission notice appear in all copies.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
// Ported from OpenBSD bcrypt_pbkdf.c v1.9
|
||||||
|
|
||||||
|
var BLF_J = 0;
|
||||||
|
|
||||||
|
var Blowfish = function() {
|
||||||
|
this.S = [
|
||||||
|
new Uint32Array([
|
||||||
|
0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7,
|
||||||
|
0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
|
||||||
|
0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16,
|
||||||
|
0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
|
||||||
|
0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee,
|
||||||
|
0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
|
||||||
|
0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef,
|
||||||
|
0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e,
|
||||||
|
0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60,
|
||||||
|
0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440,
|
||||||
|
0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce,
|
||||||
|
0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
|
||||||
|
0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e,
|
||||||
|
0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677,
|
||||||
|
0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193,
|
||||||
|
0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032,
|
||||||
|
0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88,
|
||||||
|
0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
|
||||||
|
0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e,
|
||||||
|
0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0,
|
||||||
|
0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3,
|
||||||
|
0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98,
|
||||||
|
0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88,
|
||||||
|
0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
|
||||||
|
0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6,
|
||||||
|
0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d,
|
||||||
|
0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b,
|
||||||
|
0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7,
|
||||||
|
0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba,
|
||||||
|
0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
|
||||||
|
0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f,
|
||||||
|
0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09,
|
||||||
|
0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3,
|
||||||
|
0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb,
|
||||||
|
0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279,
|
||||||
|
0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
|
||||||
|
0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab,
|
||||||
|
0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82,
|
||||||
|
0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db,
|
||||||
|
0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573,
|
||||||
|
0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0,
|
||||||
|
0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
|
||||||
|
0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790,
|
||||||
|
0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8,
|
||||||
|
0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4,
|
||||||
|
0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0,
|
||||||
|
0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7,
|
||||||
|
0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
|
||||||
|
0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad,
|
||||||
|
0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1,
|
||||||
|
0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299,
|
||||||
|
0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9,
|
||||||
|
0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477,
|
||||||
|
0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
|
||||||
|
0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49,
|
||||||
|
0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af,
|
||||||
|
0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa,
|
||||||
|
0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5,
|
||||||
|
0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41,
|
||||||
|
0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
|
||||||
|
0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400,
|
||||||
|
0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
|
||||||
|
0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664,
|
||||||
|
0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a]),
|
||||||
|
new Uint32Array([
|
||||||
|
0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623,
|
||||||
|
0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
|
||||||
|
0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1,
|
||||||
|
0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
|
||||||
|
0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6,
|
||||||
|
0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
|
||||||
|
0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e,
|
||||||
|
0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1,
|
||||||
|
0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737,
|
||||||
|
0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8,
|
||||||
|
0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff,
|
||||||
|
0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
|
||||||
|
0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701,
|
||||||
|
0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7,
|
||||||
|
0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41,
|
||||||
|
0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331,
|
||||||
|
0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf,
|
||||||
|
0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
|
||||||
|
0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e,
|
||||||
|
0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87,
|
||||||
|
0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c,
|
||||||
|
0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2,
|
||||||
|
0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16,
|
||||||
|
0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
|
||||||
|
0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b,
|
||||||
|
0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509,
|
||||||
|
0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e,
|
||||||
|
0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3,
|
||||||
|
0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f,
|
||||||
|
0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
|
||||||
|
0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4,
|
||||||
|
0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960,
|
||||||
|
0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66,
|
||||||
|
0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28,
|
||||||
|
0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802,
|
||||||
|
0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
|
||||||
|
0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510,
|
||||||
|
0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf,
|
||||||
|
0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14,
|
||||||
|
0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e,
|
||||||
|
0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50,
|
||||||
|
0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
|
||||||
|
0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8,
|
||||||
|
0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281,
|
||||||
|
0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99,
|
||||||
|
0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696,
|
||||||
|
0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128,
|
||||||
|
0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
|
||||||
|
0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0,
|
||||||
|
0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0,
|
||||||
|
0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105,
|
||||||
|
0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250,
|
||||||
|
0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3,
|
||||||
|
0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
|
||||||
|
0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00,
|
||||||
|
0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061,
|
||||||
|
0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb,
|
||||||
|
0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e,
|
||||||
|
0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735,
|
||||||
|
0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
|
||||||
|
0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9,
|
||||||
|
0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
|
||||||
|
0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20,
|
||||||
|
0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7]),
|
||||||
|
new Uint32Array([
|
||||||
|
0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934,
|
||||||
|
0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
|
||||||
|
0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af,
|
||||||
|
0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
|
||||||
|
0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45,
|
||||||
|
0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
|
||||||
|
0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a,
|
||||||
|
0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb,
|
||||||
|
0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee,
|
||||||
|
0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6,
|
||||||
|
0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42,
|
||||||
|
0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
|
||||||
|
0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2,
|
||||||
|
0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb,
|
||||||
|
0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527,
|
||||||
|
0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b,
|
||||||
|
0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33,
|
||||||
|
0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
|
||||||
|
0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3,
|
||||||
|
0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc,
|
||||||
|
0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17,
|
||||||
|
0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564,
|
||||||
|
0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b,
|
||||||
|
0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
|
||||||
|
0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922,
|
||||||
|
0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728,
|
||||||
|
0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0,
|
||||||
|
0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e,
|
||||||
|
0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37,
|
||||||
|
0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
|
||||||
|
0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804,
|
||||||
|
0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b,
|
||||||
|
0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3,
|
||||||
|
0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb,
|
||||||
|
0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d,
|
||||||
|
0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
|
||||||
|
0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350,
|
||||||
|
0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9,
|
||||||
|
0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a,
|
||||||
|
0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe,
|
||||||
|
0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d,
|
||||||
|
0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
|
||||||
|
0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f,
|
||||||
|
0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61,
|
||||||
|
0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2,
|
||||||
|
0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9,
|
||||||
|
0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2,
|
||||||
|
0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
|
||||||
|
0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e,
|
||||||
|
0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633,
|
||||||
|
0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10,
|
||||||
|
0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169,
|
||||||
|
0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52,
|
||||||
|
0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
|
||||||
|
0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5,
|
||||||
|
0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62,
|
||||||
|
0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634,
|
||||||
|
0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76,
|
||||||
|
0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24,
|
||||||
|
0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
|
||||||
|
0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4,
|
||||||
|
0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
|
||||||
|
0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837,
|
||||||
|
0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0]),
|
||||||
|
new Uint32Array([
|
||||||
|
0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b,
|
||||||
|
0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
|
||||||
|
0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b,
|
||||||
|
0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
|
||||||
|
0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8,
|
||||||
|
0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
|
||||||
|
0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304,
|
||||||
|
0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22,
|
||||||
|
0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4,
|
||||||
|
0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6,
|
||||||
|
0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9,
|
||||||
|
0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
|
||||||
|
0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593,
|
||||||
|
0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51,
|
||||||
|
0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28,
|
||||||
|
0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c,
|
||||||
|
0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b,
|
||||||
|
0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
|
||||||
|
0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c,
|
||||||
|
0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd,
|
||||||
|
0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a,
|
||||||
|
0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319,
|
||||||
|
0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb,
|
||||||
|
0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
|
||||||
|
0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991,
|
||||||
|
0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32,
|
||||||
|
0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680,
|
||||||
|
0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166,
|
||||||
|
0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae,
|
||||||
|
0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
|
||||||
|
0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5,
|
||||||
|
0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47,
|
||||||
|
0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370,
|
||||||
|
0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d,
|
||||||
|
0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84,
|
||||||
|
0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
|
||||||
|
0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8,
|
||||||
|
0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd,
|
||||||
|
0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9,
|
||||||
|
0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7,
|
||||||
|
0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38,
|
||||||
|
0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
|
||||||
|
0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c,
|
||||||
|
0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525,
|
||||||
|
0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1,
|
||||||
|
0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442,
|
||||||
|
0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964,
|
||||||
|
0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
|
||||||
|
0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8,
|
||||||
|
0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d,
|
||||||
|
0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f,
|
||||||
|
0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299,
|
||||||
|
0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02,
|
||||||
|
0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
|
||||||
|
0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614,
|
||||||
|
0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a,
|
||||||
|
0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6,
|
||||||
|
0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b,
|
||||||
|
0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0,
|
||||||
|
0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
|
||||||
|
0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e,
|
||||||
|
0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
|
||||||
|
0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f,
|
||||||
|
0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6])
|
||||||
|
];
|
||||||
|
this.P = new Uint32Array([
|
||||||
|
0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344,
|
||||||
|
0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
|
||||||
|
0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
|
||||||
|
0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
|
||||||
|
0x9216d5d9, 0x8979fb1b]);
|
||||||
|
};
|
||||||
|
|
||||||
|
function F(S, x8, i) {
|
||||||
|
return (((S[0][x8[i+3]] +
|
||||||
|
S[1][x8[i+2]]) ^
|
||||||
|
S[2][x8[i+1]]) +
|
||||||
|
S[3][x8[i]]);
|
||||||
|
};
|
||||||
|
|
||||||
|
Blowfish.prototype.encipher = function(x, x8) {
|
||||||
|
if (x8 === undefined) {
|
||||||
|
x8 = new Uint8Array(x.buffer);
|
||||||
|
if (x.byteOffset !== 0)
|
||||||
|
x8 = x8.subarray(x.byteOffset);
|
||||||
|
}
|
||||||
|
x[0] ^= this.P[0];
|
||||||
|
for (var i = 1; i < 16; i += 2) {
|
||||||
|
x[1] ^= F(this.S, x8, 0) ^ this.P[i];
|
||||||
|
x[0] ^= F(this.S, x8, 4) ^ this.P[i+1];
|
||||||
|
}
|
||||||
|
var t = x[0];
|
||||||
|
x[0] = x[1] ^ this.P[17];
|
||||||
|
x[1] = t;
|
||||||
|
};
|
||||||
|
|
||||||
|
Blowfish.prototype.decipher = function(x) {
|
||||||
|
var x8 = new Uint8Array(x.buffer);
|
||||||
|
if (x.byteOffset !== 0)
|
||||||
|
x8 = x8.subarray(x.byteOffset);
|
||||||
|
x[0] ^= this.P[17];
|
||||||
|
for (var i = 16; i > 0; i -= 2) {
|
||||||
|
x[1] ^= F(this.S, x8, 0) ^ this.P[i];
|
||||||
|
x[0] ^= F(this.S, x8, 4) ^ this.P[i-1];
|
||||||
|
}
|
||||||
|
var t = x[0];
|
||||||
|
x[0] = x[1] ^ this.P[0];
|
||||||
|
x[1] = t;
|
||||||
|
};
|
||||||
|
|
||||||
|
function stream2word(data, databytes){
|
||||||
|
var i, temp = 0;
|
||||||
|
for (i = 0; i < 4; i++, BLF_J++) {
|
||||||
|
if (BLF_J >= databytes) BLF_J = 0;
|
||||||
|
temp = (temp << 8) | data[BLF_J];
|
||||||
|
}
|
||||||
|
return temp;
|
||||||
|
};
|
||||||
|
|
||||||
|
Blowfish.prototype.expand0state = function(key, keybytes) {
|
||||||
|
var d = new Uint32Array(2), i, k;
|
||||||
|
var d8 = new Uint8Array(d.buffer);
|
||||||
|
|
||||||
|
for (i = 0, BLF_J = 0; i < 18; i++) {
|
||||||
|
this.P[i] ^= stream2word(key, keybytes);
|
||||||
|
}
|
||||||
|
BLF_J = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < 18; i += 2) {
|
||||||
|
this.encipher(d, d8);
|
||||||
|
this.P[i] = d[0];
|
||||||
|
this.P[i+1] = d[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < 4; i++) {
|
||||||
|
for (k = 0; k < 256; k += 2) {
|
||||||
|
this.encipher(d, d8);
|
||||||
|
this.S[i][k] = d[0];
|
||||||
|
this.S[i][k+1] = d[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Blowfish.prototype.expandstate = function(data, databytes, key, keybytes) {
|
||||||
|
var d = new Uint32Array(2), i, k;
|
||||||
|
|
||||||
|
for (i = 0, BLF_J = 0; i < 18; i++) {
|
||||||
|
this.P[i] ^= stream2word(key, keybytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0, BLF_J = 0; i < 18; i += 2) {
|
||||||
|
d[0] ^= stream2word(data, databytes);
|
||||||
|
d[1] ^= stream2word(data, databytes);
|
||||||
|
this.encipher(d);
|
||||||
|
this.P[i] = d[0];
|
||||||
|
this.P[i+1] = d[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < 4; i++) {
|
||||||
|
for (k = 0; k < 256; k += 2) {
|
||||||
|
d[0] ^= stream2word(data, databytes);
|
||||||
|
d[1] ^= stream2word(data, databytes);
|
||||||
|
this.encipher(d);
|
||||||
|
this.S[i][k] = d[0];
|
||||||
|
this.S[i][k+1] = d[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BLF_J = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
Blowfish.prototype.enc = function(data, blocks) {
|
||||||
|
for (var i = 0; i < blocks; i++) {
|
||||||
|
this.encipher(data.subarray(i*2));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Blowfish.prototype.dec = function(data, blocks) {
|
||||||
|
for (var i = 0; i < blocks; i++) {
|
||||||
|
this.decipher(data.subarray(i*2));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var BCRYPT_BLOCKS = 8,
|
||||||
|
BCRYPT_HASHSIZE = 32;
|
||||||
|
|
||||||
|
function bcrypt_hash(sha2pass, sha2salt, out) {
|
||||||
|
var state = new Blowfish(),
|
||||||
|
cdata = new Uint32Array(BCRYPT_BLOCKS), i,
|
||||||
|
ciphertext = new Uint8Array([79,120,121,99,104,114,111,109,97,116,105,
|
||||||
|
99,66,108,111,119,102,105,115,104,83,119,97,116,68,121,110,97,109,
|
||||||
|
105,116,101]); //"OxychromaticBlowfishSwatDynamite"
|
||||||
|
|
||||||
|
state.expandstate(sha2salt, 64, sha2pass, 64);
|
||||||
|
for (i = 0; i < 64; i++) {
|
||||||
|
state.expand0state(sha2salt, 64);
|
||||||
|
state.expand0state(sha2pass, 64);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < BCRYPT_BLOCKS; i++)
|
||||||
|
cdata[i] = stream2word(ciphertext, ciphertext.byteLength);
|
||||||
|
for (i = 0; i < 64; i++)
|
||||||
|
state.enc(cdata, cdata.byteLength / 8);
|
||||||
|
|
||||||
|
for (i = 0; i < BCRYPT_BLOCKS; i++) {
|
||||||
|
out[4*i+3] = cdata[i] >>> 24;
|
||||||
|
out[4*i+2] = cdata[i] >>> 16;
|
||||||
|
out[4*i+1] = cdata[i] >>> 8;
|
||||||
|
out[4*i+0] = cdata[i];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function bcrypt_pbkdf(pass, passlen, salt, saltlen, key, keylen, rounds) {
|
||||||
|
var sha2pass = new Uint8Array(64),
|
||||||
|
sha2salt = new Uint8Array(64),
|
||||||
|
out = new Uint8Array(BCRYPT_HASHSIZE),
|
||||||
|
tmpout = new Uint8Array(BCRYPT_HASHSIZE),
|
||||||
|
countsalt = new Uint8Array(saltlen+4),
|
||||||
|
i, j, amt, stride, dest, count,
|
||||||
|
origkeylen = keylen;
|
||||||
|
|
||||||
|
if (rounds < 1)
|
||||||
|
return -1;
|
||||||
|
if (passlen === 0 || saltlen === 0 || keylen === 0 ||
|
||||||
|
keylen > (out.byteLength * out.byteLength) || saltlen > (1<<20))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
stride = Math.floor((keylen + out.byteLength - 1) / out.byteLength);
|
||||||
|
amt = Math.floor((keylen + stride - 1) / stride);
|
||||||
|
|
||||||
|
for (i = 0; i < saltlen; i++)
|
||||||
|
countsalt[i] = salt[i];
|
||||||
|
|
||||||
|
crypto_hash_sha512(sha2pass, pass, passlen);
|
||||||
|
|
||||||
|
for (count = 1; keylen > 0; count++) {
|
||||||
|
countsalt[saltlen+0] = count >>> 24;
|
||||||
|
countsalt[saltlen+1] = count >>> 16;
|
||||||
|
countsalt[saltlen+2] = count >>> 8;
|
||||||
|
countsalt[saltlen+3] = count;
|
||||||
|
|
||||||
|
crypto_hash_sha512(sha2salt, countsalt, saltlen + 4);
|
||||||
|
bcrypt_hash(sha2pass, sha2salt, tmpout);
|
||||||
|
for (i = out.byteLength; i--;)
|
||||||
|
out[i] = tmpout[i];
|
||||||
|
|
||||||
|
for (i = 1; i < rounds; i++) {
|
||||||
|
crypto_hash_sha512(sha2salt, tmpout, tmpout.byteLength);
|
||||||
|
bcrypt_hash(sha2pass, sha2salt, tmpout);
|
||||||
|
for (j = 0; j < out.byteLength; j++)
|
||||||
|
out[j] ^= tmpout[j];
|
||||||
|
}
|
||||||
|
|
||||||
|
amt = Math.min(amt, keylen);
|
||||||
|
for (i = 0; i < amt; i++) {
|
||||||
|
dest = i * stride + (count - 1);
|
||||||
|
if (dest >= origkeylen)
|
||||||
|
break;
|
||||||
|
key[dest] = out[i];
|
||||||
|
}
|
||||||
|
keylen -= i;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
BLOCKS: BCRYPT_BLOCKS,
|
||||||
|
HASHSIZE: BCRYPT_HASHSIZE,
|
||||||
|
hash: bcrypt_hash,
|
||||||
|
pbkdf: bcrypt_pbkdf
|
||||||
|
};
|
|
@ -0,0 +1,44 @@
|
||||||
|
{
|
||||||
|
"_from": "bcrypt-pbkdf@^1.0.2",
|
||||||
|
"_id": "bcrypt-pbkdf@1.0.2",
|
||||||
|
"_inBundle": false,
|
||||||
|
"_integrity": "sha1-pDAdOJtqQ/m2f/PKEaP2Y342Dp4=",
|
||||||
|
"_location": "/bcrypt-pbkdf",
|
||||||
|
"_phantomChildren": {},
|
||||||
|
"_requested": {
|
||||||
|
"type": "range",
|
||||||
|
"registry": true,
|
||||||
|
"raw": "bcrypt-pbkdf@^1.0.2",
|
||||||
|
"name": "bcrypt-pbkdf",
|
||||||
|
"escapedName": "bcrypt-pbkdf",
|
||||||
|
"rawSpec": "^1.0.2",
|
||||||
|
"saveSpec": null,
|
||||||
|
"fetchSpec": "^1.0.2"
|
||||||
|
},
|
||||||
|
"_requiredBy": [
|
||||||
|
"/ssh2-streams"
|
||||||
|
],
|
||||||
|
"_resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.2.tgz",
|
||||||
|
"_shasum": "a4301d389b6a43f9b67ff3ca11a3f6637e360e9e",
|
||||||
|
"_spec": "bcrypt-pbkdf@^1.0.2",
|
||||||
|
"_where": "/Users/keiferju/code/Lingtu/smx-svelma/upload/node_modules/ssh2-streams",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/joyent/node-bcrypt-pbkdf/issues"
|
||||||
|
},
|
||||||
|
"bundleDependencies": false,
|
||||||
|
"dependencies": {
|
||||||
|
"tweetnacl": "^0.14.3"
|
||||||
|
},
|
||||||
|
"deprecated": false,
|
||||||
|
"description": "Port of the OpenBSD bcrypt_pbkdf function to pure JS",
|
||||||
|
"devDependencies": {},
|
||||||
|
"homepage": "https://github.com/joyent/node-bcrypt-pbkdf#readme",
|
||||||
|
"license": "BSD-3-Clause",
|
||||||
|
"main": "index.js",
|
||||||
|
"name": "bcrypt-pbkdf",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git://github.com/joyent/node-bcrypt-pbkdf.git"
|
||||||
|
},
|
||||||
|
"version": "1.0.2"
|
||||||
|
}
|
|
@ -0,0 +1,59 @@
|
||||||
|
{
|
||||||
|
"predef": [ ]
|
||||||
|
, "bitwise": false
|
||||||
|
, "camelcase": false
|
||||||
|
, "curly": false
|
||||||
|
, "eqeqeq": false
|
||||||
|
, "forin": false
|
||||||
|
, "immed": false
|
||||||
|
, "latedef": false
|
||||||
|
, "noarg": true
|
||||||
|
, "noempty": true
|
||||||
|
, "nonew": true
|
||||||
|
, "plusplus": false
|
||||||
|
, "quotmark": true
|
||||||
|
, "regexp": false
|
||||||
|
, "undef": true
|
||||||
|
, "unused": true
|
||||||
|
, "strict": false
|
||||||
|
, "trailing": true
|
||||||
|
, "maxlen": 120
|
||||||
|
, "asi": true
|
||||||
|
, "boss": true
|
||||||
|
, "debug": true
|
||||||
|
, "eqnull": true
|
||||||
|
, "esnext": true
|
||||||
|
, "evil": true
|
||||||
|
, "expr": true
|
||||||
|
, "funcscope": false
|
||||||
|
, "globalstrict": false
|
||||||
|
, "iterator": false
|
||||||
|
, "lastsemic": true
|
||||||
|
, "laxbreak": true
|
||||||
|
, "laxcomma": true
|
||||||
|
, "loopfunc": true
|
||||||
|
, "multistr": false
|
||||||
|
, "onecase": false
|
||||||
|
, "proto": false
|
||||||
|
, "regexdash": false
|
||||||
|
, "scripturl": true
|
||||||
|
, "smarttabs": false
|
||||||
|
, "shadow": false
|
||||||
|
, "sub": true
|
||||||
|
, "supernew": false
|
||||||
|
, "validthis": true
|
||||||
|
, "browser": true
|
||||||
|
, "couch": false
|
||||||
|
, "devel": false
|
||||||
|
, "dojo": false
|
||||||
|
, "mootools": false
|
||||||
|
, "node": true
|
||||||
|
, "nonstandard": true
|
||||||
|
, "prototypejs": false
|
||||||
|
, "rhino": false
|
||||||
|
, "worker": true
|
||||||
|
, "wsh": false
|
||||||
|
, "nomen": false
|
||||||
|
, "onevar": false
|
||||||
|
, "passfail": false
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
sudo: false
|
||||||
|
language: node_js
|
||||||
|
node_js:
|
||||||
|
- '0.10'
|
||||||
|
- '0.12'
|
||||||
|
- '4'
|
||||||
|
- '6'
|
||||||
|
- '8'
|
||||||
|
- '9'
|
||||||
|
branches:
|
||||||
|
only:
|
||||||
|
- master
|
||||||
|
notifications:
|
||||||
|
email:
|
||||||
|
- rod@vagg.org
|
||||||
|
- matteo.collina@gmail.com
|
|
@ -0,0 +1,13 @@
|
||||||
|
The MIT License (MIT)
|
||||||
|
=====================
|
||||||
|
|
||||||
|
Copyright (c) 2013-2016 bl contributors
|
||||||
|
----------------------------------
|
||||||
|
|
||||||
|
*bl contributors listed at <https://github.com/rvagg/bl#contributors>*
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -0,0 +1,208 @@
|
||||||
|
# bl *(BufferList)*
|
||||||
|
|
||||||
|
[](https://travis-ci.org/rvagg/bl)
|
||||||
|
|
||||||
|
**A Node.js Buffer list collector, reader and streamer thingy.**
|
||||||
|
|
||||||
|
[](https://nodei.co/npm/bl/)
|
||||||
|
[](https://nodei.co/npm/bl/)
|
||||||
|
|
||||||
|
**bl** is a storage object for collections of Node Buffers, exposing them with the main Buffer readable API. Also works as a duplex stream so you can collect buffers from a stream that emits them and emit buffers to a stream that consumes them!
|
||||||
|
|
||||||
|
The original buffers are kept intact and copies are only done as necessary. Any reads that require the use of a single original buffer will return a slice of that buffer only (which references the same memory as the original buffer). Reads that span buffers perform concatenation as required and return the results transparently.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const BufferList = require('bl')
|
||||||
|
|
||||||
|
var bl = new BufferList()
|
||||||
|
bl.append(new Buffer('abcd'))
|
||||||
|
bl.append(new Buffer('efg'))
|
||||||
|
bl.append('hi') // bl will also accept & convert Strings
|
||||||
|
bl.append(new Buffer('j'))
|
||||||
|
bl.append(new Buffer([ 0x3, 0x4 ]))
|
||||||
|
|
||||||
|
console.log(bl.length) // 12
|
||||||
|
|
||||||
|
console.log(bl.slice(0, 10).toString('ascii')) // 'abcdefghij'
|
||||||
|
console.log(bl.slice(3, 10).toString('ascii')) // 'defghij'
|
||||||
|
console.log(bl.slice(3, 6).toString('ascii')) // 'def'
|
||||||
|
console.log(bl.slice(3, 8).toString('ascii')) // 'defgh'
|
||||||
|
console.log(bl.slice(5, 10).toString('ascii')) // 'fghij'
|
||||||
|
|
||||||
|
// or just use toString!
|
||||||
|
console.log(bl.toString()) // 'abcdefghij\u0003\u0004'
|
||||||
|
console.log(bl.toString('ascii', 3, 8)) // 'defgh'
|
||||||
|
console.log(bl.toString('ascii', 5, 10)) // 'fghij'
|
||||||
|
|
||||||
|
// other standard Buffer readables
|
||||||
|
console.log(bl.readUInt16BE(10)) // 0x0304
|
||||||
|
console.log(bl.readUInt16LE(10)) // 0x0403
|
||||||
|
```
|
||||||
|
|
||||||
|
Give it a callback in the constructor and use it just like **[concat-stream](https://github.com/maxogden/node-concat-stream)**:
|
||||||
|
|
||||||
|
```js
|
||||||
|
const bl = require('bl')
|
||||||
|
, fs = require('fs')
|
||||||
|
|
||||||
|
fs.createReadStream('README.md')
|
||||||
|
.pipe(bl(function (err, data) { // note 'new' isn't strictly required
|
||||||
|
// `data` is a complete Buffer object containing the full data
|
||||||
|
console.log(data.toString())
|
||||||
|
}))
|
||||||
|
```
|
||||||
|
|
||||||
|
Note that when you use the *callback* method like this, the resulting `data` parameter is a concatenation of all `Buffer` objects in the list. If you want to avoid the overhead of this concatenation (in cases of extreme performance consciousness), then avoid the *callback* method and just listen to `'end'` instead, like a standard Stream.
|
||||||
|
|
||||||
|
Or to fetch a URL using [hyperquest](https://github.com/substack/hyperquest) (should work with [request](http://github.com/mikeal/request) and even plain Node http too!):
|
||||||
|
```js
|
||||||
|
const hyperquest = require('hyperquest')
|
||||||
|
, bl = require('bl')
|
||||||
|
, url = 'https://raw.github.com/rvagg/bl/master/README.md'
|
||||||
|
|
||||||
|
hyperquest(url).pipe(bl(function (err, data) {
|
||||||
|
console.log(data.toString())
|
||||||
|
}))
|
||||||
|
```
|
||||||
|
|
||||||
|
Or, use it as a readable stream to recompose a list of Buffers to an output source:
|
||||||
|
|
||||||
|
```js
|
||||||
|
const BufferList = require('bl')
|
||||||
|
, fs = require('fs')
|
||||||
|
|
||||||
|
var bl = new BufferList()
|
||||||
|
bl.append(new Buffer('abcd'))
|
||||||
|
bl.append(new Buffer('efg'))
|
||||||
|
bl.append(new Buffer('hi'))
|
||||||
|
bl.append(new Buffer('j'))
|
||||||
|
|
||||||
|
bl.pipe(fs.createWriteStream('gibberish.txt'))
|
||||||
|
```
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
|
* <a href="#ctor"><code><b>new BufferList([ callback ])</b></code></a>
|
||||||
|
* <a href="#length"><code>bl.<b>length</b></code></a>
|
||||||
|
* <a href="#append"><code>bl.<b>append(buffer)</b></code></a>
|
||||||
|
* <a href="#get"><code>bl.<b>get(index)</b></code></a>
|
||||||
|
* <a href="#slice"><code>bl.<b>slice([ start[, end ] ])</b></code></a>
|
||||||
|
* <a href="#shallowSlice"><code>bl.<b>shallowSlice([ start[, end ] ])</b></code></a>
|
||||||
|
* <a href="#copy"><code>bl.<b>copy(dest, [ destStart, [ srcStart [, srcEnd ] ] ])</b></code></a>
|
||||||
|
* <a href="#duplicate"><code>bl.<b>duplicate()</b></code></a>
|
||||||
|
* <a href="#consume"><code>bl.<b>consume(bytes)</b></code></a>
|
||||||
|
* <a href="#toString"><code>bl.<b>toString([encoding, [ start, [ end ]]])</b></code></a>
|
||||||
|
* <a href="#readXX"><code>bl.<b>readDoubleBE()</b></code>, <code>bl.<b>readDoubleLE()</b></code>, <code>bl.<b>readFloatBE()</b></code>, <code>bl.<b>readFloatLE()</b></code>, <code>bl.<b>readInt32BE()</b></code>, <code>bl.<b>readInt32LE()</b></code>, <code>bl.<b>readUInt32BE()</b></code>, <code>bl.<b>readUInt32LE()</b></code>, <code>bl.<b>readInt16BE()</b></code>, <code>bl.<b>readInt16LE()</b></code>, <code>bl.<b>readUInt16BE()</b></code>, <code>bl.<b>readUInt16LE()</b></code>, <code>bl.<b>readInt8()</b></code>, <code>bl.<b>readUInt8()</b></code></a>
|
||||||
|
* <a href="#streams">Streams</a>
|
||||||
|
|
||||||
|
--------------------------------------------------------
|
||||||
|
<a name="ctor"></a>
|
||||||
|
### new BufferList([ callback | Buffer | Buffer array | BufferList | BufferList array | String ])
|
||||||
|
The constructor takes an optional callback, if supplied, the callback will be called with an error argument followed by a reference to the **bl** instance, when `bl.end()` is called (i.e. from a piped stream). This is a convenient method of collecting the entire contents of a stream, particularly when the stream is *chunky*, such as a network stream.
|
||||||
|
|
||||||
|
Normally, no arguments are required for the constructor, but you can initialise the list by passing in a single `Buffer` object or an array of `Buffer` object.
|
||||||
|
|
||||||
|
`new` is not strictly required, if you don't instantiate a new object, it will be done automatically for you so you can create a new instance simply with:
|
||||||
|
|
||||||
|
```js
|
||||||
|
var bl = require('bl')
|
||||||
|
var myinstance = bl()
|
||||||
|
|
||||||
|
// equivalent to:
|
||||||
|
|
||||||
|
var BufferList = require('bl')
|
||||||
|
var myinstance = new BufferList()
|
||||||
|
```
|
||||||
|
|
||||||
|
--------------------------------------------------------
|
||||||
|
<a name="length"></a>
|
||||||
|
### bl.length
|
||||||
|
Get the length of the list in bytes. This is the sum of the lengths of all of the buffers contained in the list, minus any initial offset for a semi-consumed buffer at the beginning. Should accurately represent the total number of bytes that can be read from the list.
|
||||||
|
|
||||||
|
--------------------------------------------------------
|
||||||
|
<a name="append"></a>
|
||||||
|
### bl.append(Buffer | Buffer array | BufferList | BufferList array | String)
|
||||||
|
`append(buffer)` adds an additional buffer or BufferList to the internal list. `this` is returned so it can be chained.
|
||||||
|
|
||||||
|
--------------------------------------------------------
|
||||||
|
<a name="get"></a>
|
||||||
|
### bl.get(index)
|
||||||
|
`get()` will return the byte at the specified index.
|
||||||
|
|
||||||
|
--------------------------------------------------------
|
||||||
|
<a name="slice"></a>
|
||||||
|
### bl.slice([ start, [ end ] ])
|
||||||
|
`slice()` returns a new `Buffer` object containing the bytes within the range specified. Both `start` and `end` are optional and will default to the beginning and end of the list respectively.
|
||||||
|
|
||||||
|
If the requested range spans a single internal buffer then a slice of that buffer will be returned which shares the original memory range of that Buffer. If the range spans multiple buffers then copy operations will likely occur to give you a uniform Buffer.
|
||||||
|
|
||||||
|
--------------------------------------------------------
|
||||||
|
<a name="shallowSlice"></a>
|
||||||
|
### bl.shallowSlice([ start, [ end ] ])
|
||||||
|
`shallowSlice()` returns a new `BufferList` object containing the bytes within the range specified. Both `start` and `end` are optional and will default to the beginning and end of the list respectively.
|
||||||
|
|
||||||
|
No copies will be performed. All buffers in the result share memory with the original list.
|
||||||
|
|
||||||
|
--------------------------------------------------------
|
||||||
|
<a name="copy"></a>
|
||||||
|
### bl.copy(dest, [ destStart, [ srcStart [, srcEnd ] ] ])
|
||||||
|
`copy()` copies the content of the list in the `dest` buffer, starting from `destStart` and containing the bytes within the range specified with `srcStart` to `srcEnd`. `destStart`, `start` and `end` are optional and will default to the beginning of the `dest` buffer, and the beginning and end of the list respectively.
|
||||||
|
|
||||||
|
--------------------------------------------------------
|
||||||
|
<a name="duplicate"></a>
|
||||||
|
### bl.duplicate()
|
||||||
|
`duplicate()` performs a **shallow-copy** of the list. The internal Buffers remains the same, so if you change the underlying Buffers, the change will be reflected in both the original and the duplicate. This method is needed if you want to call `consume()` or `pipe()` and still keep the original list.Example:
|
||||||
|
|
||||||
|
```js
|
||||||
|
var bl = new BufferList()
|
||||||
|
|
||||||
|
bl.append('hello')
|
||||||
|
bl.append(' world')
|
||||||
|
bl.append('\n')
|
||||||
|
|
||||||
|
bl.duplicate().pipe(process.stdout, { end: false })
|
||||||
|
|
||||||
|
console.log(bl.toString())
|
||||||
|
```
|
||||||
|
|
||||||
|
--------------------------------------------------------
|
||||||
|
<a name="consume"></a>
|
||||||
|
### bl.consume(bytes)
|
||||||
|
`consume()` will shift bytes *off the start of the list*. The number of bytes consumed don't need to line up with the sizes of the internal Buffers—initial offsets will be calculated accordingly in order to give you a consistent view of the data.
|
||||||
|
|
||||||
|
--------------------------------------------------------
|
||||||
|
<a name="toString"></a>
|
||||||
|
### bl.toString([encoding, [ start, [ end ]]])
|
||||||
|
`toString()` will return a string representation of the buffer. The optional `start` and `end` arguments are passed on to `slice()`, while the `encoding` is passed on to `toString()` of the resulting Buffer. See the [Buffer#toString()](http://nodejs.org/docs/latest/api/buffer.html#buffer_buf_tostring_encoding_start_end) documentation for more information.
|
||||||
|
|
||||||
|
--------------------------------------------------------
|
||||||
|
<a name="readXX"></a>
|
||||||
|
### bl.readDoubleBE(), bl.readDoubleLE(), bl.readFloatBE(), bl.readFloatLE(), bl.readInt32BE(), bl.readInt32LE(), bl.readUInt32BE(), bl.readUInt32LE(), bl.readInt16BE(), bl.readInt16LE(), bl.readUInt16BE(), bl.readUInt16LE(), bl.readInt8(), bl.readUInt8()
|
||||||
|
|
||||||
|
All of the standard byte-reading methods of the `Buffer` interface are implemented and will operate across internal Buffer boundaries transparently.
|
||||||
|
|
||||||
|
See the <b><code>[Buffer](http://nodejs.org/docs/latest/api/buffer.html)</code></b> documentation for how these work.
|
||||||
|
|
||||||
|
--------------------------------------------------------
|
||||||
|
<a name="streams"></a>
|
||||||
|
### Streams
|
||||||
|
**bl** is a Node **[Duplex Stream](http://nodejs.org/docs/latest/api/stream.html#stream_class_stream_duplex)**, so it can be read from and written to like a standard Node stream. You can also `pipe()` to and from a **bl** instance.
|
||||||
|
|
||||||
|
--------------------------------------------------------
|
||||||
|
|
||||||
|
## Contributors
|
||||||
|
|
||||||
|
**bl** is brought to you by the following hackers:
|
||||||
|
|
||||||
|
* [Rod Vagg](https://github.com/rvagg)
|
||||||
|
* [Matteo Collina](https://github.com/mcollina)
|
||||||
|
* [Jarett Cruger](https://github.com/jcrugzz)
|
||||||
|
|
||||||
|
=======
|
||||||
|
|
||||||
|
<a name="license"></a>
|
||||||
|
## License & copyright
|
||||||
|
|
||||||
|
Copyright (c) 2013-2016 bl contributors (listed above).
|
||||||
|
|
||||||
|
bl is licensed under the MIT license. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE.md file for more details.
|
|
@ -0,0 +1,281 @@
|
||||||
|
var DuplexStream = require('readable-stream/duplex')
|
||||||
|
, util = require('util')
|
||||||
|
, Buffer = require('safe-buffer').Buffer
|
||||||
|
|
||||||
|
|
||||||
|
function BufferList (callback) {
|
||||||
|
if (!(this instanceof BufferList))
|
||||||
|
return new BufferList(callback)
|
||||||
|
|
||||||
|
this._bufs = []
|
||||||
|
this.length = 0
|
||||||
|
|
||||||
|
if (typeof callback == 'function') {
|
||||||
|
this._callback = callback
|
||||||
|
|
||||||
|
var piper = function piper (err) {
|
||||||
|
if (this._callback) {
|
||||||
|
this._callback(err)
|
||||||
|
this._callback = null
|
||||||
|
}
|
||||||
|
}.bind(this)
|
||||||
|
|
||||||
|
this.on('pipe', function onPipe (src) {
|
||||||
|
src.on('error', piper)
|
||||||
|
})
|
||||||
|
this.on('unpipe', function onUnpipe (src) {
|
||||||
|
src.removeListener('error', piper)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
this.append(callback)
|
||||||
|
}
|
||||||
|
|
||||||
|
DuplexStream.call(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
util.inherits(BufferList, DuplexStream)
|
||||||
|
|
||||||
|
|
||||||
|
BufferList.prototype._offset = function _offset (offset) {
|
||||||
|
var tot = 0, i = 0, _t
|
||||||
|
if (offset === 0) return [ 0, 0 ]
|
||||||
|
for (; i < this._bufs.length; i++) {
|
||||||
|
_t = tot + this._bufs[i].length
|
||||||
|
if (offset < _t || i == this._bufs.length - 1)
|
||||||
|
return [ i, offset - tot ]
|
||||||
|
tot = _t
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BufferList.prototype.append = function append (buf) {
|
||||||
|
var i = 0
|
||||||
|
|
||||||
|
if (Buffer.isBuffer(buf)) {
|
||||||
|
this._appendBuffer(buf);
|
||||||
|
} else if (Array.isArray(buf)) {
|
||||||
|
for (; i < buf.length; i++)
|
||||||
|
this.append(buf[i])
|
||||||
|
} else if (buf instanceof BufferList) {
|
||||||
|
// unwrap argument into individual BufferLists
|
||||||
|
for (; i < buf._bufs.length; i++)
|
||||||
|
this.append(buf._bufs[i])
|
||||||
|
} else if (buf != null) {
|
||||||
|
// coerce number arguments to strings, since Buffer(number) does
|
||||||
|
// uninitialized memory allocation
|
||||||
|
if (typeof buf == 'number')
|
||||||
|
buf = buf.toString()
|
||||||
|
|
||||||
|
this._appendBuffer(Buffer.from(buf));
|
||||||
|
}
|
||||||
|
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BufferList.prototype._appendBuffer = function appendBuffer (buf) {
|
||||||
|
this._bufs.push(buf)
|
||||||
|
this.length += buf.length
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BufferList.prototype._write = function _write (buf, encoding, callback) {
|
||||||
|
this._appendBuffer(buf)
|
||||||
|
|
||||||
|
if (typeof callback == 'function')
|
||||||
|
callback()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BufferList.prototype._read = function _read (size) {
|
||||||
|
if (!this.length)
|
||||||
|
return this.push(null)
|
||||||
|
|
||||||
|
size = Math.min(size, this.length)
|
||||||
|
this.push(this.slice(0, size))
|
||||||
|
this.consume(size)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BufferList.prototype.end = function end (chunk) {
|
||||||
|
DuplexStream.prototype.end.call(this, chunk)
|
||||||
|
|
||||||
|
if (this._callback) {
|
||||||
|
this._callback(null, this.slice())
|
||||||
|
this._callback = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BufferList.prototype.get = function get (index) {
|
||||||
|
return this.slice(index, index + 1)[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BufferList.prototype.slice = function slice (start, end) {
|
||||||
|
if (typeof start == 'number' && start < 0)
|
||||||
|
start += this.length
|
||||||
|
if (typeof end == 'number' && end < 0)
|
||||||
|
end += this.length
|
||||||
|
return this.copy(null, 0, start, end)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BufferList.prototype.copy = function copy (dst, dstStart, srcStart, srcEnd) {
|
||||||
|
if (typeof srcStart != 'number' || srcStart < 0)
|
||||||
|
srcStart = 0
|
||||||
|
if (typeof srcEnd != 'number' || srcEnd > this.length)
|
||||||
|
srcEnd = this.length
|
||||||
|
if (srcStart >= this.length)
|
||||||
|
return dst || Buffer.alloc(0)
|
||||||
|
if (srcEnd <= 0)
|
||||||
|
return dst || Buffer.alloc(0)
|
||||||
|
|
||||||
|
var copy = !!dst
|
||||||
|
, off = this._offset(srcStart)
|
||||||
|
, len = srcEnd - srcStart
|
||||||
|
, bytes = len
|
||||||
|
, bufoff = (copy && dstStart) || 0
|
||||||
|
, start = off[1]
|
||||||
|
, l
|
||||||
|
, i
|
||||||
|
|
||||||
|
// copy/slice everything
|
||||||
|
if (srcStart === 0 && srcEnd == this.length) {
|
||||||
|
if (!copy) { // slice, but full concat if multiple buffers
|
||||||
|
return this._bufs.length === 1
|
||||||
|
? this._bufs[0]
|
||||||
|
: Buffer.concat(this._bufs, this.length)
|
||||||
|
}
|
||||||
|
|
||||||
|
// copy, need to copy individual buffers
|
||||||
|
for (i = 0; i < this._bufs.length; i++) {
|
||||||
|
this._bufs[i].copy(dst, bufoff)
|
||||||
|
bufoff += this._bufs[i].length
|
||||||
|
}
|
||||||
|
|
||||||
|
return dst
|
||||||
|
}
|
||||||
|
|
||||||
|
// easy, cheap case where it's a subset of one of the buffers
|
||||||
|
if (bytes <= this._bufs[off[0]].length - start) {
|
||||||
|
return copy
|
||||||
|
? this._bufs[off[0]].copy(dst, dstStart, start, start + bytes)
|
||||||
|
: this._bufs[off[0]].slice(start, start + bytes)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!copy) // a slice, we need something to copy in to
|
||||||
|
dst = Buffer.allocUnsafe(len)
|
||||||
|
|
||||||
|
for (i = off[0]; i < this._bufs.length; i++) {
|
||||||
|
l = this._bufs[i].length - start
|
||||||
|
|
||||||
|
if (bytes > l) {
|
||||||
|
this._bufs[i].copy(dst, bufoff, start)
|
||||||
|
} else {
|
||||||
|
this._bufs[i].copy(dst, bufoff, start, start + bytes)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
bufoff += l
|
||||||
|
bytes -= l
|
||||||
|
|
||||||
|
if (start)
|
||||||
|
start = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
return dst
|
||||||
|
}
|
||||||
|
|
||||||
|
BufferList.prototype.shallowSlice = function shallowSlice (start, end) {
|
||||||
|
start = start || 0
|
||||||
|
end = end || this.length
|
||||||
|
|
||||||
|
if (start < 0)
|
||||||
|
start += this.length
|
||||||
|
if (end < 0)
|
||||||
|
end += this.length
|
||||||
|
|
||||||
|
var startOffset = this._offset(start)
|
||||||
|
, endOffset = this._offset(end)
|
||||||
|
, buffers = this._bufs.slice(startOffset[0], endOffset[0] + 1)
|
||||||
|
|
||||||
|
if (endOffset[1] == 0)
|
||||||
|
buffers.pop()
|
||||||
|
else
|
||||||
|
buffers[buffers.length-1] = buffers[buffers.length-1].slice(0, endOffset[1])
|
||||||
|
|
||||||
|
if (startOffset[1] != 0)
|
||||||
|
buffers[0] = buffers[0].slice(startOffset[1])
|
||||||
|
|
||||||
|
return new BufferList(buffers)
|
||||||
|
}
|
||||||
|
|
||||||
|
BufferList.prototype.toString = function toString (encoding, start, end) {
|
||||||
|
return this.slice(start, end).toString(encoding)
|
||||||
|
}
|
||||||
|
|
||||||
|
BufferList.prototype.consume = function consume (bytes) {
|
||||||
|
while (this._bufs.length) {
|
||||||
|
if (bytes >= this._bufs[0].length) {
|
||||||
|
bytes -= this._bufs[0].length
|
||||||
|
this.length -= this._bufs[0].length
|
||||||
|
this._bufs.shift()
|
||||||
|
} else {
|
||||||
|
this._bufs[0] = this._bufs[0].slice(bytes)
|
||||||
|
this.length -= bytes
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return this
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BufferList.prototype.duplicate = function duplicate () {
|
||||||
|
var i = 0
|
||||||
|
, copy = new BufferList()
|
||||||
|
|
||||||
|
for (; i < this._bufs.length; i++)
|
||||||
|
copy.append(this._bufs[i])
|
||||||
|
|
||||||
|
return copy
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BufferList.prototype.destroy = function destroy () {
|
||||||
|
this._bufs.length = 0
|
||||||
|
this.length = 0
|
||||||
|
this.push(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
;(function () {
|
||||||
|
var methods = {
|
||||||
|
'readDoubleBE' : 8
|
||||||
|
, 'readDoubleLE' : 8
|
||||||
|
, 'readFloatBE' : 4
|
||||||
|
, 'readFloatLE' : 4
|
||||||
|
, 'readInt32BE' : 4
|
||||||
|
, 'readInt32LE' : 4
|
||||||
|
, 'readUInt32BE' : 4
|
||||||
|
, 'readUInt32LE' : 4
|
||||||
|
, 'readInt16BE' : 2
|
||||||
|
, 'readInt16LE' : 2
|
||||||
|
, 'readUInt16BE' : 2
|
||||||
|
, 'readUInt16LE' : 2
|
||||||
|
, 'readInt8' : 1
|
||||||
|
, 'readUInt8' : 1
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var m in methods) {
|
||||||
|
(function (m) {
|
||||||
|
BufferList.prototype[m] = function (offset) {
|
||||||
|
return this.slice(offset, offset + methods[m])[m](0)
|
||||||
|
}
|
||||||
|
}(m))
|
||||||
|
}
|
||||||
|
}())
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = BufferList
|
|
@ -0,0 +1,63 @@
|
||||||
|
{
|
||||||
|
"_from": "bl@^1.0.0",
|
||||||
|
"_id": "bl@1.2.2",
|
||||||
|
"_inBundle": false,
|
||||||
|
"_integrity": "sha512-e8tQYnZodmebYDWGH7KMRvtzKXaJHx3BbilrgZCfvyLUYdKpK1t5PSPmpkny/SgiTSCnjfLW7v5rlONXVFkQEA==",
|
||||||
|
"_location": "/bl",
|
||||||
|
"_phantomChildren": {},
|
||||||
|
"_requested": {
|
||||||
|
"type": "range",
|
||||||
|
"registry": true,
|
||||||
|
"raw": "bl@^1.0.0",
|
||||||
|
"name": "bl",
|
||||||
|
"escapedName": "bl",
|
||||||
|
"rawSpec": "^1.0.0",
|
||||||
|
"saveSpec": null,
|
||||||
|
"fetchSpec": "^1.0.0"
|
||||||
|
},
|
||||||
|
"_requiredBy": [
|
||||||
|
"/tar-stream"
|
||||||
|
],
|
||||||
|
"_resolved": "https://registry.npmjs.org/bl/-/bl-1.2.2.tgz",
|
||||||
|
"_shasum": "a160911717103c07410cef63ef51b397c025af9c",
|
||||||
|
"_spec": "bl@^1.0.0",
|
||||||
|
"_where": "/Users/keiferju/code/Lingtu/smx-svelma/upload/node_modules/tar-stream",
|
||||||
|
"authors": [
|
||||||
|
"Rod Vagg <rod@vagg.org> (https://github.com/rvagg)",
|
||||||
|
"Matteo Collina <matteo.collina@gmail.com> (https://github.com/mcollina)",
|
||||||
|
"Jarett Cruger <jcrugzz@gmail.com> (https://github.com/jcrugzz)"
|
||||||
|
],
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/rvagg/bl/issues"
|
||||||
|
},
|
||||||
|
"bundleDependencies": false,
|
||||||
|
"dependencies": {
|
||||||
|
"readable-stream": "^2.3.5",
|
||||||
|
"safe-buffer": "^5.1.1"
|
||||||
|
},
|
||||||
|
"deprecated": false,
|
||||||
|
"description": "Buffer List: collect buffers and access with a standard readable Buffer interface, streamable too!",
|
||||||
|
"devDependencies": {
|
||||||
|
"faucet": "0.0.1",
|
||||||
|
"hash_file": "~0.1.1",
|
||||||
|
"tape": "~4.9.0"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/rvagg/bl",
|
||||||
|
"keywords": [
|
||||||
|
"buffer",
|
||||||
|
"buffers",
|
||||||
|
"stream",
|
||||||
|
"awesomesauce"
|
||||||
|
],
|
||||||
|
"license": "MIT",
|
||||||
|
"main": "bl.js",
|
||||||
|
"name": "bl",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/rvagg/bl.git"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "node test/test.js | faucet"
|
||||||
|
},
|
||||||
|
"version": "1.2.2"
|
||||||
|
}
|
|
@ -0,0 +1,702 @@
|
||||||
|
var tape = require('tape')
|
||||||
|
, crypto = require('crypto')
|
||||||
|
, fs = require('fs')
|
||||||
|
, hash = require('hash_file')
|
||||||
|
, BufferList = require('../')
|
||||||
|
, Buffer = require('safe-buffer').Buffer
|
||||||
|
|
||||||
|
, encodings =
|
||||||
|
('hex utf8 utf-8 ascii binary base64'
|
||||||
|
+ (process.browser ? '' : ' ucs2 ucs-2 utf16le utf-16le')).split(' ')
|
||||||
|
|
||||||
|
tape('single bytes from single buffer', function (t) {
|
||||||
|
var bl = new BufferList()
|
||||||
|
bl.append(Buffer.from('abcd'))
|
||||||
|
|
||||||
|
t.equal(bl.length, 4)
|
||||||
|
|
||||||
|
t.equal(bl.get(0), 97)
|
||||||
|
t.equal(bl.get(1), 98)
|
||||||
|
t.equal(bl.get(2), 99)
|
||||||
|
t.equal(bl.get(3), 100)
|
||||||
|
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('single bytes from multiple buffers', function (t) {
|
||||||
|
var bl = new BufferList()
|
||||||
|
bl.append(Buffer.from('abcd'))
|
||||||
|
bl.append(Buffer.from('efg'))
|
||||||
|
bl.append(Buffer.from('hi'))
|
||||||
|
bl.append(Buffer.from('j'))
|
||||||
|
|
||||||
|
t.equal(bl.length, 10)
|
||||||
|
|
||||||
|
t.equal(bl.get(0), 97)
|
||||||
|
t.equal(bl.get(1), 98)
|
||||||
|
t.equal(bl.get(2), 99)
|
||||||
|
t.equal(bl.get(3), 100)
|
||||||
|
t.equal(bl.get(4), 101)
|
||||||
|
t.equal(bl.get(5), 102)
|
||||||
|
t.equal(bl.get(6), 103)
|
||||||
|
t.equal(bl.get(7), 104)
|
||||||
|
t.equal(bl.get(8), 105)
|
||||||
|
t.equal(bl.get(9), 106)
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('multi bytes from single buffer', function (t) {
|
||||||
|
var bl = new BufferList()
|
||||||
|
bl.append(Buffer.from('abcd'))
|
||||||
|
|
||||||
|
t.equal(bl.length, 4)
|
||||||
|
|
||||||
|
t.equal(bl.slice(0, 4).toString('ascii'), 'abcd')
|
||||||
|
t.equal(bl.slice(0, 3).toString('ascii'), 'abc')
|
||||||
|
t.equal(bl.slice(1, 4).toString('ascii'), 'bcd')
|
||||||
|
t.equal(bl.slice(-4, -1).toString('ascii'), 'abc')
|
||||||
|
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('multi bytes from single buffer (negative indexes)', function (t) {
|
||||||
|
var bl = new BufferList()
|
||||||
|
bl.append(Buffer.from('buffer'))
|
||||||
|
|
||||||
|
t.equal(bl.length, 6)
|
||||||
|
|
||||||
|
t.equal(bl.slice(-6, -1).toString('ascii'), 'buffe')
|
||||||
|
t.equal(bl.slice(-6, -2).toString('ascii'), 'buff')
|
||||||
|
t.equal(bl.slice(-5, -2).toString('ascii'), 'uff')
|
||||||
|
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('multiple bytes from multiple buffers', function (t) {
|
||||||
|
var bl = new BufferList()
|
||||||
|
|
||||||
|
bl.append(Buffer.from('abcd'))
|
||||||
|
bl.append(Buffer.from('efg'))
|
||||||
|
bl.append(Buffer.from('hi'))
|
||||||
|
bl.append(Buffer.from('j'))
|
||||||
|
|
||||||
|
t.equal(bl.length, 10)
|
||||||
|
|
||||||
|
t.equal(bl.slice(0, 10).toString('ascii'), 'abcdefghij')
|
||||||
|
t.equal(bl.slice(3, 10).toString('ascii'), 'defghij')
|
||||||
|
t.equal(bl.slice(3, 6).toString('ascii'), 'def')
|
||||||
|
t.equal(bl.slice(3, 8).toString('ascii'), 'defgh')
|
||||||
|
t.equal(bl.slice(5, 10).toString('ascii'), 'fghij')
|
||||||
|
t.equal(bl.slice(-7, -4).toString('ascii'), 'def')
|
||||||
|
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('multiple bytes from multiple buffer lists', function (t) {
|
||||||
|
var bl = new BufferList()
|
||||||
|
|
||||||
|
bl.append(new BufferList([ Buffer.from('abcd'), Buffer.from('efg') ]))
|
||||||
|
bl.append(new BufferList([ Buffer.from('hi'), Buffer.from('j') ]))
|
||||||
|
|
||||||
|
t.equal(bl.length, 10)
|
||||||
|
|
||||||
|
t.equal(bl.slice(0, 10).toString('ascii'), 'abcdefghij')
|
||||||
|
|
||||||
|
t.equal(bl.slice(3, 10).toString('ascii'), 'defghij')
|
||||||
|
t.equal(bl.slice(3, 6).toString('ascii'), 'def')
|
||||||
|
t.equal(bl.slice(3, 8).toString('ascii'), 'defgh')
|
||||||
|
t.equal(bl.slice(5, 10).toString('ascii'), 'fghij')
|
||||||
|
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
// same data as previous test, just using nested constructors
|
||||||
|
tape('multiple bytes from crazy nested buffer lists', function (t) {
|
||||||
|
var bl = new BufferList()
|
||||||
|
|
||||||
|
bl.append(new BufferList([
|
||||||
|
new BufferList([
|
||||||
|
new BufferList(Buffer.from('abc'))
|
||||||
|
, Buffer.from('d')
|
||||||
|
, new BufferList(Buffer.from('efg'))
|
||||||
|
])
|
||||||
|
, new BufferList([ Buffer.from('hi') ])
|
||||||
|
, new BufferList(Buffer.from('j'))
|
||||||
|
]))
|
||||||
|
|
||||||
|
t.equal(bl.length, 10)
|
||||||
|
|
||||||
|
t.equal(bl.slice(0, 10).toString('ascii'), 'abcdefghij')
|
||||||
|
|
||||||
|
t.equal(bl.slice(3, 10).toString('ascii'), 'defghij')
|
||||||
|
t.equal(bl.slice(3, 6).toString('ascii'), 'def')
|
||||||
|
t.equal(bl.slice(3, 8).toString('ascii'), 'defgh')
|
||||||
|
t.equal(bl.slice(5, 10).toString('ascii'), 'fghij')
|
||||||
|
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('append accepts arrays of Buffers', function (t) {
|
||||||
|
var bl = new BufferList()
|
||||||
|
bl.append(Buffer.from('abc'))
|
||||||
|
bl.append([ Buffer.from('def') ])
|
||||||
|
bl.append([ Buffer.from('ghi'), Buffer.from('jkl') ])
|
||||||
|
bl.append([ Buffer.from('mnop'), Buffer.from('qrstu'), Buffer.from('vwxyz') ])
|
||||||
|
t.equal(bl.length, 26)
|
||||||
|
t.equal(bl.slice().toString('ascii'), 'abcdefghijklmnopqrstuvwxyz')
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('append accepts arrays of BufferLists', function (t) {
|
||||||
|
var bl = new BufferList()
|
||||||
|
bl.append(Buffer.from('abc'))
|
||||||
|
bl.append([ new BufferList('def') ])
|
||||||
|
bl.append(new BufferList([ Buffer.from('ghi'), new BufferList('jkl') ]))
|
||||||
|
bl.append([ Buffer.from('mnop'), new BufferList([ Buffer.from('qrstu'), Buffer.from('vwxyz') ]) ])
|
||||||
|
t.equal(bl.length, 26)
|
||||||
|
t.equal(bl.slice().toString('ascii'), 'abcdefghijklmnopqrstuvwxyz')
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('append chainable', function (t) {
|
||||||
|
var bl = new BufferList()
|
||||||
|
t.ok(bl.append(Buffer.from('abcd')) === bl)
|
||||||
|
t.ok(bl.append([ Buffer.from('abcd') ]) === bl)
|
||||||
|
t.ok(bl.append(new BufferList(Buffer.from('abcd'))) === bl)
|
||||||
|
t.ok(bl.append([ new BufferList(Buffer.from('abcd')) ]) === bl)
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('append chainable (test results)', function (t) {
|
||||||
|
var bl = new BufferList('abc')
|
||||||
|
.append([ new BufferList('def') ])
|
||||||
|
.append(new BufferList([ Buffer.from('ghi'), new BufferList('jkl') ]))
|
||||||
|
.append([ Buffer.from('mnop'), new BufferList([ Buffer.from('qrstu'), Buffer.from('vwxyz') ]) ])
|
||||||
|
|
||||||
|
t.equal(bl.length, 26)
|
||||||
|
t.equal(bl.slice().toString('ascii'), 'abcdefghijklmnopqrstuvwxyz')
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('consuming from multiple buffers', function (t) {
|
||||||
|
var bl = new BufferList()
|
||||||
|
|
||||||
|
bl.append(Buffer.from('abcd'))
|
||||||
|
bl.append(Buffer.from('efg'))
|
||||||
|
bl.append(Buffer.from('hi'))
|
||||||
|
bl.append(Buffer.from('j'))
|
||||||
|
|
||||||
|
t.equal(bl.length, 10)
|
||||||
|
|
||||||
|
t.equal(bl.slice(0, 10).toString('ascii'), 'abcdefghij')
|
||||||
|
|
||||||
|
bl.consume(3)
|
||||||
|
t.equal(bl.length, 7)
|
||||||
|
t.equal(bl.slice(0, 7).toString('ascii'), 'defghij')
|
||||||
|
|
||||||
|
bl.consume(2)
|
||||||
|
t.equal(bl.length, 5)
|
||||||
|
t.equal(bl.slice(0, 5).toString('ascii'), 'fghij')
|
||||||
|
|
||||||
|
bl.consume(1)
|
||||||
|
t.equal(bl.length, 4)
|
||||||
|
t.equal(bl.slice(0, 4).toString('ascii'), 'ghij')
|
||||||
|
|
||||||
|
bl.consume(1)
|
||||||
|
t.equal(bl.length, 3)
|
||||||
|
t.equal(bl.slice(0, 3).toString('ascii'), 'hij')
|
||||||
|
|
||||||
|
bl.consume(2)
|
||||||
|
t.equal(bl.length, 1)
|
||||||
|
t.equal(bl.slice(0, 1).toString('ascii'), 'j')
|
||||||
|
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('complete consumption', function (t) {
|
||||||
|
var bl = new BufferList()
|
||||||
|
|
||||||
|
bl.append(Buffer.from('a'))
|
||||||
|
bl.append(Buffer.from('b'))
|
||||||
|
|
||||||
|
bl.consume(2)
|
||||||
|
|
||||||
|
t.equal(bl.length, 0)
|
||||||
|
t.equal(bl._bufs.length, 0)
|
||||||
|
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('test readUInt8 / readInt8', function (t) {
|
||||||
|
var buf1 = Buffer.alloc(1)
|
||||||
|
, buf2 = Buffer.alloc(3)
|
||||||
|
, buf3 = Buffer.alloc(3)
|
||||||
|
, bl = new BufferList()
|
||||||
|
|
||||||
|
buf2[1] = 0x3
|
||||||
|
buf2[2] = 0x4
|
||||||
|
buf3[0] = 0x23
|
||||||
|
buf3[1] = 0x42
|
||||||
|
|
||||||
|
bl.append(buf1)
|
||||||
|
bl.append(buf2)
|
||||||
|
bl.append(buf3)
|
||||||
|
|
||||||
|
t.equal(bl.readUInt8(2), 0x3)
|
||||||
|
t.equal(bl.readInt8(2), 0x3)
|
||||||
|
t.equal(bl.readUInt8(3), 0x4)
|
||||||
|
t.equal(bl.readInt8(3), 0x4)
|
||||||
|
t.equal(bl.readUInt8(4), 0x23)
|
||||||
|
t.equal(bl.readInt8(4), 0x23)
|
||||||
|
t.equal(bl.readUInt8(5), 0x42)
|
||||||
|
t.equal(bl.readInt8(5), 0x42)
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('test readUInt16LE / readUInt16BE / readInt16LE / readInt16BE', function (t) {
|
||||||
|
var buf1 = Buffer.alloc(1)
|
||||||
|
, buf2 = Buffer.alloc(3)
|
||||||
|
, buf3 = Buffer.alloc(3)
|
||||||
|
, bl = new BufferList()
|
||||||
|
|
||||||
|
buf2[1] = 0x3
|
||||||
|
buf2[2] = 0x4
|
||||||
|
buf3[0] = 0x23
|
||||||
|
buf3[1] = 0x42
|
||||||
|
|
||||||
|
bl.append(buf1)
|
||||||
|
bl.append(buf2)
|
||||||
|
bl.append(buf3)
|
||||||
|
|
||||||
|
t.equal(bl.readUInt16BE(2), 0x0304)
|
||||||
|
t.equal(bl.readUInt16LE(2), 0x0403)
|
||||||
|
t.equal(bl.readInt16BE(2), 0x0304)
|
||||||
|
t.equal(bl.readInt16LE(2), 0x0403)
|
||||||
|
t.equal(bl.readUInt16BE(3), 0x0423)
|
||||||
|
t.equal(bl.readUInt16LE(3), 0x2304)
|
||||||
|
t.equal(bl.readInt16BE(3), 0x0423)
|
||||||
|
t.equal(bl.readInt16LE(3), 0x2304)
|
||||||
|
t.equal(bl.readUInt16BE(4), 0x2342)
|
||||||
|
t.equal(bl.readUInt16LE(4), 0x4223)
|
||||||
|
t.equal(bl.readInt16BE(4), 0x2342)
|
||||||
|
t.equal(bl.readInt16LE(4), 0x4223)
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('test readUInt32LE / readUInt32BE / readInt32LE / readInt32BE', function (t) {
|
||||||
|
var buf1 = Buffer.alloc(1)
|
||||||
|
, buf2 = Buffer.alloc(3)
|
||||||
|
, buf3 = Buffer.alloc(3)
|
||||||
|
, bl = new BufferList()
|
||||||
|
|
||||||
|
buf2[1] = 0x3
|
||||||
|
buf2[2] = 0x4
|
||||||
|
buf3[0] = 0x23
|
||||||
|
buf3[1] = 0x42
|
||||||
|
|
||||||
|
bl.append(buf1)
|
||||||
|
bl.append(buf2)
|
||||||
|
bl.append(buf3)
|
||||||
|
|
||||||
|
t.equal(bl.readUInt32BE(2), 0x03042342)
|
||||||
|
t.equal(bl.readUInt32LE(2), 0x42230403)
|
||||||
|
t.equal(bl.readInt32BE(2), 0x03042342)
|
||||||
|
t.equal(bl.readInt32LE(2), 0x42230403)
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('test readFloatLE / readFloatBE', function (t) {
|
||||||
|
var buf1 = Buffer.alloc(1)
|
||||||
|
, buf2 = Buffer.alloc(3)
|
||||||
|
, buf3 = Buffer.alloc(3)
|
||||||
|
, bl = new BufferList()
|
||||||
|
|
||||||
|
buf2[1] = 0x00
|
||||||
|
buf2[2] = 0x00
|
||||||
|
buf3[0] = 0x80
|
||||||
|
buf3[1] = 0x3f
|
||||||
|
|
||||||
|
bl.append(buf1)
|
||||||
|
bl.append(buf2)
|
||||||
|
bl.append(buf3)
|
||||||
|
|
||||||
|
t.equal(bl.readFloatLE(2), 0x01)
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('test readDoubleLE / readDoubleBE', function (t) {
|
||||||
|
var buf1 = Buffer.alloc(1)
|
||||||
|
, buf2 = Buffer.alloc(3)
|
||||||
|
, buf3 = Buffer.alloc(10)
|
||||||
|
, bl = new BufferList()
|
||||||
|
|
||||||
|
buf2[1] = 0x55
|
||||||
|
buf2[2] = 0x55
|
||||||
|
buf3[0] = 0x55
|
||||||
|
buf3[1] = 0x55
|
||||||
|
buf3[2] = 0x55
|
||||||
|
buf3[3] = 0x55
|
||||||
|
buf3[4] = 0xd5
|
||||||
|
buf3[5] = 0x3f
|
||||||
|
|
||||||
|
bl.append(buf1)
|
||||||
|
bl.append(buf2)
|
||||||
|
bl.append(buf3)
|
||||||
|
|
||||||
|
t.equal(bl.readDoubleLE(2), 0.3333333333333333)
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('test toString', function (t) {
|
||||||
|
var bl = new BufferList()
|
||||||
|
|
||||||
|
bl.append(Buffer.from('abcd'))
|
||||||
|
bl.append(Buffer.from('efg'))
|
||||||
|
bl.append(Buffer.from('hi'))
|
||||||
|
bl.append(Buffer.from('j'))
|
||||||
|
|
||||||
|
t.equal(bl.toString('ascii', 0, 10), 'abcdefghij')
|
||||||
|
t.equal(bl.toString('ascii', 3, 10), 'defghij')
|
||||||
|
t.equal(bl.toString('ascii', 3, 6), 'def')
|
||||||
|
t.equal(bl.toString('ascii', 3, 8), 'defgh')
|
||||||
|
t.equal(bl.toString('ascii', 5, 10), 'fghij')
|
||||||
|
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('test toString encoding', function (t) {
|
||||||
|
var bl = new BufferList()
|
||||||
|
, b = Buffer.from('abcdefghij\xff\x00')
|
||||||
|
|
||||||
|
bl.append(Buffer.from('abcd'))
|
||||||
|
bl.append(Buffer.from('efg'))
|
||||||
|
bl.append(Buffer.from('hi'))
|
||||||
|
bl.append(Buffer.from('j'))
|
||||||
|
bl.append(Buffer.from('\xff\x00'))
|
||||||
|
|
||||||
|
encodings.forEach(function (enc) {
|
||||||
|
t.equal(bl.toString(enc), b.toString(enc), enc)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
!process.browser && tape('test stream', function (t) {
|
||||||
|
var random = crypto.randomBytes(65534)
|
||||||
|
, rndhash = hash(random, 'md5')
|
||||||
|
, md5sum = crypto.createHash('md5')
|
||||||
|
, bl = new BufferList(function (err, buf) {
|
||||||
|
t.ok(Buffer.isBuffer(buf))
|
||||||
|
t.ok(err === null)
|
||||||
|
t.equal(rndhash, hash(bl.slice(), 'md5'))
|
||||||
|
t.equal(rndhash, hash(buf, 'md5'))
|
||||||
|
|
||||||
|
bl.pipe(fs.createWriteStream('/tmp/bl_test_rnd_out.dat'))
|
||||||
|
.on('close', function () {
|
||||||
|
var s = fs.createReadStream('/tmp/bl_test_rnd_out.dat')
|
||||||
|
s.on('data', md5sum.update.bind(md5sum))
|
||||||
|
s.on('end', function() {
|
||||||
|
t.equal(rndhash, md5sum.digest('hex'), 'woohoo! correct hash!')
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
fs.writeFileSync('/tmp/bl_test_rnd.dat', random)
|
||||||
|
fs.createReadStream('/tmp/bl_test_rnd.dat').pipe(bl)
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('instantiation with Buffer', function (t) {
|
||||||
|
var buf = crypto.randomBytes(1024)
|
||||||
|
, buf2 = crypto.randomBytes(1024)
|
||||||
|
, b = BufferList(buf)
|
||||||
|
|
||||||
|
t.equal(buf.toString('hex'), b.slice().toString('hex'), 'same buffer')
|
||||||
|
b = BufferList([ buf, buf2 ])
|
||||||
|
t.equal(b.slice().toString('hex'), Buffer.concat([ buf, buf2 ]).toString('hex'), 'same buffer')
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('test String appendage', function (t) {
|
||||||
|
var bl = new BufferList()
|
||||||
|
, b = Buffer.from('abcdefghij\xff\x00')
|
||||||
|
|
||||||
|
bl.append('abcd')
|
||||||
|
bl.append('efg')
|
||||||
|
bl.append('hi')
|
||||||
|
bl.append('j')
|
||||||
|
bl.append('\xff\x00')
|
||||||
|
|
||||||
|
encodings.forEach(function (enc) {
|
||||||
|
t.equal(bl.toString(enc), b.toString(enc))
|
||||||
|
})
|
||||||
|
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('test Number appendage', function (t) {
|
||||||
|
var bl = new BufferList()
|
||||||
|
, b = Buffer.from('1234567890')
|
||||||
|
|
||||||
|
bl.append(1234)
|
||||||
|
bl.append(567)
|
||||||
|
bl.append(89)
|
||||||
|
bl.append(0)
|
||||||
|
|
||||||
|
encodings.forEach(function (enc) {
|
||||||
|
t.equal(bl.toString(enc), b.toString(enc))
|
||||||
|
})
|
||||||
|
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('write nothing, should get empty buffer', function (t) {
|
||||||
|
t.plan(3)
|
||||||
|
BufferList(function (err, data) {
|
||||||
|
t.notOk(err, 'no error')
|
||||||
|
t.ok(Buffer.isBuffer(data), 'got a buffer')
|
||||||
|
t.equal(0, data.length, 'got a zero-length buffer')
|
||||||
|
t.end()
|
||||||
|
}).end()
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('unicode string', function (t) {
|
||||||
|
t.plan(2)
|
||||||
|
var inp1 = '\u2600'
|
||||||
|
, inp2 = '\u2603'
|
||||||
|
, exp = inp1 + ' and ' + inp2
|
||||||
|
, bl = BufferList()
|
||||||
|
bl.write(inp1)
|
||||||
|
bl.write(' and ')
|
||||||
|
bl.write(inp2)
|
||||||
|
t.equal(exp, bl.toString())
|
||||||
|
t.equal(Buffer.from(exp).toString('hex'), bl.toString('hex'))
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('should emit finish', function (t) {
|
||||||
|
var source = BufferList()
|
||||||
|
, dest = BufferList()
|
||||||
|
|
||||||
|
source.write('hello')
|
||||||
|
source.pipe(dest)
|
||||||
|
|
||||||
|
dest.on('finish', function () {
|
||||||
|
t.equal(dest.toString('utf8'), 'hello')
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('basic copy', function (t) {
|
||||||
|
var buf = crypto.randomBytes(1024)
|
||||||
|
, buf2 = Buffer.alloc(1024)
|
||||||
|
, b = BufferList(buf)
|
||||||
|
|
||||||
|
b.copy(buf2)
|
||||||
|
t.equal(b.slice().toString('hex'), buf2.toString('hex'), 'same buffer')
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('copy after many appends', function (t) {
|
||||||
|
var buf = crypto.randomBytes(512)
|
||||||
|
, buf2 = Buffer.alloc(1024)
|
||||||
|
, b = BufferList(buf)
|
||||||
|
|
||||||
|
b.append(buf)
|
||||||
|
b.copy(buf2)
|
||||||
|
t.equal(b.slice().toString('hex'), buf2.toString('hex'), 'same buffer')
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('copy at a precise position', function (t) {
|
||||||
|
var buf = crypto.randomBytes(1004)
|
||||||
|
, buf2 = Buffer.alloc(1024)
|
||||||
|
, b = BufferList(buf)
|
||||||
|
|
||||||
|
b.copy(buf2, 20)
|
||||||
|
t.equal(b.slice().toString('hex'), buf2.slice(20).toString('hex'), 'same buffer')
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('copy starting from a precise location', function (t) {
|
||||||
|
var buf = crypto.randomBytes(10)
|
||||||
|
, buf2 = Buffer.alloc(5)
|
||||||
|
, b = BufferList(buf)
|
||||||
|
|
||||||
|
b.copy(buf2, 0, 5)
|
||||||
|
t.equal(b.slice(5).toString('hex'), buf2.toString('hex'), 'same buffer')
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('copy in an interval', function (t) {
|
||||||
|
var rnd = crypto.randomBytes(10)
|
||||||
|
, b = BufferList(rnd) // put the random bytes there
|
||||||
|
, actual = Buffer.alloc(3)
|
||||||
|
, expected = Buffer.alloc(3)
|
||||||
|
|
||||||
|
rnd.copy(expected, 0, 5, 8)
|
||||||
|
b.copy(actual, 0, 5, 8)
|
||||||
|
|
||||||
|
t.equal(actual.toString('hex'), expected.toString('hex'), 'same buffer')
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('copy an interval between two buffers', function (t) {
|
||||||
|
var buf = crypto.randomBytes(10)
|
||||||
|
, buf2 = Buffer.alloc(10)
|
||||||
|
, b = BufferList(buf)
|
||||||
|
|
||||||
|
b.append(buf)
|
||||||
|
b.copy(buf2, 0, 5, 15)
|
||||||
|
|
||||||
|
t.equal(b.slice(5, 15).toString('hex'), buf2.toString('hex'), 'same buffer')
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('shallow slice across buffer boundaries', function (t) {
|
||||||
|
var bl = new BufferList(['First', 'Second', 'Third'])
|
||||||
|
|
||||||
|
t.equal(bl.shallowSlice(3, 13).toString(), 'stSecondTh')
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('shallow slice within single buffer', function (t) {
|
||||||
|
t.plan(2)
|
||||||
|
var bl = new BufferList(['First', 'Second', 'Third'])
|
||||||
|
|
||||||
|
t.equal(bl.shallowSlice(5, 10).toString(), 'Secon')
|
||||||
|
t.equal(bl.shallowSlice(7, 10).toString(), 'con')
|
||||||
|
t.end()
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('shallow slice single buffer', function (t) {
|
||||||
|
t.plan(3)
|
||||||
|
var bl = new BufferList(['First', 'Second', 'Third'])
|
||||||
|
|
||||||
|
t.equal(bl.shallowSlice(0, 5).toString(), 'First')
|
||||||
|
t.equal(bl.shallowSlice(5, 11).toString(), 'Second')
|
||||||
|
t.equal(bl.shallowSlice(11, 16).toString(), 'Third')
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('shallow slice with negative or omitted indices', function (t) {
|
||||||
|
t.plan(4)
|
||||||
|
var bl = new BufferList(['First', 'Second', 'Third'])
|
||||||
|
|
||||||
|
t.equal(bl.shallowSlice().toString(), 'FirstSecondThird')
|
||||||
|
t.equal(bl.shallowSlice(5).toString(), 'SecondThird')
|
||||||
|
t.equal(bl.shallowSlice(5, -3).toString(), 'SecondTh')
|
||||||
|
t.equal(bl.shallowSlice(-8).toString(), 'ondThird')
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('shallow slice does not make a copy', function (t) {
|
||||||
|
t.plan(1)
|
||||||
|
var buffers = [Buffer.from('First'), Buffer.from('Second'), Buffer.from('Third')]
|
||||||
|
var bl = (new BufferList(buffers)).shallowSlice(5, -3)
|
||||||
|
|
||||||
|
buffers[1].fill('h')
|
||||||
|
buffers[2].fill('h')
|
||||||
|
|
||||||
|
t.equal(bl.toString(), 'hhhhhhhh')
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('duplicate', function (t) {
|
||||||
|
t.plan(2)
|
||||||
|
|
||||||
|
var bl = new BufferList('abcdefghij\xff\x00')
|
||||||
|
, dup = bl.duplicate()
|
||||||
|
|
||||||
|
t.equal(bl.prototype, dup.prototype)
|
||||||
|
t.equal(bl.toString('hex'), dup.toString('hex'))
|
||||||
|
})
|
||||||
|
|
||||||
|
tape('destroy no pipe', function (t) {
|
||||||
|
t.plan(2)
|
||||||
|
|
||||||
|
var bl = new BufferList('alsdkfja;lsdkfja;lsdk')
|
||||||
|
bl.destroy()
|
||||||
|
|
||||||
|
t.equal(bl._bufs.length, 0)
|
||||||
|
t.equal(bl.length, 0)
|
||||||
|
})
|
||||||
|
|
||||||
|
!process.browser && tape('destroy with pipe before read end', function (t) {
|
||||||
|
t.plan(2)
|
||||||
|
|
||||||
|
var bl = new BufferList()
|
||||||
|
fs.createReadStream(__dirname + '/test.js')
|
||||||
|
.pipe(bl)
|
||||||
|
|
||||||
|
bl.destroy()
|
||||||
|
|
||||||
|
t.equal(bl._bufs.length, 0)
|
||||||
|
t.equal(bl.length, 0)
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
|
!process.browser && tape('destroy with pipe before read end with race', function (t) {
|
||||||
|
t.plan(2)
|
||||||
|
|
||||||
|
var bl = new BufferList()
|
||||||
|
fs.createReadStream(__dirname + '/test.js')
|
||||||
|
.pipe(bl)
|
||||||
|
|
||||||
|
setTimeout(function () {
|
||||||
|
bl.destroy()
|
||||||
|
setTimeout(function () {
|
||||||
|
t.equal(bl._bufs.length, 0)
|
||||||
|
t.equal(bl.length, 0)
|
||||||
|
}, 500)
|
||||||
|
}, 500)
|
||||||
|
})
|
||||||
|
|
||||||
|
!process.browser && tape('destroy with pipe after read end', function (t) {
|
||||||
|
t.plan(2)
|
||||||
|
|
||||||
|
var bl = new BufferList()
|
||||||
|
fs.createReadStream(__dirname + '/test.js')
|
||||||
|
.on('end', onEnd)
|
||||||
|
.pipe(bl)
|
||||||
|
|
||||||
|
function onEnd () {
|
||||||
|
bl.destroy()
|
||||||
|
|
||||||
|
t.equal(bl._bufs.length, 0)
|
||||||
|
t.equal(bl.length, 0)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
!process.browser && tape('destroy with pipe while writing to a destination', function (t) {
|
||||||
|
t.plan(4)
|
||||||
|
|
||||||
|
var bl = new BufferList()
|
||||||
|
, ds = new BufferList()
|
||||||
|
|
||||||
|
fs.createReadStream(__dirname + '/test.js')
|
||||||
|
.on('end', onEnd)
|
||||||
|
.pipe(bl)
|
||||||
|
|
||||||
|
function onEnd () {
|
||||||
|
bl.pipe(ds)
|
||||||
|
|
||||||
|
setTimeout(function () {
|
||||||
|
bl.destroy()
|
||||||
|
|
||||||
|
t.equals(bl._bufs.length, 0)
|
||||||
|
t.equals(bl.length, 0)
|
||||||
|
|
||||||
|
ds.destroy()
|
||||||
|
|
||||||
|
t.equals(bl._bufs.length, 0)
|
||||||
|
t.equals(bl.length, 0)
|
||||||
|
|
||||||
|
}, 100)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
!process.browser && tape('handle error', function (t) {
|
||||||
|
t.plan(2)
|
||||||
|
fs.createReadStream('/does/not/exist').pipe(BufferList(function (err, data) {
|
||||||
|
t.ok(err instanceof Error, 'has error')
|
||||||
|
t.notOk(data, 'no data')
|
||||||
|
}))
|
||||||
|
})
|
|
@ -0,0 +1,21 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2013 Julian Gruber <julian@juliangruber.com>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
|
@ -0,0 +1,129 @@
|
||||||
|
# brace-expansion
|
||||||
|
|
||||||
|
[Brace expansion](https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html),
|
||||||
|
as known from sh/bash, in JavaScript.
|
||||||
|
|
||||||
|
[](http://travis-ci.org/juliangruber/brace-expansion)
|
||||||
|
[](https://www.npmjs.org/package/brace-expansion)
|
||||||
|
[](https://greenkeeper.io/)
|
||||||
|
|
||||||
|
[](https://ci.testling.com/juliangruber/brace-expansion)
|
||||||
|
|
||||||
|
## Example
|
||||||
|
|
||||||
|
```js
|
||||||
|
var expand = require('brace-expansion');
|
||||||
|
|
||||||
|
expand('file-{a,b,c}.jpg')
|
||||||
|
// => ['file-a.jpg', 'file-b.jpg', 'file-c.jpg']
|
||||||
|
|
||||||
|
expand('-v{,,}')
|
||||||
|
// => ['-v', '-v', '-v']
|
||||||
|
|
||||||
|
expand('file{0..2}.jpg')
|
||||||
|
// => ['file0.jpg', 'file1.jpg', 'file2.jpg']
|
||||||
|
|
||||||
|
expand('file-{a..c}.jpg')
|
||||||
|
// => ['file-a.jpg', 'file-b.jpg', 'file-c.jpg']
|
||||||
|
|
||||||
|
expand('file{2..0}.jpg')
|
||||||
|
// => ['file2.jpg', 'file1.jpg', 'file0.jpg']
|
||||||
|
|
||||||
|
expand('file{0..4..2}.jpg')
|
||||||
|
// => ['file0.jpg', 'file2.jpg', 'file4.jpg']
|
||||||
|
|
||||||
|
expand('file-{a..e..2}.jpg')
|
||||||
|
// => ['file-a.jpg', 'file-c.jpg', 'file-e.jpg']
|
||||||
|
|
||||||
|
expand('file{00..10..5}.jpg')
|
||||||
|
// => ['file00.jpg', 'file05.jpg', 'file10.jpg']
|
||||||
|
|
||||||
|
expand('{{A..C},{a..c}}')
|
||||||
|
// => ['A', 'B', 'C', 'a', 'b', 'c']
|
||||||
|
|
||||||
|
expand('ppp{,config,oe{,conf}}')
|
||||||
|
// => ['ppp', 'pppconfig', 'pppoe', 'pppoeconf']
|
||||||
|
```
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
|
```js
|
||||||
|
var expand = require('brace-expansion');
|
||||||
|
```
|
||||||
|
|
||||||
|
### var expanded = expand(str)
|
||||||
|
|
||||||
|
Return an array of all possible and valid expansions of `str`. If none are
|
||||||
|
found, `[str]` is returned.
|
||||||
|
|
||||||
|
Valid expansions are:
|
||||||
|
|
||||||
|
```js
|
||||||
|
/^(.*,)+(.+)?$/
|
||||||
|
// {a,b,...}
|
||||||
|
```
|
||||||
|
|
||||||
|
A comma separated list of options, like `{a,b}` or `{a,{b,c}}` or `{,a,}`.
|
||||||
|
|
||||||
|
```js
|
||||||
|
/^-?\d+\.\.-?\d+(\.\.-?\d+)?$/
|
||||||
|
// {x..y[..incr]}
|
||||||
|
```
|
||||||
|
|
||||||
|
A numeric sequence from `x` to `y` inclusive, with optional increment.
|
||||||
|
If `x` or `y` start with a leading `0`, all the numbers will be padded
|
||||||
|
to have equal length. Negative numbers and backwards iteration work too.
|
||||||
|
|
||||||
|
```js
|
||||||
|
/^-?\d+\.\.-?\d+(\.\.-?\d+)?$/
|
||||||
|
// {x..y[..incr]}
|
||||||
|
```
|
||||||
|
|
||||||
|
An alphabetic sequence from `x` to `y` inclusive, with optional increment.
|
||||||
|
`x` and `y` must be exactly one character, and if given, `incr` must be a
|
||||||
|
number.
|
||||||
|
|
||||||
|
For compatibility reasons, the string `${` is not eligible for brace expansion.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
With [npm](https://npmjs.org) do:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm install brace-expansion
|
||||||
|
```
|
||||||
|
|
||||||
|
## Contributors
|
||||||
|
|
||||||
|
- [Julian Gruber](https://github.com/juliangruber)
|
||||||
|
- [Isaac Z. Schlueter](https://github.com/isaacs)
|
||||||
|
|
||||||
|
## Sponsors
|
||||||
|
|
||||||
|
This module is proudly supported by my [Sponsors](https://github.com/juliangruber/sponsors)!
|
||||||
|
|
||||||
|
Do you want to support modules like this to improve their quality, stability and weigh in on new features? Then please consider donating to my [Patreon](https://www.patreon.com/juliangruber). Not sure how much of my modules you're using? Try [feross/thanks](https://github.com/feross/thanks)!
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
(MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2013 Julian Gruber <julian@juliangruber.com>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to
|
||||||
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
|
@ -0,0 +1,201 @@
|
||||||
|
var concatMap = require('concat-map');
|
||||||
|
var balanced = require('balanced-match');
|
||||||
|
|
||||||
|
module.exports = expandTop;
|
||||||
|
|
||||||
|
var escSlash = '\0SLASH'+Math.random()+'\0';
|
||||||
|
var escOpen = '\0OPEN'+Math.random()+'\0';
|
||||||
|
var escClose = '\0CLOSE'+Math.random()+'\0';
|
||||||
|
var escComma = '\0COMMA'+Math.random()+'\0';
|
||||||
|
var escPeriod = '\0PERIOD'+Math.random()+'\0';
|
||||||
|
|
||||||
|
function numeric(str) {
|
||||||
|
return parseInt(str, 10) == str
|
||||||
|
? parseInt(str, 10)
|
||||||
|
: str.charCodeAt(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
function escapeBraces(str) {
|
||||||
|
return str.split('\\\\').join(escSlash)
|
||||||
|
.split('\\{').join(escOpen)
|
||||||
|
.split('\\}').join(escClose)
|
||||||
|
.split('\\,').join(escComma)
|
||||||
|
.split('\\.').join(escPeriod);
|
||||||
|
}
|
||||||
|
|
||||||
|
function unescapeBraces(str) {
|
||||||
|
return str.split(escSlash).join('\\')
|
||||||
|
.split(escOpen).join('{')
|
||||||
|
.split(escClose).join('}')
|
||||||
|
.split(escComma).join(',')
|
||||||
|
.split(escPeriod).join('.');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Basically just str.split(","), but handling cases
|
||||||
|
// where we have nested braced sections, which should be
|
||||||
|
// treated as individual members, like {a,{b,c},d}
|
||||||
|
function parseCommaParts(str) {
|
||||||
|
if (!str)
|
||||||
|
return [''];
|
||||||
|
|
||||||
|
var parts = [];
|
||||||
|
var m = balanced('{', '}', str);
|
||||||
|
|
||||||
|
if (!m)
|
||||||
|
return str.split(',');
|
||||||
|
|
||||||
|
var pre = m.pre;
|
||||||
|
var body = m.body;
|
||||||
|
var post = m.post;
|
||||||
|
var p = pre.split(',');
|
||||||
|
|
||||||
|
p[p.length-1] += '{' + body + '}';
|
||||||
|
var postParts = parseCommaParts(post);
|
||||||
|
if (post.length) {
|
||||||
|
p[p.length-1] += postParts.shift();
|
||||||
|
p.push.apply(p, postParts);
|
||||||
|
}
|
||||||
|
|
||||||
|
parts.push.apply(parts, p);
|
||||||
|
|
||||||
|
return parts;
|
||||||
|
}
|
||||||
|
|
||||||
|
function expandTop(str) {
|
||||||
|
if (!str)
|
||||||
|
return [];
|
||||||
|
|
||||||
|
// I don't know why Bash 4.3 does this, but it does.
|
||||||
|
// Anything starting with {} will have the first two bytes preserved
|
||||||
|
// but *only* at the top level, so {},a}b will not expand to anything,
|
||||||
|
// but a{},b}c will be expanded to [a}c,abc].
|
||||||
|
// One could argue that this is a bug in Bash, but since the goal of
|
||||||
|
// this module is to match Bash's rules, we escape a leading {}
|
||||||
|
if (str.substr(0, 2) === '{}') {
|
||||||
|
str = '\\{\\}' + str.substr(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return expand(escapeBraces(str), true).map(unescapeBraces);
|
||||||
|
}
|
||||||
|
|
||||||
|
function identity(e) {
|
||||||
|
return e;
|
||||||
|
}
|
||||||
|
|
||||||
|
function embrace(str) {
|
||||||
|
return '{' + str + '}';
|
||||||
|
}
|
||||||
|
function isPadded(el) {
|
||||||
|
return /^-?0\d/.test(el);
|
||||||
|
}
|
||||||
|
|
||||||
|
function lte(i, y) {
|
||||||
|
return i <= y;
|
||||||
|
}
|
||||||
|
function gte(i, y) {
|
||||||
|
return i >= y;
|
||||||
|
}
|
||||||
|
|
||||||
|
function expand(str, isTop) {
|
||||||
|
var expansions = [];
|
||||||
|
|
||||||
|
var m = balanced('{', '}', str);
|
||||||
|
if (!m || /\$$/.test(m.pre)) return [str];
|
||||||
|
|
||||||
|
var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
|
||||||
|
var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
|
||||||
|
var isSequence = isNumericSequence || isAlphaSequence;
|
||||||
|
var isOptions = m.body.indexOf(',') >= 0;
|
||||||
|
if (!isSequence && !isOptions) {
|
||||||
|
// {a},b}
|
||||||
|
if (m.post.match(/,.*\}/)) {
|
||||||
|
str = m.pre + '{' + m.body + escClose + m.post;
|
||||||
|
return expand(str);
|
||||||
|
}
|
||||||
|
return [str];
|
||||||
|
}
|
||||||
|
|
||||||
|
var n;
|
||||||
|
if (isSequence) {
|
||||||
|
n = m.body.split(/\.\./);
|
||||||
|
} else {
|
||||||
|
n = parseCommaParts(m.body);
|
||||||
|
if (n.length === 1) {
|
||||||
|
// x{{a,b}}y ==> x{a}y x{b}y
|
||||||
|
n = expand(n[0], false).map(embrace);
|
||||||
|
if (n.length === 1) {
|
||||||
|
var post = m.post.length
|
||||||
|
? expand(m.post, false)
|
||||||
|
: [''];
|
||||||
|
return post.map(function(p) {
|
||||||
|
return m.pre + n[0] + p;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// at this point, n is the parts, and we know it's not a comma set
|
||||||
|
// with a single entry.
|
||||||
|
|
||||||
|
// no need to expand pre, since it is guaranteed to be free of brace-sets
|
||||||
|
var pre = m.pre;
|
||||||
|
var post = m.post.length
|
||||||
|
? expand(m.post, false)
|
||||||
|
: [''];
|
||||||
|
|
||||||
|
var N;
|
||||||
|
|
||||||
|
if (isSequence) {
|
||||||
|
var x = numeric(n[0]);
|
||||||
|
var y = numeric(n[1]);
|
||||||
|
var width = Math.max(n[0].length, n[1].length)
|
||||||
|
var incr = n.length == 3
|
||||||
|
? Math.abs(numeric(n[2]))
|
||||||
|
: 1;
|
||||||
|
var test = lte;
|
||||||
|
var reverse = y < x;
|
||||||
|
if (reverse) {
|
||||||
|
incr *= -1;
|
||||||
|
test = gte;
|
||||||
|
}
|
||||||
|
var pad = n.some(isPadded);
|
||||||
|
|
||||||
|
N = [];
|
||||||
|
|
||||||
|
for (var i = x; test(i, y); i += incr) {
|
||||||
|
var c;
|
||||||
|
if (isAlphaSequence) {
|
||||||
|
c = String.fromCharCode(i);
|
||||||
|
if (c === '\\')
|
||||||
|
c = '';
|
||||||
|
} else {
|
||||||
|
c = String(i);
|
||||||
|
if (pad) {
|
||||||
|
var need = width - c.length;
|
||||||
|
if (need > 0) {
|
||||||
|
var z = new Array(need + 1).join('0');
|
||||||
|
if (i < 0)
|
||||||
|
c = '-' + z + c.slice(1);
|
||||||
|
else
|
||||||
|
c = z + c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
N.push(c);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
N = concatMap(n, function(el) { return expand(el, false) });
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var j = 0; j < N.length; j++) {
|
||||||
|
for (var k = 0; k < post.length; k++) {
|
||||||
|
var expansion = pre + N[j] + post[k];
|
||||||
|
if (!isTop || isSequence || expansion)
|
||||||
|
expansions.push(expansion);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return expansions;
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
{
|
||||||
|
"_from": "brace-expansion@^1.1.7",
|
||||||
|
"_id": "brace-expansion@1.1.11",
|
||||||
|
"_inBundle": false,
|
||||||
|
"_integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==",
|
||||||
|
"_location": "/brace-expansion",
|
||||||
|
"_phantomChildren": {},
|
||||||
|
"_requested": {
|
||||||
|
"type": "range",
|
||||||
|
"registry": true,
|
||||||
|
"raw": "brace-expansion@^1.1.7",
|
||||||
|
"name": "brace-expansion",
|
||||||
|
"escapedName": "brace-expansion",
|
||||||
|
"rawSpec": "^1.1.7",
|
||||||
|
"saveSpec": null,
|
||||||
|
"fetchSpec": "^1.1.7"
|
||||||
|
},
|
||||||
|
"_requiredBy": [
|
||||||
|
"/minimatch"
|
||||||
|
],
|
||||||
|
"_resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",
|
||||||
|
"_shasum": "3c7fcbf529d87226f3d2f52b966ff5271eb441dd",
|
||||||
|
"_spec": "brace-expansion@^1.1.7",
|
||||||
|
"_where": "/Users/keiferju/code/Lingtu/smx-svelma/upload/node_modules/minimatch",
|
||||||
|
"author": {
|
||||||
|
"name": "Julian Gruber",
|
||||||
|
"email": "mail@juliangruber.com",
|
||||||
|
"url": "http://juliangruber.com"
|
||||||
|
},
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/juliangruber/brace-expansion/issues"
|
||||||
|
},
|
||||||
|
"bundleDependencies": false,
|
||||||
|
"dependencies": {
|
||||||
|
"balanced-match": "^1.0.0",
|
||||||
|
"concat-map": "0.0.1"
|
||||||
|
},
|
||||||
|
"deprecated": false,
|
||||||
|
"description": "Brace expansion as known from sh/bash",
|
||||||
|
"devDependencies": {
|
||||||
|
"matcha": "^0.7.0",
|
||||||
|
"tape": "^4.6.0"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/juliangruber/brace-expansion",
|
||||||
|
"keywords": [],
|
||||||
|
"license": "MIT",
|
||||||
|
"main": "index.js",
|
||||||
|
"name": "brace-expansion",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git://github.com/juliangruber/brace-expansion.git"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"bench": "matcha test/perf/bench.js",
|
||||||
|
"gentest": "bash test/generate.sh",
|
||||||
|
"test": "tape test/*.js"
|
||||||
|
},
|
||||||
|
"testling": {
|
||||||
|
"files": "test/*.js",
|
||||||
|
"browsers": [
|
||||||
|
"ie/8..latest",
|
||||||
|
"firefox/20..latest",
|
||||||
|
"firefox/nightly",
|
||||||
|
"chrome/25..latest",
|
||||||
|
"chrome/canary",
|
||||||
|
"opera/12..latest",
|
||||||
|
"opera/next",
|
||||||
|
"safari/5.1..latest",
|
||||||
|
"ipad/6.0..latest",
|
||||||
|
"iphone/6.0..latest",
|
||||||
|
"android-browser/4.2..latest"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"version": "1.1.11"
|
||||||
|
}
|
|
@ -0,0 +1,17 @@
|
||||||
|
function allocUnsafe (size) {
|
||||||
|
if (typeof size !== 'number') {
|
||||||
|
throw new TypeError('"size" argument must be a number')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size < 0) {
|
||||||
|
throw new RangeError('"size" argument must not be negative')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Buffer.allocUnsafe) {
|
||||||
|
return Buffer.allocUnsafe(size)
|
||||||
|
} else {
|
||||||
|
return new Buffer(size)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = allocUnsafe
|
|
@ -0,0 +1,57 @@
|
||||||
|
{
|
||||||
|
"_from": "buffer-alloc-unsafe@^1.1.0",
|
||||||
|
"_id": "buffer-alloc-unsafe@1.1.0",
|
||||||
|
"_inBundle": false,
|
||||||
|
"_integrity": "sha512-TEM2iMIEQdJ2yjPJoSIsldnleVaAk1oW3DBVUykyOLsEsFmEc9kn+SFFPz+gl54KQNxlDnAwCXosOS9Okx2xAg==",
|
||||||
|
"_location": "/buffer-alloc-unsafe",
|
||||||
|
"_phantomChildren": {},
|
||||||
|
"_requested": {
|
||||||
|
"type": "range",
|
||||||
|
"registry": true,
|
||||||
|
"raw": "buffer-alloc-unsafe@^1.1.0",
|
||||||
|
"name": "buffer-alloc-unsafe",
|
||||||
|
"escapedName": "buffer-alloc-unsafe",
|
||||||
|
"rawSpec": "^1.1.0",
|
||||||
|
"saveSpec": null,
|
||||||
|
"fetchSpec": "^1.1.0"
|
||||||
|
},
|
||||||
|
"_requiredBy": [
|
||||||
|
"/buffer-alloc"
|
||||||
|
],
|
||||||
|
"_resolved": "https://registry.npmjs.org/buffer-alloc-unsafe/-/buffer-alloc-unsafe-1.1.0.tgz",
|
||||||
|
"_shasum": "bd7dc26ae2972d0eda253be061dba992349c19f0",
|
||||||
|
"_spec": "buffer-alloc-unsafe@^1.1.0",
|
||||||
|
"_where": "/Users/keiferju/code/Lingtu/smx-svelma/upload/node_modules/buffer-alloc",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/LinusU/buffer-alloc-unsafe/issues"
|
||||||
|
},
|
||||||
|
"bundleDependencies": false,
|
||||||
|
"deprecated": false,
|
||||||
|
"description": "A [ponyfill](https://ponyfill.com) for `Buffer.allocUnsafe`.",
|
||||||
|
"devDependencies": {
|
||||||
|
"standard": "^7.1.2"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"index.js"
|
||||||
|
],
|
||||||
|
"homepage": "https://github.com/LinusU/buffer-alloc-unsafe#readme",
|
||||||
|
"keywords": [
|
||||||
|
"allocUnsafe",
|
||||||
|
"allocate",
|
||||||
|
"buffer allocUnsafe",
|
||||||
|
"buffer unsafe allocate",
|
||||||
|
"buffer",
|
||||||
|
"ponyfill",
|
||||||
|
"unsafe allocate"
|
||||||
|
],
|
||||||
|
"license": "MIT",
|
||||||
|
"name": "buffer-alloc-unsafe",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/LinusU/buffer-alloc-unsafe.git"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "standard && node test"
|
||||||
|
},
|
||||||
|
"version": "1.1.0"
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
# Buffer Alloc Unsafe
|
||||||
|
|
||||||
|
A [ponyfill](https://ponyfill.com) for `Buffer.allocUnsafe`.
|
||||||
|
|
||||||
|
Works as Node.js: `v7.0.0` <br>
|
||||||
|
Works on Node.js: `v0.10.0`
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm install --save buffer-alloc-unsafe
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```js
|
||||||
|
const allocUnsafe = require('buffer-alloc-unsafe')
|
||||||
|
|
||||||
|
console.log(allocUnsafe(10))
|
||||||
|
//=> <Buffer 78 0c 80 03 01 00 00 00 05 00>
|
||||||
|
|
||||||
|
console.log(allocUnsafe(10))
|
||||||
|
//=> <Buffer 58 ed bf 5f ff 7f 00 00 01 00>
|
||||||
|
|
||||||
|
console.log(allocUnsafe(10))
|
||||||
|
//=> <Buffer 50 0c 80 03 01 00 00 00 0a 00>
|
||||||
|
|
||||||
|
allocUnsafe(-10)
|
||||||
|
//=> RangeError: "size" argument must not be negative
|
||||||
|
```
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
|
### allocUnsafe(size)
|
||||||
|
|
||||||
|
- `size` <Integer> The desired length of the new `Buffer`
|
||||||
|
|
||||||
|
Allocates a new *non-zero-filled* `Buffer` of `size` bytes. The `size` must be
|
||||||
|
less than or equal to the value of `buffer.kMaxLength` and greater than or equal
|
||||||
|
to zero. Otherwise, a `RangeError` is thrown.
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
- [buffer-alloc](https://github.com/LinusU/buffer-alloc) A ponyfill for `Buffer.alloc`
|
||||||
|
- [buffer-fill](https://github.com/LinusU/buffer-fill) A ponyfill for `Buffer.fill`
|
||||||
|
- [buffer-from](https://github.com/LinusU/buffer-from) A ponyfill for `Buffer.from`
|
|
@ -0,0 +1,32 @@
|
||||||
|
var bufferFill = require('buffer-fill')
|
||||||
|
var allocUnsafe = require('buffer-alloc-unsafe')
|
||||||
|
|
||||||
|
module.exports = function alloc (size, fill, encoding) {
|
||||||
|
if (typeof size !== 'number') {
|
||||||
|
throw new TypeError('"size" argument must be a number')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size < 0) {
|
||||||
|
throw new RangeError('"size" argument must not be negative')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Buffer.alloc) {
|
||||||
|
return Buffer.alloc(size, fill, encoding)
|
||||||
|
}
|
||||||
|
|
||||||
|
var buffer = allocUnsafe(size)
|
||||||
|
|
||||||
|
if (size === 0) {
|
||||||
|
return buffer
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fill === undefined) {
|
||||||
|
return bufferFill(buffer, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof encoding !== 'string') {
|
||||||
|
encoding = undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
return bufferFill(buffer, fill, encoding)
|
||||||
|
}
|
|
@ -0,0 +1,59 @@
|
||||||
|
{
|
||||||
|
"_from": "buffer-alloc@^1.2.0",
|
||||||
|
"_id": "buffer-alloc@1.2.0",
|
||||||
|
"_inBundle": false,
|
||||||
|
"_integrity": "sha512-CFsHQgjtW1UChdXgbyJGtnm+O/uLQeZdtbDo8mfUgYXCHSM1wgrVxXm6bSyrUuErEb+4sYVGCzASBRot7zyrow==",
|
||||||
|
"_location": "/buffer-alloc",
|
||||||
|
"_phantomChildren": {},
|
||||||
|
"_requested": {
|
||||||
|
"type": "range",
|
||||||
|
"registry": true,
|
||||||
|
"raw": "buffer-alloc@^1.2.0",
|
||||||
|
"name": "buffer-alloc",
|
||||||
|
"escapedName": "buffer-alloc",
|
||||||
|
"rawSpec": "^1.2.0",
|
||||||
|
"saveSpec": null,
|
||||||
|
"fetchSpec": "^1.2.0"
|
||||||
|
},
|
||||||
|
"_requiredBy": [
|
||||||
|
"/tar-stream"
|
||||||
|
],
|
||||||
|
"_resolved": "https://registry.npmjs.org/buffer-alloc/-/buffer-alloc-1.2.0.tgz",
|
||||||
|
"_shasum": "890dd90d923a873e08e10e5fd51a57e5b7cce0ec",
|
||||||
|
"_spec": "buffer-alloc@^1.2.0",
|
||||||
|
"_where": "/Users/keiferju/code/Lingtu/smx-svelma/upload/node_modules/tar-stream",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/LinusU/buffer-alloc/issues"
|
||||||
|
},
|
||||||
|
"bundleDependencies": false,
|
||||||
|
"dependencies": {
|
||||||
|
"buffer-alloc-unsafe": "^1.1.0",
|
||||||
|
"buffer-fill": "^1.0.0"
|
||||||
|
},
|
||||||
|
"deprecated": false,
|
||||||
|
"description": "A [ponyfill](https://ponyfill.com) for `Buffer.alloc`.",
|
||||||
|
"devDependencies": {
|
||||||
|
"standard": "^7.1.2"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"index.js"
|
||||||
|
],
|
||||||
|
"homepage": "https://github.com/LinusU/buffer-alloc#readme",
|
||||||
|
"keywords": [
|
||||||
|
"alloc",
|
||||||
|
"allocate",
|
||||||
|
"buffer alloc",
|
||||||
|
"buffer allocate",
|
||||||
|
"buffer"
|
||||||
|
],
|
||||||
|
"license": "MIT",
|
||||||
|
"name": "buffer-alloc",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/LinusU/buffer-alloc.git"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "standard && node test"
|
||||||
|
},
|
||||||
|
"version": "1.2.0"
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
# Buffer Alloc
|
||||||
|
|
||||||
|
A [ponyfill](https://ponyfill.com) for `Buffer.alloc`.
|
||||||
|
|
||||||
|
Works as Node.js: `v7.0.0` <br>
|
||||||
|
Works on Node.js: `v0.10.0`
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm install --save buffer-alloc
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```js
|
||||||
|
const alloc = require('buffer-alloc')
|
||||||
|
|
||||||
|
console.log(alloc(4))
|
||||||
|
//=> <Buffer 00 00 00 00>
|
||||||
|
|
||||||
|
console.log(alloc(6, 0x41))
|
||||||
|
//=> <Buffer 41 41 41 41 41 41>
|
||||||
|
|
||||||
|
console.log(alloc(10, 'linus', 'utf8'))
|
||||||
|
//=> <Buffer 6c 69 6e 75 73 6c 69 6e 75 73>
|
||||||
|
```
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
|
### alloc(size[, fill[, encoding]])
|
||||||
|
|
||||||
|
- `size` <Integer> The desired length of the new `Buffer`
|
||||||
|
- `fill` <String> | <Buffer> | <Integer> A value to pre-fill the new `Buffer` with. **Default:** `0`
|
||||||
|
- `encoding` <String> If `fill` is a string, this is its encoding. **Default:** `'utf8'`
|
||||||
|
|
||||||
|
Allocates a new `Buffer` of `size` bytes. If `fill` is `undefined`, the `Buffer` will be zero-filled.
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
- [buffer-alloc-unsafe](https://github.com/LinusU/buffer-alloc-unsafe) A ponyfill for `Buffer.allocUnsafe`
|
||||||
|
- [buffer-fill](https://github.com/LinusU/buffer-fill) A ponyfill for `Buffer.fill`
|
||||||
|
- [buffer-from](https://github.com/LinusU/buffer-from) A ponyfill for `Buffer.from`
|
|
@ -0,0 +1,19 @@
|
||||||
|
The MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2013 Brian J. Brennan
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal in
|
||||||
|
the Software without restriction, including without limitation the rights to use,
|
||||||
|
copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
|
||||||
|
Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
|
||||||
|
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
|
||||||
|
FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||||
|
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -0,0 +1,47 @@
|
||||||
|
# buffer-crc32
|
||||||
|
|
||||||
|
[](http://travis-ci.org/brianloveswords/buffer-crc32)
|
||||||
|
|
||||||
|
crc32 that works with binary data and fancy character sets, outputs
|
||||||
|
buffer, signed or unsigned data and has tests.
|
||||||
|
|
||||||
|
Derived from the sample CRC implementation in the PNG specification: http://www.w3.org/TR/PNG/#D-CRCAppendix
|
||||||
|
|
||||||
|
# install
|
||||||
|
```
|
||||||
|
npm install buffer-crc32
|
||||||
|
```
|
||||||
|
|
||||||
|
# example
|
||||||
|
```js
|
||||||
|
var crc32 = require('buffer-crc32');
|
||||||
|
// works with buffers
|
||||||
|
var buf = Buffer([0x00, 0x73, 0x75, 0x70, 0x20, 0x62, 0x72, 0x6f, 0x00])
|
||||||
|
crc32(buf) // -> <Buffer 94 5a ab 4a>
|
||||||
|
|
||||||
|
// has convenience methods for getting signed or unsigned ints
|
||||||
|
crc32.signed(buf) // -> -1805997238
|
||||||
|
crc32.unsigned(buf) // -> 2488970058
|
||||||
|
|
||||||
|
// will cast to buffer if given a string, so you can
|
||||||
|
// directly use foreign characters safely
|
||||||
|
crc32('自動販売機') // -> <Buffer cb 03 1a c5>
|
||||||
|
|
||||||
|
// and works in append mode too
|
||||||
|
var partialCrc = crc32('hey');
|
||||||
|
var partialCrc = crc32(' ', partialCrc);
|
||||||
|
var partialCrc = crc32('sup', partialCrc);
|
||||||
|
var partialCrc = crc32(' ', partialCrc);
|
||||||
|
var finalCrc = crc32('bros', partialCrc); // -> <Buffer 47 fa 55 70>
|
||||||
|
```
|
||||||
|
|
||||||
|
# tests
|
||||||
|
This was tested against the output of zlib's crc32 method. You can run
|
||||||
|
the tests with`npm test` (requires tap)
|
||||||
|
|
||||||
|
# see also
|
||||||
|
https://github.com/alexgorbatchev/node-crc, `crc.buffer.crc32` also
|
||||||
|
supports buffer inputs and return unsigned ints (thanks @tjholowaychuk).
|
||||||
|
|
||||||
|
# license
|
||||||
|
MIT/X11
|
|
@ -0,0 +1,111 @@
|
||||||
|
var Buffer = require('buffer').Buffer;
|
||||||
|
|
||||||
|
var CRC_TABLE = [
|
||||||
|
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
|
||||||
|
0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
|
||||||
|
0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
|
||||||
|
0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
|
||||||
|
0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
|
||||||
|
0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
|
||||||
|
0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
|
||||||
|
0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
|
||||||
|
0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
|
||||||
|
0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
|
||||||
|
0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
|
||||||
|
0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
|
||||||
|
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
|
||||||
|
0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
|
||||||
|
0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
|
||||||
|
0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
|
||||||
|
0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
|
||||||
|
0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
|
||||||
|
0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
|
||||||
|
0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
|
||||||
|
0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
|
||||||
|
0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
|
||||||
|
0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
|
||||||
|
0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
|
||||||
|
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
|
||||||
|
0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
|
||||||
|
0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
|
||||||
|
0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
|
||||||
|
0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
|
||||||
|
0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
|
||||||
|
0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
|
||||||
|
0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
|
||||||
|
0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
|
||||||
|
0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
|
||||||
|
0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
|
||||||
|
0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
|
||||||
|
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
|
||||||
|
0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
|
||||||
|
0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
|
||||||
|
0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
|
||||||
|
0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
|
||||||
|
0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
|
||||||
|
0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
|
||||||
|
0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
|
||||||
|
0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
|
||||||
|
0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
|
||||||
|
0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
|
||||||
|
0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
|
||||||
|
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
|
||||||
|
0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
|
||||||
|
0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
|
||||||
|
0x2d02ef8d
|
||||||
|
];
|
||||||
|
|
||||||
|
if (typeof Int32Array !== 'undefined') {
|
||||||
|
CRC_TABLE = new Int32Array(CRC_TABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
function ensureBuffer(input) {
|
||||||
|
if (Buffer.isBuffer(input)) {
|
||||||
|
return input;
|
||||||
|
}
|
||||||
|
|
||||||
|
var hasNewBufferAPI =
|
||||||
|
typeof Buffer.alloc === "function" &&
|
||||||
|
typeof Buffer.from === "function";
|
||||||
|
|
||||||
|
if (typeof input === "number") {
|
||||||
|
return hasNewBufferAPI ? Buffer.alloc(input) : new Buffer(input);
|
||||||
|
}
|
||||||
|
else if (typeof input === "string") {
|
||||||
|
return hasNewBufferAPI ? Buffer.from(input) : new Buffer(input);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new Error("input must be buffer, number, or string, received " +
|
||||||
|
typeof input);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function bufferizeInt(num) {
|
||||||
|
var tmp = ensureBuffer(4);
|
||||||
|
tmp.writeInt32BE(num, 0);
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
function _crc32(buf, previous) {
|
||||||
|
buf = ensureBuffer(buf);
|
||||||
|
if (Buffer.isBuffer(previous)) {
|
||||||
|
previous = previous.readUInt32BE(0);
|
||||||
|
}
|
||||||
|
var crc = ~~previous ^ -1;
|
||||||
|
for (var n = 0; n < buf.length; n++) {
|
||||||
|
crc = CRC_TABLE[(crc ^ buf[n]) & 0xff] ^ (crc >>> 8);
|
||||||
|
}
|
||||||
|
return (crc ^ -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
function crc32() {
|
||||||
|
return bufferizeInt(_crc32.apply(null, arguments));
|
||||||
|
}
|
||||||
|
crc32.signed = function () {
|
||||||
|
return _crc32.apply(null, arguments);
|
||||||
|
};
|
||||||
|
crc32.unsigned = function () {
|
||||||
|
return _crc32.apply(null, arguments) >>> 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = crc32;
|
|
@ -0,0 +1,70 @@
|
||||||
|
{
|
||||||
|
"_from": "buffer-crc32@~0.2.3",
|
||||||
|
"_id": "buffer-crc32@0.2.13",
|
||||||
|
"_inBundle": false,
|
||||||
|
"_integrity": "sha1-DTM+PwDqxQqhRUq9MO+MKl2ackI=",
|
||||||
|
"_location": "/buffer-crc32",
|
||||||
|
"_phantomChildren": {},
|
||||||
|
"_requested": {
|
||||||
|
"type": "range",
|
||||||
|
"registry": true,
|
||||||
|
"raw": "buffer-crc32@~0.2.3",
|
||||||
|
"name": "buffer-crc32",
|
||||||
|
"escapedName": "buffer-crc32",
|
||||||
|
"rawSpec": "~0.2.3",
|
||||||
|
"saveSpec": null,
|
||||||
|
"fetchSpec": "~0.2.3"
|
||||||
|
},
|
||||||
|
"_requiredBy": [
|
||||||
|
"/yauzl",
|
||||||
|
"/yazl"
|
||||||
|
],
|
||||||
|
"_resolved": "https://registry.npmjs.org/buffer-crc32/-/buffer-crc32-0.2.13.tgz",
|
||||||
|
"_shasum": "0d333e3f00eac50aa1454abd30ef8c2a5d9a7242",
|
||||||
|
"_spec": "buffer-crc32@~0.2.3",
|
||||||
|
"_where": "/Users/keiferju/code/Lingtu/smx-svelma/upload/node_modules/yauzl",
|
||||||
|
"author": {
|
||||||
|
"name": "Brian J. Brennan",
|
||||||
|
"email": "brianloveswords@gmail.com"
|
||||||
|
},
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/brianloveswords/buffer-crc32/issues"
|
||||||
|
},
|
||||||
|
"bundleDependencies": false,
|
||||||
|
"contributors": [
|
||||||
|
{
|
||||||
|
"name": "Vladimir Kuznetsov"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"dependencies": {},
|
||||||
|
"deprecated": false,
|
||||||
|
"description": "A pure javascript CRC32 algorithm that plays nice with binary data",
|
||||||
|
"devDependencies": {
|
||||||
|
"tap": "~0.2.5"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": "*"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"index.js"
|
||||||
|
],
|
||||||
|
"homepage": "https://github.com/brianloveswords/buffer-crc32",
|
||||||
|
"license": "MIT",
|
||||||
|
"licenses": [
|
||||||
|
{
|
||||||
|
"type": "MIT",
|
||||||
|
"url": "https://github.com/brianloveswords/buffer-crc32/raw/master/LICENSE"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"main": "index.js",
|
||||||
|
"name": "buffer-crc32",
|
||||||
|
"optionalDependencies": {},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git://github.com/brianloveswords/buffer-crc32.git"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "tap tests/*.test.js"
|
||||||
|
},
|
||||||
|
"version": "0.2.13"
|
||||||
|
}
|
|
@ -0,0 +1,113 @@
|
||||||
|
/* Node.js 6.4.0 and up has full support */
|
||||||
|
var hasFullSupport = (function () {
|
||||||
|
try {
|
||||||
|
if (!Buffer.isEncoding('latin1')) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
var buf = Buffer.alloc ? Buffer.alloc(4) : new Buffer(4)
|
||||||
|
|
||||||
|
buf.fill('ab', 'ucs2')
|
||||||
|
|
||||||
|
return (buf.toString('hex') === '61006200')
|
||||||
|
} catch (_) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}())
|
||||||
|
|
||||||
|
function isSingleByte (val) {
|
||||||
|
return (val.length === 1 && val.charCodeAt(0) < 256)
|
||||||
|
}
|
||||||
|
|
||||||
|
function fillWithNumber (buffer, val, start, end) {
|
||||||
|
if (start < 0 || end > buffer.length) {
|
||||||
|
throw new RangeError('Out of range index')
|
||||||
|
}
|
||||||
|
|
||||||
|
start = start >>> 0
|
||||||
|
end = end === undefined ? buffer.length : end >>> 0
|
||||||
|
|
||||||
|
if (end > start) {
|
||||||
|
buffer.fill(val, start, end)
|
||||||
|
}
|
||||||
|
|
||||||
|
return buffer
|
||||||
|
}
|
||||||
|
|
||||||
|
function fillWithBuffer (buffer, val, start, end) {
|
||||||
|
if (start < 0 || end > buffer.length) {
|
||||||
|
throw new RangeError('Out of range index')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (end <= start) {
|
||||||
|
return buffer
|
||||||
|
}
|
||||||
|
|
||||||
|
start = start >>> 0
|
||||||
|
end = end === undefined ? buffer.length : end >>> 0
|
||||||
|
|
||||||
|
var pos = start
|
||||||
|
var len = val.length
|
||||||
|
while (pos <= (end - len)) {
|
||||||
|
val.copy(buffer, pos)
|
||||||
|
pos += len
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pos !== end) {
|
||||||
|
val.copy(buffer, pos, 0, end - pos)
|
||||||
|
}
|
||||||
|
|
||||||
|
return buffer
|
||||||
|
}
|
||||||
|
|
||||||
|
function fill (buffer, val, start, end, encoding) {
|
||||||
|
if (hasFullSupport) {
|
||||||
|
return buffer.fill(val, start, end, encoding)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof val === 'number') {
|
||||||
|
return fillWithNumber(buffer, val, start, end)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof val === 'string') {
|
||||||
|
if (typeof start === 'string') {
|
||||||
|
encoding = start
|
||||||
|
start = 0
|
||||||
|
end = buffer.length
|
||||||
|
} else if (typeof end === 'string') {
|
||||||
|
encoding = end
|
||||||
|
end = buffer.length
|
||||||
|
}
|
||||||
|
|
||||||
|
if (encoding !== undefined && typeof encoding !== 'string') {
|
||||||
|
throw new TypeError('encoding must be a string')
|
||||||
|
}
|
||||||
|
|
||||||
|
if (encoding === 'latin1') {
|
||||||
|
encoding = 'binary'
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof encoding === 'string' && !Buffer.isEncoding(encoding)) {
|
||||||
|
throw new TypeError('Unknown encoding: ' + encoding)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (val === '') {
|
||||||
|
return fillWithNumber(buffer, 0, start, end)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isSingleByte(val)) {
|
||||||
|
return fillWithNumber(buffer, val.charCodeAt(0), start, end)
|
||||||
|
}
|
||||||
|
|
||||||
|
val = new Buffer(val, encoding)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Buffer.isBuffer(val)) {
|
||||||
|
return fillWithBuffer(buffer, val, start, end)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Other values (e.g. undefined, boolean, object) results in zero-fill
|
||||||
|
return fillWithNumber(buffer, 0, start, end)
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = fill
|
|
@ -0,0 +1,49 @@
|
||||||
|
{
|
||||||
|
"_from": "buffer-fill@^1.0.0",
|
||||||
|
"_id": "buffer-fill@1.0.0",
|
||||||
|
"_inBundle": false,
|
||||||
|
"_integrity": "sha1-+PeLdniYiO858gXNY39o5wISKyw=",
|
||||||
|
"_location": "/buffer-fill",
|
||||||
|
"_phantomChildren": {},
|
||||||
|
"_requested": {
|
||||||
|
"type": "range",
|
||||||
|
"registry": true,
|
||||||
|
"raw": "buffer-fill@^1.0.0",
|
||||||
|
"name": "buffer-fill",
|
||||||
|
"escapedName": "buffer-fill",
|
||||||
|
"rawSpec": "^1.0.0",
|
||||||
|
"saveSpec": null,
|
||||||
|
"fetchSpec": "^1.0.0"
|
||||||
|
},
|
||||||
|
"_requiredBy": [
|
||||||
|
"/buffer-alloc"
|
||||||
|
],
|
||||||
|
"_resolved": "https://registry.npmjs.org/buffer-fill/-/buffer-fill-1.0.0.tgz",
|
||||||
|
"_shasum": "f8f78b76789888ef39f205cd637f68e702122b2c",
|
||||||
|
"_spec": "buffer-fill@^1.0.0",
|
||||||
|
"_where": "/Users/keiferju/code/Lingtu/smx-svelma/upload/node_modules/buffer-alloc",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/LinusU/buffer-fill/issues"
|
||||||
|
},
|
||||||
|
"bundleDependencies": false,
|
||||||
|
"deprecated": false,
|
||||||
|
"description": "A [ponyfill](https://ponyfill.com) for `Buffer.fill`.",
|
||||||
|
"devDependencies": {
|
||||||
|
"buffer-alloc-unsafe": "^1.1.0",
|
||||||
|
"standard": "^7.1.2"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"index.js"
|
||||||
|
],
|
||||||
|
"homepage": "https://github.com/LinusU/buffer-fill#readme",
|
||||||
|
"license": "MIT",
|
||||||
|
"name": "buffer-fill",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/LinusU/buffer-fill.git"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "standard && node test"
|
||||||
|
},
|
||||||
|
"version": "1.0.0"
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
# Buffer Fill
|
||||||
|
|
||||||
|
A [ponyfill](https://ponyfill.com) for `Buffer.fill`.
|
||||||
|
|
||||||
|
Works as Node.js: `v6.4.0` <br>
|
||||||
|
Works on Node.js: `v0.10.0`
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
```sh
|
||||||
|
npm install --save buffer-fill
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```js
|
||||||
|
const fill = require('buffer-fill')
|
||||||
|
const buf = Buffer.allocUnsafe(5)
|
||||||
|
|
||||||
|
console.log(buf.fill(8))
|
||||||
|
//=> <Buffer 08 08 08 08 08>
|
||||||
|
|
||||||
|
console.log(buf.fill(9, 2, 4))
|
||||||
|
//=> <Buffer 08 08 09 09 08>
|
||||||
|
|
||||||
|
console.log(buf.fill('linus', 'latin1'))
|
||||||
|
//=> <Buffer 6c 69 6e 75 73>
|
||||||
|
|
||||||
|
console.log(buf.fill('\u0222'))
|
||||||
|
//=> <Buffer c8 a2 c8 a2 c8>
|
||||||
|
```
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
|
### fill(buf, value[, offset[, end]][, encoding])
|
||||||
|
|
||||||
|
- `value` <String> | <Buffer> | <Integer> The value to fill `buf` with
|
||||||
|
- `offset` <Integer> Where to start filling `buf`. **Default:** `0`
|
||||||
|
- `end` <Integer> Where to stop filling `buf` (not inclusive). **Default:** `buf.length`
|
||||||
|
- `encoding` <String> If `value` is a string, this is its encoding. **Default:** `'utf8'`
|
||||||
|
- Return: <Buffer> A reference to `buf`
|
||||||
|
|
||||||
|
Fills `buf` with the specified `value`. If the `offset` and `end` are not given,
|
||||||
|
the entire `buf` will be filled. This is meant to be a small simplification to
|
||||||
|
allow the creation and filling of a `Buffer` to be done on a single line.
|
||||||
|
|
||||||
|
If the final write of a `fill()` operation falls on a multi-byte character, then
|
||||||
|
only the first bytes of that character that fit into `buf` are written.
|
||||||
|
|
||||||
|
## See also
|
||||||
|
|
||||||
|
- [buffer-alloc-unsafe](https://github.com/LinusU/buffer-alloc-unsafe) A ponyfill for `Buffer.allocUnsafe`
|
||||||
|
- [buffer-alloc](https://github.com/LinusU/buffer-alloc) A ponyfill for `Buffer.alloc`
|
||||||
|
- [buffer-from](https://github.com/LinusU/buffer-from) A ponyfill for `Buffer.from`
|
|
@ -0,0 +1,411 @@
|
||||||
|
declare const enum LevelEnum {
|
||||||
|
/**
|
||||||
|
All colors disabled.
|
||||||
|
*/
|
||||||
|
None = 0,
|
||||||
|
|
||||||
|
/**
|
||||||
|
Basic 16 colors support.
|
||||||
|
*/
|
||||||
|
Basic = 1,
|
||||||
|
|
||||||
|
/**
|
||||||
|
ANSI 256 colors support.
|
||||||
|
*/
|
||||||
|
Ansi256 = 2,
|
||||||
|
|
||||||
|
/**
|
||||||
|
Truecolor 16 million colors support.
|
||||||
|
*/
|
||||||
|
TrueColor = 3
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Basic foreground colors.
|
||||||
|
|
||||||
|
[More colors here.](https://github.com/chalk/chalk/blob/master/readme.md#256-and-truecolor-color-support)
|
||||||
|
*/
|
||||||
|
declare type ForegroundColor =
|
||||||
|
| 'black'
|
||||||
|
| 'red'
|
||||||
|
| 'green'
|
||||||
|
| 'yellow'
|
||||||
|
| 'blue'
|
||||||
|
| 'magenta'
|
||||||
|
| 'cyan'
|
||||||
|
| 'white'
|
||||||
|
| 'gray'
|
||||||
|
| 'grey'
|
||||||
|
| 'blackBright'
|
||||||
|
| 'redBright'
|
||||||
|
| 'greenBright'
|
||||||
|
| 'yellowBright'
|
||||||
|
| 'blueBright'
|
||||||
|
| 'magentaBright'
|
||||||
|
| 'cyanBright'
|
||||||
|
| 'whiteBright';
|
||||||
|
|
||||||
|
/**
|
||||||
|
Basic background colors.
|
||||||
|
|
||||||
|
[More colors here.](https://github.com/chalk/chalk/blob/master/readme.md#256-and-truecolor-color-support)
|
||||||
|
*/
|
||||||
|
declare type BackgroundColor =
|
||||||
|
| 'bgBlack'
|
||||||
|
| 'bgRed'
|
||||||
|
| 'bgGreen'
|
||||||
|
| 'bgYellow'
|
||||||
|
| 'bgBlue'
|
||||||
|
| 'bgMagenta'
|
||||||
|
| 'bgCyan'
|
||||||
|
| 'bgWhite'
|
||||||
|
| 'bgGray'
|
||||||
|
| 'bgGrey'
|
||||||
|
| 'bgBlackBright'
|
||||||
|
| 'bgRedBright'
|
||||||
|
| 'bgGreenBright'
|
||||||
|
| 'bgYellowBright'
|
||||||
|
| 'bgBlueBright'
|
||||||
|
| 'bgMagentaBright'
|
||||||
|
| 'bgCyanBright'
|
||||||
|
| 'bgWhiteBright';
|
||||||
|
|
||||||
|
/**
|
||||||
|
Basic colors.
|
||||||
|
|
||||||
|
[More colors here.](https://github.com/chalk/chalk/blob/master/readme.md#256-and-truecolor-color-support)
|
||||||
|
*/
|
||||||
|
declare type Color = ForegroundColor | BackgroundColor;
|
||||||
|
|
||||||
|
declare type Modifiers =
|
||||||
|
| 'reset'
|
||||||
|
| 'bold'
|
||||||
|
| 'dim'
|
||||||
|
| 'italic'
|
||||||
|
| 'underline'
|
||||||
|
| 'inverse'
|
||||||
|
| 'hidden'
|
||||||
|
| 'strikethrough'
|
||||||
|
| 'visible';
|
||||||
|
|
||||||
|
declare namespace chalk {
|
||||||
|
type Level = LevelEnum;
|
||||||
|
|
||||||
|
interface Options {
|
||||||
|
/**
|
||||||
|
Specify the color support for Chalk.
|
||||||
|
By default, color support is automatically detected based on the environment.
|
||||||
|
*/
|
||||||
|
level?: Level;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Instance {
|
||||||
|
/**
|
||||||
|
Return a new Chalk instance.
|
||||||
|
*/
|
||||||
|
new (options?: Options): Chalk;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Detect whether the terminal supports color.
|
||||||
|
*/
|
||||||
|
interface ColorSupport {
|
||||||
|
/**
|
||||||
|
The color level used by Chalk.
|
||||||
|
*/
|
||||||
|
level: Level;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Return whether Chalk supports basic 16 colors.
|
||||||
|
*/
|
||||||
|
hasBasic: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Return whether Chalk supports ANSI 256 colors.
|
||||||
|
*/
|
||||||
|
has256: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Return whether Chalk supports Truecolor 16 million colors.
|
||||||
|
*/
|
||||||
|
has16m: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface ChalkFunction {
|
||||||
|
/**
|
||||||
|
Use a template string.
|
||||||
|
|
||||||
|
@remarks Template literals are unsupported for nested calls (see [issue #341](https://github.com/chalk/chalk/issues/341))
|
||||||
|
|
||||||
|
@example
|
||||||
|
```
|
||||||
|
import chalk = require('chalk');
|
||||||
|
|
||||||
|
log(chalk`
|
||||||
|
CPU: {red ${cpu.totalPercent}%}
|
||||||
|
RAM: {green ${ram.used / ram.total * 100}%}
|
||||||
|
DISK: {rgb(255,131,0) ${disk.used / disk.total * 100}%}
|
||||||
|
`);
|
||||||
|
```
|
||||||
|
*/
|
||||||
|
(text: TemplateStringsArray, ...placeholders: unknown[]): string;
|
||||||
|
|
||||||
|
(...text: unknown[]): string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Chalk extends ChalkFunction {
|
||||||
|
/**
|
||||||
|
Return a new Chalk instance.
|
||||||
|
*/
|
||||||
|
Instance: Instance;
|
||||||
|
|
||||||
|
/**
|
||||||
|
The color support for Chalk.
|
||||||
|
By default, color support is automatically detected based on the environment.
|
||||||
|
*/
|
||||||
|
level: Level;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Use HEX value to set text color.
|
||||||
|
|
||||||
|
@param color - Hexadecimal value representing the desired color.
|
||||||
|
|
||||||
|
@example
|
||||||
|
```
|
||||||
|
import chalk = require('chalk');
|
||||||
|
|
||||||
|
chalk.hex('#DEADED');
|
||||||
|
```
|
||||||
|
*/
|
||||||
|
hex(color: string): Chalk;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Use keyword color value to set text color.
|
||||||
|
|
||||||
|
@param color - Keyword value representing the desired color.
|
||||||
|
|
||||||
|
@example
|
||||||
|
```
|
||||||
|
import chalk = require('chalk');
|
||||||
|
|
||||||
|
chalk.keyword('orange');
|
||||||
|
```
|
||||||
|
*/
|
||||||
|
keyword(color: string): Chalk;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Use RGB values to set text color.
|
||||||
|
*/
|
||||||
|
rgb(red: number, green: number, blue: number): Chalk;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Use HSL values to set text color.
|
||||||
|
*/
|
||||||
|
hsl(hue: number, saturation: number, lightness: number): Chalk;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Use HSV values to set text color.
|
||||||
|
*/
|
||||||
|
hsv(hue: number, saturation: number, value: number): Chalk;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Use HWB values to set text color.
|
||||||
|
*/
|
||||||
|
hwb(hue: number, whiteness: number, blackness: number): Chalk;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Use a [Select/Set Graphic Rendition](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters) (SGR) [color code number](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit) to set text color.
|
||||||
|
|
||||||
|
30 <= code && code < 38 || 90 <= code && code < 98
|
||||||
|
For example, 31 for red, 91 for redBright.
|
||||||
|
*/
|
||||||
|
ansi(code: number): Chalk;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Use a [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set text color.
|
||||||
|
*/
|
||||||
|
ansi256(index: number): Chalk;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Use HEX value to set background color.
|
||||||
|
|
||||||
|
@param color - Hexadecimal value representing the desired color.
|
||||||
|
|
||||||
|
@example
|
||||||
|
```
|
||||||
|
import chalk = require('chalk');
|
||||||
|
|
||||||
|
chalk.bgHex('#DEADED');
|
||||||
|
```
|
||||||
|
*/
|
||||||
|
bgHex(color: string): Chalk;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Use keyword color value to set background color.
|
||||||
|
|
||||||
|
@param color - Keyword value representing the desired color.
|
||||||
|
|
||||||
|
@example
|
||||||
|
```
|
||||||
|
import chalk = require('chalk');
|
||||||
|
|
||||||
|
chalk.bgKeyword('orange');
|
||||||
|
```
|
||||||
|
*/
|
||||||
|
bgKeyword(color: string): Chalk;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Use RGB values to set background color.
|
||||||
|
*/
|
||||||
|
bgRgb(red: number, green: number, blue: number): Chalk;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Use HSL values to set background color.
|
||||||
|
*/
|
||||||
|
bgHsl(hue: number, saturation: number, lightness: number): Chalk;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Use HSV values to set background color.
|
||||||
|
*/
|
||||||
|
bgHsv(hue: number, saturation: number, value: number): Chalk;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Use HWB values to set background color.
|
||||||
|
*/
|
||||||
|
bgHwb(hue: number, whiteness: number, blackness: number): Chalk;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Use a [Select/Set Graphic Rendition](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters) (SGR) [color code number](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit) to set background color.
|
||||||
|
|
||||||
|
30 <= code && code < 38 || 90 <= code && code < 98
|
||||||
|
For example, 31 for red, 91 for redBright.
|
||||||
|
Use the foreground code, not the background code (for example, not 41, nor 101).
|
||||||
|
*/
|
||||||
|
bgAnsi(code: number): Chalk;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Use a [8-bit unsigned number](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) to set background color.
|
||||||
|
*/
|
||||||
|
bgAnsi256(index: number): Chalk;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Modifier: Resets the current color chain.
|
||||||
|
*/
|
||||||
|
readonly reset: Chalk;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Modifier: Make text bold.
|
||||||
|
*/
|
||||||
|
readonly bold: Chalk;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Modifier: Emitting only a small amount of light.
|
||||||
|
*/
|
||||||
|
readonly dim: Chalk;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Modifier: Make text italic. (Not widely supported)
|
||||||
|
*/
|
||||||
|
readonly italic: Chalk;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Modifier: Make text underline. (Not widely supported)
|
||||||
|
*/
|
||||||
|
readonly underline: Chalk;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Modifier: Inverse background and foreground colors.
|
||||||
|
*/
|
||||||
|
readonly inverse: Chalk;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Modifier: Prints the text, but makes it invisible.
|
||||||
|
*/
|
||||||
|
readonly hidden: Chalk;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Modifier: Puts a horizontal line through the center of the text. (Not widely supported)
|
||||||
|
*/
|
||||||
|
readonly strikethrough: Chalk;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Modifier: Prints the text only when Chalk has a color support level > 0.
|
||||||
|
Can be useful for things that are purely cosmetic.
|
||||||
|
*/
|
||||||
|
readonly visible: Chalk;
|
||||||
|
|
||||||
|
readonly black: Chalk;
|
||||||
|
readonly red: Chalk;
|
||||||
|
readonly green: Chalk;
|
||||||
|
readonly yellow: Chalk;
|
||||||
|
readonly blue: Chalk;
|
||||||
|
readonly magenta: Chalk;
|
||||||
|
readonly cyan: Chalk;
|
||||||
|
readonly white: Chalk;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Alias for `blackBright`.
|
||||||
|
*/
|
||||||
|
readonly gray: Chalk;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Alias for `blackBright`.
|
||||||
|
*/
|
||||||
|
readonly grey: Chalk;
|
||||||
|
|
||||||
|
readonly blackBright: Chalk;
|
||||||
|
readonly redBright: Chalk;
|
||||||
|
readonly greenBright: Chalk;
|
||||||
|
readonly yellowBright: Chalk;
|
||||||
|
readonly blueBright: Chalk;
|
||||||
|
readonly magentaBright: Chalk;
|
||||||
|
readonly cyanBright: Chalk;
|
||||||
|
readonly whiteBright: Chalk;
|
||||||
|
|
||||||
|
readonly bgBlack: Chalk;
|
||||||
|
readonly bgRed: Chalk;
|
||||||
|
readonly bgGreen: Chalk;
|
||||||
|
readonly bgYellow: Chalk;
|
||||||
|
readonly bgBlue: Chalk;
|
||||||
|
readonly bgMagenta: Chalk;
|
||||||
|
readonly bgCyan: Chalk;
|
||||||
|
readonly bgWhite: Chalk;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Alias for `bgBlackBright`.
|
||||||
|
*/
|
||||||
|
readonly bgGray: Chalk;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Alias for `bgBlackBright`.
|
||||||
|
*/
|
||||||
|
readonly bgGrey: Chalk;
|
||||||
|
|
||||||
|
readonly bgBlackBright: Chalk;
|
||||||
|
readonly bgRedBright: Chalk;
|
||||||
|
readonly bgGreenBright: Chalk;
|
||||||
|
readonly bgYellowBright: Chalk;
|
||||||
|
readonly bgBlueBright: Chalk;
|
||||||
|
readonly bgMagentaBright: Chalk;
|
||||||
|
readonly bgCyanBright: Chalk;
|
||||||
|
readonly bgWhiteBright: Chalk;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Main Chalk object that allows to chain styles together.
|
||||||
|
Call the last one as a method with a string argument.
|
||||||
|
Order doesn't matter, and later styles take precedent in case of a conflict.
|
||||||
|
This simply means that `chalk.red.yellow.green` is equivalent to `chalk.green`.
|
||||||
|
*/
|
||||||
|
declare const chalk: chalk.Chalk & chalk.ChalkFunction & {
|
||||||
|
supportsColor: chalk.ColorSupport | false;
|
||||||
|
Level: typeof LevelEnum;
|
||||||
|
Color: Color;
|
||||||
|
ForegroundColor: ForegroundColor;
|
||||||
|
BackgroundColor: BackgroundColor;
|
||||||
|
Modifiers: Modifiers;
|
||||||
|
stderr: chalk.Chalk & {supportsColor: chalk.ColorSupport | false};
|
||||||
|
};
|
||||||
|
|
||||||
|
export = chalk;
|
|
@ -0,0 +1,9 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -0,0 +1,98 @@
|
||||||
|
{
|
||||||
|
"_from": "chalk",
|
||||||
|
"_id": "chalk@3.0.0",
|
||||||
|
"_inBundle": false,
|
||||||
|
"_integrity": "sha512-4D3B6Wf41KOYRFdszmDqMCGq5VV/uMAB273JILmO+3jAlh8X4qDtdtgCR3fxtbLEMzSx22QdhnDcJvu2u1fVwg==",
|
||||||
|
"_location": "/chalk",
|
||||||
|
"_phantomChildren": {},
|
||||||
|
"_requested": {
|
||||||
|
"type": "tag",
|
||||||
|
"registry": true,
|
||||||
|
"raw": "chalk",
|
||||||
|
"name": "chalk",
|
||||||
|
"escapedName": "chalk",
|
||||||
|
"rawSpec": "",
|
||||||
|
"saveSpec": null,
|
||||||
|
"fetchSpec": "latest"
|
||||||
|
},
|
||||||
|
"_requiredBy": [
|
||||||
|
"#DEV:/",
|
||||||
|
"#USER",
|
||||||
|
"/inquirer",
|
||||||
|
"/ora"
|
||||||
|
],
|
||||||
|
"_resolved": "https://registry.npmjs.org/chalk/-/chalk-3.0.0.tgz",
|
||||||
|
"_shasum": "3f73c2bf526591f574cc492c51e2456349f844e4",
|
||||||
|
"_spec": "chalk",
|
||||||
|
"_where": "/Users/keiferju/code/Lingtu/smx-svelma/upload",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/chalk/chalk/issues"
|
||||||
|
},
|
||||||
|
"bundleDependencies": false,
|
||||||
|
"dependencies": {
|
||||||
|
"ansi-styles": "^4.1.0",
|
||||||
|
"supports-color": "^7.1.0"
|
||||||
|
},
|
||||||
|
"deprecated": false,
|
||||||
|
"description": "Terminal string styling done right",
|
||||||
|
"devDependencies": {
|
||||||
|
"ava": "^2.4.0",
|
||||||
|
"coveralls": "^3.0.7",
|
||||||
|
"execa": "^3.2.0",
|
||||||
|
"import-fresh": "^3.1.0",
|
||||||
|
"matcha": "^0.7.0",
|
||||||
|
"nyc": "^14.1.1",
|
||||||
|
"resolve-from": "^5.0.0",
|
||||||
|
"tsd": "^0.7.4",
|
||||||
|
"xo": "^0.25.3"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"source",
|
||||||
|
"index.d.ts"
|
||||||
|
],
|
||||||
|
"homepage": "https://github.com/chalk/chalk#readme",
|
||||||
|
"keywords": [
|
||||||
|
"color",
|
||||||
|
"colour",
|
||||||
|
"colors",
|
||||||
|
"terminal",
|
||||||
|
"console",
|
||||||
|
"cli",
|
||||||
|
"string",
|
||||||
|
"str",
|
||||||
|
"ansi",
|
||||||
|
"style",
|
||||||
|
"styles",
|
||||||
|
"tty",
|
||||||
|
"formatting",
|
||||||
|
"rgb",
|
||||||
|
"256",
|
||||||
|
"shell",
|
||||||
|
"xterm",
|
||||||
|
"log",
|
||||||
|
"logging",
|
||||||
|
"command-line",
|
||||||
|
"text"
|
||||||
|
],
|
||||||
|
"license": "MIT",
|
||||||
|
"main": "source",
|
||||||
|
"name": "chalk",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/chalk/chalk.git"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"bench": "matcha benchmark.js",
|
||||||
|
"test": "xo && nyc ava && tsd"
|
||||||
|
},
|
||||||
|
"version": "3.0.0",
|
||||||
|
"xo": {
|
||||||
|
"rules": {
|
||||||
|
"unicorn/prefer-string-slice": "off",
|
||||||
|
"unicorn/prefer-includes": "off"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,304 @@
|
||||||
|
<h1 align="center">
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<img width="320" src="media/logo.svg" alt="Chalk">
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
</h1>
|
||||||
|
|
||||||
|
> Terminal string styling done right
|
||||||
|
|
||||||
|
[](https://travis-ci.org/chalk/chalk) [](https://coveralls.io/github/chalk/chalk?branch=master) [](https://www.npmjs.com/package/chalk?activeTab=dependents) [](https://www.npmjs.com/package/chalk) [](https://www.youtube.com/watch?v=9auOCbH5Ns4) [](https://github.com/xojs/xo) 
|
||||||
|
|
||||||
|
<img src="https://cdn.jsdelivr.net/gh/chalk/ansi-styles@8261697c95bf34b6c7767e2cbe9941a851d59385/screenshot.svg" width="900">
|
||||||
|
|
||||||
|
|
||||||
|
## Highlights
|
||||||
|
|
||||||
|
- Expressive API
|
||||||
|
- Highly performant
|
||||||
|
- Ability to nest styles
|
||||||
|
- [256/Truecolor color support](#256-and-truecolor-color-support)
|
||||||
|
- Auto-detects color support
|
||||||
|
- Doesn't extend `String.prototype`
|
||||||
|
- Clean and focused
|
||||||
|
- Actively maintained
|
||||||
|
- [Used by ~46,000 packages](https://www.npmjs.com/browse/depended/chalk) as of October 1, 2019
|
||||||
|
|
||||||
|
|
||||||
|
## Install
|
||||||
|
|
||||||
|
```console
|
||||||
|
$ npm install chalk
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```js
|
||||||
|
const chalk = require('chalk');
|
||||||
|
|
||||||
|
console.log(chalk.blue('Hello world!'));
|
||||||
|
```
|
||||||
|
|
||||||
|
Chalk comes with an easy to use composable API where you just chain and nest the styles you want.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const chalk = require('chalk');
|
||||||
|
const log = console.log;
|
||||||
|
|
||||||
|
// Combine styled and normal strings
|
||||||
|
log(chalk.blue('Hello') + ' World' + chalk.red('!'));
|
||||||
|
|
||||||
|
// Compose multiple styles using the chainable API
|
||||||
|
log(chalk.blue.bgRed.bold('Hello world!'));
|
||||||
|
|
||||||
|
// Pass in multiple arguments
|
||||||
|
log(chalk.blue('Hello', 'World!', 'Foo', 'bar', 'biz', 'baz'));
|
||||||
|
|
||||||
|
// Nest styles
|
||||||
|
log(chalk.red('Hello', chalk.underline.bgBlue('world') + '!'));
|
||||||
|
|
||||||
|
// Nest styles of the same type even (color, underline, background)
|
||||||
|
log(chalk.green(
|
||||||
|
'I am a green line ' +
|
||||||
|
chalk.blue.underline.bold('with a blue substring') +
|
||||||
|
' that becomes green again!'
|
||||||
|
));
|
||||||
|
|
||||||
|
// ES2015 template literal
|
||||||
|
log(`
|
||||||
|
CPU: ${chalk.red('90%')}
|
||||||
|
RAM: ${chalk.green('40%')}
|
||||||
|
DISK: ${chalk.yellow('70%')}
|
||||||
|
`);
|
||||||
|
|
||||||
|
// ES2015 tagged template literal
|
||||||
|
log(chalk`
|
||||||
|
CPU: {red ${cpu.totalPercent}%}
|
||||||
|
RAM: {green ${ram.used / ram.total * 100}%}
|
||||||
|
DISK: {rgb(255,131,0) ${disk.used / disk.total * 100}%}
|
||||||
|
`);
|
||||||
|
|
||||||
|
// Use RGB colors in terminal emulators that support it.
|
||||||
|
log(chalk.keyword('orange')('Yay for orange colored text!'));
|
||||||
|
log(chalk.rgb(123, 45, 67).underline('Underlined reddish color'));
|
||||||
|
log(chalk.hex('#DEADED').bold('Bold gray!'));
|
||||||
|
```
|
||||||
|
|
||||||
|
Easily define your own themes:
|
||||||
|
|
||||||
|
```js
|
||||||
|
const chalk = require('chalk');
|
||||||
|
|
||||||
|
const error = chalk.bold.red;
|
||||||
|
const warning = chalk.keyword('orange');
|
||||||
|
|
||||||
|
console.log(error('Error!'));
|
||||||
|
console.log(warning('Warning!'));
|
||||||
|
```
|
||||||
|
|
||||||
|
Take advantage of console.log [string substitution](https://nodejs.org/docs/latest/api/console.html#console_console_log_data_args):
|
||||||
|
|
||||||
|
```js
|
||||||
|
const name = 'Sindre';
|
||||||
|
console.log(chalk.green('Hello %s'), name);
|
||||||
|
//=> 'Hello Sindre'
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
|
### chalk.`<style>[.<style>...](string, [string...])`
|
||||||
|
|
||||||
|
Example: `chalk.red.bold.underline('Hello', 'world');`
|
||||||
|
|
||||||
|
Chain [styles](#styles) and call the last one as a method with a string argument. Order doesn't matter, and later styles take precedent in case of a conflict. This simply means that `chalk.red.yellow.green` is equivalent to `chalk.green`.
|
||||||
|
|
||||||
|
Multiple arguments will be separated by space.
|
||||||
|
|
||||||
|
### chalk.level
|
||||||
|
|
||||||
|
Specifies the level of color support.
|
||||||
|
|
||||||
|
Color support is automatically detected, but you can override it by setting the `level` property. You should however only do this in your own code as it applies globally to all Chalk consumers.
|
||||||
|
|
||||||
|
If you need to change this in a reusable module, create a new instance:
|
||||||
|
|
||||||
|
```js
|
||||||
|
const ctx = new chalk.Instance({level: 0});
|
||||||
|
```
|
||||||
|
|
||||||
|
| Level | Description |
|
||||||
|
| :---: | :--- |
|
||||||
|
| `0` | All colors disabled |
|
||||||
|
| `1` | Basic color support (16 colors) |
|
||||||
|
| `2` | 256 color support |
|
||||||
|
| `3` | Truecolor support (16 million colors) |
|
||||||
|
|
||||||
|
### chalk.supportsColor
|
||||||
|
|
||||||
|
Detect whether the terminal [supports color](https://github.com/chalk/supports-color). Used internally and handled for you, but exposed for convenience.
|
||||||
|
|
||||||
|
Can be overridden by the user with the flags `--color` and `--no-color`. For situations where using `--color` is not possible, use the environment variable `FORCE_COLOR=1` (level 1), `FORCE_COLOR=2` (level 2), or `FORCE_COLOR=3` (level 3) to forcefully enable color, or `FORCE_COLOR=0` to forcefully disable. The use of `FORCE_COLOR` overrides all other color support checks.
|
||||||
|
|
||||||
|
Explicit 256/Truecolor mode can be enabled using the `--color=256` and `--color=16m` flags, respectively.
|
||||||
|
|
||||||
|
### chalk.stderr and chalk.stderr.supportsColor
|
||||||
|
|
||||||
|
`chalk.stderr` contains a separate instance configured with color support detected for `stderr` stream instead of `stdout`. Override rules from `chalk.supportsColor` apply to this too. `chalk.stderr.supportsColor` is exposed for convenience.
|
||||||
|
|
||||||
|
|
||||||
|
## Styles
|
||||||
|
|
||||||
|
### Modifiers
|
||||||
|
|
||||||
|
- `reset` - Resets the current color chain.
|
||||||
|
- `bold` - Make text bold.
|
||||||
|
- `dim` - Emitting only a small amount of light.
|
||||||
|
- `italic` - Make text italic. *(Not widely supported)*
|
||||||
|
- `underline` - Make text underline. *(Not widely supported)*
|
||||||
|
- `inverse`- Inverse background and foreground colors.
|
||||||
|
- `hidden` - Prints the text, but makes it invisible.
|
||||||
|
- `strikethrough` - Puts a horizontal line through the center of the text. *(Not widely supported)*
|
||||||
|
- `visible`- Prints the text only when Chalk has a color level > 0. Can be useful for things that are purely cosmetic.
|
||||||
|
|
||||||
|
### Colors
|
||||||
|
|
||||||
|
- `black`
|
||||||
|
- `red`
|
||||||
|
- `green`
|
||||||
|
- `yellow`
|
||||||
|
- `blue`
|
||||||
|
- `magenta`
|
||||||
|
- `cyan`
|
||||||
|
- `white`
|
||||||
|
- `blackBright` (alias: `gray`, `grey`)
|
||||||
|
- `redBright`
|
||||||
|
- `greenBright`
|
||||||
|
- `yellowBright`
|
||||||
|
- `blueBright`
|
||||||
|
- `magentaBright`
|
||||||
|
- `cyanBright`
|
||||||
|
- `whiteBright`
|
||||||
|
|
||||||
|
### Background colors
|
||||||
|
|
||||||
|
- `bgBlack`
|
||||||
|
- `bgRed`
|
||||||
|
- `bgGreen`
|
||||||
|
- `bgYellow`
|
||||||
|
- `bgBlue`
|
||||||
|
- `bgMagenta`
|
||||||
|
- `bgCyan`
|
||||||
|
- `bgWhite`
|
||||||
|
- `bgBlackBright` (alias: `bgGray`, `bgGrey`)
|
||||||
|
- `bgRedBright`
|
||||||
|
- `bgGreenBright`
|
||||||
|
- `bgYellowBright`
|
||||||
|
- `bgBlueBright`
|
||||||
|
- `bgMagentaBright`
|
||||||
|
- `bgCyanBright`
|
||||||
|
- `bgWhiteBright`
|
||||||
|
|
||||||
|
|
||||||
|
## Tagged template literal
|
||||||
|
|
||||||
|
Chalk can be used as a [tagged template literal](http://exploringjs.com/es6/ch_template-literals.html#_tagged-template-literals).
|
||||||
|
|
||||||
|
```js
|
||||||
|
const chalk = require('chalk');
|
||||||
|
|
||||||
|
const miles = 18;
|
||||||
|
const calculateFeet = miles => miles * 5280;
|
||||||
|
|
||||||
|
console.log(chalk`
|
||||||
|
There are {bold 5280 feet} in a mile.
|
||||||
|
In {bold ${miles} miles}, there are {green.bold ${calculateFeet(miles)} feet}.
|
||||||
|
`);
|
||||||
|
```
|
||||||
|
|
||||||
|
Blocks are delimited by an opening curly brace (`{`), a style, some content, and a closing curly brace (`}`).
|
||||||
|
|
||||||
|
Template styles are chained exactly like normal Chalk styles. The following two statements are equivalent:
|
||||||
|
|
||||||
|
```js
|
||||||
|
console.log(chalk.bold.rgb(10, 100, 200)('Hello!'));
|
||||||
|
console.log(chalk`{bold.rgb(10,100,200) Hello!}`);
|
||||||
|
```
|
||||||
|
|
||||||
|
Note that function styles (`rgb()`, `hsl()`, `keyword()`, etc.) may not contain spaces between parameters.
|
||||||
|
|
||||||
|
All interpolated values (`` chalk`${foo}` ``) are converted to strings via the `.toString()` method. All curly braces (`{` and `}`) in interpolated value strings are escaped.
|
||||||
|
|
||||||
|
|
||||||
|
## 256 and Truecolor color support
|
||||||
|
|
||||||
|
Chalk supports 256 colors and [Truecolor](https://gist.github.com/XVilka/8346728) (16 million colors) on supported terminal apps.
|
||||||
|
|
||||||
|
Colors are downsampled from 16 million RGB values to an ANSI color format that is supported by the terminal emulator (or by specifying `{level: n}` as a Chalk option). For example, Chalk configured to run at level 1 (basic color support) will downsample an RGB value of #FF0000 (red) to 31 (ANSI escape for red).
|
||||||
|
|
||||||
|
Examples:
|
||||||
|
|
||||||
|
- `chalk.hex('#DEADED').underline('Hello, world!')`
|
||||||
|
- `chalk.keyword('orange')('Some orange text')`
|
||||||
|
- `chalk.rgb(15, 100, 204).inverse('Hello!')`
|
||||||
|
|
||||||
|
Background versions of these models are prefixed with `bg` and the first level of the module capitalized (e.g. `keyword` for foreground colors and `bgKeyword` for background colors).
|
||||||
|
|
||||||
|
- `chalk.bgHex('#DEADED').underline('Hello, world!')`
|
||||||
|
- `chalk.bgKeyword('orange')('Some orange text')`
|
||||||
|
- `chalk.bgRgb(15, 100, 204).inverse('Hello!')`
|
||||||
|
|
||||||
|
The following color models can be used:
|
||||||
|
|
||||||
|
- [`rgb`](https://en.wikipedia.org/wiki/RGB_color_model) - Example: `chalk.rgb(255, 136, 0).bold('Orange!')`
|
||||||
|
- [`hex`](https://en.wikipedia.org/wiki/Web_colors#Hex_triplet) - Example: `chalk.hex('#FF8800').bold('Orange!')`
|
||||||
|
- [`keyword`](https://www.w3.org/wiki/CSS/Properties/color/keywords) (CSS keywords) - Example: `chalk.keyword('orange').bold('Orange!')`
|
||||||
|
- [`hsl`](https://en.wikipedia.org/wiki/HSL_and_HSV) - Example: `chalk.hsl(32, 100, 50).bold('Orange!')`
|
||||||
|
- [`hsv`](https://en.wikipedia.org/wiki/HSL_and_HSV) - Example: `chalk.hsv(32, 100, 100).bold('Orange!')`
|
||||||
|
- [`hwb`](https://en.wikipedia.org/wiki/HWB_color_model) - Example: `chalk.hwb(32, 0, 50).bold('Orange!')`
|
||||||
|
- [`ansi`](https://en.wikipedia.org/wiki/ANSI_escape_code#3/4_bit) - Example: `chalk.ansi(31).bgAnsi(93)('red on yellowBright')`
|
||||||
|
- [`ansi256`](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit) - Example: `chalk.bgAnsi256(194)('Honeydew, more or less')`
|
||||||
|
|
||||||
|
|
||||||
|
## Windows
|
||||||
|
|
||||||
|
If you're on Windows, do yourself a favor and use [Windows Terminal](https://github.com/microsoft/terminal) instead of `cmd.exe`.
|
||||||
|
|
||||||
|
|
||||||
|
## Origin story
|
||||||
|
|
||||||
|
[colors.js](https://github.com/Marak/colors.js) used to be the most popular string styling module, but it has serious deficiencies like extending `String.prototype` which causes all kinds of [problems](https://github.com/yeoman/yo/issues/68) and the package is unmaintained. Although there are other packages, they either do too much or not enough. Chalk is a clean and focused alternative.
|
||||||
|
|
||||||
|
|
||||||
|
## chalk for enterprise
|
||||||
|
|
||||||
|
Available as part of the Tidelift Subscription.
|
||||||
|
|
||||||
|
The maintainers of chalk and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-chalk?utm_source=npm-chalk&utm_medium=referral&utm_campaign=enterprise&utm_term=repo)
|
||||||
|
|
||||||
|
|
||||||
|
## Related
|
||||||
|
|
||||||
|
- [chalk-cli](https://github.com/chalk/chalk-cli) - CLI for this module
|
||||||
|
- [ansi-styles](https://github.com/chalk/ansi-styles) - ANSI escape codes for styling strings in the terminal
|
||||||
|
- [supports-color](https://github.com/chalk/supports-color) - Detect whether a terminal supports color
|
||||||
|
- [strip-ansi](https://github.com/chalk/strip-ansi) - Strip ANSI escape codes
|
||||||
|
- [strip-ansi-stream](https://github.com/chalk/strip-ansi-stream) - Strip ANSI escape codes from a stream
|
||||||
|
- [has-ansi](https://github.com/chalk/has-ansi) - Check if a string has ANSI escape codes
|
||||||
|
- [ansi-regex](https://github.com/chalk/ansi-regex) - Regular expression for matching ANSI escape codes
|
||||||
|
- [wrap-ansi](https://github.com/chalk/wrap-ansi) - Wordwrap a string with ANSI escape codes
|
||||||
|
- [slice-ansi](https://github.com/chalk/slice-ansi) - Slice a string with ANSI escape codes
|
||||||
|
- [color-convert](https://github.com/qix-/color-convert) - Converts colors between different models
|
||||||
|
- [chalk-animation](https://github.com/bokub/chalk-animation) - Animate strings in the terminal
|
||||||
|
- [gradient-string](https://github.com/bokub/gradient-string) - Apply color gradients to strings
|
||||||
|
- [chalk-pipe](https://github.com/LitoMore/chalk-pipe) - Create chalk style schemes with simpler style strings
|
||||||
|
- [terminal-link](https://github.com/sindresorhus/terminal-link) - Create clickable links in the terminal
|
||||||
|
|
||||||
|
|
||||||
|
## Maintainers
|
||||||
|
|
||||||
|
- [Sindre Sorhus](https://github.com/sindresorhus)
|
||||||
|
- [Josh Junon](https://github.com/qix-)
|
|
@ -0,0 +1,233 @@
|
||||||
|
'use strict';
|
||||||
|
const ansiStyles = require('ansi-styles');
|
||||||
|
const {stdout: stdoutColor, stderr: stderrColor} = require('supports-color');
|
||||||
|
const {
|
||||||
|
stringReplaceAll,
|
||||||
|
stringEncaseCRLFWithFirstIndex
|
||||||
|
} = require('./util');
|
||||||
|
|
||||||
|
// `supportsColor.level` → `ansiStyles.color[name]` mapping
|
||||||
|
const levelMapping = [
|
||||||
|
'ansi',
|
||||||
|
'ansi',
|
||||||
|
'ansi256',
|
||||||
|
'ansi16m'
|
||||||
|
];
|
||||||
|
|
||||||
|
const styles = Object.create(null);
|
||||||
|
|
||||||
|
const applyOptions = (object, options = {}) => {
|
||||||
|
if (options.level > 3 || options.level < 0) {
|
||||||
|
throw new Error('The `level` option should be an integer from 0 to 3');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Detect level if not set manually
|
||||||
|
const colorLevel = stdoutColor ? stdoutColor.level : 0;
|
||||||
|
object.level = options.level === undefined ? colorLevel : options.level;
|
||||||
|
};
|
||||||
|
|
||||||
|
class ChalkClass {
|
||||||
|
constructor(options) {
|
||||||
|
return chalkFactory(options);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const chalkFactory = options => {
|
||||||
|
const chalk = {};
|
||||||
|
applyOptions(chalk, options);
|
||||||
|
|
||||||
|
chalk.template = (...arguments_) => chalkTag(chalk.template, ...arguments_);
|
||||||
|
|
||||||
|
Object.setPrototypeOf(chalk, Chalk.prototype);
|
||||||
|
Object.setPrototypeOf(chalk.template, chalk);
|
||||||
|
|
||||||
|
chalk.template.constructor = () => {
|
||||||
|
throw new Error('`chalk.constructor()` is deprecated. Use `new chalk.Instance()` instead.');
|
||||||
|
};
|
||||||
|
|
||||||
|
chalk.template.Instance = ChalkClass;
|
||||||
|
|
||||||
|
return chalk.template;
|
||||||
|
};
|
||||||
|
|
||||||
|
function Chalk(options) {
|
||||||
|
return chalkFactory(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const [styleName, style] of Object.entries(ansiStyles)) {
|
||||||
|
styles[styleName] = {
|
||||||
|
get() {
|
||||||
|
const builder = createBuilder(this, createStyler(style.open, style.close, this._styler), this._isEmpty);
|
||||||
|
Object.defineProperty(this, styleName, {value: builder});
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
styles.visible = {
|
||||||
|
get() {
|
||||||
|
const builder = createBuilder(this, this._styler, true);
|
||||||
|
Object.defineProperty(this, 'visible', {value: builder});
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const usedModels = ['rgb', 'hex', 'keyword', 'hsl', 'hsv', 'hwb', 'ansi', 'ansi256'];
|
||||||
|
|
||||||
|
for (const model of usedModels) {
|
||||||
|
styles[model] = {
|
||||||
|
get() {
|
||||||
|
const {level} = this;
|
||||||
|
return function (...arguments_) {
|
||||||
|
const styler = createStyler(ansiStyles.color[levelMapping[level]][model](...arguments_), ansiStyles.color.close, this._styler);
|
||||||
|
return createBuilder(this, styler, this._isEmpty);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const model of usedModels) {
|
||||||
|
const bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
|
||||||
|
styles[bgModel] = {
|
||||||
|
get() {
|
||||||
|
const {level} = this;
|
||||||
|
return function (...arguments_) {
|
||||||
|
const styler = createStyler(ansiStyles.bgColor[levelMapping[level]][model](...arguments_), ansiStyles.bgColor.close, this._styler);
|
||||||
|
return createBuilder(this, styler, this._isEmpty);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const proto = Object.defineProperties(() => {}, {
|
||||||
|
...styles,
|
||||||
|
level: {
|
||||||
|
enumerable: true,
|
||||||
|
get() {
|
||||||
|
return this._generator.level;
|
||||||
|
},
|
||||||
|
set(level) {
|
||||||
|
this._generator.level = level;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const createStyler = (open, close, parent) => {
|
||||||
|
let openAll;
|
||||||
|
let closeAll;
|
||||||
|
if (parent === undefined) {
|
||||||
|
openAll = open;
|
||||||
|
closeAll = close;
|
||||||
|
} else {
|
||||||
|
openAll = parent.openAll + open;
|
||||||
|
closeAll = close + parent.closeAll;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
open,
|
||||||
|
close,
|
||||||
|
openAll,
|
||||||
|
closeAll,
|
||||||
|
parent
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const createBuilder = (self, _styler, _isEmpty) => {
|
||||||
|
const builder = (...arguments_) => {
|
||||||
|
// Single argument is hot path, implicit coercion is faster than anything
|
||||||
|
// eslint-disable-next-line no-implicit-coercion
|
||||||
|
return applyStyle(builder, (arguments_.length === 1) ? ('' + arguments_[0]) : arguments_.join(' '));
|
||||||
|
};
|
||||||
|
|
||||||
|
// `__proto__` is used because we must return a function, but there is
|
||||||
|
// no way to create a function with a different prototype
|
||||||
|
builder.__proto__ = proto; // eslint-disable-line no-proto
|
||||||
|
|
||||||
|
builder._generator = self;
|
||||||
|
builder._styler = _styler;
|
||||||
|
builder._isEmpty = _isEmpty;
|
||||||
|
|
||||||
|
return builder;
|
||||||
|
};
|
||||||
|
|
||||||
|
const applyStyle = (self, string) => {
|
||||||
|
if (self.level <= 0 || !string) {
|
||||||
|
return self._isEmpty ? '' : string;
|
||||||
|
}
|
||||||
|
|
||||||
|
let styler = self._styler;
|
||||||
|
|
||||||
|
if (styler === undefined) {
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const {openAll, closeAll} = styler;
|
||||||
|
if (string.indexOf('\u001B') !== -1) {
|
||||||
|
while (styler !== undefined) {
|
||||||
|
// Replace any instances already present with a re-opening code
|
||||||
|
// otherwise only the part of the string until said closing code
|
||||||
|
// will be colored, and the rest will simply be 'plain'.
|
||||||
|
string = stringReplaceAll(string, styler.close, styler.open);
|
||||||
|
|
||||||
|
styler = styler.parent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// We can move both next actions out of loop, because remaining actions in loop won't have
|
||||||
|
// any/visible effect on parts we add here. Close the styling before a linebreak and reopen
|
||||||
|
// after next line to fix a bleed issue on macOS: https://github.com/chalk/chalk/pull/92
|
||||||
|
const lfIndex = string.indexOf('\n');
|
||||||
|
if (lfIndex !== -1) {
|
||||||
|
string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return openAll + string + closeAll;
|
||||||
|
};
|
||||||
|
|
||||||
|
let template;
|
||||||
|
const chalkTag = (chalk, ...strings) => {
|
||||||
|
const [firstString] = strings;
|
||||||
|
|
||||||
|
if (!Array.isArray(firstString)) {
|
||||||
|
// If chalk() was called by itself or with a string,
|
||||||
|
// return the string itself as a string.
|
||||||
|
return strings.join(' ');
|
||||||
|
}
|
||||||
|
|
||||||
|
const arguments_ = strings.slice(1);
|
||||||
|
const parts = [firstString.raw[0]];
|
||||||
|
|
||||||
|
for (let i = 1; i < firstString.length; i++) {
|
||||||
|
parts.push(
|
||||||
|
String(arguments_[i - 1]).replace(/[{}\\]/g, '\\$&'),
|
||||||
|
String(firstString.raw[i])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (template === undefined) {
|
||||||
|
template = require('./templates');
|
||||||
|
}
|
||||||
|
|
||||||
|
return template(chalk, parts.join(''));
|
||||||
|
};
|
||||||
|
|
||||||
|
Object.defineProperties(Chalk.prototype, styles);
|
||||||
|
|
||||||
|
const chalk = Chalk(); // eslint-disable-line new-cap
|
||||||
|
chalk.supportsColor = stdoutColor;
|
||||||
|
chalk.stderr = Chalk({level: stderrColor ? stderrColor.level : 0}); // eslint-disable-line new-cap
|
||||||
|
chalk.stderr.supportsColor = stderrColor;
|
||||||
|
|
||||||
|
// For TypeScript
|
||||||
|
chalk.Level = {
|
||||||
|
None: 0,
|
||||||
|
Basic: 1,
|
||||||
|
Ansi256: 2,
|
||||||
|
TrueColor: 3,
|
||||||
|
0: 'None',
|
||||||
|
1: 'Basic',
|
||||||
|
2: 'Ansi256',
|
||||||
|
3: 'TrueColor'
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = chalk;
|
|
@ -0,0 +1,134 @@
|
||||||
|
'use strict';
|
||||||
|
const TEMPLATE_REGEX = /(?:\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
|
||||||
|
const STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
|
||||||
|
const STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
|
||||||
|
const ESCAPE_REGEX = /\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.)|([^\\])/gi;
|
||||||
|
|
||||||
|
const ESCAPES = new Map([
|
||||||
|
['n', '\n'],
|
||||||
|
['r', '\r'],
|
||||||
|
['t', '\t'],
|
||||||
|
['b', '\b'],
|
||||||
|
['f', '\f'],
|
||||||
|
['v', '\v'],
|
||||||
|
['0', '\0'],
|
||||||
|
['\\', '\\'],
|
||||||
|
['e', '\u001B'],
|
||||||
|
['a', '\u0007']
|
||||||
|
]);
|
||||||
|
|
||||||
|
function unescape(c) {
|
||||||
|
const u = c[0] === 'u';
|
||||||
|
const bracket = c[1] === '{';
|
||||||
|
|
||||||
|
if ((u && !bracket && c.length === 5) || (c[0] === 'x' && c.length === 3)) {
|
||||||
|
return String.fromCharCode(parseInt(c.slice(1), 16));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (u && bracket) {
|
||||||
|
return String.fromCodePoint(parseInt(c.slice(2, -1), 16));
|
||||||
|
}
|
||||||
|
|
||||||
|
return ESCAPES.get(c) || c;
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseArguments(name, arguments_) {
|
||||||
|
const results = [];
|
||||||
|
const chunks = arguments_.trim().split(/\s*,\s*/g);
|
||||||
|
let matches;
|
||||||
|
|
||||||
|
for (const chunk of chunks) {
|
||||||
|
const number = Number(chunk);
|
||||||
|
if (!Number.isNaN(number)) {
|
||||||
|
results.push(number);
|
||||||
|
} else if ((matches = chunk.match(STRING_REGEX))) {
|
||||||
|
results.push(matches[2].replace(ESCAPE_REGEX, (m, escape, character) => escape ? unescape(escape) : character));
|
||||||
|
} else {
|
||||||
|
throw new Error(`Invalid Chalk template style argument: ${chunk} (in style '${name}')`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseStyle(style) {
|
||||||
|
STYLE_REGEX.lastIndex = 0;
|
||||||
|
|
||||||
|
const results = [];
|
||||||
|
let matches;
|
||||||
|
|
||||||
|
while ((matches = STYLE_REGEX.exec(style)) !== null) {
|
||||||
|
const name = matches[1];
|
||||||
|
|
||||||
|
if (matches[2]) {
|
||||||
|
const args = parseArguments(name, matches[2]);
|
||||||
|
results.push([name].concat(args));
|
||||||
|
} else {
|
||||||
|
results.push([name]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildStyle(chalk, styles) {
|
||||||
|
const enabled = {};
|
||||||
|
|
||||||
|
for (const layer of styles) {
|
||||||
|
for (const style of layer.styles) {
|
||||||
|
enabled[style[0]] = layer.inverse ? null : style.slice(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let current = chalk;
|
||||||
|
for (const [styleName, styles] of Object.entries(enabled)) {
|
||||||
|
if (!Array.isArray(styles)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(styleName in current)) {
|
||||||
|
throw new Error(`Unknown Chalk style: ${styleName}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
current = styles.length > 0 ? current[styleName](...styles) : current[styleName];
|
||||||
|
}
|
||||||
|
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = (chalk, temporary) => {
|
||||||
|
const styles = [];
|
||||||
|
const chunks = [];
|
||||||
|
let chunk = [];
|
||||||
|
|
||||||
|
// eslint-disable-next-line max-params
|
||||||
|
temporary.replace(TEMPLATE_REGEX, (m, escapeCharacter, inverse, style, close, character) => {
|
||||||
|
if (escapeCharacter) {
|
||||||
|
chunk.push(unescape(escapeCharacter));
|
||||||
|
} else if (style) {
|
||||||
|
const string = chunk.join('');
|
||||||
|
chunk = [];
|
||||||
|
chunks.push(styles.length === 0 ? string : buildStyle(chalk, styles)(string));
|
||||||
|
styles.push({inverse, styles: parseStyle(style)});
|
||||||
|
} else if (close) {
|
||||||
|
if (styles.length === 0) {
|
||||||
|
throw new Error('Found extraneous } in Chalk template literal');
|
||||||
|
}
|
||||||
|
|
||||||
|
chunks.push(buildStyle(chalk, styles)(chunk.join('')));
|
||||||
|
chunk = [];
|
||||||
|
styles.pop();
|
||||||
|
} else {
|
||||||
|
chunk.push(character);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
chunks.push(chunk.join(''));
|
||||||
|
|
||||||
|
if (styles.length > 0) {
|
||||||
|
const errMsg = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`;
|
||||||
|
throw new Error(errMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
return chunks.join('');
|
||||||
|
};
|
|
@ -0,0 +1,39 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const stringReplaceAll = (string, substring, replacer) => {
|
||||||
|
let index = string.indexOf(substring);
|
||||||
|
if (index === -1) {
|
||||||
|
return string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const substringLength = substring.length;
|
||||||
|
let endIndex = 0;
|
||||||
|
let returnValue = '';
|
||||||
|
do {
|
||||||
|
returnValue += string.substr(endIndex, index - endIndex) + substring + replacer;
|
||||||
|
endIndex = index + substringLength;
|
||||||
|
index = string.indexOf(substring, endIndex);
|
||||||
|
} while (index !== -1);
|
||||||
|
|
||||||
|
returnValue += string.substr(endIndex);
|
||||||
|
return returnValue;
|
||||||
|
};
|
||||||
|
|
||||||
|
const stringEncaseCRLFWithFirstIndex = (string, prefix, postfix, index) => {
|
||||||
|
let endIndex = 0;
|
||||||
|
let returnValue = '';
|
||||||
|
do {
|
||||||
|
const gotCR = string[index - 1] === '\r';
|
||||||
|
returnValue += string.substr(endIndex, (gotCR ? index - 1 : index) - endIndex) + prefix + (gotCR ? '\r\n' : '\n') + postfix;
|
||||||
|
endIndex = index + 1;
|
||||||
|
index = string.indexOf('\n', endIndex);
|
||||||
|
} while (index !== -1);
|
||||||
|
|
||||||
|
returnValue += string.substr(endIndex);
|
||||||
|
return returnValue;
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
stringReplaceAll,
|
||||||
|
stringEncaseCRLFWithFirstIndex
|
||||||
|
};
|
|
@ -0,0 +1,5 @@
|
||||||
|
language: node_js
|
||||||
|
node_js:
|
||||||
|
- "6"
|
||||||
|
- "8"
|
||||||
|
- "10"
|
|
@ -0,0 +1,19 @@
|
||||||
|
Copyright (C) 2018 Dmitry Shirokov
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
|
@ -0,0 +1,81 @@
|
||||||
|
|
||||||
|
chardet [](https://travis-ci.org/runk/node-chardet)
|
||||||
|
=====
|
||||||
|
|
||||||
|
Chardet is a character detection module for NodeJS written in pure Javascript.
|
||||||
|
Module is based on ICU project http://site.icu-project.org/, which uses character
|
||||||
|
occurency analysis to determine the most probable encoding.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
```
|
||||||
|
npm i chardet
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
To return the encoding with the highest confidence:
|
||||||
|
```javascript
|
||||||
|
var chardet = require('chardet');
|
||||||
|
chardet.detect(Buffer.alloc('hello there!'));
|
||||||
|
// or
|
||||||
|
chardet.detectFile('/path/to/file', function(err, encoding) {});
|
||||||
|
// or
|
||||||
|
chardet.detectFileSync('/path/to/file');
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
To return the full list of possible encodings:
|
||||||
|
```javascript
|
||||||
|
var chardet = require('chardet');
|
||||||
|
chardet.detectAll(Buffer.alloc('hello there!'));
|
||||||
|
// or
|
||||||
|
chardet.detectFileAll('/path/to/file', function(err, encoding) {});
|
||||||
|
// or
|
||||||
|
chardet.detectFileAllSync('/path/to/file');
|
||||||
|
|
||||||
|
//Returned value is an array of objects sorted by confidence value in decending order
|
||||||
|
//e.g. [{ confidence: 90, name: 'UTF-8'}, {confidence: 20, name: 'windows-1252', lang: 'fr'}]
|
||||||
|
```
|
||||||
|
|
||||||
|
## Working with large data sets
|
||||||
|
|
||||||
|
Sometimes, when data set is huge and you want to optimize performace (in tradeoff of less accuracy),
|
||||||
|
you can sample only first N bytes of the buffer:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
chardet.detectFile('/path/to/file', { sampleSize: 32 }, function(err, encoding) {});
|
||||||
|
```
|
||||||
|
|
||||||
|
## Supported Encodings:
|
||||||
|
|
||||||
|
* UTF-8
|
||||||
|
* UTF-16 LE
|
||||||
|
* UTF-16 BE
|
||||||
|
* UTF-32 LE
|
||||||
|
* UTF-32 BE
|
||||||
|
* ISO-2022-JP
|
||||||
|
* ISO-2022-KR
|
||||||
|
* ISO-2022-CN
|
||||||
|
* Shift-JIS
|
||||||
|
* Big5
|
||||||
|
* EUC-JP
|
||||||
|
* EUC-KR
|
||||||
|
* GB18030
|
||||||
|
* ISO-8859-1
|
||||||
|
* ISO-8859-2
|
||||||
|
* ISO-8859-5
|
||||||
|
* ISO-8859-6
|
||||||
|
* ISO-8859-7
|
||||||
|
* ISO-8859-8
|
||||||
|
* ISO-8859-9
|
||||||
|
* windows-1250
|
||||||
|
* windows-1251
|
||||||
|
* windows-1252
|
||||||
|
* windows-1253
|
||||||
|
* windows-1254
|
||||||
|
* windows-1255
|
||||||
|
* windows-1256
|
||||||
|
* KOI8-R
|
||||||
|
|
||||||
|
Currently only these encodings are supported, more will be added soon.
|
|
@ -0,0 +1,141 @@
|
||||||
|
var util = require('util'),
|
||||||
|
Match = require ('../match');
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a superclass for the individual detectors for
|
||||||
|
* each of the detectable members of the ISO 2022 family
|
||||||
|
* of encodings.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function ISO_2022() {}
|
||||||
|
|
||||||
|
ISO_2022.prototype.match = function(det) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Matching function shared among the 2022 detectors JP, CN and KR
|
||||||
|
* Counts up the number of legal an unrecognized escape sequences in
|
||||||
|
* the sample of text, and computes a score based on the total number &
|
||||||
|
* the proportion that fit the encoding.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param text the byte buffer containing text to analyse
|
||||||
|
* @param textLen the size of the text in the byte.
|
||||||
|
* @param escapeSequences the byte escape sequences to test for.
|
||||||
|
* @return match quality, in the range of 0-100.
|
||||||
|
*/
|
||||||
|
|
||||||
|
var i, j;
|
||||||
|
var escN;
|
||||||
|
var hits = 0;
|
||||||
|
var misses = 0;
|
||||||
|
var shifts = 0;
|
||||||
|
var quality;
|
||||||
|
|
||||||
|
// TODO: refactor me
|
||||||
|
var text = det.fInputBytes;
|
||||||
|
var textLen = det.fInputLen;
|
||||||
|
|
||||||
|
scanInput:
|
||||||
|
for (i = 0; i < textLen; i++) {
|
||||||
|
if (text[i] == 0x1b) {
|
||||||
|
checkEscapes:
|
||||||
|
for (escN = 0; escN < this.escapeSequences.length; escN++) {
|
||||||
|
var seq = this.escapeSequences[escN];
|
||||||
|
|
||||||
|
if ((textLen - i) < seq.length)
|
||||||
|
continue checkEscapes;
|
||||||
|
|
||||||
|
for (j = 1; j < seq.length; j++)
|
||||||
|
if (seq[j] != text[i + j])
|
||||||
|
continue checkEscapes;
|
||||||
|
|
||||||
|
|
||||||
|
hits++;
|
||||||
|
i += seq.length - 1;
|
||||||
|
continue scanInput;
|
||||||
|
}
|
||||||
|
|
||||||
|
misses++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Shift in/out
|
||||||
|
if (text[i] == 0x0e || text[i] == 0x0f)
|
||||||
|
shifts++;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hits == 0)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
//
|
||||||
|
// Initial quality is based on relative proportion of recongized vs.
|
||||||
|
// unrecognized escape sequences.
|
||||||
|
// All good: quality = 100;
|
||||||
|
// half or less good: quality = 0;
|
||||||
|
// linear inbetween.
|
||||||
|
quality = (100 * hits - 100 * misses) / (hits + misses);
|
||||||
|
|
||||||
|
// Back off quality if there were too few escape sequences seen.
|
||||||
|
// Include shifts in this computation, so that KR does not get penalized
|
||||||
|
// for having only a single Escape sequence, but many shifts.
|
||||||
|
if (hits + shifts < 5)
|
||||||
|
quality -= (5 - (hits + shifts)) * 10;
|
||||||
|
|
||||||
|
return quality <= 0 ? null : new Match(det, this, quality);
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.ISO_2022_JP = function() {
|
||||||
|
this.name = function() {
|
||||||
|
return 'ISO-2022-JP';
|
||||||
|
};
|
||||||
|
this.escapeSequences = [
|
||||||
|
[ 0x1b, 0x24, 0x28, 0x43 ], // KS X 1001:1992
|
||||||
|
[ 0x1b, 0x24, 0x28, 0x44 ], // JIS X 212-1990
|
||||||
|
[ 0x1b, 0x24, 0x40 ], // JIS C 6226-1978
|
||||||
|
[ 0x1b, 0x24, 0x41 ], // GB 2312-80
|
||||||
|
[ 0x1b, 0x24, 0x42 ], // JIS X 208-1983
|
||||||
|
[ 0x1b, 0x26, 0x40 ], // JIS X 208 1990, 1997
|
||||||
|
[ 0x1b, 0x28, 0x42 ], // ASCII
|
||||||
|
[ 0x1b, 0x28, 0x48 ], // JIS-Roman
|
||||||
|
[ 0x1b, 0x28, 0x49 ], // Half-width katakana
|
||||||
|
[ 0x1b, 0x28, 0x4a ], // JIS-Roman
|
||||||
|
[ 0x1b, 0x2e, 0x41 ], // ISO 8859-1
|
||||||
|
[ 0x1b, 0x2e, 0x46 ] // ISO 8859-7
|
||||||
|
];
|
||||||
|
};
|
||||||
|
util.inherits(module.exports.ISO_2022_JP, ISO_2022);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
module.exports.ISO_2022_KR = function() {
|
||||||
|
this.name = function() {
|
||||||
|
return 'ISO-2022-KR';
|
||||||
|
};
|
||||||
|
this.escapeSequences = [
|
||||||
|
[ 0x1b, 0x24, 0x29, 0x43 ]
|
||||||
|
];
|
||||||
|
};
|
||||||
|
util.inherits(module.exports.ISO_2022_KR, ISO_2022);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
module.exports.ISO_2022_CN = function() {
|
||||||
|
this.name = function() {
|
||||||
|
return 'ISO-2022-CN';
|
||||||
|
};
|
||||||
|
this.escapeSequences = [
|
||||||
|
[ 0x1b, 0x24, 0x29, 0x41 ], // GB 2312-80
|
||||||
|
[ 0x1b, 0x24, 0x29, 0x47 ], // CNS 11643-1992 Plane 1
|
||||||
|
[ 0x1b, 0x24, 0x2A, 0x48 ], // CNS 11643-1992 Plane 2
|
||||||
|
[ 0x1b, 0x24, 0x29, 0x45 ], // ISO-IR-165
|
||||||
|
[ 0x1b, 0x24, 0x2B, 0x49 ], // CNS 11643-1992 Plane 3
|
||||||
|
[ 0x1b, 0x24, 0x2B, 0x4A ], // CNS 11643-1992 Plane 4
|
||||||
|
[ 0x1b, 0x24, 0x2B, 0x4B ], // CNS 11643-1992 Plane 5
|
||||||
|
[ 0x1b, 0x24, 0x2B, 0x4C ], // CNS 11643-1992 Plane 6
|
||||||
|
[ 0x1b, 0x24, 0x2B, 0x4D ], // CNS 11643-1992 Plane 7
|
||||||
|
[ 0x1b, 0x4e ], // SS2
|
||||||
|
[ 0x1b, 0x4f ] // SS3
|
||||||
|
];
|
||||||
|
};
|
||||||
|
util.inherits(module.exports.ISO_2022_CN, ISO_2022);
|
|
@ -0,0 +1,502 @@
|
||||||
|
var util = require('util'),
|
||||||
|
Match = require ('../match');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Binary search implementation (recursive)
|
||||||
|
*/
|
||||||
|
function binarySearch(arr, searchValue) {
|
||||||
|
function find(arr, searchValue, left, right) {
|
||||||
|
if (right < left)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
/*
|
||||||
|
int mid = mid = (left + right) / 2;
|
||||||
|
There is a bug in the above line;
|
||||||
|
Joshua Bloch suggests the following replacement:
|
||||||
|
*/
|
||||||
|
var mid = Math.floor((left + right) >>> 1);
|
||||||
|
if (searchValue > arr[mid])
|
||||||
|
return find(arr, searchValue, mid + 1, right);
|
||||||
|
|
||||||
|
if (searchValue < arr[mid])
|
||||||
|
return find(arr, searchValue, left, mid - 1);
|
||||||
|
|
||||||
|
return mid;
|
||||||
|
};
|
||||||
|
|
||||||
|
return find(arr, searchValue, 0, arr.length - 1);
|
||||||
|
};
|
||||||
|
|
||||||
|
// 'Character' iterated character class.
|
||||||
|
// Recognizers for specific mbcs encodings make their 'characters' available
|
||||||
|
// by providing a nextChar() function that fills in an instance of iteratedChar
|
||||||
|
// with the next char from the input.
|
||||||
|
// The returned characters are not converted to Unicode, but remain as the raw
|
||||||
|
// bytes (concatenated into an int) from the codepage data.
|
||||||
|
//
|
||||||
|
// For Asian charsets, use the raw input rather than the input that has been
|
||||||
|
// stripped of markup. Detection only considers multi-byte chars, effectively
|
||||||
|
// stripping markup anyway, and double byte chars do occur in markup too.
|
||||||
|
//
|
||||||
|
function IteratedChar() {
|
||||||
|
|
||||||
|
this.charValue = 0; // 1-4 bytes from the raw input data
|
||||||
|
this.index = 0;
|
||||||
|
this.nextIndex = 0;
|
||||||
|
this.error = false;
|
||||||
|
this.done = false;
|
||||||
|
|
||||||
|
this.reset = function() {
|
||||||
|
this.charValue = 0;
|
||||||
|
this.index = -1;
|
||||||
|
this.nextIndex = 0;
|
||||||
|
this.error = false;
|
||||||
|
this.done = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.nextByte = function(det) {
|
||||||
|
if (this.nextIndex >= det.fRawLength) {
|
||||||
|
this.done = true;
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
var byteValue = det.fRawInput[this.nextIndex++] & 0x00ff;
|
||||||
|
return byteValue;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asian double or multi-byte - charsets.
|
||||||
|
* Match is determined mostly by the input data adhering to the
|
||||||
|
* encoding scheme for the charset, and, optionally,
|
||||||
|
* frequency-of-occurence of characters.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function mbcs() {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the match of this charset with the input text data
|
||||||
|
* which is obtained via the CharsetDetector object.
|
||||||
|
*
|
||||||
|
* @param det The CharsetDetector, which contains the input text
|
||||||
|
* to be checked for being in this charset.
|
||||||
|
* @return Two values packed into one int (Damn java, anyhow)
|
||||||
|
* bits 0-7: the match confidence, ranging from 0-100
|
||||||
|
* bits 8-15: The match reason, an enum-like value.
|
||||||
|
*/
|
||||||
|
mbcs.prototype.match = function(det) {
|
||||||
|
|
||||||
|
var singleByteCharCount = 0, //TODO Do we really need this?
|
||||||
|
doubleByteCharCount = 0,
|
||||||
|
commonCharCount = 0,
|
||||||
|
badCharCount = 0,
|
||||||
|
totalCharCount = 0,
|
||||||
|
confidence = 0;
|
||||||
|
|
||||||
|
var iter = new IteratedChar();
|
||||||
|
|
||||||
|
detectBlock: {
|
||||||
|
for (iter.reset(); this.nextChar(iter, det);) {
|
||||||
|
totalCharCount++;
|
||||||
|
if (iter.error) {
|
||||||
|
badCharCount++;
|
||||||
|
} else {
|
||||||
|
var cv = iter.charValue & 0xFFFFFFFF;
|
||||||
|
|
||||||
|
if (cv <= 0xff) {
|
||||||
|
singleByteCharCount++;
|
||||||
|
} else {
|
||||||
|
doubleByteCharCount++;
|
||||||
|
if (this.commonChars != null) {
|
||||||
|
// NOTE: This assumes that there are no 4-byte common chars.
|
||||||
|
if (binarySearch(this.commonChars, cv) >= 0) {
|
||||||
|
commonCharCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (badCharCount >= 2 && badCharCount * 5 >= doubleByteCharCount) {
|
||||||
|
// console.log('its here!')
|
||||||
|
// Bail out early if the byte data is not matching the encoding scheme.
|
||||||
|
break detectBlock;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (doubleByteCharCount <= 10 && badCharCount== 0) {
|
||||||
|
// Not many multi-byte chars.
|
||||||
|
if (doubleByteCharCount == 0 && totalCharCount < 10) {
|
||||||
|
// There weren't any multibyte sequences, and there was a low density of non-ASCII single bytes.
|
||||||
|
// We don't have enough data to have any confidence.
|
||||||
|
// Statistical analysis of single byte non-ASCII charcters would probably help here.
|
||||||
|
confidence = 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// ASCII or ISO file? It's probably not our encoding,
|
||||||
|
// but is not incompatible with our encoding, so don't give it a zero.
|
||||||
|
confidence = 10;
|
||||||
|
}
|
||||||
|
break detectBlock;
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// No match if there are too many characters that don't fit the encoding scheme.
|
||||||
|
// (should we have zero tolerance for these?)
|
||||||
|
//
|
||||||
|
if (doubleByteCharCount < 20 * badCharCount) {
|
||||||
|
confidence = 0;
|
||||||
|
break detectBlock;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.commonChars == null) {
|
||||||
|
// We have no statistics on frequently occuring characters.
|
||||||
|
// Assess confidence purely on having a reasonable number of
|
||||||
|
// multi-byte characters (the more the better
|
||||||
|
confidence = 30 + doubleByteCharCount - 20 * badCharCount;
|
||||||
|
if (confidence > 100) {
|
||||||
|
confidence = 100;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
//
|
||||||
|
// Frequency of occurence statistics exist.
|
||||||
|
//
|
||||||
|
var maxVal = Math.log(parseFloat(doubleByteCharCount) / 4);
|
||||||
|
var scaleFactor = 90.0 / maxVal;
|
||||||
|
confidence = Math.floor(Math.log(commonCharCount + 1) * scaleFactor + 10);
|
||||||
|
confidence = Math.min(confidence, 100);
|
||||||
|
}
|
||||||
|
} // end of detectBlock:
|
||||||
|
|
||||||
|
return confidence == 0 ? null : new Match(det, this, confidence);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the next character (however many bytes it is) from the input data
|
||||||
|
* Subclasses for specific charset encodings must implement this function
|
||||||
|
* to get characters according to the rules of their encoding scheme.
|
||||||
|
*
|
||||||
|
* This function is not a method of class iteratedChar only because
|
||||||
|
* that would require a lot of extra derived classes, which is awkward.
|
||||||
|
* @param it The iteratedChar 'struct' into which the returned char is placed.
|
||||||
|
* @param det The charset detector, which is needed to get at the input byte data
|
||||||
|
* being iterated over.
|
||||||
|
* @return True if a character was returned, false at end of input.
|
||||||
|
*/
|
||||||
|
|
||||||
|
mbcs.prototype.nextChar = function(iter, det) {};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shift-JIS charset recognizer.
|
||||||
|
*/
|
||||||
|
module.exports.sjis = function() {
|
||||||
|
this.name = function() {
|
||||||
|
return 'Shift-JIS';
|
||||||
|
};
|
||||||
|
this.language = function() {
|
||||||
|
return 'ja';
|
||||||
|
};
|
||||||
|
|
||||||
|
// TODO: This set of data comes from the character frequency-
|
||||||
|
// of-occurence analysis tool. The data needs to be moved
|
||||||
|
// into a resource and loaded from there.
|
||||||
|
this.commonChars = [
|
||||||
|
0x8140, 0x8141, 0x8142, 0x8145, 0x815b, 0x8169, 0x816a, 0x8175, 0x8176, 0x82a0,
|
||||||
|
0x82a2, 0x82a4, 0x82a9, 0x82aa, 0x82ab, 0x82ad, 0x82af, 0x82b1, 0x82b3, 0x82b5,
|
||||||
|
0x82b7, 0x82bd, 0x82be, 0x82c1, 0x82c4, 0x82c5, 0x82c6, 0x82c8, 0x82c9, 0x82cc,
|
||||||
|
0x82cd, 0x82dc, 0x82e0, 0x82e7, 0x82e8, 0x82e9, 0x82ea, 0x82f0, 0x82f1, 0x8341,
|
||||||
|
0x8343, 0x834e, 0x834f, 0x8358, 0x835e, 0x8362, 0x8367, 0x8375, 0x8376, 0x8389,
|
||||||
|
0x838a, 0x838b, 0x838d, 0x8393, 0x8e96, 0x93fa, 0x95aa
|
||||||
|
];
|
||||||
|
|
||||||
|
this.nextChar = function(iter, det) {
|
||||||
|
iter.index = iter.nextIndex;
|
||||||
|
iter.error = false;
|
||||||
|
|
||||||
|
var firstByte;
|
||||||
|
firstByte = iter.charValue = iter.nextByte(det);
|
||||||
|
if (firstByte < 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (firstByte <= 0x7f || (firstByte > 0xa0 && firstByte <= 0xdf))
|
||||||
|
return true;
|
||||||
|
|
||||||
|
var secondByte = iter.nextByte(det);
|
||||||
|
if (secondByte < 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
iter.charValue = (firstByte << 8) | secondByte;
|
||||||
|
if (! ((secondByte >= 0x40 && secondByte <= 0x7f) || (secondByte >= 0x80 && secondByte <= 0xff))) {
|
||||||
|
// Illegal second byte value.
|
||||||
|
iter.error = true;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
util.inherits(module.exports.sjis, mbcs);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Big5 charset recognizer.
|
||||||
|
*/
|
||||||
|
module.exports.big5 = function() {
|
||||||
|
this.name = function() {
|
||||||
|
return 'Big5';
|
||||||
|
};
|
||||||
|
this.language = function() {
|
||||||
|
return 'zh';
|
||||||
|
};
|
||||||
|
// TODO: This set of data comes from the character frequency-
|
||||||
|
// of-occurence analysis tool. The data needs to be moved
|
||||||
|
// into a resource and loaded from there.
|
||||||
|
this.commonChars = [
|
||||||
|
0xa140, 0xa141, 0xa142, 0xa143, 0xa147, 0xa149, 0xa175, 0xa176, 0xa440, 0xa446,
|
||||||
|
0xa447, 0xa448, 0xa451, 0xa454, 0xa457, 0xa464, 0xa46a, 0xa46c, 0xa477, 0xa4a3,
|
||||||
|
0xa4a4, 0xa4a7, 0xa4c1, 0xa4ce, 0xa4d1, 0xa4df, 0xa4e8, 0xa4fd, 0xa540, 0xa548,
|
||||||
|
0xa558, 0xa569, 0xa5cd, 0xa5e7, 0xa657, 0xa661, 0xa662, 0xa668, 0xa670, 0xa6a8,
|
||||||
|
0xa6b3, 0xa6b9, 0xa6d3, 0xa6db, 0xa6e6, 0xa6f2, 0xa740, 0xa751, 0xa759, 0xa7da,
|
||||||
|
0xa8a3, 0xa8a5, 0xa8ad, 0xa8d1, 0xa8d3, 0xa8e4, 0xa8fc, 0xa9c0, 0xa9d2, 0xa9f3,
|
||||||
|
0xaa6b, 0xaaba, 0xaabe, 0xaacc, 0xaafc, 0xac47, 0xac4f, 0xacb0, 0xacd2, 0xad59,
|
||||||
|
0xaec9, 0xafe0, 0xb0ea, 0xb16f, 0xb2b3, 0xb2c4, 0xb36f, 0xb44c, 0xb44e, 0xb54c,
|
||||||
|
0xb5a5, 0xb5bd, 0xb5d0, 0xb5d8, 0xb671, 0xb7ed, 0xb867, 0xb944, 0xbad8, 0xbb44,
|
||||||
|
0xbba1, 0xbdd1, 0xc2c4, 0xc3b9, 0xc440, 0xc45f
|
||||||
|
];
|
||||||
|
this.nextChar = function(iter, det) {
|
||||||
|
iter.index = iter.nextIndex;
|
||||||
|
iter.error = false;
|
||||||
|
|
||||||
|
var firstByte = iter.charValue = iter.nextByte(det);
|
||||||
|
|
||||||
|
if (firstByte < 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
// single byte character.
|
||||||
|
if (firstByte <= 0x7f || firstByte == 0xff)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
var secondByte = iter.nextByte(det);
|
||||||
|
|
||||||
|
if (secondByte < 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
iter.charValue = (iter.charValue << 8) | secondByte;
|
||||||
|
|
||||||
|
if (secondByte < 0x40 || secondByte == 0x7f || secondByte == 0xff)
|
||||||
|
iter.error = true;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
util.inherits(module.exports.big5, mbcs);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* EUC charset recognizers. One abstract class that provides the common function
|
||||||
|
* for getting the next character according to the EUC encoding scheme,
|
||||||
|
* and nested derived classes for EUC_KR, EUC_JP, EUC_CN.
|
||||||
|
*
|
||||||
|
* Get the next character value for EUC based encodings.
|
||||||
|
* Character 'value' is simply the raw bytes that make up the character
|
||||||
|
* packed into an int.
|
||||||
|
*/
|
||||||
|
function eucNextChar(iter, det) {
|
||||||
|
iter.index = iter.nextIndex;
|
||||||
|
iter.error = false;
|
||||||
|
var firstByte = 0;
|
||||||
|
var secondByte = 0;
|
||||||
|
var thirdByte = 0;
|
||||||
|
//int fourthByte = 0;
|
||||||
|
buildChar: {
|
||||||
|
firstByte = iter.charValue = iter.nextByte(det);
|
||||||
|
if (firstByte < 0) {
|
||||||
|
// Ran off the end of the input data
|
||||||
|
iter.done = true;
|
||||||
|
break buildChar;
|
||||||
|
}
|
||||||
|
if (firstByte <= 0x8d) {
|
||||||
|
// single byte char
|
||||||
|
break buildChar;
|
||||||
|
}
|
||||||
|
secondByte = iter.nextByte(det);
|
||||||
|
iter.charValue = (iter.charValue << 8) | secondByte;
|
||||||
|
if (firstByte >= 0xA1 && firstByte <= 0xfe) {
|
||||||
|
// Two byte Char
|
||||||
|
if (secondByte < 0xa1) {
|
||||||
|
iter.error = true;
|
||||||
|
}
|
||||||
|
break buildChar;
|
||||||
|
}
|
||||||
|
if (firstByte == 0x8e) {
|
||||||
|
// Code Set 2.
|
||||||
|
// In EUC-JP, total char size is 2 bytes, only one byte of actual char value.
|
||||||
|
// In EUC-TW, total char size is 4 bytes, three bytes contribute to char value.
|
||||||
|
// We don't know which we've got.
|
||||||
|
// Treat it like EUC-JP. If the data really was EUC-TW, the following two
|
||||||
|
// bytes will look like a well formed 2 byte char.
|
||||||
|
if (secondByte < 0xa1) {
|
||||||
|
iter.error = true;
|
||||||
|
}
|
||||||
|
break buildChar;
|
||||||
|
}
|
||||||
|
if (firstByte == 0x8f) {
|
||||||
|
// Code set 3.
|
||||||
|
// Three byte total char size, two bytes of actual char value.
|
||||||
|
thirdByte = iter.nextByte(det);
|
||||||
|
iter.charValue = (iter.charValue << 8) | thirdByte;
|
||||||
|
if (thirdByte < 0xa1) {
|
||||||
|
iter.error = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return iter.done == false;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The charset recognize for EUC-JP. A singleton instance of this class
|
||||||
|
* is created and kept by the public CharsetDetector class
|
||||||
|
*/
|
||||||
|
module.exports.euc_jp = function() {
|
||||||
|
this.name = function() {
|
||||||
|
return 'EUC-JP';
|
||||||
|
};
|
||||||
|
this.language = function() {
|
||||||
|
return 'ja';
|
||||||
|
};
|
||||||
|
|
||||||
|
// TODO: This set of data comes from the character frequency-
|
||||||
|
// of-occurence analysis tool. The data needs to be moved
|
||||||
|
// into a resource and loaded from there.
|
||||||
|
this.commonChars = [
|
||||||
|
0xa1a1, 0xa1a2, 0xa1a3, 0xa1a6, 0xa1bc, 0xa1ca, 0xa1cb, 0xa1d6, 0xa1d7, 0xa4a2,
|
||||||
|
0xa4a4, 0xa4a6, 0xa4a8, 0xa4aa, 0xa4ab, 0xa4ac, 0xa4ad, 0xa4af, 0xa4b1, 0xa4b3,
|
||||||
|
0xa4b5, 0xa4b7, 0xa4b9, 0xa4bb, 0xa4bd, 0xa4bf, 0xa4c0, 0xa4c1, 0xa4c3, 0xa4c4,
|
||||||
|
0xa4c6, 0xa4c7, 0xa4c8, 0xa4c9, 0xa4ca, 0xa4cb, 0xa4ce, 0xa4cf, 0xa4d0, 0xa4de,
|
||||||
|
0xa4df, 0xa4e1, 0xa4e2, 0xa4e4, 0xa4e8, 0xa4e9, 0xa4ea, 0xa4eb, 0xa4ec, 0xa4ef,
|
||||||
|
0xa4f2, 0xa4f3, 0xa5a2, 0xa5a3, 0xa5a4, 0xa5a6, 0xa5a7, 0xa5aa, 0xa5ad, 0xa5af,
|
||||||
|
0xa5b0, 0xa5b3, 0xa5b5, 0xa5b7, 0xa5b8, 0xa5b9, 0xa5bf, 0xa5c3, 0xa5c6, 0xa5c7,
|
||||||
|
0xa5c8, 0xa5c9, 0xa5cb, 0xa5d0, 0xa5d5, 0xa5d6, 0xa5d7, 0xa5de, 0xa5e0, 0xa5e1,
|
||||||
|
0xa5e5, 0xa5e9, 0xa5ea, 0xa5eb, 0xa5ec, 0xa5ed, 0xa5f3, 0xb8a9, 0xb9d4, 0xbaee,
|
||||||
|
0xbbc8, 0xbef0, 0xbfb7, 0xc4ea, 0xc6fc, 0xc7bd, 0xcab8, 0xcaf3, 0xcbdc, 0xcdd1
|
||||||
|
];
|
||||||
|
|
||||||
|
this.nextChar = eucNextChar;
|
||||||
|
};
|
||||||
|
util.inherits(module.exports.euc_jp, mbcs);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The charset recognize for EUC-KR. A singleton instance of this class
|
||||||
|
* is created and kept by the public CharsetDetector class
|
||||||
|
*/
|
||||||
|
module.exports.euc_kr = function() {
|
||||||
|
this.name = function() {
|
||||||
|
return 'EUC-KR';
|
||||||
|
};
|
||||||
|
this.language = function() {
|
||||||
|
return 'ko';
|
||||||
|
};
|
||||||
|
|
||||||
|
// TODO: This set of data comes from the character frequency-
|
||||||
|
// of-occurence analysis tool. The data needs to be moved
|
||||||
|
// into a resource and loaded from there.
|
||||||
|
this.commonChars = [
|
||||||
|
0xb0a1, 0xb0b3, 0xb0c5, 0xb0cd, 0xb0d4, 0xb0e6, 0xb0ed, 0xb0f8, 0xb0fa, 0xb0fc,
|
||||||
|
0xb1b8, 0xb1b9, 0xb1c7, 0xb1d7, 0xb1e2, 0xb3aa, 0xb3bb, 0xb4c2, 0xb4cf, 0xb4d9,
|
||||||
|
0xb4eb, 0xb5a5, 0xb5b5, 0xb5bf, 0xb5c7, 0xb5e9, 0xb6f3, 0xb7af, 0xb7c2, 0xb7ce,
|
||||||
|
0xb8a6, 0xb8ae, 0xb8b6, 0xb8b8, 0xb8bb, 0xb8e9, 0xb9ab, 0xb9ae, 0xb9cc, 0xb9ce,
|
||||||
|
0xb9fd, 0xbab8, 0xbace, 0xbad0, 0xbaf1, 0xbbe7, 0xbbf3, 0xbbfd, 0xbcad, 0xbcba,
|
||||||
|
0xbcd2, 0xbcf6, 0xbdba, 0xbdc0, 0xbdc3, 0xbdc5, 0xbec6, 0xbec8, 0xbedf, 0xbeee,
|
||||||
|
0xbef8, 0xbefa, 0xbfa1, 0xbfa9, 0xbfc0, 0xbfe4, 0xbfeb, 0xbfec, 0xbff8, 0xc0a7,
|
||||||
|
0xc0af, 0xc0b8, 0xc0ba, 0xc0bb, 0xc0bd, 0xc0c7, 0xc0cc, 0xc0ce, 0xc0cf, 0xc0d6,
|
||||||
|
0xc0da, 0xc0e5, 0xc0fb, 0xc0fc, 0xc1a4, 0xc1a6, 0xc1b6, 0xc1d6, 0xc1df, 0xc1f6,
|
||||||
|
0xc1f8, 0xc4a1, 0xc5cd, 0xc6ae, 0xc7cf, 0xc7d1, 0xc7d2, 0xc7d8, 0xc7e5, 0xc8ad
|
||||||
|
];
|
||||||
|
|
||||||
|
this.nextChar = eucNextChar;
|
||||||
|
};
|
||||||
|
util.inherits(module.exports.euc_kr, mbcs);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GB-18030 recognizer. Uses simplified Chinese statistics.
|
||||||
|
*/
|
||||||
|
module.exports.gb_18030 = function() {
|
||||||
|
this.name = function() {
|
||||||
|
return 'GB18030';
|
||||||
|
};
|
||||||
|
this.language = function() {
|
||||||
|
return 'zh';
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get the next character value for EUC based encodings.
|
||||||
|
* Character 'value' is simply the raw bytes that make up the character
|
||||||
|
* packed into an int.
|
||||||
|
*/
|
||||||
|
this.nextChar = function(iter, det) {
|
||||||
|
iter.index = iter.nextIndex;
|
||||||
|
iter.error = false;
|
||||||
|
var firstByte = 0;
|
||||||
|
var secondByte = 0;
|
||||||
|
var thirdByte = 0;
|
||||||
|
var fourthByte = 0;
|
||||||
|
buildChar: {
|
||||||
|
firstByte = iter.charValue = iter.nextByte(det);
|
||||||
|
if (firstByte < 0) {
|
||||||
|
// Ran off the end of the input data
|
||||||
|
iter.done = true;
|
||||||
|
break buildChar;
|
||||||
|
}
|
||||||
|
if (firstByte <= 0x80) {
|
||||||
|
// single byte char
|
||||||
|
break buildChar;
|
||||||
|
}
|
||||||
|
secondByte = iter.nextByte(det);
|
||||||
|
iter.charValue = (iter.charValue << 8) | secondByte;
|
||||||
|
if (firstByte >= 0x81 && firstByte <= 0xFE) {
|
||||||
|
// Two byte Char
|
||||||
|
if ((secondByte >= 0x40 && secondByte <= 0x7E) || (secondByte >=80 && secondByte <= 0xFE)) {
|
||||||
|
break buildChar;
|
||||||
|
}
|
||||||
|
// Four byte char
|
||||||
|
if (secondByte >= 0x30 && secondByte <= 0x39) {
|
||||||
|
thirdByte = iter.nextByte(det);
|
||||||
|
if (thirdByte >= 0x81 && thirdByte <= 0xFE) {
|
||||||
|
fourthByte = iter.nextByte(det);
|
||||||
|
if (fourthByte >= 0x30 && fourthByte <= 0x39) {
|
||||||
|
iter.charValue = (iter.charValue << 16) | (thirdByte << 8) | fourthByte;
|
||||||
|
break buildChar;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
iter.error = true;
|
||||||
|
break buildChar;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return iter.done == false;
|
||||||
|
};
|
||||||
|
|
||||||
|
// TODO: This set of data comes from the character frequency-
|
||||||
|
// of-occurence analysis tool. The data needs to be moved
|
||||||
|
// into a resource and loaded from there.
|
||||||
|
this.commonChars = [
|
||||||
|
0xa1a1, 0xa1a2, 0xa1a3, 0xa1a4, 0xa1b0, 0xa1b1, 0xa1f1, 0xa1f3, 0xa3a1, 0xa3ac,
|
||||||
|
0xa3ba, 0xb1a8, 0xb1b8, 0xb1be, 0xb2bb, 0xb3c9, 0xb3f6, 0xb4f3, 0xb5bd, 0xb5c4,
|
||||||
|
0xb5e3, 0xb6af, 0xb6d4, 0xb6e0, 0xb7a2, 0xb7a8, 0xb7bd, 0xb7d6, 0xb7dd, 0xb8b4,
|
||||||
|
0xb8df, 0xb8f6, 0xb9ab, 0xb9c9, 0xb9d8, 0xb9fa, 0xb9fd, 0xbacd, 0xbba7, 0xbbd6,
|
||||||
|
0xbbe1, 0xbbfa, 0xbcbc, 0xbcdb, 0xbcfe, 0xbdcc, 0xbecd, 0xbedd, 0xbfb4, 0xbfc6,
|
||||||
|
0xbfc9, 0xc0b4, 0xc0ed, 0xc1cb, 0xc2db, 0xc3c7, 0xc4dc, 0xc4ea, 0xc5cc, 0xc6f7,
|
||||||
|
0xc7f8, 0xc8ab, 0xc8cb, 0xc8d5, 0xc8e7, 0xc9cf, 0xc9fa, 0xcab1, 0xcab5, 0xcac7,
|
||||||
|
0xcad0, 0xcad6, 0xcaf5, 0xcafd, 0xccec, 0xcdf8, 0xceaa, 0xcec4, 0xced2, 0xcee5,
|
||||||
|
0xcfb5, 0xcfc2, 0xcfd6, 0xd0c2, 0xd0c5, 0xd0d0, 0xd0d4, 0xd1a7, 0xd2aa, 0xd2b2,
|
||||||
|
0xd2b5, 0xd2bb, 0xd2d4, 0xd3c3, 0xd3d0, 0xd3fd, 0xd4c2, 0xd4da, 0xd5e2, 0xd6d0
|
||||||
|
];
|
||||||
|
};
|
||||||
|
util.inherits(module.exports.gb_18030, mbcs);
|
|
@ -0,0 +1,907 @@
|
||||||
|
var util = require('util'),
|
||||||
|
Match = require ('../match');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class recognizes single-byte encodings. Because the encoding scheme is so
|
||||||
|
* simple, language statistics are used to do the matching.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function NGramParser(theNgramList, theByteMap) {
|
||||||
|
var N_GRAM_MASK = 0xFFFFFF;
|
||||||
|
|
||||||
|
this.byteIndex = 0;
|
||||||
|
this.ngram = 0;
|
||||||
|
|
||||||
|
this.ngramList = theNgramList;
|
||||||
|
this.byteMap = theByteMap;
|
||||||
|
|
||||||
|
this.ngramCount = 0;
|
||||||
|
this.hitCount = 0;
|
||||||
|
|
||||||
|
this.spaceChar;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Binary search for value in table, which must have exactly 64 entries.
|
||||||
|
*/
|
||||||
|
this.search = function(table, value) {
|
||||||
|
var index = 0;
|
||||||
|
|
||||||
|
if (table[index + 32] <= value) index += 32;
|
||||||
|
if (table[index + 16] <= value) index += 16;
|
||||||
|
if (table[index + 8] <= value) index += 8;
|
||||||
|
if (table[index + 4] <= value) index += 4;
|
||||||
|
if (table[index + 2] <= value) index += 2;
|
||||||
|
if (table[index + 1] <= value) index += 1;
|
||||||
|
if (table[index] > value) index -= 1;
|
||||||
|
|
||||||
|
if (index < 0 || table[index] != value)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return index;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.lookup = function(thisNgram) {
|
||||||
|
this.ngramCount += 1;
|
||||||
|
if (this.search(this.ngramList, thisNgram) >= 0) {
|
||||||
|
this.hitCount += 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.addByte = function(b) {
|
||||||
|
this.ngram = ((this.ngram << 8) + (b & 0xFF)) & N_GRAM_MASK;
|
||||||
|
this.lookup(this.ngram);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.nextByte = function(det) {
|
||||||
|
if (this.byteIndex >= det.fInputLen)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return det.fInputBytes[this.byteIndex++] & 0xFF;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.parse = function(det, spaceCh) {
|
||||||
|
var b, ignoreSpace = false;
|
||||||
|
this.spaceChar = spaceCh;
|
||||||
|
|
||||||
|
while ((b = this.nextByte(det)) >= 0) {
|
||||||
|
var mb = this.byteMap[b];
|
||||||
|
|
||||||
|
// TODO: 0x20 might not be a space in all character sets...
|
||||||
|
if (mb != 0) {
|
||||||
|
if (!(mb == this.spaceChar && ignoreSpace)) {
|
||||||
|
this.addByte(mb);
|
||||||
|
}
|
||||||
|
|
||||||
|
ignoreSpace = (mb == this.spaceChar);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Is this OK? The buffer could have ended in the middle of a word...
|
||||||
|
this.addByte(this.spaceChar);
|
||||||
|
|
||||||
|
var rawPercent = this.hitCount / this.ngramCount;
|
||||||
|
|
||||||
|
// TODO - This is a bit of a hack to take care of a case
|
||||||
|
// were we were getting a confidence of 135...
|
||||||
|
if (rawPercent > 0.33)
|
||||||
|
return 98;
|
||||||
|
|
||||||
|
return Math.floor(rawPercent * 300.0);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
function NGramsPlusLang(la, ng) {
|
||||||
|
this.fLang = la;
|
||||||
|
this.fNGrams = ng;
|
||||||
|
};
|
||||||
|
|
||||||
|
function sbcs() {};
|
||||||
|
sbcs.prototype.spaceChar = 0x20;
|
||||||
|
sbcs.prototype.ngrams = function() {};
|
||||||
|
sbcs.prototype.byteMap = function() {};
|
||||||
|
sbcs.prototype.match = function(det) {
|
||||||
|
|
||||||
|
var ngrams = this.ngrams();
|
||||||
|
var multiple = (Array.isArray(ngrams) && ngrams[0] instanceof NGramsPlusLang);
|
||||||
|
|
||||||
|
if (!multiple) {
|
||||||
|
var parser = new NGramParser(ngrams, this.byteMap());
|
||||||
|
var confidence = parser.parse(det, this.spaceChar);
|
||||||
|
return confidence <= 0 ? null : new Match(det, this, confidence);
|
||||||
|
}
|
||||||
|
|
||||||
|
var bestConfidenceSoFar = -1;
|
||||||
|
var lang = null;
|
||||||
|
|
||||||
|
for (var i = ngrams.length - 1; i >= 0; i--) {
|
||||||
|
var ngl = ngrams[i];
|
||||||
|
|
||||||
|
var parser = new NGramParser(ngl.fNGrams, this.byteMap());
|
||||||
|
var confidence = parser.parse(det, this.spaceChar);
|
||||||
|
if (confidence > bestConfidenceSoFar) {
|
||||||
|
bestConfidenceSoFar = confidence;
|
||||||
|
lang = ngl.fLang;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var name = this.name(det);
|
||||||
|
return bestConfidenceSoFar <= 0 ? null : new Match(det, this, bestConfidenceSoFar, name, lang);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
module.exports.ISO_8859_1 = function() {
|
||||||
|
this.byteMap = function() {
|
||||||
|
return [
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
|
||||||
|
0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
|
||||||
|
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
|
||||||
|
0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
|
||||||
|
0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
|
||||||
|
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
|
||||||
|
0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0xAA, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0xB5, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0xBA, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
|
||||||
|
0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
|
||||||
|
0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0x20,
|
||||||
|
0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xDF,
|
||||||
|
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
|
||||||
|
0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
|
||||||
|
0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0x20,
|
||||||
|
0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
this.ngrams = function() {
|
||||||
|
return [
|
||||||
|
new NGramsPlusLang('da', [
|
||||||
|
0x206166, 0x206174, 0x206465, 0x20656E, 0x206572, 0x20666F, 0x206861, 0x206920,
|
||||||
|
0x206D65, 0x206F67, 0x2070E5, 0x207369, 0x207374, 0x207469, 0x207669, 0x616620,
|
||||||
|
0x616E20, 0x616E64, 0x617220, 0x617420, 0x646520, 0x64656E, 0x646572, 0x646574,
|
||||||
|
0x652073, 0x656420, 0x656465, 0x656E20, 0x656E64, 0x657220, 0x657265, 0x657320,
|
||||||
|
0x657420, 0x666F72, 0x676520, 0x67656E, 0x676572, 0x696765, 0x696C20, 0x696E67,
|
||||||
|
0x6B6520, 0x6B6B65, 0x6C6572, 0x6C6967, 0x6C6C65, 0x6D6564, 0x6E6465, 0x6E6520,
|
||||||
|
0x6E6720, 0x6E6765, 0x6F6720, 0x6F6D20, 0x6F7220, 0x70E520, 0x722064, 0x722065,
|
||||||
|
0x722073, 0x726520, 0x737465, 0x742073, 0x746520, 0x746572, 0x74696C, 0x766572
|
||||||
|
]),
|
||||||
|
new NGramsPlusLang('de', [
|
||||||
|
0x20616E, 0x206175, 0x206265, 0x206461, 0x206465, 0x206469, 0x206569, 0x206765,
|
||||||
|
0x206861, 0x20696E, 0x206D69, 0x207363, 0x207365, 0x20756E, 0x207665, 0x20766F,
|
||||||
|
0x207765, 0x207A75, 0x626572, 0x636820, 0x636865, 0x636874, 0x646173, 0x64656E,
|
||||||
|
0x646572, 0x646965, 0x652064, 0x652073, 0x65696E, 0x656974, 0x656E20, 0x657220,
|
||||||
|
0x657320, 0x67656E, 0x68656E, 0x687420, 0x696368, 0x696520, 0x696E20, 0x696E65,
|
||||||
|
0x697420, 0x6C6963, 0x6C6C65, 0x6E2061, 0x6E2064, 0x6E2073, 0x6E6420, 0x6E6465,
|
||||||
|
0x6E6520, 0x6E6720, 0x6E6765, 0x6E7465, 0x722064, 0x726465, 0x726569, 0x736368,
|
||||||
|
0x737465, 0x742064, 0x746520, 0x74656E, 0x746572, 0x756E64, 0x756E67, 0x766572
|
||||||
|
]),
|
||||||
|
new NGramsPlusLang('en', [
|
||||||
|
0x206120, 0x20616E, 0x206265, 0x20636F, 0x20666F, 0x206861, 0x206865, 0x20696E,
|
||||||
|
0x206D61, 0x206F66, 0x207072, 0x207265, 0x207361, 0x207374, 0x207468, 0x20746F,
|
||||||
|
0x207768, 0x616964, 0x616C20, 0x616E20, 0x616E64, 0x617320, 0x617420, 0x617465,
|
||||||
|
0x617469, 0x642061, 0x642074, 0x652061, 0x652073, 0x652074, 0x656420, 0x656E74,
|
||||||
|
0x657220, 0x657320, 0x666F72, 0x686174, 0x686520, 0x686572, 0x696420, 0x696E20,
|
||||||
|
0x696E67, 0x696F6E, 0x697320, 0x6E2061, 0x6E2074, 0x6E6420, 0x6E6720, 0x6E7420,
|
||||||
|
0x6F6620, 0x6F6E20, 0x6F7220, 0x726520, 0x727320, 0x732061, 0x732074, 0x736169,
|
||||||
|
0x737420, 0x742074, 0x746572, 0x746861, 0x746865, 0x74696F, 0x746F20, 0x747320
|
||||||
|
]),
|
||||||
|
new NGramsPlusLang('es', [
|
||||||
|
0x206120, 0x206361, 0x20636F, 0x206465, 0x20656C, 0x20656E, 0x206573, 0x20696E,
|
||||||
|
0x206C61, 0x206C6F, 0x207061, 0x20706F, 0x207072, 0x207175, 0x207265, 0x207365,
|
||||||
|
0x20756E, 0x207920, 0x612063, 0x612064, 0x612065, 0x61206C, 0x612070, 0x616369,
|
||||||
|
0x61646F, 0x616C20, 0x617220, 0x617320, 0x6369F3, 0x636F6E, 0x646520, 0x64656C,
|
||||||
|
0x646F20, 0x652064, 0x652065, 0x65206C, 0x656C20, 0x656E20, 0x656E74, 0x657320,
|
||||||
|
0x657374, 0x69656E, 0x69F36E, 0x6C6120, 0x6C6F73, 0x6E2065, 0x6E7465, 0x6F2064,
|
||||||
|
0x6F2065, 0x6F6E20, 0x6F7220, 0x6F7320, 0x706172, 0x717565, 0x726120, 0x726573,
|
||||||
|
0x732064, 0x732065, 0x732070, 0x736520, 0x746520, 0x746F20, 0x756520, 0xF36E20
|
||||||
|
]),
|
||||||
|
new NGramsPlusLang('fr', [
|
||||||
|
0x206175, 0x20636F, 0x206461, 0x206465, 0x206475, 0x20656E, 0x206574, 0x206C61,
|
||||||
|
0x206C65, 0x207061, 0x20706F, 0x207072, 0x207175, 0x207365, 0x20736F, 0x20756E,
|
||||||
|
0x20E020, 0x616E74, 0x617469, 0x636520, 0x636F6E, 0x646520, 0x646573, 0x647520,
|
||||||
|
0x652061, 0x652063, 0x652064, 0x652065, 0x65206C, 0x652070, 0x652073, 0x656E20,
|
||||||
|
0x656E74, 0x657220, 0x657320, 0x657420, 0x657572, 0x696F6E, 0x697320, 0x697420,
|
||||||
|
0x6C6120, 0x6C6520, 0x6C6573, 0x6D656E, 0x6E2064, 0x6E6520, 0x6E7320, 0x6E7420,
|
||||||
|
0x6F6E20, 0x6F6E74, 0x6F7572, 0x717565, 0x72206C, 0x726520, 0x732061, 0x732064,
|
||||||
|
0x732065, 0x73206C, 0x732070, 0x742064, 0x746520, 0x74696F, 0x756520, 0x757220
|
||||||
|
]),
|
||||||
|
new NGramsPlusLang('it', [
|
||||||
|
0x20616C, 0x206368, 0x20636F, 0x206465, 0x206469, 0x206520, 0x20696C, 0x20696E,
|
||||||
|
0x206C61, 0x207065, 0x207072, 0x20756E, 0x612063, 0x612064, 0x612070, 0x612073,
|
||||||
|
0x61746F, 0x636865, 0x636F6E, 0x64656C, 0x646920, 0x652061, 0x652063, 0x652064,
|
||||||
|
0x652069, 0x65206C, 0x652070, 0x652073, 0x656C20, 0x656C6C, 0x656E74, 0x657220,
|
||||||
|
0x686520, 0x692061, 0x692063, 0x692064, 0x692073, 0x696120, 0x696C20, 0x696E20,
|
||||||
|
0x696F6E, 0x6C6120, 0x6C6520, 0x6C6920, 0x6C6C61, 0x6E6520, 0x6E6920, 0x6E6F20,
|
||||||
|
0x6E7465, 0x6F2061, 0x6F2064, 0x6F2069, 0x6F2073, 0x6F6E20, 0x6F6E65, 0x706572,
|
||||||
|
0x726120, 0x726520, 0x736920, 0x746120, 0x746520, 0x746920, 0x746F20, 0x7A696F
|
||||||
|
]),
|
||||||
|
new NGramsPlusLang('nl', [
|
||||||
|
0x20616C, 0x206265, 0x206461, 0x206465, 0x206469, 0x206565, 0x20656E, 0x206765,
|
||||||
|
0x206865, 0x20696E, 0x206D61, 0x206D65, 0x206F70, 0x207465, 0x207661, 0x207665,
|
||||||
|
0x20766F, 0x207765, 0x207A69, 0x61616E, 0x616172, 0x616E20, 0x616E64, 0x617220,
|
||||||
|
0x617420, 0x636874, 0x646520, 0x64656E, 0x646572, 0x652062, 0x652076, 0x65656E,
|
||||||
|
0x656572, 0x656E20, 0x657220, 0x657273, 0x657420, 0x67656E, 0x686574, 0x696520,
|
||||||
|
0x696E20, 0x696E67, 0x697320, 0x6E2062, 0x6E2064, 0x6E2065, 0x6E2068, 0x6E206F,
|
||||||
|
0x6E2076, 0x6E6465, 0x6E6720, 0x6F6E64, 0x6F6F72, 0x6F7020, 0x6F7220, 0x736368,
|
||||||
|
0x737465, 0x742064, 0x746520, 0x74656E, 0x746572, 0x76616E, 0x766572, 0x766F6F
|
||||||
|
]),
|
||||||
|
new NGramsPlusLang('no', [
|
||||||
|
0x206174, 0x206176, 0x206465, 0x20656E, 0x206572, 0x20666F, 0x206861, 0x206920,
|
||||||
|
0x206D65, 0x206F67, 0x2070E5, 0x207365, 0x20736B, 0x20736F, 0x207374, 0x207469,
|
||||||
|
0x207669, 0x20E520, 0x616E64, 0x617220, 0x617420, 0x646520, 0x64656E, 0x646574,
|
||||||
|
0x652073, 0x656420, 0x656E20, 0x656E65, 0x657220, 0x657265, 0x657420, 0x657474,
|
||||||
|
0x666F72, 0x67656E, 0x696B6B, 0x696C20, 0x696E67, 0x6B6520, 0x6B6B65, 0x6C6520,
|
||||||
|
0x6C6C65, 0x6D6564, 0x6D656E, 0x6E2073, 0x6E6520, 0x6E6720, 0x6E6765, 0x6E6E65,
|
||||||
|
0x6F6720, 0x6F6D20, 0x6F7220, 0x70E520, 0x722073, 0x726520, 0x736F6D, 0x737465,
|
||||||
|
0x742073, 0x746520, 0x74656E, 0x746572, 0x74696C, 0x747420, 0x747465, 0x766572
|
||||||
|
]),
|
||||||
|
new NGramsPlusLang('pt', [
|
||||||
|
0x206120, 0x20636F, 0x206461, 0x206465, 0x20646F, 0x206520, 0x206573, 0x206D61,
|
||||||
|
0x206E6F, 0x206F20, 0x207061, 0x20706F, 0x207072, 0x207175, 0x207265, 0x207365,
|
||||||
|
0x20756D, 0x612061, 0x612063, 0x612064, 0x612070, 0x616465, 0x61646F, 0x616C20,
|
||||||
|
0x617220, 0x617261, 0x617320, 0x636F6D, 0x636F6E, 0x646120, 0x646520, 0x646F20,
|
||||||
|
0x646F73, 0x652061, 0x652064, 0x656D20, 0x656E74, 0x657320, 0x657374, 0x696120,
|
||||||
|
0x696361, 0x6D656E, 0x6E7465, 0x6E746F, 0x6F2061, 0x6F2063, 0x6F2064, 0x6F2065,
|
||||||
|
0x6F2070, 0x6F7320, 0x706172, 0x717565, 0x726120, 0x726573, 0x732061, 0x732064,
|
||||||
|
0x732065, 0x732070, 0x737461, 0x746520, 0x746F20, 0x756520, 0xE36F20, 0xE7E36F
|
||||||
|
]),
|
||||||
|
new NGramsPlusLang('sv', [
|
||||||
|
0x206174, 0x206176, 0x206465, 0x20656E, 0x2066F6, 0x206861, 0x206920, 0x20696E,
|
||||||
|
0x206B6F, 0x206D65, 0x206F63, 0x2070E5, 0x20736B, 0x20736F, 0x207374, 0x207469,
|
||||||
|
0x207661, 0x207669, 0x20E472, 0x616465, 0x616E20, 0x616E64, 0x617220, 0x617474,
|
||||||
|
0x636820, 0x646520, 0x64656E, 0x646572, 0x646574, 0x656420, 0x656E20, 0x657220,
|
||||||
|
0x657420, 0x66F672, 0x67656E, 0x696C6C, 0x696E67, 0x6B6120, 0x6C6C20, 0x6D6564,
|
||||||
|
0x6E2073, 0x6E6120, 0x6E6465, 0x6E6720, 0x6E6765, 0x6E696E, 0x6F6368, 0x6F6D20,
|
||||||
|
0x6F6E20, 0x70E520, 0x722061, 0x722073, 0x726120, 0x736B61, 0x736F6D, 0x742073,
|
||||||
|
0x746120, 0x746520, 0x746572, 0x74696C, 0x747420, 0x766172, 0xE47220, 0xF67220,
|
||||||
|
])
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
this.name = function(det) {
|
||||||
|
return (det && det.fC1Bytes) ? 'windows-1252' : 'ISO-8859-1';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
util.inherits(module.exports.ISO_8859_1, sbcs);
|
||||||
|
|
||||||
|
|
||||||
|
module.exports.ISO_8859_2 = function() {
|
||||||
|
this.byteMap = function() {
|
||||||
|
return [
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
|
||||||
|
0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
|
||||||
|
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
|
||||||
|
0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
|
||||||
|
0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
|
||||||
|
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
|
||||||
|
0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0xB1, 0x20, 0xB3, 0x20, 0xB5, 0xB6, 0x20,
|
||||||
|
0x20, 0xB9, 0xBA, 0xBB, 0xBC, 0x20, 0xBE, 0xBF,
|
||||||
|
0x20, 0xB1, 0x20, 0xB3, 0x20, 0xB5, 0xB6, 0xB7,
|
||||||
|
0x20, 0xB9, 0xBA, 0xBB, 0xBC, 0x20, 0xBE, 0xBF,
|
||||||
|
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
|
||||||
|
0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
|
||||||
|
0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0x20,
|
||||||
|
0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xDF,
|
||||||
|
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
|
||||||
|
0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
|
||||||
|
0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0x20,
|
||||||
|
0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0x20
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
this.ngrams = function() {
|
||||||
|
return [
|
||||||
|
new NGramsPlusLang('cs', [
|
||||||
|
0x206120, 0x206279, 0x20646F, 0x206A65, 0x206E61, 0x206E65, 0x206F20, 0x206F64,
|
||||||
|
0x20706F, 0x207072, 0x2070F8, 0x20726F, 0x207365, 0x20736F, 0x207374, 0x20746F,
|
||||||
|
0x207620, 0x207679, 0x207A61, 0x612070, 0x636520, 0x636820, 0x652070, 0x652073,
|
||||||
|
0x652076, 0x656D20, 0x656EED, 0x686F20, 0x686F64, 0x697374, 0x6A6520, 0x6B7465,
|
||||||
|
0x6C6520, 0x6C6920, 0x6E6120, 0x6EE920, 0x6EEC20, 0x6EED20, 0x6F2070, 0x6F646E,
|
||||||
|
0x6F6A69, 0x6F7374, 0x6F7520, 0x6F7661, 0x706F64, 0x706F6A, 0x70726F, 0x70F865,
|
||||||
|
0x736520, 0x736F75, 0x737461, 0x737469, 0x73746E, 0x746572, 0x746EED, 0x746F20,
|
||||||
|
0x752070, 0xBE6520, 0xE16EED, 0xE9686F, 0xED2070, 0xED2073, 0xED6D20, 0xF86564,
|
||||||
|
]),
|
||||||
|
new NGramsPlusLang('hu', [
|
||||||
|
0x206120, 0x20617A, 0x206265, 0x206567, 0x20656C, 0x206665, 0x206861, 0x20686F,
|
||||||
|
0x206973, 0x206B65, 0x206B69, 0x206BF6, 0x206C65, 0x206D61, 0x206D65, 0x206D69,
|
||||||
|
0x206E65, 0x20737A, 0x207465, 0x20E973, 0x612061, 0x61206B, 0x61206D, 0x612073,
|
||||||
|
0x616B20, 0x616E20, 0x617A20, 0x62616E, 0x62656E, 0x656779, 0x656B20, 0x656C20,
|
||||||
|
0x656C65, 0x656D20, 0x656E20, 0x657265, 0x657420, 0x657465, 0x657474, 0x677920,
|
||||||
|
0x686F67, 0x696E74, 0x697320, 0x6B2061, 0x6BF67A, 0x6D6567, 0x6D696E, 0x6E2061,
|
||||||
|
0x6E616B, 0x6E656B, 0x6E656D, 0x6E7420, 0x6F6779, 0x732061, 0x737A65, 0x737A74,
|
||||||
|
0x737AE1, 0x73E967, 0x742061, 0x747420, 0x74E173, 0x7A6572, 0xE16E20, 0xE97320,
|
||||||
|
]),
|
||||||
|
new NGramsPlusLang('pl', [
|
||||||
|
0x20637A, 0x20646F, 0x206920, 0x206A65, 0x206B6F, 0x206D61, 0x206D69, 0x206E61,
|
||||||
|
0x206E69, 0x206F64, 0x20706F, 0x207072, 0x207369, 0x207720, 0x207769, 0x207779,
|
||||||
|
0x207A20, 0x207A61, 0x612070, 0x612077, 0x616E69, 0x636820, 0x637A65, 0x637A79,
|
||||||
|
0x646F20, 0x647A69, 0x652070, 0x652073, 0x652077, 0x65207A, 0x65676F, 0x656A20,
|
||||||
|
0x656D20, 0x656E69, 0x676F20, 0x696120, 0x696520, 0x69656A, 0x6B6120, 0x6B6920,
|
||||||
|
0x6B6965, 0x6D6965, 0x6E6120, 0x6E6961, 0x6E6965, 0x6F2070, 0x6F7761, 0x6F7769,
|
||||||
|
0x706F6C, 0x707261, 0x70726F, 0x70727A, 0x727A65, 0x727A79, 0x7369EA, 0x736B69,
|
||||||
|
0x737461, 0x776965, 0x796368, 0x796D20, 0x7A6520, 0x7A6965, 0x7A7920, 0xF37720,
|
||||||
|
]),
|
||||||
|
new NGramsPlusLang('ro', [
|
||||||
|
0x206120, 0x206163, 0x206361, 0x206365, 0x20636F, 0x206375, 0x206465, 0x206469,
|
||||||
|
0x206C61, 0x206D61, 0x207065, 0x207072, 0x207365, 0x2073E3, 0x20756E, 0x20BA69,
|
||||||
|
0x20EE6E, 0x612063, 0x612064, 0x617265, 0x617420, 0x617465, 0x617520, 0x636172,
|
||||||
|
0x636F6E, 0x637520, 0x63E320, 0x646520, 0x652061, 0x652063, 0x652064, 0x652070,
|
||||||
|
0x652073, 0x656120, 0x656920, 0x656C65, 0x656E74, 0x657374, 0x692061, 0x692063,
|
||||||
|
0x692064, 0x692070, 0x696520, 0x696920, 0x696E20, 0x6C6120, 0x6C6520, 0x6C6F72,
|
||||||
|
0x6C7569, 0x6E6520, 0x6E7472, 0x6F7220, 0x70656E, 0x726520, 0x726561, 0x727520,
|
||||||
|
0x73E320, 0x746520, 0x747275, 0x74E320, 0x756920, 0x756C20, 0xBA6920, 0xEE6E20,
|
||||||
|
])
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
this.name = function(det) {
|
||||||
|
return (det && det.fC1Bytes) ? 'windows-1250' : 'ISO-8859-2';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
util.inherits(module.exports.ISO_8859_2, sbcs);
|
||||||
|
|
||||||
|
|
||||||
|
module.exports.ISO_8859_5 = function() {
|
||||||
|
this.byteMap = function() {
|
||||||
|
return [
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
|
||||||
|
0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
|
||||||
|
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
|
||||||
|
0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
|
||||||
|
0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
|
||||||
|
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
|
||||||
|
0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
|
||||||
|
0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0x20, 0xFE, 0xFF,
|
||||||
|
0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
|
||||||
|
0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
|
||||||
|
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
|
||||||
|
0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
|
||||||
|
0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
|
||||||
|
0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
|
||||||
|
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
|
||||||
|
0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
|
||||||
|
0x20, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
|
||||||
|
0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0x20, 0xFE, 0xFF
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
this.ngrams = function() {
|
||||||
|
return [
|
||||||
|
0x20D220, 0x20D2DE, 0x20D4DE, 0x20D7D0, 0x20D820, 0x20DAD0, 0x20DADE, 0x20DDD0,
|
||||||
|
0x20DDD5, 0x20DED1, 0x20DFDE, 0x20DFE0, 0x20E0D0, 0x20E1DE, 0x20E1E2, 0x20E2DE,
|
||||||
|
0x20E7E2, 0x20EDE2, 0xD0DDD8, 0xD0E2EC, 0xD3DE20, 0xD5DBEC, 0xD5DDD8, 0xD5E1E2,
|
||||||
|
0xD5E220, 0xD820DF, 0xD8D520, 0xD8D820, 0xD8EF20, 0xDBD5DD, 0xDBD820, 0xDBECDD,
|
||||||
|
0xDDD020, 0xDDD520, 0xDDD8D5, 0xDDD8EF, 0xDDDE20, 0xDDDED2, 0xDE20D2, 0xDE20DF,
|
||||||
|
0xDE20E1, 0xDED220, 0xDED2D0, 0xDED3DE, 0xDED920, 0xDEDBEC, 0xDEDC20, 0xDEE1E2,
|
||||||
|
0xDFDEDB, 0xDFE0D5, 0xDFE0D8, 0xDFE0DE, 0xE0D0D2, 0xE0D5D4, 0xE1E2D0, 0xE1E2D2,
|
||||||
|
0xE1E2D8, 0xE1EF20, 0xE2D5DB, 0xE2DE20, 0xE2DEE0, 0xE2EC20, 0xE7E2DE, 0xEBE520
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
this.name = function(det) {
|
||||||
|
return 'ISO-8859-5';
|
||||||
|
};
|
||||||
|
|
||||||
|
this.language = function() {
|
||||||
|
return 'ru';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
util.inherits(module.exports.ISO_8859_5, sbcs);
|
||||||
|
|
||||||
|
|
||||||
|
module.exports.ISO_8859_6 = function() {
|
||||||
|
this.byteMap = function() {
|
||||||
|
return [
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
|
||||||
|
0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
|
||||||
|
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
|
||||||
|
0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
|
||||||
|
0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
|
||||||
|
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
|
||||||
|
0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
|
||||||
|
0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
|
||||||
|
0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
|
||||||
|
0xD8, 0xD9, 0xDA, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
|
||||||
|
0xE8, 0xE9, 0xEA, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
this.ngrams = function() {
|
||||||
|
return [
|
||||||
|
0x20C7E4, 0x20C7E6, 0x20C8C7, 0x20D9E4, 0x20E1EA, 0x20E4E4, 0x20E5E6, 0x20E8C7,
|
||||||
|
0xC720C7, 0xC7C120, 0xC7CA20, 0xC7D120, 0xC7E420, 0xC7E4C3, 0xC7E4C7, 0xC7E4C8,
|
||||||
|
0xC7E4CA, 0xC7E4CC, 0xC7E4CD, 0xC7E4CF, 0xC7E4D3, 0xC7E4D9, 0xC7E4E2, 0xC7E4E5,
|
||||||
|
0xC7E4E8, 0xC7E4EA, 0xC7E520, 0xC7E620, 0xC7E6CA, 0xC820C7, 0xC920C7, 0xC920E1,
|
||||||
|
0xC920E4, 0xC920E5, 0xC920E8, 0xCA20C7, 0xCF20C7, 0xCFC920, 0xD120C7, 0xD1C920,
|
||||||
|
0xD320C7, 0xD920C7, 0xD9E4E9, 0xE1EA20, 0xE420C7, 0xE4C920, 0xE4E920, 0xE4EA20,
|
||||||
|
0xE520C7, 0xE5C720, 0xE5C920, 0xE5E620, 0xE620C7, 0xE720C7, 0xE7C720, 0xE8C7E4,
|
||||||
|
0xE8E620, 0xE920C7, 0xEA20C7, 0xEA20E5, 0xEA20E8, 0xEAC920, 0xEAD120, 0xEAE620
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
this.name = function(det) {
|
||||||
|
return 'ISO-8859-6';
|
||||||
|
};
|
||||||
|
|
||||||
|
this.language = function() {
|
||||||
|
return 'ar';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
util.inherits(module.exports.ISO_8859_6, sbcs);
|
||||||
|
|
||||||
|
|
||||||
|
module.exports.ISO_8859_7 = function() {
|
||||||
|
this.byteMap = function() {
|
||||||
|
return [
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
|
||||||
|
0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
|
||||||
|
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
|
||||||
|
0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
|
||||||
|
0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
|
||||||
|
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
|
||||||
|
0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0xA1, 0xA2, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0xDC, 0x20,
|
||||||
|
0xDD, 0xDE, 0xDF, 0x20, 0xFC, 0x20, 0xFD, 0xFE,
|
||||||
|
0xC0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
|
||||||
|
0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
|
||||||
|
0xF0, 0xF1, 0x20, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
|
||||||
|
0xF8, 0xF9, 0xFA, 0xFB, 0xDC, 0xDD, 0xDE, 0xDF,
|
||||||
|
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
|
||||||
|
0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
|
||||||
|
0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
|
||||||
|
0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0x20
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
this.ngrams = function() {
|
||||||
|
return [
|
||||||
|
0x20E1ED, 0x20E1F0, 0x20E3E9, 0x20E4E9, 0x20E5F0, 0x20E720, 0x20EAE1, 0x20ECE5,
|
||||||
|
0x20EDE1, 0x20EF20, 0x20F0E1, 0x20F0EF, 0x20F0F1, 0x20F3F4, 0x20F3F5, 0x20F4E7,
|
||||||
|
0x20F4EF, 0xDFE120, 0xE120E1, 0xE120F4, 0xE1E920, 0xE1ED20, 0xE1F0FC, 0xE1F220,
|
||||||
|
0xE3E9E1, 0xE5E920, 0xE5F220, 0xE720F4, 0xE7ED20, 0xE7F220, 0xE920F4, 0xE9E120,
|
||||||
|
0xE9EADE, 0xE9F220, 0xEAE1E9, 0xEAE1F4, 0xECE520, 0xED20E1, 0xED20E5, 0xED20F0,
|
||||||
|
0xEDE120, 0xEFF220, 0xEFF520, 0xF0EFF5, 0xF0F1EF, 0xF0FC20, 0xF220E1, 0xF220E5,
|
||||||
|
0xF220EA, 0xF220F0, 0xF220F4, 0xF3E520, 0xF3E720, 0xF3F4EF, 0xF4E120, 0xF4E1E9,
|
||||||
|
0xF4E7ED, 0xF4E7F2, 0xF4E9EA, 0xF4EF20, 0xF4EFF5, 0xF4F9ED, 0xF9ED20, 0xFEED20
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
this.name = function(det) {
|
||||||
|
return (det && det.fC1Bytes) ? 'windows-1253' : 'ISO-8859-7';
|
||||||
|
};
|
||||||
|
|
||||||
|
this.language = function() {
|
||||||
|
return 'el';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
util.inherits(module.exports.ISO_8859_7, sbcs);
|
||||||
|
|
||||||
|
module.exports.ISO_8859_8 = function() {
|
||||||
|
|
||||||
|
this.byteMap = function() {
|
||||||
|
return [
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
|
||||||
|
0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
|
||||||
|
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
|
||||||
|
0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
|
||||||
|
0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
|
||||||
|
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
|
||||||
|
0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0xB5, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
|
||||||
|
0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
|
||||||
|
0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
|
||||||
|
0xF8, 0xF9, 0xFA, 0x20, 0x20, 0x20, 0x20, 0x20
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
this.ngrams = function() {
|
||||||
|
return [
|
||||||
|
new NGramsPlusLang('he', [
|
||||||
|
0x20E0E5, 0x20E0E7, 0x20E0E9, 0x20E0FA, 0x20E1E9, 0x20E1EE, 0x20E4E0, 0x20E4E5,
|
||||||
|
0x20E4E9, 0x20E4EE, 0x20E4F2, 0x20E4F9, 0x20E4FA, 0x20ECE0, 0x20ECE4, 0x20EEE0,
|
||||||
|
0x20F2EC, 0x20F9EC, 0xE0FA20, 0xE420E0, 0xE420E1, 0xE420E4, 0xE420EC, 0xE420EE,
|
||||||
|
0xE420F9, 0xE4E5E0, 0xE5E020, 0xE5ED20, 0xE5EF20, 0xE5F820, 0xE5FA20, 0xE920E4,
|
||||||
|
0xE9E420, 0xE9E5FA, 0xE9E9ED, 0xE9ED20, 0xE9EF20, 0xE9F820, 0xE9FA20, 0xEC20E0,
|
||||||
|
0xEC20E4, 0xECE020, 0xECE420, 0xED20E0, 0xED20E1, 0xED20E4, 0xED20EC, 0xED20EE,
|
||||||
|
0xED20F9, 0xEEE420, 0xEF20E4, 0xF0E420, 0xF0E920, 0xF0E9ED, 0xF2EC20, 0xF820E4,
|
||||||
|
0xF8E9ED, 0xF9EC20, 0xFA20E0, 0xFA20E1, 0xFA20E4, 0xFA20EC, 0xFA20EE, 0xFA20F9,
|
||||||
|
]),
|
||||||
|
new NGramsPlusLang('he', [
|
||||||
|
0x20E0E5, 0x20E0EC, 0x20E4E9, 0x20E4EC, 0x20E4EE, 0x20E4F0, 0x20E9F0, 0x20ECF2,
|
||||||
|
0x20ECF9, 0x20EDE5, 0x20EDE9, 0x20EFE5, 0x20EFE9, 0x20F8E5, 0x20F8E9, 0x20FAE0,
|
||||||
|
0x20FAE5, 0x20FAE9, 0xE020E4, 0xE020EC, 0xE020ED, 0xE020FA, 0xE0E420, 0xE0E5E4,
|
||||||
|
0xE0EC20, 0xE0EE20, 0xE120E4, 0xE120ED, 0xE120FA, 0xE420E4, 0xE420E9, 0xE420EC,
|
||||||
|
0xE420ED, 0xE420EF, 0xE420F8, 0xE420FA, 0xE4EC20, 0xE5E020, 0xE5E420, 0xE7E020,
|
||||||
|
0xE9E020, 0xE9E120, 0xE9E420, 0xEC20E4, 0xEC20ED, 0xEC20FA, 0xECF220, 0xECF920,
|
||||||
|
0xEDE9E9, 0xEDE9F0, 0xEDE9F8, 0xEE20E4, 0xEE20ED, 0xEE20FA, 0xEEE120, 0xEEE420,
|
||||||
|
0xF2E420, 0xF920E4, 0xF920ED, 0xF920FA, 0xF9E420, 0xFAE020, 0xFAE420, 0xFAE5E9,
|
||||||
|
])
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
this.name = function(det) {
|
||||||
|
return (det && det.fC1Bytes) ? 'windows-1255' : 'ISO-8859-8';
|
||||||
|
};
|
||||||
|
|
||||||
|
this.language = function() {
|
||||||
|
return 'he';
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
||||||
|
util.inherits(module.exports.ISO_8859_8, sbcs);
|
||||||
|
|
||||||
|
|
||||||
|
module.exports.ISO_8859_9 = function() {
|
||||||
|
this.byteMap = function() {
|
||||||
|
return [
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
|
||||||
|
0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
|
||||||
|
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
|
||||||
|
0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
|
||||||
|
0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
|
||||||
|
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
|
||||||
|
0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0xAA, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0xB5, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0xBA, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
|
||||||
|
0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
|
||||||
|
0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0x20,
|
||||||
|
0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0x69, 0xFE, 0xDF,
|
||||||
|
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
|
||||||
|
0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
|
||||||
|
0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0x20,
|
||||||
|
0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
this.ngrams = function() {
|
||||||
|
return [
|
||||||
|
0x206261, 0x206269, 0x206275, 0x206461, 0x206465, 0x206765, 0x206861, 0x20696C,
|
||||||
|
0x206B61, 0x206B6F, 0x206D61, 0x206F6C, 0x207361, 0x207461, 0x207665, 0x207961,
|
||||||
|
0x612062, 0x616B20, 0x616C61, 0x616D61, 0x616E20, 0x616EFD, 0x617220, 0x617261,
|
||||||
|
0x6172FD, 0x6173FD, 0x617961, 0x626972, 0x646120, 0x646520, 0x646920, 0x652062,
|
||||||
|
0x65206B, 0x656469, 0x656E20, 0x657220, 0x657269, 0x657369, 0x696C65, 0x696E20,
|
||||||
|
0x696E69, 0x697220, 0x6C616E, 0x6C6172, 0x6C6520, 0x6C6572, 0x6E2061, 0x6E2062,
|
||||||
|
0x6E206B, 0x6E6461, 0x6E6465, 0x6E6520, 0x6E6920, 0x6E696E, 0x6EFD20, 0x72696E,
|
||||||
|
0x72FD6E, 0x766520, 0x796120, 0x796F72, 0xFD6E20, 0xFD6E64, 0xFD6EFD, 0xFDF0FD
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
this.name = function(det) {
|
||||||
|
return (det && det.fC1Bytes) ? 'windows-1254' : 'ISO-8859-9';
|
||||||
|
};
|
||||||
|
|
||||||
|
this.language = function() {
|
||||||
|
return 'tr';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
util.inherits(module.exports.ISO_8859_9, sbcs);
|
||||||
|
|
||||||
|
|
||||||
|
module.exports.windows_1251 = function() {
|
||||||
|
this.byteMap = function() {
|
||||||
|
return [
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
|
||||||
|
0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
|
||||||
|
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
|
||||||
|
0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
|
||||||
|
0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
|
||||||
|
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
|
||||||
|
0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x90, 0x83, 0x20, 0x83, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x9A, 0x20, 0x9C, 0x9D, 0x9E, 0x9F,
|
||||||
|
0x90, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x9A, 0x20, 0x9C, 0x9D, 0x9E, 0x9F,
|
||||||
|
0x20, 0xA2, 0xA2, 0xBC, 0x20, 0xB4, 0x20, 0x20,
|
||||||
|
0xB8, 0x20, 0xBA, 0x20, 0x20, 0x20, 0x20, 0xBF,
|
||||||
|
0x20, 0x20, 0xB3, 0xB3, 0xB4, 0xB5, 0x20, 0x20,
|
||||||
|
0xB8, 0x20, 0xBA, 0x20, 0xBC, 0xBE, 0xBE, 0xBF,
|
||||||
|
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
|
||||||
|
0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
|
||||||
|
0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
|
||||||
|
0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF,
|
||||||
|
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
|
||||||
|
0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
|
||||||
|
0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
|
||||||
|
0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
this.ngrams = function() {
|
||||||
|
return [
|
||||||
|
0x20E220, 0x20E2EE, 0x20E4EE, 0x20E7E0, 0x20E820, 0x20EAE0, 0x20EAEE, 0x20EDE0,
|
||||||
|
0x20EDE5, 0x20EEE1, 0x20EFEE, 0x20EFF0, 0x20F0E0, 0x20F1EE, 0x20F1F2, 0x20F2EE,
|
||||||
|
0x20F7F2, 0x20FDF2, 0xE0EDE8, 0xE0F2FC, 0xE3EE20, 0xE5EBFC, 0xE5EDE8, 0xE5F1F2,
|
||||||
|
0xE5F220, 0xE820EF, 0xE8E520, 0xE8E820, 0xE8FF20, 0xEBE5ED, 0xEBE820, 0xEBFCED,
|
||||||
|
0xEDE020, 0xEDE520, 0xEDE8E5, 0xEDE8FF, 0xEDEE20, 0xEDEEE2, 0xEE20E2, 0xEE20EF,
|
||||||
|
0xEE20F1, 0xEEE220, 0xEEE2E0, 0xEEE3EE, 0xEEE920, 0xEEEBFC, 0xEEEC20, 0xEEF1F2,
|
||||||
|
0xEFEEEB, 0xEFF0E5, 0xEFF0E8, 0xEFF0EE, 0xF0E0E2, 0xF0E5E4, 0xF1F2E0, 0xF1F2E2,
|
||||||
|
0xF1F2E8, 0xF1FF20, 0xF2E5EB, 0xF2EE20, 0xF2EEF0, 0xF2FC20, 0xF7F2EE, 0xFBF520
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
this.name = function(det) {
|
||||||
|
return 'windows-1251';
|
||||||
|
};
|
||||||
|
|
||||||
|
this.language = function() {
|
||||||
|
return 'ru';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
util.inherits(module.exports.windows_1251, sbcs);
|
||||||
|
|
||||||
|
|
||||||
|
module.exports.windows_1256 = function() {
|
||||||
|
this.byteMap = function() {
|
||||||
|
return [
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
|
||||||
|
0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
|
||||||
|
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
|
||||||
|
0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
|
||||||
|
0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
|
||||||
|
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
|
||||||
|
0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x81, 0x20, 0x83, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x88, 0x20, 0x8A, 0x20, 0x9C, 0x8D, 0x8E, 0x8F,
|
||||||
|
0x90, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x98, 0x20, 0x9A, 0x20, 0x9C, 0x20, 0x20, 0x9F,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0xAA, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0xB5, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
|
||||||
|
0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
|
||||||
|
0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0x20,
|
||||||
|
0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
|
||||||
|
0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
|
||||||
|
0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0xF4, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0xF9, 0x20, 0xFB, 0xFC, 0x20, 0x20, 0xFF
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
this.ngrams = function() {
|
||||||
|
return [
|
||||||
|
0x20C7E1, 0x20C7E4, 0x20C8C7, 0x20DAE1, 0x20DDED, 0x20E1E1, 0x20E3E4, 0x20E6C7,
|
||||||
|
0xC720C7, 0xC7C120, 0xC7CA20, 0xC7D120, 0xC7E120, 0xC7E1C3, 0xC7E1C7, 0xC7E1C8,
|
||||||
|
0xC7E1CA, 0xC7E1CC, 0xC7E1CD, 0xC7E1CF, 0xC7E1D3, 0xC7E1DA, 0xC7E1DE, 0xC7E1E3,
|
||||||
|
0xC7E1E6, 0xC7E1ED, 0xC7E320, 0xC7E420, 0xC7E4CA, 0xC820C7, 0xC920C7, 0xC920DD,
|
||||||
|
0xC920E1, 0xC920E3, 0xC920E6, 0xCA20C7, 0xCF20C7, 0xCFC920, 0xD120C7, 0xD1C920,
|
||||||
|
0xD320C7, 0xDA20C7, 0xDAE1EC, 0xDDED20, 0xE120C7, 0xE1C920, 0xE1EC20, 0xE1ED20,
|
||||||
|
0xE320C7, 0xE3C720, 0xE3C920, 0xE3E420, 0xE420C7, 0xE520C7, 0xE5C720, 0xE6C7E1,
|
||||||
|
0xE6E420, 0xEC20C7, 0xED20C7, 0xED20E3, 0xED20E6, 0xEDC920, 0xEDD120, 0xEDE420
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
this.name = function(det) {
|
||||||
|
return 'windows-1256';
|
||||||
|
};
|
||||||
|
|
||||||
|
this.language = function() {
|
||||||
|
return 'ar';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
util.inherits(module.exports.windows_1256, sbcs);
|
||||||
|
|
||||||
|
|
||||||
|
module.exports.KOI8_R = function() {
|
||||||
|
this.byteMap = function() {
|
||||||
|
return [
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
|
||||||
|
0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
|
||||||
|
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
|
||||||
|
0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
|
||||||
|
0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
|
||||||
|
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
|
||||||
|
0x78, 0x79, 0x7A, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0xA3, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0xA3, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
|
||||||
|
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
|
||||||
|
0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
|
||||||
|
0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
|
||||||
|
0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
|
||||||
|
0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
|
||||||
|
0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
|
||||||
|
0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7,
|
||||||
|
0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
this.ngrams = function() {
|
||||||
|
return [
|
||||||
|
0x20C4CF, 0x20C920, 0x20CBC1, 0x20CBCF, 0x20CEC1, 0x20CEC5, 0x20CFC2, 0x20D0CF,
|
||||||
|
0x20D0D2, 0x20D2C1, 0x20D3CF, 0x20D3D4, 0x20D4CF, 0x20D720, 0x20D7CF, 0x20DAC1,
|
||||||
|
0x20DCD4, 0x20DED4, 0xC1CEC9, 0xC1D4D8, 0xC5CCD8, 0xC5CEC9, 0xC5D3D4, 0xC5D420,
|
||||||
|
0xC7CF20, 0xC920D0, 0xC9C520, 0xC9C920, 0xC9D120, 0xCCC5CE, 0xCCC920, 0xCCD8CE,
|
||||||
|
0xCEC120, 0xCEC520, 0xCEC9C5, 0xCEC9D1, 0xCECF20, 0xCECFD7, 0xCF20D0, 0xCF20D3,
|
||||||
|
0xCF20D7, 0xCFC7CF, 0xCFCA20, 0xCFCCD8, 0xCFCD20, 0xCFD3D4, 0xCFD720, 0xCFD7C1,
|
||||||
|
0xD0CFCC, 0xD0D2C5, 0xD0D2C9, 0xD0D2CF, 0xD2C1D7, 0xD2C5C4, 0xD3D120, 0xD3D4C1,
|
||||||
|
0xD3D4C9, 0xD3D4D7, 0xD4C5CC, 0xD4CF20, 0xD4CFD2, 0xD4D820, 0xD9C820, 0xDED4CF
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
this.name = function(det) {
|
||||||
|
return 'KOI8-R';
|
||||||
|
};
|
||||||
|
|
||||||
|
this.language = function() {
|
||||||
|
return 'ru';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
util.inherits(module.exports.KOI8_R, sbcs);
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
module.exports.ISO_8859_7 = function() {
|
||||||
|
this.byteMap = function() {
|
||||||
|
return [
|
||||||
|
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
this.ngrams = function() {
|
||||||
|
return [
|
||||||
|
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
this.name = function(det) {
|
||||||
|
if (typeof det == 'undefined')
|
||||||
|
return 'ISO-8859-7';
|
||||||
|
return det.fC1Bytes ? 'windows-1253' : 'ISO-8859-7';
|
||||||
|
};
|
||||||
|
|
||||||
|
this.language = function() {
|
||||||
|
return 'el';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
util.inherits(module.exports.ISO_8859_7, sbcs);
|
||||||
|
*/
|
||||||
|
|
|
@ -0,0 +1,112 @@
|
||||||
|
'use strict';
|
||||||
|
var util = require('util'),
|
||||||
|
Match = require ('../match');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class matches UTF-16 and UTF-32, both big- and little-endian. The
|
||||||
|
* BOM will be used if it is present.
|
||||||
|
*/
|
||||||
|
module.exports.UTF_16BE = function() {
|
||||||
|
this.name = function() {
|
||||||
|
return 'UTF-16BE';
|
||||||
|
};
|
||||||
|
this.match = function(det) {
|
||||||
|
var input = det.fRawInput;
|
||||||
|
|
||||||
|
if (input.length >= 2 && ((input[0] & 0xff) == 0xfe && (input[1] & 0xff) == 0xff)) {
|
||||||
|
return new Match(det, this, 100); // confidence = 100
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Do some statistics to check for unsigned UTF-16BE
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.UTF_16LE = function() {
|
||||||
|
this.name = function() {
|
||||||
|
return 'UTF-16LE';
|
||||||
|
};
|
||||||
|
this.match = function(det) {
|
||||||
|
var input = det.fRawInput;
|
||||||
|
|
||||||
|
if (input.length >= 2 && ((input[0] & 0xff) == 0xff && (input[1] & 0xff) == 0xfe)) {
|
||||||
|
// LE BOM is present.
|
||||||
|
if (input.length >= 4 && input[2] == 0x00 && input[3] == 0x00) {
|
||||||
|
// It is probably UTF-32 LE, not UTF-16
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Match(det, this, 100); // confidence = 100
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Do some statistics to check for unsigned UTF-16LE
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function UTF_32() {};
|
||||||
|
UTF_32.prototype.match = function(det) {
|
||||||
|
var input = det.fRawInput,
|
||||||
|
limit = (det.fRawLength / 4) * 4,
|
||||||
|
numValid = 0,
|
||||||
|
numInvalid = 0,
|
||||||
|
hasBOM = false,
|
||||||
|
confidence = 0;
|
||||||
|
|
||||||
|
if (limit == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.getChar(input, 0) == 0x0000FEFF) {
|
||||||
|
hasBOM = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < limit; i += 4) {
|
||||||
|
var ch = this.getChar(input, i);
|
||||||
|
|
||||||
|
if (ch < 0 || ch >= 0x10FFFF || (ch >= 0xD800 && ch <= 0xDFFF)) {
|
||||||
|
numInvalid += 1;
|
||||||
|
} else {
|
||||||
|
numValid += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cook up some sort of confidence score, based on presence of a BOM
|
||||||
|
// and the existence of valid and/or invalid multi-byte sequences.
|
||||||
|
if (hasBOM && numInvalid == 0) {
|
||||||
|
confidence = 100;
|
||||||
|
} else if (hasBOM && numValid > numInvalid * 10) {
|
||||||
|
confidence = 80;
|
||||||
|
} else if (numValid > 3 && numInvalid == 0) {
|
||||||
|
confidence = 100;
|
||||||
|
} else if (numValid > 0 && numInvalid == 0) {
|
||||||
|
confidence = 80;
|
||||||
|
} else if (numValid > numInvalid * 10) {
|
||||||
|
// Probably corrupt UTF-32BE data. Valid sequences aren't likely by chance.
|
||||||
|
confidence = 25;
|
||||||
|
}
|
||||||
|
|
||||||
|
// return confidence == 0 ? null : new CharsetMatch(det, this, confidence);
|
||||||
|
return confidence == 0 ? null : new Match(det, this, confidence);
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.UTF_32BE = function() {
|
||||||
|
this.name = function() {
|
||||||
|
return 'UTF-32BE';
|
||||||
|
};
|
||||||
|
this.getChar = function(input, index) {
|
||||||
|
return (input[index + 0] & 0xff) << 24 | (input[index + 1] & 0xff) << 16 |
|
||||||
|
(input[index + 2] & 0xff) << 8 | (input[index + 3] & 0xff);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
util.inherits(module.exports.UTF_32BE, UTF_32);
|
||||||
|
|
||||||
|
module.exports.UTF_32LE = function() {
|
||||||
|
this.name = function() {
|
||||||
|
return 'UTF-32LE';
|
||||||
|
};
|
||||||
|
this.getChar = function(input, index) {
|
||||||
|
return (input[index + 3] & 0xff) << 24 | (input[index + 2] & 0xff) << 16 |
|
||||||
|
(input[index + 1] & 0xff) << 8 | (input[index + 0] & 0xff);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
util.inherits(module.exports.UTF_32LE, UTF_32);
|
|
@ -0,0 +1,84 @@
|
||||||
|
|
||||||
|
var Match = require ('../match');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Charset recognizer for UTF-8
|
||||||
|
*/
|
||||||
|
module.exports = function() {
|
||||||
|
this.name = function() {
|
||||||
|
return 'UTF-8';
|
||||||
|
};
|
||||||
|
this.match = function(det) {
|
||||||
|
|
||||||
|
var hasBOM = false,
|
||||||
|
numValid = 0,
|
||||||
|
numInvalid = 0,
|
||||||
|
input = det.fRawInput,
|
||||||
|
trailBytes = 0,
|
||||||
|
confidence;
|
||||||
|
|
||||||
|
if (det.fRawLength >= 3 &&
|
||||||
|
(input[0] & 0xff) == 0xef && (input[1] & 0xff) == 0xbb && (input[2] & 0xff) == 0xbf) {
|
||||||
|
hasBOM = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Scan for multi-byte sequences
|
||||||
|
for (var i = 0; i < det.fRawLength; i++) {
|
||||||
|
var b = input[i];
|
||||||
|
if ((b & 0x80) == 0)
|
||||||
|
continue; // ASCII
|
||||||
|
|
||||||
|
// Hi bit on char found. Figure out how long the sequence should be
|
||||||
|
if ((b & 0x0e0) == 0x0c0) {
|
||||||
|
trailBytes = 1;
|
||||||
|
} else if ((b & 0x0f0) == 0x0e0) {
|
||||||
|
trailBytes = 2;
|
||||||
|
} else if ((b & 0x0f8) == 0xf0) {
|
||||||
|
trailBytes = 3;
|
||||||
|
} else {
|
||||||
|
numInvalid++;
|
||||||
|
if (numInvalid > 5)
|
||||||
|
break;
|
||||||
|
trailBytes = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify that we've got the right number of trail bytes in the sequence
|
||||||
|
for (;;) {
|
||||||
|
i++;
|
||||||
|
if (i >= det.fRawLength)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if ((input[i] & 0xc0) != 0x080) {
|
||||||
|
numInvalid++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (--trailBytes == 0) {
|
||||||
|
numValid++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cook up some sort of confidence score, based on presense of a BOM
|
||||||
|
// and the existence of valid and/or invalid multi-byte sequences.
|
||||||
|
confidence = 0;
|
||||||
|
if (hasBOM && numInvalid == 0)
|
||||||
|
confidence = 100;
|
||||||
|
else if (hasBOM && numValid > numInvalid * 10)
|
||||||
|
confidence = 80;
|
||||||
|
else if (numValid > 3 && numInvalid == 0)
|
||||||
|
confidence = 100;
|
||||||
|
else if (numValid > 0 && numInvalid == 0)
|
||||||
|
confidence = 80;
|
||||||
|
else if (numValid == 0 && numInvalid == 0)
|
||||||
|
// Plain ASCII.
|
||||||
|
confidence = 10;
|
||||||
|
else if (numValid > numInvalid * 10)
|
||||||
|
// Probably corruput utf-8 data. Valid sequences aren't likely by chance.
|
||||||
|
confidence = 25;
|
||||||
|
else
|
||||||
|
return null
|
||||||
|
|
||||||
|
return new Match(det, this, confidence);
|
||||||
|
};
|
||||||
|
};
|
|
@ -0,0 +1,151 @@
|
||||||
|
|
||||||
|
var fs = require('fs');
|
||||||
|
|
||||||
|
var utf8 = require('./encoding/utf8'),
|
||||||
|
unicode = require('./encoding/unicode'),
|
||||||
|
mbcs = require('./encoding/mbcs'),
|
||||||
|
sbcs = require('./encoding/sbcs'),
|
||||||
|
iso2022 = require('./encoding/iso2022');
|
||||||
|
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
var recognisers = [
|
||||||
|
new utf8,
|
||||||
|
new unicode.UTF_16BE,
|
||||||
|
new unicode.UTF_16LE,
|
||||||
|
new unicode.UTF_32BE,
|
||||||
|
new unicode.UTF_32LE,
|
||||||
|
new mbcs.sjis,
|
||||||
|
new mbcs.big5,
|
||||||
|
new mbcs.euc_jp,
|
||||||
|
new mbcs.euc_kr,
|
||||||
|
new mbcs.gb_18030,
|
||||||
|
new iso2022.ISO_2022_JP,
|
||||||
|
new iso2022.ISO_2022_KR,
|
||||||
|
new iso2022.ISO_2022_CN,
|
||||||
|
new sbcs.ISO_8859_1,
|
||||||
|
new sbcs.ISO_8859_2,
|
||||||
|
new sbcs.ISO_8859_5,
|
||||||
|
new sbcs.ISO_8859_6,
|
||||||
|
new sbcs.ISO_8859_7,
|
||||||
|
new sbcs.ISO_8859_8,
|
||||||
|
new sbcs.ISO_8859_9,
|
||||||
|
new sbcs.windows_1251,
|
||||||
|
new sbcs.windows_1256,
|
||||||
|
new sbcs.KOI8_R
|
||||||
|
];
|
||||||
|
|
||||||
|
module.exports.detect = function(buffer, opts) {
|
||||||
|
|
||||||
|
// Tally up the byte occurence statistics.
|
||||||
|
var fByteStats = [];
|
||||||
|
for (var i = 0; i < 256; i++)
|
||||||
|
fByteStats[i] = 0;
|
||||||
|
|
||||||
|
for (var i = buffer.length - 1; i >= 0; i--)
|
||||||
|
fByteStats[buffer[i] & 0x00ff]++;
|
||||||
|
|
||||||
|
var fC1Bytes = false;
|
||||||
|
for (var i = 0x80; i <= 0x9F; i += 1) {
|
||||||
|
if (fByteStats[i] != 0) {
|
||||||
|
fC1Bytes = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var context = {
|
||||||
|
fByteStats: fByteStats,
|
||||||
|
fC1Bytes: fC1Bytes,
|
||||||
|
fRawInput: buffer,
|
||||||
|
fRawLength: buffer.length,
|
||||||
|
fInputBytes: buffer,
|
||||||
|
fInputLen: buffer.length
|
||||||
|
};
|
||||||
|
|
||||||
|
var matches = recognisers.map(function(rec) {
|
||||||
|
return rec.match(context);
|
||||||
|
}).filter(function(match) {
|
||||||
|
return !!match;
|
||||||
|
}).sort(function(a, b) {
|
||||||
|
return b.confidence - a.confidence;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (opts && opts.returnAllMatches === true) {
|
||||||
|
return matches;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return matches.length > 0 ? matches[0].name : null;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.detectFile = function(filepath, opts, cb) {
|
||||||
|
if (typeof opts === 'function') {
|
||||||
|
cb = opts;
|
||||||
|
opts = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
var fd;
|
||||||
|
|
||||||
|
var handler = function(err, buffer) {
|
||||||
|
if (fd) {
|
||||||
|
fs.closeSync(fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (err) return cb(err, null);
|
||||||
|
cb(null, self.detect(buffer, opts));
|
||||||
|
};
|
||||||
|
|
||||||
|
if (opts && opts.sampleSize) {
|
||||||
|
fd = fs.openSync(filepath, 'r'),
|
||||||
|
sample = Buffer.allocUnsafe(opts.sampleSize);
|
||||||
|
|
||||||
|
fs.read(fd, sample, 0, opts.sampleSize, null, function(err) {
|
||||||
|
handler(err, sample);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
fs.readFile(filepath, handler);
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports.detectFileSync = function(filepath, opts) {
|
||||||
|
if (opts && opts.sampleSize) {
|
||||||
|
var fd = fs.openSync(filepath, 'r'),
|
||||||
|
sample = Buffer.allocUnsafe(opts.sampleSize);
|
||||||
|
|
||||||
|
fs.readSync(fd, sample, 0, opts.sampleSize);
|
||||||
|
fs.closeSync(fd);
|
||||||
|
return self.detect(sample, opts);
|
||||||
|
}
|
||||||
|
|
||||||
|
return self.detect(fs.readFileSync(filepath), opts);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Wrappers for the previous functions to return all encodings
|
||||||
|
module.exports.detectAll = function(buffer, opts) {
|
||||||
|
if (typeof opts !== 'object') {
|
||||||
|
opts = {};
|
||||||
|
}
|
||||||
|
opts.returnAllMatches = true;
|
||||||
|
return self.detect(buffer, opts);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.detectFileAll = function(filepath, opts, cb) {
|
||||||
|
if (typeof opts === 'function') {
|
||||||
|
cb = opts;
|
||||||
|
opts = undefined;
|
||||||
|
}
|
||||||
|
if (typeof opts !== 'object') {
|
||||||
|
opts = {};
|
||||||
|
}
|
||||||
|
opts.returnAllMatches = true;
|
||||||
|
self.detectFile(filepath, opts, cb);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.detectFileAllSync = function(filepath, opts) {
|
||||||
|
if (typeof opts !== 'object') {
|
||||||
|
opts = {};
|
||||||
|
}
|
||||||
|
opts.returnAllMatches = true;
|
||||||
|
return self.detectFileSync(filepath, opts);
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
|
||||||
|
module.exports = function(det, rec, confidence, name, lang) {
|
||||||
|
this.confidence = confidence;
|
||||||
|
this.name = name || rec.name(det);
|
||||||
|
this.lang = lang;
|
||||||
|
};
|
|
@ -0,0 +1,83 @@
|
||||||
|
{
|
||||||
|
"_from": "chardet@^0.7.0",
|
||||||
|
"_id": "chardet@0.7.0",
|
||||||
|
"_inBundle": false,
|
||||||
|
"_integrity": "sha512-mT8iDcrh03qDGRRmoA2hmBJnxpllMR+0/0qlzjqZES6NdiWDcZkCNAk4rPFZ9Q85r27unkiNNg8ZOiwZXBHwcA==",
|
||||||
|
"_location": "/chardet",
|
||||||
|
"_phantomChildren": {},
|
||||||
|
"_requested": {
|
||||||
|
"type": "range",
|
||||||
|
"registry": true,
|
||||||
|
"raw": "chardet@^0.7.0",
|
||||||
|
"name": "chardet",
|
||||||
|
"escapedName": "chardet",
|
||||||
|
"rawSpec": "^0.7.0",
|
||||||
|
"saveSpec": null,
|
||||||
|
"fetchSpec": "^0.7.0"
|
||||||
|
},
|
||||||
|
"_requiredBy": [
|
||||||
|
"/external-editor"
|
||||||
|
],
|
||||||
|
"_resolved": "https://registry.npmjs.org/chardet/-/chardet-0.7.0.tgz",
|
||||||
|
"_shasum": "90094849f0937f2eedc2425d0d28a9e5f0cbad9e",
|
||||||
|
"_spec": "chardet@^0.7.0",
|
||||||
|
"_where": "/Users/keiferju/code/Lingtu/smx-svelma/upload/node_modules/external-editor",
|
||||||
|
"author": {
|
||||||
|
"name": "Dmitry Shirokov",
|
||||||
|
"email": "deadrunk@gmail.com"
|
||||||
|
},
|
||||||
|
"bugs": {
|
||||||
|
"url": "http://github.com/runk/node-chardet/issues"
|
||||||
|
},
|
||||||
|
"bundleDependencies": false,
|
||||||
|
"contributors": [
|
||||||
|
{
|
||||||
|
"name": "@spikying"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "@wtgtybhertgeghgtwtg"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "@suisho"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "@seangarner"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "@zevanty"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"deprecated": false,
|
||||||
|
"description": "Character detector",
|
||||||
|
"devDependencies": {
|
||||||
|
"github-publish-release": "^5.0.0",
|
||||||
|
"mocha": "^5.2.0"
|
||||||
|
},
|
||||||
|
"directories": {
|
||||||
|
"test": "test"
|
||||||
|
},
|
||||||
|
"engine": {
|
||||||
|
"node": ">=4"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/runk/node-chardet",
|
||||||
|
"keywords": [
|
||||||
|
"encoding",
|
||||||
|
"character",
|
||||||
|
"utf8",
|
||||||
|
"detector",
|
||||||
|
"chardet",
|
||||||
|
"icu"
|
||||||
|
],
|
||||||
|
"license": "MIT",
|
||||||
|
"main": "index.js",
|
||||||
|
"name": "chardet",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+ssh://git@github.com/runk/node-chardet.git"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"release": "scripts/release",
|
||||||
|
"test": "mocha -R spec --recursive --bail"
|
||||||
|
},
|
||||||
|
"version": "0.7.0"
|
||||||
|
}
|
|
@ -0,0 +1,47 @@
|
||||||
|
declare namespace cleanStack {
|
||||||
|
interface Options {
|
||||||
|
/**
|
||||||
|
Prettify the file paths in the stack:
|
||||||
|
|
||||||
|
`/Users/sindresorhus/dev/clean-stack/unicorn.js:2:15` → `~/dev/clean-stack/unicorn.js:2:15`
|
||||||
|
|
||||||
|
@default false
|
||||||
|
*/
|
||||||
|
readonly pretty?: boolean;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
Clean up error stack traces. Removes the mostly unhelpful internal Node.js entries.
|
||||||
|
|
||||||
|
@param stack - The `stack` property of an `Error`.
|
||||||
|
|
||||||
|
@example
|
||||||
|
```
|
||||||
|
import cleanStack = require('clean-stack');
|
||||||
|
|
||||||
|
const error = new Error('Missing unicorn');
|
||||||
|
|
||||||
|
console.log(error.stack);
|
||||||
|
|
||||||
|
// Error: Missing unicorn
|
||||||
|
// at Object.<anonymous> (/Users/sindresorhus/dev/clean-stack/unicorn.js:2:15)
|
||||||
|
// at Module._compile (module.js:409:26)
|
||||||
|
// at Object.Module._extensions..js (module.js:416:10)
|
||||||
|
// at Module.load (module.js:343:32)
|
||||||
|
// at Function.Module._load (module.js:300:12)
|
||||||
|
// at Function.Module.runMain (module.js:441:10)
|
||||||
|
// at startup (node.js:139:18)
|
||||||
|
|
||||||
|
console.log(cleanStack(error.stack));
|
||||||
|
|
||||||
|
// Error: Missing unicorn
|
||||||
|
// at Object.<anonymous> (/Users/sindresorhus/dev/clean-stack/unicorn.js:2:15)
|
||||||
|
```
|
||||||
|
*/
|
||||||
|
declare function cleanStack(
|
||||||
|
stack: string,
|
||||||
|
options?: cleanStack.Options
|
||||||
|
): string;
|
||||||
|
|
||||||
|
export = cleanStack;
|
|
@ -0,0 +1,40 @@
|
||||||
|
'use strict';
|
||||||
|
const os = require('os');
|
||||||
|
|
||||||
|
const extractPathRegex = /\s+at.*(?:\(|\s)(.*)\)?/;
|
||||||
|
const pathRegex = /^(?:(?:(?:node|(?:internal\/[\w/]*|.*node_modules\/(?:babel-polyfill|pirates)\/.*)?\w+)\.js:\d+:\d+)|native)/;
|
||||||
|
const homeDir = typeof os.homedir === 'undefined' ? '' : os.homedir();
|
||||||
|
|
||||||
|
module.exports = (stack, options) => {
|
||||||
|
options = Object.assign({pretty: false}, options);
|
||||||
|
|
||||||
|
return stack.replace(/\\/g, '/')
|
||||||
|
.split('\n')
|
||||||
|
.filter(line => {
|
||||||
|
const pathMatches = line.match(extractPathRegex);
|
||||||
|
if (pathMatches === null || !pathMatches[1]) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const match = pathMatches[1];
|
||||||
|
|
||||||
|
// Electron
|
||||||
|
if (
|
||||||
|
match.includes('.app/Contents/Resources/electron.asar') ||
|
||||||
|
match.includes('.app/Contents/Resources/default_app.asar')
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return !pathRegex.test(match);
|
||||||
|
})
|
||||||
|
.filter(line => line.trim() !== '')
|
||||||
|
.map(line => {
|
||||||
|
if (options.pretty) {
|
||||||
|
return line.replace(extractPathRegex, (m, p1) => m.replace(p1, p1.replace(homeDir, '~')));
|
||||||
|
}
|
||||||
|
|
||||||
|
return line;
|
||||||
|
})
|
||||||
|
.join('\n');
|
||||||
|
};
|
|
@ -0,0 +1,9 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -0,0 +1,71 @@
|
||||||
|
{
|
||||||
|
"_from": "clean-stack@^2.0.0",
|
||||||
|
"_id": "clean-stack@2.2.0",
|
||||||
|
"_inBundle": false,
|
||||||
|
"_integrity": "sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A==",
|
||||||
|
"_location": "/clean-stack",
|
||||||
|
"_phantomChildren": {},
|
||||||
|
"_requested": {
|
||||||
|
"type": "range",
|
||||||
|
"registry": true,
|
||||||
|
"raw": "clean-stack@^2.0.0",
|
||||||
|
"name": "clean-stack",
|
||||||
|
"escapedName": "clean-stack",
|
||||||
|
"rawSpec": "^2.0.0",
|
||||||
|
"saveSpec": null,
|
||||||
|
"fetchSpec": "^2.0.0"
|
||||||
|
},
|
||||||
|
"_requiredBy": [
|
||||||
|
"/aggregate-error"
|
||||||
|
],
|
||||||
|
"_resolved": "https://registry.npmjs.org/clean-stack/-/clean-stack-2.2.0.tgz",
|
||||||
|
"_shasum": "ee8472dbb129e727b31e8a10a427dee9dfe4008b",
|
||||||
|
"_spec": "clean-stack@^2.0.0",
|
||||||
|
"_where": "/Users/keiferju/code/Lingtu/smx-svelma/upload/node_modules/aggregate-error",
|
||||||
|
"author": {
|
||||||
|
"name": "Sindre Sorhus",
|
||||||
|
"email": "sindresorhus@gmail.com",
|
||||||
|
"url": "sindresorhus.com"
|
||||||
|
},
|
||||||
|
"browser": {
|
||||||
|
"os": false
|
||||||
|
},
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/sindresorhus/clean-stack/issues"
|
||||||
|
},
|
||||||
|
"bundleDependencies": false,
|
||||||
|
"deprecated": false,
|
||||||
|
"description": "Clean up error stack traces",
|
||||||
|
"devDependencies": {
|
||||||
|
"ava": "^1.4.1",
|
||||||
|
"tsd": "^0.7.2",
|
||||||
|
"xo": "^0.24.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=6"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"index.js",
|
||||||
|
"index.d.ts"
|
||||||
|
],
|
||||||
|
"homepage": "https://github.com/sindresorhus/clean-stack#readme",
|
||||||
|
"keywords": [
|
||||||
|
"clean",
|
||||||
|
"stack",
|
||||||
|
"trace",
|
||||||
|
"traces",
|
||||||
|
"error",
|
||||||
|
"err",
|
||||||
|
"electron"
|
||||||
|
],
|
||||||
|
"license": "MIT",
|
||||||
|
"name": "clean-stack",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/sindresorhus/clean-stack.git"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "xo && ava && tsd"
|
||||||
|
},
|
||||||
|
"version": "2.2.0"
|
||||||
|
}
|
|
@ -0,0 +1,76 @@
|
||||||
|
# clean-stack [](https://travis-ci.org/sindresorhus/clean-stack)
|
||||||
|
|
||||||
|
> Clean up error stack traces
|
||||||
|
|
||||||
|
Removes the mostly unhelpful internal Node.js entries.
|
||||||
|
|
||||||
|
Also works in Electron.
|
||||||
|
|
||||||
|
|
||||||
|
## Install
|
||||||
|
|
||||||
|
```
|
||||||
|
$ npm install clean-stack
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```js
|
||||||
|
const cleanStack = require('clean-stack');
|
||||||
|
|
||||||
|
const error = new Error('Missing unicorn');
|
||||||
|
|
||||||
|
console.log(error.stack);
|
||||||
|
/*
|
||||||
|
Error: Missing unicorn
|
||||||
|
at Object.<anonymous> (/Users/sindresorhus/dev/clean-stack/unicorn.js:2:15)
|
||||||
|
at Module._compile (module.js:409:26)
|
||||||
|
at Object.Module._extensions..js (module.js:416:10)
|
||||||
|
at Module.load (module.js:343:32)
|
||||||
|
at Function.Module._load (module.js:300:12)
|
||||||
|
at Function.Module.runMain (module.js:441:10)
|
||||||
|
at startup (node.js:139:18)
|
||||||
|
*/
|
||||||
|
|
||||||
|
console.log(cleanStack(error.stack));
|
||||||
|
/*
|
||||||
|
Error: Missing unicorn
|
||||||
|
at Object.<anonymous> (/Users/sindresorhus/dev/clean-stack/unicorn.js:2:15)
|
||||||
|
*/
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
|
### cleanStack(stack, [options])
|
||||||
|
|
||||||
|
#### stack
|
||||||
|
|
||||||
|
Type: `string`
|
||||||
|
|
||||||
|
The `stack` property of an `Error`.
|
||||||
|
|
||||||
|
#### options
|
||||||
|
|
||||||
|
Type: `Object`
|
||||||
|
|
||||||
|
##### pretty
|
||||||
|
|
||||||
|
Type: `boolean`<br>
|
||||||
|
Default: `false`
|
||||||
|
|
||||||
|
Prettify the file paths in the stack:
|
||||||
|
|
||||||
|
`/Users/sindresorhus/dev/clean-stack/unicorn.js:2:15` → `~/dev/clean-stack/unicorn.js:2:15`
|
||||||
|
|
||||||
|
|
||||||
|
## Related
|
||||||
|
|
||||||
|
- [extrack-stack](https://github.com/sindresorhus/extract-stack) - Extract the actual stack of an error
|
||||||
|
- [stack-utils](https://github.com/tapjs/stack-utils) - Captures and cleans stack traces
|
||||||
|
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
MIT © [Sindre Sorhus](https://sindresorhus.com)
|
|
@ -0,0 +1,45 @@
|
||||||
|
/// <reference types="node"/>
|
||||||
|
|
||||||
|
/**
|
||||||
|
Show cursor.
|
||||||
|
|
||||||
|
@param stream - Default: `process.stderr`.
|
||||||
|
|
||||||
|
@example
|
||||||
|
```
|
||||||
|
import * as cliCursor from 'cli-cursor';
|
||||||
|
|
||||||
|
cliCursor.show();
|
||||||
|
```
|
||||||
|
*/
|
||||||
|
export function show(stream?: NodeJS.WritableStream): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Hide cursor.
|
||||||
|
|
||||||
|
@param stream - Default: `process.stderr`.
|
||||||
|
|
||||||
|
@example
|
||||||
|
```
|
||||||
|
import * as cliCursor from 'cli-cursor';
|
||||||
|
|
||||||
|
cliCursor.hide();
|
||||||
|
```
|
||||||
|
*/
|
||||||
|
export function hide(stream?: NodeJS.WritableStream): void;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Toggle cursor visibility.
|
||||||
|
|
||||||
|
@param force - Is useful to show or hide the cursor based on a boolean.
|
||||||
|
@param stream - Default: `process.stderr`.
|
||||||
|
|
||||||
|
@example
|
||||||
|
```
|
||||||
|
import * as cliCursor from 'cli-cursor';
|
||||||
|
|
||||||
|
const unicornsAreAwesome = true;
|
||||||
|
cliCursor.toggle(unicornsAreAwesome);
|
||||||
|
```
|
||||||
|
*/
|
||||||
|
export function toggle(force?: boolean, stream?: NodeJS.WritableStream): void;
|
|
@ -0,0 +1,35 @@
|
||||||
|
'use strict';
|
||||||
|
const restoreCursor = require('restore-cursor');
|
||||||
|
|
||||||
|
let isHidden = false;
|
||||||
|
|
||||||
|
exports.show = (writableStream = process.stderr) => {
|
||||||
|
if (!writableStream.isTTY) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
isHidden = false;
|
||||||
|
writableStream.write('\u001B[?25h');
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.hide = (writableStream = process.stderr) => {
|
||||||
|
if (!writableStream.isTTY) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
restoreCursor();
|
||||||
|
isHidden = true;
|
||||||
|
writableStream.write('\u001B[?25l');
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.toggle = (force, writableStream) => {
|
||||||
|
if (force !== undefined) {
|
||||||
|
isHidden = force;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isHidden) {
|
||||||
|
exports.show(writableStream);
|
||||||
|
} else {
|
||||||
|
exports.hide(writableStream);
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,9 @@
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@ -0,0 +1,79 @@
|
||||||
|
{
|
||||||
|
"_from": "cli-cursor@^3.1.0",
|
||||||
|
"_id": "cli-cursor@3.1.0",
|
||||||
|
"_inBundle": false,
|
||||||
|
"_integrity": "sha512-I/zHAwsKf9FqGoXM4WWRACob9+SNukZTd94DWF57E4toouRulbCxcUh6RKUEOQlYTHJnzkPMySvPNaaSLNfLZw==",
|
||||||
|
"_location": "/cli-cursor",
|
||||||
|
"_phantomChildren": {},
|
||||||
|
"_requested": {
|
||||||
|
"type": "range",
|
||||||
|
"registry": true,
|
||||||
|
"raw": "cli-cursor@^3.1.0",
|
||||||
|
"name": "cli-cursor",
|
||||||
|
"escapedName": "cli-cursor",
|
||||||
|
"rawSpec": "^3.1.0",
|
||||||
|
"saveSpec": null,
|
||||||
|
"fetchSpec": "^3.1.0"
|
||||||
|
},
|
||||||
|
"_requiredBy": [
|
||||||
|
"/inquirer",
|
||||||
|
"/ora"
|
||||||
|
],
|
||||||
|
"_resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-3.1.0.tgz",
|
||||||
|
"_shasum": "264305a7ae490d1d03bf0c9ba7c925d1753af307",
|
||||||
|
"_spec": "cli-cursor@^3.1.0",
|
||||||
|
"_where": "/Users/keiferju/code/Lingtu/smx-svelma/upload/node_modules/inquirer",
|
||||||
|
"author": {
|
||||||
|
"name": "Sindre Sorhus",
|
||||||
|
"email": "sindresorhus@gmail.com",
|
||||||
|
"url": "sindresorhus.com"
|
||||||
|
},
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/sindresorhus/cli-cursor/issues"
|
||||||
|
},
|
||||||
|
"bundleDependencies": false,
|
||||||
|
"dependencies": {
|
||||||
|
"restore-cursor": "^3.1.0"
|
||||||
|
},
|
||||||
|
"deprecated": false,
|
||||||
|
"description": "Toggle the CLI cursor",
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/node": "^12.0.7",
|
||||||
|
"ava": "^2.1.0",
|
||||||
|
"tsd": "^0.7.2",
|
||||||
|
"xo": "^0.24.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">=8"
|
||||||
|
},
|
||||||
|
"files": [
|
||||||
|
"index.js",
|
||||||
|
"index.d.ts"
|
||||||
|
],
|
||||||
|
"homepage": "https://github.com/sindresorhus/cli-cursor#readme",
|
||||||
|
"keywords": [
|
||||||
|
"cli",
|
||||||
|
"cursor",
|
||||||
|
"ansi",
|
||||||
|
"toggle",
|
||||||
|
"display",
|
||||||
|
"show",
|
||||||
|
"hide",
|
||||||
|
"term",
|
||||||
|
"terminal",
|
||||||
|
"console",
|
||||||
|
"tty",
|
||||||
|
"shell",
|
||||||
|
"command-line"
|
||||||
|
],
|
||||||
|
"license": "MIT",
|
||||||
|
"name": "cli-cursor",
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/sindresorhus/cli-cursor.git"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"test": "xo && ava && tsd"
|
||||||
|
},
|
||||||
|
"version": "3.1.0"
|
||||||
|
}
|
|
@ -0,0 +1,55 @@
|
||||||
|
# cli-cursor [](https://travis-ci.org/sindresorhus/cli-cursor)
|
||||||
|
|
||||||
|
> Toggle the CLI cursor
|
||||||
|
|
||||||
|
The cursor is [gracefully restored](https://github.com/sindresorhus/restore-cursor) if the process exits.
|
||||||
|
|
||||||
|
|
||||||
|
## Install
|
||||||
|
|
||||||
|
```
|
||||||
|
$ npm install cli-cursor
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```js
|
||||||
|
const cliCursor = require('cli-cursor');
|
||||||
|
|
||||||
|
cliCursor.hide();
|
||||||
|
|
||||||
|
const unicornsAreAwesome = true;
|
||||||
|
cliCursor.toggle(unicornsAreAwesome);
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## API
|
||||||
|
|
||||||
|
### .show(stream?)
|
||||||
|
|
||||||
|
### .hide(stream?)
|
||||||
|
|
||||||
|
### .toggle(force?, stream?)
|
||||||
|
|
||||||
|
#### force
|
||||||
|
|
||||||
|
Useful for showing or hiding the cursor based on a boolean.
|
||||||
|
|
||||||
|
#### stream
|
||||||
|
|
||||||
|
Type: `stream.Writable`<br>
|
||||||
|
Default: `process.stderr`
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
<div align="center">
|
||||||
|
<b>
|
||||||
|
<a href="https://tidelift.com/subscription/pkg/npm-cli-cursor?utm_source=npm-cli-cursor&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
|
||||||
|
</b>
|
||||||
|
<br>
|
||||||
|
<sub>
|
||||||
|
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
|
||||||
|
</sub>
|
||||||
|
</div>
|
|
@ -0,0 +1,108 @@
|
||||||
|
declare namespace cliSpinners {
|
||||||
|
type SpinnerName =
|
||||||
|
| 'dots'
|
||||||
|
| 'dots2'
|
||||||
|
| 'dots3'
|
||||||
|
| 'dots4'
|
||||||
|
| 'dots5'
|
||||||
|
| 'dots6'
|
||||||
|
| 'dots7'
|
||||||
|
| 'dots8'
|
||||||
|
| 'dots9'
|
||||||
|
| 'dots10'
|
||||||
|
| 'dots11'
|
||||||
|
| 'dots12'
|
||||||
|
| 'line'
|
||||||
|
| 'line2'
|
||||||
|
| 'pipe'
|
||||||
|
| 'simpleDots'
|
||||||
|
| 'simpleDotsScrolling'
|
||||||
|
| 'star'
|
||||||
|
| 'star2'
|
||||||
|
| 'flip'
|
||||||
|
| 'hamburger'
|
||||||
|
| 'growVertical'
|
||||||
|
| 'growHorizontal'
|
||||||
|
| 'balloon'
|
||||||
|
| 'balloon2'
|
||||||
|
| 'noise'
|
||||||
|
| 'bounce'
|
||||||
|
| 'boxBounce'
|
||||||
|
| 'boxBounce2'
|
||||||
|
| 'triangle'
|
||||||
|
| 'arc'
|
||||||
|
| 'circle'
|
||||||
|
| 'squareCorners'
|
||||||
|
| 'circleQuarters'
|
||||||
|
| 'circleHalves'
|
||||||
|
| 'squish'
|
||||||
|
| 'toggle'
|
||||||
|
| 'toggle2'
|
||||||
|
| 'toggle3'
|
||||||
|
| 'toggle4'
|
||||||
|
| 'toggle5'
|
||||||
|
| 'toggle6'
|
||||||
|
| 'toggle7'
|
||||||
|
| 'toggle8'
|
||||||
|
| 'toggle9'
|
||||||
|
| 'toggle10'
|
||||||
|
| 'toggle11'
|
||||||
|
| 'toggle12'
|
||||||
|
| 'toggle13'
|
||||||
|
| 'arrow'
|
||||||
|
| 'arrow2'
|
||||||
|
| 'arrow3'
|
||||||
|
| 'bouncingBar'
|
||||||
|
| 'bouncingBall'
|
||||||
|
| 'smiley'
|
||||||
|
| 'monkey'
|
||||||
|
| 'hearts'
|
||||||
|
| 'clock'
|
||||||
|
| 'earth'
|
||||||
|
| 'moon'
|
||||||
|
| 'runner'
|
||||||
|
| 'pong'
|
||||||
|
| 'shark'
|
||||||
|
| 'dqpb'
|
||||||
|
| 'weather'
|
||||||
|
| 'christmas'
|
||||||
|
| 'grenade'
|
||||||
|
| 'point'
|
||||||
|
| 'layer'
|
||||||
|
| 'betaWave';
|
||||||
|
|
||||||
|
interface Spinner {
|
||||||
|
/**
|
||||||
|
Recommended interval.
|
||||||
|
*/
|
||||||
|
readonly interval: number;
|
||||||
|
|
||||||
|
/**
|
||||||
|
A list of frames to show for the spinner.
|
||||||
|
*/
|
||||||
|
readonly frames: string[];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
60+ spinners for use in the terminal.
|
||||||
|
|
||||||
|
@example
|
||||||
|
```
|
||||||
|
import cliSpinners = require('cli-spinners');
|
||||||
|
|
||||||
|
console.log(cliSpinners.dots);
|
||||||
|
// {
|
||||||
|
// interval: 80,
|
||||||
|
// frames: ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']
|
||||||
|
// }
|
||||||
|
```
|
||||||
|
*/
|
||||||
|
declare const cliSpinners: {
|
||||||
|
readonly [spinnerName in cliSpinners.SpinnerName]: cliSpinners.Spinner;
|
||||||
|
} & {
|
||||||
|
// TODO: Remove this for the next major release
|
||||||
|
default: typeof cliSpinners;
|
||||||
|
};
|
||||||
|
|
||||||
|
export = cliSpinners;
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue