-
-
Notifications
You must be signed in to change notification settings - Fork 485
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes: #812 PR-URL: #1363 Co-authored-by: Athan Reines <kgryte@gmail.com> Reviewed-by: Athan Reines <kgryte@gmail.com> Signed-off-by: Golden <103646877+AuenKr@users.noreply.github.com> Signed-off-by: Athan Reines <kgryte@gmail.com>
- Loading branch information
Showing
10 changed files
with
719 additions
and
0 deletions.
There are no files selected for viewing
129 changes: 129 additions & 0 deletions
129
lib/node_modules/@stdlib/string/base/replace-after/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
<!-- | ||
@license Apache-2.0 | ||
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. | ||
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. | ||
--> | ||
|
||
# replaceAfter | ||
|
||
> Replace the substring after the first occurrence of a specified search string. | ||
<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> | ||
|
||
<section class="intro"> | ||
|
||
</section> | ||
|
||
<!-- /.intro --> | ||
|
||
<!-- Package usage documentation. --> | ||
|
||
<section class="usage"> | ||
|
||
## Usage | ||
|
||
```javascript | ||
var replaceAfter = require( '@stdlib/string/base/replace-after' ); | ||
``` | ||
|
||
#### replaceAfter( str, search, replacement, fromIndex ) | ||
|
||
Replaces the substring after the first occurrence of a specified search string. | ||
|
||
```javascript | ||
var out = replaceAfter( 'beep boop', ' ', 'loop', 0 ); | ||
// returns 'beep loop' | ||
|
||
out = replaceAfter( 'beep boop', 'o', 'bar', 0 ); | ||
// returns 'beep bobar' | ||
|
||
out = replaceAfter( 'beep boop beep baz', 'beep', 'foo', 5 ); | ||
// return 'beep boop beepfoo' | ||
``` | ||
|
||
</section> | ||
|
||
<!-- /.usage --> | ||
|
||
<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
||
<section class="notes"> | ||
|
||
## 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. | ||
- If `fromIndex` is less than `0` or greater than `str.length`, the search starts at index `0` and `str.length`, respectively. | ||
|
||
</section> | ||
|
||
<!-- /.notes --> | ||
|
||
<!-- Package usage examples. --> | ||
|
||
<section class="examples"> | ||
|
||
## Examples | ||
|
||
<!-- eslint no-undef: "error" --> | ||
|
||
```javascript | ||
var replaceAfter = require( '@stdlib/string/base/replace-after' ); | ||
|
||
var out = replaceAfter( 'beep boop', 'p', 'see', 0 ); | ||
// returns 'beepsee' | ||
|
||
out = replaceAfter( 'Hello World!', 'xyz', 'foo', 0 ); | ||
// returns 'Hello World!' | ||
|
||
out = replaceAfter( 'Hello World!', '', 'foo', 0 ); | ||
// returns 'Hello World!' | ||
|
||
out = replaceAfter( '', 'xyz', 'foo', 0 ); | ||
// returns '' | ||
|
||
out = replaceAfter( 'beep boop beep baz', 'beep', 'foo', 5 ); | ||
// return 'beep boop beepfoo' | ||
``` | ||
|
||
</section> | ||
|
||
<!-- /.examples --> | ||
|
||
<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
||
<section class="references"> | ||
|
||
</section> | ||
|
||
<!-- /.references --> | ||
|
||
<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> | ||
|
||
<section class="related"> | ||
|
||
</section> | ||
|
||
<!-- /.related --> | ||
|
||
<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> | ||
|
||
<section class="links"> | ||
|
||
</section> | ||
|
||
<!-- /.links --> |
58 changes: 58 additions & 0 deletions
58
lib/node_modules/@stdlib/string/base/replace-after/benchmark/benchmark.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* @license Apache-2.0 | ||
* | ||
* 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. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
// MODULES // | ||
|
||
var bench = require( '@stdlib/bench' ); | ||
var isString = require( '@stdlib/assert/is-string' ).isPrimitive; | ||
var pkg = require( './../package.json' ).name; | ||
var replaceAfter = require( './../lib' ); | ||
|
||
|
||
// MAIN // | ||
|
||
bench( pkg, function benchmark( b ) { | ||
var values; | ||
var out; | ||
var str; | ||
var i; | ||
|
||
str = 'To be, or not to be, that is the question.'; | ||
values = [ | ||
'foo', | ||
'bar', | ||
'beep', | ||
'boop' | ||
]; | ||
|
||
b.tic(); | ||
for ( i = 0; i < b.iterations; i++ ) { | ||
out = replaceAfter( str, '.', values[ i%values.length ], 0 ); | ||
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(); | ||
}); |
38 changes: 38 additions & 0 deletions
38
lib/node_modules/@stdlib/string/base/replace-after/docs/repl.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
{{alias}}( str, search, replacement, fromIndex ) | ||
Replaces the substring after the first occurrence of a specified search | ||
string. | ||
|
||
Parameters | ||
---------- | ||
str: string | ||
Input string. | ||
|
||
search: string | ||
Search string. | ||
|
||
replacement: string | ||
Replacement string. | ||
|
||
fromIndex: integer | ||
Index from which to start the search. | ||
|
||
Returns | ||
------- | ||
out: string | ||
Output string. | ||
|
||
Examples | ||
-------- | ||
> var out = {{alias}}( 'beep boop', ' ', 'foo', 0 ) | ||
'beep foo' | ||
> out = {{alias}}( 'beep boop', 'o', 'foo', 0 ) | ||
'beep bofoo' | ||
> out = {{alias}}( 'Hello World!', 'o', 'foo', 5 ) | ||
'Hello Wofoo' | ||
> out = {{alias}}( 'beep boop beep baz', 'beep', 'foo', 5 ) | ||
'beep boop beepfoo' | ||
|
||
See Also | ||
-------- | ||
|
59 changes: 59 additions & 0 deletions
59
lib/node_modules/@stdlib/string/base/replace-after/docs/types/index.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* @license Apache-2.0 | ||
* | ||
* 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. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
// TypeScript Version: 4.1 | ||
|
||
/** | ||
* Replaces the substring after the first occurrence of a specified search string. | ||
* | ||
* @param str - input string | ||
* @param search - search string | ||
* @param replacement - replacement string | ||
* @param fromIndex - index at which to start the search | ||
* @returns output string | ||
* | ||
* @example | ||
* var out = replaceAfter( 'beep boop', ' ', 'foo', 0 ); | ||
* // returns 'beep foo' | ||
* | ||
* @example | ||
* var out = replaceAfter( 'beep boop', 'p', 'foo', 5 ); | ||
* // returns 'beep boopfoo' | ||
* | ||
* @example | ||
* var out = replaceAfter( 'Hello World!', '', 'foo', 0 ); | ||
* // returns 'Hello World!' | ||
* | ||
* @example | ||
* var out = replaceAfter( 'Hello World!', 'xyz', 'foo', 0 ); | ||
* // returns 'Hello World!' | ||
* | ||
* @example | ||
* var out = replaceAfter( 'beep boop', ' ', 'foo' , 5 ); | ||
* // returns 'beep foo' | ||
* | ||
* @example | ||
* var out = replaceAfter( 'beep boop beep baz', 'beep', 'foo' , 5 ); | ||
* // returns 'beep boop beepfoo' | ||
*/ | ||
declare function replaceAfter( str: string, search: string, replacement: string, fromIndex: number ): string; | ||
|
||
|
||
// EXPORTS // | ||
|
||
export = replaceAfter; |
69 changes: 69 additions & 0 deletions
69
lib/node_modules/@stdlib/string/base/replace-after/docs/types/test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* @license Apache-2.0 | ||
* | ||
* 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. | ||
* 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', 0 ); // $ExpectType string | ||
replaceAfter( 'beep boop', 'xyz', 'foo', 0 ); // $ExpectType string | ||
replaceAfter( 'beep boop', '', 'foo', 0 ); // $ExpectType string | ||
replaceAfter( 'beep boop', '', 'foo', 5 ); // $ExpectType string | ||
} | ||
|
||
// The compiler throws an error if the function is provided arguments having invalid types... | ||
{ | ||
replaceAfter( true, 'd', 'foo', 0 ); // $ExpectError | ||
replaceAfter( false, 'd' , 'foo', 0 ); // $ExpectError | ||
replaceAfter( 3, 'd' , 'foo', 0 ); // $ExpectError | ||
replaceAfter( [], 'd' , 'foo', 0 ); // $ExpectError | ||
replaceAfter( {}, 'd' , 'foo', 0 ); // $ExpectError | ||
replaceAfter( ( x: number ): number => x, 'd', 'foo', 0 ); // $ExpectError | ||
|
||
replaceAfter( 'abc', true, 'foo', 0 ); // $ExpectError | ||
replaceAfter( 'abc', false, 'foo', 0 ); // $ExpectError | ||
replaceAfter( 'abc', 5 , 'foo', 0 ); // $ExpectError | ||
replaceAfter( 'abc', [], 'foo', 0 ); // $ExpectError | ||
replaceAfter( 'abc', {} , 'foo', 0 ); // $ExpectError | ||
replaceAfter( 'abc', ( x: number ): number => x , 'foo', 0 ); // $ExpectError | ||
|
||
replaceAfter( 'abc', 'd', true, 0 ); // $ExpectError | ||
replaceAfter( 'abc', 'd', false, 0 ); // $ExpectError | ||
replaceAfter( 'abc', 'd', 5, 0 ); // $ExpectError | ||
replaceAfter( 'abc', 'd', [], 0 ); // $ExpectError | ||
replaceAfter( 'abc', 'd', {}, 0 ); // $ExpectError | ||
replaceAfter( 'abc', 'd', ( x: number ): number => x, 0 ); // $ExpectError | ||
|
||
replaceAfter( 'abc', 'd', 'foo', true ); // $ExpectError | ||
replaceAfter( 'abc', 'd', 'foo', false ); // $ExpectError | ||
replaceAfter( 'abc', 'd', 'foo', '5' ); // $ExpectError | ||
replaceAfter( 'abc', 'd', 'foo', [] ); // $ExpectError | ||
replaceAfter( 'abc', 'd', 'foo', {} ); // $ExpectError | ||
replaceAfter( 'abc', 'd', 'foo', ( x: number ): number => x ); // $ExpectError | ||
} | ||
|
||
// The compiler throws an error if the function is provided insufficient arguments... | ||
{ | ||
replaceAfter(); // $ExpectError | ||
replaceAfter( 'abc' ); // $ExpectError | ||
replaceAfter( 'abc', 'd' ); // $ExpectError | ||
replaceAfter( 'abc', 'd', 'd', 1, 1 ); // $ExpectError | ||
} |
Oops, something went wrong.
04ee89f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Coverage Report
The above coverage report was generated for the changes in this push.