-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
42bc561
commit 091aabd
Showing
8 changed files
with
53 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
'use strict'; | ||
const termImg = require('.'); | ||
import terminalImage from './index.js'; | ||
|
||
console.log(termImg('fixture.jpg', { | ||
console.log(terminalImage('fixture.jpg', { | ||
width: 50, | ||
fallback: () => 'Not supported here, sorry...' | ||
})); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,37 @@ | ||
/// <reference types="node"/> | ||
import {ImageOptions} from 'ansi-escapes'; | ||
|
||
declare class UnsupportedTerminalErrorClass extends Error { | ||
export class UnsupportedTerminalError extends Error { | ||
readonly name: 'UnsupportedTerminalError'; | ||
|
||
constructor(); | ||
} | ||
|
||
declare namespace termImg { | ||
interface Options<FallbackType = unknown> extends ImageOptions { | ||
/** | ||
Enables you to do something else when the terminal doesn't support images. | ||
@default () => throw new UnsupportedTerminalError() | ||
*/ | ||
readonly fallback?: () => FallbackType; | ||
} | ||
export interface Options<FallbackType = unknown> extends ImageOptions { | ||
/** | ||
Enables you to do something else when the terminal doesn't support images. | ||
type UnsupportedTerminalError = UnsupportedTerminalErrorClass; | ||
@default () => throw new UnsupportedTerminalError() | ||
*/ | ||
readonly fallback?: () => FallbackType; | ||
} | ||
|
||
declare const termImg: { | ||
UnsupportedTerminalError: typeof UnsupportedTerminalErrorClass; | ||
|
||
/** | ||
Get the image as a `string` that you can log manually. | ||
@param image - Filepath to an image or an image as a buffer. | ||
/** | ||
Get the image as a `string` that you can log manually. | ||
@example | ||
``` | ||
import termImg = require('term-img'); | ||
@param image - File path to an image or an image as a buffer. | ||
function fallback() { | ||
// Do something else when not supported | ||
} | ||
@example | ||
``` | ||
import terminalImage from 'term-img'; | ||
termImg('unicorn.jpg', {fallback}); | ||
``` | ||
*/ | ||
<FallbackType>( | ||
image: string | Buffer, | ||
options?: termImg.Options<FallbackType> | ||
): string | FallbackType; | ||
}; | ||
function fallback() { | ||
// Do something else when not supported | ||
} | ||
export = termImg; | ||
terminalImage('unicorn.jpg', {fallback}); | ||
``` | ||
*/ | ||
export default function terminalImage<FallbackType>( | ||
image: string | Buffer, | ||
options?: Options<FallbackType> | ||
): string | FallbackType; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import test from 'ava'; | ||
import termImg from '.'; | ||
import terminalImage from './index.js'; | ||
|
||
test('main', t => { | ||
process.env.TERM_PROGRAM = 'iTerm.app'; | ||
process.env.TERM_PROGRAM_VERSION = '3.3.7'; | ||
t.snapshot(termImg('fixture.jpg')); | ||
t.snapshot(terminalImage('fixture.jpg')); | ||
}); |