From 2f8f997f4718e140453c74ac5b01666cb5fff77e Mon Sep 17 00:00:00 2001 From: Harshita Kalani Date: Fri, 24 Feb 2023 22:47:59 +0530 Subject: [PATCH 01/25] readme.md and package.json added to replace-after --- .../string/base/replace-after/README.md | 249 ++++++++++++++++++ .../string/base/replace-after/package.json | 72 +++++ 2 files changed, 321 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/package.json 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..964431471486 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/replace-after/README.md @@ -0,0 +1,249 @@ + + +# 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, replacement, search\[, fromIndex] ) + +Replaces the substring after the first occurrence of a specified search string. + +```javascript +var str = 'beep boop'; +var replacement = 'foo'; +var out = replaceAfter( str, replacement, 'o' ); +// returns 'beep bofoo' + +out = replaceAfter( str, replacement, ' ' ); +// returns 'beep foo' +``` + +By default, the search starts at the beginning of the string. To start searching from a different index, provide a `fromIndex` argument: + +```javascript +var str = 'boop baz boop'; +var replacement = 'foo'; +var out = replaceAfter( str, replacement, 'o', 3 ); +// returns 'boop baz bofoo' +``` + +
+ + + + + +
+ +## Notes + +- If a substring is not present in a provided string, the function returns an empty string. +- If provided an empty substring, the function returns the input string. +- If `fromIndex` is less than `0` or greater than `str.length`, the search starts at index `0` and `str.length`, respectively. + +
+ + + + + +
+ +## Examples + + + +```javascript +var replaceAfter = require( '@stdlib/string/base/replace-after' ); + +var str = 'To be, or not to be, that is the question.'; +var replacement = 'foo'; +var out = replaceAfter( str, replacement, ', ' ); +// returns 'To be, foo' + +out = replaceAfter( str, replacement, 'to be' ); +// returns 'To be, or not to befoo' + +out = replaceAfter( str, replacement, 'question.' ); +// returns 'To be, or not to be, that is the question.foo' + +out = replaceAfter( str, replacement, 'xyz' ); +// returns '' + +out = replaceAfter( str, replacement, '' ); +// returns 'foo' +``` + +
+ + + + + +* * * + +
+ +## CLI + + + +
+ +### Usage + +```text +Usage: replace-after [options] --search= --replacement= [] + +Options: + + -h, --help Print this message. + -V, --version Print the package version. + --search string Search string. + --replacement string Replacement string. + --from-index int Start index. Default: 0. + --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. +``` + +
+ + + + + +
+ +### Notes + +- If the split separator is a [regular expression][mdn-regexp], ensure that the `split` option is either properly escaped or enclosed in quotes. + + ```bash + # Not escaped... + $ echo -n $'foo\nbar\nbaz' | replace-after --search a --replacement b --split /\r?\n/ + + # Escaped... + $ echo -n $'foo\nbar\nbaz' | replace-after --search a --replacement b --split /\\r?\\n/ + ``` + +- The implementation ignores trailing delimiters. + +
+ + + + + +
+ +### Examples + +```bash +$ replace-after abcdefg --search d --replacement pqr +abcdpqr +``` + +To use as a [standard stream][standard-streams], + +```bash +$ echo -n $'bar\nbaz' | replace-after --search b --replacement pqr +bpqr +bpqr +``` + +By default, when used as a [standard stream][standard-streams], the implementation assumes newline-delimited data. To specify an alternative delimiter, set the `split` option. + +```bash +$ echo -n 'bar\tbaz' | replace-after --search b --replacement pqr --split '\t' +bpqr +bpqr +``` + +
+ + + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + 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..bb52f455d8ab --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/replace-after/package.json @@ -0,0 +1,72 @@ +{ + "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" + } + ], + "bin": { + "substring-after": "./bin/cli" + }, + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdstring", + "utilities", + "utility", + "utils", + "util", + "string", + "str", + "check", + "search", + "replacement", + "substring", + "substr", + "after", + "match" + ] + } + \ No newline at end of file From b1c345029785bdcb06db92a84dc71b919e58dfa5 Mon Sep 17 00:00:00 2001 From: Harshita Kalani Date: Sat, 25 Feb 2023 00:49:32 +0530 Subject: [PATCH 02/25] index.js and main.js added in replace-after --- .../string/base/replace-after/lib/index.js | 45 +++++++++ .../string/base/replace-after/lib/main.js | 99 +++++++++++++++++++ 2 files changed, 144 insertions(+) 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 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..2ad093b25195 --- /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 replacement = 'foo'; +* var out = replaceAfter( str, replacement, 'o' ); +* // returns 'beep bofoo' +* +* out = replaceAfter( str, replacement, ' ' ); +* // returns 'beep foo' +*/ + +// 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..ddc793f214c9 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/replace-after/lib/main.js @@ -0,0 +1,99 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; +var format = require( '@stdlib/string/format' ); + + +// MAIN // + +/** +* Replaces the substring after the first occurrence of a specified search string. +* +* @param {string} str - input string +* @param {string} replacement - replacement string +* @param {string} search - search string +* @param {integer} [fromIndex=0] - index at which to start the search +* @throws {TypeError} first argument must be a string +* @throws {TypeError} second argument must be a string +* @throws {TypeError} third argument must be a string +* @throws {TypeError} fourth argument must be an integer +* @returns {string} substring +* +* @example +* var out = replaceAfter( 'Hello, world!', 'foo', ', ' ); +* // returns 'NaNfoo' +* +* @example +* var out = replaceAfter( 'beep boop', 'foo', 'beep' ); +* // returns 'NaNfoo' +* +* @example +* var out = replaceAfter( 'beep boop', 'foo', 'boop' ); +* // returns 'NaNfoo' +* +* @example +* var out = replaceAfter( 'beep boop', 'foo', 'xyz' ); +* // returns '' +* +* @example +* var out = replaceAfter( 'beep boop', 'foo', 'beep', 5 ); +* // returns '' +* +* @example +* var out = replaceAfter( 'beep boop beep baz', 'foo', 'beep', 5 ); +* // returns 'NaNfoo' +*/ +function replaceAfter( str, replacement, search, fromIndex ) { + var idx; + if ( !isString( str ) ) { + throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); + } + if ( !isString( replacement ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be a string. Value: `%s`.', search ) ); + } + if ( !isString( search ) ) { + throw new TypeError( format( 'invalid argument. Second argument must be a string. Value: `%s`.', search ) ); + } + if ( arguments.length > 3 ) { + if ( !isInteger( fromIndex ) ) { + throw new TypeError( format( 'invalid argument. Third argument must be an integer. Value: `%s`.', fromIndex ) ); + } + idx = str.indexOf( search, fromIndex ); + } else { + idx = str.indexOf( search ); + } + if ( idx === -1 ) { + return ''; + } + if ( str === '' || search === '' || replacement === '' || idx < 0 ) { + return str; + } + str -= str.substring( idx+search.length ); + return str + replacement; +} + + +// EXPORTS // + +module.exports = replaceAfter; From 61e942fc1daea192acfcc81795fa241cda370cfc Mon Sep 17 00:00:00 2001 From: Harshita Kalani Date: Sat, 25 Feb 2023 01:02:48 +0530 Subject: [PATCH 03/25] updated main.js and added examples --- .../base/replace-after/examples/index.js | 43 +++++++++++++++++++ .../string/base/replace-after/lib/main.js | 14 +++--- 2 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 lib/node_modules/@stdlib/string/base/replace-after/examples/index.js 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..0356ea9f5c38 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/replace-after/examples/index.js @@ -0,0 +1,43 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +var replaceAfter = require( './../lib' ); + +var str = 'To be, or not to be, that is the question.'; +var replacement = 'foo'; +var out = replaceAfter( str, replacement, ', ' ); +console.log( out ); +// => 'To be, foo' + +out = replaceAfter( str, replacement, 'to be' ); +console.log( out ); +// => 'To be, or not to befoo' + +out = replaceAfter( str, replacement, 'question.' ); +console.log( out ); +// => 'To be, or not to be, that is the question.foo' + +out = replaceAfter( str, replacement, 'xyz' ); +console.log( out ); +// => '' + +out = replaceAfter( str, replacement, '' ); +console.log( out ); +// => 'foo' 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 ddc793f214c9..563b968e6220 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 @@ -42,15 +42,15 @@ var format = require( '@stdlib/string/format' ); * * @example * var out = replaceAfter( 'Hello, world!', 'foo', ', ' ); -* // returns 'NaNfoo' +* // returns 'Hello, foo' * * @example * var out = replaceAfter( 'beep boop', 'foo', 'beep' ); -* // returns 'NaNfoo' +* // returns 'beepfoo' * * @example * var out = replaceAfter( 'beep boop', 'foo', 'boop' ); -* // returns 'NaNfoo' +* // returns 'beep boopfoo' * * @example * var out = replaceAfter( 'beep boop', 'foo', 'xyz' ); @@ -62,7 +62,7 @@ var format = require( '@stdlib/string/format' ); * * @example * var out = replaceAfter( 'beep boop beep baz', 'foo', 'beep', 5 ); -* // returns 'NaNfoo' +* // returns 'beep boop beepfoo' */ function replaceAfter( str, replacement, search, fromIndex ) { var idx; @@ -86,11 +86,11 @@ function replaceAfter( str, replacement, search, fromIndex ) { if ( idx === -1 ) { return ''; } - if ( str === '' || search === '' || replacement === '' || idx < 0 ) { + if ( str === '' || replacement === '' || idx < 0 ) { return str; } - str -= str.substring( idx+search.length ); - return str + replacement; + + return str.substring( 0, idx+search.length ) + replacement; } From 1e26eb0c4777f6e706d9794d7a3b24c0dbdba46c Mon Sep 17 00:00:00 2001 From: Harshita Kalani Date: Sat, 25 Feb 2023 01:06:14 +0530 Subject: [PATCH 04/25] etc added --- .../base/replace-after/etc/cli_opts.json | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 lib/node_modules/@stdlib/string/base/replace-after/etc/cli_opts.json diff --git a/lib/node_modules/@stdlib/string/base/replace-after/etc/cli_opts.json b/lib/node_modules/@stdlib/string/base/replace-after/etc/cli_opts.json new file mode 100644 index 000000000000..7039ea1f635e --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/replace-after/etc/cli_opts.json @@ -0,0 +1,20 @@ +{ + "string": [ + "search", + "replacement", + "from-index", + "split" + ], + "boolean": [ + "help", + "version" + ], + "alias": { + "help": [ + "h" + ], + "version": [ + "V" + ] + } +} From d96a91292a64f2108fc7e499f78019e042a60001 Mon Sep 17 00:00:00 2001 From: Harshita Kalani Date: Sat, 25 Feb 2023 07:48:04 +0530 Subject: [PATCH 05/25] benchmark added --- .../base/replace-after/benchmark/benchmark.js | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 lib/node_modules/@stdlib/string/base/replace-after/benchmark/benchmark.js 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..6f98287e22d8 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/replace-after/benchmark/benchmark.js @@ -0,0 +1,53 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var fromCodePoint = require( '@stdlib/string/from-code-point' ); +var pkg = require( './../package.json' ).name; +var replaceAfter = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var replacement; + var out; + var str; + var i; + + str = 'To be, or not to be, that is the question.'; + replacement = 'foo'; + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + out = replaceAfter( str, replacement, fromCodePoint( i%126 ) ); + 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(); +}); From ec3587e61df05459827396a86cf17d7ac2976664 Mon Sep 17 00:00:00 2001 From: Harshita Kalani Date: Sat, 25 Feb 2023 20:26:57 +0530 Subject: [PATCH 06/25] benchmark.js --- .../string/base/replace-after/benchmark/benchmark.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) 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 6f98287e22d8..9ac8bfd77105 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 @@ -30,16 +30,22 @@ var replaceAfter = require( './../lib' ); // MAIN // bench( pkg, function benchmark( b ) { - var replacement; + var values; var out; var str; var i; str = 'To be, or not to be, that is the question.'; - replacement = 'foo'; + values = [ + 'foo', + 'bar', + 'beep', + 'boop' + ]; + b.tic(); for ( i = 0; i < b.iterations; i++ ) { - out = replaceAfter( str, replacement, fromCodePoint( i%126 ) ); + out = replaceAfter( str, values[i%values.length], fromCodePoint( i%126 ) ); if ( typeof out !== 'string' ) { b.fail( 'should return a string' ); } From 778b0123170f65b1df442bfd4cbaef10e1182111 Mon Sep 17 00:00:00 2001 From: Harshita Kalani Date: Sat, 25 Feb 2023 20:30:29 +0530 Subject: [PATCH 07/25] benchmark.js --- .../@stdlib/string/base/replace-after/benchmark/benchmark.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 9ac8bfd77105..646dbc0d6232 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 @@ -45,7 +45,7 @@ bench( pkg, function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - out = replaceAfter( str, values[i%values.length], fromCodePoint( i%126 ) ); + out = replaceAfter( str, values[i%values.length], fromCodePoint( i%126 ) ); // eslint-disable-line max-len if ( typeof out !== 'string' ) { b.fail( 'should return a string' ); } From 6473012abe6f21d4ddccc81dd51b3fb90031bc6a Mon Sep 17 00:00:00 2001 From: Harshita Kalani Date: Sat, 25 Feb 2023 15:35:17 +0530 Subject: [PATCH 08/25] types added --- .../string/base/replace-after/docs/repl.txt | 34 ++++++++++ .../base/replace-after/docs/types/index.d.ts | 61 +++++++++++++++++ .../base/replace-after/docs/types/test.ts | 68 +++++++++++++++++++ .../string/base/replace-after/docs/usage.txt | 11 +++ 4 files changed, 174 insertions(+) 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/docs/usage.txt 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..47e763c6f727 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/replace-after/docs/repl.txt @@ -0,0 +1,34 @@ + +{{alias}}( str, replacement, search[, fromIndex] ) + Returns the part of a string after a specified substring. + + Parameters + ---------- + str: string + Input string. + + replacement: string + Replacement string. + + search: string + Search string. + + fromIndex: integer (optional) + Index from which to start the search. Default: `0`. + + Returns + ------- + out: string + Substring. + + Examples + -------- + > var out = {{alias}}( 'Hello World!', 'foo', 'World' ) + 'Hello Worldfoo' + > out = {{alias}}( 'Hello World!', 'foo', 'Hello ' ) + 'Hello foo' + > out = {{alias}}( 'Hello World!', 'foo', 'l', 5 ) + 'Hello Worlfoo' + + 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..6d69660e6e70 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/replace-after/docs/types/index.d.ts @@ -0,0 +1,61 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2023 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +// TypeScript Version: 2.0 + +/// + +/** +* Returns the part of a string after a specified substring. +* +* @param str - input string +* @param replacement - replacement string +* @param search - search string +* @param fromIndex - index at which to start the search (default: 0) +* @returns substring +* +* @example +* var out = replaceAfter( 'Hello, world!', 'foo', ', ' ); +* // returns 'Hello, foo' +* +* @example +* var out = replaceAfter( 'beep boop', 'foo', 'beep' ); +* // returns 'beepfoo' +* +* @example +* var out = replaceAfter( 'beep boop', 'foo', 'boop' ); +* // returns 'beep boopfoo' +* +* @example +* var out = replaceAfter( 'beep boop', 'foo', 'xyz' ); +* // returns '' +* +* @example +* var out = replaceAfter( 'beep boop', 'foo', 'beep', 5 ); +* // returns '' +* +* @example +* var out = replaceAfter( 'beep boop beep baz', 'foo', 'beep', 5 ); +* // returns ' beep boop beepfoo' +*/ +declare function replaceAfter( str: string, replacement: string, search: string, fromIndex?: number ): string; // tslint:disable-line:max-line-length + + +// 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..e0bc838c779e --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/replace-after/docs/types/test.ts @@ -0,0 +1,68 @@ +/* +* @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', 'foo', 'xyz' ); // $ExpectType string + replaceAfter( 'beep boop', 'foo', '' ); // $ExpectType string + replaceAfter( 'beep boop', 'foo', 'b', 5 ); // $ExpectType string +} + +// The compiler throws an error if the function is provided arguments having invalid types... +{ + replaceAfter( true, 'foo', 'd', 0 ); // $ExpectError + replaceAfter( false, 'foo', 'd', 0 ); // $ExpectError + replaceAfter( 3, 'foo', 'd', 0 ); // $ExpectError + replaceAfter( [], 'foo', 'd', 0 ); // $ExpectError + replaceAfter( {}, 'foo', 'd', 0 ); // $ExpectError + replaceAfter( ( x: number ): number => x, 'foo', 'd', 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', 'foo', true, 0 ); // $ExpectError + replaceAfter( 'abc', 'foo', false, 0 ); // $ExpectError + replaceAfter( 'abc', 'foo', 5, 0 ); // $ExpectError + replaceAfter( 'abc', 'foo', [], 0 ); // $ExpectError + replaceAfter( 'abc', 'foo', {}, 0 ); // $ExpectError + replaceAfter( 'abc', 'foo', ( x: number ): number => x, 0 ); // $ExpectError + + replaceAfter( 'abc', 'foo', 'd', true ); // $ExpectError + replaceAfter( 'abc', 'foo', 'd', false ); // $ExpectError + replaceAfter( 'abc', 'foo', 'd', '5' ); // $ExpectError + replaceAfter( 'abc', 'foo', 'd', [] ); // $ExpectError + replaceAfter( 'abc', 'foo', 'd', {} ); // $ExpectError + replaceAfter( 'abc', 'foo', 'd', ( x: number ): number => x ); // $ExpectError +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + replaceAfter(); // $ExpectError + replaceAfter( 'abc' ); // $ExpectError + replaceAfter( 'abc', 'd', 1, 1 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/string/base/replace-after/docs/usage.txt b/lib/node_modules/@stdlib/string/base/replace-after/docs/usage.txt new file mode 100644 index 000000000000..329ed5d0b15a --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/replace-after/docs/usage.txt @@ -0,0 +1,11 @@ + +Usage: substring-after [options] --replacement= --search= [] + +Options: + + -h, --help Print this message. + -V, --version Print the package version. + --replacement string Replacement string. + --search string Search string. + --from-index int Start index. Default: 0. + --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. From 73a3653f431dc95af6885cebc8d12857e584affd Mon Sep 17 00:00:00 2001 From: Harshita Kalani Date: Sat, 25 Feb 2023 22:31:56 +0530 Subject: [PATCH 09/25] test.js added --- .../string/base/replace-after/test/test.js | 263 ++++++++++++++++++ 1 file changed, 263 insertions(+) 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/test/test.js b/lib/node_modules/@stdlib/string/base/replace-after/test/test.js new file mode 100644 index 000000000000..0fab8edd2f83 --- /dev/null +++ b/lib/node_modules/@stdlib/string/base/replace-after/test/test.js @@ -0,0 +1,263 @@ +/** +* @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 throws an error if not provided a string as its first argument', function test( t ) { + var values; + var i; + + values = [ + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + replaceAfter( value, 'foo', 'e' ); + }; + } +}); + +tape( 'the function throws an error if not provided a string as its second argument', function test( t ) { + var values; + var i; + + values = [ + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + replaceAfter( 'beep', value, 'e' ); + }; + } +}); + +tape( 'the function throws an error if not provided a string as its third argument', function test( t ) { + var values; + var i; + + values = [ + 5, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + replaceAfter( 'beep', 'foo', value ); + }; + } +}); + +tape( 'the function throws an error if provided a non-integer value as its fourth argument', function test( t ) { + var values; + var i; + + values = [ + '5', + 3.14, + NaN, + true, + false, + null, + void 0, + [], + {}, + function noop() {} + ]; + + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + replaceAfter( 'beep', 'foo', 'e', value ); + }; + } +}); + +tape( 'the function replaces the substring after the first occurrence of a specified search string', function test( t ) { + var replacement; + var expected; + var actual; + var str; + + str = 'beep boop'; + replacement = 'foo'; + actual = replaceAfter( str, replacement, ' ' ); + expected = 'beep foo'; + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop'; + replacement = 'foo'; + actual = replaceAfter( str, replacement, 'p' ); + expected = 'beepfoo'; + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'Hello, World!'; + replacement = 'foo'; + actual = replaceAfter( str, replacement, 'o' ); + 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 replacement; + var expected; + var actual; + var str; + + str = 'beep 😀 boop 😀 baz'; + replacement = 'foo'; + actual = replaceAfter( str, replacement, '😀' ); + expected = 'beep 😀foo'; + t.strictEqual( actual, expected, 'returns expected value' ); + + str = '🤖 Robot army 🤖!'; + actual = replaceAfter( str, replacement, '🤖' ); + expected = '🤖foo'; + + str = '🐺 Wolf brothers 🐺'; + replacement = 'foo'; + actual = replaceAfter( str, replacement, 'o' ); + expected = '🐺 Wofoo'; + + t.end(); +}); + +tape( 'the function replaces the substring after the first occurrence of a specified search string (custom start index)', function test( t ) { + var replacement; + var expected; + var actual; + var str; + + str = 'beep boop baz'; + replacement = 'foo'; + actual = replaceAfter( str, ' ', 6 ); + expected = 'beep boop foo'; + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop baz'; + replacement = 'foo'; + actual = replaceAfter( str, replacement, 'p', 6 ); + expected = 'beep boopfoo'; + + str = 'beep boop baz'; + replacement = 'foo'; + actual = replaceAfter( str, replacement, 'beep', -2 ); + expected = 'beepfoo'; + + str = 'beep boop baz'; + replacement = 'foo'; + actual = replaceAfter( str, replacement, 'beep', 20 ); + expected = ''; + + t.end(); +}); + +tape( 'the function returns the empty string if the search string is not found', function test( t ) { + var replacement; + var expected; + var actual; + var str; + + str = 'beep boop'; + replacement = 'foo'; + actual = replaceAfter( str, replacement, 'z' ); + expected = ''; + t.strictEqual( actual, expected, 'returns expected value' ); + + str = 'beep boop'; + replacement = 'foo'; + actual = replaceAfter( str, replacement, 'baz' ); + expected = ''; + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); + +tape( 'the function returns the replacement string if the search string is the empty string', function test( t ) { + var replacement; + var expected; + var actual; + var str; + + str = 'beep boop'; + replacement = 'foo'; + actual = replaceAfter( str, replacement, '' ); + expected = 'foo'; + t.strictEqual( actual, expected, 'returns expected value' ); + + t.end(); +}); From 03ce774c596c6973e43ce4e3a2e726855350be6e Mon Sep 17 00:00:00 2001 From: Harshita Kalani Date: Sat, 25 Feb 2023 22:35:46 +0530 Subject: [PATCH 10/25] test.js added and main.js updated --- .../@stdlib/string/base/replace-after/lib/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 563b968e6220..d58ef6def515 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 @@ -73,11 +73,11 @@ function replaceAfter( str, replacement, search, fromIndex ) { throw new TypeError( format( 'invalid argument. Second argument must be a string. Value: `%s`.', search ) ); } if ( !isString( search ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string. Value: `%s`.', search ) ); + throw new TypeError( format( 'invalid argument. Third argument must be a string. Value: `%s`.', search ) ); } if ( arguments.length > 3 ) { if ( !isInteger( fromIndex ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be an integer. Value: `%s`.', fromIndex ) ); + throw new TypeError( format( 'invalid argument. Fourth argument must be an integer. Value: `%s`.', fromIndex ) ); } idx = str.indexOf( search, fromIndex ); } else { From 1f4d64aabe333c81948bf5e4dc978d50660b0255 Mon Sep 17 00:00:00 2001 From: Harshita Kalani Date: Sat, 25 Feb 2023 22:36:52 +0530 Subject: [PATCH 11/25] test.js added and main.js updated --- 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 d58ef6def515..9d85ad8a207d 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 @@ -70,7 +70,7 @@ function replaceAfter( str, replacement, search, fromIndex ) { throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); } if ( !isString( replacement ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string. Value: `%s`.', search ) ); + throw new TypeError( format( 'invalid argument. Second argument must be a string. Value: `%s`.', replacement ) ); } if ( !isString( search ) ) { throw new TypeError( format( 'invalid argument. Third argument must be a string. Value: `%s`.', search ) ); From 55105128948555f2720b81b586bf49a42fb4b46e Mon Sep 17 00:00:00 2001 From: Harshita Kalani Date: Sat, 25 Feb 2023 22:44:03 +0530 Subject: [PATCH 12/25] main.js updated --- lib/node_modules/@stdlib/string/base/replace-after/lib/main.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 9d85ad8a207d..a9f0f917df3f 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 @@ -86,10 +86,9 @@ function replaceAfter( str, replacement, search, fromIndex ) { if ( idx === -1 ) { return ''; } - if ( str === '' || replacement === '' || idx < 0 ) { + if ( str === '' ) { return str; } - return str.substring( 0, idx+search.length ) + replacement; } From 3f16eb0df47dcab0524751e842145d0e0b420cd1 Mon Sep 17 00:00:00 2001 From: Harshita Kalani Date: Sat, 25 Feb 2023 22:48:05 +0530 Subject: [PATCH 13/25] main.js updated --- 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 0fab8edd2f83..f01772dd0b33 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 @@ -204,7 +204,7 @@ tape( 'the function replaces the substring after the first occurrence of a speci str = 'beep boop baz'; replacement = 'foo'; - actual = replaceAfter( str, ' ', 6 ); + actual = replaceAfter( str, replacement, ' ', 6 ); expected = 'beep boop foo'; t.strictEqual( actual, expected, 'returns expected value' ); From 8774e45f4745e6a15346db4f49b446a79a7bf806 Mon Sep 17 00:00:00 2001 From: Harshita Kalani Date: Sat, 25 Feb 2023 22:54:32 +0530 Subject: [PATCH 14/25] cli removed from readme.md --- .../string/base/replace-after/README.md | 110 ------------------ 1 file changed, 110 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 964431471486..d4df0bb0021b 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after/README.md +++ b/lib/node_modules/@stdlib/string/base/replace-after/README.md @@ -114,94 +114,6 @@ out = replaceAfter( str, replacement, '' ); - - -* * * - -
- -## CLI - - - -
- -### Usage - -```text -Usage: replace-after [options] --search= --replacement= [] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --search string Search string. - --replacement string Replacement string. - --from-index int Start index. Default: 0. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. -``` - -
- - - - - -
- -### Notes - -- If the split separator is a [regular expression][mdn-regexp], ensure that the `split` option is either properly escaped or enclosed in quotes. - - ```bash - # Not escaped... - $ echo -n $'foo\nbar\nbaz' | replace-after --search a --replacement b --split /\r?\n/ - - # Escaped... - $ echo -n $'foo\nbar\nbaz' | replace-after --search a --replacement b --split /\\r?\\n/ - ``` - -- The implementation ignores trailing delimiters. - -
- - - - - -
- -### Examples - -```bash -$ replace-after abcdefg --search d --replacement pqr -abcdpqr -``` - -To use as a [standard stream][standard-streams], - -```bash -$ echo -n $'bar\nbaz' | replace-after --search b --replacement pqr -bpqr -bpqr -``` - -By default, when used as a [standard stream][standard-streams], the implementation assumes newline-delimited data. To specify an alternative delimiter, set the `split` option. - -```bash -$ echo -n 'bar\tbaz' | replace-after --search b --replacement pqr --split '\t' -bpqr -bpqr -``` - -
- - - -
- - -
@@ -214,14 +126,6 @@ bpqr @@ -230,20 +134,6 @@ bpqr From 09f192809b0bb1a9180ba4db1bff55bb59a5c74c Mon Sep 17 00:00:00 2001 From: Harshita Kalani Date: Sat, 25 Feb 2023 22:56:41 +0530 Subject: [PATCH 15/25] cli removed from readme.md --- .../@stdlib/string/base/replace-after/docs/usage.txt | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 lib/node_modules/@stdlib/string/base/replace-after/docs/usage.txt diff --git a/lib/node_modules/@stdlib/string/base/replace-after/docs/usage.txt b/lib/node_modules/@stdlib/string/base/replace-after/docs/usage.txt deleted file mode 100644 index 329ed5d0b15a..000000000000 --- a/lib/node_modules/@stdlib/string/base/replace-after/docs/usage.txt +++ /dev/null @@ -1,11 +0,0 @@ - -Usage: substring-after [options] --replacement= --search= [] - -Options: - - -h, --help Print this message. - -V, --version Print the package version. - --replacement string Replacement string. - --search string Search string. - --from-index int Start index. Default: 0. - --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. From 1ef2db63038ff3d2c514c5d01da568e034edc6f3 Mon Sep 17 00:00:00 2001 From: Harshita Kalani Date: Sat, 25 Feb 2023 22:59:27 +0530 Subject: [PATCH 16/25] package.json updated --- .../@stdlib/string/base/replace-after/package.json | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/node_modules/@stdlib/string/base/replace-after/package.json b/lib/node_modules/@stdlib/string/base/replace-after/package.json index bb52f455d8ab..77023d46913a 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after/package.json +++ b/lib/node_modules/@stdlib/string/base/replace-after/package.json @@ -13,9 +13,6 @@ "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" } ], - "bin": { - "substring-after": "./bin/cli" - }, "main": "./lib", "directories": { "benchmark": "./benchmark", @@ -62,7 +59,7 @@ "str", "check", "search", - "replacement", + "replace", "substring", "substr", "after", From e7619ff2ebe836ce41838a923ed7fc8414312bfe Mon Sep 17 00:00:00 2001 From: Harshita Kalani Date: Mon, 27 Feb 2023 15:32:51 +0530 Subject: [PATCH 17/25] main.js logic updated --- .../base/replace-after/etc/cli_opts.json | 20 ------------------- .../string/base/replace-after/lib/main.js | 2 +- 2 files changed, 1 insertion(+), 21 deletions(-) delete mode 100644 lib/node_modules/@stdlib/string/base/replace-after/etc/cli_opts.json diff --git a/lib/node_modules/@stdlib/string/base/replace-after/etc/cli_opts.json b/lib/node_modules/@stdlib/string/base/replace-after/etc/cli_opts.json deleted file mode 100644 index 7039ea1f635e..000000000000 --- a/lib/node_modules/@stdlib/string/base/replace-after/etc/cli_opts.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "string": [ - "search", - "replacement", - "from-index", - "split" - ], - "boolean": [ - "help", - "version" - ], - "alias": { - "help": [ - "h" - ], - "version": [ - "V" - ] - } -} 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 a9f0f917df3f..c544660284f9 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 @@ -86,7 +86,7 @@ function replaceAfter( str, replacement, search, fromIndex ) { if ( idx === -1 ) { return ''; } - if ( str === '' ) { + if ( str === '' || search === '' ) { return str; } return str.substring( 0, idx+search.length ) + replacement; From ca8a67bac78a8a9925c3ba53e8dd3f8e61842f91 Mon Sep 17 00:00:00 2001 From: Harshita Kalani Date: Mon, 27 Feb 2023 15:40:52 +0530 Subject: [PATCH 18/25] examples corrected wrt main.js --- .../string/base/replace-after/docs/types/index.d.ts | 4 ++-- .../@stdlib/string/base/replace-after/examples/index.js | 2 +- .../@stdlib/string/base/replace-after/lib/main.js | 7 ++----- .../@stdlib/string/base/replace-after/test/test.js | 8 ++++---- 4 files changed, 9 insertions(+), 12 deletions(-) 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 6d69660e6e70..fc448202d157 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 @@ -43,11 +43,11 @@ * * @example * var out = replaceAfter( 'beep boop', 'foo', 'xyz' ); -* // returns '' +* // returns 'beep boop' * * @example * var out = replaceAfter( 'beep boop', 'foo', 'beep', 5 ); -* // returns '' +* // returns 'beep boop' * * @example * var out = replaceAfter( 'beep boop beep baz', 'foo', 'beep', 5 ); 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 0356ea9f5c38..a66b6f5b1c2e 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 @@ -36,7 +36,7 @@ console.log( out ); out = replaceAfter( str, replacement, 'xyz' ); console.log( out ); -// => '' +// => 'To be, or not to be, that is the question.' out = replaceAfter( str, replacement, '' ); console.log( out ); 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 c544660284f9..547ea4a1879e 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 @@ -54,11 +54,11 @@ var format = require( '@stdlib/string/format' ); * * @example * var out = replaceAfter( 'beep boop', 'foo', 'xyz' ); -* // returns '' +* // returns 'beep boop' * * @example * var out = replaceAfter( 'beep boop', 'foo', 'beep', 5 ); -* // returns '' +* // returns 'beep boop' * * @example * var out = replaceAfter( 'beep boop beep baz', 'foo', 'beep', 5 ); @@ -84,9 +84,6 @@ function replaceAfter( str, replacement, search, fromIndex ) { idx = str.indexOf( search ); } if ( idx === -1 ) { - return ''; - } - if ( str === '' || search === '' ) { return str; } return str.substring( 0, idx+search.length ) + replacement; 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 f01772dd0b33..07385e2d2a33 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 @@ -221,12 +221,12 @@ tape( 'the function replaces the substring after the first occurrence of a speci str = 'beep boop baz'; replacement = 'foo'; actual = replaceAfter( str, replacement, 'beep', 20 ); - expected = ''; + expected = 'beep boop baz'; t.end(); }); -tape( 'the function returns the empty string if the search string is not found', function test( t ) { +tape( 'the function returns the input string unchanged if the search string is not found', function test( t ) { var replacement; var expected; var actual; @@ -235,13 +235,13 @@ tape( 'the function returns the empty string if the search string is not found', str = 'beep boop'; replacement = 'foo'; actual = replaceAfter( str, replacement, 'z' ); - expected = ''; + expected = 'beep boop'; t.strictEqual( actual, expected, 'returns expected value' ); str = 'beep boop'; replacement = 'foo'; actual = replaceAfter( str, replacement, 'baz' ); - expected = ''; + expected = 'beep boop'; t.strictEqual( actual, expected, 'returns expected value' ); t.end(); From e8a3b9c4f3d334afba5885e0381c0bd34d813a57 Mon Sep 17 00:00:00 2001 From: Harshita Kalani Date: Tue, 28 Feb 2023 23:49:33 +0530 Subject: [PATCH 19/25] isValid consitions removed --- .../string/base/replace-after/lib/main.js | 17 ----------------- 1 file changed, 17 deletions(-) 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 547ea4a1879e..97cb86d8853c 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 @@ -20,11 +20,6 @@ // MODULES // -var isString = require( '@stdlib/assert/is-string' ).isPrimitive; -var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive; -var format = require( '@stdlib/string/format' ); - - // MAIN // /** @@ -66,19 +61,7 @@ var format = require( '@stdlib/string/format' ); */ function replaceAfter( str, replacement, search, fromIndex ) { var idx; - if ( !isString( str ) ) { - throw new TypeError( format( 'invalid argument. First argument must be a string. Value: `%s`.', str ) ); - } - if ( !isString( replacement ) ) { - throw new TypeError( format( 'invalid argument. Second argument must be a string. Value: `%s`.', replacement ) ); - } - if ( !isString( search ) ) { - throw new TypeError( format( 'invalid argument. Third argument must be a string. Value: `%s`.', search ) ); - } if ( arguments.length > 3 ) { - if ( !isInteger( fromIndex ) ) { - throw new TypeError( format( 'invalid argument. Fourth argument must be an integer. Value: `%s`.', fromIndex ) ); - } idx = str.indexOf( search, fromIndex ); } else { idx = str.indexOf( search ); From 7b7ef7f4401c066de25a347deb27312b88b435dd Mon Sep 17 00:00:00 2001 From: Pranav <85227306+Pranavchiku@users.noreply.github.com> Date: Thu, 2 Mar 2023 10:53:24 +0530 Subject: [PATCH 20/25] Update lib/node_modules/@stdlib/string/base/replace-after/README.md --- 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 d4df0bb0021b..dd498fa1e1fa 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after/README.md +++ b/lib/node_modules/@stdlib/string/base/replace-after/README.md @@ -104,7 +104,7 @@ out = replaceAfter( str, replacement, 'question.' ); // returns 'To be, or not to be, that is the question.foo' out = replaceAfter( str, replacement, 'xyz' ); -// returns '' +// returns 'To be, or not to be, that is the question.' out = replaceAfter( str, replacement, '' ); // returns 'foo' From 18a91aab1bfb4b7b4947d283798e25318ed64af8 Mon Sep 17 00:00:00 2001 From: Pranav <85227306+Pranavchiku@users.noreply.github.com> Date: Thu, 2 Mar 2023 10:53:35 +0530 Subject: [PATCH 21/25] Update lib/node_modules/@stdlib/string/base/replace-after/benchmark/benchmark.js --- .../@stdlib/string/base/replace-after/benchmark/benchmark.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 646dbc0d6232..de6da0c08d23 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 @@ -45,7 +45,7 @@ bench( pkg, function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - out = replaceAfter( str, values[i%values.length], fromCodePoint( i%126 ) ); // eslint-disable-line max-len + out = replaceAfter( str, values[ i % values.length ], fromCodePoint( i%126 ) ); // eslint-disable-line max-len if ( typeof out !== 'string' ) { b.fail( 'should return a string' ); } From 2e0c9d1d8f13e416646472a9bec08440e78956a7 Mon Sep 17 00:00:00 2001 From: Harshita Kalani Date: Thu, 2 Mar 2023 11:15:21 +0530 Subject: [PATCH 22/25] indentation rectified in package.json --- .../string/base/replace-after/package.json | 130 +++++++++--------- 1 file changed, 65 insertions(+), 65 deletions(-) diff --git a/lib/node_modules/@stdlib/string/base/replace-after/package.json b/lib/node_modules/@stdlib/string/base/replace-after/package.json index 77023d46913a..1c381e1d70b9 100644 --- a/lib/node_modules/@stdlib/string/base/replace-after/package.json +++ b/lib/node_modules/@stdlib/string/base/replace-after/package.json @@ -1,69 +1,69 @@ { - "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": "@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" - }, - "contributors": [ - { - "name": "The Stdlib Authors", - "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" - } - ], - "main": "./lib", - "directories": { - "benchmark": "./benchmark", - "doc": "./docs", - "example": "./examples", - "lib": "./lib", - "test": "./test" - }, - "types": "./docs/types", - "scripts": {}, - "homepage": "https://github.com/stdlib-js/stdlib", - "repository": { - "type": "git", - "url": "git://github.com/stdlib-js/stdlib.git" - }, - "bugs": { - "url": "https://github.com/stdlib-js/stdlib/issues" - }, - "dependencies": {}, - "devDependencies": {}, - "engines": { - "node": ">=0.10.0", - "npm": ">2.7.0" - }, - "os": [ - "aix", - "darwin", - "freebsd", - "linux", - "macos", - "openbsd", - "sunos", - "win32", - "windows" - ], - "keywords": [ - "stdlib", - "stdstring", - "utilities", - "utility", - "utils", - "util", - "string", - "str", - "check", - "search", - "replace", - "substring", - "substr", - "after", - "match" - ] - } + } + ], + "main": "./lib", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "stdstring", + "utilities", + "utility", + "utils", + "util", + "string", + "str", + "check", + "search", + "replace", + "substring", + "substr", + "after", + "match" + ] +} \ No newline at end of file From 2f7eed4853b0092c092d75524f3821aae4d24648 Mon Sep 17 00:00:00 2001 From: Harshita Kalani Date: Thu, 2 Mar 2023 11:18:36 +0530 Subject: [PATCH 23/25] repl.txt corrected --- .../@stdlib/string/base/replace-after/docs/repl.txt | 3 ++- 1 file changed, 2 insertions(+), 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 47e763c6f727..d1f03ff9594c 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,6 +1,7 @@ {{alias}}( str, replacement, search[, fromIndex] ) - Returns the part of a string after a specified substring. + Replaces the substring after the first occurrence of a + specified search string. Parameters ---------- From 149949d1616fdc7f3f6529dda8383cf6ccb50a01 Mon Sep 17 00:00:00 2001 From: Harshita Kalani Date: Thu, 2 Mar 2023 13:05:32 +0530 Subject: [PATCH 24/25] all tests passed --- .../string/base/replace-after/test/test.js | 113 ------------------ 1 file changed, 113 deletions(-) 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 07385e2d2a33..17fcbca609ea 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 @@ -32,119 +32,6 @@ tape( 'main export is a function', function test( t ) { t.end(); }); -tape( 'the function throws an error if not provided a string as its first argument', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replaceAfter( value, 'foo', 'e' ); - }; - } -}); - -tape( 'the function throws an error if not provided a string as its second argument', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replaceAfter( 'beep', value, 'e' ); - }; - } -}); - -tape( 'the function throws an error if not provided a string as its third argument', function test( t ) { - var values; - var i; - - values = [ - 5, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replaceAfter( 'beep', 'foo', value ); - }; - } -}); - -tape( 'the function throws an error if provided a non-integer value as its fourth argument', function test( t ) { - var values; - var i; - - values = [ - '5', - 3.14, - NaN, - true, - false, - null, - void 0, - [], - {}, - function noop() {} - ]; - - for ( i = 0; i < values.length; i++ ) { - t.throws( badValue( values[i] ), TypeError, 'throws an error when provided '+values[i] ); - } - t.end(); - - function badValue( value ) { - return function badValue() { - replaceAfter( 'beep', 'foo', 'e', value ); - }; - } -}); - tape( 'the function replaces the substring after the first occurrence of a specified search string', function test( t ) { var replacement; var expected; From 18f5e8fb40d52323d38597b88696ac86b0a14530 Mon Sep 17 00:00:00 2001 From: Harshita Kalani Date: Sat, 1 Apr 2023 15:00:29 +0530 Subject: [PATCH 25/25] feat: main.js updated --- .../@stdlib/string/base/replace-after/lib/main.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) 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 97cb86d8853c..bde140ed7a55 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 @@ -29,10 +29,6 @@ * @param {string} replacement - replacement string * @param {string} search - search string * @param {integer} [fromIndex=0] - index at which to start the search -* @throws {TypeError} first argument must be a string -* @throws {TypeError} second argument must be a string -* @throws {TypeError} third argument must be a string -* @throws {TypeError} fourth argument must be an integer * @returns {string} substring * * @example @@ -61,6 +57,9 @@ */ function replaceAfter( str, replacement, search, fromIndex ) { var idx; + if (str === '' || search === '') { + return str; + } if ( arguments.length > 3 ) { idx = str.indexOf( search, fromIndex ); } else {