This repository has been archived by the owner on Nov 22, 2021. It is now read-only.
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
Showing
13 changed files
with
7,420 additions
and
243 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,9 @@ | ||
root = true | ||
|
||
[*] | ||
indent_style = space | ||
indent_size = 2 | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true |
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 |
---|---|---|
@@ -1,22 +1,40 @@ | ||
name: Tests | ||
on: [push, pull_request] | ||
name: Test | ||
on: | ||
push: | ||
pull_request: | ||
env: | ||
FORCE_COLOR: 2 | ||
jobs: | ||
test: | ||
env: | ||
NODE_ENV: development | ||
full: | ||
name: Node.js 16 Full | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout the repository | ||
uses: actions/checkout@v2 | ||
- name: Install Node.js | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: 16 | ||
- name: Install dependencies | ||
uses: bahmutov/npm-install@v1 | ||
- name: Run tests | ||
run: yarn test | ||
short: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
node-version: [12.x, 14.x] | ||
node-version: | ||
- 14 | ||
- 12 | ||
name: Node.js ${{ matrix.node-version }} Quick | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v1 | ||
- name: Use Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v1 | ||
- name: Checkout the repository | ||
uses: actions/checkout@v2 | ||
- name: Install Node.js ${{ matrix.node-version }} | ||
uses: actions/setup-node@v2 | ||
with: | ||
node-version: ${{ matrix.node-version }} | ||
- name: Test | ||
run: | | ||
npm install | ||
FORCE_COLOR= npx c8 --reporter=lcov npm test && npx codecov | ||
- name: Install dependencies | ||
uses: bahmutov/npm-install@v1 | ||
- name: Run unit tests | ||
run: jest |
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 |
---|---|---|
@@ -1,8 +1,4 @@ | ||
*.br | ||
*.gz | ||
*.cjs | ||
node_modules/ | ||
yarn-error.log | ||
|
||
package-lock.json | ||
node_modules | ||
coverage | ||
/.idea/ | ||
coverage/ |
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,7 @@ | ||
node_modules/ | ||
yarn-error.log | ||
yarn.lock | ||
|
||
test/ | ||
tsconfig.json | ||
coverage/ |
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 @@ | ||
# Change Log | ||
This project adheres to [Semantic Versioning](http://semver.org/). |
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 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright 2021 Andrey Sitnik <andrey@sitnik.ru> | ||
|
||
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 @@ | ||
# Nano Colors |
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 |
---|---|---|
@@ -1,93 +1,12 @@ | ||
declare module "colorette" { | ||
type Color = (text: string | number) => string | ||
|
||
interface Colorette { | ||
reset: Color | ||
bold: Color | ||
dim: Color | ||
italic: Color | ||
underline: Color | ||
inverse: Color | ||
hidden: Color | ||
strikethrough: Color | ||
black: Color | ||
red: Color | ||
green: Color | ||
yellow: Color | ||
blue: Color | ||
magenta: Color | ||
cyan: Color | ||
white: Color | ||
gray: Color | ||
bgBlack: Color | ||
bgRed: Color | ||
bgGreen: Color | ||
bgYellow: Color | ||
bgBlue: Color | ||
bgMagenta: Color | ||
bgCyan: Color | ||
bgWhite: Color | ||
blackBright: Color | ||
redBright: Color | ||
greenBright: Color | ||
yellowBright: Color | ||
blueBright: Color | ||
magentaBright: Color | ||
cyanBright: Color | ||
whiteBright: Color | ||
bgBlackBright: Color | ||
bgRedBright: Color | ||
bgGreenBright: Color | ||
bgYellowBright: Color | ||
bgBlueBright: Color | ||
bgMagentaBright: Color | ||
bgCyanBright: Color | ||
bgWhiteBright: Color | ||
} | ||
|
||
const reset: Color | ||
const bold: Color | ||
const dim: Color | ||
const italic: Color | ||
const underline: Color | ||
const inverse: Color | ||
const hidden: Color | ||
const strikethrough: Color | ||
const black: Color | ||
const red: Color | ||
const green: Color | ||
const yellow: Color | ||
const blue: Color | ||
const magenta: Color | ||
const cyan: Color | ||
const white: Color | ||
const gray: Color | ||
const bgBlack: Color | ||
const bgRed: Color | ||
const bgGreen: Color | ||
const bgYellow: Color | ||
const bgBlue: Color | ||
const bgMagenta: Color | ||
const bgCyan: Color | ||
const bgWhite: Color | ||
const blackBright: Color | ||
const redBright: Color | ||
const greenBright: Color | ||
const yellowBright: Color | ||
const blueBright: Color | ||
const magentaBright: Color | ||
const cyanBright: Color | ||
const whiteBright: Color | ||
const bgBlackBright: Color | ||
const bgRedBright: Color | ||
const bgGreenBright: Color | ||
const bgYellowBright: Color | ||
const bgBlueBright: Color | ||
const bgMagentaBright: Color | ||
const bgCyanBright: Color | ||
const bgWhiteBright: Color | ||
|
||
const isColorSupported: boolean | ||
|
||
function createColors(options?: { useColor: boolean }): Colorette | ||
} | ||
/** | ||
* Does environment support color output. | ||
* | ||
* ```js | ||
* import { isColorSupported } from 'nanocolors' | ||
* | ||
* if (isColorSupported) { | ||
* console.log('With colors') | ||
* } | ||
* ``` | ||
*/ | ||
export const isColorSupported: boolean |
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 |
---|---|---|
@@ -1,129 +1,3 @@ | ||
import * as tty from "tty" | ||
const isColorSupported = false | ||
|
||
const env = process.env | ||
|
||
const isDisabled = "NO_COLOR" in env | ||
const isForced = "FORCE_COLOR" in env | ||
const isWindows = process.platform === "win32" | ||
|
||
const isCompatibleTerminal = | ||
tty && tty.isatty(1) && env.TERM && env.TERM !== "dumb" | ||
|
||
const isCI = | ||
"CI" in env && | ||
("GITHUB_ACTIONS" in env || "GITLAB_CI" in env || "CIRCLECI" in env) | ||
|
||
export const isColorSupported = | ||
!isDisabled && (isForced || isWindows || isCompatibleTerminal || isCI) | ||
|
||
const raw = | ||
(open, close, searchRegex, replaceValue) => | ||
(s = "") => | ||
s === "" | ||
? s | ||
: open + | ||
(~(s += "").indexOf(close, 4) // skip opening \x1b[ | ||
? s.replace(searchRegex, replaceValue) | ||
: s) + | ||
close | ||
|
||
const init = (open, close) => | ||
raw( | ||
`\x1b[${open}m`, | ||
`\x1b[${close}m`, | ||
new RegExp(`\\x1b\\[${close}m`, "g"), | ||
`\x1b[${open}m` | ||
) | ||
|
||
export const reset = init(0, 0) | ||
export const bold = raw("\x1b[1m", "\x1b[22m", /\x1b\[22m/g, "\x1b[22m\x1b[1m") | ||
export const dim = raw("\x1b[2m", "\x1b[22m", /\x1b\[22m/g, "\x1b[22m\x1b[2m") | ||
export const italic = init(3, 23) | ||
export const underline = init(4, 24) | ||
export const inverse = init(7, 27) | ||
export const hidden = init(8, 28) | ||
export const strikethrough = init(9, 29) | ||
export const black = init(30, 39) | ||
export const red = init(31, 39) | ||
export const green = init(32, 39) | ||
export const yellow = init(33, 39) | ||
export const blue = init(34, 39) | ||
export const magenta = init(35, 39) | ||
export const cyan = init(36, 39) | ||
export const white = init(37, 39) | ||
export const gray = init(90, 39) | ||
export const bgBlack = init(40, 49) | ||
export const bgRed = init(41, 49) | ||
export const bgGreen = init(42, 49) | ||
export const bgYellow = init(43, 49) | ||
export const bgBlue = init(44, 49) | ||
export const bgMagenta = init(45, 49) | ||
export const bgCyan = init(46, 49) | ||
export const bgWhite = init(47, 49) | ||
export const blackBright = init(90, 39) | ||
export const redBright = init(91, 39) | ||
export const greenBright = init(92, 39) | ||
export const yellowBright = init(93, 39) | ||
export const blueBright = init(94, 39) | ||
export const magentaBright = init(95, 39) | ||
export const cyanBright = init(96, 39) | ||
export const whiteBright = init(97, 39) | ||
export const bgBlackBright = init(100, 49) | ||
export const bgRedBright = init(101, 49) | ||
export const bgGreenBright = init(102, 49) | ||
export const bgYellowBright = init(103, 49) | ||
export const bgBlueBright = init(104, 49) | ||
export const bgMagentaBright = init(105, 49) | ||
export const bgCyanBright = init(106, 49) | ||
export const bgWhiteBright = init(107, 49) | ||
|
||
const none = (any) => any | ||
|
||
export const createColors = ({ useColor = isColorSupported } = {}) => ({ | ||
...Object.entries({ | ||
reset, | ||
bold, | ||
dim, | ||
italic, | ||
underline, | ||
inverse, | ||
hidden, | ||
strikethrough, | ||
black, | ||
red, | ||
green, | ||
yellow, | ||
blue, | ||
magenta, | ||
cyan, | ||
white, | ||
gray, | ||
bgBlack, | ||
bgRed, | ||
bgGreen, | ||
bgYellow, | ||
bgBlue, | ||
bgMagenta, | ||
bgCyan, | ||
bgWhite, | ||
blackBright, | ||
redBright, | ||
greenBright, | ||
yellowBright, | ||
blueBright, | ||
magentaBright, | ||
cyanBright, | ||
whiteBright, | ||
bgBlackBright, | ||
bgRedBright, | ||
bgGreenBright, | ||
bgYellowBright, | ||
bgBlueBright, | ||
bgMagentaBright, | ||
bgCyanBright, | ||
bgWhiteBright, | ||
}).reduce((colorMap, [key, color]) => ({ | ||
...colorMap, | ||
[key]: useColor ? color : none, | ||
})), | ||
}) | ||
module.exports = { isColorSupported } |
Oops, something went wrong.