From 9a94c69364b2916a205f1d3766176e606cbf954d Mon Sep 17 00:00:00 2001 From: Stephannie Jimenez Date: Wed, 13 Sep 2023 16:21:03 -0500 Subject: [PATCH 01/18] feat: add truncate string packages --- .../string/base/truncate-code-point/README.md | 99 +++++ .../benchmark/benchmark.js | 56 +++ .../base/truncate-code-point/docs/repl.txt | 32 ++ .../truncate-code-point/docs/types/index.d.ts | 42 ++ .../truncate-code-point/docs/types/test.ts | 69 +++ .../truncate-code-point/examples/index.js | 41 ++ .../base/truncate-code-point/lib/index.js | 43 ++ .../base/truncate-code-point/lib/main.js | 122 ++++++ .../base/truncate-code-point/package.json | 66 +++ .../base/truncate-code-point/test/test.js | 174 ++++++++ .../base/truncate-grapheme-cluster/README.md | 102 +++++ .../benchmark/benchmark.js | 56 +++ .../truncate-grapheme-cluster/docs/repl.txt | 32 ++ .../docs/types/index.d.ts | 42 ++ .../docs/types/test.ts | 69 +++ .../examples/index.js | 46 ++ .../truncate-grapheme-cluster/lib/index.js | 43 ++ .../truncate-grapheme-cluster/lib/main.js | 99 +++++ .../truncate-grapheme-cluster/package.json | 66 +++ .../truncate-grapheme-cluster/test/test.js | 186 ++++++++ .../@stdlib/string/base/truncate/README.md | 94 ++++ .../base/truncate/benchmark/benchmark.js | 56 +++ .../string/base/truncate/docs/repl.txt | 32 ++ .../base/truncate/docs/types/index.d.ts | 42 ++ .../string/base/truncate/docs/types/test.ts | 69 +++ .../string/base/truncate/examples/index.js | 36 ++ .../@stdlib/string/base/truncate/lib/index.js | 43 ++ .../@stdlib/string/base/truncate/lib/main.js | 70 +++ .../@stdlib/string/base/truncate/package.json | 66 +++ .../@stdlib/string/base/truncate/test/test.js | 93 ++++ .../@stdlib/string/num-code-points/README.md | 154 +++++++ .../num-code-points/benchmark/benchmark.js | 50 +++ .../@stdlib/string/num-code-points/bin/cli | 106 +++++ .../string/num-code-points/docs/repl.txt | 24 ++ .../num-code-points/docs/types/index.d.ts | 48 +++ .../string/num-code-points/docs/types/test.ts | 44 ++ .../string/num-code-points/docs/usage.txt | 9 + .../string/num-code-points/etc/cli_opts.json | 18 + .../string/num-code-points/examples/index.js | 30 ++ .../string/num-code-points/lib/index.js | 43 ++ .../string/num-code-points/lib/main.js | 94 ++++ .../string/num-code-points/package.json | 73 ++++ .../test/fixtures/stdin_error.js.txt | 33 ++ .../string/num-code-points/test/test.cli.js | 261 +++++++++++ .../string/num-code-points/test/test.js | 98 +++++ .../@stdlib/string/truncate/README.md | 25 +- .../string/truncate/benchmark/benchmark.js | 156 ++++--- .../@stdlib/string/truncate/bin/cli | 35 +- .../@stdlib/string/truncate/docs/repl.txt | 21 +- .../string/truncate/docs/types/index.d.ts | 63 +++ .../string/truncate/docs/types/test.ts | 15 +- .../@stdlib/string/truncate/docs/usage.txt | 1 + .../@stdlib/string/truncate/etc/cli_opts.json | 3 +- .../@stdlib/string/truncate/lib/main.js | 82 ++-- .../@stdlib/string/truncate/test/test.cli.js | 86 ++++ .../@stdlib/string/truncate/test/test.js | 405 +++++++++++++++++- 56 files changed, 3970 insertions(+), 93 deletions(-) create mode 100644 lib/node_modules/@stdlib/string/base/truncate-code-point/README.md create mode 100644 lib/node_modules/@stdlib/string/base/truncate-code-point/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/string/base/truncate-code-point/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/string/base/truncate-code-point/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/string/base/truncate-code-point/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/string/base/truncate-code-point/examples/index.js create mode 100644 lib/node_modules/@stdlib/string/base/truncate-code-point/lib/index.js create mode 100644 lib/node_modules/@stdlib/string/base/truncate-code-point/lib/main.js create mode 100644 lib/node_modules/@stdlib/string/base/truncate-code-point/package.json create mode 100644 lib/node_modules/@stdlib/string/base/truncate-code-point/test/test.js create mode 100644 lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/README.md create mode 100644 lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/examples/index.js create mode 100644 lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/lib/index.js create mode 100644 lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/lib/main.js create mode 100644 lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/package.json create mode 100644 lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/test/test.js create mode 100644 lib/node_modules/@stdlib/string/base/truncate/README.md create mode 100644 lib/node_modules/@stdlib/string/base/truncate/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/string/base/truncate/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/string/base/truncate/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/string/base/truncate/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/string/base/truncate/examples/index.js create mode 100644 lib/node_modules/@stdlib/string/base/truncate/lib/index.js create mode 100644 lib/node_modules/@stdlib/string/base/truncate/lib/main.js create mode 100644 lib/node_modules/@stdlib/string/base/truncate/package.json create mode 100644 lib/node_modules/@stdlib/string/base/truncate/test/test.js create mode 100644 lib/node_modules/@stdlib/string/num-code-points/README.md create mode 100644 lib/node_modules/@stdlib/string/num-code-points/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/string/num-code-points/bin/cli create mode 100644 lib/node_modules/@stdlib/string/num-code-points/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/string/num-code-points/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/string/num-code-points/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/string/num-code-points/docs/usage.txt create mode 100644 lib/node_modules/@stdlib/string/num-code-points/etc/cli_opts.json create mode 100644 lib/node_modules/@stdlib/string/num-code-points/examples/index.js create mode 100644 lib/node_modules/@stdlib/string/num-code-points/lib/index.js create mode 100644 lib/node_modules/@stdlib/string/num-code-points/lib/main.js create mode 100644 lib/node_modules/@stdlib/string/num-code-points/package.json create mode 100644 lib/node_modules/@stdlib/string/num-code-points/test/fixtures/stdin_error.js.txt create mode 100644 lib/node_modules/@stdlib/string/num-code-points/test/test.cli.js create mode 100644 lib/node_modules/@stdlib/string/num-code-points/test/test.js diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-point/README.md b/lib/node_modules/@stdlib/string/base/truncate-code-point/README.md new file mode 100644 index 000000000000..645687338352 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/truncate-code-point/README.md @@ -0,0 +1,99 @@ + + +# truncateCodePoint + +> Truncate code points of a string to a specified length. + +
+ +## Usage + +```javascript +var truncateCodePoint = require( '@stdlib/string/base/truncate-code-point' ); +``` + +#### truncateCodePoint( str, len\[, ending] ) + +Truncates code points of a string to a specified length. + +```javascript +var out = truncateCodePoint( 'beep boop', 7 ); +// returns 'beep...' +``` + +By default, the truncated string is appended with `'...'`. To customize the truncated string, provide an `ending` argument: + +```javascript +var out = truncateCodePoint( 'beep boop', 7, '!' ); +// returns 'beep b!' + +out = truncateCodePoint( 'beep boop', 7, '!!!' ); +// returns 'beep!!!' +``` + +
+ + + +
+ +## Examples + + + +```javascript +var truncate = require( '@stdlib/string/truncate' ); + +var str = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; +var out = truncateCodePoint( str, 14 ); +// returns 'Lorem ipsum...' + +str = 'To be or not to be, that is the question'; +out = truncateCodePoint( str, 19, '!' ); +// returns 'To be or not to be!' + +str = 'The quick fox jumps over the lazy dog.'; +out = truncateCodePoint( str, 16, '...' ); +// returns 'The quick fox...' + +out = truncateCodePoint( 'अनुच्छेद', 7 ); +// returns 'अनुच...' +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-point/benchmark/benchmark.js b/lib/node_modules/@stdlib/string/base/truncate-code-point/benchmark/benchmark.js new file mode 100644 index 000000000000..d44f1e4f845b --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/truncate-code-point/benchmark/benchmark.js @@ -0,0 +1,56 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var truncate = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var values; + var out; + var i; + + values = [ + 'beep boop', + 'foo bar', + 'xyz abc', + '🐶🐮🐷🐰🐸' + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = truncate( values[ i%values.length ], 1 ); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( out ) ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-point/docs/repl.txt b/lib/node_modules/@stdlib/string/base/truncate-code-point/docs/repl.txt new file mode 100644 index 000000000000..3901fd76e3e9 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/truncate-code-point/docs/repl.txt @@ -0,0 +1,32 @@ + +{{alias}}( str, len[, ending] ) + Truncate code points of a string to a specified length. + + Parameters + ---------- + str: string + Input string. + + len: integer + Output string length. + + ending: string (optional) + Custom ending. Default: '...'. + + Returns + ------- + out: string + Output string. + + Examples + -------- + > var str = 'beep boop'; + > var out = {{alias}}( str, 5 ) + 'be...' + + > out = {{alias}}( str, 5, '|' ) + 'beep|' + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-point/docs/types/index.d.ts b/lib/node_modules/@stdlib/string/base/truncate-code-point/docs/types/index.d.ts new file mode 100644 index 000000000000..c685e6e856bf --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/truncate-code-point/docs/types/index.d.ts @@ -0,0 +1,42 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 2.0 + +/** +* Truncate code points of a string to a specified length. +* +* @param str - input string +* @param len - output string length (including ending) +* @param ending - custom ending (default: `...`) +* @returns truncated string +* +* @example +* var out = truncate( 'beep boop', 7 ); +* // returns 'beep...' +* +* @example +* var out = truncate( 'beep boop', 7, '|' ); +* // returns 'beep b|' +*/ +declare function truncate( str: string, len: number, ending?: string ): string; + + +// EXPORTS // + +export = truncate; diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-point/docs/types/test.ts b/lib/node_modules/@stdlib/string/base/truncate-code-point/docs/types/test.ts new file mode 100644 index 000000000000..ae2ff2f94f8e --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/truncate-code-point/docs/types/test.ts @@ -0,0 +1,69 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import truncate = require( './index' ); + + +// TESTS // + +// The function returns a string... +{ + truncate( 'abc', 1 ); // $ExpectType string + truncate( 'abcdefghi', 10, '|' ); // $ExpectType string +} + +// The compiler throws an error if the function is provided a value other than a string as its first argument... +{ + truncate( true, 1 ); // $ExpectError + truncate( false, 1 ); // $ExpectError + truncate( null, 1 ); // $ExpectError + truncate( undefined, 1 ); // $ExpectError + truncate( 5, 1 ); // $ExpectError + truncate( [], 1 ); // $ExpectError + truncate( {}, 1 ); // $ExpectError + truncate( ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument that is not a number... +{ + truncate( 'abc', true ); // $ExpectError + truncate( 'abc', false ); // $ExpectError + truncate( 'abc', null ); // $ExpectError + truncate( 'abc', 'abc' ); // $ExpectError + truncate( 'abc', [] ); // $ExpectError + truncate( 'abc', {} ); // $ExpectError + truncate( 'abc', ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument that is not a string... +{ + truncate( 'beep boop', 4, true ); // $ExpectError + truncate( 'beep boop', 4, false ); // $ExpectError + truncate( 'beep boop', 4, null ); // $ExpectError + truncate( 'beep boop', 4, 123 ); // $ExpectError + truncate( 'beep boop', 4, [], 0 ); // $ExpectError + truncate( 'beep boop', 4, {}, 0 ); // $ExpectError + truncate( 'beep boop', 4, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + truncate(); // $ExpectError + truncate( 'abc' ); // $ExpectError + truncate( 'abc', 1, '.', true ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-point/examples/index.js b/lib/node_modules/@stdlib/string/base/truncate-code-point/examples/index.js new file mode 100644 index 000000000000..9486ed3a1090 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/truncate-code-point/examples/index.js @@ -0,0 +1,41 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var truncate = require( './../lib' ); + +var str = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; +var out = truncate( str, 14 ); +console.log( out ); +// => 'Lorem ipsum...' + +str = 'To be or not to be, that is the question'; +out = truncate( str, 19, '!' ); +console.log( out ); +// => 'To be or not to be!' + +str = 'The quick fox jumps over the lazy dog.'; +out = truncate( str, 16, '...' ); +console.log( out ); +// => 'The quick fox...' + +str = 'अनुच्छेद'; +out = truncate( str, 7, '...' ); +console.log( out ); +// => 'अनुच...' diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-point/lib/index.js b/lib/node_modules/@stdlib/string/base/truncate-code-point/lib/index.js new file mode 100644 index 000000000000..1e899a3d7ad4 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/truncate-code-point/lib/index.js @@ -0,0 +1,43 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Truncate code points of a string to a specified length. +* +* @module @stdlib/string/base/truncate-code-point +* +* @example +* var truncate = require( '@stdlib/string/base/truncate-code-point' ); +* +* var out = truncate( 'beep boop', 7 ); +* // returns 'beep...' +* +* out = truncate( 'beep boop', 7, '|' ); +* // returns 'beep b|' +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-point/lib/main.js b/lib/node_modules/@stdlib/string/base/truncate-code-point/lib/main.js new file mode 100644 index 000000000000..211e7b8c36cc --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/truncate-code-point/lib/main.js @@ -0,0 +1,122 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var numCodePoints = require( '@stdlib/string/num-code-points' ); + + +// VARIABLES // + +var RE_UTF16_LOW_SURROGATE = /[\uDC00-\uDFFF]/; // TODO: replace with stdlib pkg +var RE_UTF16_HIGH_SURROGATE = /[\uD800-\uDBFF]/; // TODO: replace with stdlib pkg + + +// MAIN // + +/** +* Truncates code point of a string to a specified length. +* +* @param {string} str - input string +* @param {NonNegativeInteger} len - output string length (including ending) +* @param {string} [ending='...'] - custom ending +* @returns {string} truncated string +* +* @example +* var str = 'beep boop'; +* var out = truncate( str, 7 ); +* // returns 'beep...' +* +* @example +* var str = 'beep boop'; +* var out = truncate( str, 5, '>>>' ); +* // returns 'be>>>' +* +* @example +* var str = 'beep boop'; +* var out = truncate( str, 10 ); +* // returns 'beep boop' +* +* @example +* var str = 'beep boop'; +* var out = truncate( str, 0 ); +* // returns '' +* +* @example +* var str = 'beep boop'; +* var out = truncate( str, 2 ); +* // returns '..' +*/ +function truncate( str, len, ending ) { + var endingLength; + var strLength; + var ch1; + var ch2; + var out; + var i; + + if ( typeof ending === 'undefined' ) { + ending = '...'; + } + if ( len <= 0 ) { + return ''; + } + strLength = numCodePoints( str ); + if ( len >= strLength ) { + return str; + } + endingLength = numCodePoints( ending ); + if ( endingLength >= len ) { + str = ending; + ending = ''; + endingLength = 0; + } + out = ''; + + // Process the string one Unicode code unit at a time and count UTF-16 surrogate pairs as a single Unicode code point... + for ( i = 0; i < len - endingLength; i++ ) { + ch1 = str[ i ]; + + // Check for a high UTF-16 surrogate... + if ( RE_UTF16_HIGH_SURROGATE.test( ch1 ) ) { + // Check for an unpaired surrogate at the end of the input string... + if ( i === len - endingLength - 1 ) { + // We found an unpaired surrogate... + break; + } + // Check whether the high surrogate is paired with a low surrogate... + ch2 = str[ i+1 ]; + if ( RE_UTF16_LOW_SURROGATE.test( ch2 ) ) { + // We found a surrogate pair: + i += 1; // bump the index to process the next code unit + out += ch1 + ch2; + } + } + else { + out += ch1; + } + } + return out + ending; +} + + +// EXPORTS // + +module.exports = truncate; diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-point/package.json b/lib/node_modules/@stdlib/string/base/truncate-code-point/package.json new file mode 100644 index 000000000000..2ab3fd4ec3cc --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/truncate-code-point/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/string/base/truncate-code-point", + "version": "0.0.0", + "description": "Truncate code points of a string to a specified length.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdstring", + "utilities", + "utility", + "utils", + "util", + "pad", + "string", + "str", + "truncate", + "trunc", + "shorten", + "short" + ] +} diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-point/test/test.js b/lib/node_modules/@stdlib/string/base/truncate-code-point/test/test.js new file mode 100644 index 000000000000..d053b2a4fb1f --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/truncate-code-point/test/test.js @@ -0,0 +1,174 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var truncate = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof truncate, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function truncates a string to the specified length', function test( t ) { + var expected; + var actual; + var str; + var len; + + str = 'beep boop'; + len = 5; + expected = 'be...'; + actual = truncate( str, len ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop'; + len = 10; + expected = 'beep boop'; + actual = truncate( str, len ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop'; + len = 0; + expected = ''; + actual = truncate( str, len ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop'; + len = 1; + expected = '.'; + actual = truncate( str, len ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'अनुच्छेद'; + len = 7; + expected = 'अनुच...'; + actual = truncate( str, len ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = '六书/六書'; + len = 4; + expected = '六...'; + actual = truncate( str, len ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = '𐒻𐓟𐒻𐓟𐒻𐓟𐒻𐓟𐒻𐓟'; + len = 5; + expected = '𐒻...'; + actual = truncate( str, len ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = '\uD800𐓟𐒻𐓟𐒻𐓟𐒻𐓟𐒻𐓟'; + len = 4; + expected = '...'; + actual = truncate( str, len ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function truncates a string to the specified length (custom ending)', function test( t ) { + var expected; + var actual; + var str; + var len; + + str = 'beep boop'; + len = 5; + expected = 'beep|'; + actual = truncate( str, len, '|' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop'; + len = 10; + expected = 'beep boop'; + actual = truncate( str, len, '!' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop'; + len = 3; + expected = 'be!'; + actual = truncate( str, len, '!' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'अनुच्छेद'; + len = 7; + expected = 'अनुच् &'; + actual = truncate( str, len, ' &' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = '六书/六書'; + len = 4; + expected = '六书/&'; + actual = truncate( str, len, '&' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = '六书/六'; + len = 4; + expected = '六书/六'; + actual = truncate( str, len, '書' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = '六书/六'; + len = 4; + expected = '六书/六'; + actual = truncate( str, len, '' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function truncates a string to the specified length (truncate ending)', function test( t ) { + var expected; + var actual; + var str; + var len; + + str = 'beep boop'; + len = 5; + expected = '|||||'; + actual = truncate( str, len, '||||||' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop'; + len = 3; + expected = '~~!'; + actual = truncate( str, len, '~~!' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'aaa '; + len = 2; + expected = 'अन'; + actual = truncate( str, len, 'अनुच्छेद' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = '六书/六'; + len = 3; + expected = '六书書'; + actual = truncate( str, len, '書' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/README.md b/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/README.md new file mode 100644 index 000000000000..4be520032385 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/README.md @@ -0,0 +1,102 @@ + + +# truncateGraphemeCluster + +> Truncate grapheme clusters of a string to a specified length. + +
+ +## Usage + +```javascript +var truncateGraphemeCluster = require( '@stdlib/string/base/truncate-grapheme-cluster' ); +``` + +#### truncateGraphemeCluster( str, len\[, ending] ) + +Truncates grapheme clusters of a string to a specified length. + +```javascript +var out = truncateGraphemeCluster( 'beep boop', 7 ); +// returns 'beep...' +``` + +By default, the truncated string is appended with `'...'`. To customize the truncated string, provide an `ending` argument: + +```javascript +var out = truncateGraphemeCluster( 'beep boop', 7, '!' ); +// returns 'beep b!' + +out = truncateGraphemeCluster( 'beep boop', 7, '!!!' ); +// returns 'beep!!!' +``` + +
+ + + +
+ +## Examples + + + +```javascript +var truncate = require( '@stdlib/string/truncate' ); + +var str = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; +var out = truncateGraphemeCluster( str, 14 ); +// returns 'Lorem ipsum...' + +str = 'To be or not to be, that is the question'; +out = truncateGraphemeCluster( str, 19, '!' ); +// returns 'To be or not to be!' + +str = 'The quick fox jumps over the lazy dog.'; +out = truncateGraphemeCluster( str, 16, '...' ); +// returns 'The quick fox...' + +out = truncateGraphemeCluster( 'अनुच्छेद', 4 ); +// returns 'अ...' + +out = truncateGraphemeCluster( '🌷🌷🌷🌷🌷', 4 ); +// returns '🌷...' +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/benchmark/benchmark.js b/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/benchmark/benchmark.js new file mode 100644 index 000000000000..d44f1e4f845b --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/benchmark/benchmark.js @@ -0,0 +1,56 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var truncate = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var values; + var out; + var i; + + values = [ + 'beep boop', + 'foo bar', + 'xyz abc', + '🐶🐮🐷🐰🐸' + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = truncate( values[ i%values.length ], 1 ); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( out ) ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/docs/repl.txt b/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/docs/repl.txt new file mode 100644 index 000000000000..82ee003417af --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/docs/repl.txt @@ -0,0 +1,32 @@ + +{{alias}}( str, len[, ending] ) + Truncate grapheme clusters of a string to a specified length. + + Parameters + ---------- + str: string + Input string. + + len: integer + Output string length. + + ending: string (optional) + Custom ending. Default: '...'. + + Returns + ------- + out: string + Output string. + + Examples + -------- + > var str = 'beep boop'; + > var out = {{alias}}( str, 5 ) + 'be...' + + > out = {{alias}}( str, 5, '|' ) + 'beep|' + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/docs/types/index.d.ts b/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/docs/types/index.d.ts new file mode 100644 index 000000000000..1cbd0e75d775 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/docs/types/index.d.ts @@ -0,0 +1,42 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 2.0 + +/** +* Truncate grapheme clusters of a string to a specified length. +* +* @param str - input string +* @param len - output string length (including ending) +* @param ending - custom ending (default: `...`) +* @returns truncated string +* +* @example +* var out = truncate( 'beep boop', 7 ); +* // returns 'beep...' +* +* @example +* var out = truncate( 'beep boop', 7, '|' ); +* // returns 'beep b|' +*/ +declare function truncate( str: string, len: number, ending?: string ): string; + + +// EXPORTS // + +export = truncate; diff --git a/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/docs/types/test.ts b/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/docs/types/test.ts new file mode 100644 index 000000000000..ae2ff2f94f8e --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/docs/types/test.ts @@ -0,0 +1,69 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import truncate = require( './index' ); + + +// TESTS // + +// The function returns a string... +{ + truncate( 'abc', 1 ); // $ExpectType string + truncate( 'abcdefghi', 10, '|' ); // $ExpectType string +} + +// The compiler throws an error if the function is provided a value other than a string as its first argument... +{ + truncate( true, 1 ); // $ExpectError + truncate( false, 1 ); // $ExpectError + truncate( null, 1 ); // $ExpectError + truncate( undefined, 1 ); // $ExpectError + truncate( 5, 1 ); // $ExpectError + truncate( [], 1 ); // $ExpectError + truncate( {}, 1 ); // $ExpectError + truncate( ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument that is not a number... +{ + truncate( 'abc', true ); // $ExpectError + truncate( 'abc', false ); // $ExpectError + truncate( 'abc', null ); // $ExpectError + truncate( 'abc', 'abc' ); // $ExpectError + truncate( 'abc', [] ); // $ExpectError + truncate( 'abc', {} ); // $ExpectError + truncate( 'abc', ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument that is not a string... +{ + truncate( 'beep boop', 4, true ); // $ExpectError + truncate( 'beep boop', 4, false ); // $ExpectError + truncate( 'beep boop', 4, null ); // $ExpectError + truncate( 'beep boop', 4, 123 ); // $ExpectError + truncate( 'beep boop', 4, [], 0 ); // $ExpectError + truncate( 'beep boop', 4, {}, 0 ); // $ExpectError + truncate( 'beep boop', 4, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + truncate(); // $ExpectError + truncate( 'abc' ); // $ExpectError + truncate( 'abc', 1, '.', true ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/examples/index.js b/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/examples/index.js new file mode 100644 index 000000000000..ab746954b4d6 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/examples/index.js @@ -0,0 +1,46 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var truncate = require( './../lib' ); + +var str = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; +var out = truncate( str, 14 ); +console.log( out ); +// => 'Lorem ipsum...' + +str = 'To be or not to be, that is the question'; +out = truncate( str, 19, '!' ); +console.log( out ); +// => 'To be or not to be!' + +str = 'The quick fox jumps over the lazy dog.'; +out = truncate( str, 16, '...' ); +console.log( out ); +// => 'The quick fox...' + +str = 'अनुच्छेद'; +out = truncate( str, 4, '...' ); +console.log( out ); +// => 'अ...' + +str = '🌷🌷🌷🌷🌷'; +out = truncate( str, 4, '...' ); +console.log( out ); +// => '🌷...' diff --git a/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/lib/index.js b/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/lib/index.js new file mode 100644 index 000000000000..e249fef30e2f --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/lib/index.js @@ -0,0 +1,43 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Truncate grapheme clusters of a string to a specified length. +* +* @module @stdlib/string/base/truncate-grapheme-cluster +* +* @example +* var truncate = require( '@stdlib/string/base/truncate-grapheme-cluster' ); +* +* var out = truncate( 'beep boop', 7 ); +* // returns 'beep...' +* +* out = truncate( 'beep boop', 7, '|' ); +* // returns 'beep b|' +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/lib/main.js b/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/lib/main.js new file mode 100644 index 000000000000..f136a864348b --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/lib/main.js @@ -0,0 +1,99 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var numGraphemeClusters = require( '@stdlib/string/num-grapheme-clusters' ); +var nextGraphemeClusterBreak = require( '@stdlib/string/next-grapheme-cluster-break' ); + + +// MAIN // + +/** +* Truncates grapheme clusters of a string to a specified length. +* +* @param {string} str - input string +* @param {NonNegativeInteger} len - output string length (including ending) +* @param {string} [ending='...'] - custom ending +* @returns {string} truncated string +* +* @example +* var str = 'beep boop'; +* var out = truncate( str, 7 ); +* // returns 'beep...' +* +* @example +* var str = 'beep boop'; +* var out = truncate( str, 5, '>>>' ); +* // returns 'be>>>' +* +* @example +* var str = 'beep boop'; +* var out = truncate( str, 10 ); +* // returns 'beep boop' +* +* @example +* var str = 'beep boop'; +* var out = truncate( str, 0 ); +* // returns '' +* +* @example +* var str = 'beep boop'; +* var out = truncate( str, 2 ); +* // returns '..' +*/ +function truncate( str, len, ending ) { + var endingLength; + var strLength; + var n; + var i; + + if ( typeof ending === 'undefined' ) { + ending = '...'; + } + if ( len <= 0 ) { + return ''; + } + strLength = numGraphemeClusters( str ); + if ( len >= strLength ) { + return str; + } + endingLength = numGraphemeClusters( ending ); + if ( endingLength >= len ) { + str = ending; + ending = ''; + endingLength = 0; + } + i = 0; + n = len - endingLength; + while ( n > 0 ) { + i = nextGraphemeClusterBreak( str, i ); + n -= 1; + } + if ( i === -1 ) { + return str; + } + return str.substring( 0, i ) + ending; +} + + +// EXPORTS // + +module.exports = truncate; diff --git a/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/package.json b/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/package.json new file mode 100644 index 000000000000..a4db1dc3db95 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/string/base/truncate-grapheme-cluster", + "version": "0.0.0", + "description": "Truncate grapheme clusters of a string to a specified length.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdstring", + "utilities", + "utility", + "utils", + "util", + "pad", + "string", + "str", + "truncate", + "trunc", + "shorten", + "short" + ] +} diff --git a/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/test/test.js b/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/test/test.js new file mode 100644 index 000000000000..47348a781c33 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/test/test.js @@ -0,0 +1,186 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var truncate = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof truncate, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function truncates a string to the specified length', function test( t ) { + var expected; + var actual; + var str; + var len; + + str = 'beep boop'; + len = 5; + expected = 'be...'; + actual = truncate( str, len ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop'; + len = 10; + expected = 'beep boop'; + actual = truncate( str, len ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop'; + len = 0; + expected = ''; + actual = truncate( str, len ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop'; + len = 1; + expected = '.'; + actual = truncate( str, len ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'अनुच्छेद'; + len = 4; + expected = 'अ...'; + actual = truncate( str, len ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = '六书/六書'; + len = 4; + expected = '六...'; + actual = truncate( str, len ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = '🐶🐮🐷🐰🐸🐸'; + len = 5; + expected = '🐶🐮...'; + actual = truncate( str, len ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function truncates a string to the specified length (custom ending)', function test( t ) { + var expected; + var actual; + var str; + var len; + + str = 'beep boop'; + len = 5; + expected = 'beep|'; + actual = truncate( str, len, '|' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop'; + len = 10; + expected = 'beep boop'; + actual = truncate( str, len, '!' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop'; + len = 3; + expected = 'be!'; + actual = truncate( str, len, '!' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'अनुच्छेद'; + len = 4; + expected = 'अनु &'; + actual = truncate( str, len, ' &' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = '六书/六書'; + len = 4; + expected = '六书/&'; + actual = truncate( str, len, '&' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = '六书/六'; + len = 4; + expected = '六书/六'; + actual = truncate( str, len, '書' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = '六书/六'; + len = 4; + expected = '六书/六'; + actual = truncate( str, len, '' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = '🐶🐮🐷🐰🐸'; + len = 3; + expected = '🐶🐮🐷'; + actual = truncate( str, len, '' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = '🐶🐮🐷🐰🐸'; + len = 2; + expected = '🐶!'; + actual = truncate( str, len, '!' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function truncates a string to the specified length (truncate ending)', function test( t ) { + var expected; + var actual; + var str; + var len; + + str = 'beep boop'; + len = 5; + expected = '|||||'; + actual = truncate( str, len, '||||||' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop'; + len = 3; + expected = '~~!'; + actual = truncate( str, len, '~~!' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'aaa '; + len = 2; + expected = 'अनु'; + actual = truncate( str, len, 'अनुच्छेद' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = '六书/六'; + len = 3; + expected = '六书書'; + actual = truncate( str, len, '書' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = '🐶a🐮🐷🐰🐸'; + len = 4; + expected = '🐶a🌷🌷'; + actual = truncate( str, len, '🌷🌷' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/string/base/truncate/README.md b/lib/node_modules/@stdlib/string/base/truncate/README.md new file mode 100644 index 000000000000..f8b9078f040f --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/truncate/README.md @@ -0,0 +1,94 @@ + + +# truncate + +> Truncate UTF-16 code units of a string to a specified length. + +
+ +## Usage + +```javascript +var truncate = require( '@stdlib/string/base/truncate' ); +``` + +#### truncate( str, len\[, ending] ) + +Truncates UTF-16 code units of a string to a specified length. + +```javascript +var out = truncate( 'beep boop', 7 ); +// returns 'beep...' +``` + +By default, the truncated string is appended with `'...'`. To customize the truncated string, provide an `ending` argument: + +```javascript +var out = truncate( 'beep boop', 7, '!' ); +// returns 'beep b!' + +out = truncate( 'beep boop', 7, '!!!' ); +// returns 'beep!!!' +``` + +
+ + + +
+ +## Examples + + + +```javascript +var str = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; +var out = truncate( str, 14 ); +// returns 'Lorem ipsum...' + +str = 'To be or not to be, that is the question'; +out = truncate( str, 19, '!' ); +// returns 'To be or not to be!' + +str = 'The quick fox jumps over the lazy dog.'; +out = truncate( str, 16, '...' ); +// returns 'The quick fox...' +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/string/base/truncate/benchmark/benchmark.js b/lib/node_modules/@stdlib/string/base/truncate/benchmark/benchmark.js new file mode 100644 index 000000000000..d44f1e4f845b --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/truncate/benchmark/benchmark.js @@ -0,0 +1,56 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var truncate = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var values; + var out; + var i; + + values = [ + 'beep boop', + 'foo bar', + 'xyz abc', + '🐶🐮🐷🐰🐸' + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = truncate( values[ i%values.length ], 1 ); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( out ) ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/string/base/truncate/docs/repl.txt b/lib/node_modules/@stdlib/string/base/truncate/docs/repl.txt new file mode 100644 index 000000000000..ee842a5fcb0b --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/truncate/docs/repl.txt @@ -0,0 +1,32 @@ + +{{alias}}( str, len[, ending] ) + Truncate UTF-16 code units of a string to a specified length. + + Parameters + ---------- + str: string + Input string. + + len: integer + Output string length. + + ending: string (optional) + Custom ending. Default: '...'. + + Returns + ------- + out: string + Output string. + + Examples + -------- + > var str = 'beep boop'; + > var out = {{alias}}( str, 5 ) + 'be...' + + > out = {{alias}}( str, 5, '|' ) + 'beep|' + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/string/base/truncate/docs/types/index.d.ts b/lib/node_modules/@stdlib/string/base/truncate/docs/types/index.d.ts new file mode 100644 index 000000000000..a0ce02e1e8e6 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/truncate/docs/types/index.d.ts @@ -0,0 +1,42 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 2.0 + +/** +* Truncate UTF-16 code units of a string to a specified length. +* +* @param str - input string +* @param len - output string length (including ending) +* @param ending - custom ending (default: `...`) +* @returns truncated string +* +* @example +* var out = truncate( 'beep boop', 7 ); +* // returns 'beep...' +* +* @example +* var out = truncate( 'beep boop', 7, '|' ); +* // returns 'beep b|' +*/ +declare function truncate( str: string, len: number, ending?: string ): string; + + +// EXPORTS // + +export = truncate; diff --git a/lib/node_modules/@stdlib/string/base/truncate/docs/types/test.ts b/lib/node_modules/@stdlib/string/base/truncate/docs/types/test.ts new file mode 100644 index 000000000000..ae2ff2f94f8e --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/truncate/docs/types/test.ts @@ -0,0 +1,69 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import truncate = require( './index' ); + + +// TESTS // + +// The function returns a string... +{ + truncate( 'abc', 1 ); // $ExpectType string + truncate( 'abcdefghi', 10, '|' ); // $ExpectType string +} + +// The compiler throws an error if the function is provided a value other than a string as its first argument... +{ + truncate( true, 1 ); // $ExpectError + truncate( false, 1 ); // $ExpectError + truncate( null, 1 ); // $ExpectError + truncate( undefined, 1 ); // $ExpectError + truncate( 5, 1 ); // $ExpectError + truncate( [], 1 ); // $ExpectError + truncate( {}, 1 ); // $ExpectError + truncate( ( x: number ): number => x, 1 ); // $ExpectError +} + +// The compiler throws an error if the function is provided a second argument that is not a number... +{ + truncate( 'abc', true ); // $ExpectError + truncate( 'abc', false ); // $ExpectError + truncate( 'abc', null ); // $ExpectError + truncate( 'abc', 'abc' ); // $ExpectError + truncate( 'abc', [] ); // $ExpectError + truncate( 'abc', {} ); // $ExpectError + truncate( 'abc', ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided a third argument that is not a string... +{ + truncate( 'beep boop', 4, true ); // $ExpectError + truncate( 'beep boop', 4, false ); // $ExpectError + truncate( 'beep boop', 4, null ); // $ExpectError + truncate( 'beep boop', 4, 123 ); // $ExpectError + truncate( 'beep boop', 4, [], 0 ); // $ExpectError + truncate( 'beep boop', 4, {}, 0 ); // $ExpectError + truncate( 'beep boop', 4, ( x: number ): number => x, 0 ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + truncate(); // $ExpectError + truncate( 'abc' ); // $ExpectError + truncate( 'abc', 1, '.', true ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/string/base/truncate/examples/index.js b/lib/node_modules/@stdlib/string/base/truncate/examples/index.js new file mode 100644 index 000000000000..71c27cec48f0 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/truncate/examples/index.js @@ -0,0 +1,36 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var truncate = require( './../lib' ); + +var str = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; +var out = truncate( str, 14 ); +console.log( out ); +// => 'Lorem ipsum...' + +str = 'To be or not to be, that is the question'; +out = truncate( str, 19, '!' ); +console.log( out ); +// => 'To be or not to be!' + +str = 'The quick fox jumps over the lazy dog.'; +out = truncate( str, 16, '...' ); +console.log( out ); +// => 'The quick fox...' diff --git a/lib/node_modules/@stdlib/string/base/truncate/lib/index.js b/lib/node_modules/@stdlib/string/base/truncate/lib/index.js new file mode 100644 index 000000000000..0d7d2604298e --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/truncate/lib/index.js @@ -0,0 +1,43 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Truncate UTF-16 code units of a string to a specified length. +* +* @module @stdlib/string/base/truncate +* +* @example +* var truncate = require( '@stdlib/string/base/truncate' ); +* +* var out = truncate( 'beep boop', 7 ); +* // returns 'beep...' +* +* out = truncate( 'beep boop', 7, '|' ); +* // returns 'beep b|' +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/string/base/truncate/lib/main.js b/lib/node_modules/@stdlib/string/base/truncate/lib/main.js new file mode 100644 index 000000000000..8146faa67ae1 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/truncate/lib/main.js @@ -0,0 +1,70 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MAIN // + +/** +* Truncates UTF-16 code units of a string to a specified length. +* +* @param {string} str - input string +* @param {NonNegativeInteger} len - output string length (including ending) +* @param {string} [ending='...'] - custom ending +* @returns {string} truncated string +* +* @example +* var str = 'beep boop'; +* var out = truncate( str, 7 ); +* // returns 'beep...' +* +* @example +* var str = 'beep boop'; +* var out = truncate( str, 5, '>>>' ); +* // returns 'be>>>' +* +* @example +* var str = 'beep boop'; +* var out = truncate( str, 10 ); +* // returns 'beep boop' +* +* @example +* var str = 'beep boop'; +* var out = truncate( str, 0 ); +* // returns '' +* +* @example +* var str = 'beep boop'; +* var out = truncate( str, 2 ); +* // returns '..' +*/ +function truncate( str, len, ending ) { + ending = ending || '...'; + if ( len >= str.length ) { + return str; + } + if ( len - ending.length < 0 ) { + return ending.slice( 0, len ); + } + return str.substring( 0, len - ending.length ) + ending; +} + + +// EXPORTS // + +module.exports = truncate; diff --git a/lib/node_modules/@stdlib/string/base/truncate/package.json b/lib/node_modules/@stdlib/string/base/truncate/package.json new file mode 100644 index 000000000000..60596d188b0f --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/truncate/package.json @@ -0,0 +1,66 @@ +{ + "name": "@stdlib/string/base/truncate", + "version": "0.0.0", + "description": "Truncate UTF-16 code units of a string to a specified length.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdstring", + "utilities", + "utility", + "utils", + "util", + "pad", + "string", + "str", + "truncate", + "trunc", + "shorten", + "short" + ] +} diff --git a/lib/node_modules/@stdlib/string/base/truncate/test/test.js b/lib/node_modules/@stdlib/string/base/truncate/test/test.js new file mode 100644 index 000000000000..9251482b4324 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/truncate/test/test.js @@ -0,0 +1,93 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var truncate = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof truncate, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function truncates a string to the specified length', function test( t ) { + var expected; + var actual; + var str; + var len; + + str = 'beep boop'; + len = 5; + expected = 'be...'; + actual = truncate( str, len ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop'; + len = 10; + expected = 'beep boop'; + actual = truncate( str, len ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop'; + len = 0; + expected = ''; + actual = truncate( str, len ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop'; + len = 1; + expected = '.'; + actual = truncate( str, len ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function truncates a string to the specified length (custom ending)', function test( t ) { + var expected; + var actual; + var str; + var len; + + str = 'beep boop'; + len = 5; + expected = 'beep|'; + actual = truncate( str, len, '|' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop'; + len = 10; + expected = 'beep boop'; + actual = truncate( str, len, '!' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop'; + len = 3; + expected = 'be!'; + actual = truncate( str, len, '!' ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/string/num-code-points/README.md b/lib/node_modules/@stdlib/string/num-code-points/README.md new file mode 100644 index 000000000000..f07f6e3d4efa --- /dev/null +++ b/lib/node_modules/@stdlib/string/num-code-points/README.md @@ -0,0 +1,154 @@ + + +# numCodePoints + +> Return the number of code points in a string. + +
+ +## Usage + +```javascript +var numCodePoints = require( '@stdlib/string/num-code-points' ); +``` + +#### numCodePoints( str ) + +Returns the number of code points in a `string`. + +```javascript +var out = numCodePoints( 'last man standing' ); +// returns 17 + +out = numCodePoints( 'Hidden Treasures' ); +// returns 16 +``` + +
+ + + +
+ +## Examples + + + +```javascript +var numCodePoints = require( '@stdlib/string/num-code-points' ); + +var str = numCodePoints( 'last man standing' ); +// returns 17 + +str = numCodePoints( '六书/六書' ); +// returns 5 + +str = numCodePoints( 'अनुच्छेद' ); +// returns 8 +``` + +
+ + + +* * * + +
+ +## CLI + +
+ +### Usage + +```text +Usage: num-code-points [options] [] + +Options: + + -h, --help Print this message. + -V, --version Print the package version. + -l, --lines Analyze individual lines. +``` + +
+ + + +
+ +### Examples + +```bash +$ num-code-points beep +4 +``` + +To use as a [standard stream][standard-streams], + +```bash +$ echo -n 'beep\nboop書' | num-code-points +10 +``` + +```bash +$ echo -n 'beep\nboop書' | num-code-points -l +4 +5 +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/string/num-code-points/benchmark/benchmark.js b/lib/node_modules/@stdlib/string/num-code-points/benchmark/benchmark.js new file mode 100644 index 000000000000..f95a5f49877b --- /dev/null +++ b/lib/node_modules/@stdlib/string/num-code-points/benchmark/benchmark.js @@ -0,0 +1,50 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var fromCodePoint = require( '@stdlib/string/from-code-point' ); +var UNICODE_MAX = require( '@stdlib/constants/unicode/max' ); +var randu = require( '@stdlib/random/base/randu' ); +var floor = require( '@stdlib/math/base/special/floor' ); +var pkg = require( './../package.json' ).name; +var numCodePoints = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var str; + var out; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + str = fromCodePoint( floor( randu() * UNICODE_MAX ) ) + 'eep boop'; + out = numCodePoints( str ); + if ( out < 0 ) { + b.fail( 'should never be a negative integer' ); + } + } + b.toc(); + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/string/num-code-points/bin/cli b/lib/node_modules/@stdlib/string/num-code-points/bin/cli new file mode 100644 index 000000000000..714df7e42057 --- /dev/null +++ b/lib/node_modules/@stdlib/string/num-code-points/bin/cli @@ -0,0 +1,106 @@ +#!/usr/bin/env node + +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var readFileSync = require( '@stdlib/fs/read-file' ).sync; +var CLI = require( '@stdlib/cli/ctor' ); +var stdin = require( '@stdlib/process/read-stdin' ); +var stdinStream = require( '@stdlib/streams/node/stdin' ); +var RE_EOL = require( '@stdlib/regexp/eol' ).REGEXP; +var numCodePoints = require( './../lib' ); + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +* @returns {void} +*/ +function main() { + var flags; + var lines; + var args; + var cli; + var i; + + // Create a command-line interface: + cli = new CLI({ + 'pkg': require( './../package.json' ), + 'options': require( './../etc/cli_opts.json' ), + 'help': readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { + 'encoding': 'utf8' + }) + }); + + // Get any provided command-line options: + flags = cli.flags(); + if ( flags.help || flags.version ) { + return; + } + + // Get any provided command-line arguments: + args = cli.args(); + + // Check if we are receiving data from `stdin`... + if ( !stdinStream.isTTY ) { + return stdin( onRead ); + } + if ( flags.lines ) { + lines = args[ 0 ].split( RE_EOL ); + for ( i = 0; i < lines.length; i++ ) { + console.log( numCodePoints( lines[ i ] ) ); // eslint-disable-line no-console + } + } else { + console.log( numCodePoints( args[ 0 ] ) ); // eslint-disable-line no-console + } + + /** + * Callback invoked upon reading from `stdin`. + * + * @private + * @param {(Error|null)} error - error object + * @param {Buffer} data - data + * @returns {void} + */ + function onRead( error, data ) { + var lines; + var i; + if ( error ) { + return cli.error( error ); + } + data = data.toString(); + if ( flags.lines ) { + lines = data.split( RE_EOL ); + for ( i = 0; i < lines.length; i++ ) { + console.log( numCodePoints( lines[ i ] ) ); // eslint-disable-line no-console + } + } else { + console.log( numCodePoints( data ) ); // eslint-disable-line no-console + } + } +} + +main(); diff --git a/lib/node_modules/@stdlib/string/num-code-points/docs/repl.txt b/lib/node_modules/@stdlib/string/num-code-points/docs/repl.txt new file mode 100644 index 000000000000..ad4e0ac06058 --- /dev/null +++ b/lib/node_modules/@stdlib/string/num-code-points/docs/repl.txt @@ -0,0 +1,24 @@ + +{{alias}}( str ) + Returns the number of code points in a string. + + Parameters + ---------- + str: string + Input string. + + Returns + ------- + out: string + Number of code points. + + Examples + -------- + > var out = {{alias}}( 'beep' ) + 4 + > out = {{alias}}( '六' ) + 1 + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/string/num-code-points/docs/types/index.d.ts b/lib/node_modules/@stdlib/string/num-code-points/docs/types/index.d.ts new file mode 100644 index 000000000000..cf3ec894ea60 --- /dev/null +++ b/lib/node_modules/@stdlib/string/num-code-points/docs/types/index.d.ts @@ -0,0 +1,48 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 2.0 + +/** +* Returns the number of code points in a string. +* +* @param str - input string +* @returns number of code points +* +* @example +* var out = numCodePoints( 'last man standing' ); +* // returns 17 +* +* @example +* var out = numCodePoints( 'presidential election' ); +* // returns 21 +* +* @example +* var out = numCodePoints( '六' ); +* // returns 1 +* +* @example +* var out = numCodePoints( 'अनुच्छेद' ); +* // returns 5 +*/ +declare function numCodePoints( str: string ): number; + + +// EXPORTS // + +export = numCodePoints; diff --git a/lib/node_modules/@stdlib/string/num-code-points/docs/types/test.ts b/lib/node_modules/@stdlib/string/num-code-points/docs/types/test.ts new file mode 100644 index 000000000000..f08f9c4993f3 --- /dev/null +++ b/lib/node_modules/@stdlib/string/num-code-points/docs/types/test.ts @@ -0,0 +1,44 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +import numCodePoints = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + numCodePoints( 'abc' ); // $ExpectType number +} + +// The compiler throws an error if the function is provided a value other than a string... +{ + numCodePoints( true ); // $ExpectError + numCodePoints( false ); // $ExpectError + numCodePoints( null ); // $ExpectError + numCodePoints( undefined ); // $ExpectError + numCodePoints( 5 ); // $ExpectError + numCodePoints( [] ); // $ExpectError + numCodePoints( {} ); // $ExpectError + numCodePoints( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + numCodePoints(); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/string/num-code-points/docs/usage.txt b/lib/node_modules/@stdlib/string/num-code-points/docs/usage.txt new file mode 100644 index 000000000000..7ecfdfa2eeb0 --- /dev/null +++ b/lib/node_modules/@stdlib/string/num-code-points/docs/usage.txt @@ -0,0 +1,9 @@ + +Usage: num-code-points [options] [] + +Options: + + -h, --help Print this message. + -V, --version Print the package version. + -l, --lines Analyze individual lines. + diff --git a/lib/node_modules/@stdlib/string/num-code-points/etc/cli_opts.json b/lib/node_modules/@stdlib/string/num-code-points/etc/cli_opts.json new file mode 100644 index 000000000000..d5d5629e9e27 --- /dev/null +++ b/lib/node_modules/@stdlib/string/num-code-points/etc/cli_opts.json @@ -0,0 +1,18 @@ +{ + "boolean": [ + "help", + "version", + "lines" + ], + "alias": { + "help": [ + "h" + ], + "version": [ + "V" + ], + "lines": [ + "l" + ] + } +} diff --git a/lib/node_modules/@stdlib/string/num-code-points/examples/index.js b/lib/node_modules/@stdlib/string/num-code-points/examples/index.js new file mode 100644 index 000000000000..bc0959336e18 --- /dev/null +++ b/lib/node_modules/@stdlib/string/num-code-points/examples/index.js @@ -0,0 +1,30 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var numCodePoints = require( './../lib' ); + +console.log( numCodePoints( 'last man standing' ) ); +// => 17 + +console.log( numCodePoints( '六书/六書' ) ); +// => 5 + +console.log( numCodePoints( 'अनुच्छेद' ) ); +// => 8 diff --git a/lib/node_modules/@stdlib/string/num-code-points/lib/index.js b/lib/node_modules/@stdlib/string/num-code-points/lib/index.js new file mode 100644 index 000000000000..6adf273d4d87 --- /dev/null +++ b/lib/node_modules/@stdlib/string/num-code-points/lib/index.js @@ -0,0 +1,43 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +/** +* Return the number of code points in a string. +* +* @module @stdlib/string/num-code-points +* +* @example +* var numCodePoints = require( '@stdlib/string/num-code-points' ); +* +* var out = numCodePoints( 'last man standing' ); +* // returns 17 +* +* out = numCodePoints( '六' ); +* // returns 1 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/string/num-code-points/lib/main.js b/lib/node_modules/@stdlib/string/num-code-points/lib/main.js new file mode 100644 index 000000000000..78571b0f2eff --- /dev/null +++ b/lib/node_modules/@stdlib/string/num-code-points/lib/main.js @@ -0,0 +1,94 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var format = require( '@stdlib/string/format' ); + + +// VARIABLES // + +var RE_UTF16_LOW_SURROGATE = /[\uDC00-\uDFFF]/; // TODO: replace with stdlib pkg +var RE_UTF16_HIGH_SURROGATE = /[\uD800-\uDBFF]/; // TODO: replace with stdlib pkg + + +// MAIN // + +/** +* Returns the number of code points in a string. +* +* @param {string} str - input string +* @throws {TypeError} must provide a string +* @returns {NonNegativeInteger} number of code points +* +* @example +* var out = numCodePoints( 'last man standing' ); +* // returns 17 +* +* @example +* var out = numCodePoints( 'presidential election' ); +* // returns 21 +* +* @example +* var out = numCodePoints( 'अनुच्छेद' ); +* // returns 8 +*/ +function numCodePoints( str ) { + var count; + var ch1; + var ch2; + var i; + + if ( !isString( str ) ) { + throw new TypeError( format( 'invalid argument. Must provide a string. Value: `%s`.', str ) ); + } + count = 0; + + // Process the string one Unicode code unit at a time and count UTF-16 surrogate pairs as a single Unicode code point... + for ( i = 0; i < str.length; i++ ) { + ch1 = str[ i ]; + + // Check for a high UTF-16 surrogate... + if ( RE_UTF16_HIGH_SURROGATE.test( ch1 ) ) { + // Check for an unpaired surrogate at the end of the input string... + if ( i === str.length-1 ) { + // We found an unpaired surrogate... + break; + } + // Check whether the high surrogate is paired with a low surrogate... + ch2 = str[ i+1 ]; + if ( RE_UTF16_LOW_SURROGATE.test( ch2 ) ) { + // We found a surrogate pair: + i += 1; // bump the index to process the next code unit + count += 1; + } + } + else { + count += 1; + } + } + return count; +} + + +// EXPORTS // + +module.exports = numCodePoints; diff --git a/lib/node_modules/@stdlib/string/num-code-points/package.json b/lib/node_modules/@stdlib/string/num-code-points/package.json new file mode 100644 index 000000000000..dec608eca593 --- /dev/null +++ b/lib/node_modules/@stdlib/string/num-code-points/package.json @@ -0,0 +1,73 @@ +{ + "name": "@stdlib/string/num-code-points", + "version": "0.0.0", + "description": "Return the number of code points in a string.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "bin": { + "num-code-points": "./bin/cli" + }, + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdstring", + "utilities", + "utility", + "utils", + "util", + "string", + "str", + "length", + "len", + "unicode", + "code", + "point", + "segmentation", + "surrogate", + "astral", + "emojis" + ] +} diff --git a/lib/node_modules/@stdlib/string/num-code-points/test/fixtures/stdin_error.js.txt b/lib/node_modules/@stdlib/string/num-code-points/test/fixtures/stdin_error.js.txt new file mode 100644 index 000000000000..b42c70b3b554 --- /dev/null +++ b/lib/node_modules/@stdlib/string/num-code-points/test/fixtures/stdin_error.js.txt @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +var proc = require( 'process' ); +var resolve = require( 'path' ).resolve; +var proxyquire = require( 'proxyquire' ); + +var fpath = resolve( __dirname, '..', 'bin', 'cli' ); + +proc.stdin.isTTY = false; + +proxyquire( fpath, { + '@stdlib/process/read-stdin': stdin +}); + +function stdin( clbk ) { + clbk( new Error( 'beep' ) ); +} diff --git a/lib/node_modules/@stdlib/string/num-code-points/test/test.cli.js b/lib/node_modules/@stdlib/string/num-code-points/test/test.cli.js new file mode 100644 index 000000000000..5193adf818cd --- /dev/null +++ b/lib/node_modules/@stdlib/string/num-code-points/test/test.cli.js @@ -0,0 +1,261 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2020 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var exec = require( 'child_process' ).exec; +var tape = require( 'tape' ); +var IS_BROWSER = require( '@stdlib/assert/is-browser' ); +var IS_WINDOWS = require( '@stdlib/assert/is-windows' ); +var replace = require( '@stdlib/string/replace' ); +var readFileSync = require( '@stdlib/fs/read-file' ).sync; +var EXEC_PATH = require( '@stdlib/process/exec-path' ); + + +// VARIABLES // + +var fpath = resolve( __dirname, '..', 'bin', 'cli' ); +var opts = { + 'skip': IS_BROWSER || IS_WINDOWS +}; + + +// FIXTURES // + +var PKG_VERSION = require( './../package.json' ).version; + + +// TESTS // + +tape( 'command-line interface', function test( t ) { + t.ok( true, __filename ); + t.end(); +}); + +tape( 'when invoked with a `--help` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { + var expected; + var cmd; + + expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { + 'encoding': 'utf8' + }); + cmd = [ + EXEC_PATH, + fpath, + '--help' + ]; + + exec( cmd.join( ' ' ), done ); + + function done( error, stdout, stderr ) { + if ( error ) { + t.fail( error.message ); + } else { + t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); + t.strictEqual( stderr.toString(), expected+'\n', 'expected value' ); + } + t.end(); + } +}); + +tape( 'when invoked with a `-h` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { + var expected; + var cmd; + + expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { + 'encoding': 'utf8' + }); + cmd = [ + EXEC_PATH, + fpath, + '-h' + ]; + + exec( cmd.join( ' ' ), done ); + + function done( error, stdout, stderr ) { + if ( error ) { + t.fail( error.message ); + } else { + t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); + t.strictEqual( stderr.toString(), expected+'\n', 'expected value' ); + } + t.end(); + } +}); + +tape( 'when invoked with a `--version` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { + var cmd = [ + EXEC_PATH, + fpath, + '--version' + ]; + + exec( cmd.join( ' ' ), done ); + + function done( error, stdout, stderr ) { + if ( error ) { + t.fail( error.message ); + } else { + t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); + t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); + } + t.end(); + } +}); + +tape( 'when invoked with a `-V` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { + var cmd = [ + EXEC_PATH, + fpath, + '-V' + ]; + + exec( cmd.join( ' ' ), done ); + + function done( error, stdout, stderr ) { + if ( error ) { + t.fail( error.message ); + } else { + t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); + t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); + } + t.end(); + } +}); + +tape( 'the command-line interface prints the number of code points', opts, function test( t ) { + var cmd = [ + EXEC_PATH, + '-e', + '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\\nboop\'; require( \''+fpath+'\' );"' + ]; + + exec( cmd.join( ' ' ), done ); + + function done( error, stdout, stderr ) { + if ( error ) { + t.fail( error.message ); + } else { + t.strictEqual( stdout.toString(), '9\n', 'expected value' ); + t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); + } + t.end(); + } +}); + +tape( 'when invoked with a `-l` flag, the command-line interface prints the number of code points for individual lines', opts, function test( t ) { + var cmd = [ + EXEC_PATH, + '-e', + '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\\nboop\'; process.argv[ 3 ] = \'-l\'; require( \''+fpath+'\' );"' + ]; + + exec( cmd.join( ' ' ), done ); + + function done( error, stdout, stderr ) { + if ( error ) { + t.fail( error.message ); + } else { + t.strictEqual( stdout.toString(), '4\n4\n', 'expected value' ); + t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); + } + t.end(); + } +}); + +tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { + var cmd = [ + 'printf "beep\nboop六"', + '|', + EXEC_PATH, + fpath + ]; + + exec( cmd.join( ' ' ), done ); + + function done( error, stdout, stderr ) { + if ( error ) { + t.fail( error.message ); + } else { + t.strictEqual( stdout.toString(), '10\n', 'expected value' ); + t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); + } + t.end(); + } +}); + +tape( 'when used as a standard stream with `-l` flag, the command-line interface prints the number of code points for each line', opts, function test( t ) { + var cmd = [ + 'printf "beep\nboop六"', + '|', + EXEC_PATH, + fpath, + '-l' + ]; + + exec( cmd.join( ' ' ), done ); + + function done( error, stdout, stderr ) { + if ( error ) { + t.fail( error.message ); + } else { + t.strictEqual( stdout.toString(), '4\n5\n', 'expected value' ); + t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); + } + t.end(); + } +}); + +tape( 'when used as a standard stream, if an error is encountered when reading from `stdin`, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { + var script; + var opts; + var cmd; + + script = readFileSync( resolve( __dirname, 'fixtures', 'stdin_error.js.txt' ), { + 'encoding': 'utf8' + }); + + // Replace single quotes with double quotes: + script = replace( script, '\'', '"' ); + + cmd = [ + EXEC_PATH, + '-e', + '\''+script+'\'' + ]; + + opts = { + 'cwd': __dirname + }; + + exec( cmd.join( ' ' ), opts, done ); + + function done( error, stdout, stderr ) { + if ( error ) { + t.pass( error.message ); + t.strictEqual( error.code, 1, 'expected exit code' ); + } + t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); + t.strictEqual( stderr.toString(), 'Error: beep\n', 'expected value' ); + t.end(); + } +}); diff --git a/lib/node_modules/@stdlib/string/num-code-points/test/test.js b/lib/node_modules/@stdlib/string/num-code-points/test/test.js new file mode 100644 index 000000000000..b9e89f29948a --- /dev/null +++ b/lib/node_modules/@stdlib/string/num-code-points/test/test.js @@ -0,0 +1,98 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var numCodePoints = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof numCodePoints, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if not provided a string', function test( t ) { + var values; + var i; + + values = [ + 5, + null, + true, + void 0, + NaN, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + numCodePoints( value ); + }; + } +}); + +tape( 'the function returns 0 if provided an empty string', function test( t ) { + t.strictEqual( numCodePoints( '' ), 0, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the Unicode aware length of a provided string', function test( t ) { + var out; + + out = numCodePoints( 'hello world' ); + t.strictEqual( out, 11, 'returns expected value' ); + + out = numCodePoints( '!!!' ); + t.strictEqual( out, 3, 'returns expected value' ); + + out = numCodePoints( 'अनुच्छेद' ); + t.strictEqual( out, 8, 'returns expected value' ); + + out = numCodePoints( '六' ); + t.strictEqual( out, 1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the number of grapheme clusters (Unpaired surrogates)', function test( t ) { + var out; + + out = numCodePoints( '𐒻𐓟' ); + t.strictEqual( out, 2, 'returns expected value' ); + + out = numCodePoints( '𐒻' ); + t.strictEqual( out, 1, 'returns expected value' ); + + out = numCodePoints( '\uD800' ); + t.strictEqual( out, 0, 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/string/truncate/README.md b/lib/node_modules/@stdlib/string/truncate/README.md index bf86b54fe5e1..bb3e725ec660 100644 --- a/lib/node_modules/@stdlib/string/truncate/README.md +++ b/lib/node_modules/@stdlib/string/truncate/README.md @@ -40,7 +40,7 @@ limitations under the License. var truncate = require( '@stdlib/string/truncate' ); ``` -#### truncate( str, len\[, ending] ) +#### truncate( str, len\[, ending]\[, options] ) Truncates a string to a specified length. @@ -59,6 +59,16 @@ out = truncate( 'beep boop', 7, '!!!' ); // returns 'beep!!!' ``` +The function supports the following options: + +- **mode**: type of characters to return. Must be one of the following: + + - `'grapheme'`: grapheme clusters. Appropriate for strings containing visual characters which can span multiple Unicode code points (e.g., emoji). + - `'code_point'`: Unicode code points. Appropriate for strings containing visual characters which are comprised of more than one Unicode code unit (e.g., ideographic symbols and punctuation and mathematical alphanumerics). + - `'code_unit'`: UTF-16 code units. Appropriate for strings containing visual characters drawn from the basic multilingual plane (BMP) (e.g., common characters, such as those from the Latin, Greek, and Cyrillic alphabets). + + Default: `'grapheme'`. + @@ -67,6 +77,18 @@ out = truncate( 'beep boop', 7, '!!!' );
+## Notes + +- By default, the function assumes the general case in which an input string may contain an arbitrary number of grapheme clusters. This assumption comes with a performance cost. Accordingly, if an input string is known to only contain visual characters of a particular type (e.g., only alphanumeric), one can achieve better performance by specifying the appropriate `mode` option. + +
+ + + + + +
+
@@ -127,6 +149,7 @@ Options: --len length String length. --ending str Custom ending. Default: '...'. --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. + --mode mode Type of character to return. Default: 'grapheme'. ``` diff --git a/lib/node_modules/@stdlib/string/truncate/benchmark/benchmark.js b/lib/node_modules/@stdlib/string/truncate/benchmark/benchmark.js index e7c47f509a5d..48cb0e63bd4e 100644 --- a/lib/node_modules/@stdlib/string/truncate/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/string/truncate/benchmark/benchmark.js @@ -22,70 +22,124 @@ var bench = require( '@stdlib/bench' ); var isString = require( '@stdlib/assert/is-string' ).isPrimitive; -var fromCodePoint = require( '@stdlib/string/from-code-point' ); var pkg = require( './../package.json' ).name; var truncate = require( './../lib' ); -// FUNCTIONS // +// MAIN // -/** -* Creates a benchmark function. -* -* @private -* @param {PositiveInteger} len - string length -* @returns {Function} benchmark function -*/ -function createBenchmark( len ) { - return benchmark; - - /** - * Benchmark function. - * - * @private - * @param {Benchmark} b - benchmark instance - */ - function benchmark( b ) { - var out; - var i; - - b.tic(); - for ( i = 0; i < b.iterations; i++ ) { - out = truncate( fromCodePoint( i%126 )+'eep boop', len ); - if ( typeof out !== 'string' ) { - b.fail( 'should return a string' ); - } - } - b.toc(); - if ( !isString( out ) ) { +bench( pkg, function benchmark( b ) { + var values; + var out; + var i; + + values = [ + 'beep boop', + 'foo bar', + 'xyz abc' + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = truncate( values[ i%values.length ], 5 ); + if ( typeof out !== 'string' ) { b.fail( 'should return a string' ); } - b.pass( 'benchmark finished' ); - b.end(); } -} + b.toc(); + if ( !isString( out ) ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); +bench( pkg+':mode=grapheme', function benchmark( b ) { + var values; + var opts; + var out; + var i; -// MAIN // + values = [ + 'beep boop', + 'foo bar', + 'xyz abc' + ]; + opts = { + 'mode': 'grapheme' + }; -/** -* Main execution sequence. -* -* @private -*/ -function main() { - var min; - var max; - var f; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = truncate( values[ i%values.length ], 5, opts ); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( out ) ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( pkg+':mode=code_point', function benchmark( b ) { + var values; + var opts; + var out; var i; - min = 1; - max = 10; + values = [ + 'beep boop', + 'foo bar', + 'xyz abc' + ]; + opts = { + 'mode': 'code_point' + }; - for ( i = min; i <= max; i++ ) { - f = createBenchmark( i ); - bench( pkg+':len='+i, f ); + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = truncate( values[ i%values.length ], 5, opts ); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( out ) ) { + b.fail( 'should return a string' ); } -} + b.pass( 'benchmark finished' ); + b.end(); +}); -main(); +bench( pkg+':mode=code_unit', function benchmark( b ) { + var values; + var opts; + var out; + var i; + + values = [ + 'beep boop', + 'foo bar', + 'xyz abc' + ]; + opts = { + 'mode': 'code_unit' + }; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = truncate( values[ i%values.length ], 5, opts ); + if ( typeof out !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( out ) ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/string/truncate/bin/cli b/lib/node_modules/@stdlib/string/truncate/bin/cli index a306c0c52a1a..1502e2b731e1 100644 --- a/lib/node_modules/@stdlib/string/truncate/bin/cli +++ b/lib/node_modules/@stdlib/string/truncate/bin/cli @@ -42,9 +42,11 @@ var truncate = require( './../lib' ); * @returns {void} */ function main() { + var ending; var split; var flags; var args; + var opts; var cli; var len; @@ -62,6 +64,16 @@ function main() { if ( flags.help || flags.version ) { return; } + if ( flags.ending ) { + ending = flags.ending; + } + else { + ending = '...'; + } + opts = {}; + if ( flags.mode ) { + opts.mode = flags.mode; + } // Get any provided command-line arguments: args = cli.args(); @@ -80,10 +92,10 @@ function main() { } return stdin( onRead ); } - if ( flags.ending ) { - console.log( truncate( args[ 0 ], len, flags.ending ) ); // eslint-disable-line no-console - } else { - console.log( truncate( args[ 0 ], len ) ); // eslint-disable-line no-console + try { + console.log( truncate( args[ 0 ], len, ending, opts ) ); // eslint-disable-line no-console + } catch ( error ) { + return cli.error( error ); } /** @@ -106,15 +118,16 @@ function main() { if ( lines[ lines.length-1 ] === '' ) { lines.pop(); } - if ( flags.ending ) { - for ( i = 0; i < lines.length; i++ ) { - console.log( truncate( lines[ i ], len, flags.ending ) ); // eslint-disable-line no-console - } - } else { - for ( i = 0; i < lines.length; i++ ) { - console.log( truncate( lines[ i ], len ) ); // eslint-disable-line no-console + if ( lines.length ) { + try { + console.log( truncate( lines[ 0 ], len, ending, opts ) ); // eslint-disable-line no-console + } catch ( error ) { + return cli.error( error ); } } + for ( i = 1; i < lines.length; i++ ) { + console.log( truncate( lines[ i ], len, ending, opts ) ); // eslint-disable-line no-console + } } } diff --git a/lib/node_modules/@stdlib/string/truncate/docs/repl.txt b/lib/node_modules/@stdlib/string/truncate/docs/repl.txt index 0ba0c4f35b62..5ea94d4977d7 100644 --- a/lib/node_modules/@stdlib/string/truncate/docs/repl.txt +++ b/lib/node_modules/@stdlib/string/truncate/docs/repl.txt @@ -1,5 +1,5 @@ -{{alias}}( str, len[, ending] ) +{{alias}}( str, len[, ending][, options] ) Truncates a string to a specified length. Parameters @@ -13,6 +13,25 @@ ending: string (optional) Custom ending. Default: '...'. + options: Object (optional) + Options. + + options.mode: string (optional) + Type of characters to return. The following modes are supported: + + - grapheme: grapheme clusters. Appropriate for strings containing visual + characters which can span multiple Unicode code points (e.g., emoji). + - code_point: Unicode code points. Appropriate for strings containing + visual characters which are comprised of more than one Unicode code + unit (e.g., ideographic symbols and punctuation and mathematical + alphanumerics). + - code_unit': UTF-16 code units. Appropriate for strings containing + visual characters drawn from the basic multilingual plane (BMP) (e.g., + common characters, such as those from the Latin, Greek, and Cyrillic + alphabets). + + Default: 'grapheme'. + Returns ------- out: string diff --git a/lib/node_modules/@stdlib/string/truncate/docs/types/index.d.ts b/lib/node_modules/@stdlib/string/truncate/docs/types/index.d.ts index ad332539b54d..7fd6251f5948 100644 --- a/lib/node_modules/@stdlib/string/truncate/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/string/truncate/docs/types/index.d.ts @@ -20,6 +20,48 @@ /// +// tslint:disable:unified-signatures + +/** +* Interface describing function options. +*/ +interface Options { + /** + * Specifies the type of characters to return (default: 'grapheme'). + * + * ## Notes + * + * - The following option values are supported: + * + * - `'grapheme'`: grapheme clusters. Appropriate for strings containing visual characters which can span multiple Unicode code points (e.g., emoji). + * - `'code_point'`: Unicode code points. Appropriate for strings containing visual characters which are comprised of more than one Unicode code unit (e.g., ideographic symbols and punctuation and mathematical alphanumerics). + * - `'code_unit'`: UTF-16 code units. Appropriate for strings containing visual characters drawn from the basic multilingual plane (BMP) (e.g., common characters, such as those from the Latin, Greek, and Cyrillic alphabets). + */ + mode?: 'grapheme' | 'code_point' | 'code_unit'; +} + +/** +* Truncates a string to a specified length. +* +* @param str - input string +* @param len - output string length (including ending) +* @param options - options +* @returns truncated string +* +* @example +* var out = truncate( 'beep boop', 7, { +* 'mode': 'code_unit' +* }); +* // returns 'beep...' +* +* @example +* var out = truncate( '🐶🐮🐷🐰🐸', 5, { +* 'mode': 'grapheme' +* }); +* // returns '🐶🐮...' +*/ +declare function truncate( str: string, len: number, options?: Options ): string; + /** * Truncates a string to a specified length. * @@ -38,6 +80,27 @@ */ declare function truncate( str: string, len: number, ending?: string ): string; +/** +* Truncates a string to a specified length. +* +* @param str - input string +* @param len - output string length (including ending) +* @param ending - custom ending (default: `...`) +* @returns truncated string +* +* @example +* var out = truncate( 'beep boop', 7, { +* 'mode': 'code_unit' +* }); +* // returns 'beep...' +* +* @example +* var out = truncate( 'beep boop', 7, '|', { +* 'mode': 'grapheme' +* }); +* // returns 'beep b|' +*/ +declare function truncate( str: string, len: number, ending: string, options?: Options ): string; // EXPORTS // diff --git a/lib/node_modules/@stdlib/string/truncate/docs/types/test.ts b/lib/node_modules/@stdlib/string/truncate/docs/types/test.ts index d97d791827c5..7dda55a3e27e 100644 --- a/lib/node_modules/@stdlib/string/truncate/docs/types/test.ts +++ b/lib/node_modules/@stdlib/string/truncate/docs/types/test.ts @@ -25,6 +25,8 @@ import truncate = require( './index' ); { truncate( 'abcdefghi', 3 ); // $ExpectType string truncate( 'abcdefghi', 10, '|' ); // $ExpectType string + truncate( 'abcdefghi', 5, {} ); // $ExpectType string + truncate( 'abcdefghi', 5, '~', {} ); // $ExpectType string } // The compiler throws an error if the function is not provided a string as its first argument... @@ -57,8 +59,19 @@ import truncate = require( './index' ); truncate( 'beep boop', 4, ( x: number ): number => x, 0 ); // $ExpectError } +// The compiler throws an error if the function is provided an invalid `mode` option... +{ + truncate( 'abc', 1, '~', { 'mode': true } ); // $ExpectError + truncate( 'abc', 1, '~', { 'mode': false } ); // $ExpectError + truncate( 'abc', 1, '~', { 'mode': null } ); // $ExpectError + truncate( 'abc', 1, '~', { 'mode': '' } ); // $ExpectError + truncate( 'abc', 1, '~', { 'mode': [] } ); // $ExpectError + truncate( 'abc', 1, '~', { 'mode': {} } ); // $ExpectError + truncate( 'abc', 1, '~', { 'mode': ( x: number ): number => x } ); // $ExpectError +} + // The compiler throws an error if the function is provided an unsupported number of arguments... { truncate(); // $ExpectError - truncate( 'abc', 4, '|', true ); // $ExpectError + truncate( 'abc', 4, '|', {}, true ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/string/truncate/docs/usage.txt b/lib/node_modules/@stdlib/string/truncate/docs/usage.txt index 2f3734bdadb9..2b741cd5ec6b 100644 --- a/lib/node_modules/@stdlib/string/truncate/docs/usage.txt +++ b/lib/node_modules/@stdlib/string/truncate/docs/usage.txt @@ -8,3 +8,4 @@ Options: --len length String length. --ending str Custom ending. Default: '...'. --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. + --mode mode Type of character to return. Default: 'grapheme'. diff --git a/lib/node_modules/@stdlib/string/truncate/etc/cli_opts.json b/lib/node_modules/@stdlib/string/truncate/etc/cli_opts.json index 5dd6d7cb5402..4e441a45ae29 100644 --- a/lib/node_modules/@stdlib/string/truncate/etc/cli_opts.json +++ b/lib/node_modules/@stdlib/string/truncate/etc/cli_opts.json @@ -2,7 +2,8 @@ "string": [ "len", "ending", - "split" + "split", + "mode" ], "boolean": [ "help", diff --git a/lib/node_modules/@stdlib/string/truncate/lib/main.js b/lib/node_modules/@stdlib/string/truncate/lib/main.js index 5aadc30d4da4..26cbc74231b6 100644 --- a/lib/node_modules/@stdlib/string/truncate/lib/main.js +++ b/lib/node_modules/@stdlib/string/truncate/lib/main.js @@ -22,11 +22,26 @@ var isString = require( '@stdlib/assert/is-string' ).isPrimitive; var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive; -var numGraphemeClusters = require( '@stdlib/string/num-grapheme-clusters' ); -var nextGraphemeClusterBreak = require( '@stdlib/string/next-grapheme-cluster-break' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var isPlainObject = require( '@stdlib/assert/is-plain-object' ); +var contains = require( '@stdlib/array/base/assert/contains' ).factory; +var truncateGraphemeCluster = require( '@stdlib/string/base/truncate-grapheme-cluster' ); +var truncateCodePoint = require( '@stdlib/string/base/truncate-code-point' ); +var truncateCodeUnit = require( '@stdlib/string/base/truncate' ); var format = require( '@stdlib/string/format' ); +// VARIABLES // + +var MODES = [ 'grapheme', 'code_point', 'code_unit' ]; +var FCNS = { + 'grapheme': truncateGraphemeCluster, + 'code_point': truncateCodePoint, + 'code_unit': truncateCodeUnit +}; +var isMode = contains( MODES ); + + // MAIN // /** @@ -35,9 +50,13 @@ var format = require( '@stdlib/string/format' ); * @param {string} str - input string * @param {integer} len - output string length (including ending) * @param {string} [ending='...'] - custom ending +* @param {Options} [options] - options +* @param {string} [options.mode="grapheme"] - type of "character" to return (must be either `grapheme`, `code_point`, or `code_unit`) * @throws {TypeError} first argument must be a string * @throws {TypeError} second argument must be a nonnegative integer * @throws {TypeError} third argument must be a string +* @throws {TypeError} options argument must be an object +* @throws {TypeError} must provide valid options * @returns {string} truncated string * * @example @@ -70,38 +89,53 @@ var format = require( '@stdlib/string/format' ); * var out = truncate( str, 6 ); * // returns '🐺 W...' */ -function truncate( str, len, ending ) { - var endingLength; - var fromIndex; - var nVisual; - var idx; +function truncate( str, len ) { + var options; + var ending; + var nargs; + var opts; + if ( !isString( str ) ) { throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); } if ( !isNonNegativeInteger( len ) ) { throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', len ) ); } - if ( arguments.length > 2 ) { + opts = { + 'mode': 'grapheme' + }; + nargs = arguments.length; + + if (nargs === 2 ) { + ending = '...'; + } else if ( nargs === 3 ) { + ending = arguments[ 2 ]; + if ( isPlainObject( ending )) { + options = ending; + ending = '...'; + } else if ( !isString( ending ) ) { + throw new TypeError( format( 'invalid argument. Third argument must be a string. Value: `%s`.', str ) ); + } + } else { + ending = arguments[ 2 ]; if ( !isString( ending ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string. Value: `%s`.', ending ) ); + throw new TypeError( format( 'invalid argument. Third argument must be a string. Value: `%s`.', str ) ); + } + options = arguments[ 3 ]; + if ( !isPlainObject( options ) ) { + console.log('!!!!!!!'); + throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); } } - ending = ending || '...'; - endingLength = numGraphemeClusters( ending ); - fromIndex = 0; - if ( len > numGraphemeClusters( str ) ) { - return str; - } - if ( len - endingLength < 0 ) { - return ending.slice( 0, len ); - } - nVisual = 0; - while ( nVisual < len - endingLength ) { - idx = nextGraphemeClusterBreak( str, fromIndex ); - fromIndex = idx; - nVisual += 1; + if ( options ) { + if ( hasOwnProp( options, 'mode' ) ) { + opts.mode = options.mode; + if ( !isMode( opts.mode ) ) { + throw new TypeError( format( 'invalid option. `%s` option must be one of the following: "%s". Value: `%s`.', 'mode', MODES.join( '", "' ), opts.mode ) ); + } + } } - return str.substring( 0, idx ) + ending; + return FCNS[ opts.mode ]( str, len, ending ); } diff --git a/lib/node_modules/@stdlib/string/truncate/test/test.cli.js b/lib/node_modules/@stdlib/string/truncate/test/test.cli.js index 75d1c10b824c..b651b6960309 100644 --- a/lib/node_modules/@stdlib/string/truncate/test/test.cli.js +++ b/lib/node_modules/@stdlib/string/truncate/test/test.cli.js @@ -190,6 +190,46 @@ tape( 'the command-line interface truncates a string (custom ending)', opts, fun } }); +tape( 'the command-line interface supports specifying the type of characters to return', opts, function test( t ) { + var cmd = [ + EXEC_PATH, + '-e', + '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep boop\'; process.argv[ 3 ] = \'--len=4\'; process.argv[ 4 ] = \'--mode=code_point\'; require( \''+fpath+'\' );"' + ]; + + exec( cmd.join( ' ' ), done ); + + function done( error, stdout, stderr ) { + if ( error ) { + t.fail( error.message ); + } else { + t.strictEqual( stdout.toString(), 'b...\n', 'expected value' ); + t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); + } + t.end(); + } +}); + +tape( 'if provided an invalid option, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { + var cmd = [ + EXEC_PATH, + '-e', + '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--len=4\'; process.argv[ 4 ] = \'--mode=foo\'; require( \''+fpath+'\' );"' + ]; + + exec( cmd.join( ' ' ), done ); + + function done( error, stdout, stderr ) { + if ( error ) { + t.pass( error.message ); + t.strictEqual( error.code, 1, 'expected exit code' ); + } + t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); + t.strictEqual( stderr.toString().length > 0, true, 'expected value' ); + t.end(); + } +}); + tape( 'the command-line interface supports use as a standard stream', opts, function test( t ) { var cmd = [ 'printf "beep boop\nHello World!"', @@ -258,6 +298,29 @@ tape( 'the command-line interface supports specifying a custom delimiter when us } }); +tape( 'the command-line interface supports specifying the type of characters to return when used as a standard stream', opts, function test( t ) { + var cmd = [ + 'printf \'beep boop\tHello World!\'', + '|', + EXEC_PATH, + fpath, + '--len=5', + '--mode code_point' + ]; + + exec( cmd.join( ' ' ), done ); + + function done( error, stdout, stderr ) { + if ( error ) { + t.fail( error.message ); + } else { + t.strictEqual( stdout.toString(), 'be...\n', 'expected value' ); + t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); + } + t.end(); + } +}); + tape( 'the command-line interface supports specifying a custom delimiter when used as a standard stream (regexp)', opts, function test( t ) { var cmd = [ 'printf \'beep boop\tHello World!\'', @@ -281,6 +344,29 @@ tape( 'the command-line interface supports specifying a custom delimiter when us } }); +tape( 'when used as a standard stream, if provided an invalid option, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { + var cmd = [ + 'printf \'beep boop\tHello World!\'', + '|', + EXEC_PATH, + fpath, + '--len=5', + '--mode=foo' + ]; + + exec( cmd.join( ' ' ), done ); + + function done( error, stdout, stderr ) { + if ( error ) { + t.pass( error.message ); + t.strictEqual( error.code, 1, 'expected exit code' ); + } + t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); + t.strictEqual( stderr.toString().length > 0, true, 'expected value' ); + t.end(); + } +}); + tape( 'when used as a standard stream, if an error is encountered when reading from `stdin`, the command-line interface prints an error and sets a non-zero exit code', opts, function test( t ) { var script; var opts; diff --git a/lib/node_modules/@stdlib/string/truncate/test/test.js b/lib/node_modules/@stdlib/string/truncate/test/test.js index 897a7e844f29..b533557c1b1c 100644 --- a/lib/node_modules/@stdlib/string/truncate/test/test.js +++ b/lib/node_modules/@stdlib/string/truncate/test/test.js @@ -59,6 +59,33 @@ tape( 'the function throws an error if not provided a string primitive', functio } }); +tape( 'the function throws an error if not provided a string primitive (options)', function test( t ) { + var values; + var i; + + values = [ + 5, + NaN, + null, + void 0, + true, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + truncate( value, {} ); + }; + } +}); + tape( 'the function throws an error if not provided a nonnegative integer as its second argument', function test( t ) { var values; var i; @@ -88,6 +115,35 @@ tape( 'the function throws an error if not provided a nonnegative integer as its } }); +tape( 'the function throws an error if not provided a nonnegative integer as its third argument (options)', function test( t ) { + var values; + var i; + + values = [ + '5', + -5, + 3.14, + NaN, + null, + void 0, + true, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + truncate( 'beep boop', value, {} ); + }; + } +}); + tape( 'the function throws an error if provided a non-string as a third argument', function test( t ) { var values; var i; @@ -99,7 +155,6 @@ tape( 'the function throws an error if provided a non-string as a third argument void 0, true, [], - {}, function noop() {} ]; @@ -115,7 +170,117 @@ tape( 'the function throws an error if provided a non-string as a third argument } }); -tape( 'the function truncates a string to the specified length', function test( t ) { +tape( 'the function throws an error if provided a non-string as a third argument (options)', function test( t ) { + var values; + var i; + + values = [ + 5, + NaN, + null, + void 0, + true, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + truncate( 'beep boop', 5, value, {} ); + }; + } +}); + +tape( 'the function throws an error if provided an options argument which is not an object', function test( t ) { + var values; + var i; + + values = [ + 3, + null, + true, + void 0, + NaN, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + truncate( 'beep', 1, '!!', value ); + }; + } +}); + +tape( 'the function throws an error if provided a `mode` option which is not a supported mode (third argument)', function test( t ) { + var values; + var i; + + values = [ + 3, + null, + true, + void 0, + NaN, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + truncate( 'beep', 1, { + 'mode': value + }); + }; + } +}); + +tape( 'the function throws an error if provided a `mode` option which is not a supported mode (fourth argument)', function test( t ) { + var values; + var i; + + values = [ + 'abc', + 3, + null, + true, + void 0, + NaN, + [], + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + truncate( 'beep', 1, '!', { + 'mode': value + }); + }; + } +}); + +tape( 'the function truncates a string to the specified length (default)', function test( t ) { var expected; var actual; var str; @@ -154,7 +319,7 @@ tape( 'the function truncates a string to the specified length', function test( t.end(); }); -tape( 'the function truncates a string to the specified length (custom ending)', function test( t ) { +tape( 'the function truncates a string to the specified length (custom ending, deafult)', function test( t ) { var expected; var actual; var str; @@ -198,3 +363,237 @@ tape( 'the function truncates a string to the specified length (custom ending)', t.end(); }); + +tape( 'the function truncates a string to the specified length (mode=grapheme)', function test( t ) { + var expected; + var actual; + var opts; + var str; + var len; + + opts = { + 'mode': 'grapheme' + }; + + str = 'beep boop'; + len = 5; + expected = 'be...'; + actual = truncate( str, len, opts ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop'; + len = 10; + expected = 'beep boop'; + actual = truncate( str, len, opts ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop'; + len = 0; + expected = ''; + actual = truncate( str, len, opts ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop'; + len = 1; + expected = '.'; + actual = truncate( str, len, opts ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = '🐺 Wolf Brothers 🐺'; + len = 6; + expected = '🐺 W...'; + actual = truncate( str, len, opts ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function truncates a string to the specified length (custom ending, mode=grapheme)', function test( t ) { + var expected; + var actual; + var opts; + var str; + var len; + + opts = { + 'mode': 'grapheme' + }; + + str = 'beep boop'; + len = 5; + expected = 'beep|'; + actual = truncate( str, len, '|', opts ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop'; + len = 10; + expected = 'beep boop'; + actual = truncate( str, len, '!', opts ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop'; + len = 3; + expected = 'be!'; + actual = truncate( str, len, '!', opts ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop'; + len = 5; + expected = 'beep😃'; + actual = truncate( str, len, '😃', opts ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop foo bar'; + len = 10; + expected = 'beep 🙃 🙃 🙃'; + actual = truncate( str, len, ' 🙃 🙃 🙃', opts ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = '🐺 Wolf Brothers 🐺'; + len = 8; + expected = '🐺 Wolf 🐺'; + actual = truncate( str, len, '🐺', opts ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function truncates a string to the specified length (mode=code_point)', function test( t ) { + var expected; + var actual; + var opts; + var str; + var len; + + opts = { + 'mode': 'code_point' + }; + + str = 'beep boop'; + len = 5; + expected = 'be...'; + actual = truncate( str, len, opts ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop'; + len = 10; + expected = 'beep boop'; + actual = truncate( str, len, opts ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop'; + len = 0; + expected = ''; + actual = truncate( str, len, opts ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop'; + len = 1; + expected = '.'; + actual = truncate( str, len, opts ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function truncates a string to the specified length (custom ending, mode=code_point)', function test( t ) { + var expected; + var actual; + var opts; + var str; + var len; + + opts = { + 'mode': 'code_point' + }; + + str = 'beep boop'; + len = 5; + expected = 'beep|'; + actual = truncate( str, len, '|', opts ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop'; + len = 10; + expected = 'beep boop'; + actual = truncate( str, len, '!', opts ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop'; + len = 3; + expected = 'be!'; + actual = truncate( str, len, '!', opts ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function truncates a string to the specified length (mode=code_unit)', function test( t ) { + var expected; + var actual; + var opts; + var str; + var len; + + opts = { + 'mode': 'code_unit' + }; + + str = 'beep boop'; + len = 5; + expected = 'be...'; + actual = truncate( str, len, opts ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop'; + len = 10; + expected = 'beep boop'; + actual = truncate( str, len, opts ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop'; + len = 0; + expected = ''; + actual = truncate( str, len, opts ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop'; + len = 1; + expected = '.'; + actual = truncate( str, len, opts ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function truncates a string to the specified length (custom ending, mode=code_unit)', function test( t ) { + var expected; + var actual; + var opts; + var str; + var len; + + opts = { + 'mode': 'code_unit' + }; + + str = 'beep boop'; + len = 5; + expected = 'beep|'; + actual = truncate( str, len, '|', opts ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop'; + len = 10; + expected = 'beep boop'; + actual = truncate( str, len, '!', opts ); + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop'; + len = 3; + expected = 'be!'; + actual = truncate( str, len, '!', opts ); + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); From c85a6dfbf895a812d0eab4610708ddbd5ae679fd Mon Sep 17 00:00:00 2001 From: Stephannie Jimenez Date: Tue, 7 Nov 2023 18:10:39 -0500 Subject: [PATCH 02/18] fix: rename base packages --- .../README.md | 20 ++++++++--------- .../benchmark/benchmark.js | 0 .../docs/repl.txt | 0 .../docs/types/index.d.ts | 0 .../docs/types/test.ts | 0 .../examples/index.js | 0 .../lib/index.js | 4 ++-- .../lib/main.js | 0 .../package.json | 2 +- .../test/test.js | 0 .../README.md | 22 +++++++++---------- .../benchmark/benchmark.js | 0 .../docs/repl.txt | 0 .../docs/types/index.d.ts | 0 .../docs/types/test.ts | 0 .../examples/index.js | 0 .../lib/index.js | 4 ++-- .../lib/main.js | 0 .../package.json | 2 +- .../test/test.js | 0 .../@stdlib/string/truncate/lib/main.js | 4 ++-- 21 files changed, 29 insertions(+), 29 deletions(-) rename lib/node_modules/@stdlib/string/base/{truncate-code-point => truncate-code-points}/README.md (79%) rename lib/node_modules/@stdlib/string/base/{truncate-code-point => truncate-code-points}/benchmark/benchmark.js (100%) rename lib/node_modules/@stdlib/string/base/{truncate-code-point => truncate-code-points}/docs/repl.txt (100%) rename lib/node_modules/@stdlib/string/base/{truncate-code-point => truncate-code-points}/docs/types/index.d.ts (100%) rename lib/node_modules/@stdlib/string/base/{truncate-code-point => truncate-code-points}/docs/types/test.ts (100%) rename lib/node_modules/@stdlib/string/base/{truncate-code-point => truncate-code-points}/examples/index.js (100%) rename lib/node_modules/@stdlib/string/base/{truncate-code-point => truncate-code-points}/lib/index.js (94%) rename lib/node_modules/@stdlib/string/base/{truncate-code-point => truncate-code-points}/lib/main.js (100%) rename lib/node_modules/@stdlib/string/base/{truncate-code-point => truncate-code-points}/package.json (95%) rename lib/node_modules/@stdlib/string/base/{truncate-code-point => truncate-code-points}/test/test.js (100%) rename lib/node_modules/@stdlib/string/base/{truncate-grapheme-cluster => truncate-grapheme-clusters}/README.md (75%) rename lib/node_modules/@stdlib/string/base/{truncate-grapheme-cluster => truncate-grapheme-clusters}/benchmark/benchmark.js (100%) rename lib/node_modules/@stdlib/string/base/{truncate-grapheme-cluster => truncate-grapheme-clusters}/docs/repl.txt (100%) rename lib/node_modules/@stdlib/string/base/{truncate-grapheme-cluster => truncate-grapheme-clusters}/docs/types/index.d.ts (100%) rename lib/node_modules/@stdlib/string/base/{truncate-grapheme-cluster => truncate-grapheme-clusters}/docs/types/test.ts (100%) rename lib/node_modules/@stdlib/string/base/{truncate-grapheme-cluster => truncate-grapheme-clusters}/examples/index.js (100%) rename lib/node_modules/@stdlib/string/base/{truncate-grapheme-cluster => truncate-grapheme-clusters}/lib/index.js (93%) rename lib/node_modules/@stdlib/string/base/{truncate-grapheme-cluster => truncate-grapheme-clusters}/lib/main.js (100%) rename lib/node_modules/@stdlib/string/base/{truncate-grapheme-cluster => truncate-grapheme-clusters}/package.json (95%) rename lib/node_modules/@stdlib/string/base/{truncate-grapheme-cluster => truncate-grapheme-clusters}/test/test.js (100%) diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-point/README.md b/lib/node_modules/@stdlib/string/base/truncate-code-points/README.md similarity index 79% rename from lib/node_modules/@stdlib/string/base/truncate-code-point/README.md rename to lib/node_modules/@stdlib/string/base/truncate-code-points/README.md index 645687338352..970e544beb77 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-point/README.md +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/README.md @@ -18,7 +18,7 @@ limitations under the License. --> -# truncateCodePoint +# truncateCodePoints > Truncate code points of a string to a specified length. @@ -27,25 +27,25 @@ limitations under the License. ## Usage ```javascript -var truncateCodePoint = require( '@stdlib/string/base/truncate-code-point' ); +var truncateCodePoints = require( '@stdlib/string/base/truncate-code-points' ); ``` -#### truncateCodePoint( str, len\[, ending] ) +#### truncateCodePoints( str, len\[, ending] ) Truncates code points of a string to a specified length. ```javascript -var out = truncateCodePoint( 'beep boop', 7 ); +var out = truncateCodePoints( 'beep boop', 7 ); // returns 'beep...' ``` By default, the truncated string is appended with `'...'`. To customize the truncated string, provide an `ending` argument: ```javascript -var out = truncateCodePoint( 'beep boop', 7, '!' ); +var out = truncateCodePoints( 'beep boop', 7, '!' ); // returns 'beep b!' -out = truncateCodePoint( 'beep boop', 7, '!!!' ); +out = truncateCodePoints( 'beep boop', 7, '!!!' ); // returns 'beep!!!' ``` @@ -63,18 +63,18 @@ out = truncateCodePoint( 'beep boop', 7, '!!!' ); var truncate = require( '@stdlib/string/truncate' ); var str = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; -var out = truncateCodePoint( str, 14 ); +var out = truncateCodePoints( str, 14 ); // returns 'Lorem ipsum...' str = 'To be or not to be, that is the question'; -out = truncateCodePoint( str, 19, '!' ); +out = truncateCodePoints( str, 19, '!' ); // returns 'To be or not to be!' str = 'The quick fox jumps over the lazy dog.'; -out = truncateCodePoint( str, 16, '...' ); +out = truncateCodePoints( str, 16, '...' ); // returns 'The quick fox...' -out = truncateCodePoint( 'अनुच्छेद', 7 ); +out = truncateCodePoints( 'अनुच्छेद', 7 ); // returns 'अनुच...' ``` diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-point/benchmark/benchmark.js b/lib/node_modules/@stdlib/string/base/truncate-code-points/benchmark/benchmark.js similarity index 100% rename from lib/node_modules/@stdlib/string/base/truncate-code-point/benchmark/benchmark.js rename to lib/node_modules/@stdlib/string/base/truncate-code-points/benchmark/benchmark.js diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-point/docs/repl.txt b/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/repl.txt similarity index 100% rename from lib/node_modules/@stdlib/string/base/truncate-code-point/docs/repl.txt rename to lib/node_modules/@stdlib/string/base/truncate-code-points/docs/repl.txt diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-point/docs/types/index.d.ts b/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/types/index.d.ts similarity index 100% rename from lib/node_modules/@stdlib/string/base/truncate-code-point/docs/types/index.d.ts rename to lib/node_modules/@stdlib/string/base/truncate-code-points/docs/types/index.d.ts diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-point/docs/types/test.ts b/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/types/test.ts similarity index 100% rename from lib/node_modules/@stdlib/string/base/truncate-code-point/docs/types/test.ts rename to lib/node_modules/@stdlib/string/base/truncate-code-points/docs/types/test.ts diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-point/examples/index.js b/lib/node_modules/@stdlib/string/base/truncate-code-points/examples/index.js similarity index 100% rename from lib/node_modules/@stdlib/string/base/truncate-code-point/examples/index.js rename to lib/node_modules/@stdlib/string/base/truncate-code-points/examples/index.js diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-point/lib/index.js b/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/index.js similarity index 94% rename from lib/node_modules/@stdlib/string/base/truncate-code-point/lib/index.js rename to lib/node_modules/@stdlib/string/base/truncate-code-points/lib/index.js index 1e899a3d7ad4..731ba2b005e4 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-point/lib/index.js +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/index.js @@ -21,10 +21,10 @@ /** * Truncate code points of a string to a specified length. * -* @module @stdlib/string/base/truncate-code-point +* @module @stdlib/string/base/truncate-code-points * * @example -* var truncate = require( '@stdlib/string/base/truncate-code-point' ); +* var truncate = require( '@stdlib/string/base/truncate-code-points' ); * * var out = truncate( 'beep boop', 7 ); * // returns 'beep...' diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-point/lib/main.js b/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/main.js similarity index 100% rename from lib/node_modules/@stdlib/string/base/truncate-code-point/lib/main.js rename to lib/node_modules/@stdlib/string/base/truncate-code-points/lib/main.js diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-point/package.json b/lib/node_modules/@stdlib/string/base/truncate-code-points/package.json similarity index 95% rename from lib/node_modules/@stdlib/string/base/truncate-code-point/package.json rename to lib/node_modules/@stdlib/string/base/truncate-code-points/package.json index 2ab3fd4ec3cc..c9cb5a22274d 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-point/package.json +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/package.json @@ -1,5 +1,5 @@ { - "name": "@stdlib/string/base/truncate-code-point", + "name": "@stdlib/string/base/truncate-code-points", "version": "0.0.0", "description": "Truncate code points of a string to a specified length.", "license": "Apache-2.0", diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-point/test/test.js b/lib/node_modules/@stdlib/string/base/truncate-code-points/test/test.js similarity index 100% rename from lib/node_modules/@stdlib/string/base/truncate-code-point/test/test.js rename to lib/node_modules/@stdlib/string/base/truncate-code-points/test/test.js diff --git a/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/README.md b/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/README.md similarity index 75% rename from lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/README.md rename to lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/README.md index 4be520032385..b0e8be605593 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/README.md +++ b/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/README.md @@ -18,7 +18,7 @@ limitations under the License. --> -# truncateGraphemeCluster +# truncateGraphemeClusters > Truncate grapheme clusters of a string to a specified length. @@ -27,25 +27,25 @@ limitations under the License. ## Usage ```javascript -var truncateGraphemeCluster = require( '@stdlib/string/base/truncate-grapheme-cluster' ); +var truncateGraphemeClusters = require( '@stdlib/string/base/truncate-grapheme-clusters' ); ``` -#### truncateGraphemeCluster( str, len\[, ending] ) +#### truncateGraphemeClusters( str, len\[, ending] ) Truncates grapheme clusters of a string to a specified length. ```javascript -var out = truncateGraphemeCluster( 'beep boop', 7 ); +var out = truncateGraphemeClusters( 'beep boop', 7 ); // returns 'beep...' ``` By default, the truncated string is appended with `'...'`. To customize the truncated string, provide an `ending` argument: ```javascript -var out = truncateGraphemeCluster( 'beep boop', 7, '!' ); +var out = truncateGraphemeClusters( 'beep boop', 7, '!' ); // returns 'beep b!' -out = truncateGraphemeCluster( 'beep boop', 7, '!!!' ); +out = truncateGraphemeClusters( 'beep boop', 7, '!!!' ); // returns 'beep!!!' ``` @@ -63,21 +63,21 @@ out = truncateGraphemeCluster( 'beep boop', 7, '!!!' ); var truncate = require( '@stdlib/string/truncate' ); var str = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; -var out = truncateGraphemeCluster( str, 14 ); +var out = truncateGraphemeClusters( str, 14 ); // returns 'Lorem ipsum...' str = 'To be or not to be, that is the question'; -out = truncateGraphemeCluster( str, 19, '!' ); +out = truncateGraphemeClusters( str, 19, '!' ); // returns 'To be or not to be!' str = 'The quick fox jumps over the lazy dog.'; -out = truncateGraphemeCluster( str, 16, '...' ); +out = truncateGraphemeClusters( str, 16, '...' ); // returns 'The quick fox...' -out = truncateGraphemeCluster( 'अनुच्छेद', 4 ); +out = truncateGraphemeClusters( 'अनुच्छेद', 4 ); // returns 'अ...' -out = truncateGraphemeCluster( '🌷🌷🌷🌷🌷', 4 ); +out = truncateGraphemeClusters( '🌷🌷🌷🌷🌷', 4 ); // returns '🌷...' ``` diff --git a/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/benchmark/benchmark.js b/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/benchmark/benchmark.js similarity index 100% rename from lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/benchmark/benchmark.js rename to lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/benchmark/benchmark.js diff --git a/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/docs/repl.txt b/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/docs/repl.txt similarity index 100% rename from lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/docs/repl.txt rename to lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/docs/repl.txt diff --git a/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/docs/types/index.d.ts b/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/docs/types/index.d.ts similarity index 100% rename from lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/docs/types/index.d.ts rename to lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/docs/types/index.d.ts diff --git a/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/docs/types/test.ts b/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/docs/types/test.ts similarity index 100% rename from lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/docs/types/test.ts rename to lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/docs/types/test.ts diff --git a/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/examples/index.js b/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/examples/index.js similarity index 100% rename from lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/examples/index.js rename to lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/examples/index.js diff --git a/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/lib/index.js b/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/lib/index.js similarity index 93% rename from lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/lib/index.js rename to lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/lib/index.js index e249fef30e2f..c7b1bbb5afcc 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/lib/index.js +++ b/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/lib/index.js @@ -21,10 +21,10 @@ /** * Truncate grapheme clusters of a string to a specified length. * -* @module @stdlib/string/base/truncate-grapheme-cluster +* @module @stdlib/string/base/truncate-grapheme-clusters * * @example -* var truncate = require( '@stdlib/string/base/truncate-grapheme-cluster' ); +* var truncate = require( '@stdlib/string/base/truncate-grapheme-clusters' ); * * var out = truncate( 'beep boop', 7 ); * // returns 'beep...' diff --git a/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/lib/main.js b/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/lib/main.js similarity index 100% rename from lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/lib/main.js rename to lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/lib/main.js diff --git a/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/package.json b/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/package.json similarity index 95% rename from lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/package.json rename to lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/package.json index a4db1dc3db95..528c42f65e79 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/package.json +++ b/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/package.json @@ -1,5 +1,5 @@ { - "name": "@stdlib/string/base/truncate-grapheme-cluster", + "name": "@stdlib/string/base/truncate-grapheme-clusters", "version": "0.0.0", "description": "Truncate grapheme clusters of a string to a specified length.", "license": "Apache-2.0", diff --git a/lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/test/test.js b/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/test/test.js similarity index 100% rename from lib/node_modules/@stdlib/string/base/truncate-grapheme-cluster/test/test.js rename to lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/test/test.js diff --git a/lib/node_modules/@stdlib/string/truncate/lib/main.js b/lib/node_modules/@stdlib/string/truncate/lib/main.js index 26cbc74231b6..be775969c5b3 100644 --- a/lib/node_modules/@stdlib/string/truncate/lib/main.js +++ b/lib/node_modules/@stdlib/string/truncate/lib/main.js @@ -25,8 +25,8 @@ var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).is var hasOwnProp = require( '@stdlib/assert/has-own-property' ); var isPlainObject = require( '@stdlib/assert/is-plain-object' ); var contains = require( '@stdlib/array/base/assert/contains' ).factory; -var truncateGraphemeCluster = require( '@stdlib/string/base/truncate-grapheme-cluster' ); -var truncateCodePoint = require( '@stdlib/string/base/truncate-code-point' ); +var truncateGraphemeCluster = require( '@stdlib/string/base/truncate-grapheme-clusters' ); +var truncateCodePoint = require( '@stdlib/string/base/truncate-code-points' ); var truncateCodeUnit = require( '@stdlib/string/base/truncate' ); var format = require( '@stdlib/string/format' ); From 9a428dc5dff64952454022d199cd1043e87458d8 Mon Sep 17 00:00:00 2001 From: Stephannie Jimenez Date: Tue, 7 Nov 2023 18:33:49 -0500 Subject: [PATCH 03/18] docs: fix readme import --- .../@stdlib/string/base/truncate-code-points/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-points/README.md b/lib/node_modules/@stdlib/string/base/truncate-code-points/README.md index 970e544beb77..c86762c1999f 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-points/README.md +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/README.md @@ -60,7 +60,7 @@ out = truncateCodePoints( 'beep boop', 7, '!!!' ); ```javascript -var truncate = require( '@stdlib/string/truncate' ); +var truncateCodePoints = require( '@stdlib/string/base/truncate-code-points' ); var str = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; var out = truncateCodePoints( str, 14 ); From e306508a3416e30c5bde7b6cb887bab26383e189 Mon Sep 17 00:00:00 2001 From: Stephannie Jimenez Date: Tue, 7 Nov 2023 18:40:23 -0500 Subject: [PATCH 04/18] docs: fix readme example import --- .../@stdlib/string/base/truncate-grapheme-clusters/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/README.md b/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/README.md index b0e8be605593..fe0782f4d440 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/README.md +++ b/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/README.md @@ -60,7 +60,7 @@ out = truncateGraphemeClusters( 'beep boop', 7, '!!!' ); ```javascript -var truncate = require( '@stdlib/string/truncate' ); +var truncateGraphemeClusters = require( '@stdlib/string/base/truncate-grapheme-clusters' ); var str = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; var out = truncateGraphemeClusters( str, 14 ); From 31cb8441171b83a32e73abbd420f0f702c670341 Mon Sep 17 00:00:00 2001 From: Stephannie Jimenez Date: Tue, 7 Nov 2023 18:53:17 -0500 Subject: [PATCH 05/18] docs: add missing import in readme example --- lib/node_modules/@stdlib/string/base/truncate/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/node_modules/@stdlib/string/base/truncate/README.md b/lib/node_modules/@stdlib/string/base/truncate/README.md index f8b9078f040f..2d23c50cfafa 100644 --- a/lib/node_modules/@stdlib/string/base/truncate/README.md +++ b/lib/node_modules/@stdlib/string/base/truncate/README.md @@ -60,6 +60,8 @@ out = truncate( 'beep boop', 7, '!!!' ); ```javascript +var truncate = require( '@stdlib/string/base/truncate' ); + var str = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; var out = truncate( str, 14 ); // returns 'Lorem ipsum...' From dbc41cc02a33197d78b9f76fc8ed2e18f7cf47d5 Mon Sep 17 00:00:00 2001 From: Stephannie Jimenez Date: Fri, 10 Nov 2023 10:50:22 -0500 Subject: [PATCH 06/18] docs: update truncate-code-points description --- .../@stdlib/string/base/truncate-code-points/README.md | 4 ++-- .../@stdlib/string/base/truncate-code-points/docs/repl.txt | 3 ++- .../string/base/truncate-code-points/docs/types/index.d.ts | 2 +- .../@stdlib/string/base/truncate-code-points/lib/index.js | 2 +- .../@stdlib/string/base/truncate-code-points/lib/main.js | 2 +- .../@stdlib/string/base/truncate-code-points/package.json | 2 +- 6 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-points/README.md b/lib/node_modules/@stdlib/string/base/truncate-code-points/README.md index c86762c1999f..6e52d9cda664 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-points/README.md +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/README.md @@ -20,7 +20,7 @@ limitations under the License. # truncateCodePoints -> Truncate code points of a string to a specified length. +> Truncate the code points of a provided string in order to return a string having a specified length.
@@ -32,7 +32,7 @@ var truncateCodePoints = require( '@stdlib/string/base/truncate-code-points' ); #### truncateCodePoints( str, len\[, ending] ) -Truncates code points of a string to a specified length. +Truncates the code points of a provided string in order to return a string having a specified length. ```javascript var out = truncateCodePoints( 'beep boop', 7 ); diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/repl.txt b/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/repl.txt index 3901fd76e3e9..159d2ae31e47 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/repl.txt +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/repl.txt @@ -1,6 +1,7 @@ {{alias}}( str, len[, ending] ) - Truncate code points of a string to a specified length. + Truncate the code points of a provided string in order to return a string + having a specified length. Parameters ---------- diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/types/index.d.ts b/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/types/index.d.ts index c685e6e856bf..30f241a87501 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/types/index.d.ts @@ -19,7 +19,7 @@ // TypeScript Version: 2.0 /** -* Truncate code points of a string to a specified length. +* Truncate the code points of a provided string in order to return a string having a specified length. * * @param str - input string * @param len - output string length (including ending) diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/index.js b/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/index.js index 731ba2b005e4..026ec27349c3 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/index.js +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Truncate code points of a string to a specified length. +* Truncate the code points of a provided string in order to return a string having a specified length. * * @module @stdlib/string/base/truncate-code-points * diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/main.js b/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/main.js index 211e7b8c36cc..97d614fb0698 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/main.js +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/main.js @@ -32,7 +32,7 @@ var RE_UTF16_HIGH_SURROGATE = /[\uD800-\uDBFF]/; // TODO: replace with stdlib pk // MAIN // /** -* Truncates code point of a string to a specified length. +* Truncates the code points of a provided string in order to return a string having a specified length. * * @param {string} str - input string * @param {NonNegativeInteger} len - output string length (including ending) diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-points/package.json b/lib/node_modules/@stdlib/string/base/truncate-code-points/package.json index c9cb5a22274d..66ff10fe326f 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-points/package.json +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/string/base/truncate-code-points", "version": "0.0.0", - "description": "Truncate code points of a string to a specified length.", + "description": "Truncate the code points of a provided string in order to return a string having a specified length.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", From ed5c70e6ceb044b9643e78708883cead4363d483 Mon Sep 17 00:00:00 2001 From: Stephannie Jimenez Date: Fri, 10 Nov 2023 11:09:23 -0500 Subject: [PATCH 07/18] fix: remove variadic interfaces in base truncate packages --- .../base/truncate-code-points/README.md | 8 ++--- .../benchmark/benchmark.js | 2 +- .../base/truncate-code-points/docs/repl.txt | 8 ++--- .../docs/types/index.d.ts | 6 ++-- .../truncate-code-points/docs/types/test.ts | 31 +++++++++--------- .../truncate-code-points/examples/index.js | 2 +- .../base/truncate-code-points/lib/index.js | 2 +- .../base/truncate-code-points/lib/main.js | 13 +++----- .../base/truncate-code-points/test/test.js | 16 +++++----- .../base/truncate-grapheme-clusters/README.md | 10 +++--- .../benchmark/benchmark.js | 2 +- .../truncate-grapheme-clusters/docs/repl.txt | 8 ++--- .../docs/types/index.d.ts | 6 ++-- .../docs/types/test.ts | 31 +++++++++--------- .../examples/index.js | 2 +- .../truncate-grapheme-clusters/lib/index.js | 2 +- .../truncate-grapheme-clusters/lib/main.js | 13 +++----- .../truncate-grapheme-clusters/test/test.js | 14 ++++---- .../@stdlib/string/base/truncate/README.md | 6 ++-- .../base/truncate/benchmark/benchmark.js | 2 +- .../string/base/truncate/docs/repl.txt | 8 ++--- .../base/truncate/docs/types/index.d.ts | 6 ++-- .../string/base/truncate/docs/types/test.ts | 32 +++++++++---------- .../string/base/truncate/examples/index.js | 2 +- .../@stdlib/string/base/truncate/lib/index.js | 2 +- .../@stdlib/string/base/truncate/lib/main.js | 11 +++---- .../@stdlib/string/base/truncate/test/test.js | 8 ++--- 27 files changed, 122 insertions(+), 131 deletions(-) diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-points/README.md b/lib/node_modules/@stdlib/string/base/truncate-code-points/README.md index 6e52d9cda664..516ad319178a 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-points/README.md +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/README.md @@ -30,12 +30,12 @@ limitations under the License. var truncateCodePoints = require( '@stdlib/string/base/truncate-code-points' ); ``` -#### truncateCodePoints( str, len\[, ending] ) +#### truncateCodePoints( str, len, ending ) Truncates the code points of a provided string in order to return a string having a specified length. ```javascript -var out = truncateCodePoints( 'beep boop', 7 ); +var out = truncateCodePoints( 'beep boop', 7, '...' ); // returns 'beep...' ``` @@ -63,7 +63,7 @@ out = truncateCodePoints( 'beep boop', 7, '!!!' ); var truncateCodePoints = require( '@stdlib/string/base/truncate-code-points' ); var str = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; -var out = truncateCodePoints( str, 14 ); +var out = truncateCodePoints( str, 14, '...' ); // returns 'Lorem ipsum...' str = 'To be or not to be, that is the question'; @@ -74,7 +74,7 @@ str = 'The quick fox jumps over the lazy dog.'; out = truncateCodePoints( str, 16, '...' ); // returns 'The quick fox...' -out = truncateCodePoints( 'अनुच्छेद', 7 ); +out = truncateCodePoints( 'अनुच्छेद', 7, '...' ); // returns 'अनुच...' ``` diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-points/benchmark/benchmark.js b/lib/node_modules/@stdlib/string/base/truncate-code-points/benchmark/benchmark.js index d44f1e4f845b..153966ae4f62 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-points/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/benchmark/benchmark.js @@ -42,7 +42,7 @@ bench( pkg, function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - out = truncate( values[ i%values.length ], 1 ); + out = truncate( values[ i%values.length ], 1, '...' ); if ( typeof out !== 'string' ) { b.fail( 'should return a string' ); } diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/repl.txt b/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/repl.txt index 159d2ae31e47..02517e1b4c49 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/repl.txt +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/repl.txt @@ -1,5 +1,5 @@ -{{alias}}( str, len[, ending] ) +{{alias}}( str, len, ending ) Truncate the code points of a provided string in order to return a string having a specified length. @@ -11,8 +11,8 @@ len: integer Output string length. - ending: string (optional) - Custom ending. Default: '...'. + ending: string + Custom ending. Returns ------- @@ -22,7 +22,7 @@ Examples -------- > var str = 'beep boop'; - > var out = {{alias}}( str, 5 ) + > var out = {{alias}}( str, 5, '...' ) 'be...' > out = {{alias}}( str, 5, '|' ) diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/types/index.d.ts b/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/types/index.d.ts index 30f241a87501..384b4acbd67a 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/types/index.d.ts @@ -23,18 +23,18 @@ * * @param str - input string * @param len - output string length (including ending) -* @param ending - custom ending (default: `...`) +* @param ending - custom ending * @returns truncated string * * @example -* var out = truncate( 'beep boop', 7 ); +* var out = truncate( 'beep boop', 7, '...' ); * // returns 'beep...' * * @example * var out = truncate( 'beep boop', 7, '|' ); * // returns 'beep b|' */ -declare function truncate( str: string, len: number, ending?: string ): string; +declare function truncate( str: string, len: number, ending: string ): string; // EXPORTS // diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/types/test.ts b/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/types/test.ts index ae2ff2f94f8e..9028fe5e9e6f 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/types/test.ts +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/types/test.ts @@ -23,31 +23,30 @@ import truncate = require( './index' ); // The function returns a string... { - truncate( 'abc', 1 ); // $ExpectType string truncate( 'abcdefghi', 10, '|' ); // $ExpectType string } // The compiler throws an error if the function is provided a value other than a string as its first argument... { - truncate( true, 1 ); // $ExpectError - truncate( false, 1 ); // $ExpectError - truncate( null, 1 ); // $ExpectError - truncate( undefined, 1 ); // $ExpectError - truncate( 5, 1 ); // $ExpectError - truncate( [], 1 ); // $ExpectError - truncate( {}, 1 ); // $ExpectError - truncate( ( x: number ): number => x, 1 ); // $ExpectError + truncate( true, 1, '...' ); // $ExpectError + truncate( false, 1, '...' ); // $ExpectError + truncate( null, 1, '...' ); // $ExpectError + truncate( undefined, 1, '...' ); // $ExpectError + truncate( 5, 1, '...' ); // $ExpectError + truncate( [], 1, '...' ); // $ExpectError + truncate( {}, 1, '...' ); // $ExpectError + truncate( ( x: number ): number => x, 1, '...' ); // $ExpectError } // The compiler throws an error if the function is provided a second argument that is not a number... { - truncate( 'abc', true ); // $ExpectError - truncate( 'abc', false ); // $ExpectError - truncate( 'abc', null ); // $ExpectError - truncate( 'abc', 'abc' ); // $ExpectError - truncate( 'abc', [] ); // $ExpectError - truncate( 'abc', {} ); // $ExpectError - truncate( 'abc', ( x: number ): number => x ); // $ExpectError + truncate( 'abc', true, '...' ); // $ExpectError + truncate( 'abc', false, '...' ); // $ExpectError + truncate( 'abc', null, '...' ); // $ExpectError + truncate( 'abc', 'abc', '...' ); // $ExpectError + truncate( 'abc', [], '...' ); // $ExpectError + truncate( 'abc', {}, '...' ); // $ExpectError + truncate( 'abc', ( x: number ): number => x, '...' ); // $ExpectError } // The compiler throws an error if the function is provided a third argument that is not a string... diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-points/examples/index.js b/lib/node_modules/@stdlib/string/base/truncate-code-points/examples/index.js index 9486ed3a1090..50076dc4a4fd 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-points/examples/index.js +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/examples/index.js @@ -21,7 +21,7 @@ var truncate = require( './../lib' ); var str = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; -var out = truncate( str, 14 ); +var out = truncate( str, 14, '...' ); console.log( out ); // => 'Lorem ipsum...' diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/index.js b/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/index.js index 026ec27349c3..54bec73604b0 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/index.js +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/index.js @@ -26,7 +26,7 @@ * @example * var truncate = require( '@stdlib/string/base/truncate-code-points' ); * -* var out = truncate( 'beep boop', 7 ); +* var out = truncate( 'beep boop', 7, '...' ); * // returns 'beep...' * * out = truncate( 'beep boop', 7, '|' ); diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/main.js b/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/main.js index 97d614fb0698..c27c2a91cecd 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/main.js +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/main.js @@ -36,12 +36,12 @@ var RE_UTF16_HIGH_SURROGATE = /[\uD800-\uDBFF]/; // TODO: replace with stdlib pk * * @param {string} str - input string * @param {NonNegativeInteger} len - output string length (including ending) -* @param {string} [ending='...'] - custom ending +* @param {string} ending - custom ending * @returns {string} truncated string * * @example * var str = 'beep boop'; -* var out = truncate( str, 7 ); +* var out = truncate( str, 7, '...' ); * // returns 'beep...' * * @example @@ -51,17 +51,17 @@ var RE_UTF16_HIGH_SURROGATE = /[\uD800-\uDBFF]/; // TODO: replace with stdlib pk * * @example * var str = 'beep boop'; -* var out = truncate( str, 10 ); +* var out = truncate( str, 10, '...' ); * // returns 'beep boop' * * @example * var str = 'beep boop'; -* var out = truncate( str, 0 ); +* var out = truncate( str, 0, '...' ); * // returns '' * * @example * var str = 'beep boop'; -* var out = truncate( str, 2 ); +* var out = truncate( str, 2, '...' ); * // returns '..' */ function truncate( str, len, ending ) { @@ -72,9 +72,6 @@ function truncate( str, len, ending ) { var out; var i; - if ( typeof ending === 'undefined' ) { - ending = '...'; - } if ( len <= 0 ) { return ''; } diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-points/test/test.js b/lib/node_modules/@stdlib/string/base/truncate-code-points/test/test.js index d053b2a4fb1f..eeb9bd58abb4 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-points/test/test.js +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/test/test.js @@ -41,49 +41,49 @@ tape( 'the function truncates a string to the specified length', function test( str = 'beep boop'; len = 5; expected = 'be...'; - actual = truncate( str, len ); + actual = truncate( str, len, '...' ); t.strictEqual( actual, expected, 'returns expected value' ); str = 'beep boop'; len = 10; expected = 'beep boop'; - actual = truncate( str, len ); + actual = truncate( str, len, '...' ); t.strictEqual( actual, expected, 'returns expected value' ); str = 'beep boop'; len = 0; expected = ''; - actual = truncate( str, len ); + actual = truncate( str, len, '...' ); t.strictEqual( actual, expected, 'returns expected value' ); str = 'beep boop'; len = 1; expected = '.'; - actual = truncate( str, len ); + actual = truncate( str, len, '...' ); t.strictEqual( actual, expected, 'returns expected value' ); str = 'अनुच्छेद'; len = 7; expected = 'अनुच...'; - actual = truncate( str, len ); + actual = truncate( str, len, '...' ); t.strictEqual( actual, expected, 'returns expected value' ); str = '六书/六書'; len = 4; expected = '六...'; - actual = truncate( str, len ); + actual = truncate( str, len, '...' ); t.strictEqual( actual, expected, 'returns expected value' ); str = '𐒻𐓟𐒻𐓟𐒻𐓟𐒻𐓟𐒻𐓟'; len = 5; expected = '𐒻...'; - actual = truncate( str, len ); + actual = truncate( str, len, '...' ); t.strictEqual( actual, expected, 'returns expected value' ); str = '\uD800𐓟𐒻𐓟𐒻𐓟𐒻𐓟𐒻𐓟'; len = 4; expected = '...'; - actual = truncate( str, len ); + actual = truncate( str, len, '...' ); t.strictEqual( actual, expected, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/README.md b/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/README.md index fe0782f4d440..27b9164fda75 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/README.md +++ b/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/README.md @@ -30,12 +30,12 @@ limitations under the License. var truncateGraphemeClusters = require( '@stdlib/string/base/truncate-grapheme-clusters' ); ``` -#### truncateGraphemeClusters( str, len\[, ending] ) +#### truncateGraphemeClusters( str, len, ending ) Truncates grapheme clusters of a string to a specified length. ```javascript -var out = truncateGraphemeClusters( 'beep boop', 7 ); +var out = truncateGraphemeClusters( 'beep boop', 7, '...' ); // returns 'beep...' ``` @@ -63,7 +63,7 @@ out = truncateGraphemeClusters( 'beep boop', 7, '!!!' ); var truncateGraphemeClusters = require( '@stdlib/string/base/truncate-grapheme-clusters' ); var str = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; -var out = truncateGraphemeClusters( str, 14 ); +var out = truncateGraphemeClusters( str, 14, '...' ); // returns 'Lorem ipsum...' str = 'To be or not to be, that is the question'; @@ -74,10 +74,10 @@ str = 'The quick fox jumps over the lazy dog.'; out = truncateGraphemeClusters( str, 16, '...' ); // returns 'The quick fox...' -out = truncateGraphemeClusters( 'अनुच्छेद', 4 ); +out = truncateGraphemeClusters( 'अनुच्छेद', 4, '...' ); // returns 'अ...' -out = truncateGraphemeClusters( '🌷🌷🌷🌷🌷', 4 ); +out = truncateGraphemeClusters( '🌷🌷🌷🌷🌷', 4, '...' ); // returns '🌷...' ``` diff --git a/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/benchmark/benchmark.js b/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/benchmark/benchmark.js index d44f1e4f845b..153966ae4f62 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/benchmark/benchmark.js @@ -42,7 +42,7 @@ bench( pkg, function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - out = truncate( values[ i%values.length ], 1 ); + out = truncate( values[ i%values.length ], 1, '...' ); if ( typeof out !== 'string' ) { b.fail( 'should return a string' ); } diff --git a/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/docs/repl.txt b/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/docs/repl.txt index 82ee003417af..c10fc96a4bf2 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/docs/repl.txt +++ b/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/docs/repl.txt @@ -1,5 +1,5 @@ -{{alias}}( str, len[, ending] ) +{{alias}}( str, len, ending ) Truncate grapheme clusters of a string to a specified length. Parameters @@ -10,8 +10,8 @@ len: integer Output string length. - ending: string (optional) - Custom ending. Default: '...'. + ending: string + Custom ending. Returns ------- @@ -21,7 +21,7 @@ Examples -------- > var str = 'beep boop'; - > var out = {{alias}}( str, 5 ) + > var out = {{alias}}( str, 5, '...' ) 'be...' > out = {{alias}}( str, 5, '|' ) diff --git a/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/docs/types/index.d.ts b/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/docs/types/index.d.ts index 1cbd0e75d775..06475d8df82b 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/docs/types/index.d.ts @@ -23,18 +23,18 @@ * * @param str - input string * @param len - output string length (including ending) -* @param ending - custom ending (default: `...`) +* @param ending - ending * @returns truncated string * * @example -* var out = truncate( 'beep boop', 7 ); +* var out = truncate( 'beep boop', 7, '...' ); * // returns 'beep...' * * @example * var out = truncate( 'beep boop', 7, '|' ); * // returns 'beep b|' */ -declare function truncate( str: string, len: number, ending?: string ): string; +declare function truncate( str: string, len: number, ending: string ): string; // EXPORTS // diff --git a/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/docs/types/test.ts b/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/docs/types/test.ts index ae2ff2f94f8e..9028fe5e9e6f 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/docs/types/test.ts +++ b/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/docs/types/test.ts @@ -23,31 +23,30 @@ import truncate = require( './index' ); // The function returns a string... { - truncate( 'abc', 1 ); // $ExpectType string truncate( 'abcdefghi', 10, '|' ); // $ExpectType string } // The compiler throws an error if the function is provided a value other than a string as its first argument... { - truncate( true, 1 ); // $ExpectError - truncate( false, 1 ); // $ExpectError - truncate( null, 1 ); // $ExpectError - truncate( undefined, 1 ); // $ExpectError - truncate( 5, 1 ); // $ExpectError - truncate( [], 1 ); // $ExpectError - truncate( {}, 1 ); // $ExpectError - truncate( ( x: number ): number => x, 1 ); // $ExpectError + truncate( true, 1, '...' ); // $ExpectError + truncate( false, 1, '...' ); // $ExpectError + truncate( null, 1, '...' ); // $ExpectError + truncate( undefined, 1, '...' ); // $ExpectError + truncate( 5, 1, '...' ); // $ExpectError + truncate( [], 1, '...' ); // $ExpectError + truncate( {}, 1, '...' ); // $ExpectError + truncate( ( x: number ): number => x, 1, '...' ); // $ExpectError } // The compiler throws an error if the function is provided a second argument that is not a number... { - truncate( 'abc', true ); // $ExpectError - truncate( 'abc', false ); // $ExpectError - truncate( 'abc', null ); // $ExpectError - truncate( 'abc', 'abc' ); // $ExpectError - truncate( 'abc', [] ); // $ExpectError - truncate( 'abc', {} ); // $ExpectError - truncate( 'abc', ( x: number ): number => x ); // $ExpectError + truncate( 'abc', true, '...' ); // $ExpectError + truncate( 'abc', false, '...' ); // $ExpectError + truncate( 'abc', null, '...' ); // $ExpectError + truncate( 'abc', 'abc', '...' ); // $ExpectError + truncate( 'abc', [], '...' ); // $ExpectError + truncate( 'abc', {}, '...' ); // $ExpectError + truncate( 'abc', ( x: number ): number => x, '...' ); // $ExpectError } // The compiler throws an error if the function is provided a third argument that is not a string... diff --git a/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/examples/index.js b/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/examples/index.js index ab746954b4d6..dfd803b7ca1f 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/examples/index.js +++ b/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/examples/index.js @@ -21,7 +21,7 @@ var truncate = require( './../lib' ); var str = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; -var out = truncate( str, 14 ); +var out = truncate( str, 14, '...' ); console.log( out ); // => 'Lorem ipsum...' diff --git a/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/lib/index.js b/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/lib/index.js index c7b1bbb5afcc..f1f00dbf1980 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/lib/index.js +++ b/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/lib/index.js @@ -26,7 +26,7 @@ * @example * var truncate = require( '@stdlib/string/base/truncate-grapheme-clusters' ); * -* var out = truncate( 'beep boop', 7 ); +* var out = truncate( 'beep boop', 7, '...' ); * // returns 'beep...' * * out = truncate( 'beep boop', 7, '|' ); diff --git a/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/lib/main.js b/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/lib/main.js index f136a864348b..ec4643796cc7 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/lib/main.js +++ b/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/lib/main.js @@ -31,12 +31,12 @@ var nextGraphemeClusterBreak = require( '@stdlib/string/next-grapheme-cluster-br * * @param {string} str - input string * @param {NonNegativeInteger} len - output string length (including ending) -* @param {string} [ending='...'] - custom ending +* @param {string} ending - ending string * @returns {string} truncated string * * @example * var str = 'beep boop'; -* var out = truncate( str, 7 ); +* var out = truncate( str, 7, '...' ); * // returns 'beep...' * * @example @@ -46,17 +46,17 @@ var nextGraphemeClusterBreak = require( '@stdlib/string/next-grapheme-cluster-br * * @example * var str = 'beep boop'; -* var out = truncate( str, 10 ); +* var out = truncate( str, 10, '...' ); * // returns 'beep boop' * * @example * var str = 'beep boop'; -* var out = truncate( str, 0 ); +* var out = truncate( str, 0, '...' ); * // returns '' * * @example * var str = 'beep boop'; -* var out = truncate( str, 2 ); +* var out = truncate( str, 2, '...' ); * // returns '..' */ function truncate( str, len, ending ) { @@ -65,9 +65,6 @@ function truncate( str, len, ending ) { var n; var i; - if ( typeof ending === 'undefined' ) { - ending = '...'; - } if ( len <= 0 ) { return ''; } diff --git a/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/test/test.js b/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/test/test.js index 47348a781c33..59a84a6cb110 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/test/test.js +++ b/lib/node_modules/@stdlib/string/base/truncate-grapheme-clusters/test/test.js @@ -41,43 +41,43 @@ tape( 'the function truncates a string to the specified length', function test( str = 'beep boop'; len = 5; expected = 'be...'; - actual = truncate( str, len ); + actual = truncate( str, len, '...' ); t.strictEqual( actual, expected, 'returns expected value' ); str = 'beep boop'; len = 10; expected = 'beep boop'; - actual = truncate( str, len ); + actual = truncate( str, len, '...' ); t.strictEqual( actual, expected, 'returns expected value' ); str = 'beep boop'; len = 0; expected = ''; - actual = truncate( str, len ); + actual = truncate( str, len, '...' ); t.strictEqual( actual, expected, 'returns expected value' ); str = 'beep boop'; len = 1; expected = '.'; - actual = truncate( str, len ); + actual = truncate( str, len, '...' ); t.strictEqual( actual, expected, 'returns expected value' ); str = 'अनुच्छेद'; len = 4; expected = 'अ...'; - actual = truncate( str, len ); + actual = truncate( str, len, '...' ); t.strictEqual( actual, expected, 'returns expected value' ); str = '六书/六書'; len = 4; expected = '六...'; - actual = truncate( str, len ); + actual = truncate( str, len, '...' ); t.strictEqual( actual, expected, 'returns expected value' ); str = '🐶🐮🐷🐰🐸🐸'; len = 5; expected = '🐶🐮...'; - actual = truncate( str, len ); + actual = truncate( str, len, '...' ); t.strictEqual( actual, expected, 'returns expected value' ); t.end(); diff --git a/lib/node_modules/@stdlib/string/base/truncate/README.md b/lib/node_modules/@stdlib/string/base/truncate/README.md index 2d23c50cfafa..e333022a31a4 100644 --- a/lib/node_modules/@stdlib/string/base/truncate/README.md +++ b/lib/node_modules/@stdlib/string/base/truncate/README.md @@ -30,12 +30,12 @@ limitations under the License. var truncate = require( '@stdlib/string/base/truncate' ); ``` -#### truncate( str, len\[, ending] ) +#### truncate( str, len, ending ) Truncates UTF-16 code units of a string to a specified length. ```javascript -var out = truncate( 'beep boop', 7 ); +var out = truncate( 'beep boop', 7, '...' ); // returns 'beep...' ``` @@ -63,7 +63,7 @@ out = truncate( 'beep boop', 7, '!!!' ); var truncate = require( '@stdlib/string/base/truncate' ); var str = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; -var out = truncate( str, 14 ); +var out = truncate( str, 14, '...' ); // returns 'Lorem ipsum...' str = 'To be or not to be, that is the question'; diff --git a/lib/node_modules/@stdlib/string/base/truncate/benchmark/benchmark.js b/lib/node_modules/@stdlib/string/base/truncate/benchmark/benchmark.js index d44f1e4f845b..153966ae4f62 100644 --- a/lib/node_modules/@stdlib/string/base/truncate/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/string/base/truncate/benchmark/benchmark.js @@ -42,7 +42,7 @@ bench( pkg, function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - out = truncate( values[ i%values.length ], 1 ); + out = truncate( values[ i%values.length ], 1, '...' ); if ( typeof out !== 'string' ) { b.fail( 'should return a string' ); } diff --git a/lib/node_modules/@stdlib/string/base/truncate/docs/repl.txt b/lib/node_modules/@stdlib/string/base/truncate/docs/repl.txt index ee842a5fcb0b..b72a44d800e3 100644 --- a/lib/node_modules/@stdlib/string/base/truncate/docs/repl.txt +++ b/lib/node_modules/@stdlib/string/base/truncate/docs/repl.txt @@ -1,5 +1,5 @@ -{{alias}}( str, len[, ending] ) +{{alias}}( str, len, ending ) Truncate UTF-16 code units of a string to a specified length. Parameters @@ -10,8 +10,8 @@ len: integer Output string length. - ending: string (optional) - Custom ending. Default: '...'. + ending: string + Custom ending. Returns ------- @@ -21,7 +21,7 @@ Examples -------- > var str = 'beep boop'; - > var out = {{alias}}( str, 5 ) + > var out = {{alias}}( str, 5, '...' ) 'be...' > out = {{alias}}( str, 5, '|' ) diff --git a/lib/node_modules/@stdlib/string/base/truncate/docs/types/index.d.ts b/lib/node_modules/@stdlib/string/base/truncate/docs/types/index.d.ts index a0ce02e1e8e6..5eb9072643dd 100644 --- a/lib/node_modules/@stdlib/string/base/truncate/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/string/base/truncate/docs/types/index.d.ts @@ -23,18 +23,18 @@ * * @param str - input string * @param len - output string length (including ending) -* @param ending - custom ending (default: `...`) +* @param ending - ending string * @returns truncated string * * @example -* var out = truncate( 'beep boop', 7 ); +* var out = truncate( 'beep boop', 7, '...' ); * // returns 'beep...' * * @example * var out = truncate( 'beep boop', 7, '|' ); * // returns 'beep b|' */ -declare function truncate( str: string, len: number, ending?: string ): string; +declare function truncate( str: string, len: number, ending: string ): string; // EXPORTS // diff --git a/lib/node_modules/@stdlib/string/base/truncate/docs/types/test.ts b/lib/node_modules/@stdlib/string/base/truncate/docs/types/test.ts index ae2ff2f94f8e..f86bd37ddaf8 100644 --- a/lib/node_modules/@stdlib/string/base/truncate/docs/types/test.ts +++ b/lib/node_modules/@stdlib/string/base/truncate/docs/types/test.ts @@ -23,31 +23,31 @@ import truncate = require( './index' ); // The function returns a string... { - truncate( 'abc', 1 ); // $ExpectType string + truncate( 'abc', 1, '...' ); // $ExpectType string truncate( 'abcdefghi', 10, '|' ); // $ExpectType string } // The compiler throws an error if the function is provided a value other than a string as its first argument... { - truncate( true, 1 ); // $ExpectError - truncate( false, 1 ); // $ExpectError - truncate( null, 1 ); // $ExpectError - truncate( undefined, 1 ); // $ExpectError - truncate( 5, 1 ); // $ExpectError - truncate( [], 1 ); // $ExpectError - truncate( {}, 1 ); // $ExpectError - truncate( ( x: number ): number => x, 1 ); // $ExpectError + truncate( true, 1, '...' ); // $ExpectError + truncate( false, 1, '...' ); // $ExpectError + truncate( null, 1, '...' ); // $ExpectError + truncate( undefined, 1, '...' ); // $ExpectError + truncate( 5, 1, '...' ); // $ExpectError + truncate( [], 1, '...' ); // $ExpectError + truncate( {}, 1, '...' ); // $ExpectError + truncate( ( x: number ): number => x, 1, '...' ); // $ExpectError } // The compiler throws an error if the function is provided a second argument that is not a number... { - truncate( 'abc', true ); // $ExpectError - truncate( 'abc', false ); // $ExpectError - truncate( 'abc', null ); // $ExpectError - truncate( 'abc', 'abc' ); // $ExpectError - truncate( 'abc', [] ); // $ExpectError - truncate( 'abc', {} ); // $ExpectError - truncate( 'abc', ( x: number ): number => x ); // $ExpectError + truncate( 'abc', true, '...' ); // $ExpectError + truncate( 'abc', false, '...' ); // $ExpectError + truncate( 'abc', null, '...' ); // $ExpectError + truncate( 'abc', 'abc', '...' ); // $ExpectError + truncate( 'abc', [], '...' ); // $ExpectError + truncate( 'abc', {}, '...' ); // $ExpectError + truncate( 'abc', ( x: number ): number => x, '...' ); // $ExpectError } // The compiler throws an error if the function is provided a third argument that is not a string... diff --git a/lib/node_modules/@stdlib/string/base/truncate/examples/index.js b/lib/node_modules/@stdlib/string/base/truncate/examples/index.js index 71c27cec48f0..323f68cd813e 100644 --- a/lib/node_modules/@stdlib/string/base/truncate/examples/index.js +++ b/lib/node_modules/@stdlib/string/base/truncate/examples/index.js @@ -21,7 +21,7 @@ var truncate = require( './../lib' ); var str = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'; -var out = truncate( str, 14 ); +var out = truncate( str, 14, '...' ); console.log( out ); // => 'Lorem ipsum...' diff --git a/lib/node_modules/@stdlib/string/base/truncate/lib/index.js b/lib/node_modules/@stdlib/string/base/truncate/lib/index.js index 0d7d2604298e..a590f0f08e30 100644 --- a/lib/node_modules/@stdlib/string/base/truncate/lib/index.js +++ b/lib/node_modules/@stdlib/string/base/truncate/lib/index.js @@ -26,7 +26,7 @@ * @example * var truncate = require( '@stdlib/string/base/truncate' ); * -* var out = truncate( 'beep boop', 7 ); +* var out = truncate( 'beep boop', 7, '...' ); * // returns 'beep...' * * out = truncate( 'beep boop', 7, '|' ); diff --git a/lib/node_modules/@stdlib/string/base/truncate/lib/main.js b/lib/node_modules/@stdlib/string/base/truncate/lib/main.js index 8146faa67ae1..36b960101976 100644 --- a/lib/node_modules/@stdlib/string/base/truncate/lib/main.js +++ b/lib/node_modules/@stdlib/string/base/truncate/lib/main.js @@ -25,12 +25,12 @@ * * @param {string} str - input string * @param {NonNegativeInteger} len - output string length (including ending) -* @param {string} [ending='...'] - custom ending +* @param {string} ending - custom ending * @returns {string} truncated string * * @example * var str = 'beep boop'; -* var out = truncate( str, 7 ); +* var out = truncate( str, 7, '...' ); * // returns 'beep...' * * @example @@ -40,21 +40,20 @@ * * @example * var str = 'beep boop'; -* var out = truncate( str, 10 ); +* var out = truncate( str, 10, '...' ); * // returns 'beep boop' * * @example * var str = 'beep boop'; -* var out = truncate( str, 0 ); +* var out = truncate( str, 0, '...' ); * // returns '' * * @example * var str = 'beep boop'; -* var out = truncate( str, 2 ); +* var out = truncate( str, 2, '...' ); * // returns '..' */ function truncate( str, len, ending ) { - ending = ending || '...'; if ( len >= str.length ) { return str; } diff --git a/lib/node_modules/@stdlib/string/base/truncate/test/test.js b/lib/node_modules/@stdlib/string/base/truncate/test/test.js index 9251482b4324..b089ed55a325 100644 --- a/lib/node_modules/@stdlib/string/base/truncate/test/test.js +++ b/lib/node_modules/@stdlib/string/base/truncate/test/test.js @@ -41,25 +41,25 @@ tape( 'the function truncates a string to the specified length', function test( str = 'beep boop'; len = 5; expected = 'be...'; - actual = truncate( str, len ); + actual = truncate( str, len, '...' ); t.strictEqual( actual, expected, 'returns expected value' ); str = 'beep boop'; len = 10; expected = 'beep boop'; - actual = truncate( str, len ); + actual = truncate( str, len, '...' ); t.strictEqual( actual, expected, 'returns expected value' ); str = 'beep boop'; len = 0; expected = ''; - actual = truncate( str, len ); + actual = truncate( str, len, '...' ); t.strictEqual( actual, expected, 'returns expected value' ); str = 'beep boop'; len = 1; expected = '.'; - actual = truncate( str, len ); + actual = truncate( str, len, '...' ); t.strictEqual( actual, expected, 'returns expected value' ); t.end(); From 020a67597cddd0b1d43a26b1b609b9c05086b3e7 Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 10 Nov 2023 13:22:44 -0800 Subject: [PATCH 08/18] Apply suggestions from code review --- .../@stdlib/string/base/truncate-code-points/README.md | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-points/README.md b/lib/node_modules/@stdlib/string/base/truncate-code-points/README.md index 516ad319178a..c953255661fd 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-points/README.md +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/README.md @@ -20,7 +20,7 @@ limitations under the License. # truncateCodePoints -> Truncate the code points of a provided string in order to return a string having a specified length. +> Truncate the Unicode code points of a provided string in order to return a string having a specified length.
@@ -37,11 +37,6 @@ Truncates the code points of a provided string in order to return a string havin ```javascript var out = truncateCodePoints( 'beep boop', 7, '...' ); // returns 'beep...' -``` - -By default, the truncated string is appended with `'...'`. To customize the truncated string, provide an `ending` argument: - -```javascript var out = truncateCodePoints( 'beep boop', 7, '!' ); // returns 'beep b!' From 64c2fc7a65e6002f179b1f7ee1c6ac70df3bde85 Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 10 Nov 2023 13:23:01 -0800 Subject: [PATCH 09/18] Apply suggestions from code review --- .../@stdlib/string/base/truncate-code-points/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-points/README.md b/lib/node_modules/@stdlib/string/base/truncate-code-points/README.md index c953255661fd..b8efc26862cc 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-points/README.md +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/README.md @@ -37,7 +37,8 @@ Truncates the code points of a provided string in order to return a string havin ```javascript var out = truncateCodePoints( 'beep boop', 7, '...' ); // returns 'beep...' -var out = truncateCodePoints( 'beep boop', 7, '!' ); + +out = truncateCodePoints( 'beep boop', 7, '!' ); // returns 'beep b!' out = truncateCodePoints( 'beep boop', 7, '!!!' ); From dfe50f71e6b4fff1d114c668bd1fe9fcb2002bc9 Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 10 Nov 2023 13:28:28 -0800 Subject: [PATCH 10/18] Apply suggestions from code review --- .../@stdlib/string/base/truncate-code-points/docs/repl.txt | 1 - .../@stdlib/string/base/truncate-code-points/lib/main.js | 3 +-- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/repl.txt b/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/repl.txt index 02517e1b4c49..5f82874b8ec4 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/repl.txt +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/repl.txt @@ -24,7 +24,6 @@ > var str = 'beep boop'; > var out = {{alias}}( str, 5, '...' ) 'be...' - > out = {{alias}}( str, 5, '|' ) 'beep|' diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/main.js b/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/main.js index c27c2a91cecd..f779e190754b 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/main.js +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/main.js @@ -105,8 +105,7 @@ function truncate( str, len, ending ) { i += 1; // bump the index to process the next code unit out += ch1 + ch2; } - } - else { + } else { out += ch1; } } From 5f56e1decc783afcf80ecae9614148d392657689 Mon Sep 17 00:00:00 2001 From: Stephannie Jimenez Date: Fri, 10 Nov 2023 16:29:51 -0500 Subject: [PATCH 11/18] docs: update package description and update benchmark --- .../@stdlib/string/base/truncate-code-points/README.md | 2 +- .../string/base/truncate-code-points/benchmark/benchmark.js | 2 +- .../@stdlib/string/base/truncate-code-points/docs/repl.txt | 4 ++-- .../string/base/truncate-code-points/docs/types/index.d.ts | 2 +- .../@stdlib/string/base/truncate-code-points/lib/index.js | 2 +- .../@stdlib/string/base/truncate-code-points/lib/main.js | 2 +- .../@stdlib/string/base/truncate-code-points/package.json | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-points/README.md b/lib/node_modules/@stdlib/string/base/truncate-code-points/README.md index b8efc26862cc..fb683742cab7 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-points/README.md +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/README.md @@ -32,7 +32,7 @@ var truncateCodePoints = require( '@stdlib/string/base/truncate-code-points' ); #### truncateCodePoints( str, len, ending ) -Truncates the code points of a provided string in order to return a string having a specified length. +Truncates the Unicode code points of a provided string in order to return a string having a specified length. ```javascript var out = truncateCodePoints( 'beep boop', 7, '...' ); diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-points/benchmark/benchmark.js b/lib/node_modules/@stdlib/string/base/truncate-code-points/benchmark/benchmark.js index 153966ae4f62..3cc63bb9f4aa 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-points/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/benchmark/benchmark.js @@ -42,7 +42,7 @@ bench( pkg, function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - out = truncate( values[ i%values.length ], 1, '...' ); + out = truncate( values[ i%values.length ], 7, '...' ); if ( typeof out !== 'string' ) { b.fail( 'should return a string' ); } diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/repl.txt b/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/repl.txt index 5f82874b8ec4..32b4cfcae32a 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/repl.txt +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( str, len, ending ) - Truncate the code points of a provided string in order to return a string - having a specified length. + Truncate the Unicode code points of a provided string in order to return a + string having a specified length. Parameters ---------- diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/types/index.d.ts b/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/types/index.d.ts index 384b4acbd67a..ab1262cd218d 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/types/index.d.ts @@ -19,7 +19,7 @@ // TypeScript Version: 2.0 /** -* Truncate the code points of a provided string in order to return a string having a specified length. +* Truncate the Unicode code points of a provided string in order to return a string having a specified length. * * @param str - input string * @param len - output string length (including ending) diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/index.js b/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/index.js index 54bec73604b0..8c8bf897c130 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/index.js +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Truncate the code points of a provided string in order to return a string having a specified length. +* Truncate the Unicode code points of a provided string in order to return a string having a specified length. * * @module @stdlib/string/base/truncate-code-points * diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/main.js b/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/main.js index f779e190754b..50124a32ba55 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/main.js +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/main.js @@ -32,7 +32,7 @@ var RE_UTF16_HIGH_SURROGATE = /[\uD800-\uDBFF]/; // TODO: replace with stdlib pk // MAIN // /** -* Truncates the code points of a provided string in order to return a string having a specified length. +* Truncates the Unicode code points of a provided string in order to return a string having a specified length. * * @param {string} str - input string * @param {NonNegativeInteger} len - output string length (including ending) diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-points/package.json b/lib/node_modules/@stdlib/string/base/truncate-code-points/package.json index 66ff10fe326f..c36f2ee3bc3e 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-points/package.json +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/string/base/truncate-code-points", "version": "0.0.0", - "description": "Truncate the code points of a provided string in order to return a string having a specified length.", + "description": "Truncate the Unicode code points of a provided string in order to return a string having a specified length.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", From a90b498797330fca157ca3162e4044a661fd0804 Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 10 Nov 2023 13:43:44 -0800 Subject: [PATCH 12/18] Apply suggestions from code review --- lib/node_modules/@stdlib/string/truncate/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/string/truncate/README.md b/lib/node_modules/@stdlib/string/truncate/README.md index bb3e725ec660..d7dd11727e6d 100644 --- a/lib/node_modules/@stdlib/string/truncate/README.md +++ b/lib/node_modules/@stdlib/string/truncate/README.md @@ -63,9 +63,9 @@ The function supports the following options: - **mode**: type of characters to return. Must be one of the following: - - `'grapheme'`: grapheme clusters. Appropriate for strings containing visual characters which can span multiple Unicode code points (e.g., emoji). - - `'code_point'`: Unicode code points. Appropriate for strings containing visual characters which are comprised of more than one Unicode code unit (e.g., ideographic symbols and punctuation and mathematical alphanumerics). - - `'code_unit'`: UTF-16 code units. Appropriate for strings containing visual characters drawn from the basic multilingual plane (BMP) (e.g., common characters, such as those from the Latin, Greek, and Cyrillic alphabets). + - `'grapheme'`: grapheme clusters. Appropriate for strings containing visual characters which can span multiple Unicode code points (e.g., emoji). When the `mode` is `'grapheme'`, `N` specifies the maximum number of grapheme clusters in the returned string. + - `'code_point'`: Unicode code points. Appropriate for strings containing visual characters which are comprised of more than one Unicode code unit (e.g., ideographic symbols and punctuation and mathematical alphanumerics). When the `mode` is `'code_point'`, `N` specifies the maximum number of Unicode code points in the returned string. + - `'code_unit'`: UTF-16 code units. Appropriate for strings containing visual characters drawn from the basic multilingual plane (BMP) (e.g., common characters, such as those from the Latin, Greek, and Cyrillic alphabets). When the `mode` is `'code_unit'`, `N` specifies the number of maximum number of UTF-16 code units in the returned string. Default: `'grapheme'`. From 45a90012d6536a1415538c639e74d360837e2dd5 Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 10 Nov 2023 13:44:08 -0800 Subject: [PATCH 13/18] Apply suggestions from code review --- .../@stdlib/string/base/truncate-code-points/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-points/README.md b/lib/node_modules/@stdlib/string/base/truncate-code-points/README.md index fb683742cab7..6708fa953e57 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-points/README.md +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/README.md @@ -30,7 +30,7 @@ limitations under the License. var truncateCodePoints = require( '@stdlib/string/base/truncate-code-points' ); ``` -#### truncateCodePoints( str, len, ending ) +#### truncateCodePoints( str, N, ending ) Truncates the Unicode code points of a provided string in order to return a string having a specified length. From 695a9f4c6af9dc42e5f768ef298cfabcd3912b77 Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 10 Nov 2023 13:45:08 -0800 Subject: [PATCH 14/18] Apply suggestions from code review --- lib/node_modules/@stdlib/string/num-code-points/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/string/num-code-points/README.md b/lib/node_modules/@stdlib/string/num-code-points/README.md index f07f6e3d4efa..93311ccc616a 100644 --- a/lib/node_modules/@stdlib/string/num-code-points/README.md +++ b/lib/node_modules/@stdlib/string/num-code-points/README.md @@ -32,7 +32,7 @@ var numCodePoints = require( '@stdlib/string/num-code-points' ); #### numCodePoints( str ) -Returns the number of code points in a `string`. +Returns the number of code points in a string. ```javascript var out = numCodePoints( 'last man standing' ); From 976eefae80d7ba768c685444d98182e604bcbcf1 Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 10 Nov 2023 13:58:52 -0800 Subject: [PATCH 15/18] Apply suggestions from code review --- .../@stdlib/string/num-code-points/README.md | 10 +--------- .../@stdlib/string/num-code-points/lib/main.js | 3 +-- .../@stdlib/string/num-code-points/test/test.js | 6 +++--- 3 files changed, 5 insertions(+), 14 deletions(-) diff --git a/lib/node_modules/@stdlib/string/num-code-points/README.md b/lib/node_modules/@stdlib/string/num-code-points/README.md index 93311ccc616a..0d4ef56c3dbf 100644 --- a/lib/node_modules/@stdlib/string/num-code-points/README.md +++ b/lib/node_modules/@stdlib/string/num-code-points/README.md @@ -20,7 +20,7 @@ limitations under the License. # numCodePoints -> Return the number of code points in a string. +> Return the number of Unicode code points in a string.
@@ -127,12 +127,6 @@ $ echo -n 'beep\nboop書' | num-code-points -l @@ -145,8 +139,6 @@ $ echo -n 'beep\nboop書' | num-code-points -l -[@stdlib/string/next-grapheme-cluster-break]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/next-grapheme-cluster-break -
diff --git a/lib/node_modules/@stdlib/string/num-code-points/lib/main.js b/lib/node_modules/@stdlib/string/num-code-points/lib/main.js index 78571b0f2eff..06815efccc89 100644 --- a/lib/node_modules/@stdlib/string/num-code-points/lib/main.js +++ b/lib/node_modules/@stdlib/string/num-code-points/lib/main.js @@ -80,8 +80,7 @@ function numCodePoints( str ) { i += 1; // bump the index to process the next code unit count += 1; } - } - else { + } else { count += 1; } } diff --git a/lib/node_modules/@stdlib/string/num-code-points/test/test.js b/lib/node_modules/@stdlib/string/num-code-points/test/test.js index b9e89f29948a..1a440c7d529a 100644 --- a/lib/node_modules/@stdlib/string/num-code-points/test/test.js +++ b/lib/node_modules/@stdlib/string/num-code-points/test/test.js @@ -82,7 +82,7 @@ tape( 'the function returns the Unicode aware length of a provided string', func t.end(); }); -tape( 'the function returns the number of grapheme clusters (Unpaired surrogates)', function test( t ) { +tape( 'the function returns the number of code points (surrogates)', function test( t ) { var out; out = numCodePoints( '𐒻𐓟' ); @@ -91,8 +91,8 @@ tape( 'the function returns the number of grapheme clusters (Unpaired surrogates out = numCodePoints( '𐒻' ); t.strictEqual( out, 1, 'returns expected value' ); - out = numCodePoints( '\uD800' ); - t.strictEqual( out, 0, 'returns expected value' ); + out = numCodePoints( '\uD800' ); // trailing unpaired high surrogate + t.strictEqual( out, 1, 'returns expected value' ); t.end(); }); From 27e7e3050cbab0be543c3f80bc5806f09a0ead2c Mon Sep 17 00:00:00 2001 From: Stephannie Jimenez Date: Wed, 29 Nov 2023 18:54:09 -0500 Subject: [PATCH 16/18] fix: add review changes --- .../base/truncate-code-points/README.md | 4 +- .../base/truncate-code-points/docs/repl.txt | 2 +- .../docs/types/index.d.ts | 2 +- .../base/truncate-code-points/lib/index.js | 2 +- .../base/truncate-code-points/lib/main.js | 2 +- .../base/truncate-code-points/package.json | 2 +- .../@stdlib/string/num-code-points/README.md | 14 +++++-- .../num-code-points/benchmark/benchmark.js | 26 +++++++++---- .../@stdlib/string/num-code-points/bin/cli | 38 ++++++++++--------- .../string/num-code-points/examples/index.js | 3 ++ .../string/num-code-points/lib/main.js | 10 ++--- .../string/num-code-points/test/test.cli.js | 6 +-- .../@stdlib/string/truncate/README.md | 20 +++++----- .../@stdlib/string/truncate/bin/cli | 2 +- .../@stdlib/string/truncate/docs/repl.txt | 6 +-- .../string/truncate/docs/types/index.d.ts | 18 ++++----- .../@stdlib/string/truncate/docs/usage.txt | 2 +- .../@stdlib/string/truncate/etc/cli_opts.json | 2 +- .../@stdlib/string/truncate/lib/index.js | 2 +- .../@stdlib/string/truncate/lib/main.js | 13 +++---- .../@stdlib/string/truncate/package.json | 2 +- .../@stdlib/string/truncate/test/test.cli.js | 20 +++++----- 22 files changed, 108 insertions(+), 90 deletions(-) diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-points/README.md b/lib/node_modules/@stdlib/string/base/truncate-code-points/README.md index 6708fa953e57..e6611d385ee4 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-points/README.md +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/README.md @@ -20,7 +20,7 @@ limitations under the License. # truncateCodePoints -> Truncate the Unicode code points of a provided string in order to return a string having a specified length. +> Truncate the Unicode code points of a provided string in order to return a string having a specified number of Unicode code points.
@@ -32,7 +32,7 @@ var truncateCodePoints = require( '@stdlib/string/base/truncate-code-points' ); #### truncateCodePoints( str, N, ending ) -Truncates the Unicode code points of a provided string in order to return a string having a specified length. +Truncates the Unicode code points of a provided string in order to return a string having a specified number of Unicode code points. ```javascript var out = truncateCodePoints( 'beep boop', 7, '...' ); diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/repl.txt b/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/repl.txt index 32b4cfcae32a..d80ed1ce5cff 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/repl.txt +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/repl.txt @@ -1,7 +1,7 @@ {{alias}}( str, len, ending ) Truncate the Unicode code points of a provided string in order to return a - string having a specified length. + string having a specified number of Unicode code points. Parameters ---------- diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/types/index.d.ts b/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/types/index.d.ts index ab1262cd218d..c8776f629e07 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/types/index.d.ts @@ -19,7 +19,7 @@ // TypeScript Version: 2.0 /** -* Truncate the Unicode code points of a provided string in order to return a string having a specified length. +* Truncate the Unicode code points of a provided string in order to return a string having a specified number of Unicode code points. * * @param str - input string * @param len - output string length (including ending) diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/index.js b/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/index.js index 8c8bf897c130..9e30c6f20ff4 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/index.js +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Truncate the Unicode code points of a provided string in order to return a string having a specified length. +* Truncate the Unicode code points of a provided string in order to return a string having a specified number of Unicode code points. * * @module @stdlib/string/base/truncate-code-points * diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/main.js b/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/main.js index 50124a32ba55..86dd169fdf52 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/main.js +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/main.js @@ -32,7 +32,7 @@ var RE_UTF16_HIGH_SURROGATE = /[\uD800-\uDBFF]/; // TODO: replace with stdlib pk // MAIN // /** -* Truncates the Unicode code points of a provided string in order to return a string having a specified length. +* Truncates the Unicode code points of a provided string in order to return a string having a specified number of Unicode code points. * * @param {string} str - input string * @param {NonNegativeInteger} len - output string length (including ending) diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-points/package.json b/lib/node_modules/@stdlib/string/base/truncate-code-points/package.json index c36f2ee3bc3e..322b60b63998 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-points/package.json +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/string/base/truncate-code-points", "version": "0.0.0", - "description": "Truncate the Unicode code points of a provided string in order to return a string having a specified length.", + "description": "Truncate the Unicode code points of a provided string in order to return a string having a specified number of Unicode code points.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", diff --git a/lib/node_modules/@stdlib/string/num-code-points/README.md b/lib/node_modules/@stdlib/string/num-code-points/README.md index 0d4ef56c3dbf..33f4c9441b53 100644 --- a/lib/node_modules/@stdlib/string/num-code-points/README.md +++ b/lib/node_modules/@stdlib/string/num-code-points/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2020 The Stdlib Authors. +Copyright (c) 2023 The Stdlib Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -40,6 +40,9 @@ var out = numCodePoints( 'last man standing' ); out = numCodePoints( 'Hidden Treasures' ); // returns 16 + +out = numCodePoints( '𐒻𐓟𐒻𐓟' ); +// returns 4 ```
@@ -55,14 +58,17 @@ out = numCodePoints( 'Hidden Treasures' ); ```javascript var numCodePoints = require( '@stdlib/string/num-code-points' ); -var str = numCodePoints( 'last man standing' ); +var out = numCodePoints( 'last man standing' ); // returns 17 -str = numCodePoints( '六书/六書' ); +out = numCodePoints( '六书/六書' ); // returns 5 -str = numCodePoints( 'अनुच्छेद' ); +out = numCodePoints( 'अनुच्छेद' ); // returns 8 + +out = numCodePoints( '𐒻𐓟𐒻𐓟' ); +// returns 4 ```
diff --git a/lib/node_modules/@stdlib/string/num-code-points/benchmark/benchmark.js b/lib/node_modules/@stdlib/string/num-code-points/benchmark/benchmark.js index f95a5f49877b..8b0553116202 100644 --- a/lib/node_modules/@stdlib/string/num-code-points/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/string/num-code-points/benchmark/benchmark.js @@ -21,10 +21,7 @@ // MODULES // var bench = require( '@stdlib/bench' ); -var fromCodePoint = require( '@stdlib/string/from-code-point' ); -var UNICODE_MAX = require( '@stdlib/constants/unicode/max' ); -var randu = require( '@stdlib/random/base/randu' ); -var floor = require( '@stdlib/math/base/special/floor' ); +var isInteger = require( '@stdlib/assert/is-integer' ); var pkg = require( './../package.json' ).name; var numCodePoints = require( './../lib' ); @@ -32,19 +29,34 @@ var numCodePoints = require( './../lib' ); // MAIN // bench( pkg, function benchmark( b ) { - var str; + var strings; var out; var i; + strings = [ + 'last man standing', + 'presidential election', + 'अनुच्छेद', + '🌷', + '书/六書', + 'เ❄︎நி', + 'กิิก้้ก็็ก็็กิิก้้ก็็กิิก้้กิิก้้ก็็ก็็กิิก้้ก็็กิิก้้', + '書六/书六', + 'ܶƔλʃݖͱšɕ҆ʧѸؐҜҦɳΏ', + 'âݝΝ‚ҳӌݾҀƳ۵ۧ޳ǁǸΓ' + ]; + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - str = fromCodePoint( floor( randu() * UNICODE_MAX ) ) + 'eep boop'; - out = numCodePoints( str ); + out = numCodePoints( strings[ i%strings.length ] ); if ( out < 0 ) { b.fail( 'should never be a negative integer' ); } } b.toc(); + if ( !isInteger( out ) ) { + b.fail( 'should return an integer' ); + } b.pass( 'benchmark finished' ); b.end(); }); diff --git a/lib/node_modules/@stdlib/string/num-code-points/bin/cli b/lib/node_modules/@stdlib/string/num-code-points/bin/cli index 714df7e42057..a26c5c908def 100644 --- a/lib/node_modules/@stdlib/string/num-code-points/bin/cli +++ b/lib/node_modules/@stdlib/string/num-code-points/bin/cli @@ -28,6 +28,8 @@ var CLI = require( '@stdlib/cli/ctor' ); var stdin = require( '@stdlib/process/read-stdin' ); var stdinStream = require( '@stdlib/streams/node/stdin' ); var RE_EOL = require( '@stdlib/regexp/eol' ).REGEXP; +var isRegExpString = require( '@stdlib/assert/is-regexp-string' ); +var reFromString = require( '@stdlib/utils/regexp-from-string' ); var numCodePoints = require( './../lib' ); @@ -41,10 +43,9 @@ var numCodePoints = require( './../lib' ); */ function main() { var flags; - var lines; + var split; var args; var cli; - var i; // Create a command-line interface: cli = new CLI({ @@ -66,16 +67,17 @@ function main() { // Check if we are receiving data from `stdin`... if ( !stdinStream.isTTY ) { - return stdin( onRead ); - } - if ( flags.lines ) { - lines = args[ 0 ].split( RE_EOL ); - for ( i = 0; i < lines.length; i++ ) { - console.log( numCodePoints( lines[ i ] ) ); // eslint-disable-line no-console + if ( flags.split ) { + if ( !isRegExpString( flags.split ) ) { + flags.split = '/'+flags.split+'/'; + } + split = reFromString( flags.split ); + } else { + split = RE_EOL; } - } else { - console.log( numCodePoints( args[ 0 ] ) ); // eslint-disable-line no-console + return stdin( onRead ); } + console.log( numCodePoints( args[ 0 ] ) ); // eslint-disable-line no-console /** * Callback invoked upon reading from `stdin`. @@ -91,14 +93,14 @@ function main() { if ( error ) { return cli.error( error ); } - data = data.toString(); - if ( flags.lines ) { - lines = data.split( RE_EOL ); - for ( i = 0; i < lines.length; i++ ) { - console.log( numCodePoints( lines[ i ] ) ); // eslint-disable-line no-console - } - } else { - console.log( numCodePoints( data ) ); // eslint-disable-line no-console + lines = data.toString().split( split ); + + // Remove any trailing separators (e.g., trailing newline)... + if ( lines[ lines.length-1 ] === '' ) { + lines.pop(); + } + for ( i = 0; i < lines.length; i++ ) { + console.log( numCodePoints( lines[ i ] ) ); // eslint-disable-line no-console } } } diff --git a/lib/node_modules/@stdlib/string/num-code-points/examples/index.js b/lib/node_modules/@stdlib/string/num-code-points/examples/index.js index bc0959336e18..ec2c98168b18 100644 --- a/lib/node_modules/@stdlib/string/num-code-points/examples/index.js +++ b/lib/node_modules/@stdlib/string/num-code-points/examples/index.js @@ -28,3 +28,6 @@ console.log( numCodePoints( '六书/六書' ) ); console.log( numCodePoints( 'अनुच्छेद' ) ); // => 8 + +console.log( numCodePoints( '𐒻𐓟𐒻𐓟' ) ); +// => 4 diff --git a/lib/node_modules/@stdlib/string/num-code-points/lib/main.js b/lib/node_modules/@stdlib/string/num-code-points/lib/main.js index 06815efccc89..deb9e52ec083 100644 --- a/lib/node_modules/@stdlib/string/num-code-points/lib/main.js +++ b/lib/node_modules/@stdlib/string/num-code-points/lib/main.js @@ -53,8 +53,6 @@ var RE_UTF16_HIGH_SURROGATE = /[\uD800-\uDBFF]/; // TODO: replace with stdlib pk */ function numCodePoints( str ) { var count; - var ch1; - var ch2; var i; if ( !isString( str ) ) { @@ -64,18 +62,16 @@ function numCodePoints( str ) { // Process the string one Unicode code unit at a time and count UTF-16 surrogate pairs as a single Unicode code point... for ( i = 0; i < str.length; i++ ) { - ch1 = str[ i ]; - // Check for a high UTF-16 surrogate... - if ( RE_UTF16_HIGH_SURROGATE.test( ch1 ) ) { + if ( RE_UTF16_HIGH_SURROGATE.test( str[ i ] ) ) { // Check for an unpaired surrogate at the end of the input string... if ( i === str.length-1 ) { // We found an unpaired surrogate... + count += 1; break; } // Check whether the high surrogate is paired with a low surrogate... - ch2 = str[ i+1 ]; - if ( RE_UTF16_LOW_SURROGATE.test( ch2 ) ) { + if ( RE_UTF16_LOW_SURROGATE.test( str[ i+1 ] ) ) { // We found a surrogate pair: i += 1; // bump the index to process the next code unit count += 1; diff --git a/lib/node_modules/@stdlib/string/num-code-points/test/test.cli.js b/lib/node_modules/@stdlib/string/num-code-points/test/test.cli.js index 5193adf818cd..cf60c613972c 100644 --- a/lib/node_modules/@stdlib/string/num-code-points/test/test.cli.js +++ b/lib/node_modules/@stdlib/string/num-code-points/test/test.cli.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2020 The Stdlib Authors. +* Copyright (c) 2023 The Stdlib Authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * 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 if ( error ) { t.fail( error.message ); } else { - t.strictEqual( stdout.toString(), '4\n4\n', 'expected value' ); + t.strictEqual( stdout.toString(), '9\n', 'expected value' ); t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); } t.end(); @@ -196,7 +196,7 @@ tape( 'the command-line interface supports use as a standard stream', opts, func if ( error ) { t.fail( error.message ); } else { - t.strictEqual( stdout.toString(), '10\n', 'expected value' ); + t.strictEqual( stdout.toString(), '4\n5\n', 'expected value' ); t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); } t.end(); diff --git a/lib/node_modules/@stdlib/string/truncate/README.md b/lib/node_modules/@stdlib/string/truncate/README.md index d7dd11727e6d..30b61a1950d1 100644 --- a/lib/node_modules/@stdlib/string/truncate/README.md +++ b/lib/node_modules/@stdlib/string/truncate/README.md @@ -20,7 +20,7 @@ limitations under the License. # truncate -> Truncate a string to a specified length. +> Truncate a string. @@ -40,9 +40,9 @@ limitations under the License. var truncate = require( '@stdlib/string/truncate' ); ``` -#### truncate( str, len\[, ending]\[, options] ) +#### truncate( str, N\[, ending]\[, options] ) -Truncates a string to a specified length. +Truncates a string. ```javascript var out = truncate( 'beep boop', 7 ); @@ -146,7 +146,7 @@ Options: -h, --help Print this message. -V, --version Print the package version. - --len length String length. + --N length String length. --ending str Custom ending. Default: '...'. --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. --mode mode Type of character to return. Default: 'grapheme'. @@ -166,10 +166,10 @@ Options: ```bash # Not escaped... - $ echo -n $'Hello, World!\nBeep Boop Baz' | truncate --len 6 --split /\r?\n/ + $ echo -n $'Hello, World!\nBeep Boop Baz' | truncate --N 6 --split /\r?\n/ # Escaped... - $ echo -n $'Hello, World!\nBeep Boop Baz' | truncate --len 6 --split /\\r?\\n/ + $ echo -n $'Hello, World!\nBeep Boop Baz' | truncate --N 6 --split /\\r?\\n/ ``` - The implementation ignores trailing delimiters. @@ -187,24 +187,24 @@ Options: ### Examples ```bash -$ truncate 'Hello, World!' --len 8 +$ truncate 'Hello, World!' --N 8 Hello... -$ truncate 'Hello, World!' --len 6 --ending '!' +$ truncate 'Hello, World!' --N 6 --ending '!' Hello! ``` To use as a [standard stream][standard-streams], ```bash -$ echo -n 'Hello, World!' | truncate --len 8 +$ echo -n 'Hello, World!' | truncate --N 8 Hello... ``` 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. ```bash -$ echo -n 'Hello, World!\tBeep Boop' | truncate --split '\t' --len 8 +$ echo -n 'Hello, World!\tBeep Boop' | truncate --split '\t' --N 8 Hello... Beep ... ``` diff --git a/lib/node_modules/@stdlib/string/truncate/bin/cli b/lib/node_modules/@stdlib/string/truncate/bin/cli index 1502e2b731e1..c3148ce084d4 100644 --- a/lib/node_modules/@stdlib/string/truncate/bin/cli +++ b/lib/node_modules/@stdlib/string/truncate/bin/cli @@ -78,7 +78,7 @@ function main() { // Get any provided command-line arguments: args = cli.args(); - len = parseInt( flags.len, 10 ); + len = parseInt( flags.N, 10 ); // Check if we are receiving data from `stdin`... if ( !stdinStream.isTTY ) { diff --git a/lib/node_modules/@stdlib/string/truncate/docs/repl.txt b/lib/node_modules/@stdlib/string/truncate/docs/repl.txt index 5ea94d4977d7..48341cb23071 100644 --- a/lib/node_modules/@stdlib/string/truncate/docs/repl.txt +++ b/lib/node_modules/@stdlib/string/truncate/docs/repl.txt @@ -1,13 +1,13 @@ -{{alias}}( str, len[, ending][, options] ) - Truncates a string to a specified length. +{{alias}}( str, N[, ending][, options] ) + Truncates a string. Parameters ---------- str: string Input string. - len: integer + N: integer Output string length. ending: string (optional) diff --git a/lib/node_modules/@stdlib/string/truncate/docs/types/index.d.ts b/lib/node_modules/@stdlib/string/truncate/docs/types/index.d.ts index 7fd6251f5948..f1eee700bc79 100644 --- a/lib/node_modules/@stdlib/string/truncate/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/string/truncate/docs/types/index.d.ts @@ -41,10 +41,10 @@ interface Options { } /** -* Truncates a string to a specified length. +* Truncates a string. * * @param str - input string -* @param len - output string length (including ending) +* @param N - output string length (including ending) * @param options - options * @returns truncated string * @@ -60,13 +60,13 @@ interface Options { * }); * // returns '🐶🐮...' */ -declare function truncate( str: string, len: number, options?: Options ): string; +declare function truncate( str: string, N: number, options?: Options ): string; /** -* Truncates a string to a specified length. +* Truncates a string. * * @param str - input string -* @param len - output string length (including ending) +* @param N - output string length (including ending) * @param ending - custom ending (default: `...`) * @returns truncated string * @@ -78,13 +78,13 @@ declare function truncate( str: string, len: number, options?: Options ): string * var out = truncate( 'beep boop', 7, '|' ); * // returns 'beep b|' */ -declare function truncate( str: string, len: number, ending?: string ): string; +declare function truncate( str: string, N: number, ending?: string ): string; /** -* Truncates a string to a specified length. +* Truncates a string. * * @param str - input string -* @param len - output string length (including ending) +* @param N - output string length (including ending) * @param ending - custom ending (default: `...`) * @returns truncated string * @@ -100,7 +100,7 @@ declare function truncate( str: string, len: number, ending?: string ): string; * }); * // returns 'beep b|' */ -declare function truncate( str: string, len: number, ending: string, options?: Options ): string; +declare function truncate( str: string, N: number, ending: string, options?: Options ): string; // EXPORTS // diff --git a/lib/node_modules/@stdlib/string/truncate/docs/usage.txt b/lib/node_modules/@stdlib/string/truncate/docs/usage.txt index 2b741cd5ec6b..ecde43df28c3 100644 --- a/lib/node_modules/@stdlib/string/truncate/docs/usage.txt +++ b/lib/node_modules/@stdlib/string/truncate/docs/usage.txt @@ -5,7 +5,7 @@ Options: -h, --help Print this message. -V, --version Print the package version. - --len length String length. + --N length String length. --ending str Custom ending. Default: '...'. --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. --mode mode Type of character to return. Default: 'grapheme'. diff --git a/lib/node_modules/@stdlib/string/truncate/etc/cli_opts.json b/lib/node_modules/@stdlib/string/truncate/etc/cli_opts.json index 4e441a45ae29..f9ab6a0ecfe0 100644 --- a/lib/node_modules/@stdlib/string/truncate/etc/cli_opts.json +++ b/lib/node_modules/@stdlib/string/truncate/etc/cli_opts.json @@ -1,6 +1,6 @@ { "string": [ - "len", + "N", "ending", "split", "mode" diff --git a/lib/node_modules/@stdlib/string/truncate/lib/index.js b/lib/node_modules/@stdlib/string/truncate/lib/index.js index 6fed90ec2705..cbdd230f57a8 100644 --- a/lib/node_modules/@stdlib/string/truncate/lib/index.js +++ b/lib/node_modules/@stdlib/string/truncate/lib/index.js @@ -19,7 +19,7 @@ 'use strict'; /** -* Truncate a string to a specified length. +* Truncate a string. * * @module @stdlib/string/truncate * diff --git a/lib/node_modules/@stdlib/string/truncate/lib/main.js b/lib/node_modules/@stdlib/string/truncate/lib/main.js index be775969c5b3..a457f69bd4ed 100644 --- a/lib/node_modules/@stdlib/string/truncate/lib/main.js +++ b/lib/node_modules/@stdlib/string/truncate/lib/main.js @@ -45,10 +45,10 @@ var isMode = contains( MODES ); // MAIN // /** -* Truncates a string to a specified length. +* Truncates a string. * * @param {string} str - input string -* @param {integer} len - output string length (including ending) +* @param {integer} N - output string length (including ending) * @param {string} [ending='...'] - custom ending * @param {Options} [options] - options * @param {string} [options.mode="grapheme"] - type of "character" to return (must be either `grapheme`, `code_point`, or `code_unit`) @@ -89,7 +89,7 @@ var isMode = contains( MODES ); * var out = truncate( str, 6 ); * // returns '🐺 W...' */ -function truncate( str, len ) { +function truncate( str, N ) { var options; var ending; var nargs; @@ -98,8 +98,8 @@ function truncate( str, len ) { if ( !isString( str ) ) { throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); } - if ( !isNonNegativeInteger( len ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', len ) ); + if ( !isNonNegativeInteger( N ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be a nonnegative integer. Value: `%s`.', N ) ); } opts = { 'mode': 'grapheme' @@ -123,7 +123,6 @@ function truncate( str, len ) { } options = arguments[ 3 ]; if ( !isPlainObject( options ) ) { - console.log('!!!!!!!'); throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); } } @@ -135,7 +134,7 @@ function truncate( str, len ) { } } } - return FCNS[ opts.mode ]( str, len, ending ); + return FCNS[ opts.mode ]( str, N, ending ); } diff --git a/lib/node_modules/@stdlib/string/truncate/package.json b/lib/node_modules/@stdlib/string/truncate/package.json index 29d4c86b6ac6..5c0cf227b9ce 100644 --- a/lib/node_modules/@stdlib/string/truncate/package.json +++ b/lib/node_modules/@stdlib/string/truncate/package.json @@ -1,7 +1,7 @@ { "name": "@stdlib/string/truncate", "version": "0.0.0", - "description": "Truncate a string to a specified length.", + "description": "Truncate a string.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", diff --git a/lib/node_modules/@stdlib/string/truncate/test/test.cli.js b/lib/node_modules/@stdlib/string/truncate/test/test.cli.js index b651b6960309..12ccff7031ab 100644 --- a/lib/node_modules/@stdlib/string/truncate/test/test.cli.js +++ b/lib/node_modules/@stdlib/string/truncate/test/test.cli.js @@ -149,7 +149,7 @@ tape( 'the command-line interface truncates a string', opts, function test( t ) cmd = [ EXEC_PATH, '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep boop\'; process.argv[ 3 ] = \'--len=5\'; require( \''+fpath+'\' );"' + '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep boop\'; process.argv[ 3 ] = \'--N=5\'; require( \''+fpath+'\' );"' ]; opts = {}; @@ -173,7 +173,7 @@ tape( 'the command-line interface truncates a string (custom ending)', opts, fun cmd = [ EXEC_PATH, '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep boop\'; process.argv[ 3 ] = \'--len=5\'; process.argv[ 4 ] = \'--ending=!\'; require( \''+fpath+'\' );"' + '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep boop\'; process.argv[ 3 ] = \'--N=5\'; process.argv[ 4 ] = \'--ending=!\'; require( \''+fpath+'\' );"' ]; opts = {}; @@ -194,7 +194,7 @@ tape( 'the command-line interface supports specifying the type of characters to var cmd = [ EXEC_PATH, '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep boop\'; process.argv[ 3 ] = \'--len=4\'; process.argv[ 4 ] = \'--mode=code_point\'; require( \''+fpath+'\' );"' + '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep boop\'; process.argv[ 3 ] = \'--N=4\'; process.argv[ 4 ] = \'--mode=code_point\'; require( \''+fpath+'\' );"' ]; exec( cmd.join( ' ' ), done ); @@ -214,7 +214,7 @@ tape( 'if provided an invalid option, the command-line interface prints an error var cmd = [ EXEC_PATH, '-e', - '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--len=4\'; process.argv[ 4 ] = \'--mode=foo\'; require( \''+fpath+'\' );"' + '"process.stdin.isTTY = true; process.argv[ 2 ] = \'beep\'; process.argv[ 3 ] = \'--N=4\'; process.argv[ 4 ] = \'--mode=foo\'; require( \''+fpath+'\' );"' ]; exec( cmd.join( ' ' ), done ); @@ -236,7 +236,7 @@ tape( 'the command-line interface supports use as a standard stream', opts, func '|', EXEC_PATH, fpath, - '--len=5' + '--N=5' ]; exec( cmd.join( ' ' ), done ); @@ -258,7 +258,7 @@ tape( 'the command-line interface supports use as a standard stream (custom endi '|', EXEC_PATH, fpath, - '--len=5', + '--N=5', '--ending="|"' ]; @@ -282,7 +282,7 @@ tape( 'the command-line interface supports specifying a custom delimiter when us EXEC_PATH, fpath, '--split \'\t\'', - '--len=5' + '--N=5' ]; exec( cmd.join( ' ' ), done ); @@ -304,7 +304,7 @@ tape( 'the command-line interface supports specifying the type of characters to '|', EXEC_PATH, fpath, - '--len=5', + '--N=5', '--mode code_point' ]; @@ -328,7 +328,7 @@ tape( 'the command-line interface supports specifying a custom delimiter when us EXEC_PATH, fpath, '--split=/\\\\t/', - '--len=5' + '--N=5' ]; exec( cmd.join( ' ' ), done ); @@ -350,7 +350,7 @@ tape( 'when used as a standard stream, if provided an invalid option, the comman '|', EXEC_PATH, fpath, - '--len=5', + '--N=5', '--mode=foo' ]; From a1248372ca9edd58a5bacfd30effc2a1d706af84 Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 29 Dec 2023 09:58:36 -0800 Subject: [PATCH 17/18] Apply suggestions from code review Signed-off-by: Athan --- .../@stdlib/string/base/truncate-code-points/README.md | 2 +- .../string/base/truncate-code-points/docs/types/index.d.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-points/README.md b/lib/node_modules/@stdlib/string/base/truncate-code-points/README.md index e6611d385ee4..9b363560f035 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-points/README.md +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/README.md @@ -30,7 +30,7 @@ limitations under the License. var truncateCodePoints = require( '@stdlib/string/base/truncate-code-points' ); ``` -#### truncateCodePoints( str, N, ending ) +#### truncateCodePoints( str, len, ending ) Truncates the Unicode code points of a provided string in order to return a string having a specified number of Unicode code points. diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/types/index.d.ts b/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/types/index.d.ts index c8776f629e07..b806e98ca475 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/docs/types/index.d.ts @@ -19,7 +19,7 @@ // TypeScript Version: 2.0 /** -* Truncate the Unicode code points of a provided string in order to return a string having a specified number of Unicode code points. +* Truncates the Unicode code points of a provided string in order to return a string having a specified number of Unicode code points. * * @param str - input string * @param len - output string length (including ending) From 9e69e38f66c09331254dd671778341bd9ec2035d Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 29 Dec 2023 10:02:15 -0800 Subject: [PATCH 18/18] Apply suggestions from code review Signed-off-by: Athan --- .../@stdlib/string/base/truncate-code-points/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/main.js b/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/main.js index 86dd169fdf52..88dca150c5e4 100644 --- a/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/main.js +++ b/lib/node_modules/@stdlib/string/base/truncate-code-points/lib/main.js @@ -87,7 +87,7 @@ function truncate( str, len, ending ) { } out = ''; - // Process the string one Unicode code unit at a time and count UTF-16 surrogate pairs as a single Unicode code point... + // Process the string one code unit at a time and count UTF-16 surrogate pairs as a single Unicode code point... for ( i = 0; i < len - endingLength; i++ ) { ch1 = str[ i ];