Skip to content

Commit

Permalink
revert xo, ava. restore default export
Browse files Browse the repository at this point in the history
  • Loading branch information
broofa committed Apr 26, 2024
1 parent 073f63c commit 47e7fb7
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 14 deletions.
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"editor.insertSpaces": false,
"editor.tabSize": 2
}
5 changes: 4 additions & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type {Buffer} from 'node:buffer';
import type { Buffer } from 'node:buffer';

// From https://github.com/sindresorhus/type-fest
type Primitive =
Expand Down Expand Up @@ -264,3 +264,6 @@ export namespace iTerm {
*/
function annotation(message: string, options?: AnnotationOptions): string;
}
declare const ansiEscapes: typeof import('./index');

export default ansiEscapes
34 changes: 34 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,37 @@ export const iTerm = {
return returnValue + BEL;
},
};

export default {
beep,
clearScreen,
clearTerminal,
cursorBackward,
cursorDown,
cursorForward,
cursorGetPosition,
cursorHide,
cursorLeft,
cursorMove,
cursorNextLine,
cursorPrevLine,
cursorRestorePosition,
cursorSavePosition,
cursorShow,
cursorTo,
cursorUp,
enterAlternativeScreen,
eraseDown,
eraseEndLine,
eraseLine,
eraseLines,
eraseScreen,
eraseStartLine,
eraseUp,
exitAlternativeScreen,
iTerm,
image,
link,
scrollDown,
scrollUp,
}
57 changes: 54 additions & 3 deletions index.test-d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {Buffer} from 'node:buffer';
import {expectType} from 'tsd';
import {
import { Buffer } from 'node:buffer';
import { expectType } from 'tsd';
import ansiEscapes, {
beep,
clearScreen,
clearTerminal,
Expand Down Expand Up @@ -34,6 +34,57 @@ import {
scrollUp,
} from './index.js';

// default export (object)
expectType<string>(ansiEscapes.cursorTo(0)); expectType<string>(cursorTo(0));
expectType<string>(ansiEscapes.cursorTo(0, 1)); expectType<string>(cursorTo(0, 1));
expectType<string>(ansiEscapes.cursorMove(0)); expectType<string>(cursorMove(0));
expectType<string>(ansiEscapes.cursorMove(0, 1)); expectType<string>(cursorMove(0, 1));
expectType<string>(ansiEscapes.cursorUp()); expectType<string>(cursorUp());
expectType<string>(ansiEscapes.cursorUp(1)); expectType<string>(cursorUp(1));
expectType<string>(ansiEscapes.cursorDown()); expectType<string>(cursorDown());
expectType<string>(ansiEscapes.cursorDown(1)); expectType<string>(cursorDown(1));
expectType<string>(ansiEscapes.cursorForward()); expectType<string>(cursorForward());
expectType<string>(ansiEscapes.cursorForward(1)); expectType<string>(cursorForward(1));
expectType<string>(ansiEscapes.cursorBackward()); expectType<string>(cursorBackward());
expectType<string>(ansiEscapes.cursorBackward(1)); expectType<string>(cursorBackward(1));
expectType<string>(ansiEscapes.cursorLeft); expectType<string>(cursorLeft);
expectType<string>(ansiEscapes.cursorSavePosition); expectType<string>(cursorSavePosition);
expectType<string>(ansiEscapes.cursorRestorePosition); expectType<string>(cursorRestorePosition);
expectType<string>(ansiEscapes.cursorGetPosition); expectType<string>(cursorGetPosition);
expectType<string>(ansiEscapes.cursorNextLine); expectType<string>(cursorNextLine);
expectType<string>(ansiEscapes.cursorPrevLine); expectType<string>(cursorPrevLine);
expectType<string>(ansiEscapes.cursorHide); expectType<string>(cursorHide);
expectType<string>(ansiEscapes.cursorShow); expectType<string>(cursorShow);
expectType<string>(ansiEscapes.eraseLines(2)); expectType<string>(eraseLines(2));
expectType<string>(ansiEscapes.eraseEndLine); expectType<string>(eraseEndLine);
expectType<string>(ansiEscapes.eraseStartLine); expectType<string>(eraseStartLine);
expectType<string>(ansiEscapes.eraseLine); expectType<string>(eraseLine);
expectType<string>(ansiEscapes.eraseDown); expectType<string>(eraseDown);
expectType<string>(ansiEscapes.eraseUp); expectType<string>(eraseUp);
expectType<string>(ansiEscapes.eraseScreen); expectType<string>(eraseScreen);
expectType<string>(ansiEscapes.scrollUp); expectType<string>(scrollUp);
expectType<string>(ansiEscapes.scrollDown); expectType<string>(scrollDown);
expectType<string>(ansiEscapes.clearScreen); expectType<string>(clearScreen);
expectType<string>(ansiEscapes.clearTerminal); expectType<string>(clearTerminal);
expectType<string>(ansiEscapes.enterAlternativeScreen); expectType<string>(enterAlternativeScreen);
expectType<string>(ansiEscapes.exitAlternativeScreen); expectType<string>(exitAlternativeScreen);
expectType<string>(ansiEscapes.beep); expectType<string>(beep);
expectType<string>(ansiEscapes.link('foo', 'https://foo.bar')); expectType<string>(link('foo', 'https://foo.bar'));
expectType<string>(ansiEscapes.image(Buffer.from('1'))); expectType<string>(image(Buffer.from('1')));
expectType<string>(ansiEscapes.image(Buffer.from('1'), {width: 1})); expectType<string>(image(Buffer.from('1'), {width: 1}));
expectType<string>(ansiEscapes.image(Buffer.from('1'), {width: '1px'})); expectType<string>(image(Buffer.from('1'), {width: '1px'}));
expectType<string>(ansiEscapes.image(Buffer.from('1'), {width: 'auto'})); expectType<string>(image(Buffer.from('1'), {width: 'auto'}));
expectType<string>(ansiEscapes.image(Buffer.from('1'), {height: 1})); expectType<string>(image(Buffer.from('1'), {height: 1}));
expectType<string>(ansiEscapes.image(Buffer.from('1'), {height: '1px'})); expectType<string>(image(Buffer.from('1'), {height: '1px'}));
expectType<string>(ansiEscapes.image(Buffer.from('1'), {height: 'auto'})); expectType<string>(image(Buffer.from('1'), {height: 'auto'}));
expectType<string>(ansiEscapes.image(Buffer.from('1'), {height: 'auto'}));
expectType<string>(
ansiEscapes.image(Buffer.from('1'), {preserveAspectRatio: false}),
);
expectType<string>(ansiEscapes.iTerm.setCwd('/foo/bar'));
expectType<string>(ansiEscapes.iTerm.annotation('foo bar'));

// named exports
expectType<string>(cursorTo(0));
expectType<string>(cursorTo(0, 1));
expectType<string>(cursorMove(0));
Expand Down
7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"node": ">=14.16"
},
"scripts": {
"test": "node --test && tsd"
"test": "ava && tsd",
"//test": "xo && ava && tsd"
},
"files": [
"index.js",
Expand Down Expand Up @@ -51,6 +52,8 @@
],
"devDependencies": {
"@types/node": "20.12.7",
"tsd": "0.31.0"
"ava": "^4.3.3",
"tsd": "0.31.0",
"xo": "^0.52.3"
}
}
10 changes: 9 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,21 @@ npm install ansi-escapes
## Usage

```js
import * as ansiEscapes from 'ansi-escapes';
import ansiEscapes from 'ansi-escapes';

// Moves the cursor two rows up and to the left
process.stdout.write(ansiEscapes.cursorUp(2) + ansiEscapes.cursorLeft);
//=> '\u001B[2A\u001B[1000D'
```

Or use named exports...

```js
import {cursorUp, cursorLeft} from `ansi-escapes`;

// etc, as above...
```

**You can also use it in the browser with Xterm.js:**

```js
Expand Down
19 changes: 12 additions & 7 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import assert from 'node:assert';
import {test} from 'node:test';
import * as ansiEscapes from './index.js';
import test from 'ava';
import ansiEscapes, { cursorTo } from './index.js';

test('main', () => {
assert(Object.keys(ansiEscapes).length > 0);
assert.equal(typeof ansiEscapes.cursorTo, 'function');
assert.equal(ansiEscapes.cursorTo(2, 2), '\u001B[3;3H');
test('default export', t => {
t.true(Object.keys(ansiEscapes).length > 0);
t.is(typeof ansiEscapes.cursorTo, 'function');
t.is(ansiEscapes.cursorTo(2, 2), '\u001B[3;3H');
});

test('named exports', t => {
t.true(Object.keys(ansiEscapes).length > 0);
t.is(typeof cursorTo, 'function');
t.is(cursorTo(2, 2), '\u001B[3;3H');
});

0 comments on commit 47e7fb7

Please sign in to comment.