commit
d3fe2a6f4a
4966 changed files with 150259 additions and 0 deletions
@ -0,0 +1,61 @@ |
|||
#!/usr/bin/env node
|
|||
// https://github.com/tj/commander.js/blob/HEAD/Readme_zh-CN.md
|
|||
// https://www.npmjs.com/package/inquirer
|
|||
// https://www.npmjs.com/package/ora
|
|||
const git_util = require('./git_util.js'); |
|||
const program = require('commander'); |
|||
const inquirer = require('inquirer'); |
|||
const ora = require('ora'); |
|||
const exec = require('child_process').exec; |
|||
const fs = require('fs'); |
|||
const haveGit = fs.existsSync('./.git'); |
|||
/** |
|||
* 1. 检测是否有GIT管理 |
|||
* 2. 添加GIT源 |
|||
* 3. 设置默认源以供一键上传 |
|||
*/ |
|||
(async () => { |
|||
if (haveGit) { |
|||
exec('git remote', function (error, stdout, stderr) { |
|||
// 获取命令执行的输出
|
|||
if (error) { |
|||
throw error; |
|||
} |
|||
// 所有的源
|
|||
let origin = stdout.split('\n').slice(0, stdout.split('\n').length - 1); |
|||
console.log(origin); |
|||
inquirer.prompt([{ |
|||
type: 'confirm', // 问题类型,包括input,number,confirm,list,rawlist,password
|
|||
name: 'all', |
|||
message: '是否提交所有源', // 问题
|
|||
default: true // 默认值
|
|||
}]).then(async answers => { |
|||
if (answers.all) { |
|||
// 所有源提交
|
|||
for (let i = 0; i < origin.length; i++) { |
|||
const o = origin[i]; |
|||
await git_util.all('a', o, 'master'); |
|||
} |
|||
} else { |
|||
inquirer.prompt([{ |
|||
type: 'checkbox', // 问题类型,包括input,number,confirm,list,rawlist,password
|
|||
choices: origin, |
|||
name: 'choices', |
|||
message: '请选择一个源提交', // 问题
|
|||
default: true // 默认值
|
|||
}]).then(answers => { |
|||
console.log(answers.choices); |
|||
}) |
|||
} |
|||
}) |
|||
}); |
|||
} else { |
|||
exec('git init', function (error, stdout, stderr) { |
|||
// 获取命令执行的输出
|
|||
if (error) { |
|||
throw error; |
|||
} |
|||
console.log('git项目初始化成功'); |
|||
}); |
|||
} |
|||
})(); |
@ -0,0 +1,53 @@ |
|||
const exec = require('child_process').exec; |
|||
module.exports = { |
|||
all(msg, origin, banch) { |
|||
return new Promise((resolve, reject) => { |
|||
console.log('git add .'); |
|||
exec('git add .', function (error, stdout, stderr) { |
|||
if (error) { |
|||
reject(error); |
|||
throw error; |
|||
} |
|||
console.log("git commit -m '" + msg + "'"); |
|||
exec("git commit -m '" + msg + "'", function (error, stdout, stderr) { |
|||
if (error) { |
|||
reject(error); |
|||
throw error; |
|||
} |
|||
console.log("git push " + origin + " " + banch); |
|||
exec("git push " + origin + " " + banch, function (error, stdout, stderr) { |
|||
if (error) { |
|||
reject(error); |
|||
throw error; |
|||
} |
|||
resolve(); |
|||
}) |
|||
}) |
|||
}) |
|||
}) |
|||
}, |
|||
commit(msg, origin, banch) { |
|||
exec("git commit -m '" + msg + "'", function (error, stdout, stderr) { |
|||
if (error) { |
|||
reject(error); |
|||
throw error; |
|||
} |
|||
exec("git push " + origin + " " + banch, function (error, stdout, stderr) { |
|||
if (error) { |
|||
reject(error); |
|||
throw error; |
|||
} |
|||
resolve(); |
|||
}) |
|||
}) |
|||
}, |
|||
push(origin, banch) { |
|||
exec("git push " + origin + " " + banch, function (error, stdout, stderr) { |
|||
if (error) { |
|||
reject(error); |
|||
throw error; |
|||
} |
|||
resolve(); |
|||
}) |
|||
} |
|||
} |
@ -0,0 +1,202 @@ |
|||
/// <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; |
|||
} |
|||
} |
|||
|
|||
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; |
|||
}; |
|||
|
|||
// TODO: remove this in the next major version
|
|||
default: typeof ansiEscapes; |
|||
}; |
|||
|
|||
export = ansiEscapes; |
@ -0,0 +1,132 @@ |
|||
'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}` |
|||
}; |
@ -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,88 @@ |
|||
{ |
|||
"_from": "ansi-escapes@^4.2.1", |
|||
"_id": "ansi-escapes@4.2.1", |
|||
"_inBundle": false, |
|||
"_integrity": "sha512-Cg3ymMAdN10wOk/VYfLV7KCQyv7EDirJ64500sU7n9UlmioEtDuU5Gd+hj73hXSU/ex7tHJSssmyftDdkMLO8Q==", |
|||
"_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.2.1.tgz", |
|||
"_shasum": "4dccdb846c3eee10f6d64dea66273eab90c37228", |
|||
"_spec": "ansi-escapes@^4.2.1", |
|||
"_where": "E:\\mu_dist\\@xyx\\beer\\test-command\\node_modules\\inquirer", |
|||
"author": { |
|||
"name": "Sindre Sorhus", |
|||
"email": "sindresorhus@gmail.com", |
|||
"url": "sindresorhus.com" |
|||
}, |
|||
"bugs": { |
|||
"url": "https://github.com/sindresorhus/ansi-escapes/issues" |
|||
}, |
|||
"bundleDependencies": false, |
|||
"dependencies": { |
|||
"type-fest": "^0.5.2" |
|||
}, |
|||
"deprecated": false, |
|||
"description": "ANSI escape codes for manipulating the terminal", |
|||
"devDependencies": { |
|||
"@types/node": "^12.0.7", |
|||
"ava": "^2.1.0", |
|||
"tsd": "^0.7.1", |
|||
"xo": "^0.24.0" |
|||
}, |
|||
"engines": { |
|||
"node": ">=8" |
|||
}, |
|||
"files": [ |
|||
"index.js", |
|||
"index.d.ts" |
|||
], |
|||
"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.2.1" |
|||
} |
@ -0,0 +1,194 @@ |
|||
# 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`<br> |
|||
Default: `true` |
|||
|
|||
### iTerm.setCwd(path?) |
|||
|
|||
Type: `string`<br> |
|||
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). |
|||
|
|||
|
|||
## 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": [ |
|||
"/string-width/strip-ansi" |
|||
], |
|||
"_resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.0.tgz", |
|||
"_shasum": "388539f55179bf39339c81af30a654d69f87cb75", |
|||
"_spec": "ansi-regex@^5.0.0", |
|||
"_where": "E:\\mu_dist\\@xyx\\beer\\test-command\\node_modules\\string-width\\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,165 @@ |
|||
'use strict'; |
|||
const colorConvert = require('color-convert'); |
|||
|
|||
const wrapAnsi16 = (fn, offset) => function () { |
|||
const code = fn.apply(colorConvert, arguments); |
|||
return `\u001B[${code + offset}m`; |
|||
}; |
|||
|
|||
const wrapAnsi256 = (fn, offset) => function () { |
|||
const code = fn.apply(colorConvert, arguments); |
|||
return `\u001B[${38 + offset};5;${code}m`; |
|||
}; |
|||
|
|||
const wrapAnsi16m = (fn, offset) => function () { |
|||
const rgb = fn.apply(colorConvert, arguments); |
|||
return `\u001B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`; |
|||
}; |
|||
|
|||
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], |
|||
gray: [90, 39], |
|||
|
|||
// Bright color
|
|||
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] |
|||
} |
|||
}; |
|||
|
|||
// Fix humans
|
|||
styles.color.grey = styles.color.gray; |
|||
|
|||
for (const groupName of Object.keys(styles)) { |
|||
const group = styles[groupName]; |
|||
|
|||
for (const styleName of Object.keys(group)) { |
|||
const style = group[styleName]; |
|||
|
|||
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 |
|||
}); |
|||
} |
|||
|
|||
const ansi2ansi = n => n; |
|||
const rgb2rgb = (r, g, b) => [r, g, b]; |
|||
|
|||
styles.color.close = '\u001B[39m'; |
|||
styles.bgColor.close = '\u001B[49m'; |
|||
|
|||
styles.color.ansi = { |
|||
ansi: wrapAnsi16(ansi2ansi, 0) |
|||
}; |
|||
styles.color.ansi256 = { |
|||
ansi256: wrapAnsi256(ansi2ansi, 0) |
|||
}; |
|||
styles.color.ansi16m = { |
|||
rgb: wrapAnsi16m(rgb2rgb, 0) |
|||
}; |
|||
|
|||
styles.bgColor.ansi = { |
|||
ansi: wrapAnsi16(ansi2ansi, 10) |
|||
}; |
|||
styles.bgColor.ansi256 = { |
|||
ansi256: wrapAnsi256(ansi2ansi, 10) |
|||
}; |
|||
styles.bgColor.ansi16m = { |
|||
rgb: wrapAnsi16m(rgb2rgb, 10) |
|||
}; |
|||
|
|||
for (let key of Object.keys(colorConvert)) { |
|||
if (typeof colorConvert[key] !== 'object') { |
|||
continue; |
|||
} |
|||
|
|||
const suite = colorConvert[key]; |
|||
|
|||
if (key === 'ansi16') { |
|||
key = 'ansi'; |
|||
} |
|||
|
|||
if ('ansi16' in suite) { |
|||
styles.color.ansi[key] = wrapAnsi16(suite.ansi16, 0); |
|||
styles.bgColor.ansi[key] = wrapAnsi16(suite.ansi16, 10); |
|||
} |
|||
|
|||
if ('ansi256' in suite) { |
|||
styles.color.ansi256[key] = wrapAnsi256(suite.ansi256, 0); |
|||
styles.bgColor.ansi256[key] = wrapAnsi256(suite.ansi256, 10); |
|||
} |
|||
|
|||
if ('rgb' in suite) { |
|||
styles.color.ansi16m[key] = wrapAnsi16m(suite.rgb, 0); |
|||
styles.bgColor.ansi16m[key] = wrapAnsi16m(suite.rgb, 10); |
|||
} |
|||
} |
|||
|
|||
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,88 @@ |
|||
{ |
|||
"_from": "ansi-styles@^3.2.1", |
|||
"_id": "ansi-styles@3.2.1", |
|||
"_inBundle": false, |
|||
"_integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", |
|||
"_location": "/ansi-styles", |
|||
"_phantomChildren": {}, |
|||
"_requested": { |
|||
"type": "range", |
|||
"registry": true, |
|||
"raw": "ansi-styles@^3.2.1", |
|||
"name": "ansi-styles", |
|||
"escapedName": "ansi-styles", |
|||
"rawSpec": "^3.2.1", |
|||
"saveSpec": null, |
|||
"fetchSpec": "^3.2.1" |
|||
}, |
|||
"_requiredBy": [ |
|||
"/chalk" |
|||
], |
|||
"_resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", |
|||
"_shasum": "41fbb20243e50b12be0f04b8dedbf07520ce841d", |
|||
"_spec": "ansi-styles@^3.2.1", |
|||
"_where": "E:\\mu_dist\\@xyx\\beer\\test-command\\node_modules\\chalk", |
|||
"author": { |
|||
"name": "Sindre Sorhus", |
|||
"email": "sindresorhus@gmail.com", |
|||
"url": "sindresorhus.com" |
|||
}, |
|||
"ava": { |
|||
"require": "babel-polyfill" |
|||
}, |
|||
"bugs": { |
|||
"url": "https://github.com/chalk/ansi-styles/issues" |
|||
}, |
|||
"bundleDependencies": false, |
|||
"dependencies": { |
|||
"color-convert": "^1.9.0" |
|||
}, |
|||
"deprecated": false, |
|||
"description": "ANSI escape codes for styling strings in the terminal", |
|||
"devDependencies": { |
|||
"ava": "*", |
|||
"babel-polyfill": "^6.23.0", |
|||
"svg-term-cli": "^2.1.1", |
|||
"xo": "*" |
|||
}, |
|||
"engines": { |
|||
"node": ">=4" |
|||
}, |
|||
"files": [ |
|||
"index.js" |
|||
], |
|||
"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" |
|||
}, |
|||
"version": "3.2.1" |
|||
} |
@ -0,0 +1,147 @@ |
|||
# ansi-styles [](https://travis-ci.org/chalk/ansi-styles) |
|||
|
|||
> [ANSI escape codes](http://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="https://cdn.rawgit.com/chalk/ansi-styles/8261697c95bf34b6c7767e2cbe9941a851d59385/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` |
|||
- `gray` ("bright black") |
|||
- `redBright` |
|||
- `greenBright` |
|||
- `yellowBright` |
|||
- `blueBright` |
|||
- `magentaBright` |
|||
- `cyanBright` |
|||
- `whiteBright` |
|||
|
|||
### Background colors |
|||
|
|||
- `bgBlack` |
|||
- `bgRed` |
|||
- `bgGreen` |
|||
- `bgYellow` |
|||
- `bgBlue` |
|||
- `bgMagenta` |
|||
- `bgCyan` |
|||
- `bgWhite` |
|||
- `bgBlackBright` |
|||
- `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. |
|||
|
|||
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-) |
|||
|
|||
|
|||
## License |
|||
|
|||
MIT |
@ -0,0 +1,228 @@ |
|||
'use strict'; |
|||
const escapeStringRegexp = require('escape-string-regexp'); |
|||
const ansiStyles = require('ansi-styles'); |
|||
const stdoutColor = require('supports-color').stdout; |
|||
|
|||
const template = require('./templates.js'); |
|||
|
|||
const isSimpleWindowsTerm = process.platform === 'win32' && !(process.env.TERM || '').toLowerCase().startsWith('xterm'); |
|||
|
|||
// `supportsColor.level` → `ansiStyles.color[name]` mapping
|
|||
const levelMapping = ['ansi', 'ansi', 'ansi256', 'ansi16m']; |
|||
|
|||
// `color-convert` models to exclude from the Chalk API due to conflicts and such
|
|||
const skipModels = new Set(['gray']); |
|||
|
|||
const styles = Object.create(null); |
|||
|
|||
function applyOptions(obj, options) { |
|||
options = options || {}; |
|||
|
|||
// Detect level if not set manually
|
|||
const scLevel = stdoutColor ? stdoutColor.level : 0; |
|||
obj.level = options.level === undefined ? scLevel : options.level; |
|||
obj.enabled = 'enabled' in options ? options.enabled : obj.level > 0; |
|||
} |
|||
|
|||
function Chalk(options) { |
|||
// We check for this.template here since calling `chalk.constructor()`
|
|||
// by itself will have a `this` of a previously constructed chalk object
|
|||
if (!this || !(this instanceof Chalk) || this.template) { |
|||
const chalk = {}; |
|||
applyOptions(chalk, options); |
|||
|
|||
chalk.template = function () { |
|||
const args = [].slice.call(arguments); |
|||
return chalkTag.apply(null, [chalk.template].concat(args)); |
|||
}; |
|||
|
|||
Object.setPrototypeOf(chalk, Chalk.prototype); |
|||
Object.setPrototypeOf(chalk.template, chalk); |
|||
|
|||
chalk.template.constructor = Chalk; |
|||
|
|||
return chalk.template; |
|||
} |
|||
|
|||
applyOptions(this, options); |
|||
} |
|||
|
|||
// Use bright blue on Windows as the normal blue color is illegible
|
|||
if (isSimpleWindowsTerm) { |
|||
ansiStyles.blue.open = '\u001B[94m'; |
|||
} |
|||
|
|||
for (const key of Object.keys(ansiStyles)) { |
|||
ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g'); |
|||
|
|||
styles[key] = { |
|||
get() { |
|||
const codes = ansiStyles[key]; |
|||
return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, key); |
|||
} |
|||
}; |
|||
} |
|||
|
|||
styles.visible = { |
|||
get() { |
|||
return build.call(this, this._styles || [], true, 'visible'); |
|||
} |
|||
}; |
|||
|
|||
ansiStyles.color.closeRe = new RegExp(escapeStringRegexp(ansiStyles.color.close), 'g'); |
|||
for (const model of Object.keys(ansiStyles.color.ansi)) { |
|||
if (skipModels.has(model)) { |
|||
continue; |
|||
} |
|||
|
|||
styles[model] = { |
|||
get() { |
|||
const level = this.level; |
|||
return function () { |
|||
const open = ansiStyles.color[levelMapping[level]][model].apply(null, arguments); |
|||
const codes = { |
|||
open, |
|||
close: ansiStyles.color.close, |
|||
closeRe: ansiStyles.color.closeRe |
|||
}; |
|||
return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model); |
|||
}; |
|||
} |
|||
}; |
|||
} |
|||
|
|||
ansiStyles.bgColor.closeRe = new RegExp(escapeStringRegexp(ansiStyles.bgColor.close), 'g'); |
|||
for (const model of Object.keys(ansiStyles.bgColor.ansi)) { |
|||
if (skipModels.has(model)) { |
|||
continue; |
|||
} |
|||
|
|||
const bgModel = 'bg' + model[0].toUpperCase() + model.slice(1); |
|||
styles[bgModel] = { |
|||
get() { |
|||
const level = this.level; |
|||
return function () { |
|||
const open = ansiStyles.bgColor[levelMapping[level]][model].apply(null, arguments); |
|||
const codes = { |
|||
open, |
|||
close: ansiStyles.bgColor.close, |
|||
closeRe: ansiStyles.bgColor.closeRe |
|||
}; |
|||
return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model); |
|||
}; |
|||
} |
|||
}; |
|||
} |
|||
|
|||
const proto = Object.defineProperties(() => {}, styles); |
|||
|
|||
function build(_styles, _empty, key) { |
|||
const builder = function () { |
|||
return applyStyle.apply(builder, arguments); |
|||
}; |
|||
|
|||
builder._styles = _styles; |
|||
builder._empty = _empty; |
|||
|
|||
const self = this; |
|||
|
|||
Object.defineProperty(builder, 'level', { |
|||
enumerable: true, |
|||
get() { |
|||
return self.level; |
|||
}, |
|||
set(level) { |
|||
self.level = level; |
|||
} |
|||
}); |
|||
|
|||
Object.defineProperty(builder, 'enabled', { |
|||
enumerable: true, |
|||
get() { |
|||
return self.enabled; |
|||
}, |
|||
set(enabled) { |
|||
self.enabled = enabled; |
|||
} |
|||
}); |
|||
|
|||
// See below for fix regarding invisible grey/dim combination on Windows
|
|||
builder.hasGrey = this.hasGrey || key === 'gray' || key === 'grey'; |
|||
|
|||
// `__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
|
|||
|
|||
return builder; |
|||
} |
|||
|
|||
function applyStyle() { |
|||
// Support varags, but simply cast to string in case there's only one arg
|
|||
const args = arguments; |
|||
const argsLen = args.length; |
|||
let str = String(arguments[0]); |
|||
|
|||
if (argsLen === 0) { |
|||
return ''; |
|||
} |
|||
|
|||
if (argsLen > 1) { |
|||
// Don't slice `arguments`, it prevents V8 optimizations
|
|||
for (let a = 1; a < argsLen; a++) { |
|||
str += ' ' + args[a]; |
|||
} |
|||
} |
|||
|
|||
if (!this.enabled || this.level <= 0 || !str) { |
|||
return this._empty ? '' : str; |
|||
} |
|||
|
|||
// Turns out that on Windows dimmed gray text becomes invisible in cmd.exe,
|
|||
// see https://github.com/chalk/chalk/issues/58
|
|||
// If we're on Windows and we're dealing with a gray color, temporarily make 'dim' a noop.
|
|||
const originalDim = ansiStyles.dim.open; |
|||
if (isSimpleWindowsTerm && this.hasGrey) { |
|||
ansiStyles.dim.open = ''; |
|||
} |
|||
|
|||
for (const code of this._styles.slice().reverse()) { |
|||
// 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'.
|
|||
str = code.open + str.replace(code.closeRe, code.open) + code.close; |
|||
|
|||
// 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
|
|||
str = str.replace(/\r?\n/g, `${code.close}$&${code.open}`); |
|||
} |
|||
|
|||
// Reset the original `dim` if we changed it to work around the Windows dimmed gray issue
|
|||
ansiStyles.dim.open = originalDim; |
|||
|
|||
return str; |
|||
} |
|||
|
|||
function chalkTag(chalk, strings) { |
|||
if (!Array.isArray(strings)) { |
|||
// If chalk() was called by itself or with a string,
|
|||
// return the string itself as a string.
|
|||
return [].slice.call(arguments, 1).join(' '); |
|||
} |
|||
|
|||
const args = [].slice.call(arguments, 2); |
|||
const parts = [strings.raw[0]]; |
|||
|
|||
for (let i = 1; i < strings.length; i++) { |
|||
parts.push(String(args[i - 1]).replace(/[{}\\]/g, '\\$&')); |
|||
parts.push(String(strings.raw[i])); |
|||
} |
|||
|
|||
return template(chalk, parts.join('')); |
|||
} |
|||
|
|||
Object.defineProperties(Chalk.prototype, styles); |
|||
|
|||
module.exports = Chalk(); // eslint-disable-line new-cap
|
|||
module.exports.supportsColor = stdoutColor; |
|||
module.exports.default = module.exports; // For TypeScript
|
@ -0,0 +1,93 @@ |
|||
// @flow strict |
|||
|
|||
type TemplateStringsArray = $ReadOnlyArray<string>; |
|||
|
|||
export type Level = $Values<{ |
|||
None: 0, |
|||
Basic: 1, |
|||
Ansi256: 2, |
|||
TrueColor: 3 |
|||
}>; |
|||
|
|||
export type ChalkOptions = {| |
|||
enabled?: boolean, |
|||
level?: Level |
|||
|}; |
|||
|
|||
export type ColorSupport = {| |
|||
level: Level, |
|||
hasBasic: boolean, |
|||
has256: boolean, |
|||
has16m: boolean |
|||
|}; |
|||
|
|||
export interface Chalk { |
|||
(...text: string[]): string, |
|||
(text: TemplateStringsArray, ...placeholders: string[]): string, |
|||
constructor(options?: ChalkOptions): Chalk, |
|||
enabled: boolean, |
|||
level: Level, |
|||
rgb(r: number, g: number, b: number): Chalk, |
|||
hsl(h: number, s: number, l: number): Chalk, |
|||
hsv(h: number, s: number, v: number): Chalk, |
|||
hwb(h: number, w: number, b: number): Chalk, |
|||
bgHex(color: string): Chalk, |
|||
bgKeyword(color: string): Chalk, |
|||
bgRgb(r: number, g: number, b: number): Chalk, |
|||
bgHsl(h: number, s: number, l: number): Chalk, |
|||
bgHsv(h: number, s: number, v: number): Chalk, |
|||
bgHwb(h: number, w: number, b: number): Chalk, |
|||
hex(color: string): Chalk, |
|||
keyword(color: string): Chalk, |
|||
|
|||
+reset: Chalk, |
|||
+bold: Chalk, |
|||
+dim: Chalk, |
|||
+italic: Chalk, |
|||
+underline: Chalk, |
|||
+inverse: Chalk, |
|||
+hidden: Chalk, |
|||
+strikethrough: Chalk, |
|||
|
|||
+visible: Chalk, |
|||
|
|||
+black: Chalk, |
|||
+red: Chalk, |
|||
+green: Chalk, |
|||
+yellow: Chalk, |
|||
+blue: Chalk, |
|||
+magenta: Chalk, |
|||
+cyan: Chalk, |
|||
+white: Chalk, |
|||
+gray: Chalk, |
|||
+grey: Chalk, |
|||
+blackBright: Chalk, |
|||
+redBright: Chalk, |
|||
+greenBright: Chalk, |
|||
+yellowBright: Chalk, |
|||
+blueBright: Chalk, |
|||
+magentaBright: Chalk, |
|||
+cyanBright: Chalk, |
|||
+whiteBright: Chalk, |
|||
|
|||
+bgBlack: Chalk, |
|||
+bgRed: Chalk, |
|||
+bgGreen: Chalk, |
|||
+bgYellow: Chalk, |
|||
+bgBlue: Chalk, |
|||
+bgMagenta: Chalk, |
|||
+bgCyan: Chalk, |
|||
+bgWhite: Chalk, |
|||
+bgBlackBright: Chalk, |
|||
+bgRedBright: Chalk, |
|||
+bgGreenBright: Chalk, |
|||
+bgYellowBright: Chalk, |
|||
+bgBlueBright: Chalk, |
|||
+bgMagentaBright: Chalk, |
|||
+bgCyanBright: Chalk, |
|||
+bgWhiteBrigh: Chalk, |
|||
|
|||
supportsColor: ColorSupport |
|||
}; |
|||
|
|||
declare module.exports: 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,103 @@ |
|||
{ |
|||
"_from": "chalk@^2.4.2", |
|||
"_id": "chalk@2.4.2", |
|||
"_inBundle": false, |
|||
"_integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==", |
|||
"_location": "/chalk", |
|||
"_phantomChildren": {}, |
|||
"_requested": { |
|||
"type": "range", |
|||
"registry": true, |
|||
"raw": "chalk@^2.4.2", |
|||
"name": "chalk", |
|||
"escapedName": "chalk", |
|||
"rawSpec": "^2.4.2", |
|||
"saveSpec": null, |
|||
"fetchSpec": "^2.4.2" |
|||
}, |
|||
"_requiredBy": [ |
|||
"/inquirer" |
|||
], |
|||
"_resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz", |
|||
"_shasum": "cd42541677a54333cf541a49108c1432b44c9424", |
|||
"_spec": "chalk@^2.4.2", |
|||
"_where": "E:\\mu_dist\\@xyx\\beer\\test-command\\node_modules\\inquirer", |
|||
"bugs": { |
|||
"url": "https://github.com/chalk/chalk/issues" |
|||
}, |
|||
"bundleDependencies": false, |
|||
"dependencies": { |
|||
"ansi-styles": "^3.2.1", |
|||
"escape-string-regexp": "^1.0.5", |
|||
"supports-color": "^5.3.0" |
|||
}, |
|||
"deprecated": false, |
|||
"description": "Terminal string styling done right", |
|||
"devDependencies": { |
|||
"ava": "*", |
|||
"coveralls": "^3.0.0", |
|||
"execa": "^0.9.0", |
|||
"flow-bin": "^0.68.0", |
|||
"import-fresh": "^2.0.0", |
|||
"matcha": "^0.7.0", |
|||
"nyc": "^11.0.2", |
|||
"resolve-from": "^4.0.0", |
|||
"typescript": "^2.5.3", |
|||
"xo": "*" |
|||
}, |
|||
"engines": { |
|||
"node": ">=4" |
|||
}, |
|||
"files": [ |
|||
"index.js", |
|||
"templates.js", |
|||
"types/index.d.ts", |
|||
"index.js.flow" |
|||
], |
|||
"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", |
|||
"name": "chalk", |
|||
"repository": { |
|||
"type": "git", |
|||
"url": "git+https://github.com/chalk/chalk.git" |
|||
}, |
|||
"scripts": { |
|||
"bench": "matcha benchmark.js", |
|||
"coveralls": "nyc report --reporter=text-lcov | coveralls", |
|||
"test": "xo && tsc --project types && flow --max-warnings=0 && nyc ava" |
|||
}, |
|||
"types": "types/index.d.ts", |
|||
"version": "2.4.2", |
|||
"xo": { |
|||
"envs": [ |
|||
"node", |
|||
"mocha" |
|||
], |
|||
"ignores": [ |
|||
"test/_flow.js" |
|||
] |
|||
} |
|||
} |
@ -0,0 +1,314 @@ |
|||
<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.youtube.com/watch?v=9auOCbH5Ns4) [](https://github.com/xojs/xo) [](https://github.com/sindresorhus/awesome-nodejs) |
|||
|
|||
### [See what's new in Chalk 2](https://github.com/chalk/chalk/releases/tag/v2.0.0) |
|||
|
|||
<img src="https://cdn.rawgit.com/chalk/ansi-styles/8261697c95bf34b6c7767e2cbe9941a851d59385/screenshot.svg" alt="" 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 ~23,000 packages](https://www.npmjs.com/browse/depended/chalk) as of December 31, 2017 |
|||
|
|||
|
|||
## Install |
|||
|
|||
```console |
|||
$ npm install chalk |
|||
``` |
|||
|
|||
<a href="https://www.patreon.com/sindresorhus"> |
|||
<img src="https://c5.patreon.com/external/logo/become_a_patron_button@2x.png" width="160"> |
|||
</a> |
|||
|
|||
|
|||
## 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.enabled |
|||
|
|||
Color support is automatically detected, as is the level (see `chalk.level`). However, if you'd like to simply enable/disable Chalk, you can do so via the `.enabled` property. |
|||
|
|||
Chalk is enabled by default unless explicitly disabled via the constructor or `chalk.level` is `0`. |
|||
|
|||
If you need to change this in a reusable module, create a new instance: |
|||
|
|||
```js |
|||
const ctx = new chalk.constructor({enabled: false}); |
|||
``` |
|||
|
|||
### chalk.level |
|||
|
|||
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.constructor({level: 0}); |
|||
``` |
|||
|
|||
Levels are as follows: |
|||
|
|||
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, add the environment variable `FORCE_COLOR=1` 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. |
|||
|
|||
|
|||
## Styles |
|||
|
|||
### Modifiers |
|||
|
|||
- `reset` |
|||
- `bold` |
|||
- `dim` |
|||
- `italic` *(Not widely supported)* |
|||
- `underline` |
|||
- `inverse` |
|||
- `hidden` |
|||
- `strikethrough` *(Not widely supported)* |
|||
- `visible` (Text is emitted only if enabled) |
|||
|
|||
### Colors |
|||
|
|||
- `black` |
|||
- `red` |
|||
- `green` |
|||
- `yellow` |
|||
- `blue` *(On Windows the bright version is used since normal blue is illegible)* |
|||
- `magenta` |
|||
- `cyan` |
|||
- `white` |
|||
- `gray` ("bright black") |
|||
- `redBright` |
|||
- `greenBright` |
|||
- `yellowBright` |
|||
- `blueBright` |
|||
- `magentaBright` |
|||
- `cyanBright` |
|||
- `whiteBright` |
|||
|
|||
### Background colors |
|||
|
|||
- `bgBlack` |
|||
- `bgRed` |
|||
- `bgGreen` |
|||
- `bgYellow` |
|||
- `bgBlue` |
|||
- `bgMagenta` |
|||
- `bgCyan` |
|||
- `bgWhite` |
|||
- `bgBlackBright` |
|||
- `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!')` |
|||
- `ansi16` |
|||
- `ansi256` |
|||
|
|||
|
|||
## Windows |
|||
|
|||
If you're on Windows, do yourself a favor and use [`cmder`](http://cmder.net/) 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. |
|||
|
|||
|
|||
## 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-) |
|||
|
|||
|
|||
## License |
|||
|
|||
MIT |
@ -0,0 +1,128 @@ |
|||
'use strict'; |
|||
const TEMPLATE_REGEX = /(?:\\(u[a-f\d]{4}|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}|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) { |
|||
if ((c[0] === 'u' && c.length === 5) || (c[0] === 'x' && c.length === 3)) { |
|||
return String.fromCharCode(parseInt(c.slice(1), 16)); |
|||
} |
|||
|
|||
return ESCAPES.get(c) || c; |
|||
} |
|||
|
|||
function parseArguments(name, args) { |
|||
const results = []; |
|||
const chunks = args.trim().split(/\s*,\s*/g); |
|||
let matches; |
|||
|
|||
for (const chunk of chunks) { |
|||
if (!isNaN(chunk)) { |
|||
results.push(Number(chunk)); |
|||
} else if ((matches = chunk.match(STRING_REGEX))) { |
|||
results.push(matches[2].replace(ESCAPE_REGEX, (m, escape, chr) => escape ? unescape(escape) : chr)); |
|||
} 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 of Object.keys(enabled)) { |
|||
if (Array.isArray(enabled[styleName])) { |
|||
if (!(styleName in current)) { |
|||
throw new Error(`Unknown Chalk style: ${styleName}`); |
|||
} |
|||
|
|||
if (enabled[styleName].length > 0) { |
|||
current = current[styleName].apply(current, enabled[styleName]); |
|||
} else { |
|||
current = current[styleName]; |
|||
} |
|||
} |
|||
} |
|||
|
|||
return current; |
|||
} |
|||
|
|||
module.exports = (chalk, tmp) => { |
|||
const styles = []; |
|||
const chunks = []; |
|||
let chunk = []; |
|||
|
|||
// eslint-disable-next-line max-params
|
|||
tmp.replace(TEMPLATE_REGEX, (m, escapeChar, inverse, style, close, chr) => { |
|||
if (escapeChar) { |
|||
chunk.push(unescape(escapeChar)); |
|||
} else if (style) { |
|||
const str = chunk.join(''); |
|||
chunk = []; |
|||
chunks.push(styles.length === 0 ? str : buildStyle(chalk, styles)(str)); |
|||
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(chr); |
|||
} |
|||
}); |
|||
|
|||
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,97 @@ |
|||
// Type definitions for Chalk
|
|||
// Definitions by: Thomas Sauer <https://github.com/t-sauer>
|
|||
|
|||
export const enum Level { |
|||
None = 0, |
|||
Basic = 1, |
|||
Ansi256 = 2, |
|||
TrueColor = 3 |
|||
} |
|||
|
|||
export interface ChalkOptions { |
|||
enabled?: boolean; |
|||
level?: Level; |
|||
} |
|||
|
|||
export interface ChalkConstructor { |
|||
new (options?: ChalkOptions): Chalk; |
|||
(options?: ChalkOptions): Chalk; |
|||
} |
|||
|
|||
export interface ColorSupport { |
|||
level: Level; |
|||
hasBasic: boolean; |
|||
has256: boolean; |
|||
has16m: boolean; |
|||
} |
|||
|
|||
export interface Chalk { |
|||
(...text: string[]): string; |
|||
(text: TemplateStringsArray, ...placeholders: string[]): string; |
|||
constructor: ChalkConstructor; |
|||
enabled: boolean; |
|||
level: Level; |
|||
rgb(r: number, g: number, b: number): this; |
|||
hsl(h: number, s: number, l: number): this; |
|||
hsv(h: number, s: number, v: number): this; |
|||
hwb(h: number, w: number, b: number): this; |
|||
bgHex(color: string): this; |
|||
bgKeyword(color: string): this; |
|||
bgRgb(r: number, g: number, b: number): this; |
|||
bgHsl(h: number, s: number, l: number): this; |
|||
bgHsv(h: number, s: number, v: number): this; |
|||
bgHwb(h: number, w: number, b: number): this; |
|||
hex(color: string): this; |
|||
keyword(color: string): this; |
|||
|
|||
readonly reset: this; |
|||
readonly bold: this; |
|||
readonly dim: this; |
|||
readonly italic: this; |
|||
readonly underline: this; |
|||
readonly inverse: this; |
|||
readonly hidden: this; |
|||
readonly strikethrough: this; |
|||
|
|||
readonly visible: this; |
|||
|
|||
readonly black: this; |
|||
readonly red: this; |
|||
readonly green: this; |
|||
readonly yellow: this; |
|||
readonly blue: this; |
|||
readonly magenta: this; |
|||
readonly cyan: this; |
|||
readonly white: this; |
|||
readonly gray: this; |
|||
readonly grey: this; |
|||
readonly blackBright: this; |
|||
readonly redBright: this; |
|||
readonly greenBright: this; |
|||
readonly yellowBright: this; |
|||
readonly blueBright: this; |
|||
readonly magentaBright: this; |
|||
readonly cyanBright: this; |
|||
readonly whiteBright: this; |
|||
|
|||
readonly bgBlack: this; |
|||
readonly bgRed: this; |
|||
readonly bgGreen: this; |
|||
readonly bgYellow: this; |
|||
readonly bgBlue: this; |
|||
readonly bgMagenta: this; |
|||
readonly bgCyan: this; |
|||
readonly bgWhite: this; |
|||
readonly bgBlackBright: this; |
|||
readonly bgRedBright: this; |
|||
readonly bgGreenBright: this; |
|||
readonly bgYellowBright: this; |
|||
readonly bgBlueBright: this; |
|||
readonly bgMagentaBright: this; |
|||
readonly bgCyanBright: this; |
|||
readonly bgWhiteBright: this; |
|||
} |
|||
|
|||
declare const chalk: Chalk & { supportsColor: ColorSupport }; |
|||
|
|||
export default chalk |
@ -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": "E:\\mu_dist\\@xyx\\beer\\test-command\\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,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,78 @@ |
|||
{ |
|||
"_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" |
|||
], |
|||
"_resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-3.1.0.tgz", |
|||
"_shasum": "264305a7ae490d1d03bf0c9ba7c925d1753af307", |
|||
"_spec": "cli-cursor@^3.1.0", |
|||
"_where": "E:\\mu_dist\\@xyx\\beer\\test-command\\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; |
@ -0,0 +1,7 @@ |
|||
'use strict'; |
|||
|
|||
const spinners = Object.assign({}, require('./spinners.json')); |
|||
|
|||
module.exports = spinners; |
|||
// TODO: Remove this for the next major release
|
|||
module.exports.default = spinners; |
@ -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-spinners@^2.2.0", |
|||
"_id": "cli-spinners@2.2.0", |
|||
"_inBundle": false, |
|||
"_integrity": "sha512-tgU3fKwzYjiLEQgPMD9Jt+JjHVL9kW93FiIMX/l7rivvOD4/LL0Mf7gda3+4U2KJBloybwgj5KEoQgGRioMiKQ==", |
|||
"_location": "/cli-spinners", |
|||
"_phantomChildren": {}, |
|||
"_requested": { |
|||
"type": "range", |
|||
"registry": true, |
|||
"raw": "cli-spinners@^2.2.0", |
|||
"name": "cli-spinners", |
|||
"escapedName": "cli-spinners", |
|||
"rawSpec": "^2.2.0", |
|||
"saveSpec": null, |
|||
"fetchSpec": "^2.2.0" |
|||
}, |
|||
"_requiredBy": [ |
|||
"/ora" |
|||
], |
|||
"_resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.2.0.tgz", |
|||
"_shasum": "e8b988d9206c692302d8ee834e7a85c0144d8f77", |
|||
"_spec": "cli-spinners@^2.2.0", |
|||
"_where": "E:\\mu_dist\\@xyx\\beer\\test-command\\node_modules\\ora", |
|||
"author": { |
|||
"name": "Sindre Sorhus", |
|||
"email": "sindresorhus@gmail.com", |
|||
"url": "sindresorhus.com" |
|||
}, |
|||
"bugs": { |
|||
"url": "https://github.com/sindresorhus/cli-spinners/issues" |
|||
}, |
|||
"bundleDependencies": false, |
|||
"deprecated": false, |
|||
"description": "Spinners for use in the terminal", |
|||
"devDependencies": { |
|||
"ava": "^1.4.1", |
|||
"log-update": "^3.2.0", |
|||
"tsd": "^0.7.2", |
|||
"xo": "^0.24.0" |
|||
}, |
|||
"engines": { |
|||
"node": ">=6" |
|||
}, |
|||
"files": [ |
|||
"index.js", |
|||
"index.d.ts", |
|||
"spinners.json" |
|||
], |
|||
"homepage": "https://github.com/sindresorhus/cli-spinners#readme", |
|||
"keywords": [ |
|||
"cli", |
|||
"spinner", |
|||
"spinners", |
|||
"terminal", |
|||
"term", |
|||
"console", |
|||
"ascii", |
|||
"unicode", |
|||
"loading", |
|||
"indicator", |
|||
"progress", |
|||
"busy", |
|||
"wait", |
|||
"idle", |
|||
"json" |
|||
], |
|||
"license": "MIT", |
|||
"name": "cli-spinners", |
|||
"repository": { |
|||
"type": "git", |
|||
"url": "git+https://github.com/sindresorhus/cli-spinners.git" |
|||
}, |
|||
"scripts": { |
|||
"asciicast": "asciinema rec --command='node example-all.js' --title='cli-spinner' --quiet", |
|||
"test": "xo && ava && tsd" |
|||
}, |
|||
"version": "2.2.0" |
|||
} |
@ -0,0 +1,61 @@ |
|||
# cli-spinners [](https://travis-ci.org/sindresorhus/cli-spinners) |
|||
|
|||
> 60+ spinners for use in the terminal |
|||
|
|||
<p align="center"> |
|||
<br> |
|||
<img width="700" src="screenshot.svg"> |
|||
<br> |
|||
<br> |
|||
</p> |
|||
|
|||
The list of spinners is just a [JSON file](spinners.json) and can be used wherever. |
|||
|
|||
You probably want to use one of these spinners through the [`ora`](https://github.com/sindresorhus/ora) module. |
|||
|
|||
|
|||
## Install |
|||
|
|||
``` |
|||
$ npm install cli-spinners |
|||
``` |
|||
|
|||
|
|||
## Usage |
|||
|
|||
```js |
|||
const cliSpinners = require('cli-spinners'); |
|||
|
|||
console.log(cliSpinners.dots); |
|||
/* |
|||
{ |
|||
interval: 80, |
|||
frames: ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'] |
|||
} |
|||
*/ |
|||
``` |
|||
|
|||
|
|||
## Preview |
|||
|
|||
The header GIF is outdated. See all the [spinner at once](http://jsfiddle.net/sindresorhus/2eLtsbey/embedded/result/) or [one at the time](https://asciinema.org/a/95348?size=big). |
|||
|
|||
|
|||
## API |
|||
|
|||
Each spinner comes with a recommended `interval` and an array of `frames`. |
|||
|
|||
[See the spinners.](spinners.json) |
|||
|
|||
|
|||
## Related |
|||
|
|||
- [ora](https://github.com/sindresorhus/ora) - Elegant terminal spinner |
|||
- [CLISpinner](https://github.com/kiliankoe/CLISpinner) - Terminal spinners for Swift |
|||
- [py-spinners](https://github.com/ManrajGrover/py-spinners) - Python port |
|||
- [spinners](https://github.com/FGRibreau/spinners) - Terminal spinners for Rust |
|||
|
|||
|
|||
## License |
|||
|
|||
MIT © [Sindre Sorhus](https://sindresorhus.com) |
@ -0,0 +1,924 @@ |
|||
{ |
|||
"dots": { |
|||
"interval": 80, |
|||
"frames": [ |
|||
"⠋", |
|||
"⠙", |
|||
"⠹", |
|||
"⠸", |
|||
"⠼", |
|||
"⠴", |
|||
"⠦", |
|||
"⠧", |
|||
"⠇", |
|||
"⠏" |
|||
] |
|||
}, |
|||
"dots2": { |
|||
"interval": 80, |
|||
"frames": [ |
|||
"⣾", |
|||
"⣽", |
|||
"⣻", |
|||
"⢿", |
|||
"⡿", |
|||
"⣟", |
|||
"⣯", |
|||
"⣷" |
|||
] |
|||
}, |
|||
"dots3": { |
|||
"interval": 80, |
|||
"frames": [ |
|||
"⠋", |
|||
"⠙", |
|||
"⠚", |
|||
"⠞", |
|||
"⠖", |
|||
"⠦", |
|||
"⠴", |
|||
"⠲", |
|||
"⠳", |
|||
"⠓" |
|||
] |
|||
}, |
|||
"dots4": { |
|||
"interval": 80, |
|||
"frames": [ |
|||
"⠄", |
|||
"⠆", |
|||
"⠇", |
|||
"⠋", |
|||
"⠙", |
|||
"⠸", |
|||
"⠰", |
|||
"⠠", |
|||
"⠰", |
|||
"⠸", |
|||
"⠙", |
|||
"⠋", |
|||
"⠇", |
|||
"⠆" |
|||
] |
|||
}, |
|||
"dots5": { |
|||
"interval": 80, |
|||
"frames": [ |
|||
"⠋", |
|||
"⠙", |
|||
"⠚", |
|||
"⠒", |
|||
"⠂", |
|||
"⠂", |
|||
"⠒", |
|||
"⠲", |
|||
"⠴", |
|||
"⠦", |
|||
"⠖", |
|||
"⠒", |
|||
"⠐", |
|||
"⠐", |
|||
"⠒", |
|||
"⠓", |
|||
"⠋" |
|||
] |
|||
}, |
|||
"dots6": { |
|||
"interval": 80, |
|||
"frames": [ |
|||
"⠁", |
|||
"⠉", |
|||
"⠙", |
|||
"⠚", |
|||
"⠒", |
|||
"⠂", |
|||
"⠂", |
|||
"⠒", |
|||
"⠲", |
|||
"⠴", |
|||
"⠤", |
|||
"⠄", |
|||
"⠄", |
|||
"⠤", |
|||
"⠴", |
|||
"⠲", |
|||
"⠒", |
|||
"⠂", |
|||
"⠂", |
|||
"⠒", |
|||
"⠚", |
|||
"⠙", |
|||
"⠉", |
|||
"⠁" |
|||
] |
|||
}, |
|||
"dots7": { |
|||
"interval": 80, |
|||
"frames": [ |
|||
"⠈", |
|||
"⠉", |
|||
"⠋", |
|||
"⠓", |
|||
"⠒", |
|||
"⠐", |
|||
"⠐", |
|||
"⠒", |
|||
"⠖", |
|||
"⠦", |
|||
"⠤", |
|||
"⠠", |
|||
"⠠", |
|||
"⠤", |
|||
"⠦", |
|||
"⠖", |
|||
"⠒", |
|||
"⠐", |
|||
"⠐", |
|||
"⠒", |
|||
"⠓", |
|||
"⠋", |
|||
"⠉", |
|||
"⠈" |
|||
] |
|||
}, |
|||
"dots8": { |
|||
"interval": 80, |
|||
"frames": [ |
|||
"⠁", |
|||
"⠁", |
|||
"⠉", |
|||
"⠙", |
|||
"⠚", |
|||
"⠒", |
|||
"⠂", |
|||
"⠂", |
|||
"⠒", |
|||
"⠲", |
|||
"⠴", |
|||
"⠤", |
|||
"⠄", |
|||
"⠄", |
|||
"⠤", |
|||
"⠠", |
|||
"⠠", |
|||
"⠤", |
|||
"⠦", |
|||
"⠖", |
|||
"⠒", |
|||
"⠐", |
|||
"⠐", |
|||
"⠒", |
|||
"⠓", |
|||
"⠋", |
|||
"⠉", |
|||
"⠈", |
|||
"⠈" |
|||
] |
|||
}, |
|||
"dots9": { |
|||
"interval": 80, |
|||
"frames": [ |
|||
"⢹", |
|||
"⢺", |
|||
"⢼", |
|||
"⣸", |
|||
"⣇", |
|||
"⡧", |
|||
"⡗", |
|||
"⡏" |
|||
] |
|||
}, |
|||
"dots10": { |
|||
"interval": 80, |
|||
"frames": [ |
|||
"⢄", |
|||
"⢂", |
|||
"⢁", |
|||
"⡁", |
|||
"⡈", |
|||
"⡐", |
|||
"⡠" |
|||
] |
|||
}, |
|||
"dots11": { |
|||
"interval": 100, |
|||
"frames": [ |
|||
"⠁", |
|||
"⠂", |
|||
"⠄", |
|||
"⡀", |
|||
"⢀", |
|||
"⠠", |
|||
"⠐", |
|||
"⠈" |
|||
] |
|||
}, |
|||
"dots12": { |
|||
"interval": 80, |
|||
"frames": [ |
|||
"⢀⠀", |
|||
"⡀⠀", |
|||
"⠄⠀", |
|||
"⢂⠀", |
|||
"⡂⠀", |
|||
"⠅⠀", |
|||
"⢃⠀", |
|||
"⡃⠀", |
|||
"⠍⠀", |
|||
"⢋⠀", |
|||
"⡋⠀", |
|||
"⠍⠁", |
|||
"⢋⠁", |
|||
"⡋⠁", |
|||
"⠍⠉", |
|||
"⠋⠉", |
|||
"⠋⠉", |
|||
"⠉⠙", |
|||
"⠉⠙", |
|||
"⠉⠩", |
|||
"⠈⢙", |
|||
"⠈⡙", |
|||
"⢈⠩", |
|||
"⡀⢙", |
|||
"⠄⡙", |
|||
"⢂⠩", |
|||
"⡂⢘", |
|||
"⠅⡘", |
|||
"⢃⠨", |
|||
"⡃⢐", |
|||
"⠍⡐", |
|||
"⢋⠠", |
|||
"⡋⢀", |
|||
"⠍⡁", |
|||
"⢋⠁", |
|||
"⡋⠁", |
|||
"⠍⠉", |
|||
"⠋⠉", |
|||
"⠋⠉", |
|||
"⠉⠙", |
|||
"⠉⠙", |
|||
"⠉⠩", |
|||
"⠈⢙", |
|||
"⠈⡙", |
|||
"⠈⠩", |
|||
"⠀⢙", |
|||
"⠀⡙", |
|||
"⠀⠩", |
|||
"⠀⢘", |
|||
"⠀⡘", |
|||
"⠀⠨", |
|||
"⠀⢐", |
|||
"⠀⡐", |
|||
"⠀⠠", |
|||
"⠀⢀", |
|||
"⠀⡀" |
|||
] |
|||
}, |
|||
"line": { |
|||
"interval": 130, |
|||
"frames": [ |
|||
"-", |
|||
"\\", |
|||
"|", |
|||
"/" |
|||
] |
|||
}, |
|||
"line2": { |
|||
"interval": 100, |
|||
"frames": [ |
|||
"⠂", |
|||
"-", |
|||
"–", |
|||
"—", |
|||
"–", |
|||
"-" |
|||
] |
|||
}, |
|||
"pipe": { |
|||
"interval": 100, |
|||
"frames": [ |
|||
"┤", |
|||
"┘", |
|||
"┴", |
|||
"└", |
|||
"├", |
|||
"┌", |
|||
"┬", |
|||
"┐" |
|||
] |
|||
}, |
|||
"simpleDots": { |
|||
"interval": 400, |
|||
"frames": [ |
|||
". ", |
|||
".. ", |
|||
"...", |
|||
" " |
|||
] |
|||
}, |
|||
"simpleDotsScrolling": { |
|||
"interval": 200, |
|||
"frames": [ |
|||
". ", |
|||
".. ", |
|||
"...", |
|||
" ..", |
|||
" .", |
|||
" " |
|||
] |
|||
}, |
|||
"star": { |
|||
"interval": 70, |
|||
"frames": [ |
|||
"✶", |
|||
"✸", |
|||
"✹", |
|||
"✺", |
|||
"✹", |
|||
"✷" |
|||
] |
|||
}, |
|||
"star2": { |
|||
"interval": 80, |
|||
"frames": [ |
|||
"+", |
|||
"x", |
|||
"*" |
|||
] |
|||
}, |
|||
"flip": { |
|||
"interval": 70, |
|||
"frames": [ |
|||
"_", |
|||
"_", |
|||
"_", |
|||
"-", |
|||
"`", |
|||
"`", |
|||
"'", |
|||
"´", |
|||
"-", |
|||
"_", |
|||
"_", |
|||
"_" |
|||
] |
|||
}, |
|||
"hamburger": { |
|||
"interval": 100, |
|||
"frames": [ |
|||
"☱", |
|||
"☲", |
|||
"☴" |
|||
] |
|||
}, |
|||
"growVertical": { |
|||
"interval": 120, |
|||
"frames": [ |
|||
"▁", |
|||
"▃", |
|||
"▄", |
|||
"▅", |
|||
"▆", |
|||
"▇", |
|||
"▆", |
|||
"▅", |
|||
"▄", |
|||
"▃" |
|||
] |
|||
}, |
|||
"growHorizontal": { |
|||
"interval": 120, |
|||
"frames": [ |
|||
"▏", |
|||
"▎", |
|||
"▍", |
|||
"▌", |
|||
"▋", |
|||
"▊", |
|||
"▉", |
|||
"▊", |
|||
"▋", |
|||
"▌", |
|||
"▍", |
|||
"▎" |
|||
] |
|||
}, |
|||
"balloon": { |
|||
"interval": 140, |
|||
"frames": [ |
|||
" ", |
|||
".", |
|||
"o", |
|||
"O", |
|||
"@", |
|||
"*", |
|||
" " |
|||
] |
|||
}, |
|||
"balloon2": { |
|||
"interval": 120, |
|||
"frames": [ |
|||
".", |
|||
"o", |
|||
"O", |
|||
"°", |
|||
"O", |
|||
"o", |
|||
"." |
|||
] |
|||
}, |
|||
"noise": { |
|||
"interval": 100, |
|||
"frames": [ |
|||
"▓", |
|||
"▒", |
|||
"░" |
|||
] |
|||
}, |
|||
"bounce": { |
|||
"interval": 120, |
|||
"frames": [ |
|||
"⠁", |
|||
"⠂", |
|||
"⠄", |
|||
"⠂" |
|||
] |
|||
}, |
|||
"boxBounce": { |
|||
"interval": 120, |
|||
"frames": [ |
|||
"▖", |
|||
"▘", |
|||
"▝", |
|||
"▗" |
|||
] |
|||
}, |
|||
"boxBounce2": { |
|||
"interval": 100, |
|||
"frames": [ |
|||
"▌", |
|||
"▀", |
|||
"▐", |
|||
"▄" |
|||
] |
|||
}, |
|||
"triangle": { |
|||
"interval": 50, |
|||
"frames": [ |
|||
"◢", |
|||
"◣", |
|||
"◤", |
|||
"◥" |
|||
] |
|||
}, |
|||
"arc": { |
|||
"interval": 100, |
|||
"frames": [ |
|||
"◜", |
|||
"◠", |
|||
"◝", |
|||
"◞", |
|||
"◡", |
|||
"◟" |
|||
] |
|||
}, |
|||
"circle": { |
|||
"interval": 120, |
|||
"frames": [ |
|||
"◡", |
|||
"⊙", |
|||
"◠" |
|||
] |
|||
}, |
|||
"squareCorners": { |
|||
"interval": 180, |
|||
"frames": [ |
|||
"◰", |
|||
"◳", |
|||
"◲", |
|||
"◱" |
|||
] |
|||
}, |
|||
"circleQuarters": { |
|||
"interval": 120, |
|||
"frames": [ |
|||
"◴", |
|||
"◷", |
|||
"◶", |
|||
"◵" |
|||
] |
|||
}, |
|||
"circleHalves": { |
|||
"interval": 50, |
|||
"frames": [ |
|||
"◐", |
|||
"◓", |
|||
"◑", |
|||
"◒" |
|||
] |
|||
}, |
|||
"squish": { |
|||
"interval": 100, |
|||
"frames": [ |
|||
"╫", |
|||
"╪" |
|||
] |
|||
}, |
|||
"toggle": { |
|||
"interval": 250, |
|||
"frames": [ |
|||
"⊶", |
|||
"⊷" |
|||
] |
|||
}, |
|||
"toggle2": { |
|||
"interval": 80, |
|||
"frames": [ |
|||
"▫", |
|||
"▪" |
|||
] |
|||
}, |
|||
"toggle3": { |
|||
"interval": 120, |
|||
"frames": [ |
|||
"□", |
|||
"■" |
|||
] |
|||
}, |
|||
"toggle4": { |
|||
"interval": 100, |
|||
"frames": [ |
|||
"■", |
|||
"□", |
|||
"▪", |
|||
"▫" |
|||
] |
|||
}, |
|||
"toggle5": { |
|||
"interval": 100, |
|||
"frames": [ |
|||
"▮", |
|||
"▯" |
|||
] |
|||
}, |
|||
"toggle6": { |
|||
"interval": 300, |
|||
"frames": [ |
|||
"ဝ", |
|||
"၀" |
|||
] |
|||
}, |
|||
"toggle7": { |
|||
"interval": 80, |
|||
"frames": [ |
|||
"⦾", |
|||
"⦿" |
|||
] |
|||
}, |
|||
"toggle8": { |
|||
"interval": 100, |
|||
"frames": [ |
|||
"◍", |
|||
"◌" |
|||
] |
|||
}, |
|||
"toggle9": { |
|||
"interval": 100, |
|||
"frames": [ |
|||
"◉", |
|||
"◎" |
|||
] |
|||
}, |
|||
"toggle10": { |
|||
"interval": 100, |
|||
"frames": [ |
|||
"㊂", |
|||
"㊀", |
|||
"㊁" |
|||
] |
|||
}, |
|||
"toggle11": { |
|||
"interval": 50, |
|||
"frames": [ |
|||
"⧇", |
|||
"⧆" |
|||
] |
|||
}, |
|||
"toggle12": { |
|||
"interval": 120, |
|||
"frames": [ |
|||
"☗", |
|||
"☖" |
|||
] |
|||
}, |
|||
"toggle13": { |
|||
"interval": 80, |
|||
"frames": [ |
|||
"=", |
|||
"*", |
|||
"-" |
|||
] |
|||
}, |
|||
"arrow": { |
|||
"interval": 100, |
|||
"frames": [ |
|||
"←", |
|||
"↖", |
|||
"↑", |
|||
"↗", |
|||
"→", |
|||
"↘", |
|||
"↓", |
|||
"↙" |
|||
] |
|||
}, |
|||
"arrow2": { |
|||
"interval": 80, |
|||
"frames": [ |
|||
"⬆️ ", |
|||
"↗️ ", |
|||
"➡️ ", |
|||
"↘️ ", |
|||
"⬇️ ", |
|||
"↙️ ", |
|||
"⬅️ ", |
|||
"↖️ " |
|||
] |
|||
}, |
|||
"arrow3": { |
|||
"interval": 120, |
|||
"frames": [ |
|||
"▹▹▹▹▹", |
|||
"▸▹▹▹▹", |
|||
"▹▸▹▹▹", |
|||
"▹▹▸▹▹", |
|||
"▹▹▹▸▹", |
|||
"▹▹▹▹▸" |
|||
] |
|||
}, |
|||
"bouncingBar": { |
|||
"interval": 80, |
|||
"frames": [ |
|||
"[ ]", |
|||
"[= ]", |
|||
"[== ]", |
|||
"[=== ]", |
|||
"[ ===]", |
|||
"[ ==]", |
|||
"[ =]", |
|||
"[ ]", |
|||
"[ =]", |
|||
"[ ==]", |
|||
"[ ===]", |
|||
"[====]", |
|||
"[=== ]", |
|||
"[== ]", |
|||
"[= ]" |
|||
] |
|||
}, |
|||
"bouncingBall": { |
|||
"interval": 80, |
|||
"frames": [ |
|||
"( ● )", |
|||
"( ● )", |
|||
"( ● )", |
|||
"( ● )", |
|||
"( ●)", |
|||
"( ● )", |
|||
"( ● )", |
|||
"( ● )", |
|||
"( ● )", |
|||
"(● )" |
|||
] |
|||
}, |
|||
"smiley": { |
|||
"interval": 200, |
|||
"frames": [ |
|||
"😄 ", |
|||
"😝 " |
|||
] |
|||
}, |
|||
"monkey": { |
|||
"interval": 300, |
|||
"frames": [ |
|||
"🙈 ", |
|||
"🙈 ", |
|||
"🙉 ", |
|||
"🙊 " |
|||
] |
|||
}, |
|||
"hearts": { |
|||
"interval": 100, |
|||
"frames": [ |
|||
"💛 ", |
|||
"💙 ", |
|||
"💜 ", |
|||
"💚 ", |
|||
"❤️ " |
|||
] |
|||
}, |
|||
"clock": { |
|||
"interval": 100, |
|||
"frames": [ |
|||
"🕛 ", |
|||
"🕐 ", |
|||
"🕑 ", |
|||
"🕒 ", |
|||
"🕓 ", |
|||
"🕔 ", |
|||
"🕕 ", |
|||
"🕖 ", |
|||
"🕗 ", |
|||
"🕘 ", |
|||
"🕙 ", |
|||
"🕚 " |
|||
] |
|||
}, |
|||
"earth": { |
|||
"interval": 180, |
|||
"frames": [ |
|||
"🌍 ", |
|||
"🌎 ", |
|||
"🌏 " |
|||
] |
|||
}, |
|||
"moon": { |
|||
"interval": 80, |
|||
"frames": [ |
|||
"🌑 ", |
|||
"🌒 ", |
|||
"🌓 ", |
|||
"🌔 ", |
|||
"🌕 ", |
|||
"🌖 ", |
|||
"🌗 ", |
|||
"🌘 " |
|||
] |
|||
}, |
|||
"runner": { |
|||
"interval": 140, |
|||
"frames": [ |
|||
"🚶 ", |
|||
"🏃 " |
|||
] |
|||
}, |
|||
"pong": { |
|||
"interval": 80, |
|||
"frames": [ |
|||
"▐⠂ ▌", |
|||
"▐⠈ ▌", |
|||
"▐ ⠂ ▌", |
|||
"▐ ⠠ ▌", |
|||
"▐ ⡀ ▌", |
|||
"▐ ⠠ ▌", |
|||
"▐ ⠂ ▌", |
|||
"▐ ⠈ ▌", |
|||
"▐ ⠂ ▌", |
|||
"▐ ⠠ ▌", |
|||
"▐ ⡀ ▌", |
|||
"▐ ⠠ ▌", |
|||
"▐ ⠂ ▌", |
|||
"▐ ⠈ ▌", |
|||
"▐ ⠂▌", |
|||
"▐ ⠠▌", |
|||
"▐ ⡀▌", |
|||
"▐ ⠠ ▌", |
|||
"▐ ⠂ ▌", |
|||
"▐ ⠈ ▌", |
|||
"▐ ⠂ ▌", |
|||
"▐ ⠠ ▌", |
|||
"▐ ⡀ ▌", |
|||
"▐ ⠠ ▌", |
|||
"▐ ⠂ ▌", |
|||
"▐ ⠈ ▌", |
|||
"▐ ⠂ ▌", |
|||
"▐ ⠠ ▌", |
|||
"▐ ⡀ ▌", |
|||
"▐⠠ ▌" |
|||
] |
|||
}, |
|||
"shark": { |
|||
"interval": 120, |
|||
"frames": [ |
|||
"▐|\\____________▌", |
|||
"▐_|\\___________▌", |
|||
"▐__|\\__________▌", |
|||
"▐___|\\_________▌", |
|||
"▐____|\\________▌", |
|||
"▐_____|\\_______▌", |
|||
"▐______|\\______▌", |
|||
"▐_______|\\_____▌", |
|||
"▐________|\\____▌", |
|||
"▐_________|\\___▌", |
|||
"▐__________|\\__▌", |
|||
"▐___________|\\_▌", |
|||
"▐____________|\\▌", |
|||
"▐____________/|▌", |
|||
"▐___________/|_▌", |
|||
"▐__________/|__▌", |
|||
"▐_________/|___▌", |
|||
"▐________/|____▌", |
|||
"▐_______/|_____▌", |
|||
"▐______/|______▌", |
|||
"▐_____/|_______▌", |
|||
"▐____/|________▌", |
|||
"▐___/|_________▌", |
|||
"▐__/|__________▌", |
|||
"▐_/|___________▌", |
|||
"▐/|____________▌" |
|||
] |
|||
}, |
|||
"dqpb": { |
|||
"interval": 100, |
|||
"frames": [ |
|||
"d", |
|||
"q", |
|||
"p", |
|||
"b" |
|||
] |
|||
}, |
|||
"weather": { |
|||
"interval": 100, |
|||
"frames": [ |
|||
"☀️ ", |
|||
"☀️ ", |
|||
"☀️ ", |
|||
"🌤 ", |
|||
"⛅️ ", |
|||
"🌥 ", |
|||
"☁️ ", |
|||
"🌧 ", |
|||
"🌨 ", |
|||
"🌧 ", |
|||
"🌨 ", |
|||
"🌧 ", |
|||
"🌨 ", |
|||
"⛈ ", |
|||
"🌨 ", |
|||
"🌧 ", |
|||
"🌨 ", |
|||
"☁️ ", |
|||
"🌥 ", |
|||
"⛅️ ", |
|||
"🌤 ", |
|||
"☀️ ", |
|||
"☀️ " |
|||
] |
|||
}, |
|||
"christmas": { |
|||
"interval": 400, |
|||
"frames": [ |
|||
"🌲", |
|||
"🎄" |
|||
] |
|||
}, |
|||
"grenade": { |
|||
"interval": 80, |
|||
"frames": [ |
|||
"، ", |
|||
"′ ", |
|||
" ´ ", |
|||
" ‾ ", |
|||
" ⸌", |
|||
" ⸊", |
|||
" |", |
|||
" ⁎", |
|||
" ⁕", |
|||
" ෴ ", |
|||
" ⁓", |
|||
" ", |
|||
" ", |
|||
" " |
|||
] |
|||
}, |
|||
"point": { |
|||
"interval": 125, |
|||
"frames": [ |
|||
"∙∙∙", |
|||
"●∙∙", |
|||
"∙●∙", |
|||
"∙∙●", |
|||
"∙∙∙" |
|||
] |
|||
}, |
|||
"layer": { |
|||
"interval": 150, |
|||
"frames": [ |
|||
"-", |
|||
"=", |
|||
"≡" |
|||
] |
|||
}, |
|||
"betaWave": { |
|||
"interval": 80, |
|||
"frames": [ |
|||
"ρββββββ", |
|||
"βρβββββ", |
|||
"ββρββββ", |
|||
"βββρβββ", |
|||
"ββββρββ", |
|||
"βββββρβ", |
|||
"ββββββρ" |
|||
] |
|||
} |
|||
} |
@ -0,0 +1,3 @@ |
|||
test |
|||
coverage |
|||
CHANGELOG.md |
@ -0,0 +1,11 @@ |
|||
language: node_js |
|||
node_js: |
|||
- '0.10' |
|||
- '0.11' |
|||
- '0.12' |
|||
- 'iojs-1' |
|||
- 'iojs-2' |
|||
- 'iojs-3' |
|||
- '4.0' |
|||
after_script: |
|||
- npm run coveralls |
@ -0,0 +1,16 @@ |
|||
# Change Log |
|||
|
|||
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines. |
|||
|
|||
<a name="2.2.0"></a> |
|||
# [2.2.0](https://github.com/knownasilya/cli-width/compare/v2.1.1...v2.2.0) (2017-08-22) |
|||
|
|||
|
|||
### Features |
|||
|
|||
* return default if env is 0 ([1833baf](https://github.com/knownasilya/cli-width/commit/1833baf)), closes [#9](https://github.com/knownasilya/cli-width/issues/9) |
|||
|
|||
|
|||
|
|||
<a name="2.1.1"></a> |
|||
## [2.1.1](https://github.com/knownasilya/cli-width/compare/v2.1.0...v2.1.1) (2017-08-22) |
@ -0,0 +1,13 @@ |
|||
Copyright (c) 2015, Ilya Radchenko <ilya@burstcreations.com> |
|||
|
|||
Permission to use, copy, modify, and/or 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,72 @@ |
|||
cli-width |
|||
========= |
|||
|
|||
Get stdout window width, with four fallbacks, `tty`, `output.columns`, a custom environment variable and then a default. |
|||
|
|||
[](http://badge.fury.io/js/cli-width) |
|||
[](https://travis-ci.org/knownasilya/cli-width) |
|||
[](https://coveralls.io/github/knownasilya/cli-width?branch=master) |
|||
|
|||
## Usage |
|||
|
|||
``` |
|||
npm install --save cli-width |
|||
``` |
|||
|
|||
```js |
|||
'use strict'; |
|||
|
|||
var cliWidth = require('cli-width'); |
|||
|
|||
cliWidth(); // maybe 204 :) |
|||
``` |
|||
|
|||
You can also set the `CLI_WIDTH` environment variable. |
|||
|
|||
If none of the methods are supported, and the environment variable isn't set, |
|||
the default width value is going to be `0`, that can be changed using the configurable `options`. |
|||
|
|||
## API |
|||
|
|||
### cliWidth([options]) |
|||
|
|||
`cliWidth` can be configured using an `options` parameter, the possible properties are: |
|||
|
|||
- **defaultWidth**\<number\> Defines a default value to be used if none of the methods are available, defaults to `0` |
|||
- **output**\<object\> A stream to be used to read width values from, defaults to `process.stdout` |
|||
- **tty**\<object\> TTY module to try to read width from as a fallback, defaults to `require('tty')` |
|||
|
|||
|
|||
### Examples |
|||
|
|||
Defining both a default width value and a stream output to try to read from: |
|||
|
|||
```js |
|||
var cliWidth = require('cli-width'); |
|||
var ttys = require('ttys'); |
|||
|
|||
cliWidth({ |
|||
defaultWidth: 80, |
|||
output: ttys.output |
|||
}); |
|||
``` |
|||
|
|||
Defines a different tty module to read width from: |
|||
|
|||
```js |
|||
var cliWidth = require('cli-width'); |
|||
var ttys = require('ttys'); |
|||
|
|||
cliWidth({ |
|||
tty: ttys |
|||
}); |
|||
``` |
|||
|
|||
## Tests |
|||
|
|||
```bash |
|||
npm install |
|||
npm test |
|||
``` |
|||
|
|||
Coverage can be generated with `npm run coverage`. |
@ -0,0 +1,49 @@ |
|||
'use strict'; |
|||
|
|||
exports = module.exports = cliWidth; |
|||
|
|||
function normalizeOpts(options) { |
|||
var defaultOpts = { |
|||
defaultWidth: 0, |
|||
output: process.stdout, |
|||
tty: require('tty') |
|||
}; |
|||
|
|||
if (!options) { |
|||
return defaultOpts; |
|||
} else { |
|||
Object.keys(defaultOpts).forEach(function (key) { |
|||
if (!options[key]) { |
|||
options[key] = defaultOpts[key]; |
|||
} |
|||
}); |
|||
|
|||
return options; |
|||
} |
|||
} |
|||
|
|||
function cliWidth(options) { |
|||
var opts = normalizeOpts(options); |
|||
|
|||
if (opts.output.getWindowSize) { |
|||
return opts.output.getWindowSize()[0] || opts.defaultWidth; |
|||
} else { |
|||
if (opts.tty.getWindowSize) { |
|||
return opts.tty.getWindowSize()[1] || opts.defaultWidth; |
|||
} else { |
|||
if (opts.output.columns) { |
|||
return opts.output.columns; |
|||
} else { |
|||
if (process.env.CLI_WIDTH) { |
|||
var width = parseInt(process.env.CLI_WIDTH, 10); |
|||
|
|||
if (!isNaN(width) && width !== 0) { |
|||
return width; |
|||
} |
|||
} |
|||
} |
|||
|
|||
return opts.defaultWidth; |
|||
} |
|||
} |
|||
}; |
@ -0,0 +1,59 @@ |
|||
{ |
|||
"_from": "cli-width@^2.0.0", |
|||
"_id": "cli-width@2.2.0", |
|||
"_inBundle": false, |
|||
"_integrity": "sha1-/xnt6Kml5XkyQUewwR8PvLq+1jk=", |
|||
"_location": "/cli-width", |
|||
"_phantomChildren": {}, |
|||
"_requested": { |
|||
"type": "range", |
|||
"registry": true, |
|||
"raw": "cli-width@^2.0.0", |
|||
"name": "cli-width", |
|||
"escapedName": "cli-width", |
|||
"rawSpec": "^2.0.0", |
|||
"saveSpec": null, |
|||
"fetchSpec": "^2.0.0" |
|||
}, |
|||
"_requiredBy": [ |
|||
"/inquirer" |
|||
], |
|||
"_resolved": "https://registry.npmjs.org/cli-width/-/cli-width-2.2.0.tgz", |
|||
"_shasum": "ff19ede8a9a5e579324147b0c11f0fbcbabed639", |
|||
"_spec": "cli-width@^2.0.0", |
|||
"_where": "E:\\mu_dist\\@xyx\\beer\\test-command\\node_modules\\inquirer", |
|||
"author": { |
|||
"name": "Ilya Radchenko", |
|||
"email": "ilya@burstcreations.com" |
|||
}, |
|||
"bugs": { |
|||
"url": "https://github.com/knownasilya/cli-width/issues" |
|||
}, |
|||
"bundleDependencies": false, |
|||
"deprecated": false, |
|||
"description": "Get stdout window width, with two fallbacks, tty and then a default.", |
|||
"devDependencies": { |
|||
"coveralls": "^2.11.4", |
|||
"isparta": "^3.0.4", |
|||
"rimraf": "^2.4.3", |
|||
"standard-version": "^4.2.0", |
|||
"tap-spec": "^4.1.0", |
|||
"tape": "^3.4.0" |
|||
}, |
|||
"homepage": "https://github.com/knownasilya/cli-width", |
|||
"license": "ISC", |
|||
"main": "index.js", |
|||
"name": "cli-width", |
|||
"repository": { |
|||
"type": "git", |
|||
"url": "git+ssh://git@github.com/knownasilya/cli-width.git" |
|||
}, |
|||
"scripts": { |
|||
"coverage": "isparta cover test/*.js | tspec", |
|||
"coveralls": "npm run coverage -s && coveralls < coverage/lcov.info", |
|||
"postcoveralls": "rimraf ./coverage", |
|||
"release": "standard-version", |
|||
"test": "node test | tspec" |
|||
}, |
|||
"version": "2.2.0" |
|||
} |
@ -0,0 +1,4 @@ |
|||
/node_modules/ |
|||
/test.js |
|||
/*.html |
|||
/.travis.yml |
@ -0,0 +1,18 @@ |
|||
Copyright © 2011-2015 Paul Vorbach <paul@vorba.ch> |
|||
|
|||
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, OUT OF OR IN CONNECTION WITH THE |
|||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
@ -0,0 +1,126 @@ |
|||
# clone |
|||
|
|||
[](http://travis-ci.org/pvorb/node-clone) |
|||
|
|||
[](http://npm-stat.com/charts.html?package=clone) |
|||
|
|||
offers foolproof _deep cloning_ of objects, arrays, numbers, strings etc. in JavaScript. |
|||
|
|||
|
|||
## Installation |
|||
|
|||
npm install clone |
|||
|
|||
(It also works with browserify, ender or standalone.) |
|||
|
|||
|
|||
## Example |
|||
|
|||
~~~ javascript |
|||
var clone = require('clone'); |
|||
|
|||
var a, b; |
|||
|
|||
a = { foo: { bar: 'baz' } }; // initial value of a |
|||
|
|||
b = clone(a); // clone a -> b |
|||
a.foo.bar = 'foo'; // change a |
|||
|
|||
console.log(a); // show a |
|||
console.log(b); // show b |
|||
~~~ |
|||
|
|||
This will print: |
|||
|
|||
~~~ javascript |
|||
{ foo: { bar: 'foo' } } |
|||
{ foo: { bar: 'baz' } } |
|||
~~~ |
|||
|
|||
**clone** masters cloning simple objects (even with custom prototype), arrays, |
|||
Date objects, and RegExp objects. Everything is cloned recursively, so that you |
|||
can clone dates in arrays in objects, for example. |
|||
|
|||
|
|||
## API |
|||
|
|||
`clone(val, circular, depth)` |
|||
|
|||
* `val` -- the value that you want to clone, any type allowed |
|||
* `circular` -- boolean |
|||
|
|||
Call `clone` with `circular` set to `false` if you are certain that `obj` |
|||
contains no circular references. This will give better performance if needed. |
|||
There is no error if `undefined` or `null` is passed as `obj`. |
|||
* `depth` -- depth to which the object is to be cloned (optional, |
|||
defaults to infinity) |
|||
|
|||
`clone.clonePrototype(obj)` |
|||
|
|||
* `obj` -- the object that you want to clone |
|||
|
|||
Does a prototype clone as |
|||
[described by Oran Looney](http://oranlooney.com/functional-javascript/). |
|||
|
|||
|
|||
## Circular References |
|||
|
|||
~~~ javascript |
|||
var a, b; |
|||
|
|||
a = { hello: 'world' }; |
|||
|
|||
a.myself = a; |
|||
b = clone(a); |
|||
|
|||
console.log(b); |
|||
~~~ |
|||
|
|||
This will print: |
|||
|
|||
~~~ javascript |
|||
{ hello: "world", myself: [Circular] } |
|||
~~~ |
|||
|
|||
So, `b.myself` points to `b`, not `a`. Neat! |
|||
|
|||
|
|||
## Test |
|||
|
|||
npm test |
|||
|
|||
|
|||
## Caveat |
|||
|
|||
Some special objects like a socket or `process.stdout`/`stderr` are known to not |
|||
be cloneable. If you find other objects that cannot be cloned, please [open an |
|||
issue](https://github.com/pvorb/node-clone/issues/new). |
|||
|
|||
|
|||
## Bugs and Issues |
|||
|
|||
If you encounter any bugs or issues, feel free to [open an issue at |
|||
github](https://github.com/pvorb/node-clone/issues) or send me an email to |
|||
<paul@vorba.ch>. I also always like to hear from you, if you’re using my code. |
|||
|
|||
## License |
|||
|
|||
Copyright © 2011-2015 [Paul Vorbach](http://paul.vorba.ch/) and |
|||
[contributors](https://github.com/pvorb/node-clone/graphs/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, OUT OF OR IN CONNECTION WITH THE |
|||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
@ -0,0 +1,10 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<module type="WEB_MODULE" version="4"> |
|||
<component name="NewModuleRootManager" inherit-compiler-output="true"> |
|||
<exclude-output /> |
|||
<content url="file://$MODULE_DIR$" /> |
|||
<orderEntry type="inheritedJdk" /> |
|||
<orderEntry type="sourceFolder" forTests="false" /> |
|||
<orderEntry type="library" name="clone node_modules" level="project" /> |
|||
</component> |
|||
</module> |
@ -0,0 +1,166 @@ |
|||
var clone = (function() { |
|||
'use strict'; |
|||
|
|||
/** |
|||
* Clones (copies) an Object using deep copying. |
|||
* |
|||
* This function supports circular references by default, but if you are certain |
|||
* there are no circular references in your object, you can save some CPU time |
|||
* by calling clone(obj, false). |
|||
* |
|||
* Caution: if `circular` is false and `parent` contains circular references, |
|||
* your program may enter an infinite loop and crash. |
|||
* |
|||
* @param `parent` - the object to be cloned |
|||
* @param `circular` - set to true if the object to be cloned may contain |
|||
* circular references. (optional - true by default) |
|||
* @param `depth` - set to a number if the object is only to be cloned to |
|||
* a particular depth. (optional - defaults to Infinity) |
|||
* @param `prototype` - sets the prototype to be used when cloning an object. |
|||
* (optional - defaults to parent prototype). |
|||
*/ |
|||
function clone(parent, circular, depth, prototype) { |
|||
var filter; |
|||
if (typeof circular === 'object') { |
|||
depth = circular.depth; |
|||
prototype = circular.prototype; |
|||
filter = circular.filter; |
|||
circular = circular.circular |
|||
} |
|||
// maintain two arrays for circular references, where corresponding parents
|
|||
// and children have the same index
|
|||
var allParents = []; |
|||
var allChildren = []; |
|||
|
|||
var useBuffer = typeof Buffer != 'undefined'; |
|||
|
|||
if (typeof circular == 'undefined') |
|||
circular = true; |
|||
|
|||
if (typeof depth == 'undefined') |
|||
depth = Infinity; |
|||
|
|||
// recurse this function so we don't reset allParents and allChildren
|
|||
function _clone(parent, depth) { |
|||
// cloning null always returns null
|
|||
if (parent === null) |
|||
return null; |
|||
|
|||
if (depth == 0) |
|||
return parent; |
|||
|
|||
var child; |
|||
var proto; |
|||
if (typeof parent != 'object') { |
|||
return parent; |
|||
} |
|||
|
|||
if (clone.__isArray(parent)) { |
|||
child = []; |
|||
} else if (clone.__isRegExp(parent)) { |
|||
child = new RegExp(parent.source, __getRegExpFlags(parent)); |
|||
if (parent.lastIndex) child.lastIndex = parent.lastIndex; |
|||
} else if (clone.__isDate(parent)) { |
|||
child = new Date(parent.getTime()); |
|||
} else if (useBuffer && Buffer.isBuffer(parent)) { |
|||
if (Buffer.allocUnsafe) { |
|||
// Node.js >= 4.5.0
|
|||
child = Buffer.allocUnsafe(parent.length); |
|||
} else { |
|||
// Older Node.js versions
|
|||
child = new Buffer(parent.length); |
|||
} |
|||
parent.copy(child); |
|||
return child; |
|||
} else { |
|||
if (typeof prototype == 'undefined') { |
|||
proto = Object.getPrototypeOf(parent); |
|||
child = Object.create(proto); |
|||
} |
|||
else { |
|||
child = Object.create(prototype); |
|||
proto = prototype; |
|||
} |
|||
} |
|||
|
|||
if (circular) { |
|||
var index = allParents.indexOf(parent); |
|||
|
|||
if (index != -1) { |
|||
return allChildren[index]; |
|||
} |
|||
allParents.push(parent); |
|||
allChildren.push(child); |
|||
} |
|||
|
|||
for (var i in parent) { |
|||
var attrs; |
|||
if (proto) { |
|||
attrs = Object.getOwnPropertyDescriptor(proto, i); |
|||
} |
|||
|
|||
if (attrs && attrs.set == null) { |
|||
continue; |
|||
} |
|||
child[i] = _clone(parent[i], depth - 1); |
|||
} |
|||
|
|||
return child; |
|||
} |
|||
|
|||
return _clone(parent, depth); |
|||
} |
|||
|
|||
/** |
|||
* Simple flat clone using prototype, accepts only objects, usefull for property |
|||
* override on FLAT configuration object (no nested props). |
|||
* |
|||
* USE WITH CAUTION! This may not behave as you wish if you do not know how this |
|||
* works. |
|||
*/ |
|||
clone.clonePrototype = function clonePrototype(parent) { |
|||
if (parent === null) |
|||
return null; |
|||
|
|||
var c = function () {}; |
|||
c.prototype = parent; |
|||
return new c(); |
|||
}; |
|||
|
|||
// private utility functions
|
|||
|
|||
function __objToStr(o) { |
|||
return Object.prototype.toString.call(o); |
|||
}; |
|||
clone.__objToStr = __objToStr; |
|||
|
|||
function __isDate(o) { |
|||
return typeof o === 'object' && __objToStr(o) === '[object Date]'; |
|||
}; |
|||
clone.__isDate = __isDate; |
|||
|
|||
function __isArray(o) { |
|||
return typeof o === 'object' && __objToStr(o) === '[object Array]'; |
|||
}; |
|||
clone.__isArray = __isArray; |
|||
|
|||
function __isRegExp(o) { |
|||
return typeof o === 'object' && __objToStr(o) === '[object RegExp]'; |
|||
}; |
|||
clone.__isRegExp = __isRegExp; |
|||
|
|||
function __getRegExpFlags(re) { |
|||
var flags = ''; |
|||
if (re.global) flags += 'g'; |
|||
if (re.ignoreCase) flags += 'i'; |
|||
if (re.multiline) flags += 'm'; |
|||
return flags; |
|||
}; |
|||
clone.__getRegExpFlags = __getRegExpFlags; |
|||
|
|||
return clone; |
|||
})(); |
|||
|
|||
if (typeof module === 'object' && module.exports) { |
|||
module.exports = clone; |
|||
} |
@ -0,0 +1,137 @@ |
|||
{ |
|||
"_from": "clone@^1.0.2", |
|||
"_id": "clone@1.0.4", |
|||
"_inBundle": false, |
|||
"_integrity": "sha1-2jCcwmPfFZlMaIypAheco8fNfH4=", |
|||
"_location": "/clone", |
|||
"_phantomChildren": {}, |
|||
"_requested": { |
|||
"type": "range", |
|||
"registry": true, |
|||
"raw": "clone@^1.0.2", |
|||
"name": "clone", |
|||
"escapedName": "clone", |
|||
"rawSpec": "^1.0.2", |
|||
"saveSpec": null, |
|||
"fetchSpec": "^1.0.2" |
|||
}, |
|||
"_requiredBy": [ |
|||
"/defaults" |
|||
], |
|||
"_resolved": "https://registry.npmjs.org/clone/-/clone-1.0.4.tgz", |
|||
"_shasum": "da309cc263df15994c688ca902179ca3c7cd7c7e", |
|||
"_spec": "clone@^1.0.2", |
|||
"_where": "E:\\mu_dist\\@xyx\\beer\\test-command\\node_modules\\defaults", |
|||
"author": { |
|||
"name": "Paul Vorbach", |
|||
"email": "paul@vorba.ch", |
|||
"url": "http://paul.vorba.ch/" |
|||
}, |
|||
"bugs": { |
|||
"url": "https://github.com/pvorb/node-clone/issues" |
|||
}, |
|||
"bundleDependencies": false, |
|||
"contributors": [ |
|||
{ |
|||
"name": "Blake Miner", |
|||
"email": "miner.blake@gmail.com", |
|||
"url": "http://www.blakeminer.com/" |
|||
}, |
|||
{ |
|||
"name": "Tian You", |
|||
"email": "axqd001@gmail.com", |
|||
"url": "http://blog.axqd.net/" |
|||
}, |
|||
{ |
|||
"name": "George Stagas", |
|||
"email": "gstagas@gmail.com", |
|||
"url": "http://stagas.com/" |
|||
}, |
|||
{ |
|||
"name": "Tobiasz Cudnik", |
|||
"email": "tobiasz.cudnik@gmail.com", |
|||
"url": "https://github.com/TobiaszCudnik" |
|||
}, |
|||
{ |
|||
"name": "Pavel Lang", |
|||
"email": "langpavel@phpskelet.org", |
|||
"url": "https://github.com/langpavel" |
|||
}, |
|||
{ |
|||
"name": "Dan MacTough", |
|||
"url": "http://yabfog.com/" |
|||
}, |
|||
{ |
|||
"name": "w1nk", |
|||
"url": "https://github.com/w1nk" |
|||
}, |
|||
{ |
|||
"name": "Hugh Kennedy", |
|||
"url": "http://twitter.com/hughskennedy" |
|||
}, |
|||
{ |
|||
"name": "Dustin Diaz", |
|||
"url": "http://dustindiaz.com" |
|||
}, |
|||
{ |
|||
"name": "Ilya Shaisultanov", |
|||
"url": "https://github.com/diversario" |
|||
}, |
|||
{ |
|||
"name": "Nathan MacInnes", |
|||
"email": "nathan@macinn.es", |
|||
"url": "http://macinn.es/" |
|||
}, |
|||
{ |
|||
"name": "Benjamin E. Coe", |
|||
"email": "ben@npmjs.com", |
|||
"url": "https://twitter.com/benjamincoe" |
|||
}, |
|||
{ |
|||
"name": "Nathan Zadoks", |
|||
"url": "https://github.com/nathan7" |
|||
}, |
|||
{ |
|||
"name": "Róbert Oroszi", |
|||
"email": "robert+gh@oroszi.net", |
|||
"url": "https://github.com/oroce" |
|||
}, |
|||
{ |
|||
"name": "Aurélio A. Heckert", |
|||
"url": "http://softwarelivre.org/aurium" |
|||
}, |
|||
{ |
|||
"name": "Guy Ellis", |
|||
"url": "http://www.guyellisrocks.com/" |
|||
} |
|||
], |
|||
"dependencies": {}, |
|||
"deprecated": false, |
|||
"description": "deep cloning of objects and arrays", |
|||
"devDependencies": { |
|||
"nodeunit": "~0.9.0" |
|||
}, |
|||
"engines": { |
|||
"node": ">=0.8" |
|||
}, |
|||
"homepage": "https://github.com/pvorb/node-clone#readme", |
|||
"license": "MIT", |
|||
"main": "clone.js", |
|||
"name": "clone", |
|||
"optionalDependencies": {}, |
|||
"repository": { |
|||
"type": "git", |
|||
"url": "git://github.com/pvorb/node-clone.git" |
|||
}, |
|||
"scripts": { |
|||
"test": "nodeunit test.js" |
|||
}, |
|||
"tags": [ |
|||
"clone", |
|||
"object", |
|||
"array", |
|||
"function", |
|||
"date" |
|||
], |
|||
"version": "1.0.4" |
|||
} |
@ -0,0 +1,54 @@ |
|||
# 1.0.0 - 2016-01-07 |
|||
|
|||
- Removed: unused speed test |
|||
- Added: Automatic routing between previously unsupported conversions |
|||
([#27](https://github.com/Qix-/color-convert/pull/27)) |
|||
- Removed: `xxx2xxx()` and `xxx2xxxRaw()` functions |
|||
([#27](https://github.com/Qix-/color-convert/pull/27)) |
|||
- Removed: `convert()` class |
|||
([#27](https://github.com/Qix-/color-convert/pull/27)) |
|||
- Changed: all functions to lookup dictionary |
|||
([#27](https://github.com/Qix-/color-convert/pull/27)) |
|||
- Changed: `ansi` to `ansi256` |
|||
([#27](https://github.com/Qix-/color-convert/pull/27)) |
|||
- Fixed: argument grouping for functions requiring only one argument |
|||
([#27](https://github.com/Qix-/color-convert/pull/27)) |
|||
|
|||
# 0.6.0 - 2015-07-23 |
|||
|
|||
- Added: methods to handle |
|||
[ANSI](https://en.wikipedia.org/wiki/ANSI_escape_code#Colors) 16/256 colors: |
|||
- rgb2ansi16 |
|||
- rgb2ansi |
|||
- hsl2ansi16 |
|||
- hsl2ansi |
|||
- hsv2ansi16 |
|||
- hsv2ansi |
|||
- hwb2ansi16 |
|||
- hwb2ansi |
|||
- cmyk2ansi16 |
|||
- cmyk2ansi |
|||
- keyword2ansi16 |
|||
- keyword2ansi |
|||
- ansi162rgb |
|||
- ansi162hsl |
|||
- ansi162hsv |
|||
- ansi162hwb |
|||
- ansi162cmyk |
|||
- ansi162keyword |
|||
- ansi2rgb |
|||
- ansi2hsl |
|||
- ansi2hsv |
|||
- ansi2hwb |
|||
- ansi2cmyk |
|||
- ansi2keyword |
|||
([#18](https://github.com/harthur/color-convert/pull/18)) |
|||
|
|||
# 0.5.3 - 2015-06-02 |
|||
|
|||
- Fixed: hsl2hsv does not return `NaN` anymore when using `[0,0,0]` |
|||
([#15](https://github.com/harthur/color-convert/issues/15)) |
|||
|
|||
--- |
|||
|
|||
Check out commit logs for older releases |
@ -0,0 +1,21 @@ |
|||
Copyright (c) 2011-2016 Heather Arthur <fayearthur@gmail.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,68 @@ |
|||
# color-convert |
|||
|
|||
[](https://travis-ci.org/Qix-/color-convert) |
|||
|
|||
Color-convert is a color conversion library for JavaScript and node. |
|||
It converts all ways between `rgb`, `hsl`, `hsv`, `hwb`, `cmyk`, `ansi`, `ansi16`, `hex` strings, and CSS `keyword`s (will round to closest): |
|||
|
|||
```js |
|||
var convert = require('color-convert'); |
|||
|
|||
convert.rgb.hsl(140, 200, 100); // [96, 48, 59] |
|||
convert.keyword.rgb('blue'); // [0, 0, 255] |
|||
|
|||
var rgbChannels = convert.rgb.channels; // 3 |
|||
var cmykChannels = convert.cmyk.channels; // 4 |
|||
var ansiChannels = convert.ansi16.channels; // 1 |
|||
``` |
|||
|
|||
# Install |
|||
|
|||
```console |
|||
$ npm install color-convert |
|||
``` |
|||
|
|||
# API |
|||
|
|||
Simply get the property of the _from_ and _to_ conversion that you're looking for. |
|||
|
|||
All functions have a rounded and unrounded variant. By default, return values are rounded. To get the unrounded (raw) results, simply tack on `.raw` to the function. |
|||
|
|||
All 'from' functions have a hidden property called `.channels` that indicates the number of channels the function expects (not including alpha). |
|||
|
|||
```js |
|||
var convert = require('color-convert'); |
|||
|
|||
// Hex to LAB |
|||
convert.hex.lab('DEADBF'); // [ 76, 21, -2 ] |
|||
convert.hex.lab.raw('DEADBF'); // [ 75.56213190997677, 20.653827952644754, -2.290532499330533 ] |
|||
|
|||
// RGB to CMYK |
|||
convert.rgb.cmyk(167, 255, 4); // [ 35, 0, 98, 0 ] |
|||
convert.rgb.cmyk.raw(167, 255, 4); // [ 34.509803921568626, 0, 98.43137254901961, 0 ] |
|||
``` |
|||
|
|||
### Arrays |
|||
All functions that accept multiple arguments also support passing an array. |
|||
|
|||
Note that this does **not** apply to functions that convert from a color that only requires one value (e.g. `keyword`, `ansi256`, `hex`, etc.) |
|||
|
|||
```js |
|||
var convert = require('color-convert'); |
|||
|
|||
convert.rgb.hex(123, 45, 67); // '7B2D43' |
|||
convert.rgb.hex([123, 45, 67]); // '7B2D43' |
|||
``` |
|||
|
|||
## Routing |
|||
|
|||
Conversions that don't have an _explicitly_ defined conversion (in [conversions.js](conversions.js)), but can be converted by means of sub-conversions (e.g. XYZ -> **RGB** -> CMYK), are automatically routed together. This allows just about any color model supported by `color-convert` to be converted to any other model, so long as a sub-conversion path exists. This is also true for conversions requiring more than one step in between (e.g. LCH -> **LAB** -> **XYZ** -> **RGB** -> Hex). |
|||
|
|||
Keep in mind that extensive conversions _may_ result in a loss of precision, and exist only to be complete. For a list of "direct" (single-step) conversions, see [conversions.js](conversions.js). |
|||
|
|||
# Contribute |
|||
|
|||
If there is a new model you would like to support, or want to add a direct conversion between two existing models, please send us a pull request. |
|||
|
|||
# License |
|||
Copyright © 2011-2016, Heather Arthur and Josh Junon. Licensed under the [MIT License](LICENSE). |
@ -0,0 +1,868 @@ |
|||
/* MIT license */ |
|||
var cssKeywords = require('color-name'); |
|||
|
|||
// NOTE: conversions should only return primitive values (i.e. arrays, or
|
|||
// values that give correct `typeof` results).
|
|||
// do not use box values types (i.e. Number(), String(), etc.)
|
|||
|
|||
var reverseKeywords = {}; |
|||
for (var key in cssKeywords) { |
|||
if (cssKeywords.hasOwnProperty(key)) { |
|||
reverseKeywords[cssKeywords[key]] = key; |
|||
} |
|||
} |
|||
|
|||
var convert = module.exports = { |
|||
rgb: {channels: 3, labels: 'rgb'}, |
|||
hsl: {channels: 3, labels: 'hsl'}, |
|||
hsv: {channels: 3, labels: 'hsv'}, |
|||
hwb: {channels: 3, labels: 'hwb'}, |
|||
cmyk: {channels: 4, labels: 'cmyk'}, |
|||
xyz: {channels: 3, labels: 'xyz'}, |
|||
lab: {channels: 3, labels: 'lab'}, |
|||
lch: {channels: 3, labels: 'lch'}, |
|||
hex: {channels: 1, labels: ['hex']}, |
|||
keyword: {channels: 1, labels: ['keyword']}, |
|||
ansi16: {channels: 1, labels: ['ansi16']}, |
|||
ansi256: {channels: 1, labels: ['ansi256']}, |
|||
hcg: {channels: 3, labels: ['h', 'c', 'g']}, |
|||
apple: {channels: 3, labels: ['r16', 'g16', 'b16']}, |
|||
gray: {channels: 1, labels: ['gray']} |
|||
}; |
|||
|
|||
// hide .channels and .labels properties
|
|||
for (var model in convert) { |
|||
if (convert.hasOwnProperty(model)) { |
|||
if (!('channels' in convert[model])) { |
|||
throw new Error('missing channels property: ' + model); |
|||
} |
|||
|
|||
if (!('labels' in convert[model])) { |
|||
throw new Error('missing channel labels property: ' + model); |
|||
} |
|||
|
|||
if (convert[model].labels.length !== convert[model].channels) { |
|||
throw new Error('channel and label counts mismatch: ' + model); |
|||
} |
|||
|
|||
var channels = convert[model].channels; |
|||
var labels = convert[model].labels; |
|||
delete convert[model].channels; |
|||
delete convert[model].labels; |
|||
Object.defineProperty(convert[model], 'channels', {value: channels}); |
|||
Object.defineProperty(convert[model], 'labels', {value: labels}); |
|||
} |
|||
} |
|||
|
|||
convert.rgb.hsl = function (rgb) { |
|||
var r = rgb[0] / 255; |
|||
var g = rgb[1] / 255; |
|||
var b = rgb[2] / 255; |
|||
var min = Math.min(r, g, b); |
|||
var max = Math.max(r, g, b); |
|||
var delta = max - min; |
|||
var h; |
|||
var s; |
|||
var l; |
|||
|
|||
if (max === min) { |
|||
h = 0; |
|||
} else if (r === max) { |
|||
h = (g - b) / delta; |
|||
} else if (g === max) { |
|||
h = 2 + (b - r) / delta; |
|||
} else if (b === max) { |
|||
h = 4 + (r - g) / delta; |
|||
} |
|||
|
|||
h = Math.min(h * 60, 360); |
|||
|
|||
if (h < 0) { |
|||
h += 360; |
|||
} |
|||
|
|||
l = (min + max) / 2; |
|||
|
|||
if (max === min) { |
|||
s = 0; |
|||
} else if (l <= 0.5) { |
|||
s = delta / (max + min); |
|||
} else { |
|||
s = delta / (2 - max - min); |
|||
} |
|||
|
|||
return [h, s * 100, l * 100]; |
|||
}; |
|||
|
|||
convert.rgb.hsv = function (rgb) { |
|||
var rdif; |
|||
var gdif; |
|||
var bdif; |
|||
var h; |
|||
var s; |
|||
|
|||
var r = rgb[0] / 255; |
|||
var g = rgb[1] / 255; |
|||
var b = rgb[2] / 255; |
|||
var v = Math.max(r, g, b); |
|||
var diff = v - Math.min(r, g, b); |
|||
var diffc = function (c) { |
|||
return (v - c) / 6 / diff + 1 / 2; |
|||
}; |
|||
|
|||
if (diff === 0) { |
|||
h = s = 0; |
|||
} else { |
|||
s = diff / v; |
|||
rdif = diffc(r); |
|||
gdif = diffc(g); |
|||
bdif = diffc(b); |
|||
|
|||
if (r === v) { |
|||
h = bdif - gdif; |
|||
} else if (g === v) { |
|||
h = (1 / 3) + rdif - bdif; |
|||
} else if (b === v) { |
|||
h = (2 / 3) + gdif - rdif; |
|||
} |
|||
if (h < 0) { |
|||
h += 1; |
|||
} else if (h > 1) { |
|||
h -= 1; |
|||
} |
|||
} |
|||
|
|||
return [ |
|||
h * 360, |
|||
s * 100, |
|||
v * 100 |
|||
]; |
|||
}; |
|||
|
|||
convert.rgb.hwb = function (rgb) { |
|||
var r = rgb[0]; |
|||
var g = rgb[1]; |
|||
var b = rgb[2]; |
|||
var h = convert.rgb.hsl(rgb)[0]; |
|||
var w = 1 / 255 * Math.min(r, Math.min(g, b)); |
|||
|
|||
b = 1 - 1 / 255 * Math.max(r, Math.max(g, b)); |
|||
|
|||
return [h, w * 100, b * 100]; |
|||
}; |
|||
|
|||
convert.rgb.cmyk = function (rgb) { |
|||
var r = rgb[0] / 255; |
|||
var g = rgb[1] / 255; |
|||
var b = rgb[2] / 255; |
|||
var c; |
|||
var m; |
|||
var y; |
|||
var k; |
|||
|
|||
k = Math.min(1 - r, 1 - g, 1 - b); |
|||
c = (1 - r - k) / (1 - k) || 0; |
|||
m = (1 - g - k) / (1 - k) || 0; |
|||
y = (1 - b - k) / (1 - k) || 0; |
|||
|
|||
return [c * 100, m * 100, y * 100, k * 100]; |
|||
}; |
|||
|
|||
/** |
|||
* See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
|
|||
* */ |
|||
function comparativeDistance(x, y) { |
|||
return ( |
|||
Math.pow(x[0] - y[0], 2) + |
|||
Math.pow(x[1] - y[1], 2) + |
|||
Math.pow(x[2] - y[2], 2) |
|||
); |
|||
} |
|||
|
|||
convert.rgb.keyword = function (rgb) { |
|||
var reversed = reverseKeywords[rgb]; |
|||
if (reversed) { |
|||
return reversed; |
|||
} |
|||
|
|||
var currentClosestDistance = Infinity; |
|||
var currentClosestKeyword; |
|||
|
|||
for (var keyword in cssKeywords) { |
|||
if (cssKeywords.hasOwnProperty(keyword)) { |
|||
var value = cssKeywords[keyword]; |
|||
|
|||
// Compute comparative distance
|
|||
var distance = comparativeDistance(rgb, value); |
|||
|
|||
// Check if its less, if so set as closest
|
|||
if (distance < currentClosestDistance) { |
|||
currentClosestDistance = distance; |
|||
currentClosestKeyword = keyword; |
|||
} |
|||
} |
|||
} |
|||
|
|||
return currentClosestKeyword; |
|||
}; |
|||
|
|||
convert.keyword.rgb = function (keyword) { |
|||
return cssKeywords[keyword]; |
|||
}; |
|||
|
|||
convert.rgb.xyz = function (rgb) { |
|||
var r = rgb[0] / 255; |
|||
var g = rgb[1] / 255; |
|||
var b = rgb[2] / 255; |
|||
|
|||
// assume sRGB
|
|||
r = r > 0.04045 ? Math.pow(((r + 0.055) / 1.055), 2.4) : (r / 12.92); |
|||
g = g > 0.04045 ? Math.pow(((g + 0.055) / 1.055), 2.4) : (g / 12.92); |
|||
b = b > 0.04045 ? Math.pow(((b + 0.055) / 1.055), 2.4) : (b / 12.92); |
|||
|
|||
var x = (r * 0.4124) + (g * 0.3576) + (b * 0.1805); |
|||
var y = (r * 0.2126) + (g * 0.7152) + (b * 0.0722); |
|||
var z = (r * 0.0193) + (g * 0.1192) + (b * 0.9505); |
|||
|
|||
return [x * 100, y * 100, z * 100]; |
|||
}; |
|||
|
|||
convert.rgb.lab = function (rgb) { |
|||
var xyz = convert.rgb.xyz(rgb); |
|||
var x = xyz[0]; |
|||
var y = xyz[1]; |
|||
var z = xyz[2]; |
|||
var l; |
|||
var a; |
|||
var b; |
|||
|
|||
x /= 95.047; |
|||
y /= 100; |
|||
z /= 108.883; |
|||
|
|||
x = x > 0.008856 ? Math.pow(x, 1 / 3) : (7.787 * x) + (16 / 116); |
|||
y = y > 0.008856 ? Math.pow(y, 1 / 3) : (7.787 * y) + (16 / 116); |
|||
z = z > 0.008856 ? Math.pow(z, 1 / 3) : (7.787 * z) + (16 / 116); |
|||
|
|||
l = (116 * y) - 16; |
|||
a = 500 * (x - y); |
|||
b = 200 * (y - z); |
|||
|
|||
return [l, a, b]; |
|||
}; |
|||
|
|||
convert.hsl.rgb = function (hsl) { |
|||
var h = hsl[0] / 360; |
|||
var s = hsl[1] / 100; |
|||
var l = hsl[2] / 100; |
|||
var t1; |
|||
var t2; |
|||
var t3; |
|||
var rgb; |
|||
var val; |
|||
|
|||
if (s === 0) { |
|||
val = l * 255; |
|||
return [val, val, val]; |
|||
} |
|||
|
|||
if (l < 0.5) { |
|||
t2 = l * (1 + s); |
|||
} else { |
|||
t2 = l + s - l * s; |
|||
} |
|||
|
|||
t1 = 2 * l - t2; |
|||
|
|||
rgb = [0, 0, 0]; |
|||
for (var i = 0; i < 3; i++) { |
|||
t3 = h + 1 / 3 * -(i - 1); |
|||
if (t3 < 0) { |
|||
t3++; |
|||
} |
|||
if (t3 > 1) { |
|||
t3--; |
|||
} |
|||
|
|||
if (6 * t3 < 1) { |
|||
val = t1 + (t2 - t1) * 6 * t3; |
|||
} else if (2 * t3 < 1) { |
|||
val = t2; |
|||
} else if (3 * t3 < 2) { |
|||
val = t1 + (t2 - t1) * (2 / 3 - t3) * 6; |
|||
} else { |
|||
val = t1; |
|||
} |
|||
|
|||
rgb[i] = val * 255; |
|||
} |
|||
|
|||
return rgb; |
|||
}; |
|||
|
|||
convert.hsl.hsv = function (hsl) { |
|||
var h = hsl[0]; |
|||
var s = hsl[1] / 100; |
|||
var l = hsl[2] / 100; |
|||
var smin = s; |
|||
var lmin = Math.max(l, 0.01); |
|||
var sv; |
|||
var v; |
|||
|
|||
l *= 2; |
|||
s *= (l <= 1) ? l : 2 - l; |
|||
smin *= lmin <= 1 ? lmin : 2 - lmin; |
|||
v = (l + s) / 2; |
|||
sv = l === 0 ? (2 * smin) / (lmin + smin) : (2 * s) / (l + s); |
|||
|
|||
return [h, sv * 100, v * 100]; |
|||
}; |
|||
|
|||
convert.hsv.rgb = function (hsv) { |
|||
var h = hsv[0] / 60; |
|||
var s = hsv[1] / 100; |
|||
var v = hsv[2] / 100; |
|||
var hi = Math.floor(h) % 6; |
|||
|
|||
var f = h - Math.floor(h); |
|||
var p = 255 * v * (1 - s); |
|||
var q = 255 * v * (1 - (s * f)); |
|||
var t = 255 * v * (1 - (s * (1 - f))); |
|||
v *= 255; |
|||
|
|||
switch (hi) { |
|||
case 0: |
|||
return [v, t, p]; |
|||
case 1: |
|||
return [q, v, p]; |
|||
case 2: |
|||
return [p, v, t]; |
|||
case 3: |
|||
return [p, q, v]; |
|||
case 4: |
|||
return [t, p, v]; |
|||
case 5: |
|||
return [v, p, q]; |
|||
} |
|||
}; |
|||
|
|||
convert.hsv.hsl = function (hsv) { |
|||
var h = hsv[0]; |
|||
var s = hsv[1] / 100; |
|||
var v = hsv[2] / 100; |
|||
var vmin = Math.max(v, 0.01); |
|||
var lmin; |
|||
var sl; |
|||
var l; |
|||
|
|||
l = (2 - s) * v; |
|||
lmin = (2 - s) * vmin; |
|||
sl = s * vmin; |
|||
sl /= (lmin <= 1) ? lmin : 2 - lmin; |
|||
sl = sl || 0; |
|||
l /= 2; |
|||
|
|||
return [h, sl * 100, l * 100]; |
|||
}; |
|||
|
|||
// http://dev.w3.org/csswg/css-color/#hwb-to-rgb
|
|||
convert.hwb.rgb = function (hwb) { |
|||
var h = hwb[0] / 360; |
|||
var wh = hwb[1] / 100; |
|||
var bl = hwb[2] / 100; |
|||
var ratio = wh + bl; |
|||
var i; |
|||
var v; |
|||
var f; |
|||
var n; |
|||
|
|||
// wh + bl cant be > 1
|
|||
if (ratio > 1) { |
|||
wh /= ratio; |
|||
bl /= ratio; |
|||
} |
|||
|
|||
i = Math.floor(6 * h); |
|||
v = 1 - bl; |
|||
f = 6 * h - i; |
|||
|
|||
if ((i & 0x01) !== 0) { |
|||
f = 1 - f; |
|||
} |
|||
|
|||
n = wh + f * (v - wh); // linear interpolation
|
|||
|
|||
var r; |
|||
var g; |
|||
var b; |
|||
switch (i) { |
|||
default: |
|||
case 6: |
|||
case 0: r = v; g = n; b = wh; break; |
|||
case 1: r = n; g = v; b = wh; break; |
|||
case 2: r = wh; g = v; b = n; break; |
|||
case 3: r = wh; g = n; b = v; break; |
|||
case 4: r = n; g = wh; b = v; break; |
|||
case 5: r = v; g = wh; b = n; break; |
|||
} |
|||
|
|||
return [r * 255, g * 255, b * 255]; |
|||
}; |
|||
|
|||
convert.cmyk.rgb = function (cmyk) { |
|||
var c = cmyk[0] / 100; |
|||
var m = cmyk[1] / 100; |
|||
var y = cmyk[2] / 100; |
|||
var k = cmyk[3] / 100; |
|||
var r; |
|||
var g; |
|||
var b; |
|||
|
|||
r = 1 - Math.min(1, c * (1 - k) + k); |
|||
g = 1 - Math.min(1, m * (1 - k) + k); |
|||
b = 1 - Math.min(1, y * (1 - k) + k); |
|||
|
|||
return [r * 255, g * 255, b * 255]; |
|||
}; |
|||
|
|||
convert.xyz.rgb = function (xyz) { |
|||
var x = xyz[0] / 100; |
|||
var y = xyz[1] / 100; |
|||
var z = xyz[2] / 100; |
|||
var r; |
|||
var g; |
|||
var b; |
|||
|
|||
r = (x * 3.2406) + (y * -1.5372) + (z * -0.4986); |
|||
g = (x * -0.9689) + (y * 1.8758) + (z * 0.0415); |
|||
b = (x * 0.0557) + (y * -0.2040) + (z * 1.0570); |
|||
|
|||
// assume sRGB
|
|||
r = r > 0.0031308 |
|||
? ((1.055 * Math.pow(r, 1.0 / 2.4)) - 0.055) |
|||
: r * 12.92; |
|||
|
|||
g = g > 0.0031308 |
|||
? ((1.055 * Math.pow(g, 1.0 / 2.4)) - 0.055) |
|||
: g * 12.92; |
|||
|
|||
b = b > 0.0031308 |
|||
? ((1.055 * Math.pow(b, 1.0 / 2.4)) - 0.055) |
|||
: b * 12.92; |
|||
|
|||
r = Math.min(Math.max(0, r), 1); |
|||
g = Math.min(Math.max(0, g), 1); |
|||
b = Math.min(Math.max(0, b), 1); |
|||
|
|||
return [r * 255, g * 255, b * 255]; |
|||
}; |
|||
|
|||
convert.xyz.lab = function (xyz) { |
|||
var x = xyz[0]; |
|||
var y = xyz[1]; |
|||
var z = xyz[2]; |
|||
var l; |
|||
var a; |
|||
var b; |
|||
|
|||
x /= 95.047; |
|||
y /= 100; |
|||
z /= 108.883; |
|||
|
|||
x = x > 0.008856 ? Math.pow(x, 1 / 3) : (7.787 * x) + (16 / 116); |
|||
y = y > 0.008856 ? Math.pow(y, 1 / 3) : (7.787 * y) + (16 / 116); |
|||
z = z > 0.008856 ? Math.pow(z, 1 / 3) : (7.787 * z) + (16 / 116); |
|||
|
|||
l = (116 * y) - 16; |
|||
a = 500 * (x - y); |
|||
b = 200 * (y - z); |
|||
|
|||
return [l, a, b]; |
|||
}; |
|||
|
|||
convert.lab.xyz = function (lab) { |
|||
var l = lab[0]; |
|||
var a = lab[1]; |
|||
var b = lab[2]; |
|||
var x; |
|||
var y; |
|||
var z; |
|||
|
|||
y = (l + 16) / 116; |
|||
x = a / 500 + y; |
|||
z = y - b / 200; |
|||
|
|||
var y2 = Math.pow(y, 3); |
|||
var x2 = Math.pow(x, 3); |
|||
var z2 = Math.pow(z, 3); |
|||
y = y2 > 0.008856 ? y2 : (y - 16 / 116) / 7.787; |
|||
x = x2 > 0.008856 ? x2 : (x - 16 / 116) / 7.787; |
|||
z = z2 > 0.008856 ? z2 : (z - 16 / 116) / 7.787; |
|||
|
|||
x *= 95.047; |
|||
y *= 100; |
|||
z *= 108.883; |
|||
|
|||
return [x, y, z]; |
|||
}; |
|||
|
|||
convert.lab.lch = function (lab) { |
|||
var l = lab[0]; |
|||
var a = lab[1]; |
|||
var b = lab[2]; |
|||
var hr; |
|||
var h; |
|||
var c; |
|||
|
|||
hr = Math.atan2(b, a); |
|||
h = hr * 360 / 2 / Math.PI; |
|||
|
|||
if (h < 0) { |
|||
h += 360; |
|||
} |
|||
|
|||
c = Math.sqrt(a * a + b * b); |
|||
|
|||
return [l, c, h]; |
|||
}; |
|||
|
|||
convert.lch.lab = function (lch) { |
|||
var l = lch[0]; |
|||
var c = lch[1]; |
|||
var h = lch[2]; |
|||
var a; |
|||
var b; |
|||
var hr; |
|||
|
|||
hr = h / 360 * 2 * Math.PI; |
|||
a = c * Math.cos(hr); |
|||
b = c * Math.sin(hr); |
|||
|
|||
return [l, a, b]; |
|||
}; |
|||
|
|||
convert.rgb.ansi16 = function (args) { |
|||
var r = args[0]; |
|||
var g = args[1]; |
|||
var b = args[2]; |
|||
var value = 1 in arguments ? arguments[1] : convert.rgb.hsv(args)[2]; // hsv -> ansi16 optimization
|
|||
|
|||
value = Math.round(value / 50); |
|||
|
|||
if (value === 0) { |
|||
return 30; |
|||
} |
|||
|
|||
var ansi = 30 |
|||
+ ((Math.round(b / 255) << 2) |
|||
| (Math.round(g / 255) << 1) |
|||
| Math.round(r / 255)); |
|||
|
|||
if (value === 2) { |
|||
ansi += 60; |
|||
} |
|||
|
|||
return ansi; |
|||
}; |
|||
|
|||
convert.hsv.ansi16 = function (args) { |
|||
// optimization here; we already know the value and don't need to get
|
|||
// it converted for us.
|
|||
return convert.rgb.ansi16(convert.hsv.rgb(args), args[2]); |
|||
}; |
|||
|
|||
convert.rgb.ansi256 = function (args) { |
|||
var r = args[0]; |
|||
var g = args[1]; |
|||
var b = args[2]; |
|||
|
|||
// we use the extended greyscale palette here, with the exception of
|
|||
// black and white. normal palette only has 4 greyscale shades.
|
|||
if (r === g && g === b) { |
|||
if (r < 8) { |
|||
return 16; |
|||
} |
|||
|
|||
if (r > 248) { |
|||
return 231; |
|||
} |
|||
|
|||
return Math.round(((r - 8) / 247) * 24) + 232; |
|||
} |
|||
|
|||
var ansi = 16 |
|||
+ (36 * Math.round(r / 255 * 5)) |
|||
+ (6 * Math.round(g / 255 * 5)) |
|||
+ Math.round(b / 255 * 5); |
|||
|
|||
return ansi; |
|||
}; |
|||
|
|||
convert.ansi16.rgb = function (args) { |
|||
var color = args % 10; |
|||
|
|||
// handle greyscale
|
|||
if (color === 0 || color === 7) { |
|||
if (args > 50) { |
|||
color += 3.5; |
|||
} |
|||
|
|||
color = color / 10.5 * 255; |
|||
|
|||
return [color, color, color]; |
|||
} |
|||
|
|||
var mult = (~~(args > 50) + 1) * 0.5; |
|||
var r = ((color & 1) * mult) * 255; |
|||
var g = (((color >> 1) & 1) * mult) * 255; |
|||
var b = (((color >> 2) & 1) * mult) * 255; |
|||
|
|||
return [r, g, b]; |
|||
}; |
|||
|
|||
convert.ansi256.rgb = function (args) { |
|||
// handle greyscale
|
|||
if (args >= 232) { |
|||
var c = (args - 232) * 10 + 8; |
|||
return [c, c, c]; |
|||
} |
|||
|
|||
args -= 16; |
|||
|
|||
var rem; |
|||
var r = Math.floor(args / 36) / 5 * 255; |
|||
var g = Math.floor((rem = args % 36) / 6) / 5 * 255; |
|||
var b = (rem % 6) / 5 * 255; |
|||
|
|||
return [r, g, b]; |
|||
}; |
|||
|
|||
convert.rgb.hex = function (args) { |
|||
var integer = ((Math.round(args[0]) & 0xFF) << 16) |
|||
+ ((Math.round(args[1]) & 0xFF) << 8) |
|||
+ (Math.round(args[2]) & 0xFF); |
|||
|
|||
var string = integer.toString(16).toUpperCase(); |
|||
return '000000'.substring(string.length) + string; |
|||
}; |
|||
|
|||
convert.hex.rgb = function (args) { |
|||
var match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i); |
|||
if (!match) { |
|||
return [0, 0, 0]; |
|||
} |
|||
|
|||
var colorString = match[0]; |
|||
|
|||
if (match[0].length === 3) { |
|||
colorString = colorString.split('').map(function (char) { |
|||
return char + char; |
|||
}).join(''); |
|||
} |
|||
|
|||
var integer = parseInt(colorString, 16); |
|||
var r = (integer >> 16) & 0xFF; |
|||
var g = (integer >> 8) & 0xFF; |
|||
var b = integer & 0xFF; |
|||
|
|||
return [r, g, b]; |
|||
}; |
|||
|
|||
convert.rgb.hcg = function (rgb) { |
|||
var r = rgb[0] / 255; |
|||
var g = rgb[1] / 255; |
|||
var b = rgb[2] / 255; |
|||
var max = Math.max(Math.max(r, g), b); |
|||
var min = Math.min(Math.min(r, g), b); |
|||
var chroma = (max - min); |
|||
var grayscale; |
|||
var hue; |
|||
|
|||
if (chroma < 1) { |
|||
grayscale = min / (1 - chroma); |
|||
} else { |
|||
grayscale = 0; |
|||
} |
|||
|
|||
if (chroma <= 0) { |
|||
hue = 0; |
|||
} else |
|||
if (max === r) { |
|||
hue = ((g - b) / chroma) % 6; |
|||
} else |
|||
if (max === g) { |
|||
hue = 2 + (b - r) / chroma; |
|||
} else { |
|||
hue = 4 + (r - g) / chroma + 4; |
|||
} |
|||
|
|||
hue /= 6; |
|||
hue %= 1; |
|||
|
|||
return [hue * 360, chroma * 100, grayscale * 100]; |
|||
}; |
|||
|
|||
convert.hsl.hcg = function (hsl) { |
|||
var s = hsl[1] / 100; |
|||
var l = hsl[2] / 100; |
|||
var c = 1; |
|||
var f = 0; |
|||
|
|||
if (l < 0.5) { |
|||
c = 2.0 * s * l; |
|||
} else { |
|||
c = 2.0 * s * (1.0 - l); |
|||
} |
|||
|
|||
if (c < 1.0) { |
|||
f = (l - 0.5 * c) / (1.0 - c); |
|||
} |
|||
|
|||
return [hsl[0], c * 100, f * 100]; |
|||
}; |
|||
|
|||
convert.hsv.hcg = function (hsv) { |
|||
var s = hsv[1] / 100; |
|||
var v = hsv[2] / 100; |
|||
|
|||
var c = s * v; |
|||
var f = 0; |
|||
|
|||
if (c < 1.0) { |
|||
f = (v - c) / (1 - c); |
|||
} |
|||
|
|||
return [hsv[0], c * 100, f * 100]; |
|||
}; |
|||
|
|||
convert.hcg.rgb = function (hcg) { |
|||
var h = hcg[0] / 360; |
|||
var c = hcg[1] / 100; |
|||
var g = hcg[2] / 100; |
|||
|
|||
if (c === 0.0) { |
|||
return [g * 255, g * 255, g * 255]; |
|||
} |
|||
|
|||
var pure = [0, 0, 0]; |
|||
var hi = (h % 1) * 6; |
|||
var v = hi % 1; |
|||
var w = 1 - v; |
|||
var mg = 0; |
|||
|
|||
switch (Math.floor(hi)) { |
|||
case 0: |
|||
pure[0] = 1; pure[1] = v; pure[2] = 0; break; |
|||
case 1: |
|||
pure[0] = w; pure[1] = 1; pure[2] = 0; break; |
|||
case 2: |
|||
pure[0] = 0; pure[1] = 1; pure[2] = v; break; |
|||
case 3: |
|||
pure[0] = 0; pure[1] = w; pure[2] = 1; break; |
|||
case 4: |
|||
pure[0] = v; pure[1] = 0; pure[2] = 1; break; |
|||
default: |
|||
pure[0] = 1; pure[1] = 0; pure[2] = w; |
|||
} |
|||
|
|||
mg = (1.0 - c) * g; |
|||
|
|||
return [ |
|||
(c * pure[0] + mg) * 255, |
|||
(c * pure[1] + mg) * 255, |
|||
(c * pure[2] + mg) * 255 |
|||
]; |
|||
}; |
|||
|
|||
convert.hcg.hsv = function (hcg) { |
|||
var c = hcg[1] / 100; |
|||
var g = hcg[2] / 100; |
|||
|
|||
var v = c + g * (1.0 - c); |
|||
var f = 0; |
|||
|
|||
if (v > 0.0) { |
|||
f = c / v; |
|||
} |
|||
|
|||
return [hcg[0], f * 100, v * 100]; |
|||
}; |
|||
|
|||
convert.hcg.hsl = function (hcg) { |
|||
var c = hcg[1] / 100; |
|||
var g = hcg[2] / 100; |
|||
|
|||
var l = g * (1.0 - c) + 0.5 * c; |
|||
var s = 0; |
|||
|
|||
if (l > 0.0 && l < 0.5) { |
|||
s = c / (2 * l); |
|||
} else |
|||
if (l >= 0.5 && l < 1.0) { |
|||
s = c / (2 * (1 - l)); |
|||
} |
|||
|
|||
return [hcg[0], s * 100, l * 100]; |
|||
}; |
|||
|
|||
convert.hcg.hwb = function (hcg) { |
|||
var c = hcg[1] / 100; |
|||
var g = hcg[2] / 100; |
|||
var v = c + g * (1.0 - c); |
|||
return [hcg[0], (v - c) * 100, (1 - v) * 100]; |
|||
}; |
|||
|
|||
convert.hwb.hcg = function (hwb) { |
|||
var w = hwb[1] / 100; |
|||
var b = hwb[2] / 100; |
|||
var v = 1 - b; |
|||
var c = v - w; |
|||
var g = 0; |
|||
|
|||
if (c < 1) { |
|||
g = (v - c) / (1 - c); |
|||
} |
|||
|
|||
return [hwb[0], c * 100, g * 100]; |
|||
}; |
|||
|
|||
convert.apple.rgb = function (apple) { |
|||
return [(apple[0] / 65535) * 255, (apple[1] / 65535) * 255, (apple[2] / 65535) * 255]; |
|||
}; |
|||
|
|||
convert.rgb.apple = function (rgb) { |
|||
return [(rgb[0] / 255) * 65535, (rgb[1] / 255) * 65535, (rgb[2] / 255) * 65535]; |
|||
}; |
|||
|
|||
convert.gray.rgb = function (args) { |
|||
return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255]; |
|||
}; |
|||
|
|||
convert.gray.hsl = convert.gray.hsv = function (args) { |
|||
return [0, 0, args[0]]; |
|||
}; |
|||
|
|||
convert.gray.hwb = function (gray) { |
|||
return [0, 100, gray[0]]; |
|||
}; |
|||
|
|||
convert.gray.cmyk = function (gray) { |
|||
return [0, 0, 0, gray[0]]; |
|||
}; |
|||
|
|||
convert.gray.lab = function (gray) { |
|||
return [gray[0], 0, 0]; |
|||
}; |
|||
|
|||
convert.gray.hex = function (gray) { |
|||
var val = Math.round(gray[0] / 100 * 255) & 0xFF; |
|||
var integer = (val << 16) + (val << 8) + val; |
|||
|
|||
var string = integer.toString(16).toUpperCase(); |
|||
return '000000'.substring(string.length) + string; |
|||
}; |
|||
|
|||
convert.rgb.gray = function (rgb) { |
|||
var val = (rgb[0] + rgb[1] + rgb[2]) / 3; |
|||
return [val / 255 * 100]; |
|||
}; |
@ -0,0 +1,78 @@ |
|||
var conversions = require('./conversions'); |
|||
var route = require('./route'); |
|||
|
|||
var convert = {}; |
|||
|
|||
var models = Object.keys(conversions); |
|||
|
|||
function wrapRaw(fn) { |
|||
var wrappedFn = function (args) { |
|||
if (args === undefined || args === null) { |
|||
return args; |
|||
} |
|||
|
|||
if (arguments.length > 1) { |
|||
args = Array.prototype.slice.call(arguments); |
|||
} |
|||
|
|||
return fn(args); |
|||
}; |
|||
|
|||
// preserve .conversion property if there is one
|
|||
if ('conversion' in fn) { |
|||
wrappedFn.conversion = fn.conversion; |
|||
} |
|||
|
|||
return wrappedFn; |
|||
} |
|||
|
|||
function wrapRounded(fn) { |
|||
var wrappedFn = function (args) { |
|||
if (args === undefined || args === null) { |
|||
return args; |
|||
} |
|||
|
|||
if (arguments.length > 1) { |
|||
args = Array.prototype.slice.call(arguments); |
|||
} |
|||
|
|||
var result = fn(args); |
|||
|
|||
// we're assuming the result is an array here.
|
|||
// see notice in conversions.js; don't use box types
|
|||
// in conversion functions.
|
|||
if (typeof result === 'object') { |
|||
for (var len = result.length, i = 0; i < len; i++) { |
|||
result[i] = Math.round(result[i]); |
|||
} |
|||
} |
|||
|
|||
return result; |
|||
}; |
|||
|
|||
// preserve .conversion property if there is one
|
|||
if ('conversion' in fn) { |
|||
wrappedFn.conversion = fn.conversion; |
|||
} |
|||
|
|||
return wrappedFn; |
|||
} |
|||
|
|||
models.forEach(function (fromModel) { |
|||
convert[fromModel] = {}; |
|||
|
|||
Object.defineProperty(convert[fromModel], 'channels', {value: conversions[fromModel].channels}); |
|||
Object.defineProperty(convert[fromModel], 'labels', {value: conversions[fromModel].labels}); |
|||
|
|||
var routes = route(fromModel); |
|||
var routeModels = Object.keys(routes); |
|||
|
|||
routeModels.forEach(function (toModel) { |
|||
var fn = routes[toModel]; |
|||
|
|||
convert[fromModel][toModel] = wrapRounded(fn); |
|||
convert[fromModel][toModel].raw = wrapRaw(fn); |
|||
}); |
|||
}); |
|||
|
|||
module.exports = convert; |
@ -0,0 +1,81 @@ |
|||
{ |
|||
"_from": "color-convert@^1.9.0", |
|||
"_id": "color-convert@1.9.3", |
|||
"_inBundle": false, |
|||
"_integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", |
|||
"_location": "/color-convert", |
|||
"_phantomChildren": {}, |
|||
"_requested": { |
|||
"type": "range", |
|||
"registry": true, |
|||
"raw": "color-convert@^1.9.0", |
|||
"name": "color-convert", |
|||
"escapedName": "color-convert", |
|||
"rawSpec": "^1.9.0", |
|||
"saveSpec": null, |
|||
"fetchSpec": "^1.9.0" |
|||
}, |
|||
"_requiredBy": [ |
|||
"/ansi-styles" |
|||
], |
|||
"_resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", |
|||
"_shasum": "bb71850690e1f136567de629d2d5471deda4c1e8", |
|||
"_spec": "color-convert@^1.9.0", |
|||
"_where": "E:\\mu_dist\\@xyx\\beer\\test-command\\node_modules\\ansi-styles", |
|||
"author": { |
|||
"name": "Heather Arthur", |
|||
"email": "fayearthur@gmail.com" |
|||
}, |
|||
"bugs": { |
|||
"url": "https://github.com/Qix-/color-convert/issues" |
|||
}, |
|||
"bundleDependencies": false, |
|||
"dependencies": { |
|||
"color-name": "1.1.3" |
|||
}, |
|||
"deprecated": false, |
|||
"description": "Plain color conversion functions", |
|||
"devDependencies": { |
|||
"chalk": "1.1.1", |
|||
"xo": "0.11.2" |
|||
}, |
|||
"files": [ |
|||
"index.js", |
|||
"conversions.js", |
|||
"css-keywords.js", |
|||
"route.js" |
|||
], |
|||
"homepage": "https://github.com/Qix-/color-convert#readme", |
|||
"keywords": [ |
|||
"color", |
|||
"colour", |
|||
"convert", |
|||
"converter", |
|||
"conversion", |
|||
"rgb", |
|||
"hsl", |
|||
"hsv", |
|||
"hwb", |
|||
"cmyk", |
|||
"ansi", |
|||
"ansi16" |
|||
], |
|||
"license": "MIT", |
|||
"name": "color-convert", |
|||
"repository": { |
|||
"type": "git", |
|||
"url": "git+https://github.com/Qix-/color-convert.git" |
|||
}, |
|||
"scripts": { |
|||
"pretest": "xo", |
|||
"test": "node test/basic.js" |
|||
}, |
|||
"version": "1.9.3", |
|||
"xo": { |
|||
"rules": { |
|||
"default-case": 0, |
|||
"no-inline-comments": 0, |
|||
"operator-linebreak": 0 |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,97 @@ |
|||
var conversions = require('./conversions'); |
|||
|
|||
/* |
|||
this function routes a model to all other models. |
|||
|
|||
all functions that are routed have a property `.conversion` attached |
|||
to the returned synthetic function. This property is an array |
|||
of strings, each with the steps in between the 'from' and 'to' |
|||
color models (inclusive). |
|||
|
|||
conversions that are not possible simply are not included. |
|||
*/ |
|||
|
|||
function buildGraph() { |
|||
var graph = {}; |
|||
// https://jsperf.com/object-keys-vs-for-in-with-closure/3
|
|||
var models = Object.keys(conversions); |
|||
|
|||
for (var len = models.length, i = 0; i < len; i++) { |
|||
graph[models[i]] = { |
|||
// http://jsperf.com/1-vs-infinity
|
|||
// micro-opt, but this is simple.
|
|||
distance: -1, |
|||
parent: null |
|||
}; |
|||
} |
|||
|
|||
return graph; |
|||
} |
|||
|
|||
// https://en.wikipedia.org/wiki/Breadth-first_search
|
|||
function deriveBFS(fromModel) { |
|||
var graph = buildGraph(); |
|||
var queue = [fromModel]; // unshift -> queue -> pop
|
|||
|
|||
graph[fromModel].distance = 0; |
|||
|
|||
while (queue.length) { |
|||
var current = queue.pop(); |
|||
var adjacents = Object.keys(conversions[current]); |
|||
|
|||
for (var len = adjacents.length, i = 0; i < len; i++) { |
|||
var adjacent = adjacents[i]; |
|||
var node = graph[adjacent]; |
|||
|
|||
if (node.distance === -1) { |
|||
node.distance = graph[current].distance + 1; |
|||
node.parent = current; |
|||
queue.unshift(adjacent); |
|||
} |
|||
} |
|||
} |
|||
|
|||
return graph; |
|||
} |
|||
|
|||
function link(from, to) { |
|||
return function (args) { |
|||
return to(from(args)); |
|||
}; |
|||
} |
|||
|
|||
function wrapConversion(toModel, graph) { |
|||
var path = [graph[toModel].parent, toModel]; |
|||
var fn = conversions[graph[toModel].parent][toModel]; |
|||
|
|||
var cur = graph[toModel].parent; |
|||
while (graph[cur].parent) { |
|||
path.unshift(graph[cur].parent); |
|||
fn = link(conversions[graph[cur].parent][cur], fn); |
|||
cur = graph[cur].parent; |
|||
} |
|||
|
|||
fn.conversion = path; |
|||
return fn; |
|||
} |
|||
|
|||
module.exports = function (fromModel) { |
|||
var graph = deriveBFS(fromModel); |
|||
var conversion = {}; |
|||
|
|||
var models = Object.keys(graph); |
|||
for (var len = models.length, i = 0; i < len; i++) { |
|||
var toModel = models[i]; |
|||
var node = graph[toModel]; |
|||
|
|||
if (node.parent === null) { |
|||
// no possible conversion, or this node is the source model.
|
|||
continue; |
|||
} |
|||
|
|||
conversion[toModel] = wrapConversion(toModel, graph); |
|||
} |
|||
|
|||
return conversion; |
|||
}; |
|||
|
@ -0,0 +1,43 @@ |
|||
{ |
|||
"env": { |
|||
"browser": true, |
|||
"node": true, |
|||
"commonjs": true, |
|||
"es6": true |
|||
}, |
|||
"extends": "eslint:recommended", |
|||
"rules": { |
|||
"strict": 2, |
|||
"indent": 0, |
|||
"linebreak-style": 0, |
|||
"quotes": 0, |
|||
"semi": 0, |
|||
"no-cond-assign": 1, |
|||
"no-constant-condition": 1, |
|||
"no-duplicate-case": 1, |
|||
"no-empty": 1, |
|||
"no-ex-assign": 1, |
|||
"no-extra-boolean-cast": 1, |
|||
"no-extra-semi": 1, |
|||
"no-fallthrough": 1, |
|||
"no-func-assign": 1, |
|||
"no-global-assign": 1, |
|||
"no-implicit-globals": 2, |
|||
"no-inner-declarations": ["error", "functions"], |
|||
"no-irregular-whitespace": 2, |
|||
"no-loop-func": 1, |
|||
"no-multi-str": 1, |
|||
"no-mixed-spaces-and-tabs": 1, |
|||
"no-proto": 1, |
|||
"no-sequences": 1, |
|||
"no-throw-literal": 1, |
|||
"no-unmodified-loop-condition": 1, |
|||
"no-useless-call": 1, |
|||
"no-void": 1, |
|||
"no-with": 2, |
|||
"wrap-iife": 1, |
|||
"no-redeclare": 1, |
|||
"no-unused-vars": ["error", { "vars": "all", "args": "none" }], |
|||
"no-sparse-arrays": 1 |
|||
} |
|||
} |
@ -0,0 +1,107 @@ |
|||
//this will affect all the git repos |
|||
git config --global core.excludesfile ~/.gitignore |
|||
|
|||
|
|||
//update files since .ignore won't if already tracked |
|||
git rm --cached <file> |
|||
|
|||
# Compiled source # |
|||
################### |
|||
*.com |
|||
*.class |
|||
*.dll |
|||
*.exe |
|||
*.o |
|||
*.so |
|||
|
|||
# Packages # |
|||
############ |
|||
# it's better to unpack these files and commit the raw source |
|||
# git has its own built in compression methods |
|||
*.7z |
|||
*.dmg |
|||
*.gz |
|||
*.iso |
|||
*.jar |
|||
*.rar |
|||
*.tar |
|||
*.zip |
|||
|
|||
# Logs and databases # |
|||
###################### |
|||
*.log |
|||
*.sql |
|||
*.sqlite |
|||
|
|||
# OS generated files # |
|||
###################### |
|||
.DS_Store |
|||
.DS_Store? |
|||
._* |
|||
.Spotlight-V100 |
|||
.Trashes |
|||
# Icon? |
|||
ehthumbs.db |
|||
Thumbs.db |
|||
.cache |
|||
.project |
|||
.settings |
|||
.tmproj |
|||
*.esproj |
|||
nbproject |
|||
|
|||
# Numerous always-ignore extensions # |
|||
##################################### |
|||
*.diff |
|||
*.err |
|||
*.orig |
|||
*.rej |
|||
*.swn |
|||
*.swo |
|||
*.swp |
|||
*.vi |
|||
*~ |
|||
*.sass-cache |
|||
*.grunt |
|||
*.tmp |
|||
|
|||
# Dreamweaver added files # |
|||
########################### |
|||
_notes |
|||
dwsync.xml |
|||
|
|||
# Komodo # |
|||
########################### |
|||
*.komodoproject |
|||
.komodotools |
|||
|
|||
# Node # |
|||
##################### |
|||
node_modules |
|||
|
|||
# Bower # |
|||
##################### |
|||
bower_components |
|||
|
|||
# Folders to ignore # |
|||
##################### |
|||
.hg |
|||
.svn |
|||
.CVS |
|||
intermediate |
|||
publish |
|||
.idea |
|||
.graphics |
|||
_test |
|||
_archive |
|||
uploads |
|||
tmp |
|||
|
|||
# Vim files to ignore # |
|||
####################### |
|||
.VimballRecord |
|||
.netrwhist |
|||
|
|||
bundle.* |
|||
|
|||
_demo |
@ -0,0 +1,8 @@ |
|||
The MIT License (MIT) |
|||
Copyright (c) 2015 Dmitry Ivanov |
|||
|
|||
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,11 @@ |
|||
A JSON with color names and its values. Based on http://dev.w3.org/csswg/css-color/#named-colors. |
|||
|
|||
[](https://nodei.co/npm/color-name/) |
|||
|
|||
|
|||
```js |
|||
var colors = require('color-name'); |
|||
colors.red //[255,0,0] |
|||
``` |
|||
|
|||
<a href="LICENSE"><img src="https://upload.wikimedia.org/wikipedia/commons/0/0c/MIT_logo.svg" width="120"/></a> |
@ -0,0 +1,152 @@ |
|||
'use strict' |
|||
|
|||
module.exports = { |
|||
"aliceblue": [240, 248, 255], |
|||
"antiquewhite": [250, 235, 215], |
|||
"aqua": [0, 255, 255], |
|||
"aquamarine": [127, 255, 212], |
|||
"azure": [240, 255, 255], |
|||
"beige": [245, 245, 220], |
|||
"bisque": [255, 228, 196], |
|||
"black": [0, 0, 0], |
|||
"blanchedalmond": [255, 235, 205], |
|||
"blue": [0, 0, 255], |
|||
"blueviolet": [138, 43, 226], |
|||
"brown": [165, 42, 42], |
|||
"burlywood": [222, 184, 135], |
|||
"cadetblue": [95, 158, 160], |
|||
"chartreuse": [127, 255, 0], |
|||
"chocolate": [210, 105, 30], |
|||
"coral": [255, 127, 80], |
|||
"cornflowerblue": [100, 149, 237], |
|||
"cornsilk": [255, 248, 220], |
|||
"crimson": [220, 20, 60], |
|||
"cyan": [0, 255, 255], |
|||
"darkblue": [0, 0, 139], |
|||
"darkcyan": [0, 139, 139], |
|||
"darkgoldenrod": [184, 134, 11], |
|||
"darkgray": [169, 169, 169], |
|||
"darkgreen": [0, 100, 0], |
|||
"darkgrey": [169, 169, 169], |
|||
"darkkhaki": [189, 183, 107], |
|||
"darkmagenta": [139, 0, 139], |
|||
"darkolivegreen": [85, 107, 47], |
|||
"darkorange": [255, 140, 0], |
|||
"darkorchid": [153, 50, 204], |
|||
"darkred": [139, 0, 0], |
|||
"darksalmon": [233, 150, 122], |
|||
"darkseagreen": [143, 188, 143], |
|||
"darkslateblue": [72, 61, 139], |
|||
"darkslategray": [47, 79, 79], |
|||
"darkslategrey": [47, 79, 79], |
|||
"darkturquoise": [0, 206, 209], |
|||
"darkviolet": [148, 0, 211], |
|||
"deeppink": [255, 20, 147], |
|||
"deepskyblue": [0, 191, 255], |
|||
"dimgray": [105, 105, 105], |
|||
"dimgrey": [105, 105, 105], |
|||
"dodgerblue": [30, 144, 255], |
|||
"firebrick": [178, 34, 34], |
|||
"floralwhite": [255, 250, 240], |
|||
"forestgreen": [34, 139, 34], |
|||
"fuchsia": [255, 0, 255], |
|||
"gainsboro": [220, 220, 220], |
|||
"ghostwhite": [248, 248, 255], |
|||
"gold": [255, 215, 0], |
|||
"goldenrod": [218, 165, 32], |
|||
"gray": [128, 128, 128], |
|||
"green": [0, 128, 0], |
|||
"greenyellow": [173, 255, 47], |
|||
"grey": [128, 128, 128], |
|||
"honeydew": [240, 255, 240], |
|||
"hotpink": [255, 105, 180], |
|||
"indianred": [205, 92, 92], |
|||
"indigo": [75, 0, 130], |
|||
"ivory": [255, 255, 240], |
|||
"khaki": [240, 230, 140], |
|||
"lavender": [230, 230, 250], |
|||
"lavenderblush": [255, 240, 245], |
|||
"lawngreen": [124, 252, 0], |
|||
"lemonchiffon": [255, 250, 205], |
|||
"lightblue": [173, 216, 230], |
|||
"lightcoral": [240, 128, 128], |
|||
"lightcyan": [224, 255, 255], |
|||
"lightgoldenrodyellow": [250, 250, 210], |
|||
"lightgray": [211, 211, 211], |
|||
"lightgreen": [144, 238, 144], |
|||
"lightgrey": [211, 211, 211], |
|||
"lightpink": [255, 182, 193], |
|||
"lightsalmon": [255, 160, 122], |
|||
"lightseagreen": [32, 178, 170], |
|||
"lightskyblue": [135, 206, 250], |
|||
"lightslategray": [119, 136, 153], |
|||
"lightslategrey": [119, 136, 153], |
|||
"lightsteelblue": [176, 196, 222], |
|||
"lightyellow": [255, 255, 224], |
|||
"lime": [0, 255, 0], |
|||
"limegreen": [50, 205, 50], |
|||
"linen": [250, 240, 230], |
|||
"magenta": [255, 0, 255], |
|||
"maroon": [128, 0, 0], |
|||
"mediumaquamarine": [102, 205, 170], |
|||
"mediumblue": [0, 0, 205], |
|||
"mediumorchid": [186, 85, 211], |
|||
"mediumpurple": [147, 112, 219], |
|||
"mediumseagreen": [60, 179, 113], |
|||
"mediumslateblue": [123, 104, 238], |
|||
"mediumspringgreen": [0, 250, 154], |
|||
"mediumturquoise": [72, 209, 204], |
|||
"mediumvioletred": [199, 21, 133], |
|||
"midnightblue": [25, 25, 112], |
|||
"mintcream": [245, 255, 250], |
|||
"mistyrose": [255, 228, 225], |
|||
"moccasin": [255, 228, 181], |
|||
"navajowhite": [255, 222, 173], |
|||
"navy": [0, 0, 128], |
|||
"oldlace": [253, 245, 230], |
|||
"olive": [128, 128, 0], |
|||
"olivedrab": [107, 142, 35], |
|||
"orange": [255, 165, 0], |
|||
"orangered": [255, 69, 0], |
|||
"orchid": [218, 112, 214], |
|||
"palegoldenrod": [238, 232, 170], |
|||
"palegreen": [152, 251, 152], |
|||
"paleturquoise": [175, 238, 238], |
|||
"palevioletred": [219, 112, 147], |
|||
"papayawhip": [255, 239, 213], |
|||
"peachpuff": [255, 218, 185], |
|||
"peru": [205, 133, 63], |
|||
"pink": [255, 192, 203], |
|||
"plum": [221, 160, 221], |
|||
"powderblue": [176, 224, 230], |
|||
"purple": [128, 0, 128], |
|||
"rebeccapurple": [102, 51, 153], |
|||
"red": [255, 0, 0], |
|||
"rosybrown": [188, 143, 143], |
|||
"royalblue": [65, 105, 225], |
|||
"saddlebrown": [139, 69, 19], |
|||
"salmon": [250, 128, 114], |
|||
"sandybrown": [244, 164, 96], |
|||
"seagreen": [46, 139, 87], |
|||
"seashell": [255, 245, 238], |
|||
"sienna": [160, 82, 45], |
|||
"silver": [192, 192, 192], |
|||
"skyblue": [135, 206, 235], |
|||
"slateblue": [106, 90, 205], |
|||
"slategray": [112, 128, 144], |
|||
"slategrey": [112, 128, 144], |
|||
"snow": [255, 250, 250], |
|||
"springgreen": [0, 255, 127], |
|||
"steelblue": [70, 130, 180], |
|||
"tan": [210, 180, 140], |
|||
"teal": [0, 128, 128], |
|||
"thistle": [216, 191, 216], |
|||
"tomato": [255, 99, 71], |
|||
"turquoise": [64, 224, 208], |
|||
"violet": [238, 130, 238], |
|||
"wheat": [245, 222, 179], |
|||
"white": [255, 255, 255], |
|||
"whitesmoke": [245, 245, 245], |
|||
"yellow": [255, 255, 0], |
|||
"yellowgreen": [154, 205, 50] |
|||
}; |
@ -0,0 +1,53 @@ |
|||
{ |
|||
"_from": "color-name@1.1.3", |
|||
"_id": "color-name@1.1.3", |
|||
"_inBundle": false, |
|||
"_integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=", |
|||
"_location": "/color-name", |
|||
"_phantomChildren": {}, |
|||
"_requested": { |
|||
"type": "version", |
|||
"registry": true, |
|||
"raw": "color-name@1.1.3", |
|||
"name": "color-name", |
|||
"escapedName": "color-name", |
|||
"rawSpec": "1.1.3", |
|||
"saveSpec": null, |
|||
"fetchSpec": "1.1.3" |
|||
}, |
|||
"_requiredBy": [ |
|||
"/color-convert" |
|||
], |
|||
"_resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", |
|||
"_shasum": "a7d0558bd89c42f795dd42328f740831ca53bc25", |
|||
"_spec": "color-name@1.1.3", |
|||
"_where": "E:\\mu_dist\\@xyx\\beer\\test-command\\node_modules\\color-convert", |
|||
"author": { |
|||
"name": "DY", |
|||
"email": "dfcreative@gmail.com" |
|||
}, |
|||
"bugs": { |
|||
"url": "https://github.com/dfcreative/color-name/issues" |
|||
}, |
|||
"bundleDependencies": false, |
|||
"deprecated": false, |
|||
"description": "A list of color names and its values", |
|||
"homepage": "https://github.com/dfcreative/color-name", |
|||
"keywords": [ |
|||
"color-name", |
|||
"color", |
|||
"color-keyword", |
|||
"keyword" |
|||
], |
|||
"license": "MIT", |
|||
"main": "index.js", |
|||
"name": "color-name", |
|||
"repository": { |
|||
"type": "git", |
|||
"url": "git+ssh://git@github.com/dfcreative/color-name.git" |
|||
}, |
|||
"scripts": { |
|||
"test": "node test.js" |
|||
}, |
|||
"version": "1.1.3" |
|||
} |
@ -0,0 +1,7 @@ |
|||
'use strict' |
|||
|
|||
var names = require('./'); |
|||
var assert = require('assert'); |
|||
|
|||
assert.deepEqual(names.red, [255,0,0]); |
|||
assert.deepEqual(names.aliceblue, [240,248,255]); |
@ -0,0 +1,538 @@ |
|||
# Changelog |
|||
|
|||
All notable changes to this project will be documented in this file. |
|||
|
|||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) |
|||
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). (Format adopted after v3.0.0.) |
|||
|
|||
<!-- markdownlint-disable MD024 --> |
|||
|
|||
## [4.0.1] (2019-11-12) |
|||
|
|||
### Fixed |
|||
|
|||
* display help when requested, even if there are missing required options [(#1091)] |
|||
|
|||
## [4.0.0] (2019-11-02) |
|||
|
|||
### Added |
|||
|
|||
* automatically wrap and indent help descriptions for options and commands ([#1051]) |
|||
* `.exitOverride()` allows override of calls to `process.exit` for additional error handling and to keep program running ([#1040]) |
|||
* support for declaring required options with `.requiredOptions()` ([#1071]) |
|||
* GitHub Actions support ([#1027]) |
|||
* translation links in README |
|||
|
|||
### Changed |
|||
|
|||
* dev: switch tests from Sinon+Should to Jest with major rewrite of tests ([#1035]) |
|||
* call default subcommand even when there are unknown options ([#1047]) |
|||
* *Breaking* Commander is only officially supported on Node 8 and above, and requires Node 6 ([#1053]) |
|||
|
|||
### Fixed |
|||
|
|||
* *Breaking* keep command object out of program.args when action handler called ([#1048]) |
|||
* also, action handler now passed array of unknown arguments |
|||
* complain about unknown options when program argument supplied and action handler ([#1049]) |
|||
* this changes parameters to `command:*` event to include unknown arguments |
|||
* removed deprecated `customFds` option from call to `child_process.spawn` ([#1052]) |
|||
* rework TypeScript declarations to bring all types into imported namespace ([#1081]) |
|||
|
|||
### Migration Tips |
|||
|
|||
#### Testing for no arguments |
|||
|
|||
If you were previously using code like: |
|||
|
|||
```js |
|||
if (!program.args.length) ... |
|||
``` |
|||
|
|||
a partial replacement is: |
|||
|
|||
```js |
|||
if (program.rawArgs.length < 3) ... |
|||
``` |
|||
|
|||
## [4.0.0-1] Prerelease (2019-10-08) |
|||
|
|||
(Released in 4.0.0) |
|||
|
|||
## [4.0.0-0] Prerelease (2019-10-01) |
|||
|
|||
(Released in 4.0.0) |
|||
|
|||
## [2.20.1] (2019-09-29) |
|||
|
|||
### Fixed |
|||
|
|||
* Improve tracking of executable subcommands. |
|||
|
|||
### Changed |
|||
|
|||
* update development dependencies |
|||
|
|||
## [3.0.2] (2019-09-27) |
|||
|
|||
### Fixed |
|||
|
|||
* Improve tracking of executable subcommands. |
|||
|
|||
### Changed |
|||
|
|||
* update development dependencies |
|||
|
|||
## [3.0.1] (2019-08-30) |
|||
|
|||
### Added |
|||
|
|||
* .name and .usage to README ([#1010]) |
|||
* Table of Contents to README ([#1010]) |
|||
* TypeScript definition for `executableFile` in CommandOptions ([#1028]) |
|||
|
|||
### Changed |
|||
|
|||
* consistently use `const` rather than `var` in README ([#1026]) |
|||
|
|||
### Fixed |
|||
|
|||
* help for sub commands with custom executableFile ([#1018]) |
|||
|
|||
## [3.0.0] / 2019-08-08 |
|||
|
|||
* Add option to specify executable file name ([#999]) |
|||
* e.g. `.command('clone', 'clone description', { executableFile: 'myClone' })` |
|||
* Change docs for `.command` to contrast action handler vs git-style executable. ([#938] [#990]) |
|||
* **Breaking** Change TypeScript to use overloaded function for `.command`. ([#938] [#990]) |
|||
* Change to use straight quotes around strings in error messages (like 'this' instead of `this') ([#915]) |
|||
* Add TypeScript "reference types" for node ([#974]) |
|||
* Add support for hyphen as an option argument in subcommands ([#697]) |
|||
* Add support for a short option flag and its value to be concatenated for action handler subcommands ([#599]) |
|||
* e.g. `-p 80` can also be supplied as `-p80` |
|||
* Add executable arguments to spawn in win32, for git-style executables ([#611]) |
|||
* e.g. `node --harmony myCommand.js clone` |
|||
* Add parent command as prefix of subcommand in help ([#980]) |
|||
* Add optional custom description to `.version` ([#963]) |
|||
* e.g. `program.version('0.0.1', '-v, --vers', 'output the current version')` |
|||
* Add `.helpOption(flags, description)` routine to customise help flags and description ([#963]) |
|||
* e.g. `.helpOption('-e, --HELP', 'read more information')` |
|||
* Fix behavior of --no-* options ([#795]) |
|||
* can now define both `--foo` and `--no-foo` |
|||
* **Breaking** custom event listeners: `--no-foo` on cli now emits `option:no-foo` (previously `option:foo`) |
|||
* **Breaking** default value: defining `--no-foo` after defining `--foo` leaves the default value unchanged (previously set it to false) |
|||
* allow boolean default value, such as from environment ([#987]) |
|||
* Increment inspector port for spawned subcommands ([#991]) |
|||
* e.g. `node --inspect myCommand.js clone` |
|||
|
|||
### Migration Tips |
|||
|
|||
The custom event for a negated option like `--no-foo` is `option:no-foo` (previously `option:foo`). |
|||
|
|||
```js |
|||
program |
|||
.option('--no-foo') |
|||
.on('option:no-foo', () => { |
|||
console.log('removing foo'); |
|||
}); |
|||
``` |
|||
|
|||
When using TypeScript, adding a command does not allow an explicit `undefined` for an unwanted executable description (e.g |
|||
for a command with an action handler). |
|||
|
|||
```js |
|||
program |
|||
.command('action1', undefined, { noHelp: true }) // No longer valid |
|||
.command('action2', { noHelp: true }) // Correct |
|||
``` |
|||
|
|||
## 3.0.0-0 Prerelease / 2019-07-28 |
|||
|
|||
(Released as 3.0.0) |
|||
|
|||
## 2.20.0 / 2019-04-02 |
|||
|
|||
* fix: resolve symbolic links completely when hunting for subcommands (#935) |
|||
* Update index.d.ts (#930) |
|||
* Update Readme.md (#924) |
|||
* Remove --save option as it isn't required anymore (#918) |
|||
* Add link to the license file (#900) |
|||
* Added example of receiving args from options (#858) |
|||
* Added missing semicolon (#882) |
|||
* Add extension to .eslintrc (#876) |
|||
|
|||
## 2.19.0 / 2018-10-02 |
|||
|
|||
* Removed newline after Options and Commands headers (#864) |
|||
* Bugfix - Error output (#862) |
|||
* Fix to change default value to string (#856) |
|||
|
|||
## 2.18.0 / 2018-09-07 |
|||
|
|||
* Standardize help output (#853) |
|||
* chmod 644 travis.yml (#851) |
|||
* add support for execute typescript subcommand via ts-node (#849) |
|||
|
|||
## 2.17.1 / 2018-08-07 |
|||
|
|||
* Fix bug in command emit (#844) |
|||
|
|||
## 2.17.0 / 2018-08-03 |
|||
|
|||
* fixed newline output after help information (#833) |
|||
* Fix to emit the action even without command (#778) |
|||
* npm update (#823) |
|||
|
|||
## 2.16.0 / 2018-06-29 |
|||
|
|||
* Remove Makefile and `test/run` (#821) |
|||
* Make 'npm test' run on Windows (#820) |
|||
* Add badge to display install size (#807) |
|||
* chore: cache node_modules (#814) |
|||
* chore: remove Node.js 4 (EOL), add Node.js 10 (#813) |
|||
* fixed typo in readme (#812) |
|||
* Fix types (#804) |
|||
* Update eslint to resolve vulnerabilities in lodash (#799) |
|||
* updated readme with custom event listeners. (#791) |
|||
* fix tests (#794) |
|||
|
|||
## 2.15.0 / 2018-03-07 |
|||
|
|||
* Update downloads badge to point to graph of downloads over time instead of duplicating link to npm |
|||
* Arguments description |
|||
|
|||
## 2.14.1 / 2018-02-07 |
|||
|
|||
* Fix typing of help function |
|||
|
|||
## 2.14.0 / 2018-02-05 |
|||
|
|||
* only register the option:version event once |
|||
* Fixes issue #727: Passing empty string for option on command is set to undefined |
|||
* enable eqeqeq rule |
|||
* resolves #754 add linter configuration to project |
|||
* resolves #560 respect custom name for version option |
|||
* document how to override the version flag |
|||
* document using options per command |
|||
|
|||
## 2.13.0 / 2018-01-09 |
|||
|
|||
* Do not print default for --no- |
|||
* remove trailing spaces in command help |
|||
* Update CI's Node.js to LTS and latest version |
|||
* typedefs: Command and Option types added to commander namespace |
|||
|
|||
## 2.12.2 / 2017-11-28 |
|||
|
|||
* fix: typings are not shipped |
|||
|
|||
## 2.12.1 / 2017-11-23 |
|||
|
|||
* Move @types/node to dev dependency |
|||
|
|||
## 2.12.0 / 2017-11-22 |
|||
|
|||
* add attributeName() method to Option objects |
|||
* Documentation updated for options with --no prefix |
|||
* typings: `outputHelp` takes a string as the first parameter |
|||
* typings: use overloads |
|||
* feat(typings): update to match js api |
|||
* Print default value in option help |
|||
* Fix translation error |
|||
* Fail when using same command and alias (#491) |
|||
* feat(typings): add help callback |
|||
* fix bug when description is add after command with options (#662) |
|||
* Format js code |
|||
* Rename History.md to CHANGELOG.md (#668) |
|||
* feat(typings): add typings to support TypeScript (#646) |
|||
* use current node |
|||
|
|||
## 2.11.0 / 2017-07-03 |
|||
|
|||
* Fix help section order and padding (#652) |
|||
* feature: support for signals to subcommands (#632) |
|||
* Fixed #37, --help should not display first (#447) |
|||
* Fix translation errors. (#570) |
|||
* Add package-lock.json |
|||
* Remove engines |
|||
* Upgrade package version |
|||
* Prefix events to prevent conflicts between commands and options (#494) |
|||
* Removing dependency on graceful-readlink |
|||
* Support setting name in #name function and make it chainable |
|||
* Add .vscode directory to .gitignore (Visual Studio Code metadata) |
|||
* Updated link to ruby commander in readme files |
|||
|
|||
## 2.10.0 / 2017-06-19 |
|||
|
|||
* Update .travis.yml. drop support for older node.js versions. |
|||
* Fix require arguments in README.md |
|||
* On SemVer you do not start from 0.0.1 |
|||
* Add missing semi colon in readme |
|||
* Add save param to npm install |
|||
* node v6 travis test |
|||
* Update Readme_zh-CN.md |
|||
* Allow literal '--' to be passed-through as an argument |
|||
* Test subcommand alias help |
|||
* link build badge to master branch |
|||
* Support the alias of Git style sub-command |
|||
* added keyword commander for better search result on npm |
|||
* Fix Sub-Subcommands |
|||
* test node.js stable |
|||
* Fixes TypeError when a command has an option called `--description` |
|||
* Update README.md to make it beginner friendly and elaborate on the difference between angled and square brackets. |
|||
* Add chinese Readme file |
|||
|
|||
## 2.9.0 / 2015-10-13 |
|||
|
|||
* Add option `isDefault` to set default subcommand #415 @Qix- |
|||
* Add callback to allow filtering or post-processing of help text #434 @djulien |
|||
* Fix `undefined` text in help information close #414 #416 @zhiyelee |
|||
|
|||
## 2.8.1 / 2015-04-22 |
|||
|
|||
* Back out `support multiline description` Close #396 #397 |
|||
|
|||
## 2.8.0 / 2015-04-07 |
|||
|
|||
* Add `process.execArg` support, execution args like `--harmony` will be passed to sub-commands #387 @DigitalIO @zhiyelee |
|||
* Fix bug in Git-style sub-commands #372 @zhiyelee |
|||
* Allow commands to be hidden from help #383 @tonylukasavage |
|||
* When git-style sub-commands are in use, yet none are called, display help #382 @claylo |
|||
* Add ability to specify arguments syntax for top-level command #258 @rrthomas |
|||
* Support multiline descriptions #208 @zxqfox |
|||
|
|||
## 2.7.1 / 2015-03-11 |
|||
|
|||
* Revert #347 (fix collisions when option and first arg have same name) which causes a bug in #367. |
|||
|
|||
## 2.7.0 / 2015-03-09 |
|||
|
|||
* Fix git-style bug when installed globally. Close #335 #349 @zhiyelee |
|||
* Fix collisions when option and first arg have same name. Close #346 #347 @tonylukasavage |
|||
* Add support for camelCase on `opts()`. Close #353 @nkzawa |
|||
* Add node.js 0.12 and io.js to travis.yml |
|||
* Allow RegEx options. #337 @palanik |
|||
* Fixes exit code when sub-command failing. Close #260 #332 @pirelenito |
|||
* git-style `bin` files in $PATH make sense. Close #196 #327 @zhiyelee |
|||
|
|||
## 2.6.0 / 2014-12-30 |
|||
|
|||
* added `Command#allowUnknownOption` method. Close #138 #318 @doozr @zhiyelee |
|||
* Add application description to the help msg. Close #112 @dalssoft |
|||
|
|||
## 2.5.1 / 2014-12-15 |
|||
|
|||
* fixed two bugs incurred by variadic arguments. Close #291 @Quentin01 #302 @zhiyelee |
|||
|
|||
## 2.5.0 / 2014-10-24 |
|||
|
|||
* add support for variadic arguments. Closes #277 @whitlockjc |
|||
|
|||
## 2.4.0 / 2014-10-17 |
|||
|
|||
* fixed a bug on executing the coercion function of subcommands option. Closes #270 |
|||
* added `Command.prototype.name` to retrieve command name. Closes #264 #266 @tonylukasavage |
|||
* added `Command.prototype.opts` to retrieve all the options as a simple object of key-value pairs. Closes #262 @tonylukasavage |
|||
* fixed a bug on subcommand name. Closes #248 @jonathandelgado |
|||
* fixed function normalize doesn’t honor option terminator. Closes #216 @abbr |
|||
|
|||
## 2.3.0 / 2014-07-16 |
|||
|
|||
* add command alias'. Closes PR #210 |
|||
* fix: Typos. Closes #99 |
|||
* fix: Unused fs module. Closes #217 |
|||
|
|||
## 2.2.0 / 2014-03-29 |
|||
|
|||
* add passing of previous option value |
|||
* fix: support subcommands on windows. Closes #142 |
|||
* Now the defaultValue passed as the second argument of the coercion function. |
|||
|
|||
## 2.1.0 / 2013-11-21 |
|||
|
|||
* add: allow cflag style option params, unit test, fixes #174 |
|||
|
|||
## 2.0.0 / 2013-07-18 |
|||
|
|||
* remove input methods (.prompt, .confirm, etc) |
|||
|
|||
## 1.3.2 / 2013-07-18 |
|||
|
|||
* add support for sub-commands to co-exist with the original command |
|||
|
|||
## 1.3.1 / 2013-07-18 |
|||
|
|||
* add quick .runningCommand hack so you can opt-out of other logic when running a sub command |
|||
|
|||
## 1.3.0 / 2013-07-09 |
|||
|
|||
* add EACCES error handling |
|||
* fix sub-command --help |
|||
|
|||
## 1.2.0 / 2013-06-13 |
|||
|
|||
* allow "-" hyphen as an option argument |
|||
* support for RegExp coercion |
|||
|
|||
## 1.1.1 / 2012-11-20 |
|||
|
|||
* add more sub-command padding |
|||
* fix .usage() when args are present. Closes #106 |
|||
|
|||
## 1.1.0 / 2012-11-16 |
|||
|
|||
* add git-style executable subcommand support. Closes #94 |
|||
|
|||
## 1.0.5 / 2012-10-09 |
|||
|
|||
* fix `--name` clobbering. Closes #92 |
|||
* fix examples/help. Closes #89 |
|||
|
|||
## 1.0.4 / 2012-09-03 |
|||
|
|||
* add `outputHelp()` method. |
|||
|
|||
## 1.0.3 / 2012-08-30 |
|||
|
|||
* remove invalid .version() defaulting |
|||
|
|||
## 1.0.2 / 2012-08-24 |
|||
|
|||
* add `--foo=bar` support [arv] |
|||
* fix password on node 0.8.8. Make backward compatible with 0.6 [focusaurus] |
|||
|
|||
## 1.0.1 / 2012-08-03 |
|||
|
|||
* fix issue #56 |
|||
* fix tty.setRawMode(mode) was moved to tty.ReadStream#setRawMode() (i.e. process.stdin.setRawMode()) |
|||
|
|||
## 1.0.0 / 2012-07-05 |
|||
|
|||
* add support for optional option descriptions |
|||
* add defaulting of `.version()` to package.json's version |
|||
|
|||
## 0.6.1 / 2012-06-01 |
|||
|
|||
* Added: append (yes or no) on confirmation |
|||
* Added: allow node.js v0.7.x |
|||
|
|||
## 0.6.0 / 2012-04-10 |
|||
|
|||
* Added `.prompt(obj, callback)` support. Closes #49 |
|||
* Added default support to .choose(). Closes #41 |
|||
* Fixed the choice example |
|||
|
|||
## 0.5.1 / 2011-12-20 |
|||
|
|||
* Fixed `password()` for recent nodes. Closes #36 |
|||
|
|||
## 0.5.0 / 2011-12-04 |
|||
|
|||
* Added sub-command option support [itay] |
|||
|
|||
## 0.4.3 / 2011-12-04 |
|||
|
|||
* Fixed custom help ordering. Closes #32 |
|||
|
|||
## 0.4.2 / 2011-11-24 |
|||
|
|||
* Added travis support |
|||
* Fixed: line-buffered input automatically trimmed. Closes #31 |
|||
|
|||
## 0.4.1 / 2011-11-18 |
|||
|
|||
* Removed listening for "close" on --help |
|||
|
|||
## 0.4.0 / 2011-11-15 |
|||
|
|||
* Added support for `--`. Closes #24 |
|||
|
|||
## 0.3.3 / 2011-11-14 |
|||
|
|||
* Fixed: wait for close event when writing help info [Jerry Hamlet] |
|||
|
|||
## 0.3.2 / 2011-11-01 |
|||
|
|||
* Fixed long flag definitions with values [felixge] |
|||
|
|||
## 0.3.1 / 2011-10-31 |
|||
|
|||
* Changed `--version` short flag to `-V` from `-v` |
|||
* Changed `.version()` so it's configurable [felixge] |
|||
|
|||
## 0.3.0 / 2011-10-31 |
|||
|
|||
* Added support for long flags only. Closes #18 |
|||
|
|||
## 0.2.1 / 2011-10-24 |
|||
|
|||
* "node": ">= 0.4.x < 0.7.0". Closes #20 |
|||
|
|||
## 0.2.0 / 2011-09-26 |
|||
|
|||
* Allow for defaults that are not just boolean. Default peassignment only occurs for --no-*, optional, and required arguments. [Jim Isaacs] |
|||
|
|||
## 0.1.0 / 2011-08-24 |
|||
|
|||
* Added support for custom `--help` output |
|||
|
|||
## 0.0.5 / 2011-08-18 |
|||
|
|||
* Changed: when the user enters nothing prompt for password again |
|||
* Fixed issue with passwords beginning with numbers [NuckChorris] |
|||
|
|||
## 0.0.4 / 2011-08-15 |
|||
|
|||
* Fixed `Commander#args` |
|||
|
|||
## 0.0.3 / 2011-08-15 |
|||
|
|||
* Added default option value support |
|||
|
|||
## 0.0.2 / 2011-08-15 |
|||
|
|||
* Added mask support to `Command#password(str[, mask], fn)` |
|||
* Added `Command#password(str, fn)` |
|||
|
|||
## 0.0.1 / 2010-01-03 |
|||
|
|||
* Initial release |
|||
|
|||
[#599]: https://github.com/tj/commander.js/issues/599 |
|||
[#611]: https://github.com/tj/commander.js/issues/611 |
|||
[#697]: https://github.com/tj/commander.js/issues/697 |
|||
[#795]: https://github.com/tj/commander.js/issues/795 |
|||
[#915]: https://github.com/tj/commander.js/issues/915 |
|||
[#938]: https://github.com/tj/commander.js/issues/938 |
|||
[#963]: https://github.com/tj/commander.js/issues/963 |
|||
[#974]: https://github.com/tj/commander.js/issues/974 |
|||
[#980]: https://github.com/tj/commander.js/issues/980 |
|||
[#987]: https://github.com/tj/commander.js/issues/987 |
|||
[#990]: https://github.com/tj/commander.js/issues/990 |
|||
[#991]: https://github.com/tj/commander.js/issues/991 |
|||
[#999]: https://github.com/tj/commander.js/issues/999 |
|||
[#1010]: https://github.com/tj/commander.js/pull/1010 |
|||
[#1018]: https://github.com/tj/commander.js/pull/1018 |
|||
[#1026]: https://github.com/tj/commander.js/pull/1026 |
|||
[#1027]: https://github.com/tj/commander.js/pull/1027 |
|||
[#1028]: https://github.com/tj/commander.js/pull/1028 |
|||
[#1035]: https://github.com/tj/commander.js/pull/1035 |
|||
[#1040]: https://github.com/tj/commander.js/pull/1040 |
|||
[#1047]: https://github.com/tj/commander.js/pull/1047 |
|||
[#1048]: https://github.com/tj/commander.js/pull/1048 |
|||
[#1049]: https://github.com/tj/commander.js/pull/1049 |
|||
[#1051]: https://github.com/tj/commander.js/pull/1051 |
|||
[#1052]: https://github.com/tj/commander.js/pull/1052 |
|||
[#1053]: https://github.com/tj/commander.js/pull/1053 |
|||
[#1071]: https://github.com/tj/commander.js/pull/1071 |
|||
[#1081]: https://github.com/tj/commander.js/pull/1081 |
|||
[#1091]: https://github.com/tj/commander.js/pull/1091 |
|||
|
|||
[Unreleased]: https://github.com/tj/commander.js/compare/master...develop |
|||
[4.0.1]: https://github.com/tj/commander.js/compare/v4.0.0..v4.0.1 |
|||
[4.0.0]: https://github.com/tj/commander.js/compare/v3.0.2..v4.0.0 |
|||
[4.0.0-1]: https://github.com/tj/commander.js/compare/v4.0.0-0..v4.0.0-1 |
|||
[4.0.0-0]: https://github.com/tj/commander.js/compare/v3.0.2...v4.0.0-0 |
|||
[3.0.2]: https://github.com/tj/commander.js/compare/v3.0.1...v3.0.2 |
|||
[3.0.1]: https://github.com/tj/commander.js/compare/v3.0.0...v3.0.1 |
|||
[3.0.0]: https://github.com/tj/commander.js/compare/v2.20.1...v3.0.0 |
|||
[2.20.1]: https://github.com/tj/commander.js/compare/v2.20.0...v2.20.1 |
@ -0,0 +1,22 @@ |
|||
(The MIT License) |
|||
|
|||
Copyright (c) 2011 TJ Holowaychuk <tj@vision-media.ca> |
|||
|
|||
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,659 @@ |
|||
# Commander.js |
|||
|
|||
[](http://travis-ci.org/tj/commander.js) |
|||
[](https://www.npmjs.org/package/commander) |
|||
[](https://npmcharts.com/compare/commander?minimal=true) |
|||
[](https://packagephobia.now.sh/result?p=commander) |
|||
|
|||
The complete solution for [node.js](http://nodejs.org) command-line interfaces, inspired by Ruby's [commander](https://github.com/commander-rb/commander). |
|||
|
|||
Read this in other languages: English | [简体中文](./Readme_zh-CN.md) |
|||
|
|||
- [Commander.js](#commanderjs) |
|||
- [Installation](#installation) |
|||
- [Declaring _program_ variable](#declaring-program-variable) |
|||
- [Options](#options) |
|||
- [Common option types, boolean and value](#common-option-types-boolean-and-value) |
|||
- [Default option value](#default-option-value) |
|||
- [Other option types, negatable boolean and flag|value](#other-option-types-negatable-boolean-and-flagvalue) |
|||
- [Custom option processing](#custom-option-processing) |
|||
- [Required option](#required-option) |
|||
- [Version option](#version-option) |
|||
- [Commands](#commands) |
|||
- [Specify the argument syntax](#specify-the-argument-syntax) |
|||
- [Action handler (sub)commands](#action-handler-subcommands) |
|||
- [Git-style executable (sub)commands](#git-style-executable-subcommands) |
|||
- [Automated --help](#automated---help) |
|||
- [Custom help](#custom-help) |
|||
- [.usage and .name](#usage-and-name) |
|||
- [.outputHelp(cb)](#outputhelpcb) |
|||
- [.helpOption(flags, description)](#helpoptionflags-description) |
|||
- [.help(cb)](#helpcb) |
|||
- [Custom event listeners](#custom-event-listeners) |
|||
- [Bits and pieces](#bits-and-pieces) |
|||
- [TypeScript](#typescript) |
|||
- [Node options such as `--harmony`](#node-options-such-as---harmony) |
|||
- [Node debugging](#node-debugging) |
|||
- [Override exit handling](#override-exit-handling) |
|||
- [Examples](#examples) |
|||
- [License](#license) |
|||
- [Support](#support) |
|||
- [Commander for enterprise](#commander-for-enterprise) |
|||
|
|||
## Installation |
|||
|
|||
```bash |
|||
npm install commander |
|||
``` |
|||
|
|||
## Declaring _program_ variable |
|||
|
|||
Commander exports a global object which is convenient for quick programs. |
|||
This is used in the examples in this README for brevity. |
|||
|
|||
```js |
|||
const program = require('commander'); |
|||
program.version('0.0.1'); |
|||
``` |
|||
|
|||
For larger programs which may use commander in multiple ways, including unit testing, it is better to create a local Command object to use. |
|||
|
|||
```js |
|||
const commander = require('commander'); |
|||
const program = new commander.Command(); |
|||
program.version('0.0.1'); |
|||
``` |
|||
|
|||
## Options |
|||
|
|||
Options are defined with the `.option()` method, also serving as documentation for the options. Each option can have a short flag (single character) and a long name, separated by a comma or space. |
|||
|
|||
The options can be accessed as properties on the Command object. Multi-word options such as "--template-engine" are camel-cased, becoming `program.templateEngine` etc. Multiple short flags may be combined as a single arg, for example `-abc` is equivalent to `-a -b -c`. |
|||
|
|||
### Common option types, boolean and value |
|||
|
|||
The two most used option types are a boolean flag, and an option which takes a value (declared using angle brackets). Both are `undefined` unless specified on command line. |
|||
|
|||
```js |
|||
const program = require('commander'); |
|||
|
|||
program |
|||
.option('-d, --debug', 'output extra debugging') |
|||
.option('-s, --small', 'small pizza size') |
|||
.option('-p, --pizza-type <type>', 'flavour of pizza'); |
|||
|
|||
program.parse(process.argv); |
|||
|
|||
if (program.debug) console.log(program.opts()); |
|||
console.log('pizza details:'); |
|||
if (program.small) console.log('- small pizza size'); |
|||
if (program.pizzaType) console.log(`- ${program.pizzaType}`); |
|||
``` |
|||
|
|||
```bash |
|||
$ pizza-options -d |
|||
{ debug: true, small: undefined, pizzaType: undefined } |
|||
pizza details: |
|||
$ pizza-options -p |
|||
error: option '-p, --pizza-type <type>' argument missing |
|||
$ pizza-options -ds -p vegetarian |
|||
{ debug: true, small: true, pizzaType: 'vegetarian' } |
|||
pizza details: |
|||
- small pizza size |
|||
- vegetarian |
|||
$ pizza-options --pizza-type=cheese |
|||
pizza details: |
|||
- cheese |
|||
``` |
|||
|
|||
`program.parse(arguments)` processes the arguments, leaving any args not consumed by the options as the `program.args` array. |
|||
|
|||
### Default option value |
|||
|
|||
You can specify a default value for an option which takes a value. |
|||
|
|||
```js |
|||
const program = require('commander'); |
|||
|
|||
program |
|||
.option('-c, --cheese <type>', 'add the specified type of cheese', 'blue'); |
|||
|
|||
program.parse(process.argv); |
|||
|
|||
console.log(`cheese: ${program.cheese}`); |
|||
``` |
|||
|
|||
```bash |
|||
$ pizza-options |
|||
cheese: blue |
|||
$ pizza-options --cheese stilton |
|||
cheese: stilton |
|||
``` |
|||
|
|||
### Other option types, negatable boolean and flag|value |
|||
|
|||
You can specify a boolean option long name with a leading `no-` to set the option value to false when used. |
|||
Defined alone this also makes the option true by default. |
|||
|
|||
If you define `--foo` first, adding `--no-foo` does not change the default value from what it would |
|||
otherwise be. You can specify a default boolean value for a boolean flag and it can be overridden on command line. |
|||
|
|||
```js |
|||
const program = require('commander'); |
|||
|
|||
program |
|||
.option('--no-sauce', 'Remove sauce') |
|||
.option('--cheese <flavour>', 'cheese flavour', 'mozzarella') |
|||
.option('--no-cheese', 'plain with no cheese') |
|||
.parse(process.argv); |
|||
|
|||
const sauceStr = program.sauce ? 'sauce' : 'no sauce'; |
|||
const cheeseStr = (program.cheese === false) ? 'no cheese' : `${program.cheese} cheese`; |
|||
console.log(`You ordered a pizza with ${sauceStr} and ${cheeseStr}`); |
|||
``` |
|||
|
|||
```bash |
|||
$ pizza-options |
|||
You ordered a pizza with sauce and mozzarella cheese |
|||
$ pizza-options --sauce |
|||
error: unknown option '--sauce' |
|||
$ pizza-options --cheese=blue |
|||
You ordered a pizza with sauce and blue cheese |
|||
$ pizza-options --no-sauce --no-cheese |
|||
You ordered a pizza with no sauce and no cheese |
|||
``` |
|||
|
|||
You can specify an option which functions as a flag but may also take a value (declared using square brackets). |
|||
|
|||
```js |
|||
const program = require('commander'); |
|||
|
|||
program |
|||
.option('-c, --cheese [type]', 'Add cheese with optional type'); |
|||
|
|||
program.parse(process.argv); |
|||
|
|||
if (program.cheese === undefined) console.log('no cheese'); |
|||
else if (program.cheese === true) console.log('add cheese'); |
|||
else console.log(`add cheese type ${program.cheese}`); |
|||
``` |
|||
|
|||
```bash |
|||
$ pizza-options |
|||
no cheese |
|||
$ pizza-options --cheese |
|||
add cheese |
|||
$ pizza-options --cheese mozzarella |
|||
add cheese type mozzarella |
|||
``` |
|||
|
|||
### Custom option processing |
|||
|
|||
You may specify a function to do custom processing of option values. The callback function receives two parameters, the user specified value and the |
|||
previous value for the option. It returns the new value for the option. |
|||
|
|||
This allows you to coerce the option value to the desired type, or accumulate values, or do entirely custom processing. |
|||
|
|||
You can optionally specify the default/starting value for the option after the function. |
|||
|
|||
```js |
|||
const program = require('commander'); |
|||
|
|||
function myParseInt(value, dummyPrevious) { |
|||
// parseInt takes a string and an optional radix |
|||
return parseInt(value); |
|||
} |
|||
|
|||
function increaseVerbosity(dummyValue, previous) { |
|||
return previous + 1; |
|||
} |
|||
|
|||
function collect(value, previous) { |
|||
return previous.concat([value]); |
|||
} |
|||
|
|||
function commaSeparatedList(value, dummyPrevious) { |
|||
return value.split(','); |
|||
} |
|||
|
|||
program |
|||
.option('-f, --float <number>', 'float argument', parseFloat) |
|||
.option('-i, --integer <number>', 'integer argument', myParseInt) |
|||
.option('-v, --verbose', 'verbosity that can be increased', increaseVerbosity, 0) |
|||
.option('-c, --collect <value>', 'repeatable value', collect, []) |
|||
.option('-l, --list <items>', 'comma separated list', commaSeparatedList) |
|||
; |
|||
|
|||
program.parse(process.argv); |
|||
|
|||
if (program.float !== undefined) console.log(`float: ${program.float}`); |
|||
if (program.integer !== undefined) console.log(`integer: ${program.integer}`); |
|||
if (program.verbose > 0) console.log(`verbosity: ${program.verbose}`); |
|||
if (program.collect.length > 0) console.log(program.collect); |
|||
if (program.list !== undefined) console.log(program.list); |
|||
``` |
|||
|
|||
```bash |
|||
$ custom -f 1e2 |
|||
float: 100 |
|||
$ custom --integer 2 |
|||
integer: 2 |
|||
$ custom -v -v -v |
|||
verbose: 3 |
|||
$ custom -c a -c b -c c |
|||
[ 'a', 'b', 'c' ] |
|||
$ custom --list x,y,z |
|||
[ 'x', 'y', 'z' ] |
|||
``` |
|||
|
|||
### Required option |
|||
|
|||
You may specify a required (mandatory) option using `.requiredOption`. The option must be specified on the command line, or by having a default value. The method is otherwise the same as `.option` in format, taking flags and description, and optional default value or custom processing. |
|||
|
|||
```js |
|||
const program = require('commander'); |
|||
|
|||
program |
|||
.requiredOption('-c, --cheese <type>', 'pizza must have cheese'); |
|||
|
|||
program.parse(process.argv); |
|||
``` |
|||
|
|||
``` |
|||
$ pizza |
|||
error: required option '-c, --cheese <type>' not specified |
|||
``` |
|||
|
|||
### Version option |
|||
|
|||
The optional `version` method adds handling for displaying the command version. The default option flags are `-V` and `--version`, and when present the command prints the version number and exits. |
|||
|
|||
```js |
|||
program.version('0.0.1'); |
|||
``` |
|||
|
|||
```bash |
|||
$ ./examples/pizza -V |
|||
0.0.1 |
|||
``` |
|||
|
|||
You may change the flags and description by passing additional parameters to the `version` method, using |
|||
the same syntax for flags as the `option` method. The version flags can be named anything, but a long name is required. |
|||
|
|||
```js |
|||
program.version('0.0.1', '-v, --vers', 'output the current version'); |
|||
``` |
|||
|
|||
## Commands |
|||
|
|||
You can specify (sub)commands for your top-level command using `.command`. There are two ways these can be implemented: using an action handler attached to the command, or as a separate executable file (described in more detail later). In the first parameter to `.command` you specify the command name and any command arguments. The arguments may be `<required>` or `[optional]`, and the last argument may also be `variadic...`. |
|||
|
|||
For example: |
|||
|
|||
```js |
|||
// Command implemented using action handler (description is supplied separately to `.command`) |
|||
// Returns new command for configuring. |
|||
program |
|||
.command('clone <source> [destination]') |
|||
.description('clone a repository into a newly created directory') |
|||
.action((source, destination) => { |
|||
console.log('clone command called'); |
|||
}); |
|||
|
|||
// Command implemented using separate executable file (description is second parameter to `.command`) |
|||
// Returns top-level command for adding more commands. |
|||
program |
|||
.command('start <service>', 'start named service') |
|||
.command('stop [service]', 'stop named service, or all if no name supplied'); |
|||
``` |
|||
|
|||
### Specify the argument syntax |
|||
|
|||
You use `.arguments` to specify the arguments for the top-level command, and for subcommands they are included in the `.command` call. Angled brackets (e.g. `<required>`) indicate required input. Square brackets (e.g. `[optional]`) indicate optional input. |
|||
|
|||
```js |
|||
const program = require('commander'); |
|||
|
|||
program |
|||
.version('0.1.0') |
|||
.arguments('<cmd> [env]') |
|||
.action(function (cmd, env) { |
|||
cmdValue = cmd; |
|||
envValue = env; |
|||
}); |
|||
|
|||
program.parse(process.argv); |
|||
|
|||
if (typeof cmdValue === 'undefined') { |
|||
console.error('no command given!'); |
|||
process.exit(1); |
|||
} |
|||
console.log('command:', cmdValue); |
|||
console.log('environment:', envValue || "no environment given"); |
|||
``` |
|||
|
|||
The last argument of a command can be variadic, and only the last argument. To make an argument variadic you |
|||
append `...` to the argument name. For example: |
|||
|
|||
```js |
|||
const program = require('commander'); |
|||
|
|||
program |
|||
.version('0.1.0') |
|||
.command('rmdir <dir> [otherDirs...]') |
|||
.action(function (dir, otherDirs) { |
|||
console.log('rmdir %s', dir); |
|||
if (otherDirs) { |
|||
otherDirs.forEach(function (oDir) { |
|||
console.log('rmdir %s', oDir); |
|||
}); |
|||
} |
|||
}); |
|||
|
|||
program.parse(process.argv); |
|||
``` |
|||
|
|||
The variadic argument is passed to the action handler as an array. (And this also applies to `program.args`.) |
|||
|
|||
### Action handler (sub)commands |
|||
|
|||
You can add options to a command that uses an action handler. |
|||
The action handler gets passed a parameter for each argument you declared, and one additional argument which is the |
|||
command object itself. This command argument has the values for the command-specific options added as properties. |
|||
|
|||
```js |
|||
const program = require('commander'); |
|||
|
|||
program |
|||
.command('rm <dir>') |
|||
.option('-r, --recursive', 'Remove recursively') |
|||
.action(function (dir, cmdObj) { |
|||
console.log('remove ' + dir + (cmdObj.recursive ? ' recursively' : '')) |
|||
}) |
|||
|
|||
program.parse(process.argv) |
|||
``` |
|||
|
|||
A command's options on the command line are validated when the command is used. Any unknown options will be reported as an error. However, if an action-based command does not define an action, then the options are not validated. |
|||
|
|||
Configuration options can be passed with the call to `.command()`. Specifying `true` for `opts.noHelp` will remove the command from the generated help output. |
|||
|
|||
### Git-style executable (sub)commands |
|||
|
|||
When `.command()` is invoked with a description argument, this tells commander that you're going to use separate executables for sub-commands, much like `git(1)` and other popular tools. |
|||
Commander will search the executables in the directory of the entry script (like `./examples/pm`) with the name `program-subcommand`, like `pm-install`, `pm-search`. |
|||
You can specify a custom name with the `executableFile` configuration option. |
|||
|
|||
You handle the options for an executable (sub)command in the executable, and don't declare them at the top-level. |
|||
|
|||
```js |
|||
// file: ./examples/pm |
|||
const program = require('commander'); |
|||
|
|||
program |
|||
.version('0.1.0') |
|||
.command('install [name]', 'install one or more packages') |
|||
.command('search [query]', 'search with optional query') |
|||
.command('update', 'update installed packages', {executableFile: 'myUpdateSubCommand'}) |
|||
.command('list', 'list packages installed', {isDefault: true}) |
|||
.parse(process.argv); |
|||
``` |
|||
|
|||
Configuration options can be passed with the call to `.command()`. Specifying `true` for `opts.noHelp` will remove the command from the generated help output. Specifying `true` for `opts.isDefault` will run the subcommand if no other subcommand is specified. |
|||
Specifying a name with `executableFile` will override the default constructed name. |
|||
|
|||
If the program is designed to be installed globally, make sure the executables have proper modes, like `755`. |
|||
|
|||
## Automated --help |
|||
|
|||
The help information is auto-generated based on the information commander already knows about your program, so the following `--help` info is for free: |
|||
|
|||
```bash |
|||
$ ./examples/pizza --help |
|||
Usage: pizza [options] |
|||
|
|||
An application for pizzas ordering |
|||
|
|||
Options: |
|||
-V, --version output the version number |
|||
-p, --peppers Add peppers |
|||
-P, --pineapple Add pineapple |
|||
-b, --bbq Add bbq sauce |
|||
-c, --cheese <type> Add the specified type of cheese (default: "marble") |
|||
-C, --no-cheese You do not want any cheese |
|||
-h, --help output usage information |
|||
``` |
|||
|
|||
### Custom help |
|||
|
|||
You can display arbitrary `-h, --help` information |
|||
by listening for "--help". Commander will automatically |
|||
exit once you are done so that the remainder of your program |
|||
does not execute causing undesired behaviors, for example |
|||
in the following executable "stuff" will not output when |
|||
`--help` is used. |
|||
|
|||
```js |
|||
#!/usr/bin/env node |
|||
|
|||
const program = require('commander'); |
|||
|
|||
program |
|||
.version('0.1.0') |
|||
.option('-f, --foo', 'enable some foo') |
|||
.option('-b, --bar', 'enable some bar') |
|||
.option('-B, --baz', 'enable some baz'); |
|||
|
|||
// must be before .parse() since |
|||
// node's emit() is immediate |
|||
|
|||
program.on('--help', function(){ |
|||
console.log('') |
|||
console.log('Examples:'); |
|||
console.log(' $ custom-help --help'); |
|||
console.log(' $ custom-help -h'); |
|||
}); |
|||
|
|||
program.parse(process.argv); |
|||
|
|||
console.log('stuff'); |
|||
``` |
|||
|
|||
Yields the following help output when `node script-name.js -h` or `node script-name.js --help` are run: |
|||
|
|||
```Text |
|||
Usage: custom-help [options] |
|||
|
|||
Options: |
|||
-h, --help output usage information |
|||
-V, --version output the version number |
|||
-f, --foo enable some foo |
|||
-b, --bar enable some bar |
|||
-B, --baz enable some baz |
|||
|
|||
Examples: |
|||
$ custom-help --help |
|||
$ custom-help -h |
|||
``` |
|||
|
|||
### .usage and .name |
|||
|
|||
These allow you to customise the usage description in the first line of the help. The name is otherwise |
|||
deduced from the (full) program arguments. Given: |
|||
|
|||
```js |
|||
program |
|||
.name("my-command") |
|||
.usage("[global options] command") |
|||
``` |
|||
|
|||
The help will start with: |
|||
|
|||
```Text |
|||
Usage: my-command [global options] command |
|||
``` |
|||
|
|||
### .outputHelp(cb) |
|||
|
|||
Output help information without exiting. |
|||
Optional callback cb allows post-processing of help text before it is displayed. |
|||
|
|||
If you want to display help by default (e.g. if no command was provided), you can use something like: |
|||
|
|||
```js |
|||
const program = require('commander'); |
|||
const colors = require('colors'); |
|||
|
|||
program |
|||
.version('0.1.0') |
|||
.command('getstream [url]', 'get stream URL') |
|||
.parse(process.argv); |
|||
|
|||
if (!process.argv.slice(2).length) { |
|||
program.outputHelp(make_red); |
|||
} |
|||
|
|||
function make_red(txt) { |
|||
return colors.red(txt); //display the help text in red on the console |
|||
} |
|||
``` |
|||
|
|||
### .helpOption(flags, description) |
|||
|
|||
Override the default help flags and description. |
|||
|
|||
```js |
|||
program |
|||
.helpOption('-e, --HELP', 'read more information'); |
|||
``` |
|||
|
|||
### .help(cb) |
|||
|
|||
Output help information and exit immediately. |
|||
Optional callback cb allows post-processing of help text before it is displayed. |
|||
|
|||
## Custom event listeners |
|||
|
|||
You can execute custom actions by listening to command and option events. |
|||
|
|||
```js |
|||
program.on('option:verbose', function () { |
|||
process.env.VERBOSE = this.verbose; |
|||
}); |
|||
|
|||
// error on unknown commands |
|||
program.on('command:*', function () { |
|||
console.error('Invalid command: %s\nSee --help for a list of available commands.', program.args.join(' ')); |
|||
process.exit(1); |
|||
}); |
|||
``` |
|||
|
|||
## Bits and pieces |
|||
|
|||
### TypeScript |
|||
|
|||
The Commander package includes its TypeScript Definition file, but also requires the node types which you need to install yourself. e.g. |
|||
|
|||
```bash |
|||
npm install commander |
|||
npm install --save-dev @types/node |
|||
``` |
|||
|
|||
If you use `ts-node` and git-style sub-commands written as `.ts` files, you need to call your program through node to get the sub-commands called correctly. e.g. |
|||
|
|||
```bash |
|||
node -r ts-node/register pm.ts |
|||
``` |
|||
|
|||
### Node options such as `--harmony` |
|||
|
|||
You can enable `--harmony` option in two ways: |
|||
|
|||
- Use `#! /usr/bin/env node --harmony` in the sub-commands scripts. (Note Windows does not support this pattern.) |
|||
- Use the `--harmony` option when call the command, like `node --harmony examples/pm publish`. The `--harmony` option will be preserved when spawning sub-command process. |
|||
|
|||
### Node debugging |
|||
|
|||
If you are using the node inspector for [debugging](https://nodejs.org/en/docs/guides/debugging-getting-started/) git-style executable (sub)commands using `node --inspect` et al, |
|||
the inspector port is incremented by 1 for the spawned subcommand. |
|||
|
|||
### Override exit handling |
|||
|
|||
By default Commander calls `process.exit` when it detects errors, or after displaying the help or version. You can override |
|||
this behaviour and optionally supply a callback. The default override throws a `CommanderError`. |
|||
|
|||
The override callback is passed a `CommanderError` with properties `exitCode` number, `code` string, and `message`. The default override behaviour is to throw the error, except for async handling of executable subcommand completion which carries on. The normal display of error messages or version or help |
|||
is not affected by the override which is called after the display. |
|||
|
|||
``` js |
|||
program.exitOverride(); |
|||
|
|||
try { |
|||
program.parse(process.argv); |
|||
} catch (err) { |
|||
// custom processing... |
|||
} |
|||
``` |
|||
|
|||
## Examples |
|||
|
|||
```js |
|||
const program = require('commander'); |
|||
|
|||
program |
|||
.version('0.1.0') |
|||
.option('-C, --chdir <path>', 'change the working directory') |
|||
.option('-c, --config <path>', 'set config path. defaults to ./deploy.conf') |
|||
.option('-T, --no-tests', 'ignore test hook'); |
|||
|
|||
program |
|||
.command('setup [env]') |
|||
.description('run setup commands for all envs') |
|||
.option("-s, --setup_mode [mode]", "Which setup mode to use") |
|||
.action(function(env, options){ |
|||
const mode = options.setup_mode || "normal"; |
|||
env = env || 'all'; |
|||
console.log('setup for %s env(s) with %s mode', env, mode); |
|||
}); |
|||
|
|||
program |
|||
.command('exec <cmd>') |
|||
.alias('ex') |
|||
.description('execute the given remote cmd') |
|||
.option("-e, --exec_mode <mode>", "Which exec mode to use") |
|||
.action(function(cmd, options){ |
|||
console.log('exec "%s" using %s mode', cmd, options.exec_mode); |
|||
}).on('--help', function() { |
|||
console.log(''); |
|||
console.log('Examples:'); |
|||
console.log(''); |
|||
console.log(' $ deploy exec sequential'); |
|||
console.log(' $ deploy exec async'); |
|||
}); |
|||
|
|||
program |
|||
.command('*') |
|||
.action(function(env){ |
|||
console.log('deploying "%s"', env); |
|||
}); |
|||
|
|||
program.parse(process.argv); |
|||
``` |
|||
|
|||
More Demos can be found in the [examples](https://github.com/tj/commander.js/tree/master/examples) directory. |
|||
|
|||
## License |
|||
|
|||
[MIT](https://github.com/tj/commander.js/blob/master/LICENSE) |
|||
|
|||
## Support |
|||
|
|||
Commander is supported on Node 8 and above. (Commander is likely to still work on older versions of Node, but is not tested below Node 8.) |
|||
|
|||
The main forum for free and community support is the project [Issues](https://github.com/tj/commander.js/issues) on GitHub. |
|||
|
|||
### Commander for enterprise |
|||
|
|||
Available as part of the Tidelift Subscription |
|||
|
|||
The maintainers of Commander 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-commander?utm_source=npm-commander&utm_medium=referral&utm_campaign=enterprise&utm_term=repo) |
File diff suppressed because it is too large
@ -0,0 +1,75 @@ |
|||
{ |
|||
"_from": "commander", |
|||
"_id": "commander@4.0.1", |
|||
"_inBundle": false, |
|||
"_integrity": "sha512-IPF4ouhCP+qdlcmCedhxX4xiGBPyigb8v5NeUp+0LyhwLgxMqyp3S0vl7TAPfS/hiP7FC3caI/PB9lTmP8r1NA==", |
|||
"_location": "/commander", |
|||
"_phantomChildren": {}, |
|||
"_requested": { |
|||
"type": "tag", |
|||
"registry": true, |
|||
"raw": "commander", |
|||
"name": "commander", |
|||
"escapedName": "commander", |
|||
"rawSpec": "", |
|||
"saveSpec": null, |
|||
"fetchSpec": "latest" |
|||
}, |
|||
"_requiredBy": [ |
|||
"#USER", |
|||
"/" |
|||
], |
|||
"_resolved": "https://registry.npmjs.org/commander/-/commander-4.0.1.tgz", |
|||
"_shasum": "b67622721785993182e807f4883633e6401ba53c", |
|||
"_spec": "commander", |
|||
"_where": "E:\\mu_dist\\@xyx\\beer\\test-command", |
|||
"author": { |
|||
"name": "TJ Holowaychuk", |
|||
"email": "tj@vision-media.ca" |
|||
}, |
|||
"bugs": { |
|||
"url": "https://github.com/tj/commander.js/issues" |
|||
}, |
|||
"bundleDependencies": false, |
|||
"dependencies": {}, |
|||
"deprecated": false, |
|||
"description": "the complete solution for node.js command-line programs", |
|||
"devDependencies": { |
|||
"@types/jest": "^24.0.18", |
|||
"@types/node": "^12.7.5", |
|||
"eslint": "^6.4.0", |
|||
"eslint-plugin-jest": "^22.17.0", |
|||
"jest": "^24.8.0", |
|||
"standard": "^14.3.1", |
|||
"ts-node": "^8.4.1", |
|||
"typescript": "^3.6.3" |
|||
}, |
|||
"engines": { |
|||
"node": ">= 6" |
|||
}, |
|||
"files": [ |
|||
"index.js", |
|||
"typings/index.d.ts" |
|||
], |
|||
"homepage": "https://github.com/tj/commander.js#readme", |
|||
"keywords": [ |
|||
"commander", |
|||
"command", |
|||
"option", |
|||
"parser" |
|||
], |
|||
"license": "MIT", |
|||
"main": "index", |
|||
"name": "commander", |
|||
"repository": { |
|||
"type": "git", |
|||
"url": "git+https://github.com/tj/commander.js.git" |
|||
}, |
|||
"scripts": { |
|||
"lint": "eslint index.js \"tests/**/*.js\"", |
|||
"test": "jest && npm run test-typings", |
|||
"test-typings": "tsc -p tsconfig.json" |
|||
}, |
|||
"typings": "typings/index.d.ts", |
|||
"version": "4.0.1" |
|||
} |
@ -0,0 +1,302 @@ |
|||
// Type definitions for commander 2.11
|
|||
// Project: https://github.com/visionmedia/commander.js
|
|||
// Definitions by: Alan Agius <https://github.com/alan-agius4>, Marcelo Dezem <https://github.com/mdezem>, vvakame <https://github.com/vvakame>, Jules Randolph <https://github.com/sveinburne>
|
|||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|||
|
|||
///<reference types="node" />
|
|||
|
|||
declare namespace commander { |
|||
|
|||
interface CommanderError extends Error { |
|||
code: string; |
|||
exitCode: number; |
|||
message: string; |
|||
nestedError?: string; |
|||
} |
|||
type CommanderErrorConstructor = { new (exitCode: number, code: string, message: string): CommanderError }; |
|||
|
|||
interface Option { |
|||
flags: string; |
|||
required: boolean; // A value must be supplied when the option is specified.
|
|||
optional: boolean; // A value is optional when the option is specified.
|
|||
mandatory: boolean; // The option must have a value after parsing, which usually means it must be specified on command line.
|
|||
bool: boolean; |
|||
short?: string; |
|||
long: string; |
|||
description: string; |
|||
} |
|||
type OptionConstructor = { new (flags: string, description?: string): Option }; |
|||
|
|||
interface Command extends NodeJS.EventEmitter { |
|||
[key: string]: any; // options as properties
|
|||
|
|||
args: string[]; |
|||
|
|||
/** |
|||
* Set the program version to `str`. |
|||
* |
|||
* This method auto-registers the "-V, --version" flag |
|||
* which will print the version number when passed. |
|||
* |
|||
* You can optionally supply the flags and description to override the defaults. |
|||
* |
|||
*/ |
|||
version(str: string, flags?: string, description?: string): Command; |
|||
|
|||
/** |
|||
* Define a command, implemented using an action handler. |
|||
* |
|||
* @remarks |
|||
* The command description is supplied using `.description`, not as a parameter to `.command`. |
|||
* |
|||
* @example |
|||
* ```ts
|
|||
* program |
|||
* .command('clone <source> [destination]') |
|||
* .description('clone a repository into a newly created directory') |
|||
* .action((source, destination) => { |
|||
* console.log('clone command called'); |
|||
* }); |
|||
* ``` |
|||
* |
|||
* @param nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...` |
|||
* @param opts - configuration options |
|||
* @returns new command |
|||
*/ |
|||
command(nameAndArgs: string, opts?: CommandOptions): Command; |
|||
/** |
|||
* Define a command, implemented in a separate executable file. |
|||
* |
|||
* @remarks |
|||
* The command description is supplied as the second parameter to `.command`. |
|||
* |
|||
* @example |
|||
* ```ts
|
|||
* program |
|||
* .command('start <service>', 'start named service') |
|||
* .command('stop [service]', 'stop named serice, or all if no name supplied'); |
|||
* ``` |
|||
* |
|||
* @param nameAndArgs - command name and arguments, args are `<required>` or `[optional]` and last may also be `variadic...` |
|||
* @param description - description of executable command |
|||
* @param opts - configuration options |
|||
* @returns top level command for chaining more command definitions |
|||
*/ |
|||
command(nameAndArgs: string, description: string, opts?: commander.CommandOptions): Command; |
|||
|
|||
/** |
|||
* Define argument syntax for the top-level command. |
|||
* |
|||
* @param {string} desc |
|||
* @returns {Command} for chaining |
|||
*/ |
|||
arguments(desc: string): Command; |
|||
|
|||
/** |
|||
* Parse expected `args`. |
|||
* |
|||
* For example `["[type]"]` becomes `[{ required: false, name: 'type' }]`. |
|||
* |
|||
* @param {string[]} args |
|||
* @returns {Command} for chaining |
|||
*/ |
|||
parseExpectedArgs(args: string[]): Command; |
|||
|
|||
/** |
|||
* Register callback to use as replacement for calling process.exit. |
|||
*/ |
|||
exitOverride(callback?: (err: CommanderError) => never|void): Command; |
|||
|
|||
/** |
|||
* Register callback `fn` for the command. |
|||
* |
|||
* @example |
|||
* program |
|||
* .command('help') |
|||
* .description('display verbose help') |
|||
* .action(function() { |
|||
* // output help here
|
|||
* }); |
|||
* |
|||
* @param {(...args: any[]) => void} fn |
|||
* @returns {Command} for chaining |
|||
*/ |
|||
action(fn: (...args: any[]) => void): Command; |
|||
|
|||
/** |
|||
* Define option with `flags`, `description` and optional |
|||
* coercion `fn`. |
|||
* |
|||
* The `flags` string should contain both the short and long flags, |
|||
* separated by comma, a pipe or space. The following are all valid |
|||
* all will output this way when `--help` is used. |
|||
* |
|||
* "-p, --pepper" |
|||
* "-p|--pepper" |
|||
* "-p --pepper" |
|||
* |
|||
* @example |
|||
* // simple boolean defaulting to false
|
|||
* program.option('-p, --pepper', 'add pepper'); |
|||
* |
|||
* --pepper |
|||
* program.pepper |
|||
* // => Boolean
|
|||
* |
|||
* // simple boolean defaulting to true
|
|||
* program.option('-C, --no-cheese', 'remove cheese'); |
|||
* |
|||
* program.cheese |
|||
* // => true
|
|||
* |
|||
* --no-cheese |
|||
* program.cheese |
|||
* // => false
|
|||
* |
|||
* // required argument
|
|||
* program.option('-C, --chdir <path>', 'change the working directory'); |
|||
* |
|||
* --chdir /tmp |
|||
* program.chdir |
|||
* // => "/tmp"
|
|||
* |
|||
* // optional argument
|
|||
* program.option('-c, --cheese [type]', 'add cheese [marble]'); |
|||
* |
|||
* @param {string} flags |
|||
* @param {string} [description] |
|||
* @param {((arg1: any, arg2: any) => void) | RegExp} [fn] function or default |
|||
* @param {*} [defaultValue] |
|||
* @returns {Command} for chaining |
|||
*/ |
|||
option(flags: string, description?: string, fn?: ((arg1: any, arg2: any) => void) | RegExp, defaultValue?: any): Command; |
|||
option(flags: string, description?: string, defaultValue?: any): Command; |
|||
|
|||
/** |
|||
* Define a required option, which must have a value after parsing. This usually means |
|||
* the option must be specified on the command line. (Otherwise the same as .option().) |
|||
* |
|||
* The `flags` string should contain both the short and long flags, separated by comma, a pipe or space. |
|||
*/ |
|||
requiredOption(flags: string, description?: string, fn?: ((arg1: any, arg2: any) => void) | RegExp, defaultValue?: any): Command; |
|||
requiredOption(flags: string, description?: string, defaultValue?: any): Command; |
|||
|
|||
/** |
|||
* Allow unknown options on the command line. |
|||
* |
|||
* @param {boolean} [arg] if `true` or omitted, no error will be thrown for unknown options. |
|||
* @returns {Command} for chaining |
|||
*/ |
|||
allowUnknownOption(arg?: boolean): Command; |
|||
|
|||
/** |
|||
* Parse `argv`, settings options and invoking commands when defined. |
|||
* |
|||
* @param {string[]} argv |
|||
* @returns {Command} for chaining |
|||
*/ |
|||
parse(argv: string[]): Command; |
|||
|
|||
/** |
|||
* Parse options from `argv` returning `argv` void of these options. |
|||
* |
|||
* @param {string[]} argv |
|||
* @returns {ParseOptionsResult} |
|||
*/ |
|||
parseOptions(argv: string[]): commander.ParseOptionsResult; |
|||
|
|||
/** |
|||
* Return an object containing options as key-value pairs |
|||
* |
|||
* @returns {{[key: string]: any}} |
|||
*/ |
|||
opts(): { [key: string]: any }; |
|||
|
|||
/** |
|||
* Set the description to `str`. |
|||
* |
|||
* @param {string} str |
|||
* @param {{[argName: string]: string}} argsDescription |
|||
* @return {(Command | string)} |
|||
*/ |
|||
description(str: string, argsDescription?: {[argName: string]: string}): Command; |
|||
description(): string; |
|||
|
|||
/** |
|||
* Set an alias for the command. |
|||
* |
|||
* @param {string} alias |
|||
* @return {(Command | string)} |
|||
*/ |
|||
alias(alias: string): Command; |
|||
alias(): string; |
|||
|
|||
/** |
|||
* Set or get the command usage. |
|||
* |
|||
* @param {string} str |
|||
* @return {(Command | string)} |
|||
*/ |
|||
usage(str: string): Command; |
|||
usage(): string; |
|||
|
|||
/** |
|||
* Set the name of the command. |
|||
* |
|||
* @param {string} str |
|||
* @return {Command} |
|||
*/ |
|||
name(str: string): Command; |
|||
|
|||
/** |
|||
* Get the name of the command. |
|||
* |
|||
* @return {string} |
|||
*/ |
|||
name(): string; |
|||
|
|||
/** |
|||
* Output help information for this command. |
|||
* |
|||
* When listener(s) are available for the helpLongFlag |
|||
* those callbacks are invoked. |
|||
* |
|||
* @param {(str: string) => string} [cb] |
|||
*/ |
|||
outputHelp(cb?: (str: string) => string): void; |
|||
|
|||
/** |
|||
* You can pass in flags and a description to override the help |
|||
* flags and help description for your command. |
|||
*/ |
|||
helpOption(flags?: string, description?: string): Command; |
|||
|
|||
/** |
|||
* Output help information and exit. |
|||
*/ |
|||
help(cb?: (str: string) => string): never; |
|||
} |
|||
type CommandConstructor = { new (name?: string): Command }; |
|||
|
|||
|
|||
interface CommandOptions { |
|||
noHelp?: boolean; |
|||
isDefault?: boolean; |
|||
executableFile?: string; |
|||
} |
|||
|
|||
interface ParseOptionsResult { |
|||
args: string[]; |
|||
unknown: string[]; |
|||
} |
|||
|
|||
interface CommanderStatic extends Command { |
|||
Command: CommandConstructor; |
|||
Option: OptionConstructor; |
|||
CommanderError:CommanderErrorConstructor; |
|||
} |
|||
|
|||
} |
|||
|
|||
declare const commander: commander.CommanderStatic; |
|||
export = commander; |
@ -0,0 +1 @@ |
|||
node_modules |
@ -0,0 +1,21 @@ |
|||
The MIT License (MIT) |
|||
|
|||
Copyright (c) 2015 Elijah Insua |
|||
|
|||
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,43 @@ |
|||
# defaults |
|||
|
|||
A simple one level options merge utility |
|||
|
|||
## install |
|||
|
|||
`npm install defaults` |
|||
|
|||
## use |
|||
|
|||
```javascript |
|||
|
|||
var defaults = require('defaults'); |
|||
|
|||
var handle = function(options, fn) { |
|||
options = defaults(options, { |
|||
timeout: 100 |
|||
}); |
|||
|
|||
setTimeout(function() { |
|||
fn(options); |
|||
}, options.timeout); |
|||
} |
|||
|
|||
handle({ timeout: 1000 }, function() { |
|||
// we're here 1000 ms later |
|||
}); |
|||
|
|||
handle({ timeout: 10000 }, function() { |
|||
// we're here 10s later |
|||
}); |
|||
|
|||
``` |
|||
|
|||
## summary |
|||
|
|||
this module exports a function that takes 2 arguments: `options` and `defaults`. When called, it overrides all of `undefined` properties in `options` with the clones of properties defined in `defaults` |
|||
|
|||
Sidecases: if called with a falsy `options` value, options will be initialized to a new object before being merged onto. |
|||
|
|||
## license |
|||
|
|||
[MIT](LICENSE) |
@ -0,0 +1,13 @@ |
|||
var clone = require('clone'); |
|||
|
|||
module.exports = function(options, defaults) { |
|||
options = options || {}; |
|||
|
|||
Object.keys(defaults).forEach(function(key) { |
|||
if (typeof options[key] === 'undefined') { |
|||
options[key] = clone(defaults[key]); |
|||
} |
|||
}); |
|||
|
|||
return options; |
|||
}; |
@ -0,0 +1,57 @@ |
|||
{ |
|||
"_from": "defaults@^1.0.3", |
|||
"_id": "defaults@1.0.3", |
|||
"_inBundle": false, |
|||
"_integrity": "sha1-xlYFHpgX2f8I7YgUd/P+QBnz730=", |
|||
"_location": "/defaults", |
|||
"_phantomChildren": {}, |
|||
"_requested": { |
|||
"type": "range", |
|||
"registry": true, |
|||
"raw": "defaults@^1.0.3", |
|||
"name": "defaults", |
|||
"escapedName": "defaults", |
|||
"rawSpec": "^1.0.3", |
|||
"saveSpec": null, |
|||
"fetchSpec": "^1.0.3" |
|||
}, |
|||
"_requiredBy": [ |
|||
"/wcwidth" |
|||
], |
|||
"_resolved": "https://registry.npmjs.org/defaults/-/defaults-1.0.3.tgz", |
|||
"_shasum": "c656051e9817d9ff08ed881477f3fe4019f3ef7d", |
|||
"_spec": "defaults@^1.0.3", |
|||
"_where": "E:\\mu_dist\\@xyx\\beer\\test-command\\node_modules\\wcwidth", |
|||
"author": { |
|||
"name": "Elijah Insua", |
|||
"email": "tmpvar@gmail.com" |
|||
}, |
|||
"bugs": { |
|||
"url": "https://github.com/tmpvar/defaults/issues" |
|||
}, |
|||
"bundleDependencies": false, |
|||
"dependencies": { |
|||
"clone": "^1.0.2" |
|||
}, |
|||
"deprecated": false, |
|||
"description": "merge single level defaults over a config object", |
|||
"devDependencies": { |
|||
"tap": "^2.0.0" |
|||
}, |
|||
"homepage": "https://github.com/tmpvar/defaults#readme", |
|||
"keywords": [ |
|||
"config", |
|||
"defaults" |
|||
], |
|||
"license": "MIT", |
|||
"main": "index.js", |
|||
"name": "defaults", |
|||
"repository": { |
|||
"type": "git", |
|||
"url": "git://github.com/tmpvar/defaults.git" |
|||
}, |
|||
"scripts": { |
|||
"test": "node test.js" |
|||
}, |
|||
"version": "1.0.3" |
|||
} |
@ -0,0 +1,34 @@ |
|||
var defaults = require('./'), |
|||
test = require('tap').test; |
|||
|
|||
test("ensure options is an object", function(t) { |
|||
var options = defaults(false, { a : true }); |
|||
t.ok(options.a); |
|||
t.end() |
|||
}); |
|||
|
|||
test("ensure defaults override keys", function(t) { |
|||
var result = defaults({}, { a: false, b: true }); |
|||
t.ok(result.b, 'b merges over undefined'); |
|||
t.equal(result.a, false, 'a merges over undefined'); |
|||
t.end(); |
|||
}); |
|||
|
|||
test("ensure defined keys are not overwritten", function(t) { |
|||
var result = defaults({ b: false }, { a: false, b: true }); |
|||
t.equal(result.b, false, 'b not merged'); |
|||
t.equal(result.a, false, 'a merges over undefined'); |
|||
t.end(); |
|||
}); |
|||
|
|||
test("ensure defaults clone nested objects", function(t) { |
|||
var d = { a: [1,2,3], b: { hello : 'world' } }; |
|||
var result = defaults({}, d); |
|||
t.equal(result.a.length, 3, 'objects should be clones'); |
|||
t.ok(result.a !== d.a, 'objects should be clones'); |
|||
|
|||
t.equal(Object.keys(result.b).length, 1, 'objects should be clones'); |
|||
t.ok(result.b !== d.b, 'objects should be clones'); |
|||
t.end(); |
|||
}); |
|||
|
@ -0,0 +1,20 @@ |
|||
Copyright Mathias Bynens <https://mathiasbynens.be/> |
|||
|
|||
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 @@ |
|||
# emoji-regex [](https://travis-ci.org/mathiasbynens/emoji-regex) |
|||
|
|||
_emoji-regex_ offers a regular expression to match all emoji symbols (including textual representations of emoji) as per the Unicode Standard. |
|||
|
|||
This repository contains a script that generates this regular expression based on [the data from Unicode v12](https://github.com/mathiasbynens/unicode-12.0.0). Because of this, the regular expression can easily be updated whenever new emoji are added to the Unicode standard. |
|||
|
|||
## Installation |
|||
|
|||
Via [npm](https://www.npmjs.com/): |
|||
|
|||
```bash |
|||
npm install emoji-regex |
|||
``` |
|||
|
|||
In [Node.js](https://nodejs.org/): |
|||
|
|||
```js |
|||
const emojiRegex = require('emoji-regex'); |
|||
// Note: because the regular expression has the global flag set, this module |
|||
// exports a function that returns the regex rather than exporting the regular |
|||
// expression itself, to make it impossible to (accidentally) mutate the |
|||
// original regular expression. |
|||
|
|||
const text = ` |
|||
\u{231A}: ⌚ default emoji presentation character (Emoji_Presentation) |
|||
\u{2194}\u{FE0F}: ↔️ default text presentation character rendered as emoji |
|||
\u{1F469}: 👩 emoji modifier base (Emoji_Modifier_Base) |
|||
\u{1F469}\u{1F3FF}: 👩🏿 emoji modifier base followed by a modifier |
|||
`; |
|||
|
|||
const regex = emojiRegex(); |
|||
let match; |
|||
while (match = regex.exec(text)) { |
|||
const emoji = match[0]; |
|||
console.log(`Matched sequence ${ emoji } — code points: ${ [...emoji].length }`); |
|||
} |
|||
``` |
|||
|
|||
Console output: |
|||
|
|||
``` |
|||
Matched sequence ⌚ — code points: 1 |
|||
Matched sequence ⌚ — code points: 1 |
|||
Matched sequence ↔️ — code points: 2 |
|||
Matched sequence ↔️ — code points: 2 |
|||
Matched sequence 👩 — code points: 1 |
|||
Matched sequence 👩 — code points: 1 |
|||
Matched sequence 👩🏿 — code points: 2 |
|||
Matched sequence 👩🏿 — code points: 2 |
|||
``` |
|||
|
|||
To match emoji in their textual representation as well (i.e. emoji that are not `Emoji_Presentation` symbols and that aren’t forced to render as emoji by a variation selector), `require` the other regex: |
|||
|
|||
```js |
|||
const emojiRegex = require('emoji-regex/text.js'); |
|||
``` |
|||
|
|||
Additionally, in environments which support ES2015 Unicode escapes, you may `require` ES2015-style versions of the regexes: |
|||
|
|||
```js |
|||
const emojiRegex = require('emoji-regex/es2015/index.js'); |
|||
const emojiRegexText = require('emoji-regex/es2015/text.js'); |
|||
``` |
|||
|
|||
## Author |
|||
|
|||
| [](https://twitter.com/mathias "Follow @mathias on Twitter") | |
|||
|---| |
|||
| [Mathias Bynens](https://mathiasbynens.be/) | |
|||
|
|||
## License |
|||
|
|||
_emoji-regex_ is available under the [MIT](https://mths.be/mit) license. |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,23 @@ |
|||
declare module 'emoji-regex' { |
|||
function emojiRegex(): RegExp; |
|||
|
|||
export default emojiRegex; |
|||
} |
|||
|
|||
declare module 'emoji-regex/text' { |
|||
function emojiRegex(): RegExp; |
|||
|
|||
export default emojiRegex; |
|||
} |
|||
|
|||
declare module 'emoji-regex/es2015' { |
|||
function emojiRegex(): RegExp; |
|||
|
|||
export default emojiRegex; |
|||
} |
|||
|
|||
declare module 'emoji-regex/es2015/text' { |
|||
function emojiRegex(): RegExp; |
|||
|
|||
export default emojiRegex; |
|||
} |
File diff suppressed because one or more lines are too long
@ -0,0 +1,77 @@ |
|||
{ |
|||
"_from": "emoji-regex@^8.0.0", |
|||
"_id": "emoji-regex@8.0.0", |
|||
"_inBundle": false, |
|||
"_integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==", |
|||
"_location": "/emoji-regex", |
|||
"_phantomChildren": {}, |
|||
"_requested": { |
|||
"type": "range", |
|||
"registry": true, |
|||
"raw": "emoji-regex@^8.0.0", |
|||
"name": "emoji-regex", |
|||
"escapedName": "emoji-regex", |
|||
"rawSpec": "^8.0.0", |
|||
"saveSpec": null, |
|||
"fetchSpec": "^8.0.0" |
|||
}, |
|||
"_requiredBy": [ |
|||
"/string-width" |
|||
], |
|||
"_resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", |
|||
"_shasum": "e818fd69ce5ccfcb404594f842963bf53164cc37", |
|||
"_spec": "emoji-regex@^8.0.0", |
|||
"_where": "E:\\mu_dist\\@xyx\\beer\\test-command\\node_modules\\string-width", |
|||
"author": { |
|||
"name": "Mathias Bynens", |
|||
"url": "https://mathiasbynens.be/" |
|||
}, |
|||
"bugs": { |
|||
"url": "https://github.com/mathiasbynens/emoji-regex/issues" |
|||
}, |
|||
"bundleDependencies": false, |
|||
"deprecated": false, |
|||
"description": "A regular expression to match all Emoji-only symbols as per the Unicode Standard.", |
|||
"devDependencies": { |
|||
"@babel/cli": "^7.2.3", |
|||
"@babel/core": "^7.3.4", |
|||
"@babel/plugin-proposal-unicode-property-regex": "^7.2.0", |
|||
"@babel/preset-env": "^7.3.4", |
|||
"mocha": "^6.0.2", |
|||
"regexgen": "^1.3.0", |
|||
"unicode-12.0.0": "^0.7.9" |
|||
}, |
|||
"files": [ |
|||
"LICENSE-MIT.txt", |
|||
"index.js", |
|||
"index.d.ts", |
|||
"text.js", |
|||
"es2015/index.js", |
|||
"es2015/text.js" |
|||
], |
|||
"homepage": "https://mths.be/emoji-regex", |
|||
"keywords": [ |
|||
"unicode", |
|||
"regex", |
|||
"regexp", |
|||
"regular expressions", |
|||
"code points", |
|||
"symbols", |
|||
"characters", |
|||
"emoji" |
|||
], |
|||
"license": "MIT", |
|||
"main": "index.js", |
|||
"name": "emoji-regex", |
|||
"repository": { |
|||
"type": "git", |
|||
"url": "git+https://github.com/mathiasbynens/emoji-regex.git" |
|||
}, |
|||
"scripts": { |
|||
"build": "rm -rf -- es2015; babel src -d .; NODE_ENV=es2015 babel src -d ./es2015; node script/inject-sequences.js", |
|||
"test": "mocha", |
|||
"test:watch": "npm run test -- --watch" |
|||
}, |
|||
"types": "index.d.ts", |
|||
"version": "8.0.0" |
|||
} |
File diff suppressed because one or more lines are too long
@ -0,0 +1,11 @@ |
|||
'use strict'; |
|||
|
|||
var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g; |
|||
|
|||
module.exports = function (str) { |
|||
if (typeof str !== 'string') { |
|||
throw new TypeError('Expected a string'); |
|||
} |
|||
|
|||
return str.replace(matchOperatorsRe, '\\$&'); |
|||
}; |
@ -0,0 +1,21 @@ |
|||
The MIT License (MIT) |
|||
|
|||
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,82 @@ |
|||
{ |
|||
"_from": "escape-string-regexp@^1.0.5", |
|||
"_id": "escape-string-regexp@1.0.5", |
|||
"_inBundle": false, |
|||
"_integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", |
|||
"_location": "/escape-string-regexp", |
|||
"_phantomChildren": {}, |
|||
"_requested": { |
|||
"type": "range", |
|||
"registry": true, |
|||
"raw": "escape-string-regexp@^1.0.5", |
|||
"name": "escape-string-regexp", |
|||
"escapedName": "escape-string-regexp", |
|||
"rawSpec": "^1.0.5", |
|||
"saveSpec": null, |
|||
"fetchSpec": "^1.0.5" |
|||
}, |
|||
"_requiredBy": [ |
|||
"/chalk", |
|||
"/figures" |
|||
], |
|||
"_resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", |
|||
"_shasum": "1b61c0562190a8dff6ae3bb2cf0200ca130b86d4", |
|||
"_spec": "escape-string-regexp@^1.0.5", |
|||
"_where": "E:\\mu_dist\\@xyx\\beer\\test-command\\node_modules\\chalk", |
|||
"author": { |
|||
"name": "Sindre Sorhus", |
|||
"email": "sindresorhus@gmail.com", |
|||
"url": "sindresorhus.com" |
|||
}, |
|||
"bugs": { |
|||
"url": "https://github.com/sindresorhus/escape-string-regexp/issues" |
|||
}, |
|||
"bundleDependencies": false, |
|||
"deprecated": false, |
|||
"description": "Escape RegExp special characters", |
|||
"devDependencies": { |
|||
"ava": "*", |
|||
"xo": "*" |
|||
}, |
|||
"engines": { |
|||
"node": ">=0.8.0" |
|||
}, |
|||
"files": [ |
|||
"index.js" |
|||
], |
|||
"homepage": "https://github.com/sindresorhus/escape-string-regexp#readme", |
|||
"keywords": [ |
|||
"escape", |
|||
"regex", |
|||
"regexp", |
|||
"re", |
|||
"regular", |
|||
"expression", |
|||
"string", |
|||
"str", |
|||
"special", |
|||
"characters" |
|||
], |
|||
"license": "MIT", |
|||
"maintainers": [ |
|||
{ |
|||
"name": "Sindre Sorhus", |
|||
"email": "sindresorhus@gmail.com", |
|||
"url": "sindresorhus.com" |
|||
}, |
|||
{ |
|||
"name": "Joshua Boy Nicolai Appelman", |
|||
"email": "joshua@jbna.nl", |
|||
"url": "jbna.nl" |
|||
} |
|||
], |
|||
"name": "escape-string-regexp", |
|||
"repository": { |
|||
"type": "git", |
|||
"url": "git+https://github.com/sindresorhus/escape-string-regexp.git" |
|||
}, |
|||
"scripts": { |
|||
"test": "xo && ava" |
|||
}, |
|||
"version": "1.0.5" |
|||
} |
@ -0,0 +1,27 @@ |
|||
# escape-string-regexp [](https://travis-ci.org/sindresorhus/escape-string-regexp) |
|||
|
|||
> Escape RegExp special characters |
|||
|
|||
|
|||
## Install |
|||
|
|||
``` |
|||
$ npm install --save escape-string-regexp |
|||
``` |
|||
|
|||
|
|||
## Usage |
|||
|
|||
```js |
|||
const escapeStringRegexp = require('escape-string-regexp'); |
|||
|
|||
const escapedString = escapeStringRegexp('how much $ for a unicorn?'); |
|||
//=> 'how much \$ for a unicorn\?' |
|||
|
|||
new RegExp(escapedString); |
|||
``` |
|||
|
|||
|
|||
## License |
|||
|
|||
MIT © [Sindre Sorhus](http://sindresorhus.com) |
@ -0,0 +1,21 @@ |
|||
The MIT License (MIT) |
|||
|
|||
Copyright (c) 2016 Kevin Gravier |
|||
|
|||
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,171 @@ |
|||
# External Editor |
|||
|
|||
[](https://travis-ci.org/mrkmg/node-external-editor/branches) |
|||
[](https://www.npmjs.com/package/external-editor) |
|||
[](https://opensource.org/licenses/MIT) |
|||
|
|||
|
|||
A node module to edit a string with a users preferred text editor using $VISUAL or $ENVIRONMENT. |
|||
|
|||
Version: 3.1.0 |
|||
|
|||
As of version 3.0.0, the minimum version of node supported is 4. |
|||
|
|||
## Install |
|||
|
|||
`npm install external-editor --save` |
|||
|
|||
## Usage |
|||
|
|||
A simple example using the `.edit` convenience method |
|||
|
|||
import {edit} from "external-editor"; |
|||
const data = edit('\n\n# Please write your text above'); |
|||
console.log(data); |
|||
|
|||
A full featured example |
|||
|
|||
import {ExternalEditor, CreateFileError, ReadFileError, RemoveFileError} from "external-editor" |
|||
|
|||
try { |
|||
const editor = new ExternalEditor(); |
|||
const text = editor.run() // the text is also available in editor.text |
|||
|
|||
if (editor.last_exit_status !== 0) { |
|||
console.log("The editor exited with a non-zero code"); |
|||
} |
|||
} catch (err) { |
|||
if (err instanceOf CreateFileError) { |
|||
console.log('Failed to create the temporary file'); |
|||
} else if (err instanceOf ReadFileError) { |
|||
console.log('Failed to read the temporary file'); |
|||
} else if (err instanceOf LaunchEditorError) { |
|||
console.log('Failed to launch your editor'); |
|||
} else { |
|||
throw err; |
|||
} |
|||
} |
|||
|
|||
// Do things with the text |
|||
|
|||
// Eventually call the cleanup to remove the temporary file |
|||
try { |
|||
editor.cleanup(); |
|||
} catch (err) { |
|||
if (err instanceOf RemoveFileError) { |
|||
console.log('Failed to remove the temporary file'); |
|||
} else { |
|||
throw err |
|||
} |
|||
} |
|||
|
|||
|
|||
#### API |
|||
**Convenience Methods** |
|||
|
|||
- `edit(text, config)` |
|||
- `text` (string) *Optional* Defaults to empty string |
|||
- `config` (Config) *Optional* Options for temporary file creation |
|||
- **Returns** (string) The contents of the file |
|||
- Could throw `CreateFileError`, `ReadFileError`, or `LaunchEditorError`, or `RemoveFileError` |
|||
- `editAsync(text, callback, config)` |
|||
- `text` (string) *Optional* Defaults to empty string |
|||
- `callback` (function (error, text)) |
|||
- `error` could be of type `CreateFileError`, `ReadFileError`, or `LaunchEditorError`, or `RemoveFileError` |
|||
- `text`(string) The contents of the file |
|||
- `config` (Config) *Optional* Options for temporary file creation |
|||
|
|||
|
|||
**Errors** |
|||
|
|||
- `CreateFileError` Error thrown if the temporary file could not be created. |
|||
- `ReadFileError` Error thrown if the temporary file could not be read. |
|||
- `RemoveFileError` Error thrown if the temporary file could not be removed during cleanup. |
|||
- `LaunchEditorError` Error thrown if the editor could not be launched. |
|||
|
|||
**External Editor Public Methods** |
|||
|
|||
- `new ExternalEditor(text, config)` |
|||
- `text` (string) *Optional* Defaults to empty string |
|||
- `config` (Config) *Optional* Options for temporary file creation |
|||
- Could throw `CreateFileError` |
|||
- `run()` Launches the editor. |
|||
- **Returns** (string) The contents of the file |
|||
- Could throw `LaunchEditorError` or `ReadFileError` |
|||
- `runAsync(callback)` Launches the editor in an async way |
|||
- `callback` (function (error, text)) |
|||
- `error` could be of type `ReadFileError` or `LaunchEditorError` |
|||
- `text`(string) The contents of the file |
|||
- `cleanup()` Removes the temporary file. |
|||
- Could throw `RemoveFileError` |
|||
|
|||
**External Editor Public Properties** |
|||
|
|||
- `text` (string) *readonly* The text in the temporary file. |
|||
- `editor.bin` (string) The editor determined from the environment. |
|||
- `editor.args` (array) Default arguments for the bin |
|||
- `tempFile` (string) Path to temporary file. Can be changed, but be careful as the temporary file probably already |
|||
exists and would need be removed manually. |
|||
- `lastExitStatus` (number) The last exit code emitted from the editor. |
|||
|
|||
**Config Options** |
|||
|
|||
- `prefix` (string) *Optional* A prefix for the file name. |
|||
- `postfix` (string; *Optional* A postfix for the file name. Useful if you want to provide an extension. |
|||
- `mode` (number) *Optional* Which mode to create the file with. e.g. 644 |
|||
- `template` (string) *Optional* A template for the filename. See [tmp](https://www.npmjs.com/package/tmp). |
|||
- `dir` (string) *Optional* Which path to store the file. |
|||
|
|||
## Errors |
|||
|
|||
All errors have a simple message explaining what went wrong. They all also have an `originalError` property containing |
|||
the original error thrown for debugging purposes. |
|||
|
|||
## Why Synchronous? |
|||
|
|||
Everything is synchronous to make sure the editor has complete control of the stdin and stdout. Testing has shown |
|||
async launching of the editor can lead to issues when using readline or other packages which try to read from stdin or |
|||
write to stdout. Seeing as this will be used in an interactive CLI environment, I made the decision to force the package |
|||
to be synchronous. If you know a reliable way to force all stdin and stdout to be limited only to the child_process, |
|||
please submit a PR. |
|||
|
|||
If async is really needed, you can use `editAsync` or `runAsync`. If you are using readline or have anything else |
|||
listening to the stdin or you write to stdout, you will most likely have problem, so make sure to remove any other |
|||
listeners on stdin, stdout, or stderr. |
|||
|
|||
## Demo |
|||
|
|||
[](https://asciinema.org/a/a1qh9lypbe65mj0ivfuoslz2s) |
|||
|
|||
## Breaking Changes from v2 to v3 |
|||
|
|||
- NodeJS 0.12 support dropped. |
|||
- Switched to named imports. |
|||
- All "snake_cased" variables and properties are now "camelCased". |
|||
- `ExternalEditor.temp_file` is now `ExternalEditor.tempFile`. |
|||
- `ExternalEditor.last_exit_status` is now `ExternalEditor.lastExitStatus`. |
|||
- `Error.original_error` is now `Error.originalError`. |
|||
|
|||
## License |
|||
|
|||
The MIT License (MIT) |
|||
|
|||
Copyright (c) 2016-2018 Kevin Gravier |
|||
|
|||
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,40 @@ |
|||
var ExternalEditor = require('./main').ExternalEditor; |
|||
var readline = require('readline'); |
|||
|
|||
var rl = readline.createInterface({ |
|||
input: process.stdin, |
|||
output: null |
|||
}); |
|||
|
|||
var message = '\n\n# Please Write a message\n# Any line starting with # is ignored'; |
|||
|
|||
process.stdout.write('Please write a message. (press enter to launch your preferred editor)'); |
|||
|
|||
editor = new ExternalEditor(message); |
|||
|
|||
rl.on('line', function () { |
|||
try { |
|||
rl.pause(); |
|||
editor.runAsync(function (error, response) |
|||
{ |
|||
if (error) { |
|||
process.stdout.write(error.message); |
|||
process.exit(1); |
|||
} |
|||
if (response.length === 0) { |
|||
readline.moveCursor(process.stdout, 0, -1); |
|||
process.stdout.write('Your message was empty, please try again. (press enter to launch your preferred editor)'); |
|||
rl.resume(); |
|||
} else { |
|||
process.stdout.write('Your Message:\n'); |
|||
process.stdout.write(response); |
|||
process.stdout.write('\n'); |
|||
rl.close(); |
|||
} |
|||
}); |
|||
} catch (err) { |
|||
process.stderr.write(err.message); |
|||
process.stdout.write('\n'); |
|||
rl.close(); |
|||
} |
|||
}); |
@ -0,0 +1,38 @@ |
|||
var ExternalEditor = require('./main').ExternalEditor; |
|||
var readline = require('readline'); |
|||
|
|||
var rl = readline.createInterface({ |
|||
input: process.stdin, |
|||
output: null |
|||
}); |
|||
|
|||
var message = '\n\n# Please Write a message\n# Any line starting with # is ignored'; |
|||
|
|||
process.stdout.write('Please write a message. (press enter to launch your preferred editor)'); |
|||
|
|||
editor = new ExternalEditor(message); |
|||
|
|||
rl.on('line', function () { |
|||
try { |
|||
// Get response, remove all lines starting with #, remove any trailing newlines.
|
|||
var response = editor.run().replace(/^#.*\n?/gm, '').replace(/\n+$/g, '').trim(); |
|||
|
|||
if (editor.lastExitStatus !== 0) { |
|||
process.stderr.write("WARN: The editor exited with a non-zero status\n\n") |
|||
} |
|||
|
|||
if (response.length === 0) { |
|||
readline.moveCursor(process.stdout, 0, -1); |
|||
process.stdout.write('Your message was empty, please try again. (press enter to launch your preferred editor)'); |
|||
} else { |
|||
process.stdout.write('Your Message:\n'); |
|||
process.stdout.write(response); |
|||
process.stdout.write('\n'); |
|||
rl.close(); |
|||
} |
|||
} catch (err) { |
|||
process.stderr.write(err.message); |
|||
process.stdout.write('\n'); |
|||
rl.close(); |
|||
} |
|||
}); |
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue