Skip to content

Commit 2c603eb

Browse files
committedMay 2, 2024
Require Node.js 18
1 parent d383ae1 commit 2c603eb

File tree

7 files changed

+48
-47
lines changed

7 files changed

+48
-47
lines changed
 

‎base.d.ts

+15-20
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
/* eslint-disable @typescript-eslint/member-ordering */
2-
import type { Buffer } from 'node:buffer';
3-
41
// From https://github.com/sindresorhus/type-fest
52
type Primitive =
63
| null // eslint-disable-line @typescript-eslint/ban-types
@@ -237,31 +234,29 @@ export function link(text: string, url: string): string;
237234
/**
238235
Display an image.
239236
240-
_Currently only supported on iTerm2 >=3_
241-
242237
See [term-img](https://github.com/sindresorhus/term-img) for a higher-level module.
243238
244-
@param buffer - Buffer of an image. Usually read in with `fs.readFile()`.
239+
@param data - Image data. Usually read in with `fs.readFile()`.
245240
*/
246-
export function image(buffer: Buffer, options?: ImageOptions): string;
241+
export function image(data: Uint8Array, options?: ImageOptions): string;
247242

248-
export namespace iTerm {
243+
export const iTerm: {
249244
/**
250-
[Inform iTerm2](https://www.iterm2.com/documentation-escape-codes.html) of the current directory to help semantic history and enable [Cmd-clicking relative paths](https://coderwall.com/p/b7e82q/quickly-open-files-in-iterm-with-cmd-click).
245+
[Inform iTerm2](https://www.iterm2.com/documentation-escape-codes.html) of the current directory to help semantic history and enable [Cmd-clicking relative paths](https://coderwall.com/p/b7e82q/quickly-open-files-in-iterm-with-cmd-click).
251246
252-
@param cwd - Current directory. Default: `process.cwd()`.
253-
*/
254-
function setCwd(cwd?: string): string;
247+
@param cwd - Current directory. Default: `process.cwd()`.
248+
*/
249+
setCwd(cwd?: string): string,
255250

256251
/**
257-
An annotation looks like this when shown:
252+
An annotation looks like this when shown:
258253
259-
![screenshot of iTerm annotation](https://user-images.githubusercontent.com/924465/64382136-b60ac700-cfe9-11e9-8a35-9682e8dc4b72.png)
254+
![screenshot of iTerm annotation](https://user-images.githubusercontent.com/924465/64382136-b60ac700-cfe9-11e9-8a35-9682e8dc4b72.png)
260255
261-
See the [iTerm Proprietary Escape Codes documentation](https://iterm2.com/documentation-escape-codes.html) for more information.
256+
See the [iTerm Proprietary Escape Codes documentation](https://iterm2.com/documentation-escape-codes.html) for more information.
262257
263-
@param message - The message to display within the annotation. The `|` character is disallowed and will be stripped.
264-
@returns An escape code which will create an annotation when printed in iTerm2.
265-
*/
266-
function annotation(message: string, options?: AnnotationOptions): string;
267-
}
258+
@param message - The message to display within the annotation. The `|` character is disallowed and will be stripped.
259+
@returns An escape code which will create an annotation when printed in iTerm2.
260+
*/
261+
annotation(message: string, options?: AnnotationOptions): string
262+
};

‎base.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import process from 'node:process';
2+
import {isBrowser} from 'environment';
23

34
const ESC = '\u001B[';
45
const OSC = '\u001B]';
56
const BEL = '\u0007';
67
const SEP = ';';
78

8-
/* global window */
9-
const isBrowser = typeof window !== 'undefined' && typeof window.document !== 'undefined';
10-
119
const isTerminalApp = !isBrowser && process.env.TERM_PROGRAM === 'Apple_Terminal';
1210
const isWindows = !isBrowser && process.platform === 'win32';
11+
1312
const cwdFunction = isBrowser ? () => {
1413
throw new Error('`process.cwd()` only works in Node.js, not the browser.');
1514
} : process.cwd;
@@ -115,7 +114,7 @@ export const link = (text, url) => [
115114
BEL,
116115
].join('');
117116

118-
export const image = (buffer, options = {}) => {
117+
export const image = (data, options = {}) => {
119118
let returnValue = `${OSC}1337;File=inline=1`;
120119

121120
if (options.width) {
@@ -130,7 +129,7 @@ export const image = (buffer, options = {}) => {
130129
returnValue += ';preserveAspectRatio=0';
131130
}
132131

133-
return returnValue + ':' + buffer.toString('base64') + BEL;
132+
return returnValue + ':' + Buffer.from(data).toString('base64') + BEL;
134133
};
135134

136135
export const iTerm = {
@@ -139,13 +138,13 @@ export const iTerm = {
139138
annotation(message, options = {}) {
140139
let returnValue = `${OSC}1337;`;
141140

142-
const hasX = typeof options.x !== 'undefined';
143-
const hasY = typeof options.y !== 'undefined';
144-
if ((hasX || hasY) && !(hasX && hasY && typeof options.length !== 'undefined')) {
141+
const hasX = options.x !== undefined;
142+
const hasY = options.y !== undefined;
143+
if ((hasX || hasY) && !(hasX && hasY && options.length !== undefined)) {
145144
throw new Error('`x`, `y` and `length` must be defined when `x` or `y` is defined');
146145
}
147146

148-
message = message.replace(/\|/g, '');
147+
message = message.replaceAll('|', '');
149148

150149
returnValue += options.isHidden ? 'AddHiddenAnnotation=' : 'AddAnnotation=';
151150

‎index.d.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export * from './base.d.js';
2-
export * as default from './base.d.js';
1+
export * from './base.js';
2+
export * as default from './base.js';

‎index.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
import * as ansiEscapes from './base.js';
2-
3-
export default ansiEscapes;
4-
export * from './base.js';
1+
export * from './base.js';
2+
export * as default from './base.js';

‎package.json

+19-8
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,23 @@
1111
"url": "https://sindresorhus.com"
1212
},
1313
"type": "module",
14-
"exports": "./index.js",
15-
"types": "./index.d.ts",
14+
"exports": {
15+
"types": "./index.d.ts",
16+
"default": "./index.js"
17+
},
1618
"sideEffects": false,
1719
"engines": {
18-
"node": ">=14.16"
20+
"node": ">=18"
1921
},
2022
"scripts": {
2123
"test": "ava && tsd",
2224
"//test": "xo && ava && tsd"
2325
},
2426
"files": [
2527
"index.js",
26-
"index.d.ts"
28+
"index.d.ts",
29+
"base.js",
30+
"base.d.ts"
2731
],
2832
"keywords": [
2933
"ansi",
@@ -48,12 +52,19 @@
4852
"codes",
4953
"cursor",
5054
"iterm",
51-
"iterm2"
55+
"iterm2",
56+
"clear",
57+
"screen",
58+
"erase",
59+
"scrollback"
5260
],
61+
"dependencies": {
62+
"environment": "^1.0.0"
63+
},
5364
"devDependencies": {
54-
"@types/node": "20.12.7",
55-
"ava": "^4.3.3",
65+
"@types/node": "20.12.8",
66+
"ava": "^6.1.2",
5667
"tsd": "0.31.0",
57-
"xo": "^0.52.3"
68+
"xo": "^0.58.0"
5869
}
5970
}

‎readme.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ process.stdout.write(ansiEscapes.cursorUp(2) + ansiEscapes.cursorLeft);
2121
Or use named exports...
2222

2323
```js
24-
import {cursorUp, cursorLeft} from `ansi-escapes`;
24+
import {cursorUp, cursorLeft} from 'ansi-escapes';
2525

2626
// etc, as above...
2727
```
@@ -164,8 +164,6 @@ Create a clickable link.
164164

165165
Display an image.
166166

167-
*Currently only supported on iTerm2 >=3*
168-
169167
See [term-img](https://github.com/sindresorhus/term-img) for a higher-level module.
170168

171169
#### input

‎test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import test from 'ava';
2-
import ansiEscapes, { cursorTo } from './index.js';
2+
import ansiEscapes, {cursorTo} from './index.js';
33

44
test('default export', t => {
55
t.true(Object.keys(ansiEscapes).length > 0);

0 commit comments

Comments
 (0)
Please sign in to comment.