Skip to content

Commit 27e7e30

Browse files
committed
fix: add review changes
1 parent 976eefa commit 27e7e30

File tree

22 files changed

+108
-90
lines changed

22 files changed

+108
-90
lines changed

lib/node_modules/@stdlib/string/base/truncate-code-points/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ limitations under the License.
2020

2121
# truncateCodePoints
2222

23-
> Truncate the Unicode code points of a provided string in order to return a string having a specified length.
23+
> Truncate the Unicode code points of a provided string in order to return a string having a specified number of Unicode code points.
2424
2525
<section class="usage">
2626

@@ -32,7 +32,7 @@ var truncateCodePoints = require( '@stdlib/string/base/truncate-code-points' );
3232

3333
#### truncateCodePoints( str, N, ending )
3434

35-
Truncates the Unicode code points of a provided string in order to return a string having a specified length.
35+
Truncates the Unicode code points of a provided string in order to return a string having a specified number of Unicode code points.
3636

3737
```javascript
3838
var out = truncateCodePoints( 'beep boop', 7, '...' );

lib/node_modules/@stdlib/string/base/truncate-code-points/docs/repl.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
{{alias}}( str, len, ending )
33
Truncate the Unicode code points of a provided string in order to return a
4-
string having a specified length.
4+
string having a specified number of Unicode code points.
55

66
Parameters
77
----------

lib/node_modules/@stdlib/string/base/truncate-code-points/docs/types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// TypeScript Version: 2.0
2020

2121
/**
22-
* Truncate the Unicode code points of a provided string in order to return a string having a specified length.
22+
* Truncate the Unicode code points of a provided string in order to return a string having a specified number of Unicode code points.
2323
*
2424
* @param str - input string
2525
* @param len - output string length (including ending)

lib/node_modules/@stdlib/string/base/truncate-code-points/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
'use strict';
2020

2121
/**
22-
* Truncate the Unicode code points of a provided string in order to return a string having a specified length.
22+
* Truncate the Unicode code points of a provided string in order to return a string having a specified number of Unicode code points.
2323
*
2424
* @module @stdlib/string/base/truncate-code-points
2525
*

lib/node_modules/@stdlib/string/base/truncate-code-points/lib/main.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var RE_UTF16_HIGH_SURROGATE = /[\uD800-\uDBFF]/; // TODO: replace with stdlib pk
3232
// MAIN //
3333

3434
/**
35-
* Truncates the Unicode code points of a provided string in order to return a string having a specified length.
35+
* Truncates the Unicode code points of a provided string in order to return a string having a specified number of Unicode code points.
3636
*
3737
* @param {string} str - input string
3838
* @param {NonNegativeInteger} len - output string length (including ending)

lib/node_modules/@stdlib/string/base/truncate-code-points/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@stdlib/string/base/truncate-code-points",
33
"version": "0.0.0",
4-
"description": "Truncate the Unicode code points of a provided string in order to return a string having a specified length.",
4+
"description": "Truncate the Unicode code points of a provided string in order to return a string having a specified number of Unicode code points.",
55
"license": "Apache-2.0",
66
"author": {
77
"name": "The Stdlib Authors",

lib/node_modules/@stdlib/string/num-code-points/README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
@license Apache-2.0
44
5-
Copyright (c) 2020 The Stdlib Authors.
5+
Copyright (c) 2023 The Stdlib Authors.
66
77
Licensed under the Apache License, Version 2.0 (the "License");
88
you may not use this file except in compliance with the License.
@@ -40,6 +40,9 @@ var out = numCodePoints( 'last man standing' );
4040

4141
out = numCodePoints( 'Hidden Treasures' );
4242
// returns 16
43+
44+
out = numCodePoints( '𐒻𐓟𐒻𐓟' );
45+
// returns 4
4346
```
4447

4548
</section>
@@ -55,14 +58,17 @@ out = numCodePoints( 'Hidden Treasures' );
5558
```javascript
5659
var numCodePoints = require( '@stdlib/string/num-code-points' );
5760

58-
var str = numCodePoints( 'last man standing' );
61+
var out = numCodePoints( 'last man standing' );
5962
// returns 17
6063

61-
str = numCodePoints( '六书/六書' );
64+
out = numCodePoints( '六书/六書' );
6265
// returns 5
6366

64-
str = numCodePoints( 'अनुच्छेद' );
67+
out = numCodePoints( 'अनुच्छेद' );
6568
// returns 8
69+
70+
out = numCodePoints( '𐒻𐓟𐒻𐓟' );
71+
// returns 4
6672
```
6773

6874
</section>

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

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,42 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var fromCodePoint = require( '@stdlib/string/from-code-point' );
25-
var UNICODE_MAX = require( '@stdlib/constants/unicode/max' );
26-
var randu = require( '@stdlib/random/base/randu' );
27-
var floor = require( '@stdlib/math/base/special/floor' );
24+
var isInteger = require( '@stdlib/assert/is-integer' );
2825
var pkg = require( './../package.json' ).name;
2926
var numCodePoints = require( './../lib' );
3027

3128

3229
// MAIN //
3330

3431
bench( pkg, function benchmark( b ) {
35-
var str;
32+
var strings;
3633
var out;
3734
var i;
3835

36+
strings = [
37+
'last man standing',
38+
'presidential election',
39+
'अनुच्छेद',
40+
'🌷',
41+
'书/六書',
42+
'เ❄︎நி',
43+
'กิิก้้ก็็ก็็กิิก้้ก็็กิิก้้กิิก้้ก็็ก็็กิิก้้ก็็กิิก้้',
44+
'書六/书六',
45+
'ܶƔλʃݖͱšɕ҆ʧѸؐҜҦɳΏ',
46+
'âݝΝ‚ҳӌݾҀƳ۵ۧ޳ǁǸΓ'
47+
];
48+
3949
b.tic();
4050
for ( i = 0; i < b.iterations; i++ ) {
41-
str = fromCodePoint( floor( randu() * UNICODE_MAX ) ) + 'eep boop';
42-
out = numCodePoints( str );
51+
out = numCodePoints( strings[ i%strings.length ] );
4352
if ( out < 0 ) {
4453
b.fail( 'should never be a negative integer' );
4554
}
4655
}
4756
b.toc();
57+
if ( !isInteger( out ) ) {
58+
b.fail( 'should return an integer' );
59+
}
4860
b.pass( 'benchmark finished' );
4961
b.end();
5062
});

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

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ 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' );
3133
var numCodePoints = require( './../lib' );
3234

3335

@@ -41,10 +43,9 @@ var numCodePoints = require( './../lib' );
4143
*/
4244
function main() {
4345
var flags;
44-
var lines;
46+
var split;
4547
var args;
4648
var cli;
47-
var i;
4849

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

6768
// Check if we are receiving data from `stdin`...
6869
if ( !stdinStream.isTTY ) {
69-
return stdin( onRead );
70-
}
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
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;
7577
}
76-
} else {
77-
console.log( numCodePoints( args[ 0 ] ) ); // eslint-disable-line no-console
78+
return stdin( onRead );
7879
}
80+
console.log( numCodePoints( args[ 0 ] ) ); // eslint-disable-line no-console
7981

8082
/**
8183
* Callback invoked upon reading from `stdin`.
@@ -91,14 +93,14 @@ function main() {
9193
if ( error ) {
9294
return cli.error( error );
9395
}
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
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
102104
}
103105
}
104106
}

lib/node_modules/@stdlib/string/num-code-points/examples/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ console.log( numCodePoints( '六书/六書' ) );
2828

2929
console.log( numCodePoints( 'अनुच्छेद' ) );
3030
// => 8
31+
32+
console.log( numCodePoints( '𐒻𐓟𐒻𐓟' ) );
33+
// => 4

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ var RE_UTF16_HIGH_SURROGATE = /[\uD800-\uDBFF]/; // TODO: replace with stdlib pk
5353
*/
5454
function numCodePoints( str ) {
5555
var count;
56-
var ch1;
57-
var ch2;
5856
var i;
5957

6058
if ( !isString( str ) ) {
@@ -64,18 +62,16 @@ function numCodePoints( str ) {
6462

6563
// Process the string one Unicode code unit at a time and count UTF-16 surrogate pairs as a single Unicode code point...
6664
for ( i = 0; i < str.length; i++ ) {
67-
ch1 = str[ i ];
68-
6965
// Check for a high UTF-16 surrogate...
70-
if ( RE_UTF16_HIGH_SURROGATE.test( ch1 ) ) {
66+
if ( RE_UTF16_HIGH_SURROGATE.test( str[ i ] ) ) {
7167
// Check for an unpaired surrogate at the end of the input string...
7268
if ( i === str.length-1 ) {
7369
// We found an unpaired surrogate...
70+
count += 1;
7471
break;
7572
}
7673
// Check whether the high surrogate is paired with a low surrogate...
77-
ch2 = str[ i+1 ];
78-
if ( RE_UTF16_LOW_SURROGATE.test( ch2 ) ) {
74+
if ( RE_UTF16_LOW_SURROGATE.test( str[ i+1 ] ) ) {
7975
// We found a surrogate pair:
8076
i += 1; // bump the index to process the next code unit
8177
count += 1;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2020 The Stdlib Authors.
4+
* Copyright (c) 2023 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -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(), '4\n4\n', 'expected value' );
178+
t.strictEqual( stdout.toString(), '9\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(), '10\n', 'expected value' );
199+
t.strictEqual( stdout.toString(), '4\n5\n', 'expected value' );
200200
t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' );
201201
}
202202
t.end();

lib/node_modules/@stdlib/string/truncate/README.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ limitations under the License.
2020

2121
# truncate
2222

23-
> Truncate a string to a specified length.
23+
> Truncate a string.
2424
2525
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
2626

@@ -40,9 +40,9 @@ limitations under the License.
4040
var truncate = require( '@stdlib/string/truncate' );
4141
```
4242

43-
#### truncate( str, len\[, ending]\[, options] )
43+
#### truncate( str, N\[, ending]\[, options] )
4444

45-
Truncates a string to a specified length.
45+
Truncates a string.
4646

4747
```javascript
4848
var out = truncate( 'beep boop', 7 );
@@ -146,7 +146,7 @@ Options:
146146
147147
-h, --help Print this message.
148148
-V, --version Print the package version.
149-
--len length String length.
149+
--N length String length.
150150
--ending str Custom ending. Default: '...'.
151151
--split sep Delimiter for stdin data. Default: '/\\r?\\n/'.
152152
--mode mode Type of character to return. Default: 'grapheme'.
@@ -166,10 +166,10 @@ Options:
166166

167167
```bash
168168
# Not escaped...
169-
$ echo -n $'Hello, World!\nBeep Boop Baz' | truncate --len 6 --split /\r?\n/
169+
$ echo -n $'Hello, World!\nBeep Boop Baz' | truncate --N 6 --split /\r?\n/
170170

171171
# Escaped...
172-
$ echo -n $'Hello, World!\nBeep Boop Baz' | truncate --len 6 --split /\\r?\\n/
172+
$ echo -n $'Hello, World!\nBeep Boop Baz' | truncate --N 6 --split /\\r?\\n/
173173
```
174174

175175
- The implementation ignores trailing delimiters.
@@ -187,24 +187,24 @@ Options:
187187
### Examples
188188

189189
```bash
190-
$ truncate 'Hello, World!' --len 8
190+
$ truncate 'Hello, World!' --N 8
191191
Hello...
192192
193-
$ truncate 'Hello, World!' --len 6 --ending '!'
193+
$ truncate 'Hello, World!' --N 6 --ending '!'
194194
Hello!
195195
```
196196

197197
To use as a [standard stream][standard-streams],
198198

199199
```bash
200-
$ echo -n 'Hello, World!' | truncate --len 8
200+
$ echo -n 'Hello, World!' | truncate --N 8
201201
Hello...
202202
```
203203

204204
By default, when used as a [standard stream][standard-streams], the implementation assumes newline-delimited data. To specify an alternative delimiter, set the `split` option.
205205

206206
```bash
207-
$ echo -n 'Hello, World!\tBeep Boop' | truncate --split '\t' --len 8
207+
$ echo -n 'Hello, World!\tBeep Boop' | truncate --split '\t' --N 8
208208
Hello...
209209
Beep ...
210210
```

lib/node_modules/@stdlib/string/truncate/bin/cli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function main() {
7878
// Get any provided command-line arguments:
7979
args = cli.args();
8080

81-
len = parseInt( flags.len, 10 );
81+
len = parseInt( flags.N, 10 );
8282

8383
// Check if we are receiving data from `stdin`...
8484
if ( !stdinStream.isTTY ) {

lib/node_modules/@stdlib/string/truncate/docs/repl.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11

2-
{{alias}}( str, len[, ending][, options] )
3-
Truncates a string to a specified length.
2+
{{alias}}( str, N[, ending][, options] )
3+
Truncates a string.
44

55
Parameters
66
----------
77
str: string
88
Input string.
99

10-
len: integer
10+
N: integer
1111
Output string length.
1212

1313
ending: string (optional)

0 commit comments

Comments
 (0)