Socket
Socket
Sign inDemoInstall

choices-separator

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

choices-separator - npm Package Compare versions

Comparing version 1.1.0 to 2.0.0

78

index.js
'use strict';
var extend = require('extend-shallow');
var debug = require('debug')('choices-separator');
var repeat = require('repeat-string');
var strip = require('strip-color');
var dim = require('ansi-dim');
/**
* Separator object, used in choices arrays in prompts to create a visual break
* between sections.
* Separator object, used in choices arrays in prompts, to
* create a visual break between sections. The default separator
* line is `────────` styled with [ansi-dim].
*
* @param {String} `line` String to use as a separator
* ```js
* new Separator('----');
* new Separator({line: '----'})
* new Separator({line: '----', prefix: ' '});
* ```
* @param {String} `options` Optionally provide a custom `line` and or `prefix` to use.
* @api public
*/
function Separator(line, options) {
function Separator(options) {
debug('initializing from <%s>', __filename);
this.isSeparator = true;
this.type = 'separator';
if (typeof line !== 'string') {
options = line;
line = null;
if (typeof options === 'string') {
options = { line: options };
}
var opts = extend({line: line}, options);
this.prefix = opts.prefix || ' ';
this.chars = {middot: 'Β·', line: '─', bullet: 'β€’'};
if (typeof opts.line === 'string') {
if (this.chars[opts.line]) {
this.line = dim(this.chars[opts.line]);
} else {
this.line = opts.line;
}
this.options = options || {};
this.prefix = ' ';
if (typeof this.options.prefix === 'string') {
this.prefix = this.options.prefix;
}
if (typeof this.options.line === 'string') {
this.line = this.options.line;
} else {
this.line = dim(repeat(this.chars.line, 8));
this.line = dim('────────');
}

@@ -40,6 +45,29 @@ }

/**
* Render the separator line with a prefix.
* Returns the `separator.line` stripped of ansi styling.
*
* ```js
* var separator = new Separator();
* console.log(separator.raw());
* //=> '────────'
* ```
* @return {String}
* @api public
*/
Separator.prototype.raw = function() {
return strip(this.line);
};
/**
* Render `separator.prefix` plus `separator.line`.
*
* ```js
* var separator = new Separator();
* console.log(separator.render());
* //=> ' \u001b[2m────────\u001b[22m\n')
* ```
* @return {String}
* @api public
*/
Separator.prototype.render = function() {

@@ -50,4 +78,4 @@ return this.prefix + this.line + '\n';

/**
* Helper function returning false if object is a separator
* @param {Object} `obj` object to test against
* Returns false if the given object is a separator.
* @param {Object} `choice` object to test against
* @return {Boolean} Returns false if the given object is a separator

@@ -57,4 +85,4 @@ * @api public

Separator.exclude = function(obj) {
return obj.type !== 'separator';
Separator.exclude = function(choice) {
return choice.type !== 'separator';
};

@@ -64,3 +92,3 @@

* Stringify separator
* @return {String} the separator display string
* @return {String} Returns the `separator.line` string
* @api public

@@ -67,0 +95,0 @@ */

{
"name": "choices-separator",
"description": "Separator for choices arrays in prompts. Based on the Separator from inquirer.",
"version": "1.1.0",
"version": "2.0.0",
"homepage": "https://github.com/enquirer/choices-separator",

@@ -25,9 +25,7 @@ "author": "Jon Schlinkert (https://github.com/jonschlinkert)",

"debug": "^2.6.6",
"extend-shallow": "^2.0.1",
"repeat-string": "^1.6.1"
"strip-color": "^0.1.0"
},
"devDependencies": {
"gulp-format-md": "^0.1.12",
"mocha": "^3.3.0",
"strip-color": "^0.1.0"
"mocha": "^3.3.0"
},

@@ -34,0 +32,0 @@ "keywords": [

@@ -16,12 +16,8 @@ # choices-separator [![NPM version](https://img.shields.io/npm/v/choices-separator.svg?style=flat)](https://www.npmjs.com/package/choices-separator) [![NPM monthly downloads](https://img.shields.io/npm/dm/choices-separator.svg?style=flat)](https://npmjs.org/package/choices-separator) [![NPM total downloads](https://img.shields.io/npm/dt/choices-separator.svg?style=flat)](https://npmjs.org/package/choices-separator) [![Linux Build Status](https://img.shields.io/travis/enquirer/choices-separator.svg?style=flat&label=Travis)](https://travis-ci.org/enquirer/choices-separator)

```js
var Enquirer = require('enquirer');
var Separator = require('choices-separator');
var Prompt = require('prompt-checkbox');
var enquirer = new Enquirer();
enquirer.register('checkbox', require('enquirer-prompt-checkbox'));
var question = {
type: 'checkbox',
message: 'Select toppings',
name: 'toppings',
var prompt = new Prompt({
message: 'Which do you prefer?',
name: 'favorites',
choices: [

@@ -37,13 +33,74 @@ new Separator(' = Color = '),

]
};
});
enquirer.ask(question)
.then(function(answers) {
console.log(answers)
prompt.run()
.then(function(answer) {
console.log(answer)
});
```
## API
### [Separator](index.js#L21)
Separator object, used in choices arrays in prompts, to create a visual break between sections. The default separator line is `────────` styled with [ansi-dim](https://github.com/jonschlinkert/ansi-dim).
**Params**
* `options` **{String}**: Optionally provide a custom `line` and or `prefix` to use.
**Example**
```js
new Separator('----');
new Separator({line: '----'})
new Separator({line: '----', prefix: ' '});
```
### [.raw](index.js#L56)
Returns the `separator.line` stripped of ansi styling.
* `returns` **{String}**
**Example**
```js
var separator = new Separator();
console.log(separator.raw());
//=> '────────'
```
### [.render](index.js#L72)
Render `separator.prefix` plus `separator.line`.
* `returns` **{String}**
**Example**
```js
var separator = new Separator();
console.log(separator.render());
//=> ' \u001b[2m────────\u001b[22m\n')
```
### [.exclude](index.js#L83)
Returns false if the given object is a separator.
**Params**
* `choice` **{Object}**: object to test against
* `returns` **{Boolean}**: Returns false if the given object is a separator
### [.toString](index.js#L93)
Stringify separator
* `returns` **{String}**: Returns the `separator.line` string
## Attribution
Currently base on the `Separator` class from Inquirer.
Originally inspired by the `Separator` class from Inquirer.

@@ -92,2 +149,2 @@ ## About

_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on May 09, 2017._
_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on May 17, 2017._
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