bananass-utils-console 0.8.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +11 -153
- package/build/icons.d.ts +31 -0
- package/{src/icons → build}/icons.js +10 -51
- package/build/{is-interactive/is-interactive.d.ts → is-interactive.d.ts} +5 -4
- package/{src/is-interactive → build}/is-interactive.js +4 -8
- package/build/{is-unicode-supported/is-unicode-supported.d.ts → is-unicode-supported.d.ts} +6 -1
- package/{src/is-unicode-supported → build}/is-unicode-supported.js +16 -24
- package/build/{logger/logger.d.ts → logger.d.ts} +32 -35
- package/build/logger.js +163 -0
- package/build/{spinner/spinner.d.ts → spinner.d.ts} +57 -78
- package/build/spinner.js +277 -0
- package/build/theme.d.ts +64 -0
- package/{src/theme → build}/theme.js +31 -46
- package/package.json +24 -25
- package/build/icons/icons.d.ts +0 -28
- package/build/icons/index.d.ts +0 -1
- package/build/is-interactive/index.d.ts +0 -2
- package/build/is-unicode-supported/index.d.ts +0 -2
- package/build/logger/index.d.ts +0 -2
- package/build/spinner/index.d.ts +0 -2
- package/build/theme/index.d.ts +0 -1
- package/build/theme/theme.d.ts +0 -60
- package/src/icons/index.js +0 -1
- package/src/is-interactive/index.js +0 -3
- package/src/is-unicode-supported/index.js +0 -3
- package/src/logger/index.js +0 -3
- package/src/logger/logger.js +0 -208
- package/src/spinner/index.js +0 -3
- package/src/spinner/spinner.js +0 -388
- package/src/theme/index.js +0 -1
package/README.md
CHANGED
|
@@ -1,160 +1,18 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `bananass-utils-console`
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[](https://github.com/lumirlumir/npm-bananass/actions/workflows/test.yml)
|
|
5
|
-
[](https://codecov.io/gh/lumirlumir/npm-bananass)
|
|
6
|
-

|
|
3
|
+
Console Utilities for Bananass Framework.🍌
|
|
7
4
|
|
|
8
|
-
|
|
9
|
-
[](https://www.npmjs.com/package/bananass)
|
|
5
|
+
## Documentation
|
|
10
6
|
|
|
11
|
-
|
|
7
|
+
- [English](https://bananass.lumir.page/en/)
|
|
8
|
+
- [Korean](https://bananass.lumir.page/)
|
|
12
9
|
|
|
13
|
-
|
|
10
|
+
## Repository
|
|
14
11
|
|
|
15
|
-
|
|
12
|
+
- [`bananass-utils-console` monorepo](https://github.com/lumirlumir/npm-bananass)
|
|
13
|
+
- [`bananass-utils-console` package](https://github.com/lumirlumir/npm-bananass/tree/main/packages/bananass-utils-console)
|
|
16
14
|
|
|
17
|
-
|
|
18
|
-
>
|
|
19
|
-
> ```js
|
|
20
|
-
> const whyBananass = {
|
|
21
|
-
> banana: '🍌',
|
|
22
|
-
> bananas: '🍌🍌',
|
|
23
|
-
> bananass: '🍌🍌🍌🍌',
|
|
24
|
-
> }
|
|
25
|
-
> ```
|
|
26
|
-
>
|
|
27
|
-
> ```js
|
|
28
|
-
> console.log(('b' + 'a' + +'a' + 'a').toLowerCase() + (!(1/0) + [])[3].repeat(2));
|
|
29
|
-
> ```
|
|
15
|
+
## npm
|
|
30
16
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
바나나<sup>Bananass</sup> 프레임워크에 오신 것을 환영합니다!
|
|
35
|
-
|
|
36
|
-
바나나는 **자바스크립트<sup>JavaScript</sup> 및 타입스크립트<sup>TypeScript</sup> 기반의 알고리즘 문제 풀이를 위한 프레임워크**로, [백준](https://www.acmicpc.net/)ㆍ[코드포스](https://codeforces.com/) 등 다양한 문제 풀이 플랫폼들의 Node.js 환경에서 반복적으로 마주치는 문제점들을 해결하며, 간결하고 편리한 사용자 경험을 제공합니다.
|
|
37
|
-
|
|
38
|
-
- 타입스크립트<sup>TypeScript</sup> 지원이 필요하시다고요?
|
|
39
|
-
- ES16<sup>ES2025</sup> 등 자바스크립트 최신 문법을 쓰고 싶은데 막히셨나요?
|
|
40
|
-
- 외부 라이브러리를 사용하고 싶으신가요?
|
|
41
|
-
- 매번 `readline` / `fs` 템플릿 코드 복붙하기 지치셨나요?
|
|
42
|
-
|
|
43
|
-
이제 걱정하지 마세요! 바나나 프레임워크는 이런 문제점들을 모두 해결합니다.
|
|
44
|
-
|
|
45
|
-
## 왜 바나나일까요?
|
|
46
|
-
|
|
47
|
-
함께 자바스크립트를 이용한 [백준 1000번: A+B](https://www.acmicpc.net/problem/1000) 문제 풀이 예제를 살펴봅시다!
|
|
48
|
-
|
|
49
|
-
- 기존 방법을 통한 문제 풀이.
|
|
50
|
-
|
|
51
|
-
```js
|
|
52
|
-
const readline = require('node:readline');
|
|
53
|
-
const { EOL } = require('node:os');
|
|
54
|
-
|
|
55
|
-
let inputStr = '';
|
|
56
|
-
|
|
57
|
-
const rl = readline.createInterface({
|
|
58
|
-
input: process.stdin,
|
|
59
|
-
output: process.stdout,
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
rl.on('line', line => {
|
|
63
|
-
inputStr = `${inputStr}${line}${EOL}`;
|
|
64
|
-
}).on('close', () => {
|
|
65
|
-
console.log(solution(inputStr));
|
|
66
|
-
|
|
67
|
-
process.exit(0);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
function solution(input) {
|
|
71
|
-
const [a, b] = input
|
|
72
|
-
.trim()
|
|
73
|
-
.split(' ')
|
|
74
|
-
.map(val => Number(val));
|
|
75
|
-
|
|
76
|
-
return a + b;
|
|
77
|
-
}
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
- 바나나 프레임워크를 이용한 문제 풀이.
|
|
81
|
-
|
|
82
|
-
```js
|
|
83
|
-
function solution(input) {
|
|
84
|
-
const [a, b] = input
|
|
85
|
-
.trim()
|
|
86
|
-
.split(' ')
|
|
87
|
-
.map(Number);
|
|
88
|
-
|
|
89
|
-
return a + b;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export default { solution };
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
더 간결하고, 더 직관적인 코드! 입력 처리에 들이던 시간은 줄이고, 오직 알고리즘에만 집중할 수 있습니다.
|
|
96
|
-
|
|
97
|
-
## 이게 전부인가요?
|
|
98
|
-
|
|
99
|
-
물론, 아닙니다!
|
|
100
|
-
|
|
101
|
-
- 자바스크립트<sup>JavaScript</sup> 및 타입스크립트<sup>TypeScript</sup> 지원.
|
|
102
|
-
- ESM<sup>ECMAScript Module</sup> 및 CommonJS 모듈 시스템 지원.
|
|
103
|
-
- 백준 Node.js 환경에 구애받지 않는 ES16<sup>ES2025</sup> 등 최신 문법 지원.
|
|
104
|
-
- 사용자 정의 모듈 및 `lodash` 등 외부 라이브러리 불러오기 지원.
|
|
105
|
-
- 프로그래머스처럼 `solution` 함수 하나로 시작하기 지원.
|
|
106
|
-
- 테스트 케이스 작성 및 실행 지원.
|
|
107
|
-
- `create-bananass`로 시작하기 지원.
|
|
108
|
-
- `fs` 모듈을 사용한 더욱 빠른 입출력 지원.
|
|
109
|
-
- 편의를 위한 다양한 CLI 명령어 지원.
|
|
110
|
-
- 풍부하고 상세한 문서 지원.
|
|
111
|
-
- ESLint 및 Prettier 설정 지원.
|
|
112
|
-
|
|
113
|
-
어떤가요? 바나나 프레임워크를 통해 더욱 편리한 문제 풀이를 경험해보고 싶지 않으신가요?
|
|
114
|
-
|
|
115
|
-
## 바나나로 시작하기
|
|
116
|
-
|
|
117
|
-
[React](https://ko.react.dev)의 `create-react-app`, [Next.js](https://nextjs.org)의 `create-next-app` 처럼, 바나나 프레임워크에서 제공하는 `create-bananass`로 지금 바로 새로운 문제 풀이 패러다임을 경험해보세요!
|
|
118
|
-
|
|
119
|
-
바나나 프레임워크는 `create-bananass`를 통해 즉시 설치하고 사용할 수 있습니다.
|
|
120
|
-
|
|
121
|
-
```sh
|
|
122
|
-
npm create bananass@latest
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
더 자세한 사용법은 [바나나 프레임워크 문서](https://bananass.lumir.page)를 참고해주세요.
|
|
126
|
-
|
|
127
|
-
## 바나나 프레임워크 문서
|
|
128
|
-
|
|
129
|
-
바나나 프레임워크는 문서화를 가장 큰 가치로 여깁니다. 바나나 프레임워크의 모든 사용법과 기능은 [바나나 프레임워크 문서](https://bananass.lumir.page)에서 확인하실 수 있습니다.
|
|
130
|
-
|
|
131
|
-
## 기여(이슈<sup>Issue</sup>, 끌어오기 요청<sup>Pull Request</sup>, 토론<sup>Discussion</sup>)
|
|
132
|
-
|
|
133
|
-
바나나 프레임워크 기여에 관심을 가져주셔서 감사합니다!
|
|
134
|
-
|
|
135
|
-
버그<sup>Bug</sup> 및 제안<sup>Suggestion</sup> 등 여러 주제에 대한 이슈<sup>Issue</sup>, 끌어오기 요청<sup>Pull Request</sup>, 토론<sup>Discussion</sup> 등을 모두 환영합니다.
|
|
136
|
-
|
|
137
|
-
다만, 올바른 커뮤니티 환경을 준수하고 더 나은 오픈 소스를 만들기 위해, 바나나 프레임워크에 기여하기 전 반드시 아래 내용들을 확인해주세요.
|
|
138
|
-
|
|
139
|
-
- [기여자 행동 강령 규약](https://github.com/lumirlumir/.github/blob/main/CODE_OF_CONDUCT_KO.md#%EA%B8%B0%EC%97%AC%EC%9E%90-%ED%96%89%EB%8F%99-%EA%B0%95%EB%A0%B9-%EA%B7%9C%EC%95%BD)
|
|
140
|
-
- [기여하기](CONTRIBUTING.md)
|
|
141
|
-
|
|
142
|
-
## 버전 정책<sup>Versioning</sup>
|
|
143
|
-
|
|
144
|
-
바나나 프레임워크는 [유의적 버전 정책<sup>Semantic Versioning</sup>](https://semver.org/lang/ko/)을 따릅니다. 모든 릴리즈 버전은 `주(MAJOR).부(MINOR).수(PATCH)` 형식을 따릅니다.
|
|
145
|
-
|
|
146
|
-
## 기여자 행동 강령 규약<sup>Code of Conduct</sup>
|
|
147
|
-
|
|
148
|
-
커뮤니티에 기여하기 전, [기여자 행동 강령 규약](https://github.com/lumirlumir/.github/blob/main/CODE_OF_CONDUCT_KO.md#%EA%B8%B0%EC%97%AC%EC%9E%90-%ED%96%89%EB%8F%99-%EA%B0%95%EB%A0%B9-%EA%B7%9C%EC%95%BD)을 참고해주세요.
|
|
149
|
-
|
|
150
|
-
## 변경 사항<sup>Change Log</sup>
|
|
151
|
-
|
|
152
|
-
변경 사항에 대한 상세한 내용을 확인하려면, [변경 사항](CHANGELOG.md)을 참고해주세요.
|
|
153
|
-
|
|
154
|
-
## 보안<sup>Security</sup>
|
|
155
|
-
|
|
156
|
-
보안 문제를 발견하셨나요? [보안](https://github.com/lumirlumir/.github/blob/main/SECURITY_KO.md#%EB%B3%B4%EC%95%88) 문서를 참고해주세요.
|
|
157
|
-
|
|
158
|
-
## 라이선스<sup>License</sup>
|
|
159
|
-
|
|
160
|
-
바나나 프레임워크는 MIT 라이선스를 따릅니다. [라이선스](LICENSE.md) 문서를 참고해주세요.
|
|
17
|
+
- [`npm`](https://www.npmjs.com/package/bananass-utils-console)
|
|
18
|
+
- [`npmx`](https://npmx.dev/package/bananass-utils-console)
|
package/build/icons.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Console icons.
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Defines the frames and interval of a spinner.
|
|
6
|
+
*/
|
|
7
|
+
export interface SpinnerStyle {
|
|
8
|
+
/**
|
|
9
|
+
* The frames displayed sequentially to animate the spinner.
|
|
10
|
+
*/
|
|
11
|
+
frames: string[];
|
|
12
|
+
/**
|
|
13
|
+
* The interval between frames, in milliseconds.
|
|
14
|
+
*/
|
|
15
|
+
interval: number;
|
|
16
|
+
}
|
|
17
|
+
export declare const successIcon: string;
|
|
18
|
+
export declare const errorIcon: string;
|
|
19
|
+
export declare const warningIcon: string;
|
|
20
|
+
export declare const infoIcon: string;
|
|
21
|
+
export declare const bananassIcon: string;
|
|
22
|
+
export declare const bulletIcon: string;
|
|
23
|
+
export declare const boxDrawingsLightHorizontalIcon: string;
|
|
24
|
+
export declare const successText: string;
|
|
25
|
+
export declare const errorText: string;
|
|
26
|
+
export declare const warningText: string;
|
|
27
|
+
export declare const infoText: string;
|
|
28
|
+
export declare const defaultSpinner: {
|
|
29
|
+
frames: string[];
|
|
30
|
+
interval: 80;
|
|
31
|
+
};
|
|
@@ -1,79 +1,38 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @fileoverview Console icons.
|
|
3
3
|
*/
|
|
4
|
-
|
|
5
4
|
// --------------------------------------------------------------------------------
|
|
6
5
|
// Import
|
|
7
6
|
// --------------------------------------------------------------------------------
|
|
8
|
-
|
|
9
7
|
import { styleText } from 'node:util';
|
|
10
|
-
import isUnicodeSupported from
|
|
11
|
-
|
|
12
|
-
// --------------------------------------------------------------------------------
|
|
13
|
-
// Typedef
|
|
14
|
-
// --------------------------------------------------------------------------------
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @typedef {object} SpinnerStyle
|
|
18
|
-
* @property {string[]} frames
|
|
19
|
-
* @property {number} interval
|
|
20
|
-
*/
|
|
21
|
-
|
|
8
|
+
import isUnicodeSupported from "./is-unicode-supported.js";
|
|
22
9
|
// --------------------------------------------------------------------------------
|
|
23
10
|
// Helpers
|
|
24
11
|
// --------------------------------------------------------------------------------
|
|
25
|
-
|
|
26
12
|
/**
|
|
27
|
-
* @
|
|
28
|
-
* @param
|
|
29
|
-
* @param {T} ascii Used when Unicode is not supported.
|
|
30
|
-
* @returns {T}
|
|
13
|
+
* @param unicode Used when Unicode is supported.
|
|
14
|
+
* @param ascii Used when Unicode is not supported.
|
|
31
15
|
*/
|
|
32
|
-
|
|
33
|
-
|
|
16
|
+
function choose(unicode, ascii) {
|
|
17
|
+
return isUnicodeSupported() ? unicode : ascii;
|
|
18
|
+
}
|
|
34
19
|
// --------------------------------------------------------------------------------
|
|
35
20
|
// Export
|
|
36
21
|
// --------------------------------------------------------------------------------
|
|
37
|
-
|
|
38
|
-
/** @type {string} */
|
|
39
22
|
export const successIcon = styleText(['green', 'bold'], choose('✓', 'V'));
|
|
40
|
-
/** @type {string} */
|
|
41
23
|
export const errorIcon = styleText(['red', 'bold'], choose('✕', 'X'));
|
|
42
|
-
/** @type {string} */
|
|
43
24
|
export const warningIcon = styleText(['yellow', 'bold'], choose('⚠', '!'));
|
|
44
|
-
/** @type {string} */
|
|
45
25
|
export const infoIcon = styleText(['blue', 'bold'], choose('✦', 'i'));
|
|
46
|
-
/** @type {string} */
|
|
47
26
|
export const bananassIcon = choose('🍌', '');
|
|
48
|
-
/** @type {string} U+2022: "Bullet" (•) */
|
|
49
27
|
export const bulletIcon = choose('\u2022', '*');
|
|
50
|
-
/** @type {string} U+2500: "Box Drawings Light Horizontal" (─) */
|
|
51
28
|
export const boxDrawingsLightHorizontalIcon = choose('\u2500', '-');
|
|
52
|
-
|
|
53
29
|
// --------------------------------------------------------------------------------
|
|
54
|
-
|
|
55
|
-
/** @type {string} */
|
|
56
|
-
export const successText = styleText(
|
|
57
|
-
['white', 'bgGreen', 'bold'],
|
|
58
|
-
` ${successIcon} SUCCESS `,
|
|
59
|
-
);
|
|
60
|
-
/** @type {string} */
|
|
30
|
+
export const successText = styleText(['white', 'bgGreen', 'bold'], ` ${successIcon} SUCCESS `);
|
|
61
31
|
export const errorText = styleText(['white', 'bgRed', 'bold'], ` ${errorIcon} ERROR `);
|
|
62
|
-
|
|
63
|
-
export const warningText = styleText(
|
|
64
|
-
['white', 'bgYellow', 'bold'],
|
|
65
|
-
` ${warningIcon} WARN `,
|
|
66
|
-
);
|
|
67
|
-
/** @type {string} */
|
|
32
|
+
export const warningText = styleText(['white', 'bgYellow', 'bold'], ` ${warningIcon} WARN `);
|
|
68
33
|
export const infoText = styleText(['white', 'bgBlue', 'bold'], ` ${infoIcon} INFO `);
|
|
69
|
-
|
|
70
34
|
// --------------------------------------------------------------------------------
|
|
71
|
-
|
|
72
|
-
/** @type {SpinnerStyle} */
|
|
73
35
|
export const defaultSpinner = {
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
['-', '\\', '|', '/'],
|
|
77
|
-
),
|
|
78
|
-
interval: 80,
|
|
36
|
+
frames: choose(['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'], ['-', '\\', '|', '/']),
|
|
37
|
+
interval: 80,
|
|
79
38
|
};
|
|
@@ -3,19 +3,20 @@
|
|
|
3
3
|
* @module bananass-utils-console/is-interactive
|
|
4
4
|
* @license MIT Portions of this code were borrowed from [`is-interactive`](https://github.com/sindresorhus/is-interactive).
|
|
5
5
|
*/
|
|
6
|
+
import type { WriteStream } from 'node:tty';
|
|
6
7
|
/**
|
|
7
8
|
* Check if stdout or stderr is [interactive](https://unix.stackexchange.com/a/43389/7678).
|
|
8
9
|
*
|
|
9
10
|
* It checks that the stream is [TTY](https://jameshfisher.com/2017/12/09/what-is-a-tty/), not a dumb terminal, and not running in a CI.
|
|
10
11
|
*
|
|
11
12
|
* This can be useful to decide whether to present interactive UI or animations in the terminal.
|
|
12
|
-
* @param
|
|
13
|
-
* @returns
|
|
13
|
+
* @param stream The stream to check. (default: `process.stdout`)
|
|
14
|
+
* @returns `true` if the stream is interactive, `false` otherwise.
|
|
14
15
|
* @example
|
|
15
|
-
* ```
|
|
16
|
+
* ```js
|
|
16
17
|
* import isInteractive from 'bananass-utils-console/is-interactive';
|
|
17
18
|
*
|
|
18
19
|
* isInteractive(); // true
|
|
19
20
|
* ```
|
|
20
21
|
*/
|
|
21
|
-
export default function isInteractive(stream?:
|
|
22
|
+
export default function isInteractive(stream?: WriteStream): boolean;
|
|
@@ -3,28 +3,24 @@
|
|
|
3
3
|
* @module bananass-utils-console/is-interactive
|
|
4
4
|
* @license MIT Portions of this code were borrowed from [`is-interactive`](https://github.com/sindresorhus/is-interactive).
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
6
|
// --------------------------------------------------------------------------------
|
|
8
7
|
// Export
|
|
9
8
|
// --------------------------------------------------------------------------------
|
|
10
|
-
|
|
11
9
|
/**
|
|
12
10
|
* Check if stdout or stderr is [interactive](https://unix.stackexchange.com/a/43389/7678).
|
|
13
11
|
*
|
|
14
12
|
* It checks that the stream is [TTY](https://jameshfisher.com/2017/12/09/what-is-a-tty/), not a dumb terminal, and not running in a CI.
|
|
15
13
|
*
|
|
16
14
|
* This can be useful to decide whether to present interactive UI or animations in the terminal.
|
|
17
|
-
* @param
|
|
18
|
-
* @returns
|
|
15
|
+
* @param stream The stream to check. (default: `process.stdout`)
|
|
16
|
+
* @returns `true` if the stream is interactive, `false` otherwise.
|
|
19
17
|
* @example
|
|
20
|
-
* ```
|
|
18
|
+
* ```js
|
|
21
19
|
* import isInteractive from 'bananass-utils-console/is-interactive';
|
|
22
20
|
*
|
|
23
21
|
* isInteractive(); // true
|
|
24
22
|
* ```
|
|
25
23
|
*/
|
|
26
24
|
export default function isInteractive(stream = process.stdout) {
|
|
27
|
-
|
|
28
|
-
stream && stream.isTTY && process.env.TERM !== 'dumb' && !('CI' in process.env),
|
|
29
|
-
);
|
|
25
|
+
return Boolean(stream && stream.isTTY && process.env.TERM !== 'dumb' && !('CI' in process.env));
|
|
30
26
|
}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Detect whether the terminal supports Unicode.
|
|
3
|
+
* @module bananass-utils-console/is-unicode-supported
|
|
4
|
+
* @license MIT Portions of this code were borrowed from [`is-unicode-supported`](https://github.com/sindresorhus/is-unicode-supported).
|
|
5
|
+
*/
|
|
1
6
|
/**
|
|
2
7
|
* Detect whether the terminal supports Unicode.
|
|
3
8
|
*
|
|
@@ -9,7 +14,7 @@
|
|
|
9
14
|
* which Windows terminals that do support Unicode.
|
|
10
15
|
* However, I have been using this logic in some popular packages for years without problems.
|
|
11
16
|
*
|
|
12
|
-
* @returns
|
|
17
|
+
* @returns Returns a `boolean` for whether the terminal supports Unicode.
|
|
13
18
|
* @example
|
|
14
19
|
* ```
|
|
15
20
|
* import isUnicodeSupported from 'bananass-utils-console/is-unicode-supported';
|
|
@@ -3,17 +3,13 @@
|
|
|
3
3
|
* @module bananass-utils-console/is-unicode-supported
|
|
4
4
|
* @license MIT Portions of this code were borrowed from [`is-unicode-supported`](https://github.com/sindresorhus/is-unicode-supported).
|
|
5
5
|
*/
|
|
6
|
-
|
|
7
6
|
// --------------------------------------------------------------------------------
|
|
8
7
|
// Import
|
|
9
8
|
// --------------------------------------------------------------------------------
|
|
10
|
-
|
|
11
9
|
import process from 'node:process';
|
|
12
|
-
|
|
13
10
|
// --------------------------------------------------------------------------------
|
|
14
11
|
// Export
|
|
15
12
|
// --------------------------------------------------------------------------------
|
|
16
|
-
|
|
17
13
|
/**
|
|
18
14
|
* Detect whether the terminal supports Unicode.
|
|
19
15
|
*
|
|
@@ -25,7 +21,7 @@ import process from 'node:process';
|
|
|
25
21
|
* which Windows terminals that do support Unicode.
|
|
26
22
|
* However, I have been using this logic in some popular packages for years without problems.
|
|
27
23
|
*
|
|
28
|
-
* @returns
|
|
24
|
+
* @returns Returns a `boolean` for whether the terminal supports Unicode.
|
|
29
25
|
* @example
|
|
30
26
|
* ```
|
|
31
27
|
* import isUnicodeSupported from 'bananass-utils-console/is-unicode-supported';
|
|
@@ -34,23 +30,19 @@ import process from 'node:process';
|
|
|
34
30
|
* ```
|
|
35
31
|
*/
|
|
36
32
|
export default function isUnicodeSupported() {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
TERM === 'rxvt-unicode' ||
|
|
53
|
-
TERM === 'rxvt-unicode-256color' ||
|
|
54
|
-
env.TERMINAL_EMULATOR === 'JetBrains-JediTerm'
|
|
55
|
-
);
|
|
33
|
+
const { env } = process;
|
|
34
|
+
const { TERM, TERM_PROGRAM } = env;
|
|
35
|
+
if (process.platform !== 'win32') {
|
|
36
|
+
return TERM !== 'linux'; // Linux console (kernel)
|
|
37
|
+
}
|
|
38
|
+
return (Boolean(env.WT_SESSION) || // Windows Terminal
|
|
39
|
+
Boolean(env.TERMINUS_SUBLIME) || // Terminus (<0.2.27)
|
|
40
|
+
env.ConEmuTask === '{cmd::Cmder}' || // ConEmu and cmder
|
|
41
|
+
TERM_PROGRAM === 'Terminus-Sublime' ||
|
|
42
|
+
TERM_PROGRAM === 'vscode' ||
|
|
43
|
+
TERM === 'xterm-256color' ||
|
|
44
|
+
TERM === 'alacritty' ||
|
|
45
|
+
TERM === 'rxvt-unicode' ||
|
|
46
|
+
TERM === 'rxvt-unicode-256color' ||
|
|
47
|
+
env.TERMINAL_EMULATOR === 'JetBrains-JediTerm');
|
|
56
48
|
}
|
|
@@ -1,28 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* @param {Options} [options]
|
|
5
|
-
* @returns {Logger} A new `Logger` instance.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* import createLogger from 'bananass-utils-console/logger';
|
|
9
|
-
*
|
|
10
|
-
* const logger = createLogger({
|
|
11
|
-
* debug: false,
|
|
12
|
-
* quiet: false,
|
|
13
|
-
* textPrefix: '>',
|
|
14
|
-
* })
|
|
15
|
-
*
|
|
16
|
-
* logger
|
|
17
|
-
* .log('Hello, log!');
|
|
18
|
-
* .debug('Hello, debug!');
|
|
19
|
-
* .eol();
|
|
2
|
+
* @fileoverview Console logger.
|
|
3
|
+
* @module bananass-utils-console/logger
|
|
20
4
|
*/
|
|
21
|
-
export default function createLogger(options?: Options): Logger;
|
|
22
5
|
/**
|
|
23
6
|
* Logger options.
|
|
24
7
|
*/
|
|
25
|
-
|
|
8
|
+
interface Options {
|
|
26
9
|
/**
|
|
27
10
|
* Enable debug mode.
|
|
28
11
|
*/
|
|
@@ -35,15 +18,9 @@ export type Options = {
|
|
|
35
18
|
* Text prefix.
|
|
36
19
|
*/
|
|
37
20
|
textPrefix?: string | boolean | undefined;
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* @typedef {object} Options Logger options.
|
|
41
|
-
* @property {boolean | undefined} [debug] Enable debug mode.
|
|
42
|
-
* @property {boolean | undefined} [quiet] Enable quiet mode.
|
|
43
|
-
* @property {string | boolean | undefined} [textPrefix] Text prefix.
|
|
44
|
-
*/
|
|
21
|
+
}
|
|
45
22
|
declare class Logger {
|
|
46
|
-
|
|
23
|
+
#private;
|
|
47
24
|
constructor(options?: Options);
|
|
48
25
|
/**
|
|
49
26
|
* Log a message or executes a callback.
|
|
@@ -56,8 +33,8 @@ declare class Logger {
|
|
|
56
33
|
* - `quiet === true`: output X
|
|
57
34
|
* - `quiet === false`: output O
|
|
58
35
|
*
|
|
59
|
-
* @param
|
|
60
|
-
* @returns
|
|
36
|
+
* @param params The message or callback function, followed by any additional arguments.
|
|
37
|
+
* @returns The current `Logger` instance for chaining.
|
|
61
38
|
*/
|
|
62
39
|
log(...params: unknown[]): Logger;
|
|
63
40
|
/**
|
|
@@ -72,8 +49,8 @@ declare class Logger {
|
|
|
72
49
|
* - `quiet === false && debug === true`: output O
|
|
73
50
|
* - `quiet === false && debug === false`: output X
|
|
74
51
|
*
|
|
75
|
-
* @param
|
|
76
|
-
* @returns
|
|
52
|
+
* @param params The message or callback function, followed by any additional arguments.
|
|
53
|
+
* @returns The current `Logger` instance for chaining.
|
|
77
54
|
*/
|
|
78
55
|
debug(...params: unknown[]): Logger;
|
|
79
56
|
/**
|
|
@@ -83,14 +60,34 @@ declare class Logger {
|
|
|
83
60
|
* then invokes either `log()` or `debug()` depending on the previously method called.
|
|
84
61
|
* After logging, it restores the original text prefix.
|
|
85
62
|
*
|
|
86
|
-
* @returns
|
|
63
|
+
* @returns The current `Logger` instance for chaining.
|
|
87
64
|
*/
|
|
88
65
|
eol(): Logger;
|
|
89
66
|
/**
|
|
90
67
|
* Get the last method called.
|
|
91
68
|
* @returns {'log' | 'debug'}
|
|
92
69
|
*/
|
|
93
|
-
get lastMethodCalled():
|
|
94
|
-
#private;
|
|
70
|
+
get lastMethodCalled(): 'log' | 'debug';
|
|
95
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Create a new `Logger` instance.
|
|
74
|
+
*
|
|
75
|
+
* @param options The logger options.
|
|
76
|
+
* @returns A new `Logger` instance.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* import createLogger from 'bananass-utils-console/logger';
|
|
80
|
+
*
|
|
81
|
+
* const logger = createLogger({
|
|
82
|
+
* debug: false,
|
|
83
|
+
* quiet: false,
|
|
84
|
+
* textPrefix: '>',
|
|
85
|
+
* })
|
|
86
|
+
*
|
|
87
|
+
* logger
|
|
88
|
+
* .log('Hello, log!');
|
|
89
|
+
* .debug('Hello, debug!');
|
|
90
|
+
* .eol();
|
|
91
|
+
*/
|
|
92
|
+
export default function createLogger(options?: Options): Logger;
|
|
96
93
|
export {};
|