Comparing version 1.2.2 to 1.3.0
# Change log | ||
## 1.3.0 (2021-12-29) | ||
- added support CommonJS (now supported ESM and CommonJS) | ||
- added aliases: `.fg()` for `.ansi256()` and `.bg()` for `.bgAnsi256()` methods | ||
- fixed some inner param types | ||
- remove examples from NPM package (it can be cloned und run local) | ||
## 1.2.2 (2021-12-28) | ||
@@ -4,0 +10,0 @@ - fixed the path of examples in package.json |
{ | ||
"name": "ansis", | ||
"version": "1.2.2", | ||
"version": "1.3.0", | ||
"description": "Color styling of text for ANSI terminals using the SGR codes defined in the ECMA-48 standard.", | ||
@@ -43,3 +43,4 @@ "keywords": [ | ||
"type": "module", | ||
"main": "src/index.js", | ||
"main": "src/commonjs/index.cjs", | ||
"module": "./src/index.js", | ||
"types": "src/index.d.ts", | ||
@@ -49,2 +50,3 @@ "scripts": { | ||
"bench": "node ./bench/index.js", | ||
"build:cjs": "rollup -c", | ||
"test": "NODE_OPTIONS=--experimental-vm-modules jest --detectOpenHandles", | ||
@@ -55,3 +57,2 @@ "test:coverage": "NODE_OPTIONS=--experimental-vm-modules jest --detectOpenHandles --collectCoverage" | ||
"src", | ||
"examples", | ||
"CHANGELOG.md", | ||
@@ -64,4 +65,2 @@ "README.md", | ||
}, | ||
"peerDependencies": { | ||
}, | ||
"devDependencies": { | ||
@@ -72,4 +71,5 @@ "@babel/core": "^7.16.5", | ||
"jest": "^27.4.5", | ||
"prettier": "^2.5.1" | ||
"prettier": "^2.5.1", | ||
"rollup": "^2.62.0" | ||
} | ||
} |
@@ -25,15 +25,12 @@ <h1 align="center"> | ||
```console | ||
npm install ansis --save-dev | ||
```bash | ||
npm install ansis --save | ||
``` | ||
## Show ANSI demo | ||
``` | ||
npm run demo | ||
``` | ||
## Quick start | ||
```js | ||
import ansis from 'ansis'; | ||
import ansis from 'ansis'; // ESM | ||
// OR | ||
const ansis = require('ansis'); // CommonJS | ||
@@ -47,5 +44,12 @@ console.log(ansis.green(`Hello ${ansis.inverse('ANSI')} World!`)); | ||
## Show ANSI demo | ||
```bash | ||
git clone https://github.com/webdiscus/ansis.git | ||
cd ./ansis | ||
npm i | ||
npm run demo | ||
``` | ||
## Features | ||
- supports ES modules, 100% vanilla JavaScript, compact code, no dependencies | ||
- supports `ES Modules` and `CommonJS`, no dependencies | ||
- powerful and lightweight library is faster than many others such as `chalk` `kleur` `ansi-colors` etc. | ||
@@ -155,14 +159,29 @@ - supports the standard de facto API of the `chalk` | ||
## 256 ANSI colors | ||
The pre-defined set of 256 colors: | ||
| Code range | Description | | ||
|-----------:|-------------------------------------------| | ||
| 0 - 7 | standard colors | | ||
| 8 - 15 | bright colors | | ||
| 16 - 231 | 6 × 6 × 6 cube (216 colors) | | ||
| 232 - 255 | grayscale from black to white in 24 steps | | ||
| | ||
See [ANSI color codes](https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit). | ||
**Foreground method:** `.ansi256(code)` has aliases `.ansi(code)` and `.fg(code)`.\ | ||
**Background method:** `.bgAnsi256(code)` has aliases `.bgAnsi(code)` and `.bg(code)`. | ||
```js | ||
// foreground color | ||
ansis.ansi256(96).bold('bold Bright Cyan'); | ||
ansis.fg(96).bold('bold Bright Cyan'); // `fg` is the short alias for `ansi256` | ||
// background color | ||
ansis.bgAnsi256(105)('Bright Magenta'); | ||
ansis.bg(105)('Bright Magenta'); // `bg` is the short alias for `bgAnsi256` | ||
``` | ||
> Aliases | ||
> | ||
> `ansis.ansi()` is alias for `ansis.ansi256()`\ | ||
> `ansis.bgAnsi()` is alias for `ansis.bgAnsi256()` | ||
> The `ansi256()` and `bgAnsi256()` methods are implemented for compatibility with the `chalk` API. | ||
@@ -205,3 +224,3 @@ ## Truecolor | ||
- **New Line**: correct break of escape sequences at `end of line`\ | ||
<img width="128" src="doc/img/break-style-nl.png" alt="new line"> | ||
![output](doc/img/break-style-nl.png?raw=true "break styles at EOL") | ||
- **NO_COLOR**: supports the environment variables [`NO_COLOR`](https://no-color.org) `FORCE_COLOR` and flags `--no-color` `--color` | ||
@@ -211,10 +230,11 @@ | ||
### Initialize | ||
``` | ||
cd ./bench | ||
### Setup | ||
```bash | ||
git clone https://github.com/webdiscus/ansis.git | ||
cd ./ansis/bench | ||
npm i | ||
``` | ||
### Start benchmark | ||
``` | ||
### Run benchmark | ||
```bash | ||
npm run bench | ||
@@ -375,2 +395,6 @@ ``` | ||
## Build CommonJS bundle | ||
`npm run build:cjs` will create the `./src/commonjs/index.cjs` file from ESM entrypoint. | ||
## Also See | ||
@@ -377,0 +401,0 @@ |
@@ -17,6 +17,6 @@ interface StyleProperties { | ||
* | ||
* @param {string[]} strings String or multiple strings in arguments. | ||
* @param {string} string | ||
* All strings from the arguments will be concatenated. | ||
*/ | ||
(...strings: string[]): string; | ||
(string: string): string; | ||
} | ||
@@ -44,3 +44,3 @@ | ||
/** | ||
* Alias to ansi256. | ||
* Alias for ansi256. | ||
* @param {number} code in range [0, 255]. | ||
@@ -51,2 +51,8 @@ */ | ||
/** | ||
* Alias for ansi256. | ||
* @param {number} code in range [0, 255]. | ||
*/ | ||
fg: (code: number) => AnsisInstance; | ||
/** | ||
* Set RGB values for foreground color. | ||
@@ -83,3 +89,3 @@ * | ||
/** | ||
* Alias to bgAnsi256. | ||
* Alias for bgAnsi256. | ||
* @param {number} code in range [0, 255]. | ||
@@ -90,2 +96,8 @@ */ | ||
/** | ||
* Alias for bgAnsi256. | ||
* @param {number} code in range [0, 255]. | ||
*/ | ||
bg: (code: number) => AnsisInstance; | ||
/** | ||
* Set RGB values for background color. | ||
@@ -92,0 +104,0 @@ * |
@@ -30,3 +30,3 @@ import { clamp, hexToRgb, strReplaceAll } from './utils.js'; | ||
* | ||
* @param {string | string[]} str | ||
* @param {string} str | ||
* @param {AnsisProps} props | ||
@@ -111,3 +111,3 @@ * @returns {string} | ||
/** | ||
* Alias to ansi256. | ||
* Alias for ansi256. | ||
* @type {AnsisInstance.ansi256} | ||
@@ -118,2 +118,9 @@ */ | ||
/** | ||
* Alias for `ansi256`. | ||
* @type {AnsisInstance.ansi256} | ||
*/ | ||
styles.fg = styles.ansi256; | ||
/** | ||
* @type {AnsisInstance.bgAnsi256} | ||
@@ -132,3 +139,3 @@ */ | ||
/** | ||
* Alias to bgAnsi256. | ||
* Alias for bgAnsi256. | ||
* @type {AnsisInstance.bgAnsi256} | ||
@@ -139,2 +146,8 @@ */ | ||
/** | ||
* Alias for bgAnsi256. | ||
* @type {AnsisInstance.bgAnsi256} | ||
*/ | ||
styles.bg = styles.bgAnsi256; | ||
/** | ||
* @type {AnsisInstance.rgb} | ||
@@ -141,0 +154,0 @@ */ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
45732
909
419
6