From 1b9d2763dc20828fc1497f90d684cf85f8b96cc8 Mon Sep 17 00:00:00 2001 From: Stephannie Jimenez Date: Mon, 30 Oct 2023 12:30:03 -0500 Subject: [PATCH 01/13] feat: add next-code-point string package --- .../@stdlib/string/next-code-point/README.md | 205 ++++++++++++++ .../next-code-point/benchmark/benchmark.js | 64 +++++ .../@stdlib/string/next-code-point/bin/cli | 91 ++++++ .../string/next-code-point/docs/repl.txt | 30 ++ .../next-code-point/docs/types/index.d.ts | 42 +++ .../string/next-code-point/docs/types/test.ts | 47 ++++ .../string/next-code-point/docs/usage.txt | 8 + .../string/next-code-point/etc/cli_opts.json | 17 ++ .../string/next-code-point/examples/index.js | 33 +++ .../string/next-code-point/lib/index.js | 43 +++ .../string/next-code-point/lib/main.js | 119 ++++++++ .../string/next-code-point/package.json | 74 +++++ .../test/fixtures/stdin_error.js.txt | 33 +++ .../string/next-code-point/test/test.cli.js | 260 ++++++++++++++++++ .../string/next-code-point/test/test.js | 236 ++++++++++++++++ 15 files changed, 1302 insertions(+) create mode 100644 lib/node_modules/@stdlib/string/next-code-point/README.md create mode 100644 lib/node_modules/@stdlib/string/next-code-point/benchmark/benchmark.js create mode 100755 lib/node_modules/@stdlib/string/next-code-point/bin/cli create mode 100644 lib/node_modules/@stdlib/string/next-code-point/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/string/next-code-point/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/string/next-code-point/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/string/next-code-point/docs/usage.txt create mode 100644 lib/node_modules/@stdlib/string/next-code-point/etc/cli_opts.json create mode 100644 lib/node_modules/@stdlib/string/next-code-point/examples/index.js create mode 100644 lib/node_modules/@stdlib/string/next-code-point/lib/index.js create mode 100644 lib/node_modules/@stdlib/string/next-code-point/lib/main.js create mode 100644 lib/node_modules/@stdlib/string/next-code-point/package.json create mode 100644 lib/node_modules/@stdlib/string/next-code-point/test/fixtures/stdin_error.js.txt create mode 100644 lib/node_modules/@stdlib/string/next-code-point/test/test.cli.js create mode 100644 lib/node_modules/@stdlib/string/next-code-point/test/test.js diff --git a/lib/node_modules/@stdlib/string/next-code-point/README.md b/lib/node_modules/@stdlib/string/next-code-point/README.md new file mode 100644 index 000000000000..1ae3ba2c255c --- /dev/null +++ b/lib/node_modules/@stdlib/string/next-code-point/README.md @@ -0,0 +1,205 @@ + + +# nextCodePoint + +> Return the next code point in a string after a specified position. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var nextCodePoint = require( '@stdlib/string/next-code-point' ); +``` + +#### nextCodePoint( string\[, fromIndex] ) + +Returns the next code point in a string after a specified position. + +```javascript +var out = nextCodePoint( 'last man standing' ); +// returns 1 +``` + +By default, the function searches for a grapheme cluster starting from the first index. To specify an alternative starting search index, provide a `fromIndex` argument. + +```javascript +var out = nextCodePoint( 'last man standing', 4 ); +// returns 5 +``` + +
+ + + + + +
+ +## Notes + +- If `string` is an empty string, the function returns `-1` irrespective of `fromIndex`. +- If an code point does not exist after `fromIndex`, the function returns `-1`. +- Note that `fromIndex` does **not** refer to a visual character position, but to an index in the ordered sequence of [UTF-16][utf-16] code units. + +
+ + + + + +
+ +## Examples + + + +```javascript +var nextCodePoint = require( '@stdlib/string/next-code-point' ); + +var out = nextCodePoint( 'last man standing', 4 ); +// returns 5 + +out = nextCodePoint( 'presidential election', 8 ); +// returns 9 + +out = nextCodePoint( 'अनुच्छेद', 1 ); +// returns 2 + +out = nextCodePoint( '🌷', 0 ); +// returns -1 +``` + +
+ + + + + +* * * + +
+ +## CLI + + + +
+ +### Usage + +```text +Usage: next-code-point [options] [] + +Options: + + -h, --help Print this message. + -V, --version Print the package version. + --from index Starting search position in string. Default: 0. +``` + +
+ + + + + +
+ +
+ + + + + +
+ +### Examples + +```bash +$ next-code-point --from=1 अनुच्छेद +3 +``` + +To use as a [standard stream][standard-streams], + +```bash +$ echo -n 'अनुच्छेद' | next-code-point --from=1 +3 +``` + +
+ + + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/string/next-code-point/benchmark/benchmark.js b/lib/node_modules/@stdlib/string/next-code-point/benchmark/benchmark.js new file mode 100644 index 000000000000..3f3cd0e98699 --- /dev/null +++ b/lib/node_modules/@stdlib/string/next-code-point/benchmark/benchmark.js @@ -0,0 +1,64 @@ +/** +* @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 isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var nextCodePoint = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var strings; + var len; + var out; + var i; + + strings = [ + 'last man standing', + 'presidential election', + 'अनुच्छेद', + '🌷', + '书/六書', + 'เ❄︎நி', + 'กิิก้้ก็็ก็็กิิก้้ก็็กิิก้้กิิก้้ก็็ก็็กิิก้้ก็็กิิก้้', + '書六/书六', + 'ܶƔλʃݖͱšɕ҆ʧѸؐҜҦɳΏ', + 'âݝΝ‚ҳӌݾҀƳ۵ۧ޳ǁǸΓ' + ]; + len = strings.length; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = nextCodePoint( strings[ i%len ], 1 ); + if ( out !== out ) { + b.fail( 'should not return NaN' ); + } + } + 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/next-code-point/bin/cli b/lib/node_modules/@stdlib/string/next-code-point/bin/cli new file mode 100755 index 000000000000..c23a6472876b --- /dev/null +++ b/lib/node_modules/@stdlib/string/next-code-point/bin/cli @@ -0,0 +1,91 @@ +#!/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 nextCodePoint = require( './../lib' ); + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +* @returns {void} +*/ +function main() { + var flags; + var args; + var cli; + var pos; + + // 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; + } + if ( flags.from ) { + pos = parseInt( flags.from, 10 ); + } else { + pos = 0; + } + // Get any provided command-line arguments: + args = cli.args(); + + // Check if we are receiving data from `stdin`... + if ( stdinStream.isTTY ) { + return console.log( nextCodePoint( args[ 0 ], pos ) ); // eslint-disable-line no-console + } + return stdin( onRead ); + + /** + * Callback invoked upon reading from `stdin`. + * + * @private + * @param {(Error|null)} error - error object + * @param {Buffer} data - data + * @returns {void} + */ + function onRead( error, data ) { + if ( error ) { + return cli.error( error ); + } + console.log( nextCodePoint( data.toString(), pos ) ); // eslint-disable-line no-console + } +} + +main(); diff --git a/lib/node_modules/@stdlib/string/next-code-point/docs/repl.txt b/lib/node_modules/@stdlib/string/next-code-point/docs/repl.txt new file mode 100644 index 000000000000..ee208803b5a8 --- /dev/null +++ b/lib/node_modules/@stdlib/string/next-code-point/docs/repl.txt @@ -0,0 +1,30 @@ + +{{alias}}( str[, fromIndex] ) + Returns the next code point in a string after a specified position. + + Parameters + ---------- + str: string + Input string. + + fromIndex: integer (optional) + Position. Default: 0. + + Returns + ------- + out: integer + Next code point position. + + Examples + -------- + > var out = {{alias}}( 'last man standing', 4 ) + 5 + > out = {{alias}}( 'presidential election', 8 ) + 9 + > out = {{alias}}( 'अनुच्छेद', 1 ) + 3 + > out = {{alias}}( '🌷' ) + -1 + + See Also + -------- diff --git a/lib/node_modules/@stdlib/string/next-code-point/docs/types/index.d.ts b/lib/node_modules/@stdlib/string/next-code-point/docs/types/index.d.ts new file mode 100644 index 000000000000..a4d03a4d2187 --- /dev/null +++ b/lib/node_modules/@stdlib/string/next-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: 4.1 + +/** +* Returns the next code point in a string after a specified position. +* +* @param str - input string +* @param fromIndex - position (default: 0) +* @throws first argument must be a string +* @throws second argument must be an integer +* @returns next code point position +* +* @example +* var out = nextCodePoint( 'अनुच्छेद', 1 ); +* // returns 3 +* +* out = nextCodePoint( '🌷' ); +* // returns -1 +*/ +declare function nextCodePoint( str: string, fromIndex?: number ): number; // tslint:disable-line:max-line-length + + +// EXPORTS // + +export = nextCodePoint; diff --git a/lib/node_modules/@stdlib/string/next-code-point/docs/types/test.ts b/lib/node_modules/@stdlib/string/next-code-point/docs/types/test.ts new file mode 100644 index 000000000000..9e57319488a1 --- /dev/null +++ b/lib/node_modules/@stdlib/string/next-code-point/docs/types/test.ts @@ -0,0 +1,47 @@ +/* +* @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 nextCodePoint = require( './index' ); + + +// TESTS // + +// The function returns a number... +{ + nextCodePoint( 'last man standing', 4 ); // $ExpectType number + nextCodePoint( 'presidential election', 8 ); // $ExpectType number + nextCodePoint( 'अनुच्छेद', 1 ); // $ExpectType number + nextCodePoint( '🌷', 0 ); // $ExpectType number +} + +// The compiler throws an error if the function is provided invalid arguments... +{ + nextCodePoint( false, 3 ); // $ExpectError + nextCodePoint( {}, 3 ); // $ExpectError + nextCodePoint( ( x: number ): number => x, 3 ); // $ExpectError + + nextCodePoint( 'string', true ); // $ExpectError + nextCodePoint( 'string', false ); // $ExpectError + nextCodePoint( 'string', {} ); // $ExpectError + nextCodePoint( 'string', ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + nextCodePoint(); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/string/next-code-point/docs/usage.txt b/lib/node_modules/@stdlib/string/next-code-point/docs/usage.txt new file mode 100644 index 000000000000..69c6b9559752 --- /dev/null +++ b/lib/node_modules/@stdlib/string/next-code-point/docs/usage.txt @@ -0,0 +1,8 @@ + +Usage: next-code-point [options] [] + +Options: + + -h, --help Print this message. + -V, --version Print the package version. + --from index Starting search position in string. Default: 0. diff --git a/lib/node_modules/@stdlib/string/next-code-point/etc/cli_opts.json b/lib/node_modules/@stdlib/string/next-code-point/etc/cli_opts.json new file mode 100644 index 000000000000..8a766dc0ecdb --- /dev/null +++ b/lib/node_modules/@stdlib/string/next-code-point/etc/cli_opts.json @@ -0,0 +1,17 @@ +{ + "string": [ + "from" + ], + "boolean": [ + "help", + "version" + ], + "alias": { + "help": [ + "h" + ], + "version": [ + "V" + ] + } +} diff --git a/lib/node_modules/@stdlib/string/next-code-point/examples/index.js b/lib/node_modules/@stdlib/string/next-code-point/examples/index.js new file mode 100644 index 000000000000..9e3e21ee5473 --- /dev/null +++ b/lib/node_modules/@stdlib/string/next-code-point/examples/index.js @@ -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. +*/ + +'use strict'; + +var nextCodePoint = require( './../lib' ); + +console.log( nextCodePoint( 'last man standing', 4 ) ); +// => 5 + +console.log( nextCodePoint( 'presidential election', 8 ) ); +// => 9 + +console.log( nextCodePoint( 'अनुच्छेद', 1 ) ); +// => 3 + +console.log( nextCodePoint( '🌷', 0 ) ); +// => -1 diff --git a/lib/node_modules/@stdlib/string/next-code-point/lib/index.js b/lib/node_modules/@stdlib/string/next-code-point/lib/index.js new file mode 100644 index 000000000000..2a0a14823349 --- /dev/null +++ b/lib/node_modules/@stdlib/string/next-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'; + +/** +* Return the next code point break in a string after a specified position. +* +* @module @stdlib/string/next-code-point +* +* @example +* var nextCodePoint = require( '@stdlib/string/next-code-point' ); +* +* var out = nextCodePoint( 'अनुच्छेद', 1 ); +* // returns 3 +* +* out = nextCodePoint( '🌷', 0 ); +* // returns -1 +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/string/next-code-point/lib/main.js b/lib/node_modules/@stdlib/string/next-code-point/lib/main.js new file mode 100644 index 000000000000..175a1304c6f6 --- /dev/null +++ b/lib/node_modules/@stdlib/string/next-code-point/lib/main.js @@ -0,0 +1,119 @@ +/** +* @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 isInteger = require( '@stdlib/assert/is-integer' ).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 next code point in a string after a specified position. +* +* @param {string} str - input string +* @param {integer} [fromIndex=0] - position +* @throws {TypeError} first argument must be a string +* @throws {TypeError} second argument must be an integer +* @returns {NonNegativeInteger} next grapheme position +* +* @example +* var out = nextCodePoint( 'last man standing', 4 ); +* // returns 5 +* +* @example +* var out = nextCodePoint( 'presidential election', 8 ); +* // returns 9 +* +* @example +* var out = nextCodePoint( 'अनुच्छेद', 1 ); +* // returns 3 +* +* @example +* var out = nextCodePoint( '🌷' ); +* // returns -1 +*/ +function nextCodePoint( str, fromIndex ) { + var len; + var ch1; + var ch2; + var idx; + var i; + + if ( !isString( str ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + } + if ( arguments.length > 1 ) { + if ( !isInteger( fromIndex ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be an integer. Value: `%s`.', fromIndex ) ); + } + idx = fromIndex; + } else { + idx = 0; + } + len = str.length; + if ( idx < 0 ) { + idx += len; + if ( idx < 0 ) { + idx = 0; + } + } + if ( len === 0 || idx >= len ) { + return -1; + } + + // Begin searching for the next code point ... + for ( i = idx + 1; i < len; i++ ) { + ch1 = str[ i ]; + + // Check for a high UTF-16 surrogate... + if ( RE_UTF16_HIGH_SURROGATE.test( ch1 ) ) { + // 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: + return i + 1; + } + } + else { + if( i === len - 1 ) { + return -1; + } + else { + return i; + } + } + } + // No more code points: + return -1; +} + + +// EXPORTS // + +module.exports = nextCodePoint; diff --git a/lib/node_modules/@stdlib/string/next-code-point/package.json b/lib/node_modules/@stdlib/string/next-code-point/package.json new file mode 100644 index 000000000000..2d41491cf9f0 --- /dev/null +++ b/lib/node_modules/@stdlib/string/next-code-point/package.json @@ -0,0 +1,74 @@ +{ + "name": "@stdlib/string/next-code-point", + "version": "0.0.0", + "description": "Return the next code point in a string after a specified position.", + "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": { + "next-code-point": "./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", + "string", + "str", + "utilities", + "utility", + "utils", + "util", + "code", + "point", + "pt", + "unicode", + "utf-16", + "utf16", + "surrogate", + "astral", + "segmentation", + "tc39" + ] +} diff --git a/lib/node_modules/@stdlib/string/next-code-point/test/fixtures/stdin_error.js.txt b/lib/node_modules/@stdlib/string/next-code-point/test/fixtures/stdin_error.js.txt new file mode 100644 index 000000000000..103efa254ed3 --- /dev/null +++ b/lib/node_modules/@stdlib/string/next-code-point/test/fixtures/stdin_error.js.txt @@ -0,0 +1,33 @@ +/** +* @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. +*/ + +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/next-code-point/test/test.cli.js b/lib/node_modules/@stdlib/string/next-code-point/test/test.cli.js new file mode 100644 index 000000000000..964a7a258e7a --- /dev/null +++ b/lib/node_modules/@stdlib/string/next-code-point/test/test.cli.js @@ -0,0 +1,260 @@ +/** +* @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 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 returns the next code point break position in a string', opts, function test( t ) { + var cmd = [ + EXEC_PATH, + '-e', + '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--from=1\'; process.argv[ 3 ] = \'अनुच्छेद\'; require( \''+fpath+'\' );"' + ]; + + exec( cmd.join( ' ' ), done ); + + function done( error, stdout, stderr ) { + if ( error ) { + t.fail( error.message ); + } else { + t.strictEqual( stdout.toString(), '2\n', 'expected value' ); + t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); + } + t.end(); + } +}); + +tape( 'the command-line interface supports negative integers when specifying a starting search index', opts, function test( t ) { + var cmd = [ + EXEC_PATH, + '-e', + '"process.stdin.isTTY = true; process.argv[ 2 ] = \'--from=-7\'; process.argv[ 3 ] = \'अनुच्छेद\'; require( \''+fpath+'\' );"' + ]; + + exec( cmd.join( ' ' ), done ); + + function done( error, stdout, stderr ) { + if ( error ) { + t.fail( error.message ); + } else { + t.strictEqual( stdout.toString(), '2\n', 'expected value' ); + t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); + } + t.end(); + } +}); + +tape( 'the command-line interface uses a default starting search index of `0`', opts, function test( t ) { + var cmd = [ + EXEC_PATH, + '-e', + '"process.stdin.isTTY = true; process.argv[ 2 ] = \'नुच्छेद\'; require( \''+fpath+'\' );"' + ]; + + exec( cmd.join( ' ' ), done ); + + function done( error, stdout, stderr ) { + if ( error ) { + t.fail( error.message ); + } else { + t.strictEqual( stdout.toString(), '1\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 \'अनुच्छेद\'', + '|', + EXEC_PATH, + fpath, + '--from=1' + ]; + + exec( cmd.join( ' ' ), done ); + + function done( error, stdout, stderr ) { + if ( error ) { + t.fail( error.message ); + } else { + t.strictEqual( stdout.toString(), '2\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/next-code-point/test/test.js b/lib/node_modules/@stdlib/string/next-code-point/test/test.js new file mode 100644 index 000000000000..baa7c5dc935f --- /dev/null +++ b/lib/node_modules/@stdlib/string/next-code-point/test/test.js @@ -0,0 +1,236 @@ +/** +* @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 nextCodePoint = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof nextCodePoint, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if the first argument is not a string (one argument)', function test( t ) { + var values; + var i; + + values = [ + -5, + 3.14, + -1.0, + NaN, + true, + false, + null, + void 0, + [ 'beep', 'boop' ], + [ 1, 2, 3 ], + {}, + 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() { + nextCodePoint( value ); + }; + } +}); + +tape( 'the function throws an error if the first argument is not a string (two arguments)', function test( t ) { + var values; + var i; + + values = [ + -5, + 3.14, + -1.0, + NaN, + true, + false, + null, + void 0, + [ 'beep', 'boop' ], + [ 1, 2, 3 ], + {}, + 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() { + nextCodePoint( value, 0 ); + }; + } +}); + +tape( 'the function throws an error if the second argument is not an integer', function test( t ) { + var values; + var i; + + values = [ + 'bar', + 3.14, + NaN, + null, + void 0, + [ 'beep', 'boop' ], + [ 1, 2, 3 ], + {}, + 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() { + nextCodePoint( 'foo', value ); + }; + } +}); + +tape( 'the function returns the next code point break position in a provided string', function test( t ) { + var out; + + out = nextCodePoint( 'last man standing' ); + t.strictEqual( out, 1, 'returns expected value' ); + + out = nextCodePoint( 'presidential election' ); + t.strictEqual( out, 1, 'returns expected value' ); + + out = nextCodePoint( 'नुच्छेद' ); + t.strictEqual( out, 1, 'returns expected value' ); + + out = nextCodePoint( '\uD800' ); + t.strictEqual( out, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing an index from which to begin searching', function test( t ) { + var out; + + out = nextCodePoint( 'last man standing', 4 ); + t.strictEqual( out, 5, 'returns expected value' ); + + out = nextCodePoint( 'presidential election', 8 ); + t.strictEqual( out, 9, 'returns expected value' ); + + out = nextCodePoint( 'अनुच्छेद', 1 ); + t.strictEqual( out, 2, 'returns expected value' ); + + out = nextCodePoint( '𐒻𐓟𐒻𐓟', 1 ); + t.strictEqual( out, 3, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function supports providing a negative integer for the starting search index', function test( t ) { + var out; + + out = nextCodePoint( 'last man standing', -13 ); + t.strictEqual( out, 5, 'returns expected value' ); + + out = nextCodePoint( 'presidential election', -13 ); + t.strictEqual( out, 9, 'returns expected value' ); + + out = nextCodePoint( 'अनुच्छेद', -7 ); + t.strictEqual( out, 2, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if the starting search index is greater than or equal to the string length', function test( t ) { + var out; + + out = nextCodePoint( 'last man standing', 17 ); + t.strictEqual( out, -1, 'returns expected value' ); + + out = nextCodePoint( 'presidential election', 22 ); + t.strictEqual( out, -1, 'returns expected value' ); + + out = nextCodePoint( 'अनुच्छेद', 10 ); + t.strictEqual( out, -1, 'returns expected value' ); + + out = nextCodePoint( '🌷', 2 ); + t.strictEqual( out, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if the starting search index resides within the last code point of the string', function test( t ) { + var out; + + out = nextCodePoint( 'last man standing', 16 ); + t.strictEqual( out, -1, 'returns expected value' ); + + out = nextCodePoint( 'presidential election', 20 ); + t.strictEqual( out, -1, 'returns expected value' ); + + out = nextCodePoint( 'अनुच्छेद', 7 ); + t.strictEqual( out, -1, 'returns expected value' ); + + out = nextCodePoint( '🌷', 1 ); + t.strictEqual( out, -1, 'returns expected value' ); + + out = nextCodePoint( '🌷' ); + t.strictEqual( out, -1, 'returns expected value' ); + + out = nextCodePoint( '六', 0 ); + t.strictEqual( out, -1, 'returns expected value' ); + + out = nextCodePoint( '六' ); + t.strictEqual( out, -1, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns `-1` if provided an empty string', function test( t ) { + var out; + + out = nextCodePoint( '', -2 ); + t.strictEqual( out, -1, 'returns expected value' ); + + out = nextCodePoint( '', 2 ); + t.strictEqual( out, -1, 'returns expected value' ); + + out = nextCodePoint( '', 0 ); + t.strictEqual( out, -1, 'returns expected value' ); + + out = nextCodePoint( '' ); + t.strictEqual( out, -1, 'returns expected value' ); + + t.end(); +}); From 1e998d8507deabf9ec8ed4cd498e207f99ee30ae Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 30 Oct 2023 21:54:51 -0700 Subject: [PATCH 02/13] Apply suggestions from code review --- lib/node_modules/@stdlib/string/next-code-point/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/string/next-code-point/README.md b/lib/node_modules/@stdlib/string/next-code-point/README.md index 1ae3ba2c255c..c4c205cd876e 100644 --- a/lib/node_modules/@stdlib/string/next-code-point/README.md +++ b/lib/node_modules/@stdlib/string/next-code-point/README.md @@ -20,7 +20,7 @@ limitations under the License. # nextCodePoint -> Return the next code point in a string after a specified position. +> Return the next Unicode code point in a string after a specified position. @@ -42,14 +42,14 @@ var nextCodePoint = require( '@stdlib/string/next-code-point' ); #### nextCodePoint( string\[, fromIndex] ) -Returns the next code point in a string after a specified position. +Returns the next Unicode code point in a string after a specified position. ```javascript var out = nextCodePoint( 'last man standing' ); // returns 1 ``` -By default, the function searches for a grapheme cluster starting from the first index. To specify an alternative starting search index, provide a `fromIndex` argument. +By default, the function searches for a Unicode code point starting from the first index. To specify an alternative starting search index, provide a `fromIndex` argument. ```javascript var out = nextCodePoint( 'last man standing', 4 ); From f13f01824f0be5d58716c6588e09038867ae4a1e Mon Sep 17 00:00:00 2001 From: Stephannie Jimenez Date: Tue, 7 Nov 2023 18:28:28 -0500 Subject: [PATCH 03/13] docs: update example in repl --- .../README.md | 30 ++++----- .../benchmark/benchmark.js | 4 +- .../bin/cli | 6 +- .../docs/repl.txt | 5 +- .../docs/types/index.d.ts | 10 +-- .../docs/types/test.ts | 26 ++++---- .../docs/usage.txt | 2 +- .../etc/cli_opts.json | 0 .../examples/index.js | 12 ++-- .../lib/index.js | 10 +-- .../lib/main.js | 23 ++++--- .../package.json | 6 +- .../test/fixtures/stdin_error.js.txt | 0 .../test/test.cli.js | 0 .../test/test.js | 62 +++++++++---------- 15 files changed, 98 insertions(+), 98 deletions(-) rename lib/node_modules/@stdlib/string/{next-code-point => next-code-point-index}/README.md (81%) rename lib/node_modules/@stdlib/string/{next-code-point => next-code-point-index}/benchmark/benchmark.js (94%) rename lib/node_modules/@stdlib/string/{next-code-point => next-code-point-index}/bin/cli (89%) rename lib/node_modules/@stdlib/string/{next-code-point => next-code-point-index}/docs/repl.txt (82%) rename lib/node_modules/@stdlib/string/{next-code-point => next-code-point-index}/docs/types/index.d.ts (72%) rename lib/node_modules/@stdlib/string/{next-code-point => next-code-point-index}/docs/types/test.ts (52%) rename lib/node_modules/@stdlib/string/{next-code-point => next-code-point-index}/docs/usage.txt (80%) rename lib/node_modules/@stdlib/string/{next-code-point => next-code-point-index}/etc/cli_opts.json (100%) rename lib/node_modules/@stdlib/string/{next-code-point => next-code-point-index}/examples/index.js (68%) rename lib/node_modules/@stdlib/string/{next-code-point => next-code-point-index}/lib/index.js (70%) rename lib/node_modules/@stdlib/string/{next-code-point => next-code-point-index}/lib/main.js (84%) rename lib/node_modules/@stdlib/string/{next-code-point => next-code-point-index}/package.json (86%) rename lib/node_modules/@stdlib/string/{next-code-point => next-code-point-index}/test/fixtures/stdin_error.js.txt (100%) rename lib/node_modules/@stdlib/string/{next-code-point => next-code-point-index}/test/test.cli.js (100%) rename lib/node_modules/@stdlib/string/{next-code-point => next-code-point-index}/test/test.js (74%) diff --git a/lib/node_modules/@stdlib/string/next-code-point/README.md b/lib/node_modules/@stdlib/string/next-code-point-index/README.md similarity index 81% rename from lib/node_modules/@stdlib/string/next-code-point/README.md rename to lib/node_modules/@stdlib/string/next-code-point-index/README.md index c4c205cd876e..1ba01a808a91 100644 --- a/lib/node_modules/@stdlib/string/next-code-point/README.md +++ b/lib/node_modules/@stdlib/string/next-code-point-index/README.md @@ -18,9 +18,9 @@ limitations under the License. --> -# nextCodePoint +# nextCodePointIndex -> Return the next Unicode code point in a string after a specified position. +> Return the position of the next Unicode code point in a string after a specified position. @@ -37,22 +37,22 @@ limitations under the License. ## Usage ```javascript -var nextCodePoint = require( '@stdlib/string/next-code-point' ); +var nextCodePointIndex = require( '@stdlib/string/next-code-point-index' ); ``` -#### nextCodePoint( string\[, fromIndex] ) +#### nextCodePointIndex( string\[, fromIndex] ) -Returns the next Unicode code point in a string after a specified position. +Returns the position of the next Unicode code point in a string after a specified position. ```javascript -var out = nextCodePoint( 'last man standing' ); +var out = nextCodePointIndex( 'last man standing' ); // returns 1 ``` By default, the function searches for a Unicode code point starting from the first index. To specify an alternative starting search index, provide a `fromIndex` argument. ```javascript -var out = nextCodePoint( 'last man standing', 4 ); +var out = nextCodePointIndex( 'last man standing', 4 ); // returns 5 ``` @@ -83,18 +83,18 @@ var out = nextCodePoint( 'last man standing', 4 ); ```javascript -var nextCodePoint = require( '@stdlib/string/next-code-point' ); +var nextCodePointIndex = require( '@stdlib/string/next-code-point-index' ); -var out = nextCodePoint( 'last man standing', 4 ); +var out = nextCodePointIndex( 'last man standing', 4 ); // returns 5 -out = nextCodePoint( 'presidential election', 8 ); +out = nextCodePointIndex( 'presidential election', 8 ); // returns 9 -out = nextCodePoint( 'अनुच्छेद', 1 ); +out = nextCodePointIndex( 'अनुच्छेद', 1 ); // returns 2 -out = nextCodePoint( '🌷', 0 ); +out = nextCodePointIndex( '🌷', 0 ); // returns -1 ``` @@ -117,7 +117,7 @@ out = nextCodePoint( '🌷', 0 ); ### Usage ```text -Usage: next-code-point [options] [] +Usage: next-code-point-index [options] [] Options: @@ -145,14 +145,14 @@ Options: ### Examples ```bash -$ next-code-point --from=1 अनुच्छेद +$ next-code-point-index --from=1 अनुच्छेद 3 ``` To use as a [standard stream][standard-streams], ```bash -$ echo -n 'अनुच्छेद' | next-code-point --from=1 +$ echo -n 'अनुच्छेद' | next-code-point-index --from=1 3 ``` diff --git a/lib/node_modules/@stdlib/string/next-code-point/benchmark/benchmark.js b/lib/node_modules/@stdlib/string/next-code-point-index/benchmark/benchmark.js similarity index 94% rename from lib/node_modules/@stdlib/string/next-code-point/benchmark/benchmark.js rename to lib/node_modules/@stdlib/string/next-code-point-index/benchmark/benchmark.js index 3f3cd0e98699..1eedf93a09db 100644 --- a/lib/node_modules/@stdlib/string/next-code-point/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/string/next-code-point-index/benchmark/benchmark.js @@ -23,7 +23,7 @@ var bench = require( '@stdlib/bench' ); var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; var pkg = require( './../package.json' ).name; -var nextCodePoint = require( './../lib' ); +var nextCodePointIndex = require( './../lib' ); // MAIN // @@ -50,7 +50,7 @@ bench( pkg, function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - out = nextCodePoint( strings[ i%len ], 1 ); + out = nextCodePointIndex( strings[ i%len ], 1 ); if ( out !== out ) { b.fail( 'should not return NaN' ); } diff --git a/lib/node_modules/@stdlib/string/next-code-point/bin/cli b/lib/node_modules/@stdlib/string/next-code-point-index/bin/cli similarity index 89% rename from lib/node_modules/@stdlib/string/next-code-point/bin/cli rename to lib/node_modules/@stdlib/string/next-code-point-index/bin/cli index c23a6472876b..dcc36981b8d1 100755 --- a/lib/node_modules/@stdlib/string/next-code-point/bin/cli +++ b/lib/node_modules/@stdlib/string/next-code-point-index/bin/cli @@ -27,7 +27,7 @@ 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 nextCodePoint = require( './../lib' ); +var nextCodePointIndex = require( './../lib' ); // MAIN // @@ -68,7 +68,7 @@ function main() { // Check if we are receiving data from `stdin`... if ( stdinStream.isTTY ) { - return console.log( nextCodePoint( args[ 0 ], pos ) ); // eslint-disable-line no-console + return console.log( nextCodePointIndex( args[ 0 ], pos ) ); // eslint-disable-line no-console } return stdin( onRead ); @@ -84,7 +84,7 @@ function main() { if ( error ) { return cli.error( error ); } - console.log( nextCodePoint( data.toString(), pos ) ); // eslint-disable-line no-console + console.log( nextCodePointIndex( data.toString(), pos ) ); // eslint-disable-line no-console } } diff --git a/lib/node_modules/@stdlib/string/next-code-point/docs/repl.txt b/lib/node_modules/@stdlib/string/next-code-point-index/docs/repl.txt similarity index 82% rename from lib/node_modules/@stdlib/string/next-code-point/docs/repl.txt rename to lib/node_modules/@stdlib/string/next-code-point-index/docs/repl.txt index ee208803b5a8..5a0be1d23b0d 100644 --- a/lib/node_modules/@stdlib/string/next-code-point/docs/repl.txt +++ b/lib/node_modules/@stdlib/string/next-code-point-index/docs/repl.txt @@ -1,6 +1,7 @@ {{alias}}( str[, fromIndex] ) - Returns the next code point in a string after a specified position. + Returns the position of the next Unicode code point in a string after a + specified position. Parameters ---------- @@ -22,7 +23,7 @@ > out = {{alias}}( 'presidential election', 8 ) 9 > out = {{alias}}( 'अनुच्छेद', 1 ) - 3 + 2 > out = {{alias}}( '🌷' ) -1 diff --git a/lib/node_modules/@stdlib/string/next-code-point/docs/types/index.d.ts b/lib/node_modules/@stdlib/string/next-code-point-index/docs/types/index.d.ts similarity index 72% rename from lib/node_modules/@stdlib/string/next-code-point/docs/types/index.d.ts rename to lib/node_modules/@stdlib/string/next-code-point-index/docs/types/index.d.ts index a4d03a4d2187..213ba28a911a 100644 --- a/lib/node_modules/@stdlib/string/next-code-point/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/string/next-code-point-index/docs/types/index.d.ts @@ -19,7 +19,7 @@ // TypeScript Version: 4.1 /** -* Returns the next code point in a string after a specified position. +* Returns the position of the next Unicode code point in a string after a specified position. * * @param str - input string * @param fromIndex - position (default: 0) @@ -28,15 +28,15 @@ * @returns next code point position * * @example -* var out = nextCodePoint( 'अनुच्छेद', 1 ); +* var out = nextCodePointIndex( 'अनुच्छेद', 1 ); * // returns 3 * -* out = nextCodePoint( '🌷' ); +* out = nextCodePointIndex( '🌷' ); * // returns -1 */ -declare function nextCodePoint( str: string, fromIndex?: number ): number; // tslint:disable-line:max-line-length +declare function nextCodePointIndex( str: string, fromIndex?: number ): number; // tslint:disable-line:max-line-length // EXPORTS // -export = nextCodePoint; +export = nextCodePointIndex; diff --git a/lib/node_modules/@stdlib/string/next-code-point/docs/types/test.ts b/lib/node_modules/@stdlib/string/next-code-point-index/docs/types/test.ts similarity index 52% rename from lib/node_modules/@stdlib/string/next-code-point/docs/types/test.ts rename to lib/node_modules/@stdlib/string/next-code-point-index/docs/types/test.ts index 9e57319488a1..cf9a41076e9d 100644 --- a/lib/node_modules/@stdlib/string/next-code-point/docs/types/test.ts +++ b/lib/node_modules/@stdlib/string/next-code-point-index/docs/types/test.ts @@ -16,32 +16,32 @@ * limitations under the License. */ -import nextCodePoint = require( './index' ); +import nextCodePointIndex = require( './index' ); // TESTS // // The function returns a number... { - nextCodePoint( 'last man standing', 4 ); // $ExpectType number - nextCodePoint( 'presidential election', 8 ); // $ExpectType number - nextCodePoint( 'अनुच्छेद', 1 ); // $ExpectType number - nextCodePoint( '🌷', 0 ); // $ExpectType number + nextCodePointIndex( 'last man standing', 4 ); // $ExpectType number + nextCodePointIndex( 'presidential election', 8 ); // $ExpectType number + nextCodePointIndex( 'अनुच्छेद', 1 ); // $ExpectType number + nextCodePointIndex( '🌷', 0 ); // $ExpectType number } // The compiler throws an error if the function is provided invalid arguments... { - nextCodePoint( false, 3 ); // $ExpectError - nextCodePoint( {}, 3 ); // $ExpectError - nextCodePoint( ( x: number ): number => x, 3 ); // $ExpectError + nextCodePointIndex( false, 3 ); // $ExpectError + nextCodePointIndex( {}, 3 ); // $ExpectError + nextCodePointIndex( ( x: number ): number => x, 3 ); // $ExpectError - nextCodePoint( 'string', true ); // $ExpectError - nextCodePoint( 'string', false ); // $ExpectError - nextCodePoint( 'string', {} ); // $ExpectError - nextCodePoint( 'string', ( x: number ): number => x ); // $ExpectError + nextCodePointIndex( 'string', true ); // $ExpectError + nextCodePointIndex( 'string', false ); // $ExpectError + nextCodePointIndex( 'string', {} ); // $ExpectError + nextCodePointIndex( 'string', ( x: number ): number => x ); // $ExpectError } // The compiler throws an error if the function is provided insufficient arguments... { - nextCodePoint(); // $ExpectError + nextCodePointIndex(); // $ExpectError } diff --git a/lib/node_modules/@stdlib/string/next-code-point/docs/usage.txt b/lib/node_modules/@stdlib/string/next-code-point-index/docs/usage.txt similarity index 80% rename from lib/node_modules/@stdlib/string/next-code-point/docs/usage.txt rename to lib/node_modules/@stdlib/string/next-code-point-index/docs/usage.txt index 69c6b9559752..63c838c6e2a3 100644 --- a/lib/node_modules/@stdlib/string/next-code-point/docs/usage.txt +++ b/lib/node_modules/@stdlib/string/next-code-point-index/docs/usage.txt @@ -1,5 +1,5 @@ -Usage: next-code-point [options] [] +Usage: next-code-point-index [options] [] Options: diff --git a/lib/node_modules/@stdlib/string/next-code-point/etc/cli_opts.json b/lib/node_modules/@stdlib/string/next-code-point-index/etc/cli_opts.json similarity index 100% rename from lib/node_modules/@stdlib/string/next-code-point/etc/cli_opts.json rename to lib/node_modules/@stdlib/string/next-code-point-index/etc/cli_opts.json diff --git a/lib/node_modules/@stdlib/string/next-code-point/examples/index.js b/lib/node_modules/@stdlib/string/next-code-point-index/examples/index.js similarity index 68% rename from lib/node_modules/@stdlib/string/next-code-point/examples/index.js rename to lib/node_modules/@stdlib/string/next-code-point-index/examples/index.js index 9e3e21ee5473..ca8d37ce913c 100644 --- a/lib/node_modules/@stdlib/string/next-code-point/examples/index.js +++ b/lib/node_modules/@stdlib/string/next-code-point-index/examples/index.js @@ -18,16 +18,16 @@ 'use strict'; -var nextCodePoint = require( './../lib' ); +var nextCodePointIndex = require( './../lib' ); -console.log( nextCodePoint( 'last man standing', 4 ) ); +console.log( nextCodePointIndex( 'last man standing', 4 ) ); // => 5 -console.log( nextCodePoint( 'presidential election', 8 ) ); +console.log( nextCodePointIndex( 'presidential election', 8 ) ); // => 9 -console.log( nextCodePoint( 'अनुच्छेद', 1 ) ); -// => 3 +console.log( nextCodePointIndex( 'अनुच्छेद', 1 ) ); +// => 2 -console.log( nextCodePoint( '🌷', 0 ) ); +console.log( nextCodePointIndex( '🌷', 0 ) ); // => -1 diff --git a/lib/node_modules/@stdlib/string/next-code-point/lib/index.js b/lib/node_modules/@stdlib/string/next-code-point-index/lib/index.js similarity index 70% rename from lib/node_modules/@stdlib/string/next-code-point/lib/index.js rename to lib/node_modules/@stdlib/string/next-code-point-index/lib/index.js index 2a0a14823349..27327c4176c7 100644 --- a/lib/node_modules/@stdlib/string/next-code-point/lib/index.js +++ b/lib/node_modules/@stdlib/string/next-code-point-index/lib/index.js @@ -19,17 +19,17 @@ 'use strict'; /** -* Return the next code point break in a string after a specified position. +* Return the position of the next Unicode code point in a string after a specified position. * -* @module @stdlib/string/next-code-point +* @module @stdlib/string/next-code-point-index * * @example -* var nextCodePoint = require( '@stdlib/string/next-code-point' ); +* var nextCodePointIndex = require( '@stdlib/string/next-code-point-index' ); * -* var out = nextCodePoint( 'अनुच्छेद', 1 ); +* var out = nextCodePointIndex( 'अनुच्छेद', 1 ); * // returns 3 * -* out = nextCodePoint( '🌷', 0 ); +* out = nextCodePointIndex( '🌷', 0 ); * // returns -1 */ diff --git a/lib/node_modules/@stdlib/string/next-code-point/lib/main.js b/lib/node_modules/@stdlib/string/next-code-point-index/lib/main.js similarity index 84% rename from lib/node_modules/@stdlib/string/next-code-point/lib/main.js rename to lib/node_modules/@stdlib/string/next-code-point-index/lib/main.js index 175a1304c6f6..4cc509d0af1c 100644 --- a/lib/node_modules/@stdlib/string/next-code-point/lib/main.js +++ b/lib/node_modules/@stdlib/string/next-code-point-index/lib/main.js @@ -34,7 +34,7 @@ var RE_UTF16_HIGH_SURROGATE = /[\uD800-\uDBFF]/; // TODO: replace with stdlib pk // MAIN // /** -* Returns the next code point in a string after a specified position. +* Returns the position of the next Unicode code point in a string after a specified position. * * @param {string} str - input string * @param {integer} [fromIndex=0] - position @@ -43,22 +43,22 @@ var RE_UTF16_HIGH_SURROGATE = /[\uD800-\uDBFF]/; // TODO: replace with stdlib pk * @returns {NonNegativeInteger} next grapheme position * * @example -* var out = nextCodePoint( 'last man standing', 4 ); +* var out = nextCodePointIndex( 'last man standing', 4 ); * // returns 5 * * @example -* var out = nextCodePoint( 'presidential election', 8 ); +* var out = nextCodePointIndex( 'presidential election', 8 ); * // returns 9 * * @example -* var out = nextCodePoint( 'अनुच्छेद', 1 ); -* // returns 3 +* var out = nextCodePointIndex( 'अनुच्छेद', 1 ); +* // returns 2 * * @example -* var out = nextCodePoint( '🌷' ); +* var out = nextCodePointIndex( '🌷' ); * // returns -1 */ -function nextCodePoint( str, fromIndex ) { +function nextCodePointIndex( str, fromIndex ) { var len; var ch1; var ch2; @@ -101,12 +101,11 @@ function nextCodePoint( str, fromIndex ) { } } else { - if( i === len - 1 ) { + if ( i === len - 1 ) { return -1; } - else { - return i; - } + + return i; } } // No more code points: @@ -116,4 +115,4 @@ function nextCodePoint( str, fromIndex ) { // EXPORTS // -module.exports = nextCodePoint; +module.exports = nextCodePointIndex; diff --git a/lib/node_modules/@stdlib/string/next-code-point/package.json b/lib/node_modules/@stdlib/string/next-code-point-index/package.json similarity index 86% rename from lib/node_modules/@stdlib/string/next-code-point/package.json rename to lib/node_modules/@stdlib/string/next-code-point-index/package.json index 2d41491cf9f0..baa059e922b3 100644 --- a/lib/node_modules/@stdlib/string/next-code-point/package.json +++ b/lib/node_modules/@stdlib/string/next-code-point-index/package.json @@ -1,7 +1,7 @@ { - "name": "@stdlib/string/next-code-point", + "name": "@stdlib/string/next-code-point-index", "version": "0.0.0", - "description": "Return the next code point in a string after a specified position.", + "description": "Return the position of the next Unicode code point in a string after a specified position.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", @@ -14,7 +14,7 @@ } ], "bin": { - "next-code-point": "./bin/cli" + "next-code-point-index": "./bin/cli" }, "main": "./lib", "directories": { diff --git a/lib/node_modules/@stdlib/string/next-code-point/test/fixtures/stdin_error.js.txt b/lib/node_modules/@stdlib/string/next-code-point-index/test/fixtures/stdin_error.js.txt similarity index 100% rename from lib/node_modules/@stdlib/string/next-code-point/test/fixtures/stdin_error.js.txt rename to lib/node_modules/@stdlib/string/next-code-point-index/test/fixtures/stdin_error.js.txt diff --git a/lib/node_modules/@stdlib/string/next-code-point/test/test.cli.js b/lib/node_modules/@stdlib/string/next-code-point-index/test/test.cli.js similarity index 100% rename from lib/node_modules/@stdlib/string/next-code-point/test/test.cli.js rename to lib/node_modules/@stdlib/string/next-code-point-index/test/test.cli.js diff --git a/lib/node_modules/@stdlib/string/next-code-point/test/test.js b/lib/node_modules/@stdlib/string/next-code-point-index/test/test.js similarity index 74% rename from lib/node_modules/@stdlib/string/next-code-point/test/test.js rename to lib/node_modules/@stdlib/string/next-code-point-index/test/test.js index baa7c5dc935f..7cb90a9d76a2 100644 --- a/lib/node_modules/@stdlib/string/next-code-point/test/test.js +++ b/lib/node_modules/@stdlib/string/next-code-point-index/test/test.js @@ -21,14 +21,14 @@ // MODULES // var tape = require( 'tape' ); -var nextCodePoint = require( './../lib' ); +var nextCodePointIndex = require( './../lib' ); // TESTS // tape( 'main export is a function', function test( t ) { t.ok( true, __filename ); - t.strictEqual( typeof nextCodePoint, 'function', 'main export is a function' ); + t.strictEqual( typeof nextCodePointIndex, 'function', 'main export is a function' ); t.end(); }); @@ -58,7 +58,7 @@ tape( 'the function throws an error if the first argument is not a string (one a function badValue( value ) { return function badValue() { - nextCodePoint( value ); + nextCodePointIndex( value ); }; } }); @@ -89,7 +89,7 @@ tape( 'the function throws an error if the first argument is not a string (two a function badValue( value ) { return function badValue() { - nextCodePoint( value, 0 ); + nextCodePointIndex( value, 0 ); }; } }); @@ -116,7 +116,7 @@ tape( 'the function throws an error if the second argument is not an integer', f function badValue( value ) { return function badValue() { - nextCodePoint( 'foo', value ); + nextCodePointIndex( 'foo', value ); }; } }); @@ -124,16 +124,16 @@ tape( 'the function throws an error if the second argument is not an integer', f tape( 'the function returns the next code point break position in a provided string', function test( t ) { var out; - out = nextCodePoint( 'last man standing' ); + out = nextCodePointIndex( 'last man standing' ); t.strictEqual( out, 1, 'returns expected value' ); - out = nextCodePoint( 'presidential election' ); + out = nextCodePointIndex( 'presidential election' ); t.strictEqual( out, 1, 'returns expected value' ); - out = nextCodePoint( 'नुच्छेद' ); + out = nextCodePointIndex( 'नुच्छेद' ); t.strictEqual( out, 1, 'returns expected value' ); - out = nextCodePoint( '\uD800' ); + out = nextCodePointIndex( '\uD800' ); t.strictEqual( out, -1, 'returns expected value' ); t.end(); @@ -142,16 +142,16 @@ tape( 'the function returns the next code point break position in a provided str tape( 'the function supports providing an index from which to begin searching', function test( t ) { var out; - out = nextCodePoint( 'last man standing', 4 ); + out = nextCodePointIndex( 'last man standing', 4 ); t.strictEqual( out, 5, 'returns expected value' ); - out = nextCodePoint( 'presidential election', 8 ); + out = nextCodePointIndex( 'presidential election', 8 ); t.strictEqual( out, 9, 'returns expected value' ); - out = nextCodePoint( 'अनुच्छेद', 1 ); + out = nextCodePointIndex( 'अनुच्छेद', 1 ); t.strictEqual( out, 2, 'returns expected value' ); - out = nextCodePoint( '𐒻𐓟𐒻𐓟', 1 ); + out = nextCodePointIndex( '𐒻𐓟𐒻𐓟', 1 ); t.strictEqual( out, 3, 'returns expected value' ); t.end(); @@ -160,13 +160,13 @@ tape( 'the function supports providing an index from which to begin searching', tape( 'the function supports providing a negative integer for the starting search index', function test( t ) { var out; - out = nextCodePoint( 'last man standing', -13 ); + out = nextCodePointIndex( 'last man standing', -13 ); t.strictEqual( out, 5, 'returns expected value' ); - out = nextCodePoint( 'presidential election', -13 ); + out = nextCodePointIndex( 'presidential election', -13 ); t.strictEqual( out, 9, 'returns expected value' ); - out = nextCodePoint( 'अनुच्छेद', -7 ); + out = nextCodePointIndex( 'अनुच्छेद', -7 ); t.strictEqual( out, 2, 'returns expected value' ); t.end(); @@ -175,16 +175,16 @@ tape( 'the function supports providing a negative integer for the starting searc tape( 'the function returns `-1` if the starting search index is greater than or equal to the string length', function test( t ) { var out; - out = nextCodePoint( 'last man standing', 17 ); + out = nextCodePointIndex( 'last man standing', 17 ); t.strictEqual( out, -1, 'returns expected value' ); - out = nextCodePoint( 'presidential election', 22 ); + out = nextCodePointIndex( 'presidential election', 22 ); t.strictEqual( out, -1, 'returns expected value' ); - out = nextCodePoint( 'अनुच्छेद', 10 ); + out = nextCodePointIndex( 'अनुच्छेद', 10 ); t.strictEqual( out, -1, 'returns expected value' ); - out = nextCodePoint( '🌷', 2 ); + out = nextCodePointIndex( '🌷', 2 ); t.strictEqual( out, -1, 'returns expected value' ); t.end(); @@ -193,25 +193,25 @@ tape( 'the function returns `-1` if the starting search index is greater than or tape( 'the function returns `-1` if the starting search index resides within the last code point of the string', function test( t ) { var out; - out = nextCodePoint( 'last man standing', 16 ); + out = nextCodePointIndex( 'last man standing', 16 ); t.strictEqual( out, -1, 'returns expected value' ); - out = nextCodePoint( 'presidential election', 20 ); + out = nextCodePointIndex( 'presidential election', 20 ); t.strictEqual( out, -1, 'returns expected value' ); - out = nextCodePoint( 'अनुच्छेद', 7 ); + out = nextCodePointIndex( 'अनुच्छेद', 7 ); t.strictEqual( out, -1, 'returns expected value' ); - out = nextCodePoint( '🌷', 1 ); + out = nextCodePointIndex( '🌷', 1 ); t.strictEqual( out, -1, 'returns expected value' ); - out = nextCodePoint( '🌷' ); + out = nextCodePointIndex( '🌷' ); t.strictEqual( out, -1, 'returns expected value' ); - out = nextCodePoint( '六', 0 ); + out = nextCodePointIndex( '六', 0 ); t.strictEqual( out, -1, 'returns expected value' ); - out = nextCodePoint( '六' ); + out = nextCodePointIndex( '六' ); t.strictEqual( out, -1, 'returns expected value' ); t.end(); @@ -220,16 +220,16 @@ tape( 'the function returns `-1` if the starting search index resides within the tape( 'the function returns `-1` if provided an empty string', function test( t ) { var out; - out = nextCodePoint( '', -2 ); + out = nextCodePointIndex( '', -2 ); t.strictEqual( out, -1, 'returns expected value' ); - out = nextCodePoint( '', 2 ); + out = nextCodePointIndex( '', 2 ); t.strictEqual( out, -1, 'returns expected value' ); - out = nextCodePoint( '', 0 ); + out = nextCodePointIndex( '', 0 ); t.strictEqual( out, -1, 'returns expected value' ); - out = nextCodePoint( '' ); + out = nextCodePointIndex( '' ); t.strictEqual( out, -1, 'returns expected value' ); t.end(); From 3ee3c46f0e83329c4a3d0585ce0ae11537fdbf8c Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 8 Nov 2023 13:33:15 -0800 Subject: [PATCH 04/13] Apply suggestions from code review --- .../@stdlib/string/next-code-point-index/README.md | 14 +------------- .../string/next-code-point-index/lib/main.js | 3 +-- .../test/fixtures/stdin_error.js.txt | 2 +- 3 files changed, 3 insertions(+), 16 deletions(-) diff --git a/lib/node_modules/@stdlib/string/next-code-point-index/README.md b/lib/node_modules/@stdlib/string/next-code-point-index/README.md index 1ba01a808a91..d368d2cd2106 100644 --- a/lib/node_modules/@stdlib/string/next-code-point-index/README.md +++ b/lib/node_modules/@stdlib/string/next-code-point-index/README.md @@ -67,7 +67,7 @@ var out = nextCodePointIndex( 'last man standing', 4 ); ## Notes - If `string` is an empty string, the function returns `-1` irrespective of `fromIndex`. -- If an code point does not exist after `fromIndex`, the function returns `-1`. +- If a code point does not exist after `fromIndex`, the function returns `-1`. - Note that `fromIndex` does **not** refer to a visual character position, but to an index in the ordered sequence of [UTF-16][utf-16] code units. @@ -176,12 +176,6 @@ $ echo -n 'अनुच्छेद' | next-code-point-index --from=1 @@ -194,12 +188,6 @@ $ echo -n 'अनुच्छेद' | next-code-point-index --from=1 [utf-16]: https://en.wikipedia.org/wiki/UTF-16 - - -[@stdlib/string/num-grapheme-clusters]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/num-grapheme-clusters - - - diff --git a/lib/node_modules/@stdlib/string/next-code-point-index/lib/main.js b/lib/node_modules/@stdlib/string/next-code-point-index/lib/main.js index 4cc509d0af1c..e65998c44b67 100644 --- a/lib/node_modules/@stdlib/string/next-code-point-index/lib/main.js +++ b/lib/node_modules/@stdlib/string/next-code-point-index/lib/main.js @@ -99,8 +99,7 @@ function nextCodePointIndex( str, fromIndex ) { // We found a surrogate pair: return i + 1; } - } - else { + } else { if ( i === len - 1 ) { return -1; } diff --git a/lib/node_modules/@stdlib/string/next-code-point-index/test/fixtures/stdin_error.js.txt b/lib/node_modules/@stdlib/string/next-code-point-index/test/fixtures/stdin_error.js.txt index 103efa254ed3..b42c70b3b554 100644 --- a/lib/node_modules/@stdlib/string/next-code-point-index/test/fixtures/stdin_error.js.txt +++ b/lib/node_modules/@stdlib/string/next-code-point-index/test/fixtures/stdin_error.js.txt @@ -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. From 40c63c57ef940e5a85a02e36844782f5efbde85b Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 8 Nov 2023 13:33:59 -0800 Subject: [PATCH 05/13] Apply suggestions from code review --- .../@stdlib/string/next-code-point-index/lib/main.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/string/next-code-point-index/lib/main.js b/lib/node_modules/@stdlib/string/next-code-point-index/lib/main.js index e65998c44b67..743ea1cb54d1 100644 --- a/lib/node_modules/@stdlib/string/next-code-point-index/lib/main.js +++ b/lib/node_modules/@stdlib/string/next-code-point-index/lib/main.js @@ -103,7 +103,6 @@ function nextCodePointIndex( str, fromIndex ) { if ( i === len - 1 ) { return -1; } - return i; } } From 0acb4ba2eb7528c05292b4abe63af54d81e72d56 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 8 Nov 2023 13:35:58 -0800 Subject: [PATCH 06/13] Apply suggestions from code review --- .../@stdlib/string/next-code-point-index/lib/main.js | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/node_modules/@stdlib/string/next-code-point-index/lib/main.js b/lib/node_modules/@stdlib/string/next-code-point-index/lib/main.js index 743ea1cb54d1..e956205aefa1 100644 --- a/lib/node_modules/@stdlib/string/next-code-point-index/lib/main.js +++ b/lib/node_modules/@stdlib/string/next-code-point-index/lib/main.js @@ -60,8 +60,6 @@ var RE_UTF16_HIGH_SURROGATE = /[\uD800-\uDBFF]/; // TODO: replace with stdlib pk */ function nextCodePointIndex( str, fromIndex ) { var len; - var ch1; - var ch2; var idx; var i; @@ -89,13 +87,10 @@ function nextCodePointIndex( str, fromIndex ) { // Begin searching for the next code point ... for ( i = idx + 1; i < len; 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 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: return i + 1; } From cf6061774b7324b2690382ae7621ecd6acbfa3a4 Mon Sep 17 00:00:00 2001 From: Athan Date: Wed, 8 Nov 2023 13:38:16 -0800 Subject: [PATCH 07/13] Apply suggestions from code review --- .../@stdlib/string/next-code-point-index/docs/types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/string/next-code-point-index/docs/types/index.d.ts b/lib/node_modules/@stdlib/string/next-code-point-index/docs/types/index.d.ts index 213ba28a911a..446e4ccfe8e4 100644 --- a/lib/node_modules/@stdlib/string/next-code-point-index/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/string/next-code-point-index/docs/types/index.d.ts @@ -34,7 +34,7 @@ * out = nextCodePointIndex( '🌷' ); * // returns -1 */ -declare function nextCodePointIndex( str: string, fromIndex?: number ): number; // tslint:disable-line:max-line-length +declare function nextCodePointIndex( str: string, fromIndex?: number ): number; // EXPORTS // From 6e419e314a1262ac1500403d172d2d497dc51cda Mon Sep 17 00:00:00 2001 From: Stephannie Jimenez Date: Fri, 10 Nov 2023 14:37:29 -0500 Subject: [PATCH 08/13] fix: add case for unpaired high surrogate with tests --- .../string/next-code-point-index/README.md | 8 ++++---- .../string/next-code-point-index/docs/repl.txt | 4 ++-- .../next-code-point-index/docs/types/index.d.ts | 2 +- .../next-code-point-index/examples/index.js | 4 ++-- .../string/next-code-point-index/lib/index.js | 2 +- .../string/next-code-point-index/lib/main.js | 15 +++++++++------ .../string/next-code-point-index/test/test.js | 6 ++++++ 7 files changed, 25 insertions(+), 16 deletions(-) diff --git a/lib/node_modules/@stdlib/string/next-code-point-index/README.md b/lib/node_modules/@stdlib/string/next-code-point-index/README.md index d368d2cd2106..7de508d90598 100644 --- a/lib/node_modules/@stdlib/string/next-code-point-index/README.md +++ b/lib/node_modules/@stdlib/string/next-code-point-index/README.md @@ -91,8 +91,8 @@ var out = nextCodePointIndex( 'last man standing', 4 ); out = nextCodePointIndex( 'presidential election', 8 ); // returns 9 -out = nextCodePointIndex( 'अनुच्छेद', 1 ); -// returns 2 +out = nextCodePointIndex( '𐒻𐓟𐒻𐓟', 1 ); +// returns 3 out = nextCodePointIndex( '🌷', 0 ); // returns -1 @@ -145,14 +145,14 @@ Options: ### Examples ```bash -$ next-code-point-index --from=1 अनुच्छेद +$ next-code-point-index --from=1 𐒻𐓟𐒻𐓟 3 ``` To use as a [standard stream][standard-streams], ```bash -$ echo -n 'अनुच्छेद' | next-code-point-index --from=1 +$ echo -n '𐒻𐓟𐒻𐓟' | next-code-point-index --from=1 3 ``` diff --git a/lib/node_modules/@stdlib/string/next-code-point-index/docs/repl.txt b/lib/node_modules/@stdlib/string/next-code-point-index/docs/repl.txt index 5a0be1d23b0d..de9089c2c045 100644 --- a/lib/node_modules/@stdlib/string/next-code-point-index/docs/repl.txt +++ b/lib/node_modules/@stdlib/string/next-code-point-index/docs/repl.txt @@ -22,8 +22,8 @@ 5 > out = {{alias}}( 'presidential election', 8 ) 9 - > out = {{alias}}( 'अनुच्छेद', 1 ) - 2 + > out = {{alias}}( '𐒻𐓟𐒻𐓟', 1 ) + 3 > out = {{alias}}( '🌷' ) -1 diff --git a/lib/node_modules/@stdlib/string/next-code-point-index/docs/types/index.d.ts b/lib/node_modules/@stdlib/string/next-code-point-index/docs/types/index.d.ts index 446e4ccfe8e4..4507b77c900d 100644 --- a/lib/node_modules/@stdlib/string/next-code-point-index/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/string/next-code-point-index/docs/types/index.d.ts @@ -28,7 +28,7 @@ * @returns next code point position * * @example -* var out = nextCodePointIndex( 'अनुच्छेद', 1 ); +* var out = nextCodePointIndex( '𐒻𐓟𐒻𐓟', 1 ); * // returns 3 * * out = nextCodePointIndex( '🌷' ); diff --git a/lib/node_modules/@stdlib/string/next-code-point-index/examples/index.js b/lib/node_modules/@stdlib/string/next-code-point-index/examples/index.js index ca8d37ce913c..bd5f7d7361da 100644 --- a/lib/node_modules/@stdlib/string/next-code-point-index/examples/index.js +++ b/lib/node_modules/@stdlib/string/next-code-point-index/examples/index.js @@ -26,8 +26,8 @@ console.log( nextCodePointIndex( 'last man standing', 4 ) ); console.log( nextCodePointIndex( 'presidential election', 8 ) ); // => 9 -console.log( nextCodePointIndex( 'अनुच्छेद', 1 ) ); -// => 2 +console.log( nextCodePointIndex( '𐒻𐓟𐒻𐓟', 1 ) ); +// => 3 console.log( nextCodePointIndex( '🌷', 0 ) ); // => -1 diff --git a/lib/node_modules/@stdlib/string/next-code-point-index/lib/index.js b/lib/node_modules/@stdlib/string/next-code-point-index/lib/index.js index 27327c4176c7..b45fabdf28cc 100644 --- a/lib/node_modules/@stdlib/string/next-code-point-index/lib/index.js +++ b/lib/node_modules/@stdlib/string/next-code-point-index/lib/index.js @@ -26,7 +26,7 @@ * @example * var nextCodePointIndex = require( '@stdlib/string/next-code-point-index' ); * -* var out = nextCodePointIndex( 'अनुच्छेद', 1 ); +* var out = nextCodePointIndex( '𐒻𐓟𐒻𐓟', 1 ); * // returns 3 * * out = nextCodePointIndex( '🌷', 0 ); diff --git a/lib/node_modules/@stdlib/string/next-code-point-index/lib/main.js b/lib/node_modules/@stdlib/string/next-code-point-index/lib/main.js index e956205aefa1..56623305926f 100644 --- a/lib/node_modules/@stdlib/string/next-code-point-index/lib/main.js +++ b/lib/node_modules/@stdlib/string/next-code-point-index/lib/main.js @@ -51,8 +51,8 @@ var RE_UTF16_HIGH_SURROGATE = /[\uD800-\uDBFF]/; // TODO: replace with stdlib pk * // returns 9 * * @example -* var out = nextCodePointIndex( 'अनुच्छेद', 1 ); -* // returns 2 +* var out = nextCodePointIndex( '𐒻𐓟𐒻𐓟', 1 ); +* // returns 3 * * @example * var out = nextCodePointIndex( '🌷' ); @@ -94,12 +94,15 @@ function nextCodePointIndex( str, fromIndex ) { // We found a surrogate pair: return i + 1; } - } else { - if ( i === len - 1 ) { - return -1; + if ( i !== len - 1 ) { + return i; } - return i; + return -1; } + if ( i === len - 1 ) { + return -1; + } + return i; } // No more code points: return -1; diff --git a/lib/node_modules/@stdlib/string/next-code-point-index/test/test.js b/lib/node_modules/@stdlib/string/next-code-point-index/test/test.js index 7cb90a9d76a2..06abde0d2824 100644 --- a/lib/node_modules/@stdlib/string/next-code-point-index/test/test.js +++ b/lib/node_modules/@stdlib/string/next-code-point-index/test/test.js @@ -154,6 +154,12 @@ tape( 'the function supports providing an index from which to begin searching', out = nextCodePointIndex( '𐒻𐓟𐒻𐓟', 1 ); t.strictEqual( out, 3, 'returns expected value' ); + out = nextCodePointIndex( 'a\uDBFFaaaaaaa', 0 ); + t.strictEqual( out, 1, 'returns expected value' ); + + out = nextCodePointIndex( 'a\uDBFF', 0 ); + t.strictEqual( out, -1, 'returns expected value' ); + t.end(); }); From 1c06df1602513359dc79e3bb386723e13ea68821 Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 10 Nov 2023 12:28:34 -0800 Subject: [PATCH 09/13] Apply suggestions from code review --- .../@stdlib/string/next-code-point-index/lib/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/string/next-code-point-index/lib/main.js b/lib/node_modules/@stdlib/string/next-code-point-index/lib/main.js index 56623305926f..95573359bd10 100644 --- a/lib/node_modules/@stdlib/string/next-code-point-index/lib/main.js +++ b/lib/node_modules/@stdlib/string/next-code-point-index/lib/main.js @@ -40,7 +40,7 @@ var RE_UTF16_HIGH_SURROGATE = /[\uD800-\uDBFF]/; // TODO: replace with stdlib pk * @param {integer} [fromIndex=0] - position * @throws {TypeError} first argument must be a string * @throws {TypeError} second argument must be an integer -* @returns {NonNegativeInteger} next grapheme position +* @returns {Integer} position of the next Unicode code point * * @example * var out = nextCodePointIndex( 'last man standing', 4 ); @@ -90,7 +90,7 @@ function nextCodePointIndex( str, fromIndex ) { // Check for a high UTF-16 surrogate... if ( RE_UTF16_HIGH_SURROGATE.test( str[ i ] ) ) { // Check whether the high surrogate is paired with a low surrogate... - if ( RE_UTF16_LOW_SURROGATE.test( str[ i+1 ] ) ) { + if ( i < len-1 && RE_UTF16_LOW_SURROGATE.test( str[ i+1 ] ) ) { // We found a surrogate pair: return i + 1; } From 0f08e635aaff2a92c9114dd720da1b1310f28e2d Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 10 Nov 2023 12:45:36 -0800 Subject: [PATCH 10/13] refactor: update implementation to avoid for loop --- .../string/next-code-point-index/lib/main.js | 32 +++++++------------ 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/lib/node_modules/@stdlib/string/next-code-point-index/lib/main.js b/lib/node_modules/@stdlib/string/next-code-point-index/lib/main.js index 95573359bd10..a5b476bac781 100644 --- a/lib/node_modules/@stdlib/string/next-code-point-index/lib/main.js +++ b/lib/node_modules/@stdlib/string/next-code-point-index/lib/main.js @@ -59,6 +59,7 @@ var RE_UTF16_HIGH_SURROGATE = /[\uD800-\uDBFF]/; // TODO: replace with stdlib pk * // returns -1 */ function nextCodePointIndex( str, fromIndex ) { + var lastIndex; var len; var idx; var i; @@ -81,31 +82,22 @@ function nextCodePointIndex( str, fromIndex ) { idx = 0; } } - if ( len === 0 || idx >= len ) { + lastIndex = len - 1; + if ( idx >= lastIndex ) { return -1; - } + } - // Begin searching for the next code point ... - for ( i = idx + 1; i < len; i++ ) { - // Check for a high UTF-16 surrogate... - if ( RE_UTF16_HIGH_SURROGATE.test( str[ i ] ) ) { - // Check whether the high surrogate is paired with a low surrogate... - if ( i < len-1 && RE_UTF16_LOW_SURROGATE.test( str[ i+1 ] ) ) { - // We found a surrogate pair: - return i + 1; - } - if ( i !== len - 1 ) { - return i; - } - return -1; - } - if ( i === len - 1 ) { - return -1; + // Check for a high UTF-16 surrogate... + i = idx + 1; + if ( RE_UTF16_HIGH_SURROGATE.test( str[ idx ] ) ) { + // Check whether the high surrogate is paired with a low surrogate... + if ( RE_UTF16_LOW_SURROGATE.test( str[ i ] ) ) { + // We found a surrogate pair: + return i + 1; } return i; } - // No more code points: - return -1; + return i; } From ddd8b1c81e09056d8ce1dc3636fba1d30c0598ef Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 10 Nov 2023 12:49:06 -0800 Subject: [PATCH 11/13] Apply suggestions from code review --- .../@stdlib/string/next-code-point-index/test/test.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/node_modules/@stdlib/string/next-code-point-index/test/test.js b/lib/node_modules/@stdlib/string/next-code-point-index/test/test.js index 06abde0d2824..129885905b1f 100644 --- a/lib/node_modules/@stdlib/string/next-code-point-index/test/test.js +++ b/lib/node_modules/@stdlib/string/next-code-point-index/test/test.js @@ -121,7 +121,7 @@ tape( 'the function throws an error if the second argument is not an integer', f } }); -tape( 'the function returns the next code point break position in a provided string', function test( t ) { +tape( 'the function returns the next code point position in a provided string', function test( t ) { var out; out = nextCodePointIndex( 'last man standing' ); @@ -133,7 +133,7 @@ tape( 'the function returns the next code point break position in a provided str out = nextCodePointIndex( 'नुच्छेद' ); t.strictEqual( out, 1, 'returns expected value' ); - out = nextCodePointIndex( '\uD800' ); + out = nextCodePointIndex( '\uD800' ); // unpaired ending high surrogate t.strictEqual( out, -1, 'returns expected value' ); t.end(); @@ -154,11 +154,11 @@ tape( 'the function supports providing an index from which to begin searching', out = nextCodePointIndex( '𐒻𐓟𐒻𐓟', 1 ); t.strictEqual( out, 3, 'returns expected value' ); - out = nextCodePointIndex( 'a\uDBFFaaaaaaa', 0 ); + out = nextCodePointIndex( 'a\uDBFFaaaaaaa', 0 ); // unpaired high surrogate t.strictEqual( out, 1, 'returns expected value' ); - out = nextCodePointIndex( 'a\uDBFF', 0 ); - t.strictEqual( out, -1, 'returns expected value' ); + out = nextCodePointIndex( 'a\uDBFF', 0 ); // unpaired ending high surrogate + t.strictEqual( out, 1, 'returns expected value' ); t.end(); }); From 392881b2b247a09c228c0e33c6a50634d4f2d68c Mon Sep 17 00:00:00 2001 From: Athan Date: Fri, 10 Nov 2023 13:00:04 -0800 Subject: [PATCH 12/13] fix: address bug when surrogate pair comprises the entire string --- .../@stdlib/string/next-code-point-index/lib/main.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/string/next-code-point-index/lib/main.js b/lib/node_modules/@stdlib/string/next-code-point-index/lib/main.js index a5b476bac781..8e4d80d7896c 100644 --- a/lib/node_modules/@stdlib/string/next-code-point-index/lib/main.js +++ b/lib/node_modules/@stdlib/string/next-code-point-index/lib/main.js @@ -63,6 +63,7 @@ function nextCodePointIndex( str, fromIndex ) { var len; var idx; var i; + var j; if ( !isString( str ) ) { throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); @@ -85,15 +86,16 @@ function nextCodePointIndex( str, fromIndex ) { lastIndex = len - 1; if ( idx >= lastIndex ) { return -1; - } + } // Check for a high UTF-16 surrogate... - i = idx + 1; + i = idx + 1; + j = i + 1; if ( RE_UTF16_HIGH_SURROGATE.test( str[ idx ] ) ) { // Check whether the high surrogate is paired with a low surrogate... if ( RE_UTF16_LOW_SURROGATE.test( str[ i ] ) ) { // We found a surrogate pair: - return i + 1; + return ( j === lastIndex ) ? -1 : j; } return i; } From 7857375cdfda1f8c19dae26de50f1c960f2ba44f Mon Sep 17 00:00:00 2001 From: Stephannie Jimenez Date: Fri, 10 Nov 2023 16:09:16 -0500 Subject: [PATCH 13/13] fix: update examples, fix tests and bug when a paired surrogate is at the end of the string --- .../@stdlib/string/next-code-point-index/README.md | 12 ++++++------ .../string/next-code-point-index/docs/repl.txt | 4 ++-- .../next-code-point-index/docs/types/index.d.ts | 4 ++-- .../string/next-code-point-index/examples/index.js | 4 ++-- .../string/next-code-point-index/lib/index.js | 4 ++-- .../@stdlib/string/next-code-point-index/lib/main.js | 8 ++++---- .../string/next-code-point-index/test/test.js | 4 ++-- 7 files changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/node_modules/@stdlib/string/next-code-point-index/README.md b/lib/node_modules/@stdlib/string/next-code-point-index/README.md index 7de508d90598..970341192f4f 100644 --- a/lib/node_modules/@stdlib/string/next-code-point-index/README.md +++ b/lib/node_modules/@stdlib/string/next-code-point-index/README.md @@ -91,8 +91,8 @@ var out = nextCodePointIndex( 'last man standing', 4 ); out = nextCodePointIndex( 'presidential election', 8 ); // returns 9 -out = nextCodePointIndex( '𐒻𐓟𐒻𐓟', 1 ); -// returns 3 +out = nextCodePointIndex( '𐒻𐓟𐒻𐓟', 0 ); +// returns 2 out = nextCodePointIndex( '🌷', 0 ); // returns -1 @@ -145,15 +145,15 @@ Options: ### Examples ```bash -$ next-code-point-index --from=1 𐒻𐓟𐒻𐓟 -3 +$ next-code-point-index --from=0 𐒻𐓟𐒻𐓟 +2 ``` To use as a [standard stream][standard-streams], ```bash -$ echo -n '𐒻𐓟𐒻𐓟' | next-code-point-index --from=1 -3 +$ echo -n '𐒻𐓟𐒻𐓟' | next-code-point-index --from=0 +2 ``` diff --git a/lib/node_modules/@stdlib/string/next-code-point-index/docs/repl.txt b/lib/node_modules/@stdlib/string/next-code-point-index/docs/repl.txt index de9089c2c045..15203eb6068a 100644 --- a/lib/node_modules/@stdlib/string/next-code-point-index/docs/repl.txt +++ b/lib/node_modules/@stdlib/string/next-code-point-index/docs/repl.txt @@ -22,8 +22,8 @@ 5 > out = {{alias}}( 'presidential election', 8 ) 9 - > out = {{alias}}( '𐒻𐓟𐒻𐓟', 1 ) - 3 + > out = {{alias}}( '𐒻𐓟𐒻𐓟', 0 ) + 2 > out = {{alias}}( '🌷' ) -1 diff --git a/lib/node_modules/@stdlib/string/next-code-point-index/docs/types/index.d.ts b/lib/node_modules/@stdlib/string/next-code-point-index/docs/types/index.d.ts index 4507b77c900d..986bcf2539d0 100644 --- a/lib/node_modules/@stdlib/string/next-code-point-index/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/string/next-code-point-index/docs/types/index.d.ts @@ -28,8 +28,8 @@ * @returns next code point position * * @example -* var out = nextCodePointIndex( '𐒻𐓟𐒻𐓟', 1 ); -* // returns 3 +* var out = nextCodePointIndex( '𐒻𐓟𐒻𐓟', 0 ); +* // returns 2 * * out = nextCodePointIndex( '🌷' ); * // returns -1 diff --git a/lib/node_modules/@stdlib/string/next-code-point-index/examples/index.js b/lib/node_modules/@stdlib/string/next-code-point-index/examples/index.js index bd5f7d7361da..a034f6f7b746 100644 --- a/lib/node_modules/@stdlib/string/next-code-point-index/examples/index.js +++ b/lib/node_modules/@stdlib/string/next-code-point-index/examples/index.js @@ -26,8 +26,8 @@ console.log( nextCodePointIndex( 'last man standing', 4 ) ); console.log( nextCodePointIndex( 'presidential election', 8 ) ); // => 9 -console.log( nextCodePointIndex( '𐒻𐓟𐒻𐓟', 1 ) ); -// => 3 +console.log( nextCodePointIndex( '𐒻𐓟𐒻𐓟', 0 ) ); +// => 2 console.log( nextCodePointIndex( '🌷', 0 ) ); // => -1 diff --git a/lib/node_modules/@stdlib/string/next-code-point-index/lib/index.js b/lib/node_modules/@stdlib/string/next-code-point-index/lib/index.js index b45fabdf28cc..716736f8ac9c 100644 --- a/lib/node_modules/@stdlib/string/next-code-point-index/lib/index.js +++ b/lib/node_modules/@stdlib/string/next-code-point-index/lib/index.js @@ -26,8 +26,8 @@ * @example * var nextCodePointIndex = require( '@stdlib/string/next-code-point-index' ); * -* var out = nextCodePointIndex( '𐒻𐓟𐒻𐓟', 1 ); -* // returns 3 +* var out = nextCodePointIndex( '𐒻𐓟𐒻𐓟', 0 ); +* // returns 2 * * out = nextCodePointIndex( '🌷', 0 ); * // returns -1 diff --git a/lib/node_modules/@stdlib/string/next-code-point-index/lib/main.js b/lib/node_modules/@stdlib/string/next-code-point-index/lib/main.js index 8e4d80d7896c..d0ffffc10860 100644 --- a/lib/node_modules/@stdlib/string/next-code-point-index/lib/main.js +++ b/lib/node_modules/@stdlib/string/next-code-point-index/lib/main.js @@ -40,7 +40,7 @@ var RE_UTF16_HIGH_SURROGATE = /[\uD800-\uDBFF]/; // TODO: replace with stdlib pk * @param {integer} [fromIndex=0] - position * @throws {TypeError} first argument must be a string * @throws {TypeError} second argument must be an integer -* @returns {Integer} position of the next Unicode code point +* @returns {integer} position of the next Unicode code point * * @example * var out = nextCodePointIndex( 'last man standing', 4 ); @@ -51,8 +51,8 @@ var RE_UTF16_HIGH_SURROGATE = /[\uD800-\uDBFF]/; // TODO: replace with stdlib pk * // returns 9 * * @example -* var out = nextCodePointIndex( '𐒻𐓟𐒻𐓟', 1 ); -* // returns 3 +* var out = nextCodePointIndex( '𐒻𐓟𐒻𐓟', 0 ); +* // returns 2 * * @example * var out = nextCodePointIndex( '🌷' ); @@ -95,7 +95,7 @@ function nextCodePointIndex( str, fromIndex ) { // Check whether the high surrogate is paired with a low surrogate... if ( RE_UTF16_LOW_SURROGATE.test( str[ i ] ) ) { // We found a surrogate pair: - return ( j === lastIndex ) ? -1 : j; + return ( j >= lastIndex ) ? -1 : j; } return i; } diff --git a/lib/node_modules/@stdlib/string/next-code-point-index/test/test.js b/lib/node_modules/@stdlib/string/next-code-point-index/test/test.js index 129885905b1f..7a95ca27c23a 100644 --- a/lib/node_modules/@stdlib/string/next-code-point-index/test/test.js +++ b/lib/node_modules/@stdlib/string/next-code-point-index/test/test.js @@ -151,8 +151,8 @@ tape( 'the function supports providing an index from which to begin searching', out = nextCodePointIndex( 'अनुच्छेद', 1 ); t.strictEqual( out, 2, 'returns expected value' ); - out = nextCodePointIndex( '𐒻𐓟𐒻𐓟', 1 ); - t.strictEqual( out, 3, 'returns expected value' ); + out = nextCodePointIndex( '𐒻𐓟𐒻𐓟', 0 ); + t.strictEqual( out, 2, 'returns expected value' ); out = nextCodePointIndex( 'a\uDBFFaaaaaaa', 0 ); // unpaired high surrogate t.strictEqual( out, 1, 'returns expected value' );