Skip to content

Commit

Permalink
release 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
webdiscus committed Mar 29, 2024
1 parent 07010f1 commit 96a2a47
Show file tree
Hide file tree
Showing 30 changed files with 1,066 additions and 628 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ jobs:
strategy:
matrix:
os: [ ubuntu-latest ]
# rollup require node >= 18
#node-version: [ 14, 16, 18, 20 ]
# rollup requires node >= 18
node-version: [ 18, 20 ]

runs-on: ${{ matrix.os }}
Expand Down
52 changes: 52 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,57 @@
# Change log

## 3.0.0 (2024-03-29)

- feat: add detection of color spaces support: TrueColor, 256 colors, 16 colors, no color
- feat: add fallback for supported color space: truecolor —> 256 colors —> 16 colors —> no colors
- perform: improve performance for `hex()` function
- chore: size increased from 3.2 KB to 3.8 KB as new features were added
- test: switch from jest to vitest
- test: add tests for new features
- docs: update readme for color spaces support

### BREAKING CHANGE

In the new major version `3.x` are removed unused styles and methods.

> ⚠️ Warning
>
> Before update, please check your code whether is used deleted styles and methods.
### Support Node.js

Drop supports for Node <= `14`. Minimal supported version is `15.0.0` (Released 2020-10-20).
In the theory the `v3` can works with Node`12`, but we can't test it.

### Deleted styles

The `not widely supported` styles are deleted:

- `faint` (alias for dim), replace in your code with `dim`
- `doubleUnderline`, replace in your code with `underline`
- `frame`, replace in your code with `underline`
- `encircle`, replace in your code with `underline`
- `overline`, replace in your code with `underline`

### Deleted methods

The methods are deleted:

- `ansi`, replace in your code with `ansi256` or `fg`
- `bgAnsi`, replace in your code with `bgAnsi256` or `bg`

### Deleted clamp in functions

The clamp (0, 255) for the ANSI 256 codes and RGB values is removed, because is unused.
You should self check the function arguments.

The affected functions:

- `ansi256` and `fg` (alias to ansi256) - expected a code in the range `0 - 255`
- `bgAnsi256` and `bg` (alias to bgAnsi256) - expected a code in the range`0 - 255`
- `rgb` - expected r, g, b values in the range `0 - 255`
- `bgRgb` - expected r, g, b values in the range `0 - 255`

## 2.3.0 (2024-02-15)

- feat: add detection of additional terminals, thanks @dse, [colors.js:issue #42](https://github.com/DABH/colors.js/issues/42)
Expand Down
194 changes: 135 additions & 59 deletions README.md

Large diffs are not rendered by default.

44 changes: 36 additions & 8 deletions bench/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,20 @@ import colorCli from 'colors-cli/lib/color-safe.js';
import kleur from 'kleur';
import * as kleurColors from 'kleur/colors';
import picocolors from 'picocolors';
import { Ansis, green, red, yellow, hex } from 'ansis';
import { Ansis, green, red, yellow, hex, rgb } from 'ansis';

import spectrum from '../examples/fixtures/spectrum.js';
import { getColorSpace } from '../src/color-support.js';

const colorSpace = getColorSpace();

const log = console.log;

if (colorSpace < 3) {
log(red.inverse` WARNING `, yellow`Your terminal don't support TrueColor!`);
log('The result of some tests can be NOT correct! Choose a modern terminal, e.g. iTerm.\n');
}

// create a new instance of Ansis for correct measure in benchmark
const ansis = new Ansis();

Expand Down Expand Up @@ -72,8 +82,7 @@ const bench = new Bench({

// colors present in all libraries
const baseColors = ['black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white'];

let fixture = [];
let fixture;

log(hex('#F88').inverse.bold` -= Benchmark =- `);

Expand All @@ -90,7 +99,8 @@ bench('Colorette bench').
add(vendors[6].name, () => fixture[6](vendors[6].lib)).
add(vendors[7].name, () => fixture[7](vendors[7].lib)).
add(vendors[8].name, () => fixture[8](vendors[8].lib)).
add(vendors[9].name, () => fixture[9](vendors[9].lib)).run();
add(vendors[9].name, () => fixture[9](vendors[9].lib)).
run();

// Base colors
bench('Base colors').
Expand Down Expand Up @@ -119,8 +129,8 @@ bench('Chained styles').
add('kleur/colors (not supported)', () =>
baseColors.forEach((style) => kleurColors[style].bold.underline.italic('foo')),
).
add('kleur', () => baseColors.forEach((style) => kleur[style]().bold().underline().italic('foo'))) // alternate syntax
.add('chalk', () => baseColors.forEach((style) => chalk[style].bold.underline.italic('foo'))).
// add('kleur', () => baseColors.forEach((style) => kleur[style]().bold().underline().italic('foo'))). // alternate syntax
add('chalk', () => baseColors.forEach((style) => chalk[style].bold.underline.italic('foo'))).
add('ansis', () => baseColors.forEach((style) => ansis[style].bold.underline.italic('foo'))).
run();

Expand Down Expand Up @@ -198,14 +208,32 @@ bench('Deep nested styles').
bench('RGB colors').add('chalk', () => {
for (let i = 0; i < 256; i++) chalk.rgb(i, 150, 200)('foo');
}).add('ansis', () => {
for (let i = 0; i < 256; i++) ansis.rgb(i, 150, 200)('foo');
for (let i = 0; i < 256; i++) rgb(i, 150, 200)('foo');
}).run();

// HEX colors
// the hex(), rgb(), bgHex(), bgRgb() methods support only chalk and ansis
bench('HEX colors').
add('chalk', () => chalk.hex('#FBA')('foo')).
add('ansis', () => ansis.hex('#FBA')('foo')).
add('ansis', () => hex('#FBA')('foo')).
run();

// Spectrum HEX colors
bench('Spectrum HEX colors').
add('chalk', () => {
let str = '';
spectrum.forEach(color => {
str += chalk.hex(color)('█');
});
return str;
}).
add('ansis', () => {
let str = '';
spectrum.forEach(color => {
str += hex(color)('█');
});
return str;
}).
run();

// Template literals
Expand Down
Binary file modified docs/img/ansis-demo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img/ansis-fallback.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions examples/ansis-styles-demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ import {
yellow, yellowBright,
} from 'ansis';

import { hexToRgb } from '../src/utils.js';
import spectrum from '../examples/fixtures/spectrum.js';

const out = `${bold`bold`} ${dim`dim`} ${italic`italic`} ${underline`underline`} ${strikethrough`strikethrough`} ${inverse`inverse`} ${bold.italic.underline.strike`bold italic underline strike`}` +
'\n' +
`${red`red`} ${green`green`} ${yellow`yellow`} ${blue`blue`} ${magenta`magenta`} ${cyan`cyan`} ${white`white`} ${gray`gray`} ${bold.yellow`bold yellow`} ${dim.cyan`dim cyan`} ${red.italic`italic red`} ` +
Expand All @@ -41,6 +44,24 @@ const out = `${bold`bold`} ${dim`dim`} ${italic`italic`} ${underline`underline`}
'#f10794',
].reduce((out, hex) => out + black.hex(hex)(hex), '') +
'\n' +
spectrum.reduce((out, hex) => out + black.hex(hex)('█'), '') +
'\n' +
[
'#d93611',
//'#d97511',
'#d9d609',
//'#a0d911',
'#18d911',
//'#11d9c2',
'#099dd9',
//'#1157d9',
'#7a09f6',
'#c509d9',
'#f10794',
].reduce((out, hex) => {
let [r, g, b] = hexToRgb(hex);
return out + black.hex(hex)(`[${r},${g},${b}]`);
}, '') + '\n' +
[
' 197 ',
' 203 ',
Expand Down
50 changes: 50 additions & 0 deletions examples/fixtures/spectrum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
export default [
'#ff0000',
'#ff0021',
'#ff0041',
'#ff0062',
'#ff0082',
'#ff00a3',
'#ff00c3',
'#ff00e4',
'#fa00ff',
'#d900ff',
'#b900ff',
'#9800ff',
'#7800ff',
'#5700ff',
'#3700ff',
'#1600ff',
'#000bff',
'#002bff',
'#004cff',
'#006cff',
'#008dff',
'#00adff',
'#00ceff',
'#00eeff',
'#00ffef',
'#00ffcf',
'#00ffae',
'#00ff8e',
'#00ff6d',
'#00ff4d',
'#00ff2c',
'#00ff0c',
'#15ff00',
'#36ff00',
'#56ff00',
'#77ff00',
'#97ff00',
'#b8ff00',
'#d8ff00',
'#f9ff00',
'#ffe500',
'#ffc400',
'#ffa400',
'#ff8300',
'#ff6300',
'#ff4200',
'#ff2200',
'#ff0100',
];
15 changes: 15 additions & 0 deletions examples/spectrum.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env node

import { hex, bgHex } from '../src/index.mjs';
import spectrum from './fixtures/spectrum.js';

const log = console.log;

let str = '';
spectrum.forEach(color => {
str += hex(color)('█');
});

log();
log(str);
log();
34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ansis",
"version": "2.3.0",
"description": "Colorize text in terminal or console output with ANSI colors & styles",
"version": "3.0.0",
"description": "Colorize text in terminal and console output with ANSI colors & styles",
"keywords": [
"ansi",
"colour",
Expand Down Expand Up @@ -70,33 +70,33 @@
"demo": "node --experimental-modules ./examples/index.js",
"bench": "(cd ./bench/ && npm install); node ./bench/index.js",
"compare": "(cd ./compare/ && npm install); node ./compare/index.js",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --detectOpenHandles",
"test:unit": "NODE_OPTIONS=--experimental-vm-modules jest --detectOpenHandles --runTestsByPath ./test/unit.test.js",
"test:index": "NODE_OPTIONS=--experimental-vm-modules jest --detectOpenHandles --runTestsByPath ./test/index.test.js",
"test:flags": "NODE_OPTIONS=--experimental-vm-modules jest --detectOpenHandles --runTestsByPath ./test/flags.test.js",
"test:package": "NODE_OPTIONS=--experimental-vm-modules jest --detectOpenHandles --runTestsByPath ./test/package.test.js",
"test": "vitest run",
"test:unit": "vitest run ./test/unit.test.js",
"test:ansi16": "vitest run ./test/ansi16.test.js",
"test:ansi256": "vitest run ./test/ansi256.test.js",
"test:index": "vitest run ./test/index.test.js",
"test:flags": "vitest run ./test/flags.test.js",
"test:package": "vitest run ./test/package.test.js",
"test:cjs": "node ./test/package/cjs/test.cjs",
"test:esm": "node ./test/package/esm/test.mjs",
"test:coverage": "NODE_OPTIONS=--experimental-vm-modules jest --detectOpenHandles --collectCoverage",
"test:coverage": "vitest run --coverage",
"publish:public": "(npm run build) && npm publish ./dist --access public",
"publish:beta": "(npm run build) && npm publish ./dist --tag beta"
},
"engines": {
"node": ">=12.13"
"node": ">=15"
},
"devDependencies": {
"@babel/core": "^7.23.2",
"@babel/preset-env": "^7.23.2",
"@rollup/plugin-replace": "^5.0.5",
"@rollup/plugin-terser": "^0.4.4",
"@types/jest": "^29.5.7",
"@types/node": "^20.8.10",
"@types/node": "^20.11.30",
"@vitest/coverage-v8": "^1.4.0",
"ansis": "file:dist",
"jest": "^29.7.0",
"prettier": "^3.0.3",
"rollup": "^4.2.0",
"prettier": "^3.2.5",
"rollup": "^4.13.0",
"rollup-plugin-copy": "^3.5.0",
"rollup-plugin-dts": "^6.1.0",
"terser": "^5.24.0"
"terser": "^5.30.0",
"vitest": "^1.4.0"
}
}
6 changes: 3 additions & 3 deletions pkg/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ansis",
"version": "2.3.0",
"description": "Colorize text in terminal or console output with ANSI colors & styles",
"version": "3.0.0",
"description": "Colorize text in terminal and console output with ANSI colors & styles",
"keywords": [
"ansi",
"colour",
Expand Down Expand Up @@ -65,7 +65,7 @@
}
},
"engines": {
"node": ">=12.13"
"node": ">=15"
},
"files": [
"index.d.ts",
Expand Down
Loading

0 comments on commit 96a2a47

Please sign in to comment.