Skip to content

Added implementation for @stdlib/string/base/replace-after #921

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

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
a510f8e
readme.md for replace-before
HarshitaKalani Feb 4, 2023
3725623
readme.md added for replace-before
HarshitaKalani Feb 4, 2023
357a601
Merge branch 'develop' of https://github.com/stdlib-js/stdlib into re…
HarshitaKalani Feb 4, 2023
42ef006
Added main.js for replace-before
HarshitaKalani Feb 4, 2023
864227e
updated a comment in main.js
HarshitaKalani Feb 4, 2023
7a75514
index.js added in replace-before
HarshitaKalani Feb 4, 2023
6049a76
benchmark.js added in replace-before
HarshitaKalani Feb 4, 2023
32e46a6
updated main.js in replace-before
HarshitaKalani Feb 4, 2023
ed76908
examples added in replace-before
HarshitaKalani Feb 4, 2023
4de1ada
test added in replace_before
HarshitaKalani Feb 4, 2023
aeca05e
package.json added to replace_before
HarshitaKalani Feb 4, 2023
2611bde
etc added to replace-before
HarshitaKalani Feb 4, 2023
f2bad45
docs added in replace_before
HarshitaKalani Feb 4, 2023
fbc12e2
added bin in replace_before
HarshitaKalani Feb 4, 2023
d9391fa
updated 2021 to 2023 in all files
HarshitaKalani Feb 5, 2023
58b88e9
indeantation added in readme.md
HarshitaKalani Feb 5, 2023
1b8fad0
made the required changes after review
HarshitaKalani Feb 12, 2023
fee7998
Update lib/node_modules/@stdlib/string/base/replace-before/README.md
HarshitaKalani Feb 12, 2023
6b45090
Update lib/node_modules/@stdlib/string/base/replace-before/README.md
HarshitaKalani Feb 12, 2023
1f1fe55
Update lib/node_modules/@stdlib/string/base/replace-before/README.md
HarshitaKalani Feb 12, 2023
a837811
Update lib/node_modules/@stdlib/string/base/replace-before/README.md
HarshitaKalani Feb 12, 2023
7485791
Update lib/node_modules/@stdlib/string/base/replace-before/README.md
HarshitaKalani Feb 12, 2023
e5a2d71
Update lib/node_modules/@stdlib/string/base/replace-before/README.md
HarshitaKalani Feb 12, 2023
9875414
Update lib/node_modules/@stdlib/string/base/replace-before/benchmark/…
HarshitaKalani Feb 12, 2023
e74289c
Update lib/node_modules/@stdlib/string/base/replace-before/docs/repl.txt
HarshitaKalani Feb 12, 2023
3d2838b
Update lib/node_modules/@stdlib/string/base/replace-before/docs/repl.txt
HarshitaKalani Feb 12, 2023
da64037
Update lib/node_modules/@stdlib/string/base/replace-before/docs/types…
HarshitaKalani Feb 12, 2023
927bb0e
Update lib/node_modules/@stdlib/string/base/replace-before/docs/types…
HarshitaKalani Feb 12, 2023
4de2f23
Update lib/node_modules/@stdlib/string/base/replace-before/docs/types…
HarshitaKalani Feb 12, 2023
5357956
updated the changes
HarshitaKalani Feb 13, 2023
3de2a67
resolve conflict
HarshitaKalani Feb 13, 2023
b9a5ed3
lint errors and cli test cases resolved
HarshitaKalani Feb 22, 2023
381c32c
updation in docs
HarshitaKalani Feb 24, 2023
0b06210
readme.md updated
HarshitaKalani Feb 24, 2023
85b24ea
package.json updates
HarshitaKalani Feb 24, 2023
321ef7b
repl.txt updates
HarshitaKalani Feb 24, 2023
2b47faa
readme.md updated
HarshitaKalani Feb 24, 2023
8763a7d
readme.md and package.json added to replace-after
HarshitaKalani Feb 24, 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
4 changes: 3 additions & 1 deletion lib/node_modules/@stdlib/string/base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
"utility",
"utils",
"util",
"base"
"base",
"replace"
]
}

249 changes: 249 additions & 0 deletions lib/node_modules/@stdlib/string/base/replace-after/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
<!--

@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.

-->

# 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, 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'
```

</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 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.

</section>

<!-- /.notes -->

<!-- Package usage examples. -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```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'
```

</section>

<!-- /.examples -->

<!-- Section for describing a command-line interface. -->

* * *

<section class="cli">

## CLI

<!-- CLI usage documentation. -->

<section class="usage">

### Usage

```text
Usage: replace-after [options] --search=<string> --replacement=<string> [<string>]

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/'.
```

</section>

<!-- /.usage -->

<!-- CLI usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

### 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.

</section>

<!-- /.notes -->

<!-- CLI usage examples. -->

<section class="examples">

### 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
```

</section>

<!-- /.examples -->

</section>

<!-- /.cli -->

<!-- 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">

* * *

## See Also

- <span class="package-name">[`@stdlib/string/substring-before`][@stdlib/string/substring-before]</span><span class="delimiter">: </span><span class="description">return the part of a string before a specified substring.</span>
- <span class="package-name">[`@stdlib/string/substring-before-last`][@stdlib/string/substring-before-last]</span><span class="delimiter">: </span><span class="description">return the part of a string before the last occurrence of a specified substring.</span>
- <span class="package-name">[`@stdlib/string/replace-after-last`][@stdlib/string/substring-after-last]</span><span class="delimiter">: </span><span class="description">return the part of a string after the last occurrence of a specified substring.</span>

</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">

[standard-streams]: https://en.wikipedia.org/wiki/Standard_streams

[mdn-regexp]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions

<!-- <related-links> -->

[@stdlib/string/substring-before]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/substring-before

[@stdlib/string/substring-before-last]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/substring-before-last

[@stdlib/string/substring-after-last]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/string/replace-after-last

<!-- </related-links> -->

</section>

<!-- /.links -->
72 changes: 72 additions & 0 deletions lib/node_modules/@stdlib/string/base/replace-after/package.json
Original file line number Diff line number Diff line change
@@ -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"
]
}

Loading