Skip to content

Commit

Permalink
chore: remove DEPRECATED named import syntax, use new syntax since v2
Browse files Browse the repository at this point in the history
  • Loading branch information
webdiscus committed Jul 14, 2024
1 parent d1be810 commit d700050
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 88 deletions.
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
# Change log

## 3.3.0 (2024-07-14)

- feat(BREAKING CHANGE): remove `old` named import DEPRECATED in `v2.0.0` (2023-11-03).
If you update the package from `v1.x` to `v3.3.0` then check your code:\
ESM
```diff
- import { red } from 'ansis/colors';
+ import { red } from 'ansis';
```
CJS
```diff
- const { red } = require('ansis/colors');
+ const { red } = require('ansis');
```
- chore: cleanup/optimize `package.json` for npm package

## 3.2.1 (2024-07-12)

- chore: reduce unpacked size by ~ 1 KB
Expand Down Expand Up @@ -38,6 +54,8 @@
- test: add more tests
- docs: improve readme

<a id="v3-0-0" name="v3-0-0"></a>

## 3.0.0 (2024-03-29)

- feat: add detection of color spaces support: TrueColor, 256 colors, 16 colors, no color
Expand All @@ -61,6 +79,22 @@ In the new major version `3.x` are removed unused styles and methods.
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 DEPRECATED named import syntax (since `v3.3.0`)

ESM

```diff
- import { red } from 'ansis/colors';
+ import { red } from 'ansis';
```

CJS

```diff
- const { red } = require('ansis/colors');
+ const { red } = require('ansis');
```

### Deleted styles

The `not widely supported` styles are deleted:
Expand Down
35 changes: 14 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,15 @@ hex('#E0115F').bold.underline('TrueColor!')
- Quick response to issues.
- Long term support.

## 🏆 Compare & Benchmark
## ⚖️ Similar packages

See the [features comparison](#compare) and [benchmarks](#benchmark) of most popular terminal colors libraries:\
[ansis][ansis], [chalk][chalk], [kleur][kleur], [kolorist][kolorist], [colors.js][colors.js], [colorette][colorette], [picocolors][picocolors], [ansi-colors][ansi-colors], [cli-color][cli-color], [colors-cli][colors-cli].
Most popular ANSI libraries for Node.js:

[chalk][chalk], [kleur][kleur], [kolorist][kolorist], [colors.js][colors.js], [colorette][colorette], [picocolors][picocolors], [ansi-colors][ansi-colors], [cli-color][cli-color], [colors-cli][colors-cli]

-[Compare features](#compare)

- 📊 [Benchmarks](#benchmark)

<a id="features" name="features"></a>

Expand Down Expand Up @@ -97,8 +102,8 @@ See the [features comparison](#compare) and [benchmarks](#benchmark) of most pop

> #### ⚠️ Warning
>
> The `v3` has the **BREAKING CHANGES** (removed not widely supported styles and deprecated methods).\
> For details see the [changelog](https://github.com/webdiscus/ansis/blob/master/CHANGELOG.md).
> The `v3` has the **BREAKING CHANGES** (removed not widely supported styles and DEPRECATIONS).\
> For details see the [changelog](https://github.com/webdiscus/ansis/blob/master/CHANGELOG.md#v3-0-0).

## ❓Question / Feature Request / Bug

Expand Down Expand Up @@ -696,8 +701,9 @@ npm run compare
> The size of distributed code that will be loaded via `require` or `import` into your app. It's not a package size.
>
> **Named import**\
> ESM\
> `import { red, green, blue } from 'lib';`\
> or\
> CJS\
> `const { red, green, blue } = require('lib');`
>
> **Naming colors**
Expand Down Expand Up @@ -744,7 +750,7 @@ npm run demo

<a id="benchmark" name="#benchmark"></a>

## Benchmark
## Benchmarks

To measure performance is used [benchmark.js](https://github.com/bestiejs/benchmark.js).

Expand All @@ -761,7 +767,7 @@ To measure performance is used [benchmark.js](https://github.com/bestiejs/benchm
>
> The real performance results of `chalk` and `ansis` in this test are very close.
### Run benchmark
### Run benchmarks

```bash
git clone https://github.com/webdiscus/ansis.git
Expand Down Expand Up @@ -945,19 +951,6 @@ c.hex('#FBA')('foo');
`npm run test` will run the unit and integration tests.\
`npm run test:coverage` will run the tests with coverage.

## Also See

Most popular ANSI libraries for `Node.js`:

- [colors.js][colors.js]
- [colorette][colorette]
- [picocolors][picocolors]
- [cli-color][cli-color]
- [colors-cli][colors-cli]
- [ansi-colors][ansi-colors]
- [kleur][kleur]
- [chalk][chalk]

## License

[ISC](https://github.com/webdiscus/ansis/blob/master/LICENSE)
Expand Down
32 changes: 15 additions & 17 deletions README.npm.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<p align="center">
<a href="https://github.com/webdiscus/ansis">
<img width="323" src="https://github.com/webdiscus/ansis/raw/master/docs/img/ansis-logo.png" alt="ansis"><br>
<img width="323" src="https://github.com/webdiscus/ansis/raw/master/docs/img/ansis-logo.png"><br>
ANSI Styling
</a>
</p>
Expand All @@ -14,44 +14,42 @@ Colorize terminal with ANSI colors & styles, smaller and faster alternative to C

🚀 [Install and Quick Start](https://github.com/webdiscus/ansis#install)

[Compare features](https://github.com/webdiscus/ansis#compare) with similar packages

📊 [Benchmarks](https://github.com/webdiscus/ansis#benchmark)

📖 [Read full docs on GitHub](https://github.com/webdiscus/ansis)

## Usage

```js
import ansis, { red, green, black, ansi256, hex } from 'ansis';

ansis.cyan('path/to/file')
green('Succeful!')
red`Error!`
black.bgYellow`Warning!`
ansis.cyan('file')
green('Ok')
red`Error`
black.bgYellow`Warning`
ansi256(214)`Orange`
hex('#E0115F').bold.underline('TrueColor')
hex('#E0115F').bold('TrueColor')
```

## 🏆 Compare & Benchmark

See the [features comparison](https://github.com/webdiscus/ansis#compare) and [benchmarks](https://github.com/webdiscus/ansis#benchmark) of most popular terminal colors libraries:\
`ansis` `chalk` `kleur` `kolorist` `colors.js` `colorette` `picocolors` `ansi-colors` `cli-color` `colors-cli`.

## 💡 Highlights
## Highlights

![ANSI demo](https://github.com/webdiscus/ansis/raw/master/docs/img/ansis-demo.png)

- Supports ESM, CommonJS, TypeScript, Bun, Deno, Next.JS
- [Standard API](https://github.com/webdiscus/ansis#base-colors), drop-in replacement for Chalk
- Default and named import: `import ansis, { red, bold, hex } from 'ansis'`
- Supports ESM, CJS, TypeScript, Bun, Deno, Next.JS
- Named import: `import ansis, { red, bold, hex } from 'ansis'`
- Chained syntax: `red.bold.underline('text')`
- Nested template strings: ``` red`RED ${green`GREEN`} RED` ```
- ANSI styles: `dim` **`bold`** _`italic`_ <u>`underline`</u> <s>`strikethrough`</s>
- ANSI 16 colors: ``` red`Error!` ``` ``` redBright`Error!` ``` ``` bgRed`Error!` ``` ``` bgRedBright`Error!` ```
- ANSI 256 colors: ``` fg(56)`violet` ``` ``` bg(208)`orange` ```
- TrueColor: ``` rgb(224, 17, 95)`Ruby` ``` ``` hex('#96C')`Amethyst` ```
- Color fallback: TrueColor → 256 colors → 16 colors → no colors
- Raw ANSI codes: ``` `foo ${red.open}red{red.close} bar` ```
- Raw ANSI codes: ``` `foo ${red.open}bar{red.close} foo` ```
- Strip ANSI codes: `ansis.strip()`
- Detect color support: `ansis.isSupported()`
- Supports CLI: `NO_COLOR` `FORCE_COLOR` `--no-color` `--color`
- Correct style break at the `end of line` when used `\n`
- Doesn't extend `String.prototype`
- Zero dependencies
- No dependencies
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ansis",
"version": "3.2.1",
"description": "Colorize terminal with ANSI colors & styles",
"version": "3.3.0",
"description": "Colorize terminal output with ANSI colors & styles",
"keywords": [
"ansi",
"colour",
Expand Down
21 changes: 5 additions & 16 deletions package.npm.json
Original file line number Diff line number Diff line change
@@ -1,44 +1,33 @@
{
"name": "ansis",
"version": "3.2.1",
"description": "Colorize terminal with ANSI colors & styles",
"version": "3.3.0",
"description": "Colorize terminal output with ANSI colors & styles",
"keywords": [
"ansi",
"color",
"truecolor",
"ansi256",
"console",
"terminal",
"cli",
"chalk"
],
"license": "ISC",
"author": "webdiscus",
"homepage": "https://github.com/webdiscus/ansis",
"repository": "webdiscus/ansis",
"sideEffects": false,
"main": "./index.js",
"types": "./index.d.ts",
"exports": {
".": {
"types": "./index.d.ts",
"require": "./index.js",
"import": "./index.mjs"
},
"./colors": {
"types": "./index.d.ts",
"require": "./index.js",
"import": "./index.mjs"
}
},
"sideEffects": false,
"engines": {
"node": ">=15"
},
"files": [
"index.d.ts",
"index.js",
"index.mjs",
"package.json",
"LICENSE",
"README.md"
"index.*"
]
}
12 changes: 2 additions & 10 deletions test/package.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ describe('Usage `ansis` npm package', () => {
'\x1b[38;2;255;117;209mextend: ansis2.pink\x1b[39m\n' +
'\x1b[3m\x1b[38;2;255;171;64mextend: ansis2.italic.orange\x1b[39m\x1b[23m\n' +
'colored: \x1b[32mgreen text\x1b[39m\n' +
'striped: green text\n' +
'--- OLD named import: \x1b[33mconst { magenta, cyan, blue } = require(\'ansis/colors\');\x1b[39m\n' +
'\x1b[35mmagenta\x1b[39m\n' +
'\x1b[36m\x1b[1mcyan bold\x1b[22m\x1b[39m\n' +
'\x1b[34m\x1b[3mblue italic\x1b[23m\x1b[39m';
'striped: green text';
expect(esc(received)).toEqual(esc(expected));
});

Expand All @@ -45,11 +41,7 @@ describe('Usage `ansis` npm package', () => {
'\x1b[38;2;255;117;209mextend: ansis2.pink\x1b[39m\n' +
'\x1b[3m\x1b[38;2;255;171;64mextend: ansis2.italic.orange\x1b[39m\x1b[23m\n' +
'colored: \x1b[32mgreen text\x1b[39m\n' +
'striped: green text\n' +
'--- OLD named import: \x1b[33mimport { magenta, cyan, blue } from \'ansis/colors\';\x1b[39m\n' +
'\x1b[35mmagenta\x1b[39m\n' +
'\x1b[36m\x1b[1mcyan bold\x1b[22m\x1b[39m\n' +
'\x1b[34m\x1b[3mblue italic\x1b[23m\x1b[39m';
'striped: green text';
expect(esc(received)).toEqual(esc(expected));
});
});
14 changes: 3 additions & 11 deletions test/package/cjs/test.cjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
const ansis = require('ansis');

// test new named import
const { Ansis, red, green, yellow, hex } = require('ansis');

// test old named import
const { magenta, cyan, blue } = require('ansis/colors');
// test named import
const { Ansis, red, green, hex } = require('ansis');

const log = console.log;

Expand Down Expand Up @@ -41,9 +38,4 @@ log(ansis2.italic.orange('extend: ansis2.italic.orange'));
// strip
const greenText = green`green text`;
log('colored: ', greenText);
log('striped: ', ansis.strip(greenText));

log(`--- OLD named import: ${yellow`const { magenta, cyan, blue } = require('ansis/colors');`}`);
log(magenta`magenta`);
log(cyan.bold`cyan bold`);
log(blue.italic`blue italic`);
log('striped: ', ansis.strip(greenText));
14 changes: 3 additions & 11 deletions test/package/esm/test.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
// test new named import
import ansis, { Ansis, red, green, yellow, hex } from 'ansis';

// test old named import
import { magenta, cyan, blue } from 'ansis/colors';
// test named import
import ansis, { Ansis, red, green, hex } from 'ansis';

const log = console.log;

Expand Down Expand Up @@ -39,9 +36,4 @@ log(ansis2.italic.orange('extend: ansis2.italic.orange'));
// strip
const greenText = green`green text`;
log('colored: ', greenText);
log('striped: ', ansis.strip(greenText));

log(`--- OLD named import: ${yellow`import { magenta, cyan, blue } from 'ansis/colors';`}`);
log(magenta`magenta`);
log(cyan.bold`cyan bold`);
log(blue.italic`blue italic`);
log('striped: ', ansis.strip(greenText));

0 comments on commit d700050

Please sign in to comment.