@inquirer/core 0.0.17-alpha.0 → 0.0.18-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -1,7 +1,3 @@
1
- const _ = {
2
- isFunction: require('lodash/isFunction'),
3
- noop: require('lodash/noop'),
4
- };
5
1
  const readline = require('readline');
6
2
  const chalk = require('chalk');
7
3
  const MuteStream = require('mute-stream');
@@ -50,7 +46,7 @@ class StateManager {
50
46
  this.screen = new ScreenManager(this.rl);
51
47
 
52
48
  let config = configFactory;
53
- if (_.isFunction(configFactory)) {
49
+ if (typeof configFactory === 'function') {
54
50
  config = configFactory(this.rl);
55
51
  }
56
52
 
@@ -70,7 +66,7 @@ class StateManager {
70
66
 
71
67
  // Load asynchronous properties
72
68
  const showLoader = setTimeout(this.startLoading, 500);
73
- if (_.isFunction(message)) {
69
+ if (typeof message === 'function') {
74
70
  message = await runAsync(message)();
75
71
  }
76
72
 
@@ -85,14 +81,16 @@ class StateManager {
85
81
  }
86
82
 
87
83
  onKeypress(value, key) {
88
- const { onKeypress = _.noop } = this.config;
84
+ const { onKeypress } = this.config;
89
85
  // Ignore enter keypress. The "line" event is handling those.
90
86
  if (key.name === 'enter' || key.name === 'return') {
91
87
  return;
92
88
  }
93
89
 
94
90
  this.setState({ value: this.rl.line, error: null });
95
- onKeypress(this.rl.line, key, this.getState(), this.setState);
91
+ if (onKeypress) {
92
+ onKeypress(this.rl.line, key, this.getState(), this.setState);
93
+ }
96
94
  }
97
95
 
98
96
  startLoading() {
@@ -195,7 +193,7 @@ class StateManager {
195
193
  prefix: this.getPrefix(),
196
194
  ...state,
197
195
  // Only pass message down if it's a string. Otherwise we're still in init state
198
- message: _.isFunction(message) ? 'Loading...' : message,
196
+ message: typeof message === 'function' ? 'Loading...' : message,
199
197
  value: transformer(value, { isFinal: status === 'done' }),
200
198
  validate: undefined,
201
199
  filter: undefined,
package/lib/Paginator.js CHANGED
@@ -1,8 +1,5 @@
1
1
  'use strict';
2
2
 
3
- const _ = {
4
- flatten: require('lodash/flatten'),
5
- };
6
3
  const chalk = require('chalk');
7
4
  const cliWidth = require('cli-width');
8
5
  const { breakLines } = require('./utils');
@@ -45,7 +42,7 @@ class Paginator {
45
42
  this.lastIndex = active;
46
43
 
47
44
  // Duplicate the lines so it give an infinite list look
48
- const infinite = _.flatten([lines, lines, lines]);
45
+ const infinite = [lines, lines, lines].flat();
49
46
  const topIndex = Math.max(0, active + lines.length - this.pointer);
50
47
 
51
48
  const section = infinite.splice(topIndex, pageSize).join('\n');
@@ -1,6 +1,3 @@
1
- const _ = {
2
- last: require('lodash/last'),
3
- };
4
1
  const cliWidth = require('cli-width');
5
2
  const stripAnsi = require('strip-ansi');
6
3
  const stringWidth = require('string-width');
@@ -9,7 +6,7 @@ const util = require('./readline');
9
6
  const { breakLines } = require('./utils');
10
7
 
11
8
  const height = (content) => content.split('\n').length;
12
- const lastLine = (content) => _.last(content.split('\n'));
9
+ const lastLine = (content) => content.split('\n').pop();
13
10
 
14
11
  module.exports = class ScreenManager {
15
12
  constructor(rl) {
package/lib/utils.js CHANGED
@@ -1,22 +1,19 @@
1
- const _ = {
2
- flatten: require('lodash/flatten'),
3
- };
4
-
5
1
  /**
6
2
  * Force line returns at specific width. This function is ANSI code friendly and it'll
7
3
  * ignore invisible codes during width calculation.
8
- * @param {string} lines
4
+ * @param {string} content
9
5
  * @param {number} width
10
6
  * @return {string}
11
7
  */
12
8
  exports.breakLines = (content, width) => {
13
9
  const regex = new RegExp('(?:(?:\\033[[0-9;]*m)*.?){1,' + width + '}', 'g');
14
- return _.flatten(
15
- content.split('\n').map((line) => {
10
+ return content
11
+ .split('\n')
12
+ .flatMap((line) => {
16
13
  const chunk = line.match(regex);
17
14
  // Remove the last match as it's always empty
18
15
  chunk.pop();
19
16
  return chunk || '';
20
17
  })
21
- ).join('\n');
18
+ .join('\n');
22
19
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inquirer/core",
3
- "version": "0.0.17-alpha.0",
3
+ "version": "0.0.18-alpha.0",
4
4
  "description": "Core Inquirer prompt API",
5
5
  "main": "index.js",
6
6
  "repository": "SBoudrias/Inquirer.js",
@@ -15,7 +15,7 @@
15
15
  "dependencies": {
16
16
  "ansi-escapes": "^4.2.1",
17
17
  "chalk": "^4.1.1",
18
- "cli-spinners": "^2.6.0",
18
+ "cli-spinners": "^2.6.1",
19
19
  "cli-width": "^3.0.0",
20
20
  "lodash": "^4.17.21",
21
21
  "mute-stream": "^0.0.8",
@@ -26,5 +26,5 @@
26
26
  "publishConfig": {
27
27
  "access": "public"
28
28
  },
29
- "gitHead": "8e0b3d4c76bcf5c970936fec2561d3cc7964abb5"
29
+ "gitHead": "e71313db1a6e26f501b58d75a9d3acf53dab5da7"
30
30
  }