From dda2690306e1e774f172f7d7ee3786fcef5d6360 Mon Sep 17 00:00:00 2001 From: Stephannie Jimenez Date: Sat, 12 Aug 2023 00:10:43 -0500 Subject: [PATCH 1/9] feat: create reverse base packages and refactor main string package --- .../string/base/reverse-code-point/README.md | 92 ++++++++++ .../reverse-code-point/benchmark/benchmark.js | 56 ++++++ .../base/reverse-code-point/docs/repl.txt | 26 +++ .../reverse-code-point/docs/types/index.d.ts | 52 ++++++ .../reverse-code-point/docs/types/test.ts | 46 +++++ .../base/reverse-code-point/examples/index.js | 33 ++++ .../base/reverse-code-point/lib/index.js | 43 +++++ .../base/reverse-code-point/lib/main.js | 91 ++++++++++ .../base/reverse-code-point/package.json | 67 +++++++ .../base/reverse-code-point/test/test.js | 65 +++++++ .../base/reverse-grapheme-cluster/README.md | 98 +++++++++++ .../benchmark/benchmark.js | 56 ++++++ .../reverse-grapheme-cluster/docs/repl.txt | 27 +++ .../docs/types/index.d.ts | 56 ++++++ .../docs/types/test.ts | 46 +++++ .../examples/index.js | 33 ++++ .../reverse-grapheme-cluster/lib/index.js | 46 +++++ .../base/reverse-grapheme-cluster/lib/main.js | 75 ++++++++ .../reverse-grapheme-cluster/package.json | 68 ++++++++ .../reverse-grapheme-cluster/test/test.js | 77 +++++++++ .../@stdlib/string/base/reverse/README.md | 89 ++++++++++ .../base/reverse/benchmark/benchmark.js | 56 ++++++ .../@stdlib/string/base/reverse/docs/repl.txt | 26 +++ .../string/base/reverse/docs/types/index.d.ts | 52 ++++++ .../string/base/reverse/docs/types/test.ts | 46 +++++ .../string/base/reverse/examples/index.js | 30 ++++ .../@stdlib/string/base/reverse/lib/index.js | 43 +++++ .../@stdlib/string/base/reverse/lib/main.js | 59 +++++++ .../@stdlib/string/base/reverse/package.json | 67 +++++++ .../@stdlib/string/base/reverse/test/test.js | 53 ++++++ .../@stdlib/string/reverse/README.md | 19 +- .../string/reverse/benchmark/benchmark.js | 90 ++++++++++ .../@stdlib/string/reverse/bin/cli | 22 ++- .../@stdlib/string/reverse/docs/repl.txt | 21 ++- .../string/reverse/docs/types/index.d.ts | 41 +++-- .../@stdlib/string/reverse/docs/types/test.ts | 27 +++ .../@stdlib/string/reverse/docs/usage.txt | 1 + .../@stdlib/string/reverse/etc/cli_opts.json | 3 +- .../@stdlib/string/reverse/lib/main.js | 56 ++++-- .../@stdlib/string/reverse/test/test.cli.js | 40 +++++ .../@stdlib/string/reverse/test/test.js | 163 ++++++++++++++++++ 41 files changed, 2123 insertions(+), 34 deletions(-) create mode 100644 lib/node_modules/@stdlib/string/base/reverse-code-point/README.md create mode 100644 lib/node_modules/@stdlib/string/base/reverse-code-point/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/string/base/reverse-code-point/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/string/base/reverse-code-point/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/string/base/reverse-code-point/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/string/base/reverse-code-point/examples/index.js create mode 100644 lib/node_modules/@stdlib/string/base/reverse-code-point/lib/index.js create mode 100644 lib/node_modules/@stdlib/string/base/reverse-code-point/lib/main.js create mode 100644 lib/node_modules/@stdlib/string/base/reverse-code-point/package.json create mode 100644 lib/node_modules/@stdlib/string/base/reverse-code-point/test/test.js create mode 100644 lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/README.md create mode 100644 lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/examples/index.js create mode 100644 lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/lib/index.js create mode 100644 lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/lib/main.js create mode 100644 lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/package.json create mode 100644 lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/test/test.js create mode 100644 lib/node_modules/@stdlib/string/base/reverse/README.md create mode 100644 lib/node_modules/@stdlib/string/base/reverse/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/string/base/reverse/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/string/base/reverse/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/string/base/reverse/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/string/base/reverse/examples/index.js create mode 100644 lib/node_modules/@stdlib/string/base/reverse/lib/index.js create mode 100644 lib/node_modules/@stdlib/string/base/reverse/lib/main.js create mode 100644 lib/node_modules/@stdlib/string/base/reverse/package.json create mode 100644 lib/node_modules/@stdlib/string/base/reverse/test/test.js diff --git a/lib/node_modules/@stdlib/string/base/reverse-code-point/README.md b/lib/node_modules/@stdlib/string/base/reverse-code-point/README.md new file mode 100644 index 000000000000..d498f54eae81 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/reverse-code-point/README.md @@ -0,0 +1,92 @@ + + +# reverseCodePoint + +> Reverse the Unicode code points of a string. + +
+ +## Usage + +```javascript +var reverseCodePoint = require( '@stdlib/string/base/reverse-code-point' ); +``` + +#### reverseCodePoint( str ) + +Reverses the Unicode code points of a string. + +```javascript +var out = reverseCodePoint( 'last man standing' ); +// returns 'gnidnats nam tsal' + +out = reverseCodePoint( 'Hidden Treasures' ); +// returns 'serusaerT neddiH' + +out = reverseCodePoint( 'foo bar' ); +// returns 'rab oof' +``` + +
+ + + +
+ +## Examples + + + +```javascript +var reverseCodePoint = require( '@stdlib/string/base/reverse-code-point' ); + +var str = reverseCodePoint( 'presidential election' ); +// returns 'noitcele laitnediserp' + +str = reverseCodePoint( 'JavaScript' ); +// returns 'tpircSavaJ' + +str = reverseCodePoint( 'The Last of the Mohicans' ); +// returns 'snacihoM eht fo tsaL ehT' + +str = reverseCodePoint( 'अनुच्छेद' ); +// returns 'देछ्चुनअ' +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/string/base/reverse-code-point/benchmark/benchmark.js b/lib/node_modules/@stdlib/string/base/reverse-code-point/benchmark/benchmark.js new file mode 100644 index 000000000000..052ff1d5291c --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/reverse-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 reverse = 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 = reverse( 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/reverse-code-point/docs/repl.txt b/lib/node_modules/@stdlib/string/base/reverse-code-point/docs/repl.txt new file mode 100644 index 000000000000..afb19a2d7541 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/reverse-code-point/docs/repl.txt @@ -0,0 +1,26 @@ + +{{alias}}( str ) + Reverses the Unicode code points of a string. + + Parameters + ---------- + str: string + Input string. + + Returns + ------- + out: string + Output string. + + Examples + -------- + > var out = {{alias}}( 'beep' ) + 'peeb' + > out = {{alias}}( 'Boop' ) + 'pooB' + > out = {{alias}}( 'foo bar' ) + 'rab oof' + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/string/base/reverse-code-point/docs/types/index.d.ts b/lib/node_modules/@stdlib/string/base/reverse-code-point/docs/types/index.d.ts new file mode 100644 index 000000000000..48765eeb8827 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/reverse-code-point/docs/types/index.d.ts @@ -0,0 +1,52 @@ +/* +* @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 + +/** +* Reverses the Unicode code points of a string. +* +* @param str - input string +* @returns output string +* +* @example +* var out = reverse( 'last man standing' ); +* // returns 'gnidnats nam tsal' +* +* @example +* var out = reverse( 'presidential election' ); +* // returns 'noitcele laitnediserp' +* +* @example +* var out = reverse( 'JavaScript' ); +* // returns 'tpircSavaJ' +* +* @example +* var out = reverse( 'Hidden Treasures' ); +* // returns 'serusaerT neddiH' +* +* @example +* var out = reverse( 'foo bar' ); +* // returns 'rab oof' +*/ +declare function reverse( str: string ): string; + + +// EXPORTS // + +export = reverse; diff --git a/lib/node_modules/@stdlib/string/base/reverse-code-point/docs/types/test.ts b/lib/node_modules/@stdlib/string/base/reverse-code-point/docs/types/test.ts new file mode 100644 index 000000000000..116ee34cdeca --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/reverse-code-point/docs/types/test.ts @@ -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. +*/ + +import reverse = require( './index' ); + + +// TESTS // + +// The function returns a string... +{ + reverse( 'abc' ); // $ExpectType string +} + +// The compiler throws an error if the function is provided a value other than a string... +{ + reverse( true ); // $ExpectError + reverse( false ); // $ExpectError + reverse( null ); // $ExpectError + reverse( undefined ); // $ExpectError + reverse( 5 ); // $ExpectError + reverse( [] ); // $ExpectError + reverse( {} ); // $ExpectError + reverse( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + reverse(); // $ExpectError + reverse( 'abc', 1 ); // $ExpectError + reverse( 'abc', 1, 2 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/string/base/reverse-code-point/examples/index.js b/lib/node_modules/@stdlib/string/base/reverse-code-point/examples/index.js new file mode 100644 index 000000000000..b56a85ddc032 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/reverse-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 reverse = require( './../lib' ); + +console.log( reverse( 'presidential election' ) ); +// => 'noitcele laitnediserp' + +console.log( reverse( 'JavaScript' ) ); +// => 'tpircSavaJ' + +console.log( reverse( 'The Last of the Mohicans' ) ); +// => 'snacihoM eht fo tsaL ehT' + +console.log( reverse( 'अनुच्छेद' ) ); +// => 'देछ्चुनअ' diff --git a/lib/node_modules/@stdlib/string/base/reverse-code-point/lib/index.js b/lib/node_modules/@stdlib/string/base/reverse-code-point/lib/index.js new file mode 100644 index 000000000000..a3238bb4f353 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/reverse-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'; + +/** +* Reverse the Unicode code points of a string. +* +* @module @stdlib/string/base/reverse-code-point +* +* @example +* var reverse = require( '@stdlib/string/base/reverse-code-point' ); +* +* var out = reverse( 'last man standing' ); +* // returns 'gnidnats nam tsal' +* +* out = reverse( 'Hidden Treasures' ); +* // returns 'serusaerT neddiH'; +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/string/base/reverse-code-point/lib/main.js b/lib/node_modules/@stdlib/string/base/reverse-code-point/lib/main.js new file mode 100644 index 000000000000..0122d57ec4c3 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/reverse-code-point/lib/main.js @@ -0,0 +1,91 @@ +/** +* @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'; + +// 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 // + +/** +* Reverses the Unicode code points of a string. +* +* @param {string} str - input string +* @returns {string} output string +* +* @example +* var out = reverse( 'last man standing' ); +* // returns 'gnidnats nam tsal' +* +* @example +* var out = reverse( 'presidential election' ); +* // returns 'noitcele laitnediserp' +* +* @example +* var out = reverse( 'JavaScript' ); +* // returns 'tpircSavaJ' +* +* @example +* var out = reverse( 'Hidden Treasures' ); +* // returns 'serusaerT neddiH' +*/ +function reverse( str ) { + var len; + var out; + var ch1; + var ch2; + var i; + + len = str.length; + 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; 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-1 ) { + // We found an unpaired surrogate... + out = ch1 + out; + 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 + out; + } + } + else { + out = ch1 + out; + } + } + return out; +} + + +// EXPORTS // + +module.exports = reverse; diff --git a/lib/node_modules/@stdlib/string/base/reverse-code-point/package.json b/lib/node_modules/@stdlib/string/base/reverse-code-point/package.json new file mode 100644 index 000000000000..bc82e8615f12 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/reverse-code-point/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/string/base/reverse-code-point", + "version": "0.0.0", + "description": "Reverse the Unicode code points of 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" + } + ], + "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", + "base", + "reverse", + "character", + "char", + "codepoint", + "unicode" + ] +} diff --git a/lib/node_modules/@stdlib/string/base/reverse-code-point/test/test.js b/lib/node_modules/@stdlib/string/base/reverse-code-point/test/test.js new file mode 100644 index 000000000000..9758072388f4 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/reverse-code-point/test/test.js @@ -0,0 +1,65 @@ +/** +* @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 reverse = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof reverse, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns an empty string if provided an empty string', function test( t ) { + t.strictEqual( reverse( '' ), '', 'returns expected value' ); + t.end(); +}); + +tape( 'the function reverses the Unicode code point of a provided string (ascii)', function test( t ) { + var out; + + out = reverse( 'hello world' ); + t.strictEqual( out, 'dlrow olleh', 'returns expected value' ); + + out = reverse( '!!!*' ); + t.strictEqual( out, '*!!!', 'returns expected value' ); + + out = reverse( 'Hello World' ); + t.strictEqual( out, 'dlroW olleH', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function reverses the Unicode code point of a provided string (Unicode)', function test( t ) { + var out; + + out = reverse( 'अनुच्छेद' ); + t.strictEqual( out, 'देछ्चुनअ', 'returns expected value' ); + + out = reverse( '六书/六書' ); + t.strictEqual( out, '書六/书六', 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/README.md b/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/README.md new file mode 100644 index 000000000000..796eda393864 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/README.md @@ -0,0 +1,98 @@ + + +# reverseGraphemeCluster + +> Reverse the grapheme clusters (i.e., user-perceived characters) of a string. + +
+ +## Usage + + + +```javascript +var reverseGraphemeCluster = require( '@stdlib/string/base/reverse-grapheme-cluster' ); +``` + +#### reverseGraphemeCluster( str ) + +Reverses the grapheme clusters (i.e., user-perceived characters) of a string. + + + +```javascript +var out = reverseGraphemeCluster( 'last man standing' ); +// returns 'gnidnats nam tsal' + +out = reverseGraphemeCluster( 'Hidden Treasures' ); +// returns 'serusaerT neddiH' + +out = reverseGraphemeCluster( 'foo bar' ); +// returns 'rab oof' +``` + +
+ + + +
+ +## Examples + + + + + +```javascript +var reverseGraphemeCluster = require( '@stdlib/string/base/reverse-grapheme-cluster' ); + +var str = reverseGraphemeCluster( 'presidential election' ); +// returns 'noitcele laitnediserp' + +str = reverseGraphemeCluster( 'JavaScript' ); +// returns 'tpircSavaJ' + +str = reverseGraphemeCluster( 'The Last of the Mohicans' ); +// returns 'snacihoM eht fo tsaL ehT' + +str = reverseGraphemeCluster( '🐶🐮🐷🐰🐸' ); +// returns '🐸🐰🐷🐮🐶' +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/benchmark/benchmark.js b/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/benchmark/benchmark.js new file mode 100644 index 000000000000..8f45bcfe87b9 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/reverse-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 reverse = 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 = reverse( values[ i%values.length ] ); + 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/reverse-grapheme-cluster/docs/repl.txt b/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/docs/repl.txt new file mode 100644 index 000000000000..960ed7170ec5 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/docs/repl.txt @@ -0,0 +1,27 @@ + +{{alias}}( str ) + Reverses the grapheme clusters (i.e., user-perceived characters) of a + string. + + Parameters + ---------- + str: string + Input string. + + Returns + ------- + out: string + Output string. + + Examples + -------- + > var out = {{alias}}( 'beep' ) + 'peeb' + > out = {{alias}}( 'Boop' ) + 'pooB' + > out = {{alias}}( 'foo bar' ) + 'rab oof' + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/docs/types/index.d.ts b/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/docs/types/index.d.ts new file mode 100644 index 000000000000..1f40280204a6 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/docs/types/index.d.ts @@ -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. +*/ + +// TypeScript Version: 2.0 + +/** +* Reverses the grapheme clusters (i.e., user-perceived characters) of a string. +* +* @param str - input string +* @returns output string +* +* @example +* var out = reverse( 'last man standing' ); +* // returns 'gnidnats nam tsal' +* +* @example +* var out = reverse( 'presidential election' ); +* // returns 'noitcele laitnediserp' +* +* @example +* var out = reverse( 'JavaScript' ); +* // returns 'tpircSavaJ' +* +* @example +* var out = reverse( 'Hidden Treasures' ); +* // returns 'serusaerT neddiH' +* +* @example +* var out = reverse( '🐶🐮🐷🐰🐸' ); +* // returns '🐸🐰🐷🐮🐶' +* +* @example +* var out = reverse( 'foo bar' ); +* // returns 'rab oof' +*/ +declare function reverse( str: string ): string; + + +// EXPORTS // + +export = reverse; diff --git a/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/docs/types/test.ts b/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/docs/types/test.ts new file mode 100644 index 000000000000..f6d42b97e478 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/docs/types/test.ts @@ -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. +*/ + +import reverse = require( './index' ); + + +// TESTS // + +// The function returns a string... +{ + reverse( 'abc' ); // $ExpectType string +} + +// The compiler throws an error if the function is provided a value other than a string... +{ + reverse( true ); // $ExpectError + reverse( false ); // $ExpectError + reverse( null ); // $ExpectError + reverse( undefined ); // $ExpectError + reverse( 5 ); // $ExpectError + reverse( [] ); // $ExpectError + reverse( {} ); // $ExpectError + reverse( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + reverse(); // $ExpectError + reverse( 'abc', 2 ); // $ExpectError + reverse( 'abc', 1, 2 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/examples/index.js b/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/examples/index.js new file mode 100644 index 000000000000..621bdba60c55 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/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 reverseGraphemeCluster = require( './../lib' ); + +console.log( reverseGraphemeCluster( 'presidential election' ) ); +// => 'noitcele laitnediserp' + +console.log( reverseGraphemeCluster( 'JavaScript' ) ); +// => 'tpircSavaJ' + +console.log( reverseGraphemeCluster( 'The Last of the Mohicans' ) ); +// => 'snacihoM eht fo tsaL ehT' + +console.log( reverseGraphemeCluster( '🐶🐮🐷🐰🐸' ) ); +// => '🐸🐰🐷🐮🐶' diff --git a/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/lib/index.js b/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/lib/index.js new file mode 100644 index 000000000000..7c17478125c2 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/lib/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'; + +/** +* Reverse the grapheme clusters (i.e., user-perceived characters) of a string. +* +* @module @stdlib/string/base/reverse-grapheme-cluster +* +* @example +* var reverse = require( '@stdlib/string/base/reverse-grapheme-cluster' ); +* +* var out = reverse( 'last man standing' ); +* // returns 'gnidnats nam tsal' +* +* out = reverse( 'Hidden Treasures' ); +* // returns 'serusaerT neddiH'; +* +* out = reverse( '🐶🐮🐷🐰🐸' ); +* // returns '🐸🐰🐷🐮🐶' +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/lib/main.js b/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/lib/main.js new file mode 100644 index 000000000000..9815ac5e6e61 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/lib/main.js @@ -0,0 +1,75 @@ +/** +* @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 prevGraphemeClusterBreak = require( '@stdlib/string/prev-grapheme-cluster-break' ); + + +// MAIN // + +/** +* Reverses the grapheme clusters (i.e., user-perceived characters) of a string. +* +* @param {string} str - input string +* @returns {string} output string +* +* @example +* var out = reverse( 'last man standing' ); +* // returns 'gnidnats nam tsal' +* +* @example +* var out = reverse( 'presidential election' ); +* // returns 'noitcele laitnediserp' +* +* @example +* var out = reverse( 'JavaScript' ); +* // returns 'tpircSavaJ' +* +* @example +* var out = reverse( 'Hidden Treasures' ); +* // returns 'serusaerT neddiH' +* +* @example +* var out = reverse( '🐶🐮🐷🐰🐸' ); +* // returns '🐸🐰🐷🐮🐶' +*/ +function reverse( str ) { + var out; + var idx; + var brk; + var i; + + out = ''; + idx = str.length - 1; + while ( idx >= 0 ) { + brk = prevGraphemeClusterBreak( str, idx ); + for ( i = brk + 1; i <= idx; i++ ) { + out += str.charAt( i ); + } + idx = brk; + } + return out; +} + + +// EXPORTS // + +module.exports = reverse; diff --git a/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/package.json b/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/package.json new file mode 100644 index 000000000000..7c293e7b2712 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/package.json @@ -0,0 +1,68 @@ +{ + "name": "@stdlib/string/base/first-grapheme-cluster", + "version": "0.0.0", + "description": "Reverse the grapheme cluster (i.e., user-perceived character) of 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" + } + ], + "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", + "base", + "reverse", + "character", + "char", + "grapheme", + "cluster", + "unicode" + ] +} diff --git a/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/test/test.js b/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/test/test.js new file mode 100644 index 000000000000..564d45a2e119 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/test/test.js @@ -0,0 +1,77 @@ +/** +* @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 reverse = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof reverse, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns an empty string if provided an empty string', function test( t ) { + t.strictEqual( reverse( '' ), '', 'returns expected value' ); + t.end(); +}); + +tape( 'the function reverses the grapheme clusters of a provided string (ascii)', function test( t ) { + var out; + + out = reverse( 'hello world' ); + t.strictEqual( out, 'dlrow olleh', 'returns expected value' ); + + out = reverse( '!!!*' ); + t.strictEqual( out, '*!!!', 'returns expected value' ); + + out = reverse( 'Hello World' ); + t.strictEqual( out, 'dlroW olleH', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function reverses the grapheme clusters of a provided string (Unicode)', function test( t ) { + var out; + + out = reverse( 'अनुच्छेद', 1 ); + t.strictEqual( out, 'दछेच्नुअ', 'returns expected value' ); + + out = reverse( '六书/六書', 1 ); + t.strictEqual( out, '書六/书六', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function reverses the grapheme clusters of a provided string (emoji)', function test( t ) { + var out; + + out = reverse( '🌷', 1 ); + t.strictEqual( out, '🌷', 'returns expected value' ); + + out = reverse( '🏝️🌷', 1 ); + t.strictEqual( out, '🌷🏝️', 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/string/base/reverse/README.md b/lib/node_modules/@stdlib/string/base/reverse/README.md new file mode 100644 index 000000000000..466cf4bc5f8e --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/reverse/README.md @@ -0,0 +1,89 @@ + + +# reverse + +> reverse the UTF-16 code units of a string. + +
+ +## Usage + +```javascript +var reverse = require( '@stdlib/string/base/reverse' ); +``` + +#### reverse( str ) + +Reverses the UTF-16 code units of a string. + +```javascript +var out = reverse( 'last man standing' ); +// returns 'gnidnats nam tsal' + +out = reverse( 'Hidden Treasures' ); +// returns 'serusaerT neddiH' + +out = reverse( 'foo bar' ); +// returns 'rab oof' +``` + +
+ + + +
+ +## Examples + + + +```javascript +var reverse = require( '@stdlib/string/base/reverse' ); + +var str = reverse( 'presidential election' ); +// returns 'noitcele laitnediserp' + +str = reverse( 'JavaScript' ); +// returns 'tpircSavaJ' + +str = reverse( 'The Last of the Mohicans' ); +// returns 'snacihoM eht fo tsaL ehT' +``` + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/string/base/reverse/benchmark/benchmark.js b/lib/node_modules/@stdlib/string/base/reverse/benchmark/benchmark.js new file mode 100644 index 000000000000..8f45bcfe87b9 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/reverse/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 reverse = 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 = reverse( values[ i%values.length ] ); + 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/reverse/docs/repl.txt b/lib/node_modules/@stdlib/string/base/reverse/docs/repl.txt new file mode 100644 index 000000000000..0bac948a9534 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/reverse/docs/repl.txt @@ -0,0 +1,26 @@ + +{{alias}}( str ) + Reverses the UTF-16 code units of a string. + + Parameters + ---------- + str: string + Input string. + + Returns + ------- + out: string + Output string. + + Examples + -------- + > var out = {{alias}}( 'beep' ) + 'peeb' + > out = {{alias}}( 'Boop' ) + 'pooB' + > out = {{alias}}( 'foo bar' ) + 'rab oof' + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/string/base/reverse/docs/types/index.d.ts b/lib/node_modules/@stdlib/string/base/reverse/docs/types/index.d.ts new file mode 100644 index 000000000000..43d3f4e76127 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/reverse/docs/types/index.d.ts @@ -0,0 +1,52 @@ +/* +* @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 + +/** +* Reverses the UTF-16 code units of a string. +* +* @param str - input string +* @returns output string +* +* @example +* var out = reverse( 'last man standing' ); +* // returns 'gnidnats nam tsal' +* +* @example +* var out = reverse( 'presidential election' ); +* // returns 'noitcele laitnediserp' +* +* @example +* var out = reverse( 'JavaScript' ); +* // returns 'tpircSavaJ' +* +* @example +* var out = reverse( 'Hidden Treasures' ); +* // returns 'serusaerT neddiH' +* +* @example +* var out = reverse( 'foo bar' ); +* // returns 'rab oof' +*/ +declare function reverse( str: string ): string; + + +// EXPORTS // + +export = reverse; diff --git a/lib/node_modules/@stdlib/string/base/reverse/docs/types/test.ts b/lib/node_modules/@stdlib/string/base/reverse/docs/types/test.ts new file mode 100644 index 000000000000..116ee34cdeca --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/reverse/docs/types/test.ts @@ -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. +*/ + +import reverse = require( './index' ); + + +// TESTS // + +// The function returns a string... +{ + reverse( 'abc' ); // $ExpectType string +} + +// The compiler throws an error if the function is provided a value other than a string... +{ + reverse( true ); // $ExpectError + reverse( false ); // $ExpectError + reverse( null ); // $ExpectError + reverse( undefined ); // $ExpectError + reverse( 5 ); // $ExpectError + reverse( [] ); // $ExpectError + reverse( {} ); // $ExpectError + reverse( ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + reverse(); // $ExpectError + reverse( 'abc', 1 ); // $ExpectError + reverse( 'abc', 1, 2 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/string/base/reverse/examples/index.js b/lib/node_modules/@stdlib/string/base/reverse/examples/index.js new file mode 100644 index 000000000000..1c473d63bb16 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/reverse/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 reverse = require( './../lib' ); + +console.log( reverse( 'presidential election' ) ); +// => 'noitcele laitnediserp' + +console.log( reverse( 'JavaScript' ) ); +// => 'tpircSavaJ' + +console.log( reverse( 'The Last of the Mohicans' ) ); +// => 'snacihoM eht fo tsaL ehT' diff --git a/lib/node_modules/@stdlib/string/base/reverse/lib/index.js b/lib/node_modules/@stdlib/string/base/reverse/lib/index.js new file mode 100644 index 000000000000..f5e7c1fe8f83 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/reverse/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'; + +/** +* Reverse the UTF-16 code units of a string. +* +* @module @stdlib/string/base/reverse +* +* @example +* var reverse = require( '@stdlib/string/base/reverse' ); +* +* var out = reverse( 'last man standing' ); +* // returns 'gnidnats nam tsal' +* +* out = reverse( 'Hidden Treasures' ); +* // returns 'serusaerT neddiH'; +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/string/base/reverse/lib/main.js b/lib/node_modules/@stdlib/string/base/reverse/lib/main.js new file mode 100644 index 000000000000..a213dc65aad4 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/reverse/lib/main.js @@ -0,0 +1,59 @@ +/** +* @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 // + +/** +* Reverses the UTF-16 code units of a string. +* +* @param {string} str - input string +* @returns {string} output string +* +* @example +* var out = reverse( 'last man standing' ); +* // returns 'gnidnats nam tsal' +* +* @example +* var out = reverse( 'presidential election' ); +* // returns 'noitcele laitnediserp' +* +* @example +* var out = reverse( 'JavaScript' ); +* // returns 'tpircSavaJ' +* +* @example +* var out = reverse( 'Hidden Treasures' ); +* // returns 'serusaerT neddiH' +*/ +function reverse( str ) { + var out; + var i; + + out = ''; + for ( i = str.length - 1; i >= 0; i--) { + out += str[i]; + } + return out; +} + + +// EXPORTS // + +module.exports = reverse; diff --git a/lib/node_modules/@stdlib/string/base/reverse/package.json b/lib/node_modules/@stdlib/string/base/reverse/package.json new file mode 100644 index 000000000000..41b2e85fb055 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/reverse/package.json @@ -0,0 +1,67 @@ +{ + "name": "@stdlib/string/base/reverse", + "version": "0.0.0", + "description": "Reverse the UTF-16 code units of 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" + } + ], + "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", + "base", + "reverse", + "character", + "char", + "codeunit", + "unicode" + ] +} diff --git a/lib/node_modules/@stdlib/string/base/reverse/test/test.js b/lib/node_modules/@stdlib/string/base/reverse/test/test.js new file mode 100644 index 000000000000..51934d51a75b --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/reverse/test/test.js @@ -0,0 +1,53 @@ +/** +* @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 reverse = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof reverse, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns an empty string if provided an empty string', function test( t ) { + t.strictEqual( reverse( '' ), '', 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns reversed UTF-16 code units of the string', function test( t ) { + var out; + + out = reverse( 'hello world' ); + t.strictEqual( out, 'dlrow olleh', 'returns expected value' ); + + out = reverse( '!!!*' ); + t.strictEqual( out, '*!!!', 'returns expected value' ); + + out = reverse( 'Hello World' ); + t.strictEqual( out, 'dlroW olleH', 'returns expected value' ); + + t.end(); +}); diff --git a/lib/node_modules/@stdlib/string/reverse/README.md b/lib/node_modules/@stdlib/string/reverse/README.md index ad7255a1412b..99afd4d81185 100644 --- a/lib/node_modules/@stdlib/string/reverse/README.md +++ b/lib/node_modules/@stdlib/string/reverse/README.md @@ -30,7 +30,7 @@ limitations under the License. var reverseString = require( '@stdlib/string/reverse' ); ``` -#### reverseString( str ) +#### reverseString( str\[, options] ) Reverses a `string`. @@ -45,12 +45,28 @@ out = reverseString( 'Lorem ipsum 𝌆 dolor sit ameͨ͆t.' ); // returns '.teͨ͆ma tis rolod 𝌆 muspi meroL' ``` +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'`. + + +
+## 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. +
@@ -99,6 +115,7 @@ Options: -h, --help Print this message. -V, --version Print the package version. --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/reverse/benchmark/benchmark.js b/lib/node_modules/@stdlib/string/reverse/benchmark/benchmark.js index 9ecfea55aed7..6de65042d3da 100644 --- a/lib/node_modules/@stdlib/string/reverse/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/string/reverse/benchmark/benchmark.js @@ -49,3 +49,93 @@ bench( pkg, function benchmark( b ) { b.pass( 'benchmark finished' ); b.end(); }); + +bench( pkg+':mode=grapheme', function benchmark( b ) { + var values; + var opts; + var out; + var i; + + values = [ + 'beep boop', + 'foo bar', + 'xyz abc' + ]; + opts = { + 'mode': 'grapheme' + }; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = reverseString( values[ i%values.length ], 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; + + values = [ + 'beep boop', + 'foo bar', + 'xyz abc' + ]; + opts = { + 'mode': 'code_point' + }; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = reverseString( values[ i%values.length ], 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_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 = reverseString( values[ i%values.length ], 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/reverse/bin/cli b/lib/node_modules/@stdlib/string/reverse/bin/cli index f7ba6a5d5935..c96be860bfba 100755 --- a/lib/node_modules/@stdlib/string/reverse/bin/cli +++ b/lib/node_modules/@stdlib/string/reverse/bin/cli @@ -45,6 +45,7 @@ function main() { var split; var flags; var args; + var opts; var cli; // Create a command-line interface: @@ -61,6 +62,10 @@ function main() { if ( flags.help || flags.version ) { return; } + opts = {}; + if ( flags.mode ) { + opts.mode = flags.mode; + } // Get any provided command-line arguments: args = cli.args(); @@ -77,7 +82,11 @@ function main() { } return stdin( onRead ); } - console.log( reverse( args[ 0 ] ) ); // eslint-disable-line no-console + try { + console.log( reverse( args[ 0 ], opts ) ); // eslint-disable-line no-console + } catch ( error ) { + return cli.error( error ); + } /** * Callback invoked upon reading from `stdin`. @@ -99,8 +108,15 @@ function main() { if ( lines[ lines.length-1 ] === '' ) { lines.pop(); } - for ( i = 0; i < lines.length; i++ ) { - console.log( reverse( lines[ i ] ) ); // eslint-disable-line no-console + if ( lines.length ) { + try { + console.log( reverse( lines[ 0 ], opts ) ); // eslint-disable-line no-console + } catch ( error ) { + return cli.error( error ); + } + for ( i = 1; i < lines.length; i++ ) { + console.log( reverse( lines[ i ], opts ) ); // eslint-disable-line no-console + } } } } diff --git a/lib/node_modules/@stdlib/string/reverse/docs/repl.txt b/lib/node_modules/@stdlib/string/reverse/docs/repl.txt index 8de69b78d81e..9a996c8b035b 100644 --- a/lib/node_modules/@stdlib/string/reverse/docs/repl.txt +++ b/lib/node_modules/@stdlib/string/reverse/docs/repl.txt @@ -1,5 +1,5 @@ -{{alias}}( str ) +{{alias}}( str[, options] ) Reverses a `string`. Parameters @@ -7,6 +7,25 @@ str: string Input string. + 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/reverse/docs/types/index.d.ts b/lib/node_modules/@stdlib/string/reverse/docs/types/index.d.ts index 008230d3011e..ba473c8aa025 100644 --- a/lib/node_modules/@stdlib/string/reverse/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/string/reverse/docs/types/index.d.ts @@ -18,29 +18,46 @@ // TypeScript Version: 2.0 +// 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'; +} + /** * Reverses a string. * * @param str - input string +* @param options - options * @returns reversed string * * @example -* var out = reverseString( 'last man standing' ); +* var out = reverseString( 'last man standing', { +* 'mode': 'code_unit' +* }); * // returns 'gnidnats nam tsal' * * @example -* var out = reverseString( 'presidential election' ); -* // returns 'noitcele laitnediserp' -* -* @example -* var out = reverseString( 'javaScript' ); -* // returns 'tpircSavaj' -* -* @example -* var out = reverseString( 'Hidden Treasures' ); -* // returns 'serusaerT neddiH' +* var out = reverseString( '🐶🐮🐷🐰🐸', { +* 'mode': 'grapheme' +* }); +* // returns '🐸🐰🐷🐮🐶' */ -declare function reverseString( str: string ): string; +declare function reverseString( str: string, options?: Options ): string; // EXPORTS // diff --git a/lib/node_modules/@stdlib/string/reverse/docs/types/test.ts b/lib/node_modules/@stdlib/string/reverse/docs/types/test.ts index b00c8a9c20c6..0a961943a0bc 100644 --- a/lib/node_modules/@stdlib/string/reverse/docs/types/test.ts +++ b/lib/node_modules/@stdlib/string/reverse/docs/types/test.ts @@ -36,6 +36,33 @@ import reverseString = require( './index' ); reverseString( [] ); // $ExpectError reverseString( {} ); // $ExpectError reverseString( ( x: number ): number => x ); // $ExpectError + + reverseString( true, {} ); // $ExpectError + reverseString( false, {} ); // $ExpectError + reverseString( null, {} ); // $ExpectError + reverseString( undefined, {} ); // $ExpectError + reverseString( 5, {} ); // $ExpectError + reverseString( [], {} ); // $ExpectError + reverseString( {}, {} ); // $ExpectError + reverseString( ( x: number ): number => x, {} ); // $ExpectError +} + +// The compiler throws an error if the function is provided an invalid `mode` option... +{ + reverseString( 'abc', { 'mode': true } ); // $ExpectError + reverseString( 'abc', { 'mode': false } ); // $ExpectError + reverseString( 'abc', { 'mode': null } ); // $ExpectError + reverseString( 'abc', { 'mode': '' } ); // $ExpectError + reverseString( 'abc', { 'mode': [] } ); // $ExpectError + reverseString( 'abc', { 'mode': ( x: number ): number => x } ); // $ExpectError + + reverseString( 'abc', 1, { 'mode': true } ); // $ExpectError + reverseString( 'abc', 1, { 'mode': false } ); // $ExpectError + reverseString( 'abc', 1, { 'mode': null } ); // $ExpectError + reverseString( 'abc', 1, { 'mode': '' } ); // $ExpectError + reverseString( 'abc', 1, { 'mode': [] } ); // $ExpectError + reverseString( 'abc', 1, { 'mode': {} } ); // $ExpectError + reverseString( 'abc', 1, { 'mode': ( x: number ): number => x } ); // $ExpectError } // The compiler throws an error if the function is provided insufficient arguments... diff --git a/lib/node_modules/@stdlib/string/reverse/docs/usage.txt b/lib/node_modules/@stdlib/string/reverse/docs/usage.txt index c6a6e7fa6946..c1aee420147d 100644 --- a/lib/node_modules/@stdlib/string/reverse/docs/usage.txt +++ b/lib/node_modules/@stdlib/string/reverse/docs/usage.txt @@ -6,3 +6,4 @@ Options: -h, --help Print this message. -V, --version Print the package version. --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/reverse/etc/cli_opts.json b/lib/node_modules/@stdlib/string/reverse/etc/cli_opts.json index 7c40f9a10cc1..b090761664d1 100644 --- a/lib/node_modules/@stdlib/string/reverse/etc/cli_opts.json +++ b/lib/node_modules/@stdlib/string/reverse/etc/cli_opts.json @@ -1,6 +1,7 @@ { "string": [ - "split" + "split", + "mode" ], "boolean": [ "help", diff --git a/lib/node_modules/@stdlib/string/reverse/lib/main.js b/lib/node_modules/@stdlib/string/reverse/lib/main.js index a257ecb8e572..85f504ea6a66 100644 --- a/lib/node_modules/@stdlib/string/reverse/lib/main.js +++ b/lib/node_modules/@stdlib/string/reverse/lib/main.js @@ -20,18 +20,37 @@ // MODULES // -var prevGraphemeClusterBreak = require( '@stdlib/string/prev-grapheme-cluster-break' ); var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var isPlainObject = require( '@stdlib/assert/is-plain-object' ); +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var contains = require( '@stdlib/array/base/assert/contains' ).factory; +var reverseCodeUnit = require( '@stdlib/string/base/reverse' ); +var reverseCodePoint = require( '@stdlib/string/base/reverse-code-point' ); +var reverseGraphemeCluster = require( '@stdlib/string/base/reverse-grapheme-cluster' ); var format = require( '@stdlib/string/format' ); +// VARIABLES // + +var MODES = [ 'grapheme', 'code_point', 'code_unit' ]; +var FCNS = { + 'grapheme': reverseGraphemeCluster, + 'code_point': reverseCodePoint, + 'code_unit': reverseCodeUnit +}; +var isMode = contains( MODES ); + + // MAIN // /** * Reverses a string. * * @param {string} str - input string +* @param {Options} [options] - options * @throws {TypeError} must provide a string primitive +* @throws {TypeError} options argument must be an object +* @throws {TypeError} must provide valid options * @returns {string} reversed string * * @example @@ -51,27 +70,32 @@ var format = require( '@stdlib/string/format' ); * // returns 'serusaerT neddiH' */ function reverse( str ) { - var out; - var brk; - var idx; - var i; + var options; + var nargs; + var opts; + if ( !isString( str ) ) { throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); } - if ( str === '' ) { - return ''; + opts = { + 'mode': 'grapheme' + }; + nargs = arguments.length; + if ( nargs > 1 ) { + options = arguments[ 1 ]; + if ( !isPlainObject( options ) ) { + throw new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) ); + } } - - out = []; - idx = str.length - 1; - while ( idx >= 0 ) { - brk = prevGraphemeClusterBreak( str, idx ); - for ( i = brk + 1; i <= idx; i++ ) { - out.push( str.charAt( i ) ); + 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 ) ); + } } - idx = brk; } - return out.join( '' ); + return FCNS[ opts.mode ]( str ); } diff --git a/lib/node_modules/@stdlib/string/reverse/test/test.cli.js b/lib/node_modules/@stdlib/string/reverse/test/test.cli.js index 8c854eb4fc8c..17977c7a5194 100644 --- a/lib/node_modules/@stdlib/string/reverse/test/test.cli.js +++ b/lib/node_modules/@stdlib/string/reverse/test/test.cli.js @@ -162,6 +162,46 @@ tape( 'the command-line interface reverses a string argument', opts, function te } }); +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\'; process.argv[ 3 ] = \'--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(), 'peeb\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 ] = \'--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 "foobar\nlast man standing"', diff --git a/lib/node_modules/@stdlib/string/reverse/test/test.js b/lib/node_modules/@stdlib/string/reverse/test/test.js index 950bd47087bf..44b5eb47f69e 100644 --- a/lib/node_modules/@stdlib/string/reverse/test/test.js +++ b/lib/node_modules/@stdlib/string/reverse/test/test.js @@ -59,8 +59,92 @@ tape( 'the function throws an error if not provided a string', function test( t } }); +tape( 'the function throws an error if not provided a string (options)', 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() { + reverseString( 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 = [ + '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() { + reverseString( 'beep', value ); + }; + } +}); + +tape( 'the function throws an error if provided a `mode` option which is not a supported mode', 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() { + reverseString( 'beep', { + 'mode': value + }); + }; + } +}); + tape( 'the function returns an empty string if provided an empty string', function test( t ) { t.strictEqual( reverseString( '' ), '', 'returns expected value' ); + t.strictEqual( reverseString( '', {} ), '', 'returns expected value' ); t.end(); }); @@ -116,3 +200,82 @@ tape( 'the function reverses a string', function test( t ) { } t.end(); }); + +tape( 'the function reverses the first string (mode=grapheme)', function test( t ) { + var opts; + var out; + + opts = { + 'mode': 'grapheme' + }; + + out = reverseString( 'hello world', opts ); + t.strictEqual( out, 'dlrow olleh', 'returns expected value' ); + + out = reverseString( '*!!!', opts ); + t.strictEqual( out, '!!!*', 'returns expected value' ); + + out = reverseString( 'अनुच्छेद', opts ); + t.strictEqual( out, 'दछेच्नुअ', 'returns expected value' ); + + out = reverseString( '六书/六書', opts ); + t.strictEqual( out, '書六/书六', 'returns expected value' ); + + out = reverseString( '🌷', opts ); + t.strictEqual( out, '🌷', 'returns expected value' ); + + out = reverseString( '👉🏿', opts ); + t.strictEqual( out, '🏿👉', 'returns expected value' ); + + t.end(); +}); + +tape( 'the function reverses the first string (mode=code_point)', function test( t ) { + var opts; + var out; + + opts = { + 'mode': 'code_point' + }; + + out = reverseString( 'hello world', opts ); + t.strictEqual( out, 'dlrow olleh', 'returns expected value' ); + + out = reverseString( '*!!!', opts ); + t.strictEqual( out, '!!!*', 'returns expected value' ); + + out = reverseString( 'अनुच्छेद', opts ); + t.strictEqual( out, 'देछ्चुनअ', 'returns expected value' ); + + out = reverseString( '六书/六書', opts ); + t.strictEqual( out, '書六/书六', 'returns expected value' ); + + out = reverseString( '🌷', opts ); + t.strictEqual( out, '🌷', 'returns expected value' ); + t.end(); +}); + +tape( 'the function reverses the first string (mode=code_unit)', function test( t ) { + var opts; + var out; + + opts = { + 'mode': 'code_unit' + }; + + out = reverseString( 'hello world', opts ); + t.strictEqual( out, 'dlrow olleh', 'returns expected value' ); + + out = reverseString( '*!!!', opts ); + t.strictEqual( out, '!!!*', 'returns expected value' ); + + out = reverseString( 'अनुच्छेद', opts ); + t.strictEqual( out, 'देछ्चुनअ', 'returns expected value' ); + + out = reverseString( '六书/六書', opts ); + t.strictEqual( out, '書六/书六', 'returns expected value' ); + + out = reverseString( '🌷', opts ); + t.strictEqual( out, '\udf37\ud83c', 'returns expected value' ); + t.end(); +}); From df8f433365f26b32b006407d14ebb766f654aef8 Mon Sep 17 00:00:00 2001 From: Stephannie Jimenez Date: Mon, 14 Aug 2023 14:22:12 -0500 Subject: [PATCH 2/9] fix: fix bug and add tests --- .../string/base/reverse-code-point/lib/main.js | 5 ++++- .../string/base/reverse-code-point/test/test.js | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/string/base/reverse-code-point/lib/main.js b/lib/node_modules/@stdlib/string/base/reverse-code-point/lib/main.js index 0122d57ec4c3..f88f5ac1485e 100644 --- a/lib/node_modules/@stdlib/string/base/reverse-code-point/lib/main.js +++ b/lib/node_modules/@stdlib/string/base/reverse-code-point/lib/main.js @@ -74,8 +74,11 @@ function reverse( str ) { 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 + out; + i += 1; // bump the index to process the next code unit + } + else { + out = ch1 + out; } } else { diff --git a/lib/node_modules/@stdlib/string/base/reverse-code-point/test/test.js b/lib/node_modules/@stdlib/string/base/reverse-code-point/test/test.js index 9758072388f4..71f9d7986684 100644 --- a/lib/node_modules/@stdlib/string/base/reverse-code-point/test/test.js +++ b/lib/node_modules/@stdlib/string/base/reverse-code-point/test/test.js @@ -63,3 +63,15 @@ tape( 'the function reverses the Unicode code point of a provided string (Unicod t.end(); }); + +tape( 'the function reverses the Unicode code point of a provided string (surrogate pair)', function test( t ) { + var out; + + out = reverse( 'foo\uD834\uDF06bar' ); + t.strictEqual( out, 'rab\uD834\uDF06oof', 'returns expected value' ); + + out = reverse( 'foo\uD834bar\uDF06baz' ); + t.strictEqual( out, 'zab\uDF06rab\uD834oof', 'returns expected value' ); + + t.end(); +}); From 9c3ea43173f9fbe481c2976db6e1414b8cbe9d48 Mon Sep 17 00:00:00 2001 From: Stephannie Jimenez Date: Mon, 14 Aug 2023 17:12:07 -0500 Subject: [PATCH 3/9] fix: add more tests to fix code coverage --- .../@stdlib/string/base/reverse-code-point/test/test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/node_modules/@stdlib/string/base/reverse-code-point/test/test.js b/lib/node_modules/@stdlib/string/base/reverse-code-point/test/test.js index 71f9d7986684..552d51fbd488 100644 --- a/lib/node_modules/@stdlib/string/base/reverse-code-point/test/test.js +++ b/lib/node_modules/@stdlib/string/base/reverse-code-point/test/test.js @@ -73,5 +73,8 @@ tape( 'the function reverses the Unicode code point of a provided string (surrog out = reverse( 'foo\uD834bar\uDF06baz' ); t.strictEqual( out, 'zab\uDF06rab\uD834oof', 'returns expected value' ); + out = reverse( 'foo\uD834bar\uDF06\uD834' ); + t.strictEqual( out, '\uD834\uDF06rab\uD834oof', 'returns expected value' ); + t.end(); }); From 6dee1658f6a8af10c393d754554ab9d534016f3f Mon Sep 17 00:00:00 2001 From: Stephannie Jimenez Date: Fri, 25 Aug 2023 17:34:07 -0500 Subject: [PATCH 4/9] fix: rename packages to use plural context --- .../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 .../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 | 10 ++++----- .../lib/index.js | 4 ++-- .../lib/main.js | 0 .../package.json | 2 +- .../test/test.js | 0 .../@stdlib/string/reverse/lib/main.js | 8 +++---- 21 files changed, 37 insertions(+), 37 deletions(-) rename lib/node_modules/@stdlib/string/base/{reverse-code-point => reverse-code-points}/README.md (73%) rename lib/node_modules/@stdlib/string/base/{reverse-code-point => reverse-code-points}/benchmark/benchmark.js (100%) rename lib/node_modules/@stdlib/string/base/{reverse-code-point => reverse-code-points}/docs/repl.txt (100%) rename lib/node_modules/@stdlib/string/base/{reverse-code-point => reverse-code-points}/docs/types/index.d.ts (100%) rename lib/node_modules/@stdlib/string/base/{reverse-code-point => reverse-code-points}/docs/types/test.ts (100%) rename lib/node_modules/@stdlib/string/base/{reverse-code-point => reverse-code-points}/examples/index.js (100%) rename lib/node_modules/@stdlib/string/base/{reverse-code-point => reverse-code-points}/lib/index.js (94%) rename lib/node_modules/@stdlib/string/base/{reverse-code-point => reverse-code-points}/lib/main.js (100%) rename lib/node_modules/@stdlib/string/base/{reverse-code-point => reverse-code-points}/package.json (96%) rename lib/node_modules/@stdlib/string/base/{reverse-code-point => reverse-code-points}/test/test.js (100%) rename lib/node_modules/@stdlib/string/base/{reverse-grapheme-cluster => reverse-grapheme-clusters}/README.md (72%) rename lib/node_modules/@stdlib/string/base/{reverse-grapheme-cluster => reverse-grapheme-clusters}/benchmark/benchmark.js (100%) rename lib/node_modules/@stdlib/string/base/{reverse-grapheme-cluster => reverse-grapheme-clusters}/docs/repl.txt (100%) rename lib/node_modules/@stdlib/string/base/{reverse-grapheme-cluster => reverse-grapheme-clusters}/docs/types/index.d.ts (100%) rename lib/node_modules/@stdlib/string/base/{reverse-grapheme-cluster => reverse-grapheme-clusters}/docs/types/test.ts (100%) rename lib/node_modules/@stdlib/string/base/{reverse-grapheme-cluster => reverse-grapheme-clusters}/examples/index.js (70%) rename lib/node_modules/@stdlib/string/base/{reverse-grapheme-cluster => reverse-grapheme-clusters}/lib/index.js (94%) rename lib/node_modules/@stdlib/string/base/{reverse-grapheme-cluster => reverse-grapheme-clusters}/lib/main.js (100%) rename lib/node_modules/@stdlib/string/base/{reverse-grapheme-cluster => reverse-grapheme-clusters}/package.json (95%) rename lib/node_modules/@stdlib/string/base/{reverse-grapheme-cluster => reverse-grapheme-clusters}/test/test.js (100%) diff --git a/lib/node_modules/@stdlib/string/base/reverse-code-point/README.md b/lib/node_modules/@stdlib/string/base/reverse-code-points/README.md similarity index 73% rename from lib/node_modules/@stdlib/string/base/reverse-code-point/README.md rename to lib/node_modules/@stdlib/string/base/reverse-code-points/README.md index d498f54eae81..83553c12c1fa 100644 --- a/lib/node_modules/@stdlib/string/base/reverse-code-point/README.md +++ b/lib/node_modules/@stdlib/string/base/reverse-code-points/README.md @@ -18,7 +18,7 @@ limitations under the License. --> -# reverseCodePoint +# reverseCodePoints > Reverse the Unicode code points of a string. @@ -27,21 +27,21 @@ limitations under the License. ## Usage ```javascript -var reverseCodePoint = require( '@stdlib/string/base/reverse-code-point' ); +var reverseCodePoints = require( '@stdlib/string/base/reverse-code-points' ); ``` -#### reverseCodePoint( str ) +#### reverseCodePoints( str ) Reverses the Unicode code points of a string. ```javascript -var out = reverseCodePoint( 'last man standing' ); +var out = reverseCodePoints( 'last man standing' ); // returns 'gnidnats nam tsal' -out = reverseCodePoint( 'Hidden Treasures' ); +out = reverseCodePoints( 'Hidden Treasures' ); // returns 'serusaerT neddiH' -out = reverseCodePoint( 'foo bar' ); +out = reverseCodePoints( 'foo bar' ); // returns 'rab oof' ``` @@ -56,18 +56,18 @@ out = reverseCodePoint( 'foo bar' ); ```javascript -var reverseCodePoint = require( '@stdlib/string/base/reverse-code-point' ); +var reverseCodePoints = require( '@stdlib/string/base/reverse-code-points' ); -var str = reverseCodePoint( 'presidential election' ); +var str = reverseCodePoints( 'presidential election' ); // returns 'noitcele laitnediserp' -str = reverseCodePoint( 'JavaScript' ); +str = reverseCodePoints( 'JavaScript' ); // returns 'tpircSavaJ' -str = reverseCodePoint( 'The Last of the Mohicans' ); +str = reverseCodePoints( 'The Last of the Mohicans' ); // returns 'snacihoM eht fo tsaL ehT' -str = reverseCodePoint( 'अनुच्छेद' ); +str = reverseCodePoints( 'अनुच्छेद' ); // returns 'देछ्चुनअ' ``` diff --git a/lib/node_modules/@stdlib/string/base/reverse-code-point/benchmark/benchmark.js b/lib/node_modules/@stdlib/string/base/reverse-code-points/benchmark/benchmark.js similarity index 100% rename from lib/node_modules/@stdlib/string/base/reverse-code-point/benchmark/benchmark.js rename to lib/node_modules/@stdlib/string/base/reverse-code-points/benchmark/benchmark.js diff --git a/lib/node_modules/@stdlib/string/base/reverse-code-point/docs/repl.txt b/lib/node_modules/@stdlib/string/base/reverse-code-points/docs/repl.txt similarity index 100% rename from lib/node_modules/@stdlib/string/base/reverse-code-point/docs/repl.txt rename to lib/node_modules/@stdlib/string/base/reverse-code-points/docs/repl.txt diff --git a/lib/node_modules/@stdlib/string/base/reverse-code-point/docs/types/index.d.ts b/lib/node_modules/@stdlib/string/base/reverse-code-points/docs/types/index.d.ts similarity index 100% rename from lib/node_modules/@stdlib/string/base/reverse-code-point/docs/types/index.d.ts rename to lib/node_modules/@stdlib/string/base/reverse-code-points/docs/types/index.d.ts diff --git a/lib/node_modules/@stdlib/string/base/reverse-code-point/docs/types/test.ts b/lib/node_modules/@stdlib/string/base/reverse-code-points/docs/types/test.ts similarity index 100% rename from lib/node_modules/@stdlib/string/base/reverse-code-point/docs/types/test.ts rename to lib/node_modules/@stdlib/string/base/reverse-code-points/docs/types/test.ts diff --git a/lib/node_modules/@stdlib/string/base/reverse-code-point/examples/index.js b/lib/node_modules/@stdlib/string/base/reverse-code-points/examples/index.js similarity index 100% rename from lib/node_modules/@stdlib/string/base/reverse-code-point/examples/index.js rename to lib/node_modules/@stdlib/string/base/reverse-code-points/examples/index.js diff --git a/lib/node_modules/@stdlib/string/base/reverse-code-point/lib/index.js b/lib/node_modules/@stdlib/string/base/reverse-code-points/lib/index.js similarity index 94% rename from lib/node_modules/@stdlib/string/base/reverse-code-point/lib/index.js rename to lib/node_modules/@stdlib/string/base/reverse-code-points/lib/index.js index a3238bb4f353..7d6e5f35db83 100644 --- a/lib/node_modules/@stdlib/string/base/reverse-code-point/lib/index.js +++ b/lib/node_modules/@stdlib/string/base/reverse-code-points/lib/index.js @@ -21,10 +21,10 @@ /** * Reverse the Unicode code points of a string. * -* @module @stdlib/string/base/reverse-code-point +* @module @stdlib/string/base/reverse-code-points * * @example -* var reverse = require( '@stdlib/string/base/reverse-code-point' ); +* var reverse = require( '@stdlib/string/base/reverse-code-points' ); * * var out = reverse( 'last man standing' ); * // returns 'gnidnats nam tsal' diff --git a/lib/node_modules/@stdlib/string/base/reverse-code-point/lib/main.js b/lib/node_modules/@stdlib/string/base/reverse-code-points/lib/main.js similarity index 100% rename from lib/node_modules/@stdlib/string/base/reverse-code-point/lib/main.js rename to lib/node_modules/@stdlib/string/base/reverse-code-points/lib/main.js diff --git a/lib/node_modules/@stdlib/string/base/reverse-code-point/package.json b/lib/node_modules/@stdlib/string/base/reverse-code-points/package.json similarity index 96% rename from lib/node_modules/@stdlib/string/base/reverse-code-point/package.json rename to lib/node_modules/@stdlib/string/base/reverse-code-points/package.json index bc82e8615f12..4a59877e1ef3 100644 --- a/lib/node_modules/@stdlib/string/base/reverse-code-point/package.json +++ b/lib/node_modules/@stdlib/string/base/reverse-code-points/package.json @@ -1,5 +1,5 @@ { - "name": "@stdlib/string/base/reverse-code-point", + "name": "@stdlib/string/base/reverse-code-points", "version": "0.0.0", "description": "Reverse the Unicode code points of a string.", "license": "Apache-2.0", diff --git a/lib/node_modules/@stdlib/string/base/reverse-code-point/test/test.js b/lib/node_modules/@stdlib/string/base/reverse-code-points/test/test.js similarity index 100% rename from lib/node_modules/@stdlib/string/base/reverse-code-point/test/test.js rename to lib/node_modules/@stdlib/string/base/reverse-code-points/test/test.js diff --git a/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/README.md b/lib/node_modules/@stdlib/string/base/reverse-grapheme-clusters/README.md similarity index 72% rename from lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/README.md rename to lib/node_modules/@stdlib/string/base/reverse-grapheme-clusters/README.md index 796eda393864..47e0de864276 100644 --- a/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/README.md +++ b/lib/node_modules/@stdlib/string/base/reverse-grapheme-clusters/README.md @@ -18,7 +18,7 @@ limitations under the License. --> -# reverseGraphemeCluster +# reverseGraphemeClusters > Reverse the grapheme clusters (i.e., user-perceived characters) of a string. @@ -29,23 +29,23 @@ limitations under the License. ```javascript -var reverseGraphemeCluster = require( '@stdlib/string/base/reverse-grapheme-cluster' ); +var reverseGraphemeClusters = require( '@stdlib/string/base/reverse-grapheme-clusters' ); ``` -#### reverseGraphemeCluster( str ) +#### reverseGraphemeClusters( str ) Reverses the grapheme clusters (i.e., user-perceived characters) of a string. ```javascript -var out = reverseGraphemeCluster( 'last man standing' ); +var out = reverseGraphemeClusters( 'last man standing' ); // returns 'gnidnats nam tsal' -out = reverseGraphemeCluster( 'Hidden Treasures' ); +out = reverseGraphemeClusters( 'Hidden Treasures' ); // returns 'serusaerT neddiH' -out = reverseGraphemeCluster( 'foo bar' ); +out = reverseGraphemeClusters( 'foo bar' ); // returns 'rab oof' ``` @@ -62,18 +62,18 @@ out = reverseGraphemeCluster( 'foo bar' ); ```javascript -var reverseGraphemeCluster = require( '@stdlib/string/base/reverse-grapheme-cluster' ); +var reverseGraphemeClusters = require( '@stdlib/string/base/reverse-grapheme-clusters' ); -var str = reverseGraphemeCluster( 'presidential election' ); +var str = reverseGraphemeClusters( 'presidential election' ); // returns 'noitcele laitnediserp' -str = reverseGraphemeCluster( 'JavaScript' ); +str = reverseGraphemeClusters( 'JavaScript' ); // returns 'tpircSavaJ' -str = reverseGraphemeCluster( 'The Last of the Mohicans' ); +str = reverseGraphemeClusters( 'The Last of the Mohicans' ); // returns 'snacihoM eht fo tsaL ehT' -str = reverseGraphemeCluster( '🐶🐮🐷🐰🐸' ); +str = reverseGraphemeClusters( '🐶🐮🐷🐰🐸' ); // returns '🐸🐰🐷🐮🐶' ``` diff --git a/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/benchmark/benchmark.js b/lib/node_modules/@stdlib/string/base/reverse-grapheme-clusters/benchmark/benchmark.js similarity index 100% rename from lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/benchmark/benchmark.js rename to lib/node_modules/@stdlib/string/base/reverse-grapheme-clusters/benchmark/benchmark.js diff --git a/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/docs/repl.txt b/lib/node_modules/@stdlib/string/base/reverse-grapheme-clusters/docs/repl.txt similarity index 100% rename from lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/docs/repl.txt rename to lib/node_modules/@stdlib/string/base/reverse-grapheme-clusters/docs/repl.txt diff --git a/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/docs/types/index.d.ts b/lib/node_modules/@stdlib/string/base/reverse-grapheme-clusters/docs/types/index.d.ts similarity index 100% rename from lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/docs/types/index.d.ts rename to lib/node_modules/@stdlib/string/base/reverse-grapheme-clusters/docs/types/index.d.ts diff --git a/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/docs/types/test.ts b/lib/node_modules/@stdlib/string/base/reverse-grapheme-clusters/docs/types/test.ts similarity index 100% rename from lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/docs/types/test.ts rename to lib/node_modules/@stdlib/string/base/reverse-grapheme-clusters/docs/types/test.ts diff --git a/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/examples/index.js b/lib/node_modules/@stdlib/string/base/reverse-grapheme-clusters/examples/index.js similarity index 70% rename from lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/examples/index.js rename to lib/node_modules/@stdlib/string/base/reverse-grapheme-clusters/examples/index.js index 621bdba60c55..2f92c9871ec3 100644 --- a/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/examples/index.js +++ b/lib/node_modules/@stdlib/string/base/reverse-grapheme-clusters/examples/index.js @@ -18,16 +18,16 @@ 'use strict'; -var reverseGraphemeCluster = require( './../lib' ); +var reverseGraphemeClusters = require( './../lib' ); -console.log( reverseGraphemeCluster( 'presidential election' ) ); +console.log( reverseGraphemeClusters( 'presidential election' ) ); // => 'noitcele laitnediserp' -console.log( reverseGraphemeCluster( 'JavaScript' ) ); +console.log( reverseGraphemeClusters( 'JavaScript' ) ); // => 'tpircSavaJ' -console.log( reverseGraphemeCluster( 'The Last of the Mohicans' ) ); +console.log( reverseGraphemeClusters( 'The Last of the Mohicans' ) ); // => 'snacihoM eht fo tsaL ehT' -console.log( reverseGraphemeCluster( '🐶🐮🐷🐰🐸' ) ); +console.log( reverseGraphemeClusters( '🐶🐮🐷🐰🐸' ) ); // => '🐸🐰🐷🐮🐶' diff --git a/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/lib/index.js b/lib/node_modules/@stdlib/string/base/reverse-grapheme-clusters/lib/index.js similarity index 94% rename from lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/lib/index.js rename to lib/node_modules/@stdlib/string/base/reverse-grapheme-clusters/lib/index.js index 7c17478125c2..2c4753e3d26f 100644 --- a/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/lib/index.js +++ b/lib/node_modules/@stdlib/string/base/reverse-grapheme-clusters/lib/index.js @@ -21,10 +21,10 @@ /** * Reverse the grapheme clusters (i.e., user-perceived characters) of a string. * -* @module @stdlib/string/base/reverse-grapheme-cluster +* @module @stdlib/string/base/reverse-grapheme-clusters * * @example -* var reverse = require( '@stdlib/string/base/reverse-grapheme-cluster' ); +* var reverse = require( '@stdlib/string/base/reverse-grapheme-clusters' ); * * var out = reverse( 'last man standing' ); * // returns 'gnidnats nam tsal' diff --git a/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/lib/main.js b/lib/node_modules/@stdlib/string/base/reverse-grapheme-clusters/lib/main.js similarity index 100% rename from lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/lib/main.js rename to lib/node_modules/@stdlib/string/base/reverse-grapheme-clusters/lib/main.js diff --git a/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/package.json b/lib/node_modules/@stdlib/string/base/reverse-grapheme-clusters/package.json similarity index 95% rename from lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/package.json rename to lib/node_modules/@stdlib/string/base/reverse-grapheme-clusters/package.json index 7c293e7b2712..5e5986361dbc 100644 --- a/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/package.json +++ b/lib/node_modules/@stdlib/string/base/reverse-grapheme-clusters/package.json @@ -1,5 +1,5 @@ { - "name": "@stdlib/string/base/first-grapheme-cluster", + "name": "@stdlib/string/base/first-grapheme-clusters", "version": "0.0.0", "description": "Reverse the grapheme cluster (i.e., user-perceived character) of a string.", "license": "Apache-2.0", diff --git a/lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/test/test.js b/lib/node_modules/@stdlib/string/base/reverse-grapheme-clusters/test/test.js similarity index 100% rename from lib/node_modules/@stdlib/string/base/reverse-grapheme-cluster/test/test.js rename to lib/node_modules/@stdlib/string/base/reverse-grapheme-clusters/test/test.js diff --git a/lib/node_modules/@stdlib/string/reverse/lib/main.js b/lib/node_modules/@stdlib/string/reverse/lib/main.js index 85f504ea6a66..3828e1d1d553 100644 --- a/lib/node_modules/@stdlib/string/reverse/lib/main.js +++ b/lib/node_modules/@stdlib/string/reverse/lib/main.js @@ -25,8 +25,8 @@ var isPlainObject = require( '@stdlib/assert/is-plain-object' ); var hasOwnProp = require( '@stdlib/assert/has-own-property' ); var contains = require( '@stdlib/array/base/assert/contains' ).factory; var reverseCodeUnit = require( '@stdlib/string/base/reverse' ); -var reverseCodePoint = require( '@stdlib/string/base/reverse-code-point' ); -var reverseGraphemeCluster = require( '@stdlib/string/base/reverse-grapheme-cluster' ); +var reverseCodePoints = require( '@stdlib/string/base/reverse-code-points' ); +var reverseGraphemeClusters = require( '@stdlib/string/base/reverse-grapheme-clusters' ); var format = require( '@stdlib/string/format' ); @@ -34,8 +34,8 @@ var format = require( '@stdlib/string/format' ); var MODES = [ 'grapheme', 'code_point', 'code_unit' ]; var FCNS = { - 'grapheme': reverseGraphemeCluster, - 'code_point': reverseCodePoint, + 'grapheme': reverseGraphemeClusters, + 'code_point': reverseCodePoints, 'code_unit': reverseCodeUnit }; var isMode = contains( MODES ); From 0901c7f784ac792a6ddd2a164492875b26936b3d Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 21 Sep 2023 16:04:14 -0700 Subject: [PATCH 5/9] Apply suggestions from code review --- .../@stdlib/string/base/reverse-code-points/lib/main.js | 6 ++---- .../@stdlib/string/base/reverse-code-points/test/test.js | 6 +++--- .../string/base/reverse-grapheme-clusters/package.json | 4 ++-- lib/node_modules/@stdlib/string/base/reverse/lib/main.js | 4 ++-- lib/node_modules/@stdlib/string/reverse/README.md | 2 +- lib/node_modules/@stdlib/string/reverse/docs/repl.txt | 4 ++-- .../@stdlib/string/reverse/docs/types/index.d.ts | 4 ++-- lib/node_modules/@stdlib/string/reverse/docs/usage.txt | 2 +- lib/node_modules/@stdlib/string/reverse/test/test.cli.js | 2 +- 9 files changed, 16 insertions(+), 18 deletions(-) diff --git a/lib/node_modules/@stdlib/string/base/reverse-code-points/lib/main.js b/lib/node_modules/@stdlib/string/base/reverse-code-points/lib/main.js index f88f5ac1485e..5f6360b0aabf 100644 --- a/lib/node_modules/@stdlib/string/base/reverse-code-points/lib/main.js +++ b/lib/node_modules/@stdlib/string/base/reverse-code-points/lib/main.js @@ -76,12 +76,10 @@ function reverse( str ) { // We found a surrogate pair: out = ch1 + ch2 + out; i += 1; // bump the index to process the next code unit - } - else { + } else { out = ch1 + out; } - } - else { + } else { out = ch1 + out; } } diff --git a/lib/node_modules/@stdlib/string/base/reverse-code-points/test/test.js b/lib/node_modules/@stdlib/string/base/reverse-code-points/test/test.js index 552d51fbd488..7f7866d1eda4 100644 --- a/lib/node_modules/@stdlib/string/base/reverse-code-points/test/test.js +++ b/lib/node_modules/@stdlib/string/base/reverse-code-points/test/test.js @@ -37,7 +37,7 @@ tape( 'the function returns an empty string if provided an empty string', functi t.end(); }); -tape( 'the function reverses the Unicode code point of a provided string (ascii)', function test( t ) { +tape( 'the function reverses the Unicode code points of a provided string (ascii)', function test( t ) { var out; out = reverse( 'hello world' ); @@ -52,7 +52,7 @@ tape( 'the function reverses the Unicode code point of a provided string (ascii) t.end(); }); -tape( 'the function reverses the Unicode code point of a provided string (Unicode)', function test( t ) { +tape( 'the function reverses the Unicode code points of a provided string (Unicode)', function test( t ) { var out; out = reverse( 'अनुच्छेद' ); @@ -64,7 +64,7 @@ tape( 'the function reverses the Unicode code point of a provided string (Unicod t.end(); }); -tape( 'the function reverses the Unicode code point of a provided string (surrogate pair)', function test( t ) { +tape( 'the function reverses the Unicode code points of a provided string (surrogate pair)', function test( t ) { var out; out = reverse( 'foo\uD834\uDF06bar' ); diff --git a/lib/node_modules/@stdlib/string/base/reverse-grapheme-clusters/package.json b/lib/node_modules/@stdlib/string/base/reverse-grapheme-clusters/package.json index 5e5986361dbc..dd9070a92e36 100644 --- a/lib/node_modules/@stdlib/string/base/reverse-grapheme-clusters/package.json +++ b/lib/node_modules/@stdlib/string/base/reverse-grapheme-clusters/package.json @@ -1,7 +1,7 @@ { - "name": "@stdlib/string/base/first-grapheme-clusters", + "name": "@stdlib/string/base/reverse-grapheme-clusters", "version": "0.0.0", - "description": "Reverse the grapheme cluster (i.e., user-perceived character) of a string.", + "description": "Reverse the grapheme clusters (i.e., user-perceived characters) of a string.", "license": "Apache-2.0", "author": { "name": "The Stdlib Authors", diff --git a/lib/node_modules/@stdlib/string/base/reverse/lib/main.js b/lib/node_modules/@stdlib/string/base/reverse/lib/main.js index a213dc65aad4..f8e3dcd7e083 100644 --- a/lib/node_modules/@stdlib/string/base/reverse/lib/main.js +++ b/lib/node_modules/@stdlib/string/base/reverse/lib/main.js @@ -47,8 +47,8 @@ function reverse( str ) { var i; out = ''; - for ( i = str.length - 1; i >= 0; i--) { - out += str[i]; + for ( i = str.length - 1; i >= 0; i-- ) { + out += str[ i ]; } return out; } diff --git a/lib/node_modules/@stdlib/string/reverse/README.md b/lib/node_modules/@stdlib/string/reverse/README.md index 99afd4d81185..a95a9fae4db8 100644 --- a/lib/node_modules/@stdlib/string/reverse/README.md +++ b/lib/node_modules/@stdlib/string/reverse/README.md @@ -47,7 +47,7 @@ out = reverseString( 'Lorem ipsum 𝌆 dolor sit ameͨ͆t.' ); The function supports the following options: -- **mode**: type of characters to return. Must be one of the following: +- **mode**: type of characters to reverse. 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). diff --git a/lib/node_modules/@stdlib/string/reverse/docs/repl.txt b/lib/node_modules/@stdlib/string/reverse/docs/repl.txt index 9a996c8b035b..06ec709581fc 100644 --- a/lib/node_modules/@stdlib/string/reverse/docs/repl.txt +++ b/lib/node_modules/@stdlib/string/reverse/docs/repl.txt @@ -1,6 +1,6 @@ {{alias}}( str[, options] ) - Reverses a `string`. + Reverses a string. Parameters ---------- @@ -11,7 +11,7 @@ Options. options.mode: string (optional) - Type of characters to return. The following modes are supported: + Type of characters to reverse. The following modes are supported: - grapheme: grapheme clusters. Appropriate for strings containing visual characters which can span multiple Unicode code points (e.g., emoji). diff --git a/lib/node_modules/@stdlib/string/reverse/docs/types/index.d.ts b/lib/node_modules/@stdlib/string/reverse/docs/types/index.d.ts index ba473c8aa025..028f6fb12b4a 100644 --- a/lib/node_modules/@stdlib/string/reverse/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/string/reverse/docs/types/index.d.ts @@ -25,11 +25,11 @@ */ interface Options { /** - * Specifies the type of characters to return (default: 'grapheme'). + * Specifies the type of characters to reverse (default: 'grapheme'). * * ## Notes * - * - The following option values are supported: + * - 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). diff --git a/lib/node_modules/@stdlib/string/reverse/docs/usage.txt b/lib/node_modules/@stdlib/string/reverse/docs/usage.txt index c1aee420147d..b0a676239ca4 100644 --- a/lib/node_modules/@stdlib/string/reverse/docs/usage.txt +++ b/lib/node_modules/@stdlib/string/reverse/docs/usage.txt @@ -6,4 +6,4 @@ Options: -h, --help Print this message. -V, --version Print the package version. --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. - --mode mode Type of character to return. Default: 'grapheme'. + --mode mode Type of character to reverse. Default: 'grapheme'. diff --git a/lib/node_modules/@stdlib/string/reverse/test/test.cli.js b/lib/node_modules/@stdlib/string/reverse/test/test.cli.js index 17977c7a5194..394ca6f99cc9 100644 --- a/lib/node_modules/@stdlib/string/reverse/test/test.cli.js +++ b/lib/node_modules/@stdlib/string/reverse/test/test.cli.js @@ -162,7 +162,7 @@ tape( 'the command-line interface reverses a string argument', opts, function te } }); -tape( 'the command-line interface supports specifying the type of characters to return', opts, function test( t ) { +tape( 'the command-line interface supports specifying the type of characters to reverse', opts, function test( t ) { var cmd = [ EXEC_PATH, '-e', From 6bad9fd0a792e860f27baa777bb412bfd1068c53 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 21 Sep 2023 16:06:42 -0700 Subject: [PATCH 6/9] Apply suggestions from code review --- .../@stdlib/string/base/reverse-grapheme-clusters/README.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/lib/node_modules/@stdlib/string/base/reverse-grapheme-clusters/README.md b/lib/node_modules/@stdlib/string/base/reverse-grapheme-clusters/README.md index 47e0de864276..3cf6926c1d77 100644 --- a/lib/node_modules/@stdlib/string/base/reverse-grapheme-clusters/README.md +++ b/lib/node_modules/@stdlib/string/base/reverse-grapheme-clusters/README.md @@ -26,8 +26,6 @@ limitations under the License. ## Usage - - ```javascript var reverseGraphemeClusters = require( '@stdlib/string/base/reverse-grapheme-clusters' ); ``` @@ -36,8 +34,6 @@ var reverseGraphemeClusters = require( '@stdlib/string/base/reverse-grapheme-clu Reverses the grapheme clusters (i.e., user-perceived characters) of a string. - - ```javascript var out = reverseGraphemeClusters( 'last man standing' ); // returns 'gnidnats nam tsal' @@ -59,8 +55,6 @@ out = reverseGraphemeClusters( 'foo bar' ); - - ```javascript var reverseGraphemeClusters = require( '@stdlib/string/base/reverse-grapheme-clusters' ); From a02dc34962a962f9bd4485d9ce5521171781b0a3 Mon Sep 17 00:00:00 2001 From: Athan Date: Thu, 21 Sep 2023 16:09:36 -0700 Subject: [PATCH 7/9] Apply suggestions from code review --- lib/node_modules/@stdlib/string/reverse/docs/types/index.d.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/node_modules/@stdlib/string/reverse/docs/types/index.d.ts b/lib/node_modules/@stdlib/string/reverse/docs/types/index.d.ts index 028f6fb12b4a..add71c374893 100644 --- a/lib/node_modules/@stdlib/string/reverse/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/string/reverse/docs/types/index.d.ts @@ -18,8 +18,6 @@ // TypeScript Version: 2.0 -// tslint:disable:unified-signatures - /** * Interface describing function options. */ From 6a05b257b6d5cb33901ed0978c2da552d35bb99e Mon Sep 17 00:00:00 2001 From: Stephannie Jimenez Date: Tue, 26 Sep 2023 14:55:46 -0500 Subject: [PATCH 8/9] fix: use nextGraphemeCluster in implementation, fix tests and docstrings --- .../base/reverse-grapheme-clusters/lib/main.js | 18 ++++++++++++------ .../@stdlib/string/reverse/docs/types/test.ts | 10 ++++++++++ .../@stdlib/string/reverse/lib/main.js | 1 + .../@stdlib/string/reverse/test/test.js | 4 ++-- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/string/base/reverse-grapheme-clusters/lib/main.js b/lib/node_modules/@stdlib/string/base/reverse-grapheme-clusters/lib/main.js index 9815ac5e6e61..f2405c942809 100644 --- a/lib/node_modules/@stdlib/string/base/reverse-grapheme-clusters/lib/main.js +++ b/lib/node_modules/@stdlib/string/base/reverse-grapheme-clusters/lib/main.js @@ -20,7 +20,7 @@ // MODULES // -var prevGraphemeClusterBreak = require( '@stdlib/string/prev-grapheme-cluster-break' ); +var nextGraphemeClusterBreak = require( '@stdlib/string/next-grapheme-cluster-break' ); // MAIN // @@ -52,18 +52,24 @@ var prevGraphemeClusterBreak = require( '@stdlib/string/prev-grapheme-cluster-br * // returns '🐸🐰🐷🐮🐶' */ function reverse( str ) { + var cluster; var out; var idx; var brk; var i; out = ''; - idx = str.length - 1; - while ( idx >= 0 ) { - brk = prevGraphemeClusterBreak( str, idx ); - for ( i = brk + 1; i <= idx; i++ ) { - out += str.charAt( i ); + idx = 0; + while ( idx < str.length ) { + brk = nextGraphemeClusterBreak( str, idx ); + if ( brk === -1 ) { + brk = str.length; } + cluster = ''; + for ( i = idx; i < brk; i++ ) { + cluster += str.charAt( i ); + } + out = cluster + out; idx = brk; } return out; diff --git a/lib/node_modules/@stdlib/string/reverse/docs/types/test.ts b/lib/node_modules/@stdlib/string/reverse/docs/types/test.ts index 0a961943a0bc..a4fd92322c9c 100644 --- a/lib/node_modules/@stdlib/string/reverse/docs/types/test.ts +++ b/lib/node_modules/@stdlib/string/reverse/docs/types/test.ts @@ -47,6 +47,16 @@ import reverseString = require( './index' ); reverseString( ( x: number ): number => x, {} ); // $ExpectError } +// The compiler throws an error if the function is provided a value other than an object as second argument... +{ + reverseString( 'abc', true ); // $ExpectError + reverseString( 'abc', false ); // $ExpectError + reverseString( 'abc', null ); // $ExpectError + reverseString( 'abc', '' ); // $ExpectError + reverseString( 'abc', [] ); // $ExpectError + reverseString( 'abc', ( x: number ): number => x ); // $ExpectError +} + // The compiler throws an error if the function is provided an invalid `mode` option... { reverseString( 'abc', { 'mode': true } ); // $ExpectError diff --git a/lib/node_modules/@stdlib/string/reverse/lib/main.js b/lib/node_modules/@stdlib/string/reverse/lib/main.js index 3828e1d1d553..a61f598ac3ff 100644 --- a/lib/node_modules/@stdlib/string/reverse/lib/main.js +++ b/lib/node_modules/@stdlib/string/reverse/lib/main.js @@ -48,6 +48,7 @@ var isMode = contains( MODES ); * * @param {string} str - input string * @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} must provide a string primitive * @throws {TypeError} options argument must be an object * @throws {TypeError} must provide valid options diff --git a/lib/node_modules/@stdlib/string/reverse/test/test.js b/lib/node_modules/@stdlib/string/reverse/test/test.js index 44b5eb47f69e..9d1debfc52d2 100644 --- a/lib/node_modules/@stdlib/string/reverse/test/test.js +++ b/lib/node_modules/@stdlib/string/reverse/test/test.js @@ -224,8 +224,8 @@ tape( 'the function reverses the first string (mode=grapheme)', function test( t out = reverseString( '🌷', opts ); t.strictEqual( out, '🌷', 'returns expected value' ); - out = reverseString( '👉🏿', opts ); - t.strictEqual( out, '🏿👉', 'returns expected value' ); + out = reverseString( '👉🏿🌷', opts ); + t.strictEqual( out, '🌷👉🏿', 'returns expected value' ); t.end(); }); From a7e4835497fd300a8045f8272ddcfbc6303de7f3 Mon Sep 17 00:00:00 2001 From: Athan Date: Mon, 30 Oct 2023 22:16:28 -0700 Subject: [PATCH 9/9] Apply suggestions from code review --- .../@stdlib/string/reverse/docs/types/test.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/lib/node_modules/@stdlib/string/reverse/docs/types/test.ts b/lib/node_modules/@stdlib/string/reverse/docs/types/test.ts index a4fd92322c9c..888c2d1341f7 100644 --- a/lib/node_modules/@stdlib/string/reverse/docs/types/test.ts +++ b/lib/node_modules/@stdlib/string/reverse/docs/types/test.ts @@ -49,6 +49,8 @@ import reverseString = require( './index' ); // The compiler throws an error if the function is provided a value other than an object as second argument... { + reverseString( 'abc', '1' ); // $ExpectError + reverseString( 'abc', 1 ); // $ExpectError reverseString( 'abc', true ); // $ExpectError reverseString( 'abc', false ); // $ExpectError reverseString( 'abc', null ); // $ExpectError @@ -65,14 +67,6 @@ import reverseString = require( './index' ); reverseString( 'abc', { 'mode': '' } ); // $ExpectError reverseString( 'abc', { 'mode': [] } ); // $ExpectError reverseString( 'abc', { 'mode': ( x: number ): number => x } ); // $ExpectError - - reverseString( 'abc', 1, { 'mode': true } ); // $ExpectError - reverseString( 'abc', 1, { 'mode': false } ); // $ExpectError - reverseString( 'abc', 1, { 'mode': null } ); // $ExpectError - reverseString( 'abc', 1, { 'mode': '' } ); // $ExpectError - reverseString( 'abc', 1, { 'mode': [] } ); // $ExpectError - reverseString( 'abc', 1, { 'mode': {} } ); // $ExpectError - reverseString( 'abc', 1, { 'mode': ( x: number ): number => x } ); // $ExpectError } // The compiler throws an error if the function is provided insufficient arguments...