Socket
Socket
Sign inDemoInstall

ansi-fragments

Package Overview
Dependencies
9
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.0 to 0.1.1

build/fragments/__tests__/fragments.spec.d.ts

2

build/fragments/Color.d.ts
import IFragment from './IFragment';
export declare type AnsiColor = 'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white' | 'brightBlack' | 'brightRed' | 'brightGreen' | 'brightYellow' | 'brightBlue' | 'brightMagenta' | 'brightCyan' | 'brightWhite' | 'gray' | 'bgBlack' | 'bgRed' | 'bgGreen' | 'bgYellow' | 'bgBlue' | 'bgMagenta' | 'bgCyan' | 'bgWhite' | 'bgBrightBlack' | 'bgBrightRed' | 'bgBrightGreen' | 'bgBrightYellow' | 'bgBrightBlue' | 'bgBrightMagenta' | 'bgBrightCyan' | 'bgBrightWhite';
export declare type AnsiColor = 'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white' | 'brightBlack' | 'brightRed' | 'brightGreen' | 'brightYellow' | 'brightBlue' | 'brightMagenta' | 'brightCyan' | 'brightWhite' | 'gray' | 'bgBlack' | 'bgRed' | 'bgGreen' | 'bgYellow' | 'bgBlue' | 'bgMagenta' | 'bgCyan' | 'bgWhite' | 'bgBrightBlack' | 'bgBrightRed' | 'bgBrightGreen' | 'bgBrightYellow' | 'bgBrightBlue' | 'bgBrightMagenta' | 'bgBrightCyan' | 'bgBrightWhite' | 'none';
export declare function color(ansiColor: AnsiColor, ...children: Array<string | IFragment>): Color;

@@ -4,0 +4,0 @@ export declare class Color implements IFragment {

@@ -19,3 +19,6 @@ "use strict";

const children = utils_1.buildChildren(this.children);
if (this.color in colorette_1.default) {
if (this.color === 'none') {
return children;
}
else if (this.color in colorette_1.default) {
// tslint:disable-next-line: no-unsafe-any no-any

@@ -22,0 +25,0 @@ return colorette_1.default[this.color](children);

import IFragment from './IFragment';
export declare type AnsiModifier = 'dim' | 'bold' | 'hidden' | 'italic' | 'underline' | 'strikethrough';
export declare type AnsiModifier = 'dim' | 'bold' | 'hidden' | 'italic' | 'underline' | 'strikethrough' | 'none';
export declare function modifier(ansiModifier: AnsiModifier, ...children: Array<string | IFragment>): Modifier;

@@ -4,0 +4,0 @@ export declare class Modifier implements IFragment {

@@ -19,3 +19,6 @@ "use strict";

const children = utils_1.buildChildren(this.children);
if (this.modifier in colorette_1.default) {
if (this.modifier === 'none') {
return children;
}
else if (this.modifier in colorette_1.default) {
// tslint:disable-next-line: no-unsafe-any no-any

@@ -22,0 +25,0 @@ return colorette_1.default[this.modifier](children);

{
"name": "ansi-fragments",
"version": "0.1.0",
"version": "0.1.1",
"main": "build/index.js",

@@ -25,2 +25,3 @@ "license": "MIT",

"lint": "tslint -t stylish --project tsconfig.json",
"test": "jest",
"build": "tsc --build tsconfig.json",

@@ -32,3 +33,2 @@ "clean": "del build",

"colorette": "^1.0.7",
"del-cli": "^1.1.0",
"slice-ansi": "^2.0.0",

@@ -39,7 +39,15 @@ "strip-ansi": "^5.0.0"

"@callstack/tslint-config": "^0.1.0",
"@types/jest": "^23.3.13",
"@types/slice-ansi": "^2.0.0",
"@types/strip-ansi": "^3.0.0",
"del-cli": "^1.1.0",
"jest": "^24.0.0",
"ts-jest": "^23.10.5",
"tslint": "^5.12.0",
"typescript": "^3.2.2"
},
"jest": {
"preset": "ts-jest",
"rootDir": "./src"
}
}

@@ -12,2 +12,13 @@ # ansi-fragments

- [ansi-fragments](#ansi-fragments)
- [Installation](#installation)
- [Usage](#usage)
- [API](#api)
- [`color`](#color)
- [`modifier`](#modifier)
- [`container`](#container)
- [`pad`](#pad)
- [`fixed`](#fixed)
- [`provide`](#provide)
## Installation

@@ -46,4 +57,11 @@

#### `color(ansiColor: AnsiColor, ...children: Array<string | IFragment>): IFragment`
#### `color`
```ts
color(
ansiColor: AnsiColor,
...children: Array<string | IFragment>
): IFragment
```
Creates fragment for standard ANSI [colors](./src/fragments/Color.ts).

@@ -57,4 +75,11 @@

#### `modifier(ansiModifier: AnsiModifier, ...children: Array<string | IFragment>): IFragment`
#### `modifier`
```ts
modifier(
ansiModifier: AnsiModifier,
...children: Array<string | IFragment>
): IFragment
```
Creates fragment for standard ANSI [modifiers](./src/fragments/Modifier.ts): `dim`, `bold`, `hidden`, `italic`, `underline`, `strikethrough`.

@@ -68,4 +93,8 @@

#### `container(...children: Array<string | IFragment>): IFragment`
#### `container`
```ts
container(...children: Array<string | IFragment>): IFragment
```
Creates fragment, which sole purpose is to hold and build nested fragments.

@@ -83,4 +112,8 @@

#### `pad(count: number, separator?: string): IFragment`
#### `pad`
```ts
pad(count: number, separator?: string): IFragment
```
Creates fragment, which repeats given separator (default: ` `) given number of times.

@@ -94,4 +127,12 @@

#### `fixed(value: number, bias: 'start' | 'end', ...children: Array<string | IFragment>): IFragment`
#### `fixed`
```ts
fixed(
value: number,
bias: 'start' | 'end',
...children: Array<string | IFragment>
): IFragment
```
Creates fragment, which makes sure the children will always build to given number of non-ANSI characters. It will either trim the results or add necessary amount of spaces. The `bias` control if trimming/padding should be done at the start of the string representing built children or at the end.

@@ -105,3 +146,35 @@

#### `provide`
```ts
provide<T>(
value: T,
builder: (value: T) => string | IFragment
): IFragment
```
Provides given value to a builder function, which should return `string` or fragment. Useful in situations when the output is connected with some calculated value - using `provide` you only need to calculate final value once and forward it to custom styling logic.
```js
provide(getMessageFromSomewhere(), value => {
switch (value.level) {
case 'error':
return container(
color('red', modifier('bold', value.level.toUpperCase())),
pad(2),
value.log
);
case 'info':
return container(
color('blue', value.level.toUpperCase()),
pad(2),
value.log
);
default:
return container(value.level.toUpperCase(), pad(2), value.log);
}
})
```
<!-- badges (common) -->

@@ -108,0 +181,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc