Skip to content

feat: add support for replacing a substring after the first occurrence of a search string #922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 25 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2f8f997
readme.md and package.json added to replace-after
HarshitaKalani Feb 24, 2023
b1c3450
index.js and main.js added in replace-after
HarshitaKalani Feb 24, 2023
61e942f
updated main.js and added examples
HarshitaKalani Feb 24, 2023
1e26eb0
etc added
HarshitaKalani Feb 24, 2023
d96a912
benchmark added
HarshitaKalani Feb 25, 2023
ec3587e
benchmark.js
HarshitaKalani Feb 25, 2023
778b012
benchmark.js
HarshitaKalani Feb 25, 2023
6473012
types added
HarshitaKalani Feb 25, 2023
73a3653
test.js added
HarshitaKalani Feb 25, 2023
03ce774
test.js added and main.js updated
HarshitaKalani Feb 25, 2023
1f4d64a
test.js added and main.js updated
HarshitaKalani Feb 25, 2023
5510512
main.js updated
HarshitaKalani Feb 25, 2023
3f16eb0
main.js updated
HarshitaKalani Feb 25, 2023
8774e45
cli removed from readme.md
HarshitaKalani Feb 25, 2023
09f1928
cli removed from readme.md
HarshitaKalani Feb 25, 2023
1ef2db6
package.json updated
HarshitaKalani Feb 25, 2023
e7619ff
main.js logic updated
HarshitaKalani Feb 27, 2023
ca8a67b
examples corrected wrt main.js
HarshitaKalani Feb 27, 2023
e8a3b9c
isValid consitions removed
HarshitaKalani Feb 28, 2023
7b7ef7f
Update lib/node_modules/@stdlib/string/base/replace-after/README.md
Pranavchiku Mar 2, 2023
18a91aa
Update lib/node_modules/@stdlib/string/base/replace-after/benchmark/b…
Pranavchiku Mar 2, 2023
2e0c9d1
indentation rectified in package.json
HarshitaKalani Mar 2, 2023
2f7eed4
repl.txt corrected
HarshitaKalani Mar 2, 2023
149949d
all tests passed
HarshitaKalani Mar 2, 2023
18f5e8f
feat: main.js updated
HarshitaKalani Apr 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
examples corrected wrt main.js
  • Loading branch information
HarshitaKalani committed Apr 1, 2023
commit ca8a67bac78a8a9925c3ba53e8dd3f8e61842f91
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down