Socket
Socket
Sign inDemoInstall

cli-ux

Package Overview
Dependencies
Maintainers
1
Versions
167
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cli-ux - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

lib/table.d.ts

2

lib/errors.js

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

error(err, exitCode = 1) {
if (this.options.mock && typeof err !== 'string' && exitCode !== false)
throw err;
try {

@@ -49,0 +51,0 @@ if (typeof err === 'string') {

14

lib/index.d.ts
import { ActionBase } from './action/base';
import { IWarnOptions } from './errors';
import { IPromptOptions } from './prompt';
import { StreamOutput } from './stream';
import { TableOptions } from './table';
export interface IOptions {

@@ -12,9 +14,7 @@ errlog?: string;

action: ActionBase;
private stdoutStream;
private stderrStream;
stdout: StreamOutput;
stderr: StreamOutput;
private errorsDep;
private promptDep;
constructor(options?: IOptions);
readonly stderr: string;
readonly stdout: string;
prompt(name: string, options?: IPromptOptions): Promise<any>;

@@ -24,3 +24,9 @@ log(data: string, ...args: any[]): void;

error(err: Error | string, exitCode?: number | false): void;
exit(code?: number): void;
table(data: any[], options: Partial<TableOptions>): any;
styledJSON(obj: any): void;
styledHeader(header: string): void;
styledObject(obj: any, keys: string[]): void;
done(): void;
}
export declare const cli: CLI;

@@ -13,9 +13,9 @@ "use strict";

this.options = options;
this.stdoutStream = new stream_1.StreamOutput(this.options.mock ? undefined : process.stdout);
this.stderrStream = new stream_1.StreamOutput(this.options.mock ? undefined : process.stderr);
this.stdout = new stream_1.StreamOutput(this.options.mock ? undefined : process.stdout);
this.stderr = new stream_1.StreamOutput(this.options.mock ? undefined : process.stderr);
const depOpts = {
debug: !!options.debug,
mock: !!options.mock,
stderr: this.stderrStream,
stdout: this.stdoutStream,
stderr: this.stderr,
stdout: this.stdout,
};

@@ -25,17 +25,5 @@ this.errorsDep = new errors_1.Errors(depOpts);

this.action = base_1.shouldDisplaySpinner(depOpts) ? new spinner_1.SpinnerAction(depOpts) : new simple_1.SimpleAction(depOpts);
if (this.options.mock || !process.stderr.isTTY || !process.stdout.isTTY)
deps_1.deps.chalk.enabled = false;
}
get stderr() {
const output = this.stderrStream.output;
if (!output) {
throw new Error('not mocking stderr');
}
return output;
}
get stdout() {
const output = this.stdoutStream.output;
if (!output) {
throw new Error('not mocking stdout');
}
return output;
}
prompt(name, options = {}) {

@@ -48,3 +36,3 @@ return this.action.pauseAsync(() => {

this.action.pause(() => {
return this.stdoutStream.log(data, ...args);
return this.stdout.log(data, ...args);
});

@@ -62,4 +50,63 @@ }

}
exit(code = 1) {
this.errorsDep.exit(code);
}
table(data, options) {
let table = require('./table');
return table(this, data, options);
}
styledJSON(obj) {
let json = JSON.stringify(obj, null, 2);
if (deps_1.deps.chalk.enabled) {
let cardinal = require('cardinal');
let theme = require('cardinal/themes/jq');
this.log(cardinal.highlight(json, { json: true, theme: theme }));
}
else {
this.log(json);
}
}
styledHeader(header) {
this.log(deps_1.deps.chalk.dim('=== ') + deps_1.deps.chalk.bold(header));
}
styledObject(obj, keys) {
const util = require('util');
let keyLengths = Object.keys(obj).map(key => key.toString().length);
let maxKeyLength = Math.max.apply(Math, keyLengths) + 2;
function pp(obj) {
if (typeof obj === 'string' || typeof obj === 'number') {
return obj;
}
else if (typeof obj === 'object') {
return Object.keys(obj)
.map(k => k + ': ' + util.inspect(obj[k]))
.join(', ');
}
else {
return util.inspect(obj);
}
}
let logKeyValue = (key, value) => {
this.log(`${deps_1.deps.chalk.blue(key)}:` + ' '.repeat(maxKeyLength - key.length - 1) + pp(value));
};
for (var key of keys || Object.keys(obj).sort()) {
let value = obj[key];
if (Array.isArray(value)) {
if (value.length > 0) {
logKeyValue(key, value[0]);
for (var e of value.slice(1)) {
this.log(' '.repeat(maxKeyLength) + pp(e));
}
}
}
else if (value !== null && value !== undefined) {
logKeyValue(key, value);
}
}
}
done() {
this.action.stop();
}
}
exports.CLI = CLI;
exports.cli = new CLI();
{
"name": "cli-ux",
"description": "set of CLI output utilities",
"version": "1.0.0",
"version": "1.0.1",
"author": "Jeff Dickey",
"bugs": "https://github.com/jdxcode/cli-ux/issues",
"dependencies": {
"@types/fs-extra": "^4.0.2",
"ansi-escapes": "^3.0.0",
"ansi-styles": "^3.2.0",
"cardinal": "^1.0.0",
"chalk": "^2.1.0",
"fs-extra": "^4.0.1",
"lodash.ary": "^4.1.1",
"lodash.get": "^4.4.2",
"lodash.identity": "^3.0.0",
"lodash.partial": "^4.2.1",
"lodash.property": "^4.4.2",
"lodash.result": "^4.5.2",
"moment": "^2.18.1",

@@ -22,2 +28,3 @@ "password-prompt": "^1.0.3",

"@types/chalk": "^0.4.31",
"@types/fs-extra": "^4.0.2",
"@types/jest": "^20.0.8",

@@ -24,0 +31,0 @@ "@types/node": "^8.0.28",

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