Skip to content

Commit 8380291

Browse files
committed
fix: apply suggestions from code review
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: passed - task: lint_javascript_examples status: na - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent 11f531c commit 8380291

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

lib/node_modules/@stdlib/string/num-code-points/bin/cli

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ var CLI = require( '@stdlib/cli/ctor' );
2828
var stdin = require( '@stdlib/process/read-stdin' );
2929
var stdinStream = require( '@stdlib/streams/node/stdin' );
3030
var RE_EOL = require( '@stdlib/regexp/eol' ).REGEXP;
31-
var isRegExpString = require( '@stdlib/assert/is-regexp-string' );
32-
var reFromString = require( '@stdlib/utils/regexp-from-string' );
3331
var numCodePoints = require( './../lib' );
3432

3533

@@ -43,9 +41,10 @@ var numCodePoints = require( './../lib' );
4341
*/
4442
function main() {
4543
var flags;
46-
var split;
44+
var lines;
4745
var args;
4846
var cli;
47+
var i;
4948

5049
// Create a command-line interface:
5150
cli = new CLI({
@@ -67,17 +66,16 @@ function main() {
6766

6867
// Check if we are receiving data from `stdin`...
6968
if ( !stdinStream.isTTY ) {
70-
if ( flags.split ) {
71-
if ( !isRegExpString( flags.split ) ) {
72-
flags.split = '/'+flags.split+'/';
73-
}
74-
split = reFromString( flags.split );
75-
} else {
76-
split = RE_EOL;
77-
}
7869
return stdin( onRead );
7970
}
80-
console.log( numCodePoints( args[ 0 ] ) ); // eslint-disable-line no-console
71+
if ( flags.lines ) {
72+
lines = args[ 0 ].split( RE_EOL );
73+
for ( i = 0; i < lines.length; i++ ) {
74+
console.log( numCodePoints( lines[ i ] ) ); // eslint-disable-line no-console
75+
}
76+
} else {
77+
console.log( numCodePoints( args[ 0 ] ) ); // eslint-disable-line no-console
78+
}
8179

8280
/**
8381
* Callback invoked upon reading from `stdin`.
@@ -93,14 +91,14 @@ function main() {
9391
if ( error ) {
9492
return cli.error( error );
9593
}
96-
lines = data.toString().split( split );
97-
98-
// Remove any trailing separators (e.g., trailing newline)...
99-
if ( lines[ lines.length-1 ] === '' ) {
100-
lines.pop();
101-
}
102-
for ( i = 0; i < lines.length; i++ ) {
103-
console.log( numCodePoints( lines[ i ] ) ); // eslint-disable-line no-console
94+
data = data.toString();
95+
if ( flags.lines ) {
96+
lines = data.split( RE_EOL );
97+
for ( i = 0; i < lines.length; i++ ) {
98+
console.log( numCodePoints( lines[ i ] ) ); // eslint-disable-line no-console
99+
}
100+
} else {
101+
console.log( numCodePoints( data ) ); // eslint-disable-line no-console
104102
}
105103
}
106104
}

lib/node_modules/@stdlib/string/num-code-points/test/test.cli.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ tape( 'when invoked with a `-l` flag, the command-line interface prints the numb
175175
if ( error ) {
176176
t.fail( error.message );
177177
} else {
178-
t.strictEqual( stdout.toString(), '9\n', 'expected value' );
178+
t.strictEqual( stdout.toString(), '4\n4\n', 'expected value' );
179179
t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' );
180180
}
181181
t.end();
@@ -196,7 +196,7 @@ tape( 'the command-line interface supports use as a standard stream', opts, func
196196
if ( error ) {
197197
t.fail( error.message );
198198
} else {
199-
t.strictEqual( stdout.toString(), '4\n5\n', 'expected value' );
199+
t.strictEqual( stdout.toString(), '10\n', 'expected value' );
200200
t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' );
201201
}
202202
t.end();

0 commit comments

Comments
 (0)