From fb4f1f08651f4465ea01dc5aed602c08edd9a8c7 Mon Sep 17 00:00:00 2001 From: AuenKr Date: Sat, 24 Feb 2024 11:31:45 +0530 Subject: [PATCH 01/11] feat: add @stdlib/string/base/replace-after --- .../string/base/replace-after/README.md | 122 ++++++++++++++++++ .../base/replace-after/benchmark/benchmark.js | 58 +++++++++ .../string/base/replace-after/docs/repl.txt | 32 +++++ .../base/replace-after/docs/types/index.d.ts | 50 +++++++ .../base/replace-after/docs/types/test.ts | 60 +++++++++ .../base/replace-after/examples/index.js | 37 ++++++ .../string/base/replace-after/lib/index.js | 45 +++++++ .../string/base/replace-after/lib/main.js | 58 +++++++++ .../string/base/replace-after/package.json | 68 ++++++++++ .../string/base/replace-after/test/test.js | 97 ++++++++++++++ 10 files changed, 627 insertions(+) create mode 100644 lib/node_modules/@stdlib/string/base/replace-after/README.md create mode 100644 lib/node_modules/@stdlib/string/base/replace-after/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/string/base/replace-after/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/string/base/replace-after/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/string/base/replace-after/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/string/base/replace-after/examples/index.js create mode 100644 lib/node_modules/@stdlib/string/base/replace-after/lib/index.js create mode 100644 lib/node_modules/@stdlib/string/base/replace-after/lib/main.js create mode 100644 lib/node_modules/@stdlib/string/base/replace-after/package.json create mode 100644 lib/node_modules/@stdlib/string/base/replace-after/test/test.js diff --git a/lib/node_modules/@stdlib/string/base/replace-after/README.md b/lib/node_modules/@stdlib/string/base/replace-after/README.md new file mode 100644 index 000000000000..52e8207bacf6 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/replace-after/README.md @@ -0,0 +1,122 @@ + + +# replaceAfter + +> Replace the substring after the first occurrence of a specified search string. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var replaceAfter = require( '@stdlib/string/base/replace-after' ); +``` + +#### replaceAfter( str, search, replacement ) + +Replaces the substring after the first occurrence of a specified search string. + +```javascript +var out = replaceAfter( 'beep boop', ' ', 'loop' ); +// returns 'beep loop' + +out = replaceAfter( 'beep boop', 'o', 'bar' ); +// returns 'beep bobar' +``` + +
+ + + + + +
+ +## Notes + +- If a search string is not present in a provided string, the function returns the provided string unchanged. +- If a search string is an empty string, the function returns the provided string unchanged. + +
+ + + + + +
+ +## Examples + + + +```javascript +var replaceAfter = require( '@stdlib/string/base/replace-after' ); + +var out = replaceAfter( 'beep boop', 'p', 'see' ); +// returns 'beepsee' + +out = replaceAfter( 'Hello World!', 'xyz', 'foo' ); +// returns 'Hello World!' + +out = replaceAfter( 'Hello World!', '', 'foo' ); +// returns 'Hello World!' + +out = replaceAfter( '', 'xyz', 'foo'); +// returns '' +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/string/base/replace-after/benchmark/benchmark.js b/lib/node_modules/@stdlib/string/base/replace-after/benchmark/benchmark.js new file mode 100644 index 000000000000..5d1e7b3857ee --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/replace-after/benchmark/benchmark.js @@ -0,0 +1,58 @@ +/** +* @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 replaceAfter = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var values; + var out; + var str; + var i; + + str = 'To be, or not to be, that is the question.'; + values = [ + 'foo', + 'bar', + 'beep', + 'boop' + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = replaceAfter( str, '.', 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/replace-after/docs/repl.txt b/lib/node_modules/@stdlib/string/base/replace-after/docs/repl.txt new file mode 100644 index 000000000000..77e11861ab29 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/replace-after/docs/repl.txt @@ -0,0 +1,32 @@ + +{{alias}}( str, search, replacement ) + Replaces the substring after the first occurrence of a specified search + string. + + Parameters + ---------- + str: string + Input string. + + search: string + Search string. + + replacement: string + Replacement string. + + Returns + ------- + out: string + Output string. + + Examples + -------- + > var str = 'beep boop'; + > var out = {{alias}}( str, ' ', 'foo' ) + 'beep foo' + > out = {{alias}}( str, 'o', 'foo' ) + 'beep bofoo' + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/string/base/replace-after/docs/types/index.d.ts b/lib/node_modules/@stdlib/string/base/replace-after/docs/types/index.d.ts new file mode 100644 index 000000000000..6dc3cfd3b206 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/replace-after/docs/types/index.d.ts @@ -0,0 +1,50 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 4.1 + +/** +* Replaces the substring after the first occurrence of a specified search string. +* +* @param str - input string +* @param search - search string +* @param replacement - replacement string +* @returns output string +* +* @example +* var out = replaceAfter( 'beep boop', ' ', 'foo' ); +* // returns 'beep foo' +* +* @example +* var out = replaceAfter( 'beep boop', 'p', 'foo' ); +* // returns 'beepfoo' +* +* @example +* var out = replaceAfter( 'Hello World!', '', 'foo' ); +* // returns 'Hello World!' +* +* @example +* var out = replaceAfter( 'Hello World!', 'xyz', 'foo' ); +* // returns 'Hello World!' +*/ +declare function replaceAfter( str: string, search: string, replacement: string ): string; + + +// EXPORTS // + +export = replaceAfter; diff --git a/lib/node_modules/@stdlib/string/base/replace-after/docs/types/test.ts b/lib/node_modules/@stdlib/string/base/replace-after/docs/types/test.ts new file mode 100644 index 000000000000..57094c4adec3 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/replace-after/docs/types/test.ts @@ -0,0 +1,60 @@ +/* +* @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 replaceAfter = require( './index' ); + + +// TESTS // + +// The function returns a string... +{ + replaceAfter( 'beep boop', ' ', 'foo' ); // $ExpectType string + replaceAfter( 'beep boop', 'xyz', 'foo' ); // $ExpectType string + replaceAfter( 'beep boop', '', 'foo' ); // $ExpectType string +} + +// The compiler throws an error if the function is provided arguments having invalid types... +{ + replaceAfter( true, 'd', 'foo' ); // $ExpectError + replaceAfter( false, 'd' , 'foo' ); // $ExpectError + replaceAfter( 3, 'd' , 'foo' ); // $ExpectError + replaceAfter( [], 'd' , 'foo' ); // $ExpectError + replaceAfter( {}, 'd' , 'foo' ); // $ExpectError + replaceAfter( ( x: number ): number => x, 'd', 'foo' ); // $ExpectError + + replaceAfter( 'abc', true, 'foo' ); // $ExpectError + replaceAfter( 'abc', false, 'foo' ); // $ExpectError + replaceAfter( 'abc', 5 , 'foo' ); // $ExpectError + replaceAfter( 'abc', [], 'foo' ); // $ExpectError + replaceAfter( 'abc', {} , 'foo' ); // $ExpectError + replaceAfter( 'abc', ( x: number ): number => x , 'foo' ); // $ExpectError + + replaceAfter( 'abc', 'd', true ); // $ExpectError + replaceAfter( 'abc', 'd', false ); // $ExpectError + replaceAfter( 'abc', 'd', 5 ); // $ExpectError + replaceAfter( 'abc', 'd', [] ); // $ExpectError + replaceAfter( 'abc', 'd', {} ); // $ExpectError + replaceAfter( 'abc', 'd', ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided insufficient arguments... +{ + replaceAfter(); // $ExpectError + replaceAfter( 'abc' ); // $ExpectError + replaceAfter( 'abc', 'd' ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/string/base/replace-after/examples/index.js b/lib/node_modules/@stdlib/string/base/replace-after/examples/index.js new file mode 100644 index 000000000000..2d9df5273f23 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/replace-after/examples/index.js @@ -0,0 +1,37 @@ +/** +* @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 replaceAfter = require( './../lib' ); + +var out = replaceAfter( 'beep boop', 'p', 'see' ); +console.log( out ); +// => 'beepsee' + +out = replaceAfter( 'Hello World!', 'xyz', 'foo' ); +console.log( out ); +// => 'Hello World!' + +out = replaceAfter( 'Hello World!', '', 'foo' ); +console.log( out ); +// => 'Hello World!' + +out = replaceAfter( '', 'xyz', 'foo' ); +console.log( out ); +// => '' diff --git a/lib/node_modules/@stdlib/string/base/replace-after/lib/index.js b/lib/node_modules/@stdlib/string/base/replace-after/lib/index.js new file mode 100644 index 000000000000..88b6e9707522 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/replace-after/lib/index.js @@ -0,0 +1,45 @@ +/** +* @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'; + +/** +* Replace the substring after the first occurrence of a specified search string. +* +* @module @stdlib/string/base/replace-after +* +* @example +* var replaceAfter = require( '@stdlib/string/base/replace-after' ); +* +* var str = 'beep boop'; +* +* var out = replaceAfter( str, ' ', 'foo' ); +* // returns 'beep foo' +* +* out = replaceAfter( str, 'o', 'bar' ); +* // returns 'beep bobar' +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/string/base/replace-after/lib/main.js b/lib/node_modules/@stdlib/string/base/replace-after/lib/main.js new file mode 100644 index 000000000000..bcf61fec3de2 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/replace-after/lib/main.js @@ -0,0 +1,58 @@ +/** +* @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 // + +/** +* Replaces the substring after the first occurrence of a specified search string. +* +* @param {string} str - input string +* @param {string} search - search string +* @param {string} replacement - replacement string +* @returns {string} string +* +* @example +* var out = replaceAfter( 'beep boop', ' ', 'foo' ); +* // returns 'beep foo' +* +* @example +* var out = replaceAfter( 'beep boop', 'p', 'foo' ); +* // returns 'beepfoo' +* +* @example +* var out = replaceAfter( 'Hello World!', '', 'foo' ); +* // returns 'Hello World!' +* +* @example +* var out = replaceAfter( 'Hello World!', 'xyz', 'foo' ); +* // returns 'Hello World!' +*/ +function replaceAfter( str, search, replacement ) { + var idx = str.indexOf( search ); + if ( str === '' || search === '' || replacement === '' || idx < 0 ) { + return str; + } + return str.substring(0, idx + search.length ) + replacement; +} + + +// EXPORTS // + +module.exports = replaceAfter; diff --git a/lib/node_modules/@stdlib/string/base/replace-after/package.json b/lib/node_modules/@stdlib/string/base/replace-after/package.json new file mode 100644 index 000000000000..07094952dd27 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/replace-after/package.json @@ -0,0 +1,68 @@ +{ + "name": "@stdlib/string/base/replace-after", + "version": "0.0.0", + "description": "Replace the substring after the first occurrence of a specified search 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", + "base", + "string", + "str", + "replace", + "search", + "substring", + "substr", + "after", + "match" + ] +} diff --git a/lib/node_modules/@stdlib/string/base/replace-after/test/test.js b/lib/node_modules/@stdlib/string/base/replace-after/test/test.js new file mode 100644 index 000000000000..c8f51614b226 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/replace-after/test/test.js @@ -0,0 +1,97 @@ +/** +* @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 replaceAfter = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof replaceAfter, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function replaces the substring after the first occurrence of a specified search string', function test( t ) { + var expected; + var actual; + + actual = replaceAfter( 'beep boop', ' ', 'foo' ); + expected = 'beep foo'; + t.strictEqual( actual, expected, 'returns expected value' ); + + actual = replaceAfter( 'beep boop', 'p', 'foo' ); + expected = 'beepfoo'; + t.strictEqual( actual, expected, 'returns expected value' ); + + actual = replaceAfter( 'Hello, World!', 'o', 'foo' ); + expected = 'Hellofoo'; + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function replaces the substring after the first occurrence of a specified search string (Unicode characters)', function test( t ) { + var expected; + var actual; + + actual = replaceAfter( 'beep 😀 boop 😀 baz', '😀', 'foo' ); + expected = 'beep 😀foo'; + t.strictEqual( actual, expected, 'returns expected value' ); + + actual = replaceAfter( '🤖 Robot army 🤖!', '🤖', 'foo' ); + expected = '🤖foo'; + t.strictEqual( actual, expected, 'returns expected value' ); + + actual = replaceAfter( '🐺 Wolf brothers 🐺', 'o', 'foo' ); + expected = '🐺 Wofoo'; + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the entire string if the search string is not found', function test( t ) { + var expected; + var actual; + + actual = replaceAfter( 'beep boop', 'z', 'foo' ); + expected = 'beep boop'; + t.strictEqual( actual, expected, 'returns expected value' ); + + actual = replaceAfter( 'beep boop', 'baz', 'foo' ); + expected = 'beep boop'; + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the entire string if the search string is the empty string', function test( t ) { + var expected; + var actual; + + actual = replaceAfter( 'beep boop', '', 'foo' ); + expected = 'beep boop'; + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); From 97e35fa7e797f7f6d2298df1fa1f645587db2a65 Mon Sep 17 00:00:00 2001 From: Golden <103646877+AuenKr@users.noreply.github.com> Date: Sat, 24 Feb 2024 15:33:52 +0530 Subject: [PATCH 02/11] Update lib/node_modules/@stdlib/string/base/replace-after/README.md Co-authored-by: Athan Signed-off-by: Golden <103646877+AuenKr@users.noreply.github.com> --- lib/node_modules/@stdlib/string/base/replace-after/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/string/base/replace-after/README.md b/lib/node_modules/@stdlib/string/base/replace-after/README.md index 52e8207bacf6..3ab4d09774de 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after/README.md +++ b/lib/node_modules/@stdlib/string/base/replace-after/README.md @@ -89,7 +89,7 @@ out = replaceAfter( 'Hello World!', 'xyz', 'foo' ); out = replaceAfter( 'Hello World!', '', 'foo' ); // returns 'Hello World!' -out = replaceAfter( '', 'xyz', 'foo'); +out = replaceAfter( '', 'xyz', 'foo' ); // returns '' ``` From 238a8a2e1057bfbc351e22734da79d1290474945 Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 24 Feb 2024 02:04:45 -0800 Subject: [PATCH 03/11] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/string/base/replace-after/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/string/base/replace-after/lib/main.js b/lib/node_modules/@stdlib/string/base/replace-after/lib/main.js index bcf61fec3de2..61e726b4d731 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after/lib/main.js +++ b/lib/node_modules/@stdlib/string/base/replace-after/lib/main.js @@ -49,7 +49,7 @@ function replaceAfter( str, search, replacement ) { if ( str === '' || search === '' || replacement === '' || idx < 0 ) { return str; } - return str.substring(0, idx + search.length ) + replacement; + return str.substring( 0, idx + search.length ) + replacement; } From 609b2ce0e6626153d58562d66f5250761cd5aff4 Mon Sep 17 00:00:00 2001 From: AuenKr Date: Sat, 24 Feb 2024 23:14:30 +0530 Subject: [PATCH 04/11] fixup! feat: add fromIndex argument --- .../string/base/replace-after/README.md | 17 +++++++++--- .../base/replace-after/benchmark/benchmark.js | 2 +- .../string/base/replace-after/docs/repl.txt | 14 +++++++--- .../base/replace-after/docs/types/index.d.ts | 13 +++++++-- .../base/replace-after/docs/types/test.ts | 4 ++- .../base/replace-after/examples/index.js | 10 ++++++- .../string/base/replace-after/lib/index.js | 8 +++++- .../string/base/replace-after/lib/main.js | 23 +++++++++++++--- .../string/base/replace-after/test/test.js | 27 ++++++++++++++++++- 9 files changed, 100 insertions(+), 18 deletions(-) diff --git a/lib/node_modules/@stdlib/string/base/replace-after/README.md b/lib/node_modules/@stdlib/string/base/replace-after/README.md index 3ab4d09774de..a9d8978fdc05 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after/README.md +++ b/lib/node_modules/@stdlib/string/base/replace-after/README.md @@ -2,7 +2,7 @@ @license Apache-2.0 -Copyright (c) 2023 The Stdlib Authors. +Copyright (c) 2024 The Stdlib Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -40,9 +40,9 @@ limitations under the License. var replaceAfter = require( '@stdlib/string/base/replace-after' ); ``` -#### replaceAfter( str, search, replacement ) +#### replaceAfter( str, search, replacement, fromIndex ) -Replaces the substring after the first occurrence of a specified search string. +Returns the part of a string after replacing. ```javascript var out = replaceAfter( 'beep boop', ' ', 'loop' ); @@ -52,6 +52,13 @@ out = replaceAfter( 'beep boop', 'o', 'bar' ); // returns 'beep bobar' ``` +By default, the search starts at the beginning of the string. To start searching from a different index, provide a `fromIndex` argument: + +```javascript +var out = replaceAfter( 'beep boop beep baz', 'beep', 'foo', 5 ); +// return 'beep boop beepfoo' +``` + @@ -64,6 +71,7 @@ out = replaceAfter( 'beep boop', 'o', 'bar' ); - If a search string is not present in a provided string, the function returns the provided string unchanged. - If a search string is an empty string, the function returns the provided string unchanged. +- If `fromIndex` is less than `0` or greater than `str.length`, the search starts at index `0` and `str.length`, respectively. @@ -91,6 +99,9 @@ out = replaceAfter( 'Hello World!', '', 'foo' ); out = replaceAfter( '', 'xyz', 'foo' ); // returns '' + +out = replaceAfter( 'beep boop beep baz', 'beep', 'foo', 5 ); +// return 'beep boop beepfoo' ``` diff --git a/lib/node_modules/@stdlib/string/base/replace-after/benchmark/benchmark.js b/lib/node_modules/@stdlib/string/base/replace-after/benchmark/benchmark.js index 5d1e7b3857ee..ab3fb92819b5 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/string/base/replace-after/benchmark/benchmark.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2023 The Stdlib Authors. +* Copyright (c) 2024 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. diff --git a/lib/node_modules/@stdlib/string/base/replace-after/docs/repl.txt b/lib/node_modules/@stdlib/string/base/replace-after/docs/repl.txt index 77e11861ab29..03ada0adfafb 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after/docs/repl.txt +++ b/lib/node_modules/@stdlib/string/base/replace-after/docs/repl.txt @@ -1,5 +1,5 @@ -{{alias}}( str, search, replacement ) +{{alias}}( str, search, replacement[, fromIndex] ) Replaces the substring after the first occurrence of a specified search string. @@ -14,6 +14,9 @@ replacement: string Replacement string. + fromIndex: integer (optional) + Index from which to start the search. Default: `0`. + Returns ------- out: string @@ -21,11 +24,14 @@ Examples -------- - > var str = 'beep boop'; - > var out = {{alias}}( str, ' ', 'foo' ) + > var out = {{alias}}( 'beep boop', ' ', 'foo' ) 'beep foo' - > out = {{alias}}( str, 'o', 'foo' ) + > out = {{alias}}( 'beep boop', 'o', 'foo' ) 'beep bofoo' + > var out = {{alias}}( 'Hello World!', 'l', 'foo', 3 ) + 'Hellfoo' + > var out = {{alias}}( 'beep boop beep baz', 'beep', 'foo', 5 ) + 'beep boop beepfoo' See Also -------- diff --git a/lib/node_modules/@stdlib/string/base/replace-after/docs/types/index.d.ts b/lib/node_modules/@stdlib/string/base/replace-after/docs/types/index.d.ts index 6dc3cfd3b206..9fd9da93c446 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/string/base/replace-after/docs/types/index.d.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2023 The Stdlib Authors. +* Copyright (c) 2024 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. @@ -24,6 +24,7 @@ * @param str - input string * @param search - search string * @param replacement - replacement string +* @param fromIndex - index at which to start the search (default: 0) * @returns output string * * @example @@ -41,8 +42,16 @@ * @example * var out = replaceAfter( 'Hello World!', 'xyz', 'foo' ); * // returns 'Hello World!' +* +* @example +* var out = replaceAfter( 'beep boop', ' ', 'foo' , 5 ); +* // returns 'beep foo' +* +* @example +* var out = replaceAfter( 'beep boop beep baz', 'beep', 'foo' , 5 ); +* // returns 'beep boop beepfoo' */ -declare function replaceAfter( str: string, search: string, replacement: string ): string; +declare function replaceAfter( str: string, search: string, replacement: string, fromIndex?: number ): string; // EXPORTS // diff --git a/lib/node_modules/@stdlib/string/base/replace-after/docs/types/test.ts b/lib/node_modules/@stdlib/string/base/replace-after/docs/types/test.ts index 57094c4adec3..58469bd391b3 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after/docs/types/test.ts +++ b/lib/node_modules/@stdlib/string/base/replace-after/docs/types/test.ts @@ -1,7 +1,7 @@ /* * @license Apache-2.0 * -* Copyright (c) 2023 The Stdlib Authors. +* Copyright (c) 2024 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. @@ -26,6 +26,7 @@ import replaceAfter = require( './index' ); replaceAfter( 'beep boop', ' ', 'foo' ); // $ExpectType string replaceAfter( 'beep boop', 'xyz', 'foo' ); // $ExpectType string replaceAfter( 'beep boop', '', 'foo' ); // $ExpectType string + replaceAfter( 'beep boop', '', 'foo', 5 ); // $ExpectType string } // The compiler throws an error if the function is provided arguments having invalid types... @@ -57,4 +58,5 @@ import replaceAfter = require( './index' ); replaceAfter(); // $ExpectError replaceAfter( 'abc' ); // $ExpectError replaceAfter( 'abc', 'd' ); // $ExpectError + replaceAfter( 'abc', 'd', 'd', 1, 1 ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/string/base/replace-after/examples/index.js b/lib/node_modules/@stdlib/string/base/replace-after/examples/index.js index 2d9df5273f23..428faef63d31 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after/examples/index.js +++ b/lib/node_modules/@stdlib/string/base/replace-after/examples/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2023 The Stdlib Authors. +* Copyright (c) 2024 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. @@ -35,3 +35,11 @@ console.log( out ); out = replaceAfter( '', 'xyz', 'foo' ); console.log( out ); // => '' + +out = replaceAfter( 'beep boop', ' ', 'foo', 5 ); +console.log( out ); +// => 'beep boop' + +out = replaceAfter( 'beep boop beep baz', 'beep', 'foo', 5 ); +console.log( out ); +// => 'beep boop beepfoo' diff --git a/lib/node_modules/@stdlib/string/base/replace-after/lib/index.js b/lib/node_modules/@stdlib/string/base/replace-after/lib/index.js index 88b6e9707522..7f2f8c70995c 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after/lib/index.js +++ b/lib/node_modules/@stdlib/string/base/replace-after/lib/index.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2023 The Stdlib Authors. +* Copyright (c) 2024 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. @@ -33,6 +33,12 @@ * * out = replaceAfter( str, 'o', 'bar' ); * // returns 'beep bobar' +* +* var out = replaceAfter( 'beep boop', ' ', 'foo', 5 ); +* // returns 'beep foo' +* +* var out = replaceAfter( 'beep boop beep baz', 'beep', 'foo', 5 ); +* // returns 'beep boop beepfoo' */ // MODULES // diff --git a/lib/node_modules/@stdlib/string/base/replace-after/lib/main.js b/lib/node_modules/@stdlib/string/base/replace-after/lib/main.js index 61e726b4d731..ba6c242ed1ce 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after/lib/main.js +++ b/lib/node_modules/@stdlib/string/base/replace-after/lib/main.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2023 The Stdlib Authors. +* Copyright (c) 2024 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. @@ -26,7 +26,8 @@ * @param {string} str - input string * @param {string} search - search string * @param {string} replacement - replacement string -* @returns {string} string +* @param {integer} [fromIndex=0] - index at which to start the search +* @returns {string} - string * * @example * var out = replaceAfter( 'beep boop', ' ', 'foo' ); @@ -43,9 +44,23 @@ * @example * var out = replaceAfter( 'Hello World!', 'xyz', 'foo' ); * // returns 'Hello World!' +* +* @example +* var out = replaceAfter( 'beep boop', ' ', 'foo', 5 ); +* // returns 'beep boop' +* +* @example +* var out = replaceAfter( 'beep boop beep baz', 'beep', 'foo', 5 ); +* // returns 'beep boop beepfoo' */ -function replaceAfter( str, search, replacement ) { - var idx = str.indexOf( search ); +function replaceAfter( str, search, replacement, fromIndex ) { + var idx; + if ( fromIndex < 0 ) { + fromIndex = 0; + } else if ( fromIndex > str.length ) { + fromIndex = str.length; + } + idx = str.indexOf( search, fromIndex ); if ( str === '' || search === '' || replacement === '' || idx < 0 ) { return str; } diff --git a/lib/node_modules/@stdlib/string/base/replace-after/test/test.js b/lib/node_modules/@stdlib/string/base/replace-after/test/test.js index c8f51614b226..25d06bf849d0 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after/test/test.js +++ b/lib/node_modules/@stdlib/string/base/replace-after/test/test.js @@ -1,7 +1,7 @@ /** * @license Apache-2.0 * -* Copyright (c) 2023 The Stdlib Authors. +* Copyright (c) 2024 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. @@ -70,6 +70,31 @@ tape( 'the function replaces the substring after the first occurrence of a speci t.end(); }); +tape( 'the function returns the string after a provided search string (custom start index)', function test( t ) { + var expected; + var actual; + var str; + + str = 'beep boop baz'; + actual = replaceAfter( str, ' ', 'foo', 6 ); + expected = 'beep boop foo'; + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop baz'; + actual = replaceAfter( str, 'p', 'foo', 6 ); + expected = 'beep boopfoo'; + + str = 'beep boop baz'; + actual = replaceAfter( str, 'beep', 'foo', -2 ); + expected = 'beepfoo'; + + str = 'beep boop baz'; + actual = replaceAfter( str, 'beep', 'foo', 20 ); + expected = ''; + + t.end(); +}); + tape( 'the function returns the entire string if the search string is not found', function test( t ) { var expected; var actual; From ad83e85e62250086a0d2ee4a6da290f8eb1c94ec Mon Sep 17 00:00:00 2001 From: AuenKr Date: Sun, 25 Feb 2024 09:31:23 +0530 Subject: [PATCH 05/11] fixup! feat: make fromIndex mandatory argument --- .../string/base/replace-after/README.md | 18 +++---- .../base/replace-after/benchmark/benchmark.js | 2 +- .../string/base/replace-after/docs/repl.txt | 10 ++-- .../base/replace-after/docs/types/index.d.ts | 14 ++--- .../base/replace-after/docs/types/test.ts | 53 +++++++++++-------- .../base/replace-after/examples/index.js | 12 +++-- .../string/base/replace-after/lib/index.js | 4 +- .../string/base/replace-after/lib/main.js | 12 ++--- .../string/base/replace-after/test/test.js | 18 +++---- 9 files changed, 75 insertions(+), 68 deletions(-) diff --git a/lib/node_modules/@stdlib/string/base/replace-after/README.md b/lib/node_modules/@stdlib/string/base/replace-after/README.md index a9d8978fdc05..da93aeff8de5 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after/README.md +++ b/lib/node_modules/@stdlib/string/base/replace-after/README.md @@ -45,17 +45,13 @@ var replaceAfter = require( '@stdlib/string/base/replace-after' ); Returns the part of a string after replacing. ```javascript -var out = replaceAfter( 'beep boop', ' ', 'loop' ); +var out = replaceAfter( 'beep boop', ' ', 'loop', 0 ); // returns 'beep loop' -out = replaceAfter( 'beep boop', 'o', 'bar' ); +out = replaceAfter( 'beep boop', 'o', 'bar', 0 ); // returns 'beep bobar' -``` - -By default, the search starts at the beginning of the string. To start searching from a different index, provide a `fromIndex` argument: -```javascript -var out = replaceAfter( 'beep boop beep baz', 'beep', 'foo', 5 ); +out = replaceAfter( 'beep boop beep baz', 'beep', 'foo', 5 ); // return 'beep boop beepfoo' ``` @@ -88,16 +84,16 @@ var out = replaceAfter( 'beep boop beep baz', 'beep', 'foo', 5 ); ```javascript var replaceAfter = require( '@stdlib/string/base/replace-after' ); -var out = replaceAfter( 'beep boop', 'p', 'see' ); +var out = replaceAfter( 'beep boop', 'p', 'see', 0 ); // returns 'beepsee' -out = replaceAfter( 'Hello World!', 'xyz', 'foo' ); +out = replaceAfter( 'Hello World!', 'xyz', 'foo', 0 ); // returns 'Hello World!' -out = replaceAfter( 'Hello World!', '', 'foo' ); +out = replaceAfter( 'Hello World!', '', 'foo', 0 ); // returns 'Hello World!' -out = replaceAfter( '', 'xyz', 'foo' ); +out = replaceAfter( '', 'xyz', 'foo', 0 ); // returns '' out = replaceAfter( 'beep boop beep baz', 'beep', 'foo', 5 ); diff --git a/lib/node_modules/@stdlib/string/base/replace-after/benchmark/benchmark.js b/lib/node_modules/@stdlib/string/base/replace-after/benchmark/benchmark.js index ab3fb92819b5..7845c5668e00 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/string/base/replace-after/benchmark/benchmark.js @@ -44,7 +44,7 @@ bench( pkg, function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - out = replaceAfter( str, '.', values[ i%values.length ] ); + out = replaceAfter( str, '.', values[ i%values.length ], 0 ); if ( typeof out !== 'string' ) { b.fail( 'should return a string' ); } diff --git a/lib/node_modules/@stdlib/string/base/replace-after/docs/repl.txt b/lib/node_modules/@stdlib/string/base/replace-after/docs/repl.txt index 03ada0adfafb..84b097637b05 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after/docs/repl.txt +++ b/lib/node_modules/@stdlib/string/base/replace-after/docs/repl.txt @@ -1,5 +1,5 @@ -{{alias}}( str, search, replacement[, fromIndex] ) +{{alias}}( str, search, replacement, fromIndex ) Replaces the substring after the first occurrence of a specified search string. @@ -14,8 +14,8 @@ replacement: string Replacement string. - fromIndex: integer (optional) - Index from which to start the search. Default: `0`. + fromIndex: number + Index from which to start the search. Returns ------- @@ -24,9 +24,9 @@ Examples -------- - > var out = {{alias}}( 'beep boop', ' ', 'foo' ) + > var out = {{alias}}( 'beep boop', ' ', 'foo', 0 ) 'beep foo' - > out = {{alias}}( 'beep boop', 'o', 'foo' ) + > out = {{alias}}( 'beep boop', 'o', 'foo', 0 ) 'beep bofoo' > var out = {{alias}}( 'Hello World!', 'l', 'foo', 3 ) 'Hellfoo' diff --git a/lib/node_modules/@stdlib/string/base/replace-after/docs/types/index.d.ts b/lib/node_modules/@stdlib/string/base/replace-after/docs/types/index.d.ts index 9fd9da93c446..fc0ed52126ec 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/string/base/replace-after/docs/types/index.d.ts @@ -24,23 +24,23 @@ * @param str - input string * @param search - search string * @param replacement - replacement string -* @param fromIndex - index at which to start the search (default: 0) +* @param fromIndex - index at which to start the search * @returns output string * * @example -* var out = replaceAfter( 'beep boop', ' ', 'foo' ); +* var out = replaceAfter( 'beep boop', ' ', 'foo', 0 ); * // returns 'beep foo' * * @example -* var out = replaceAfter( 'beep boop', 'p', 'foo' ); -* // returns 'beepfoo' +* var out = replaceAfter( 'beep boop', 'p', 'foo', 5 ); +* // returns 'beep boopfoo' * * @example -* var out = replaceAfter( 'Hello World!', '', 'foo' ); +* var out = replaceAfter( 'Hello World!', '', 'foo', 0 ); * // returns 'Hello World!' * * @example -* var out = replaceAfter( 'Hello World!', 'xyz', 'foo' ); +* var out = replaceAfter( 'Hello World!', 'xyz', 'foo', 0 ); * // returns 'Hello World!' * * @example @@ -51,7 +51,7 @@ * var out = replaceAfter( 'beep boop beep baz', 'beep', 'foo' , 5 ); * // returns 'beep boop beepfoo' */ -declare function replaceAfter( str: string, search: string, replacement: string, fromIndex?: number ): string; +declare function replaceAfter( str: string, search: string, replacement: string, fromIndex: number ): string; // EXPORTS // diff --git a/lib/node_modules/@stdlib/string/base/replace-after/docs/types/test.ts b/lib/node_modules/@stdlib/string/base/replace-after/docs/types/test.ts index 58469bd391b3..97a9fd498177 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after/docs/types/test.ts +++ b/lib/node_modules/@stdlib/string/base/replace-after/docs/types/test.ts @@ -23,34 +23,41 @@ import replaceAfter = require( './index' ); // The function returns a string... { - replaceAfter( 'beep boop', ' ', 'foo' ); // $ExpectType string - replaceAfter( 'beep boop', 'xyz', 'foo' ); // $ExpectType string - replaceAfter( 'beep boop', '', 'foo' ); // $ExpectType string + replaceAfter( 'beep boop', ' ', 'foo', 0 ); // $ExpectType string + replaceAfter( 'beep boop', 'xyz', 'foo', 0 ); // $ExpectType string + replaceAfter( 'beep boop', '', 'foo', 0 ); // $ExpectType string replaceAfter( 'beep boop', '', 'foo', 5 ); // $ExpectType string } // The compiler throws an error if the function is provided arguments having invalid types... { - replaceAfter( true, 'd', 'foo' ); // $ExpectError - replaceAfter( false, 'd' , 'foo' ); // $ExpectError - replaceAfter( 3, 'd' , 'foo' ); // $ExpectError - replaceAfter( [], 'd' , 'foo' ); // $ExpectError - replaceAfter( {}, 'd' , 'foo' ); // $ExpectError - replaceAfter( ( x: number ): number => x, 'd', 'foo' ); // $ExpectError - - replaceAfter( 'abc', true, 'foo' ); // $ExpectError - replaceAfter( 'abc', false, 'foo' ); // $ExpectError - replaceAfter( 'abc', 5 , 'foo' ); // $ExpectError - replaceAfter( 'abc', [], 'foo' ); // $ExpectError - replaceAfter( 'abc', {} , 'foo' ); // $ExpectError - replaceAfter( 'abc', ( x: number ): number => x , 'foo' ); // $ExpectError - - replaceAfter( 'abc', 'd', true ); // $ExpectError - replaceAfter( 'abc', 'd', false ); // $ExpectError - replaceAfter( 'abc', 'd', 5 ); // $ExpectError - replaceAfter( 'abc', 'd', [] ); // $ExpectError - replaceAfter( 'abc', 'd', {} ); // $ExpectError - replaceAfter( 'abc', 'd', ( x: number ): number => x ); // $ExpectError + replaceAfter( true, 'd', 'foo', 0 ); // $ExpectError + replaceAfter( false, 'd' , 'foo', 0 ); // $ExpectError + replaceAfter( 3, 'd' , 'foo', 0 ); // $ExpectError + replaceAfter( [], 'd' , 'foo', 0 ); // $ExpectError + replaceAfter( {}, 'd' , 'foo', 0 ); // $ExpectError + replaceAfter( ( x: number ): number => x, 'd', 'foo', 0 ); // $ExpectError + + replaceAfter( 'abc', true, 'foo', 0 ); // $ExpectError + replaceAfter( 'abc', false, 'foo', 0 ); // $ExpectError + replaceAfter( 'abc', 5 , 'foo', 0 ); // $ExpectError + replaceAfter( 'abc', [], 'foo', 0 ); // $ExpectError + replaceAfter( 'abc', {} , 'foo', 0 ); // $ExpectError + replaceAfter( 'abc', ( x: number ): number => x , 'foo', 0 ); // $ExpectError + + replaceAfter( 'abc', 'd', true, 0 ); // $ExpectError + replaceAfter( 'abc', 'd', false, 0 ); // $ExpectError + replaceAfter( 'abc', 'd', 5, 0 ); // $ExpectError + replaceAfter( 'abc', 'd', [], 0 ); // $ExpectError + replaceAfter( 'abc', 'd', {}, 0 ); // $ExpectError + replaceAfter( 'abc', 'd', ( x: number ): number => x, 0 ); // $ExpectError + + replaceAfter( 'abc', 'd', 'foo', true ); // $ExpectError + replaceAfter( 'abc', 'd', 'foo', false ); // $ExpectError + replaceAfter( 'abc', 'd', 'foo', '5' ); // $ExpectError + replaceAfter( 'abc', 'd', 'foo', [] ); // $ExpectError + replaceAfter( 'abc', 'd', 'foo', {} ); // $ExpectError + replaceAfter( 'abc', 'd', 'foo', ( 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/base/replace-after/examples/index.js b/lib/node_modules/@stdlib/string/base/replace-after/examples/index.js index 428faef63d31..f8e57dd00432 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after/examples/index.js +++ b/lib/node_modules/@stdlib/string/base/replace-after/examples/index.js @@ -20,19 +20,23 @@ var replaceAfter = require( './../lib' ); -var out = replaceAfter( 'beep boop', 'p', 'see' ); +var out = replaceAfter( 'beep boop', 'p', 'see', 0 ); console.log( out ); // => 'beepsee' -out = replaceAfter( 'Hello World!', 'xyz', 'foo' ); +out = replaceAfter( 'beep boop', 'p', 'see', 5 ); +console.log( out ); +// => 'beep boopsee' + +out = replaceAfter( 'Hello World!', 'xyz', 'foo', 0 ); console.log( out ); // => 'Hello World!' -out = replaceAfter( 'Hello World!', '', 'foo' ); +out = replaceAfter( 'Hello World!', '', 'foo', 0 ); console.log( out ); // => 'Hello World!' -out = replaceAfter( '', 'xyz', 'foo' ); +out = replaceAfter( '', 'xyz', 'foo', 0 ); console.log( out ); // => '' diff --git a/lib/node_modules/@stdlib/string/base/replace-after/lib/index.js b/lib/node_modules/@stdlib/string/base/replace-after/lib/index.js index 7f2f8c70995c..d1507fe9dc76 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after/lib/index.js +++ b/lib/node_modules/@stdlib/string/base/replace-after/lib/index.js @@ -28,10 +28,10 @@ * * var str = 'beep boop'; * -* var out = replaceAfter( str, ' ', 'foo' ); +* var out = replaceAfter( str, ' ', 'foo', 0 ); * // returns 'beep foo' * -* out = replaceAfter( str, 'o', 'bar' ); +* out = replaceAfter( str, 'o', 'bar', 0 ); * // returns 'beep bobar' * * var out = replaceAfter( 'beep boop', ' ', 'foo', 5 ); diff --git a/lib/node_modules/@stdlib/string/base/replace-after/lib/main.js b/lib/node_modules/@stdlib/string/base/replace-after/lib/main.js index ba6c242ed1ce..e5b4589bc3e8 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after/lib/main.js +++ b/lib/node_modules/@stdlib/string/base/replace-after/lib/main.js @@ -26,23 +26,23 @@ * @param {string} str - input string * @param {string} search - search string * @param {string} replacement - replacement string -* @param {integer} [fromIndex=0] - index at which to start the search +* @param {integer} fromIndex - index at which to start the search * @returns {string} - string * * @example -* var out = replaceAfter( 'beep boop', ' ', 'foo' ); +* var out = replaceAfter( 'beep boop', ' ', 'foo', 0 ); * // returns 'beep foo' * * @example -* var out = replaceAfter( 'beep boop', 'p', 'foo' ); -* // returns 'beepfoo' +* var out = replaceAfter( 'beep boop', 'p', 'foo', 5 ); +* // returns 'beep boopfoo' * * @example -* var out = replaceAfter( 'Hello World!', '', 'foo' ); +* var out = replaceAfter( 'Hello World!', '', 'foo', 0 ); * // returns 'Hello World!' * * @example -* var out = replaceAfter( 'Hello World!', 'xyz', 'foo' ); +* var out = replaceAfter( 'Hello World!', 'xyz', 'foo', 0 ); * // returns 'Hello World!' * * @example diff --git a/lib/node_modules/@stdlib/string/base/replace-after/test/test.js b/lib/node_modules/@stdlib/string/base/replace-after/test/test.js index 25d06bf849d0..f26c16babbb9 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after/test/test.js +++ b/lib/node_modules/@stdlib/string/base/replace-after/test/test.js @@ -36,15 +36,15 @@ tape( 'the function replaces the substring after the first occurrence of a speci var expected; var actual; - actual = replaceAfter( 'beep boop', ' ', 'foo' ); + actual = replaceAfter( 'beep boop', ' ', 'foo', 0 ); expected = 'beep foo'; t.strictEqual( actual, expected, 'returns expected value' ); - actual = replaceAfter( 'beep boop', 'p', 'foo' ); + actual = replaceAfter( 'beep boop', 'p', 'foo', 0 ); expected = 'beepfoo'; t.strictEqual( actual, expected, 'returns expected value' ); - actual = replaceAfter( 'Hello, World!', 'o', 'foo' ); + actual = replaceAfter( 'Hello, World!', 'o', 'foo', 0 ); expected = 'Hellofoo'; t.strictEqual( actual, expected, 'returns expected value' ); @@ -55,15 +55,15 @@ tape( 'the function replaces the substring after the first occurrence of a speci var expected; var actual; - actual = replaceAfter( 'beep 😀 boop 😀 baz', '😀', 'foo' ); + actual = replaceAfter( 'beep 😀 boop 😀 baz', '😀', 'foo', 0 ); expected = 'beep 😀foo'; t.strictEqual( actual, expected, 'returns expected value' ); - actual = replaceAfter( '🤖 Robot army 🤖!', '🤖', 'foo' ); + actual = replaceAfter( '🤖 Robot army 🤖!', '🤖', 'foo', 0 ); expected = '🤖foo'; t.strictEqual( actual, expected, 'returns expected value' ); - actual = replaceAfter( '🐺 Wolf brothers 🐺', 'o', 'foo' ); + actual = replaceAfter( '🐺 Wolf brothers 🐺', 'o', 'foo', 0 ); expected = '🐺 Wofoo'; t.strictEqual( actual, expected, 'returns expected value' ); @@ -99,11 +99,11 @@ tape( 'the function returns the entire string if the search string is not found' var expected; var actual; - actual = replaceAfter( 'beep boop', 'z', 'foo' ); + actual = replaceAfter( 'beep boop', 'z', 'foo', 0 ); expected = 'beep boop'; t.strictEqual( actual, expected, 'returns expected value' ); - actual = replaceAfter( 'beep boop', 'baz', 'foo' ); + actual = replaceAfter( 'beep boop', 'baz', 'foo', 0 ); expected = 'beep boop'; t.strictEqual( actual, expected, 'returns expected value' ); @@ -114,7 +114,7 @@ tape( 'the function returns the entire string if the search string is the empty var expected; var actual; - actual = replaceAfter( 'beep boop', '', 'foo' ); + actual = replaceAfter( 'beep boop', '', 'foo', 0 ); expected = 'beep boop'; t.strictEqual( actual, expected, 'returns expected value' ); From 17650124329ab608770005b2c9d0997846d9c68d Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 24 Feb 2024 20:07:01 -0800 Subject: [PATCH 06/11] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/string/base/replace-after/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/string/base/replace-after/README.md b/lib/node_modules/@stdlib/string/base/replace-after/README.md index da93aeff8de5..fcdebda493d3 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after/README.md +++ b/lib/node_modules/@stdlib/string/base/replace-after/README.md @@ -42,7 +42,7 @@ var replaceAfter = require( '@stdlib/string/base/replace-after' ); #### replaceAfter( str, search, replacement, fromIndex ) -Returns the part of a string after replacing. +Replaces the substring after the first occurrence of a specified search string. ```javascript var out = replaceAfter( 'beep boop', ' ', 'loop', 0 ); From dfdf671b53fda3c970761ea914f946025604c4a5 Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 24 Feb 2024 20:07:58 -0800 Subject: [PATCH 07/11] Apply suggestions from code review Signed-off-by: Athan --- .../@stdlib/string/base/replace-after/docs/repl.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/string/base/replace-after/docs/repl.txt b/lib/node_modules/@stdlib/string/base/replace-after/docs/repl.txt index 84b097637b05..5d5edabd1ca9 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after/docs/repl.txt +++ b/lib/node_modules/@stdlib/string/base/replace-after/docs/repl.txt @@ -14,7 +14,7 @@ replacement: string Replacement string. - fromIndex: number + fromIndex: integer Index from which to start the search. Returns From 93584bd0f89fb0aa2d7909d85805edcc37088ccb Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 24 Feb 2024 20:09:09 -0800 Subject: [PATCH 08/11] Apply suggestions from code review Signed-off-by: Athan --- .../@stdlib/string/base/replace-after/docs/repl.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/string/base/replace-after/docs/repl.txt b/lib/node_modules/@stdlib/string/base/replace-after/docs/repl.txt index 5d5edabd1ca9..e7443b109d05 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after/docs/repl.txt +++ b/lib/node_modules/@stdlib/string/base/replace-after/docs/repl.txt @@ -28,9 +28,9 @@ 'beep foo' > out = {{alias}}( 'beep boop', 'o', 'foo', 0 ) 'beep bofoo' - > var out = {{alias}}( 'Hello World!', 'l', 'foo', 3 ) - 'Hellfoo' - > var out = {{alias}}( 'beep boop beep baz', 'beep', 'foo', 5 ) + > out = {{alias}}( 'Hello World!', 'o', 'foo', 5 ) + 'Hello Wfoo' + > out = {{alias}}( 'beep boop beep baz', 'beep', 'foo', 5 ) 'beep boop beepfoo' See Also From 346c51e396240bb106c1965db8f73fb2ae32283e Mon Sep 17 00:00:00 2001 From: Athan Date: Sat, 24 Feb 2024 20:16:36 -0800 Subject: [PATCH 09/11] Apply suggestions from code review Signed-off-by: Athan --- lib/node_modules/@stdlib/string/base/replace-after/test/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/string/base/replace-after/test/test.js b/lib/node_modules/@stdlib/string/base/replace-after/test/test.js index f26c16babbb9..f5c38c50e53a 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after/test/test.js +++ b/lib/node_modules/@stdlib/string/base/replace-after/test/test.js @@ -70,7 +70,7 @@ tape( 'the function replaces the substring after the first occurrence of a speci t.end(); }); -tape( 'the function returns the string after a provided search string (custom start index)', function test( t ) { +tape( 'the function replaces the substring after a provided search string (custom start index)', function test( t ) { var expected; var actual; var str; From e40d258cf36fa95f7afc9da8cef79424f146b65f Mon Sep 17 00:00:00 2001 From: AuenKr Date: Sun, 25 Feb 2024 10:20:51 +0530 Subject: [PATCH 10/11] fixup! feat: test issue fixed --- .../@stdlib/string/base/replace-after/test/test.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/string/base/replace-after/test/test.js b/lib/node_modules/@stdlib/string/base/replace-after/test/test.js index f5c38c50e53a..e821a331a15f 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after/test/test.js +++ b/lib/node_modules/@stdlib/string/base/replace-after/test/test.js @@ -83,14 +83,17 @@ tape( 'the function replaces the substring after a provided search string (custo str = 'beep boop baz'; actual = replaceAfter( str, 'p', 'foo', 6 ); expected = 'beep boopfoo'; + t.strictEqual( actual, expected, 'returns expected value' ); str = 'beep boop baz'; actual = replaceAfter( str, 'beep', 'foo', -2 ); expected = 'beepfoo'; + t.strictEqual( actual, expected, 'returns expected value' ); str = 'beep boop baz'; actual = replaceAfter( str, 'beep', 'foo', 20 ); - expected = ''; + expected = 'beep boop baz'; + t.strictEqual( actual, expected, 'returns expected value' ); t.end(); }); From c757331f18349e483c3dc699e93021be3846d1e9 Mon Sep 17 00:00:00 2001 From: Golden <103646877+AuenKr@users.noreply.github.com> Date: Sun, 25 Feb 2024 13:25:25 +0530 Subject: [PATCH 11/11] Update repl.txt Signed-off-by: Golden <103646877+AuenKr@users.noreply.github.com> --- .../@stdlib/string/base/replace-after/docs/repl.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/string/base/replace-after/docs/repl.txt b/lib/node_modules/@stdlib/string/base/replace-after/docs/repl.txt index e7443b109d05..6dc96fb92589 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after/docs/repl.txt +++ b/lib/node_modules/@stdlib/string/base/replace-after/docs/repl.txt @@ -29,7 +29,7 @@ > out = {{alias}}( 'beep boop', 'o', 'foo', 0 ) 'beep bofoo' > out = {{alias}}( 'Hello World!', 'o', 'foo', 5 ) - 'Hello Wfoo' + 'Hello Wofoo' > out = {{alias}}( 'beep boop beep baz', 'beep', 'foo', 5 ) 'beep boop beepfoo'