New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ansi-fragments

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ansi-fragments - npm Package Compare versions

Comparing version 0.2.0 to 0.2.1

33

build/fragments/__tests__/fragments.spec.js

@@ -11,5 +11,4 @@ "use strict";

const Fixed_1 = require("../Fixed");
const colorette_1 = __importDefault(require("colorette"));
const IfElse_1 = require("../IfElse");
const Provide_1 = require("../Provide");
const colorette_1 = __importDefault(require("colorette"));
colorette_1.default.options.enabled = true;

@@ -22,24 +21,12 @@ test('should build fragments to string', () => {

});
test('should build logical fragments', () => {
let condition1 = true;
const tree1 = IfElse_1.ifElse(() => condition1, Color_1.color('red', 'ERROR'), Color_1.color('yellow', 'WARNING'));
expect(JSON.stringify(tree1.build())).toEqual(JSON.stringify(colorette_1.default.red('ERROR')));
condition1 = false;
expect(JSON.stringify(tree1.build())).toEqual(JSON.stringify(colorette_1.default.yellow('WARNING')));
const message = { level: 'error', log: 'Something went wrong' };
const tree2 = Provide_1.provide(message, (value) => {
switch (value.level) {
case 'error':
return Container_1.container(Color_1.color('red', Modifier_1.modifier('bold', value.level.toUpperCase())), Pad_1.pad(2), value.log);
case 'info':
return Container_1.container(Color_1.color('blue', value.level.toUpperCase()), Pad_1.pad(2), value.log);
default:
return Container_1.container(value.level.toUpperCase(), Pad_1.pad(2), value.log);
}
});
expect(JSON.stringify(tree2.build())).toEqual(JSON.stringify(`${colorette_1.default.red(colorette_1.default.bold(message.level.toUpperCase()))} ${message.log}`));
message.level = 'info';
message.log = 'Some log';
expect(JSON.stringify(tree2.build())).toEqual(JSON.stringify(`${colorette_1.default.blue(message.level.toUpperCase())} ${message.log}`));
test('ifElse fragment should render correct fragmnent', () => {
expect(IfElse_1.ifElse(true, 'Hello', 'Bye').build()).toEqual('Hello');
expect(IfElse_1.ifElse(1, 'Hello', 'Bye').build()).toEqual('Hello');
expect(IfElse_1.ifElse(undefined, 'Hello', 'Bye').build()).toEqual('Bye');
// tslint:disable-next-line: no-null-keyword
expect(IfElse_1.ifElse(null, 'Hello', 'Bye').build()).toEqual('Bye');
expect(IfElse_1.ifElse(true, 'Hello').build()).toEqual('Hello');
expect(IfElse_1.ifElse(false, 'Hello').build()).toEqual('');
expect(IfElse_1.ifElse(() => true, 'Hello', 'Bye').build()).toEqual('Hello');
});
//# sourceMappingURL=fragments.spec.js.map
import IFragment from './IFragment';
declare type ConditionValue = boolean | string | number | null | undefined;
declare type Condition = ConditionValue | (() => ConditionValue);
export declare function ifElse(condition: Condition, ifTrueFragment: string | IFragment, elseFragment: string | IFragment): IfElse;
export declare type ConditionValue = boolean | string | number | null | undefined;
export declare type Condition = ConditionValue | (() => ConditionValue);
export declare function ifElse(condition: Condition, ifTrueFragment: string | IFragment, elseFragment?: string | IFragment): IfElse;
export declare class IfElse implements IFragment {
private readonly ifTrueFragment;
private readonly elseFragment?;
private readonly condition;
private readonly ifTrueFragment;
private readonly elseFragment;
constructor(condition: Condition, ifTrueFragment: string | IFragment, elseFragment: string | IFragment);
constructor(condition: Condition, ifTrueFragment: string | IFragment, elseFragment?: string | IFragment);
build(): string;
}
export {};
//# sourceMappingURL=IfElse.d.ts.map

@@ -15,6 +15,6 @@ "use strict";

build() {
const value = typeof this.condition === 'function'
? Boolean(this.condition())
: Boolean(this.condition);
return utils_1.buildChildren(utils_1.toArray(value ? this.ifTrueFragment : this.elseFragment));
const value = Boolean(typeof this.condition === 'function' ? this.condition() : this.condition);
return utils_1.buildChildren([
value ? this.ifTrueFragment : this.elseFragment || '',
]);
}

@@ -21,0 +21,0 @@ }

@@ -6,4 +6,3 @@ export { color, AnsiColor } from './fragments/Color';

export { fixed } from './fragments/Fixed';
export { ifElse } from './fragments/IfElse';
export { provide } from './fragments/Provide';
export { ifElse, Condition, ConditionValue } from './fragments/IfElse';
//# sourceMappingURL=index.d.ts.map

@@ -15,4 +15,2 @@ "use strict";

exports.ifElse = IfElse_1.ifElse;
var Provide_1 = require("./fragments/Provide");
exports.provide = Provide_1.provide;
//# sourceMappingURL=index.js.map
{
"name": "ansi-fragments",
"version": "0.2.0",
"version": "0.2.1",
"main": "build/index.js",

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

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

@@ -42,2 +41,3 @@ "strip-ansi": "^5.0.0"

"@types/strip-ansi": "^3.0.0",
"del-cli": "^1.1.0",
"jest": "^24.0.0",

@@ -44,0 +44,0 @@ "ts-jest": "^23.10.5",

@@ -21,3 +21,3 @@ # ansi-fragments

- [`fixed`](#fixed)
- [`ifElse`](#ifelse)
- [`ifElse`](#ifElse)
- [`provide`](#provide)

@@ -166,3 +166,2 @@

#### `provide`

@@ -169,0 +168,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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc