ansi-construct
Advanced tools
Comparing version
@@ -1,4 +0,59 @@ | ||
declare const one = 1; | ||
declare const two = 2; | ||
export { default as colors } from 'picocolors'; | ||
export { one, two }; | ||
interface AnsiObject { | ||
text: string; | ||
color?: BuiltinColors | BuiltinColors[]; | ||
padStart?: number | [number, string]; | ||
/** | ||
* When both padStart and padEnd are set, padStart will be executed first. | ||
*/ | ||
padEnd?: number | [number, string]; | ||
} | ||
declare type AnsiArray = [string] | [string, BuiltinColors] | [string, BuiltinColors, BuiltinColors] | [string, BuiltinColors, BuiltinColors, BuiltinColors] | [string, BuiltinColors, BuiltinColors, BuiltinColors, BuiltinColors]; | ||
interface AnsiObjectShorthand { | ||
/** | ||
* Text | ||
*/ | ||
t: AnsiObject['text']; | ||
/** | ||
* Color | ||
*/ | ||
c?: AnsiObject['color']; | ||
/** | ||
* padStart | ||
*/ | ||
ps?: AnsiObject['padStart']; | ||
/** | ||
* padEnd | ||
* | ||
* When both padStart and padEnd are set, padStart will be executed first. | ||
*/ | ||
pe?: AnsiObject['padEnd']; | ||
} | ||
declare type AnsiItem = AnsiObject | AnsiObjectShorthand | AnsiArray | string | undefined | null | false; | ||
declare type AnsiItems = AnsiItem[]; | ||
declare type AnsiLines = AnsiItems[]; | ||
interface ConstructOptions { | ||
/** | ||
* Enable colors or not. | ||
* | ||
* @default auto | ||
*/ | ||
colors?: boolean; | ||
/** | ||
* Padding between each item | ||
* | ||
* @default '' | ||
*/ | ||
padding?: string; | ||
} | ||
declare type BuiltinColors = 'reset' | 'bold' | 'dim' | 'italic' | 'underline' | 'inverse' | 'hidden' | 'strikethrough' | 'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white' | 'gray' | 'bgBlack' | 'bgRed' | 'bgGreen' | 'bgYellow' | 'bgBlue' | 'bgMagenta' | 'bgCyan' | 'bgWhite'; | ||
declare function space(length?: number): string; | ||
declare function newline(length?: number): string; | ||
declare function c(...items: AnsiItem[]): string; | ||
declare function construct(items: AnsiItem[], options?: ConstructOptions): string; | ||
declare function constructLines(items: AnsiLines, options?: ConstructOptions): string; | ||
export { AnsiArray, AnsiItem, AnsiItems, AnsiLines, AnsiObject, AnsiObjectShorthand, BuiltinColors, ConstructOptions, c, construct, constructLines, newline, space }; |
{ | ||
"name": "ansi-construct", | ||
"type": "module", | ||
"version": "0.0.0", | ||
"version": "0.0.1", | ||
"packageManager": "pnpm@7.2.1", | ||
@@ -49,2 +49,5 @@ "description": "", | ||
}, | ||
"dependencies": { | ||
"picocolors": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
@@ -64,6 +67,3 @@ "@antfu/eslint-config": "^0.25.1", | ||
"vitest": "^0.15.1" | ||
}, | ||
"dependencies": { | ||
"kolorist": "^1.5.1" | ||
} | ||
} |
@@ -5,2 +5,20 @@ # ansi-construct | ||
Construct ANSI colors strings from object descriptors. | ||
## Usage | ||
```ts | ||
import type { AnsiItem } from 'ansi-construct' | ||
import { construct } from 'ansi-construct' | ||
const items: AnsiItem[] = [ | ||
{ text: 'foo', color: 'red', padStart: 5 }, | ||
{ text: 'bar', color: ['green', 'bold', 'underline'] }, | ||
' raw text ', | ||
{ t: 'shorthand', c: 'cyan' } | ||
] | ||
console.log(construct(items)) // '\x1b[31mfoo\x1b[0m \x1b[32mbar\x1b[0m raw text \x1b[36m\x1b[0m' | ||
``` | ||
## Sponsors | ||
@@ -7,0 +25,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
8829
163%173
1341.67%34
112.5%+ Added
+ Added
- Removed
- Removed