-
-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 95a349a
Showing
11 changed files
with
218 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = tab | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
|
||
[*.yml] | ||
indent_style = space | ||
indent_size = 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* text=auto eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: CI | ||
on: | ||
- push | ||
- pull_request | ||
jobs: | ||
test: | ||
name: Node.js ${{ matrix.node-version }} | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
node-version: | ||
- 16 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v2 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- run: npm install | ||
- run: npm test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import * as colors from './index.js'; | ||
|
||
console.log(colors.red('Hello'), colors.blue(colors.bold('World'))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Intentionally not using template literal for performance. | ||
const format = (startCode, endCode) => string => '\u001B[' + startCode + 'm' + string + '\u001B[' + endCode + 'm'; | ||
|
||
export const reset = format(0, 0); | ||
export const bold = format(1, 22); | ||
export const dim = format(2, 22); | ||
export const italic = format(3, 23); | ||
export const underline = format(4, 24); | ||
export const overline = format(53, 55); | ||
export const inverse = format(7, 27); | ||
export const hidden = format(8, 28); | ||
export const strikethrough = format(9, 29); | ||
|
||
export const black = format(30, 39); | ||
export const red = format(31, 39); | ||
export const green = format(32, 39); | ||
export const yellow = format(33, 39); | ||
export const blue = format(34, 39); | ||
export const magenta = format(35, 39); | ||
export const cyan = format(36, 39); | ||
export const white = format(37, 39); | ||
export const gray = format(90, 39); | ||
|
||
export const bgBlack = format(40, 49); | ||
export const bgRed = format(41, 49); | ||
export const bgGreen = format(42, 49); | ||
export const bgYellow = format(43, 49); | ||
export const bgBlue = format(44, 49); | ||
export const bgMagenta = format(45, 49); | ||
export const bgCyan = format(46, 49); | ||
export const bgWhite = format(47, 49); | ||
export const bgGray = format(100, 49); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
MIT License | ||
|
||
Copyright (c) Sindre Sorhus <[email protected]> (https://sindresorhus.com) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
{ | ||
"name": "yoctocolors", | ||
"version": "0.0.0", | ||
"description": "The smallest and fastest command-line coloring package on the internet. Trust me.", | ||
"license": "MIT", | ||
"repository": "sindresorhus/yoctocolors", | ||
"funding": "https://github.com/sponsors/sindresorhus", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "[email protected]", | ||
"url": "https://sindresorhus.com" | ||
}, | ||
"type": "module", | ||
"exports": "./index.js", | ||
"engines": { | ||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"index.d.ts" | ||
], | ||
"keywords": [ | ||
"color", | ||
"colour", | ||
"colors", | ||
"terminal", | ||
"console", | ||
"cli", | ||
"string", | ||
"ansi", | ||
"style", | ||
"styles", | ||
"tty", | ||
"formatting", | ||
"shell", | ||
"xterm", | ||
"log", | ||
"logging", | ||
"command-line", | ||
"text" | ||
], | ||
"devDependencies": { | ||
"ava": "^3.15.0", | ||
"xo": "^0.44.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<sup>yoctocolors 🌈</sup> | ||
|
||
> The smallest and fastest command-line coloring package on the internet. Trust me. | ||
The only thing that matters is micro-benchmark performance! ⚡️ | ||
|
||
*Check out [Chalk](https://github.com/chalk/chalk) if you want something more mature and comprehensive.* | ||
|
||
## Features | ||
|
||
- **4x faster and 5x smaller than [nanocolors](https://github.com/ai/nanocolors)** | ||
- Cat friendly | ||
- An additional color | ||
- Tree-shakeable but not stirred | ||
- Actively maintained (at least for another week) | ||
- No dependencies | ||
|
||
## Install | ||
|
||
```sh | ||
npm install yoctocolors | ||
``` | ||
|
||
## Usage | ||
|
||
```js | ||
import * as colors from 'yoctocolors'; | ||
|
||
console.log(colors.red('Yo!')); | ||
``` | ||
|
||
## Styles | ||
|
||
### Modifiers | ||
|
||
- `reset` - Reset the current style. | ||
- `bold` - Make the text bold. | ||
- `dim` - Make the text have lower opacity. | ||
- `italic` - Make the text italic. *(Not widely supported)* | ||
- `underline` - Put a horizontal line above the text. *(Not widely supported)* | ||
- `overline` - Put a horizontal line below the text. *(Not widely supported)* | ||
- `inverse`- Invert background and foreground colors. | ||
- `hidden` - Print the text but make it invisible. | ||
- `strikethrough` - Put a horizontal line through the center of the text. *(Not widely supported)* | ||
|
||
### Colors | ||
|
||
- `black` | ||
- `red` | ||
- `green` | ||
- `yellow` | ||
- `blue` | ||
- `magenta` | ||
- `cyan` | ||
- `white` | ||
- `gray` | ||
|
||
### Background colors | ||
|
||
- `bgBlack` | ||
- `bgRed` | ||
- `bgGreen` | ||
- `bgYellow` | ||
- `bgBlue` | ||
- `bgMagenta` | ||
- `bgCyan` | ||
- `bgWhite` | ||
- `bgGray` | ||
|
||
## Prior art | ||
|
||
Yes | ||
|
||
## Benchmark | ||
|
||
``` | ||
❯ ./test/simple-benchmark.js | ||
nanocolors 31508276 ops/sec | ||
picocolors 32524769 ops/sec | ||
yoctocolors 132894792 ops/sec | ||
``` | ||
|
||
*Benchmark from [`nanocolors`](https://github.com/ai/nanocolors/blob/main/test/simple-benchmark.js)* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import test from 'ava'; | ||
import * as colors from './index.js'; | ||
|
||
test('main', t => { | ||
t.is(colors.red('foo'), '\u001B[31mfoo\u001B[39m'); | ||
}); |