From be2d33cc9741df70fd14161eab521701f56d4846 Mon Sep 17 00:00:00 2001 From: AuenKr Date: Sat, 24 Feb 2024 11:42:00 +0530 Subject: [PATCH 01/12] feat: add @stdlib/string/base/replace-after-last --- .../string/base/replace-after-last/README.md | 122 ++++++++++++++++++ .../replace-after-last/benchmark/benchmark.js | 58 +++++++++ .../base/replace-after-last/docs/repl.txt | 32 +++++ .../replace-after-last/docs/types/index.d.ts | 50 +++++++ .../replace-after-last/docs/types/test.ts | 60 +++++++++ .../base/replace-after-last/examples/index.js | 37 ++++++ .../base/replace-after-last/lib/index.js | 45 +++++++ .../base/replace-after-last/lib/main.js | 58 +++++++++ .../base/replace-after-last/package.json | 69 ++++++++++ .../base/replace-after-last/test/test.js | 97 ++++++++++++++ 10 files changed, 628 insertions(+) create mode 100644 lib/node_modules/@stdlib/string/base/replace-after-last/README.md create mode 100644 lib/node_modules/@stdlib/string/base/replace-after-last/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/string/base/replace-after-last/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/string/base/replace-after-last/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/string/base/replace-after-last/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/string/base/replace-after-last/examples/index.js create mode 100644 lib/node_modules/@stdlib/string/base/replace-after-last/lib/index.js create mode 100644 lib/node_modules/@stdlib/string/base/replace-after-last/lib/main.js create mode 100644 lib/node_modules/@stdlib/string/base/replace-after-last/package.json create mode 100644 lib/node_modules/@stdlib/string/base/replace-after-last/test/test.js diff --git a/lib/node_modules/@stdlib/string/base/replace-after-last/README.md b/lib/node_modules/@stdlib/string/base/replace-after-last/README.md new file mode 100644 index 000000000000..7c1d02dc1e9e --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/replace-after-last/README.md @@ -0,0 +1,122 @@ + + +# replaceAfterLast + +> Replace the substring after the last occurrence of a specified search string. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var replaceAfterLast = require( '@stdlib/string/base/replace-after-last' ); +``` + +#### replaceAfterLast( str, search, replacement ) + +Replaces the substring after the last occurrence of a specified search string. + +```javascript +var out = replaceAfterLast( 'beep boop', ' ', 'loop' ); +// returns 'beep loop' + +out = replaceAfterLast( 'beep boop', 'o', 'bar' ); +// returns 'beep boobar' +``` + +
+ + + + + +
+ +## 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 replaceAfterLast = require( '@stdlib/string/base/replace-after-last' ); + +var out = replaceAfterLast( 'beep boop', 'p', 'see' ); +// returns 'beep boopsee' + +out = replaceAfterLast( 'Hello World!', 'xyz', 'foo' ); +// returns 'Hello World!' + +out = replaceAfterLast( 'Hello World!', '', 'foo' ); +// returns 'Hello World!' + +out = replaceAfterLast( '', 'xyz', 'foo'); +// returns '' +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/string/base/replace-after-last/benchmark/benchmark.js b/lib/node_modules/@stdlib/string/base/replace-after-last/benchmark/benchmark.js new file mode 100644 index 000000000000..194d2a176818 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/replace-after-last/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 replaceAfterLast = 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 = replaceAfterLast( 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-last/docs/repl.txt b/lib/node_modules/@stdlib/string/base/replace-after-last/docs/repl.txt new file mode 100644 index 000000000000..182e0884ff7d --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/replace-after-last/docs/repl.txt @@ -0,0 +1,32 @@ + +{{alias}}( str, search, replacement ) + Replaces the substring after the last 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 boofoo' + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/string/base/replace-after-last/docs/types/index.d.ts b/lib/node_modules/@stdlib/string/base/replace-after-last/docs/types/index.d.ts new file mode 100644 index 000000000000..d7ea574bacc2 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/replace-after-last/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 last occurrence of a specified search string. +* +* @param str - input string +* @param search - search string +* @param replacement - replacement string +* @returns output string +* +* @example +* var out = replaceAfterLast( 'beep boop', ' ', 'foo' ); +* // returns 'beep foo' +* +* @example +* var out = replaceAfterLast( 'beep boop', 'p', 'foo' ); +* // returns 'beep boopfoo' +* +* @example +* var out = replaceAfterLast( 'Hello World!', '', 'foo' ); +* // returns 'Hello World!' +* +* @example +* var out = replaceAfterLast( 'Hello World!', 'xyz', 'foo' ); +* // returns 'Hello World!' +*/ +declare function replaceAfterLast( str: string, search: string, replacement: string ): string; + + +// EXPORTS // + +export = replaceAfterLast; diff --git a/lib/node_modules/@stdlib/string/base/replace-after-last/docs/types/test.ts b/lib/node_modules/@stdlib/string/base/replace-after-last/docs/types/test.ts new file mode 100644 index 000000000000..57094c4adec3 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/replace-after-last/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-last/examples/index.js b/lib/node_modules/@stdlib/string/base/replace-after-last/examples/index.js new file mode 100644 index 000000000000..8301e07591ce --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/replace-after-last/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 replaceAfterLast = require( './../lib' ); + +var out = replaceAfterLast( 'beep boop', 'p', 'see' ); +console.log( out ); +// => 'beep boopsee' + +out = replaceAfterLast( 'Hello World!', 'xyz', 'foo' ); +console.log( out ); +// => 'Hello World!' + +out = replaceAfterLast( 'Hello World!', '', 'foo' ); +console.log( out ); +// => 'Hello World!' + +out = replaceAfterLast( '', 'xyz', 'foo' ); +console.log( out ); +// => '' diff --git a/lib/node_modules/@stdlib/string/base/replace-after-last/lib/index.js b/lib/node_modules/@stdlib/string/base/replace-after-last/lib/index.js new file mode 100644 index 000000000000..187a18dae380 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/replace-after-last/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 last occurrence of a specified search string. +* +* @module @stdlib/string/base/replace-after-last +* +* @example +* var replaceAfterLast = require( '@stdlib/string/base/replace-after-last' ); +* +* var str = 'beep boop'; +* +* var out = replaceAfterLast( str, ' ', 'foo' ); +* // returns 'beep foo' +* +* out = replaceAfterLast( str, 'o', 'bar' ); +* // returns 'beep boobar' +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/string/base/replace-after-last/lib/main.js b/lib/node_modules/@stdlib/string/base/replace-after-last/lib/main.js new file mode 100644 index 000000000000..81269aa4288e --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/replace-after-last/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 last 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 = replaceAfterLast( 'beep boop', ' ', 'foo' ); +* // returns 'beep foo' +* +* @example +* var out = replaceAfterLast( 'beep boop', 'p', 'foo' ); +* // returns 'beep boopfoo' +* +* @example +* var out = replaceAfterLast( 'Hello World!', '', 'foo' ); +* // returns 'Hello World!' +* +* @example +* var out = replaceAfterLast( 'Hello World!', 'xyz', 'foo' ); +* // returns 'Hello World!' +*/ +function replaceAfterLast( str, search, replacement ) { + var idx = str.lastIndexOf( search ); + if ( str === '' || search === '' || replacement === '' || idx < 0 ) { + return str; + } + return str.substring( 0, idx + search.length ) + replacement; +} + + +// EXPORTS // + +module.exports = replaceAfterLast; diff --git a/lib/node_modules/@stdlib/string/base/replace-after-last/package.json b/lib/node_modules/@stdlib/string/base/replace-after-last/package.json new file mode 100644 index 000000000000..f6269b2751f9 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/replace-after-last/package.json @@ -0,0 +1,69 @@ +{ + "name": "@stdlib/string/base/replace-after-last", + "version": "0.0.0", + "description": "Replace the substring after the last 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", + "last", + "match" + ] +} diff --git a/lib/node_modules/@stdlib/string/base/replace-after-last/test/test.js b/lib/node_modules/@stdlib/string/base/replace-after-last/test/test.js new file mode 100644 index 000000000000..391532b7838e --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/replace-after-last/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 replaceAfterLast = require( './../lib' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof replaceAfterLast, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function replaces the substring after the last occurrence of a specified search string', function test( t ) { + var expected; + var actual; + + actual = replaceAfterLast( 'beep boop', ' ', 'foo' ); + expected = 'beep foo'; + t.strictEqual( actual, expected, 'returns expected value' ); + + actual = replaceAfterLast( 'beep boop', 'p', 'foo' ); + expected = 'beep boopfoo'; + t.strictEqual( actual, expected, 'returns expected value' ); + + actual = replaceAfterLast( 'Hello, World!', 'o', 'foo' ); + expected = 'Hello, Wofoo'; + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function replaces the substring after the last occurrence of a specified search string (Unicode characters)', function test( t ) { + var expected; + var actual; + + actual = replaceAfterLast( 'beep 😀 boop 😀 baz', '😀', 'foo' ); + expected = 'beep 😀 boop 😀foo'; + t.strictEqual( actual, expected, 'returns expected value' ); + + actual = replaceAfterLast( '🤖 Robot army 🤖!', '🤖', 'foo' ); + expected = '🤖 Robot army 🤖foo'; + t.strictEqual( actual, expected, 'returns expected value' ); + + actual = replaceAfterLast( '🐺 Wolf brothers 🐺', 'o', 'foo' ); + expected = '🐺 Wolf brofoo'; + 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 = replaceAfterLast( 'beep boop', 'z', 'foo' ); + expected = 'beep boop'; + t.strictEqual( actual, expected, 'returns expected value' ); + + actual = replaceAfterLast( '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 = replaceAfterLast( 'beep boop', '', 'foo' ); + expected = 'beep boop'; + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); From a5d2267c2c45c446bd2696c2befd53dbaf981874 Mon Sep 17 00:00:00 2001 From: AuenKr Date: Sun, 25 Feb 2024 15:27:00 +0530 Subject: [PATCH 02/12] fixup! feat: add fromIndex argument --- .../string/base/replace-after-last/README.md | 25 ++++--- .../replace-after-last/benchmark/benchmark.js | 4 +- .../base/replace-after-last/docs/repl.txt | 11 +++- .../replace-after-last/docs/types/index.d.ts | 27 ++++++-- .../replace-after-last/docs/types/test.ts | 65 +++++++++++-------- .../base/replace-after-last/examples/index.js | 24 +++++-- .../base/replace-after-last/lib/index.js | 6 +- .../base/replace-after-last/lib/main.js | 33 ++++++++-- .../base/replace-after-last/test/test.js | 62 ++++++++++++++---- 9 files changed, 183 insertions(+), 74 deletions(-) diff --git a/lib/node_modules/@stdlib/string/base/replace-after-last/README.md b/lib/node_modules/@stdlib/string/base/replace-after-last/README.md index 7c1d02dc1e9e..1b8cc0c02131 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after-last/README.md +++ b/lib/node_modules/@stdlib/string/base/replace-after-last/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,15 +40,17 @@ limitations under the License. var replaceAfterLast = require( '@stdlib/string/base/replace-after-last' ); ``` -#### replaceAfterLast( str, search, replacement ) +#### replaceAfterLast( str, search, replacement, fromIndex ) -Replaces the substring after the last occurrence of a specified search string. +- Replaces the substring after the last occurrence of a specified search string. +- fromIndex is index of last character to be considered beginning of a match. ```javascript -var out = replaceAfterLast( 'beep boop', ' ', 'loop' ); +var str = 'beep boop'; +var out = replaceAfterLast( str, ' ', 'loop', str.length ); // returns 'beep loop' -out = replaceAfterLast( 'beep boop', 'o', 'bar' ); +out = replaceAfterLast( str, 'o', 'bar', str.length ); // returns 'beep boobar' ``` @@ -64,6 +66,7 @@ out = replaceAfterLast( '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 search string length, the function returns the provided string unchanged. @@ -80,16 +83,20 @@ out = replaceAfterLast( 'beep boop', 'o', 'bar' ); ```javascript var replaceAfterLast = require( '@stdlib/string/base/replace-after-last' ); -var out = replaceAfterLast( 'beep boop', 'p', 'see' ); +var str = 'beep boop'; +var out = replaceAfterLast( str, 'p', 'see', str.length ); // returns 'beep boopsee' -out = replaceAfterLast( 'Hello World!', 'xyz', 'foo' ); +str = 'Hello World!'; +out = replaceAfterLast( str, 'xyz', 'foo', str.length ); // returns 'Hello World!' -out = replaceAfterLast( 'Hello World!', '', 'foo' ); +str = 'Hello World!'; +out = replaceAfterLast( str, '', 'foo', str.length ); // returns 'Hello World!' -out = replaceAfterLast( '', 'xyz', 'foo'); +str = ''; +out = replaceAfterLast( str, 'xyz', 'foo', str.length ); // returns '' ``` diff --git a/lib/node_modules/@stdlib/string/base/replace-after-last/benchmark/benchmark.js b/lib/node_modules/@stdlib/string/base/replace-after-last/benchmark/benchmark.js index 194d2a176818..36875fdfa6fa 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after-last/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/string/base/replace-after-last/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. @@ -44,7 +44,7 @@ bench( pkg, function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - out = replaceAfterLast( str, '.', values[ i%values.length ] ); + out = replaceAfterLast( str, '.', values[ i%values.length ], str.length ); if ( typeof out !== 'string' ) { b.fail( 'should return a string' ); } diff --git a/lib/node_modules/@stdlib/string/base/replace-after-last/docs/repl.txt b/lib/node_modules/@stdlib/string/base/replace-after-last/docs/repl.txt index 182e0884ff7d..1d908d220610 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after-last/docs/repl.txt +++ b/lib/node_modules/@stdlib/string/base/replace-after-last/docs/repl.txt @@ -1,5 +1,5 @@ -{{alias}}( str, search, replacement ) +{{alias}}( str, search, replacement, fromIndex ) Replaces the substring after the last occurrence of a specified search string. @@ -14,6 +14,9 @@ replacement: string Replacement string. + fromIndex: integer + Index of last character to be considered beginning of a match. + Returns ------- out: string @@ -22,10 +25,12 @@ Examples -------- > var str = 'beep boop'; - > var out = {{alias}}( str, ' ', 'foo' ) + > var out = {{alias}}( str, ' ', 'foo', str.length ) 'beep foo' - > out = {{alias}}( str, 'o', 'foo' ) + > out = {{alias}}( str, 'o', 'foo', str.length ) 'beep boofoo' + > out = {{alias}}( 'Hello World!', 'o', 'foo', 5 ) + 'Hellofoo' See Also -------- diff --git a/lib/node_modules/@stdlib/string/base/replace-after-last/docs/types/index.d.ts b/lib/node_modules/@stdlib/string/base/replace-after-last/docs/types/index.d.ts index d7ea574bacc2..ce3c00fe4d35 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after-last/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/string/base/replace-after-last/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,25 +24,40 @@ * @param str - input string * @param search - search string * @param replacement - replacement string +* @param fromIndex - index of last character to be considered beginning of a match * @returns output string * * @example -* var out = replaceAfterLast( 'beep boop', ' ', 'foo' ); +* var str = 'beep boop'; +* var out = replaceAfterLast( str, ' ', 'foo', str.length ); * // returns 'beep foo' * * @example -* var out = replaceAfterLast( 'beep boop', 'p', 'foo' ); +* var str = 'beep boop'; +* var out = replaceAfterLast( str, 'p', 'foo', str.length ); * // returns 'beep boopfoo' * * @example -* var out = replaceAfterLast( 'Hello World!', '', 'foo' ); +* var str = 'Hello World!'; +* var out = replaceAfterLast( str, '', 'foo', str.length); * // returns 'Hello World!' * * @example -* var out = replaceAfterLast( 'Hello World!', 'xyz', 'foo' ); +* var str = 'Hello World!'; +* var out = replaceAfterLast( str, 'xyz', 'foo', str.length ); * // returns 'Hello World!' +* +* @example +* var str = 'beep boop baz'; +* var out = replaceAfterLast( str, 'p b', 'foo', str.length ); +* // returns 'beep boop bfoo' +* +* @example +* var str = 'beep boop baz'; +* var out = replaceAfterLast( str, 'p b', 'foo', 6 ); +* // returns 'beep bfoo' */ -declare function replaceAfterLast( str: string, search: string, replacement: string ): string; +declare function replaceAfterLast( str: string, search: string, replacement: string, fromIndex: number ): string; // EXPORTS // diff --git a/lib/node_modules/@stdlib/string/base/replace-after-last/docs/types/test.ts b/lib/node_modules/@stdlib/string/base/replace-after-last/docs/types/test.ts index 57094c4adec3..2f422eb28372 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after-last/docs/types/test.ts +++ b/lib/node_modules/@stdlib/string/base/replace-after-last/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. @@ -16,45 +16,54 @@ * limitations under the License. */ -import replaceAfter = require( './index' ); +import replaceAfterLast = 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 + replaceAfterLast( 'beep boop', ' ', 'foo', 'beep boop'.length ); // $ExpectType string + replaceAfterLast( 'beep boop', 'xyz', 'foo', 'beep boop'.length ); // $ExpectType string + replaceAfterLast( 'beep boop', '', 'foo', 'beep boop'.length ); // $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 + replaceAfterLast( true, 'd', 'foo', 100 ); // $ExpectError + replaceAfterLast( false, 'd' , 'foo', 100 ); // $ExpectError + replaceAfterLast( 3, 'd' , 'foo', 100 ); // $ExpectError + replaceAfterLast( [], 'd' , 'foo', 100 ); // $ExpectError + replaceAfterLast( {}, 'd' , 'foo', 100 ); // $ExpectError + replaceAfterLast( ( x: number ): number => x, 'd', 'foo', 100 ); // $ExpectError + + replaceAfterLast( 'abc', true, 'foo', 'abc'.length ); // $ExpectError + replaceAfterLast( 'abc', false, 'foo', 'abc'.length ); // $ExpectError + replaceAfterLast( 'abc', 5 , 'foo', 'abc'.length ); // $ExpectError + replaceAfterLast( 'abc', [], 'foo', 'abc'.length ); // $ExpectError + replaceAfterLast( 'abc', {} , 'foo', 'abc'.length ); // $ExpectError + replaceAfterLast( 'abc', ( x: number ): number => x , 'foo', 'abc'.length ); // $ExpectError + + replaceAfterLast( 'abc', 'd', true, 'abc'.length ); // $ExpectError + replaceAfterLast( 'abc', 'd', false, 'abc'.length ); // $ExpectError + replaceAfterLast( 'abc', 'd', 5, 'abc'.length ); // $ExpectError + replaceAfterLast( 'abc', 'd', [], 'abc'.length ); // $ExpectError + replaceAfterLast( 'abc', 'd', {}, 'abc'.length ); // $ExpectError + replaceAfterLast( 'abc', 'd', ( x: number ): number => x, 'abc'.length ); // $ExpectError + + replaceAfterLast( 'abc', 'd', 'foo', true ); // $ExpectError + replaceAfterLast( 'abc', 'd', 'foo', false ); // $ExpectError + replaceAfterLast( 'abc', 'd', 'foo', '5' ); // $ExpectError + replaceAfterLast( 'abc', 'd', 'foo', [] ); // $ExpectError + replaceAfterLast( 'abc', 'd', 'foo', {} ); // $ExpectError + replaceAfterLast( 'abc', 'd', 'foo', ( 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 + replaceAfterLast(); // $ExpectError + replaceAfterLast( 'abc' ); // $ExpectError + replaceAfterLast( 'abc', 'd' ); // $ExpectError + replaceAfterLast( 'abc', 'd', 'foo' ); // $ExpectError + replaceAfterLast( 'abc', 'd', 'foo', 4, 4 ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/string/base/replace-after-last/examples/index.js b/lib/node_modules/@stdlib/string/base/replace-after-last/examples/index.js index 8301e07591ce..48acaabbb172 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after-last/examples/index.js +++ b/lib/node_modules/@stdlib/string/base/replace-after-last/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. @@ -20,18 +20,32 @@ var replaceAfterLast = require( './../lib' ); -var out = replaceAfterLast( 'beep boop', 'p', 'see' ); +var str = 'beep boop'; +var out = replaceAfterLast( str, 'p', 'see', str.length ); console.log( out ); // => 'beep boopsee' -out = replaceAfterLast( 'Hello World!', 'xyz', 'foo' ); +str = 'Hello World!'; +out = replaceAfterLast( str, 'xyz', 'foo', str.length ); console.log( out ); // => 'Hello World!' -out = replaceAfterLast( 'Hello World!', '', 'foo' ); +str = 'Hello World!'; +out = replaceAfterLast( str, '', 'foo', str.length ); console.log( out ); // => 'Hello World!' -out = replaceAfterLast( '', 'xyz', 'foo' ); +str = ''; +out = replaceAfterLast( str, 'xyz', 'foo', str.length ); console.log( out ); // => '' + +str = 'beep boop baz'; +out = replaceAfterLast( str, 'p b', 'foo', str.length ); +console.log( out ); +// => 'beep boop bfoo' + +str = 'beep boop baz'; +out = replaceAfterLast( str, 'p b', 'foo', 6 ); +console.log( out ); +// => 'beep bfoo' diff --git a/lib/node_modules/@stdlib/string/base/replace-after-last/lib/index.js b/lib/node_modules/@stdlib/string/base/replace-after-last/lib/index.js index 187a18dae380..533d2b958255 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after-last/lib/index.js +++ b/lib/node_modules/@stdlib/string/base/replace-after-last/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. @@ -28,10 +28,10 @@ * * var str = 'beep boop'; * -* var out = replaceAfterLast( str, ' ', 'foo' ); +* var out = replaceAfterLast( str, ' ', 'foo', str.length ); * // returns 'beep foo' * -* out = replaceAfterLast( str, 'o', 'bar' ); +* out = replaceAfterLast( str, 'o', 'bar', str.length ); * // returns 'beep boobar' */ diff --git a/lib/node_modules/@stdlib/string/base/replace-after-last/lib/main.js b/lib/node_modules/@stdlib/string/base/replace-after-last/lib/main.js index 81269aa4288e..cb9f127a51ef 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after-last/lib/main.js +++ b/lib/node_modules/@stdlib/string/base/replace-after-last/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,26 +26,45 @@ * @param {string} str - input string * @param {string} search - search string * @param {string} replacement - replacement string +* @param {integer} fromIndex - index of last character to be considered beginning of a match * @returns {string} string * * @example -* var out = replaceAfterLast( 'beep boop', ' ', 'foo' ); +* var str = 'beep boop'; +* var out = replaceAfterLast( str, ' ', 'foo', str.length ); * // returns 'beep foo' * * @example -* var out = replaceAfterLast( 'beep boop', 'p', 'foo' ); +* var str = 'beep boop'; +* var out = replaceAfterLast( str, 'p', 'foo', str.length ); * // returns 'beep boopfoo' * * @example -* var out = replaceAfterLast( 'Hello World!', '', 'foo' ); +* var str = 'Hello World!'; +* var out = replaceAfterLast( str, '', 'foo', str.length); * // returns 'Hello World!' * * @example -* var out = replaceAfterLast( 'Hello World!', 'xyz', 'foo' ); +* var str = 'Hello World!'; +* var out = replaceAfterLast( str, 'xyz', 'foo', str.length ); * // returns 'Hello World!' +* +* @example +* var str = 'beep boop baz'; +* var out = replaceAfterLast( str, 'p b', 'foo', str.length ); +* // returns 'beep boop bfoo' +* +* @example +* var str = 'beep boop baz'; +* var out = replaceAfterLast( str, 'p b', 'foo', 6 ); +* // returns 'beep bfoo' */ -function replaceAfterLast( str, search, replacement ) { - var idx = str.lastIndexOf( search ); +function replaceAfterLast( str, search, replacement, fromIndex ) { + var idx; + if ( fromIndex < 0 || fromIndex > str.length ) { + return str; + } + idx = str.lastIndexOf( search, fromIndex ); if ( str === '' || search === '' || replacement === '' || idx < 0 ) { return str; } diff --git a/lib/node_modules/@stdlib/string/base/replace-after-last/test/test.js b/lib/node_modules/@stdlib/string/base/replace-after-last/test/test.js index 391532b7838e..ca399c0ad26d 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after-last/test/test.js +++ b/lib/node_modules/@stdlib/string/base/replace-after-last/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. @@ -35,16 +35,19 @@ tape( 'main export is a function', function test( t ) { tape( 'the function replaces the substring after the last occurrence of a specified search string', function test( t ) { var expected; var actual; - - actual = replaceAfterLast( 'beep boop', ' ', 'foo' ); + var str; + str = 'beep boop'; + actual = replaceAfterLast( str, ' ', 'foo', str.length ); expected = 'beep foo'; t.strictEqual( actual, expected, 'returns expected value' ); - actual = replaceAfterLast( 'beep boop', 'p', 'foo' ); + str = 'beep boop'; + actual = replaceAfterLast( str, 'p', 'foo', str.length ); expected = 'beep boopfoo'; t.strictEqual( actual, expected, 'returns expected value' ); - actual = replaceAfterLast( 'Hello, World!', 'o', 'foo' ); + str = 'Hello, World!'; + actual = replaceAfterLast( str, 'o', 'foo', str.length ); expected = 'Hello, Wofoo'; t.strictEqual( actual, expected, 'returns expected value' ); @@ -54,31 +57,66 @@ tape( 'the function replaces the substring after the last occurrence of a specif tape( 'the function replaces the substring after the last occurrence of a specified search string (Unicode characters)', function test( t ) { var expected; var actual; + var str; - actual = replaceAfterLast( 'beep 😀 boop 😀 baz', '😀', 'foo' ); + str = 'beep 😀 boop 😀 baz'; + actual = replaceAfterLast( str, '😀', 'foo', str.length ); expected = 'beep 😀 boop 😀foo'; t.strictEqual( actual, expected, 'returns expected value' ); - actual = replaceAfterLast( '🤖 Robot army 🤖!', '🤖', 'foo' ); + str = '🤖 Robot army 🤖!'; + actual = replaceAfterLast( str, '🤖', 'foo', str.length ); expected = '🤖 Robot army 🤖foo'; t.strictEqual( actual, expected, 'returns expected value' ); - actual = replaceAfterLast( '🐺 Wolf brothers 🐺', 'o', 'foo' ); + str = '🐺 Wolf brothers 🐺'; + actual = replaceAfterLast( str, 'o', 'foo', str.length ); expected = '🐺 Wolf brofoo'; t.strictEqual( actual, expected, 'returns expected value' ); t.end(); }); +tape( 'the function replaces the substring after a provided search string (custom start index)', function test( t ) { + var expected; + var actual; + var str; + + str = 'beep boop baz'; + actual = replaceAfterLast( str, ' ', 'foo', 6 ); + expected = 'beep foo'; + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop baz'; + actual = replaceAfterLast( str, 'p', 'foo', 6 ); + expected = 'beepfoo'; + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop baz'; + actual = replaceAfterLast( str, 'beep', 'foo', -2 ); + expected = 'beep boop baz'; + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop baz'; + actual = replaceAfterLast( str, 'beep', 'foo', 20 ); + expected = 'beep boop baz'; + 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; + var str; - actual = replaceAfterLast( 'beep boop', 'z', 'foo' ); + str = 'beep boop'; + actual = replaceAfterLast( str, 'z', 'foo', str.length ); expected = 'beep boop'; t.strictEqual( actual, expected, 'returns expected value' ); - actual = replaceAfterLast( 'beep boop', 'baz', 'foo' ); + str = 'beep boop'; + actual = replaceAfterLast( str, 'baz', 'foo', str.length ); expected = 'beep boop'; t.strictEqual( actual, expected, 'returns expected value' ); @@ -88,8 +126,10 @@ tape( 'the function returns the entire string if the search string is not found' tape( 'the function returns the entire string if the search string is the empty string', function test( t ) { var expected; var actual; + var str; - actual = replaceAfterLast( 'beep boop', '', 'foo' ); + str = 'beep boop'; + actual = replaceAfterLast( str, '', 'foo', str.length ); expected = 'beep boop'; t.strictEqual( actual, expected, 'returns expected value' ); From da2d6c55c00c9ebb78c7fdc2897aae2758220572 Mon Sep 17 00:00:00 2001 From: Golden <103646877+AuenKr@users.noreply.github.com> Date: Mon, 26 Feb 2024 22:47:36 +0530 Subject: [PATCH 03/12] Update lib/node_modules/@stdlib/string/base/replace-after-last/benchmark/benchmark.js Co-authored-by: Athan Signed-off-by: Golden <103646877+AuenKr@users.noreply.github.com> --- .../string/base/replace-after-last/benchmark/benchmark.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/string/base/replace-after-last/benchmark/benchmark.js b/lib/node_modules/@stdlib/string/base/replace-after-last/benchmark/benchmark.js index 36875fdfa6fa..5c83fa02335a 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after-last/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/string/base/replace-after-last/benchmark/benchmark.js @@ -44,7 +44,7 @@ bench( pkg, function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - out = replaceAfterLast( str, '.', values[ i%values.length ], str.length ); + out = replaceAfterLast( str, 'T', values[ i%values.length ], str.length ); if ( typeof out !== 'string' ) { b.fail( 'should return a string' ); } From 422b5af001a0cf6fcb49f55442da2bbb8e476a24 Mon Sep 17 00:00:00 2001 From: Golden <103646877+AuenKr@users.noreply.github.com> Date: Mon, 26 Feb 2024 22:47:46 +0530 Subject: [PATCH 04/12] Update lib/node_modules/@stdlib/string/base/replace-after-last/README.md Co-authored-by: Athan Signed-off-by: Golden <103646877+AuenKr@users.noreply.github.com> --- .../@stdlib/string/base/replace-after-last/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/string/base/replace-after-last/README.md b/lib/node_modules/@stdlib/string/base/replace-after-last/README.md index 1b8cc0c02131..94913db0af0d 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after-last/README.md +++ b/lib/node_modules/@stdlib/string/base/replace-after-last/README.md @@ -42,8 +42,7 @@ var replaceAfterLast = require( '@stdlib/string/base/replace-after-last' ); #### replaceAfterLast( str, search, replacement, fromIndex ) -- Replaces the substring after the last occurrence of a specified search string. -- fromIndex is index of last character to be considered beginning of a match. +Replaces the substring after the last occurrence of a specified search string. ```javascript var str = 'beep boop'; From dac231c4fba27565c8d23d406c07993aa7ef9023 Mon Sep 17 00:00:00 2001 From: Golden <103646877+AuenKr@users.noreply.github.com> Date: Mon, 26 Feb 2024 22:50:33 +0530 Subject: [PATCH 05/12] Update lib/node_modules/@stdlib/string/base/replace-after-last/docs/repl.txt Co-authored-by: Athan Signed-off-by: Golden <103646877+AuenKr@users.noreply.github.com> --- .../@stdlib/string/base/replace-after-last/docs/repl.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/string/base/replace-after-last/docs/repl.txt b/lib/node_modules/@stdlib/string/base/replace-after-last/docs/repl.txt index 1d908d220610..dceadc4889f2 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after-last/docs/repl.txt +++ b/lib/node_modules/@stdlib/string/base/replace-after-last/docs/repl.txt @@ -15,7 +15,7 @@ Replacement string. fromIndex: integer - Index of last character to be considered beginning of a match. + Index from which to start searching. Returns ------- From 46845dd727523fcfa12a365903c02bb009fe42f9 Mon Sep 17 00:00:00 2001 From: Golden <103646877+AuenKr@users.noreply.github.com> Date: Mon, 26 Feb 2024 22:50:45 +0530 Subject: [PATCH 06/12] Update lib/node_modules/@stdlib/string/base/replace-after-last/docs/types/index.d.ts Co-authored-by: Athan Signed-off-by: Golden <103646877+AuenKr@users.noreply.github.com> --- .../string/base/replace-after-last/docs/types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/string/base/replace-after-last/docs/types/index.d.ts b/lib/node_modules/@stdlib/string/base/replace-after-last/docs/types/index.d.ts index ce3c00fe4d35..146a1ec61cf1 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after-last/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/string/base/replace-after-last/docs/types/index.d.ts @@ -24,7 +24,7 @@ * @param str - input string * @param search - search string * @param replacement - replacement string -* @param fromIndex - index of last character to be considered beginning of a match +* @param fromIndex - index from which to start searching * @returns output string * * @example From ab5af1ff57041d60af53f0c12d5eb70786467c10 Mon Sep 17 00:00:00 2001 From: Golden <103646877+AuenKr@users.noreply.github.com> Date: Mon, 26 Feb 2024 22:51:25 +0530 Subject: [PATCH 07/12] Update lib/node_modules/@stdlib/string/base/replace-after-last/test/test.js Co-authored-by: Athan Signed-off-by: Golden <103646877+AuenKr@users.noreply.github.com> --- .../@stdlib/string/base/replace-after-last/test/test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/node_modules/@stdlib/string/base/replace-after-last/test/test.js b/lib/node_modules/@stdlib/string/base/replace-after-last/test/test.js index ca399c0ad26d..fe195f769b2c 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after-last/test/test.js +++ b/lib/node_modules/@stdlib/string/base/replace-after-last/test/test.js @@ -36,6 +36,7 @@ tape( 'the function replaces the substring after the last occurrence of a specif var expected; var actual; var str; + str = 'beep boop'; actual = replaceAfterLast( str, ' ', 'foo', str.length ); expected = 'beep foo'; From 4b186b9fe8bdd146c085788e3f6622cb5982415f Mon Sep 17 00:00:00 2001 From: Golden <103646877+AuenKr@users.noreply.github.com> Date: Mon, 26 Feb 2024 22:52:17 +0530 Subject: [PATCH 08/12] Update lib/node_modules/@stdlib/string/base/replace-after-last/docs/types/index.d.ts Co-authored-by: Athan Signed-off-by: Golden <103646877+AuenKr@users.noreply.github.com> --- .../string/base/replace-after-last/docs/types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/string/base/replace-after-last/docs/types/index.d.ts b/lib/node_modules/@stdlib/string/base/replace-after-last/docs/types/index.d.ts index 146a1ec61cf1..b820eb823b84 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after-last/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/string/base/replace-after-last/docs/types/index.d.ts @@ -39,7 +39,7 @@ * * @example * var str = 'Hello World!'; -* var out = replaceAfterLast( str, '', 'foo', str.length); +* var out = replaceAfterLast( str, '', 'foo', str.length ); * // returns 'Hello World!' * * @example From 21f834488d4537851e7d6596c77910e7120a5abe Mon Sep 17 00:00:00 2001 From: Golden <103646877+AuenKr@users.noreply.github.com> Date: Mon, 26 Feb 2024 22:52:32 +0530 Subject: [PATCH 09/12] Update lib/node_modules/@stdlib/string/base/replace-after-last/lib/main.js Co-authored-by: Athan Signed-off-by: Golden <103646877+AuenKr@users.noreply.github.com> --- .../@stdlib/string/base/replace-after-last/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/string/base/replace-after-last/lib/main.js b/lib/node_modules/@stdlib/string/base/replace-after-last/lib/main.js index cb9f127a51ef..217f6bec2758 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after-last/lib/main.js +++ b/lib/node_modules/@stdlib/string/base/replace-after-last/lib/main.js @@ -26,7 +26,7 @@ * @param {string} str - input string * @param {string} search - search string * @param {string} replacement - replacement string -* @param {integer} fromIndex - index of last character to be considered beginning of a match +* @param {integer} fromIndex - index from which to start searching * @returns {string} string * * @example From 3a4cf1ce47cc121fd101b27302dce85596cfbdd7 Mon Sep 17 00:00:00 2001 From: Golden <103646877+AuenKr@users.noreply.github.com> Date: Mon, 26 Feb 2024 22:52:51 +0530 Subject: [PATCH 10/12] Update lib/node_modules/@stdlib/string/base/replace-after-last/lib/main.js Co-authored-by: Athan Signed-off-by: Golden <103646877+AuenKr@users.noreply.github.com> --- .../@stdlib/string/base/replace-after-last/lib/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/string/base/replace-after-last/lib/main.js b/lib/node_modules/@stdlib/string/base/replace-after-last/lib/main.js index 217f6bec2758..6e939bdad73c 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after-last/lib/main.js +++ b/lib/node_modules/@stdlib/string/base/replace-after-last/lib/main.js @@ -41,7 +41,7 @@ * * @example * var str = 'Hello World!'; -* var out = replaceAfterLast( str, '', 'foo', str.length); +* var out = replaceAfterLast( str, '', 'foo', str.length ); * // returns 'Hello World!' * * @example From 7f43c1c93fbd2ef994371670aead226f0351e06b Mon Sep 17 00:00:00 2001 From: AuenKr Date: Mon, 26 Feb 2024 23:05:57 +0530 Subject: [PATCH 11/12] fixup! feat: applied changes for fromIndex --- .../string/base/replace-after-last/README.md | 6 +++- .../replace-after-last/docs/types/test.ts | 30 +++++++++---------- .../base/replace-after-last/lib/main.js | 2 +- .../base/replace-after-last/test/test.js | 2 +- 4 files changed, 22 insertions(+), 18 deletions(-) diff --git a/lib/node_modules/@stdlib/string/base/replace-after-last/README.md b/lib/node_modules/@stdlib/string/base/replace-after-last/README.md index 94913db0af0d..257702390616 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after-last/README.md +++ b/lib/node_modules/@stdlib/string/base/replace-after-last/README.md @@ -65,7 +65,7 @@ out = replaceAfterLast( str, 'o', 'bar', str.length ); - 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 search string length, the function returns the provided string unchanged. +- If `fromIndex` is less than `0`, the function returns the provided string unchanged. @@ -97,6 +97,10 @@ out = replaceAfterLast( str, '', 'foo', str.length ); str = ''; out = replaceAfterLast( str, 'xyz', 'foo', str.length ); // returns '' + +str = 'beep boop beep baz'; +out = replaceAfterLast( str, 'beep', 'foo', 5 ); +// return 'beepfoo' ``` diff --git a/lib/node_modules/@stdlib/string/base/replace-after-last/docs/types/test.ts b/lib/node_modules/@stdlib/string/base/replace-after-last/docs/types/test.ts index 2f422eb28372..5e008fd2d325 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after-last/docs/types/test.ts +++ b/lib/node_modules/@stdlib/string/base/replace-after-last/docs/types/test.ts @@ -23,9 +23,9 @@ import replaceAfterLast = require( './index' ); // The function returns a string... { - replaceAfterLast( 'beep boop', ' ', 'foo', 'beep boop'.length ); // $ExpectType string - replaceAfterLast( 'beep boop', 'xyz', 'foo', 'beep boop'.length ); // $ExpectType string - replaceAfterLast( 'beep boop', '', 'foo', 'beep boop'.length ); // $ExpectType string + replaceAfterLast( 'beep boop', ' ', 'foo', 10 ); // $ExpectType string + replaceAfterLast( 'beep boop', 'xyz', 'foo', 10 ); // $ExpectType string + replaceAfterLast( 'beep boop', '', 'foo', 10 ); // $ExpectType string } // The compiler throws an error if the function is provided arguments having invalid types... @@ -37,19 +37,19 @@ import replaceAfterLast = require( './index' ); replaceAfterLast( {}, 'd' , 'foo', 100 ); // $ExpectError replaceAfterLast( ( x: number ): number => x, 'd', 'foo', 100 ); // $ExpectError - replaceAfterLast( 'abc', true, 'foo', 'abc'.length ); // $ExpectError - replaceAfterLast( 'abc', false, 'foo', 'abc'.length ); // $ExpectError - replaceAfterLast( 'abc', 5 , 'foo', 'abc'.length ); // $ExpectError - replaceAfterLast( 'abc', [], 'foo', 'abc'.length ); // $ExpectError - replaceAfterLast( 'abc', {} , 'foo', 'abc'.length ); // $ExpectError - replaceAfterLast( 'abc', ( x: number ): number => x , 'foo', 'abc'.length ); // $ExpectError + replaceAfterLast( 'abc', true, 'foo', 10 ); // $ExpectError + replaceAfterLast( 'abc', false, 'foo', 10 ); // $ExpectError + replaceAfterLast( 'abc', 5 , 'foo', 10 ); // $ExpectError + replaceAfterLast( 'abc', [], 'foo', 10 ); // $ExpectError + replaceAfterLast( 'abc', {} , 'foo', 10 ); // $ExpectError + replaceAfterLast( 'abc', ( x: number ): number => x , 'foo', 10 ); // $ExpectError - replaceAfterLast( 'abc', 'd', true, 'abc'.length ); // $ExpectError - replaceAfterLast( 'abc', 'd', false, 'abc'.length ); // $ExpectError - replaceAfterLast( 'abc', 'd', 5, 'abc'.length ); // $ExpectError - replaceAfterLast( 'abc', 'd', [], 'abc'.length ); // $ExpectError - replaceAfterLast( 'abc', 'd', {}, 'abc'.length ); // $ExpectError - replaceAfterLast( 'abc', 'd', ( x: number ): number => x, 'abc'.length ); // $ExpectError + replaceAfterLast( 'abc', 'd', true, 10 ); // $ExpectError + replaceAfterLast( 'abc', 'd', false, 10 ); // $ExpectError + replaceAfterLast( 'abc', 'd', 5, 10 ); // $ExpectError + replaceAfterLast( 'abc', 'd', [], 10 ); // $ExpectError + replaceAfterLast( 'abc', 'd', {}, 10 ); // $ExpectError + replaceAfterLast( 'abc', 'd', ( x: number ): number => x, 10 ); // $ExpectError replaceAfterLast( 'abc', 'd', 'foo', true ); // $ExpectError replaceAfterLast( 'abc', 'd', 'foo', false ); // $ExpectError diff --git a/lib/node_modules/@stdlib/string/base/replace-after-last/lib/main.js b/lib/node_modules/@stdlib/string/base/replace-after-last/lib/main.js index 6e939bdad73c..cfc8d37ece84 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after-last/lib/main.js +++ b/lib/node_modules/@stdlib/string/base/replace-after-last/lib/main.js @@ -61,7 +61,7 @@ */ function replaceAfterLast( str, search, replacement, fromIndex ) { var idx; - if ( fromIndex < 0 || fromIndex > str.length ) { + if ( fromIndex < 0 ) { return str; } idx = str.lastIndexOf( search, fromIndex ); diff --git a/lib/node_modules/@stdlib/string/base/replace-after-last/test/test.js b/lib/node_modules/@stdlib/string/base/replace-after-last/test/test.js index fe195f769b2c..1036682dd25a 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after-last/test/test.js +++ b/lib/node_modules/@stdlib/string/base/replace-after-last/test/test.js @@ -100,7 +100,7 @@ tape( 'the function replaces the substring after a provided search string (custo str = 'beep boop baz'; actual = replaceAfterLast( str, 'beep', 'foo', 20 ); - expected = 'beep boop baz'; + expected = 'beepfoo'; t.strictEqual( actual, expected, 'returns expected value' ); t.end(); From 3f011bfc33c713fc22e595c3ca01829ce1363840 Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Tue, 27 Feb 2024 09:39:43 -0500 Subject: [PATCH 12/12] Update lib/node_modules/@stdlib/string/base/replace-after-last/docs/types/index.d.ts Signed-off-by: Philipp Burckhardt --- .../string/base/replace-after-last/docs/types/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/string/base/replace-after-last/docs/types/index.d.ts b/lib/node_modules/@stdlib/string/base/replace-after-last/docs/types/index.d.ts index b820eb823b84..812e5112b620 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after-last/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/string/base/replace-after-last/docs/types/index.d.ts @@ -57,7 +57,7 @@ * var out = replaceAfterLast( str, 'p b', 'foo', 6 ); * // returns 'beep bfoo' */ -declare function replaceAfterLast( str: string, search: string, replacement: string, fromIndex: number ): string; +declare function replaceAfterLast( str: string, search: string, replacement: string, fromIndex: number ): string; // EXPORTS //