time-to-botec

Benchmark sampling in different programming languages
Log | Files | Refs | README

README.md (6421B)


      1 <!--
      2 
      3 @license Apache-2.0
      4 
      5 Copyright (c) 2021 The Stdlib Authors.
      6 
      7 Licensed under the Apache License, Version 2.0 (the "License");
      8 you may not use this file except in compliance with the License.
      9 You may obtain a copy of the License at
     10 
     11    http://www.apache.org/licenses/LICENSE-2.0
     12 
     13 Unless required by applicable law or agreed to in writing, software
     14 distributed under the License is distributed on an "AS IS" BASIS,
     15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16 See the License for the specific language governing permissions and
     17 limitations under the License.
     18 
     19 -->
     20 
     21 # substringAfter
     22 
     23 > Return the part of a string after a specified substring.
     24 
     25 <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->
     26 
     27 <section class="intro">
     28 
     29 </section>
     30 
     31 <!-- /.intro -->
     32 
     33 <!-- Package usage documentation. -->
     34 
     35 <section class="usage">
     36 
     37 ## Usage
     38 
     39 ```javascript
     40 var substringAfter = require( '@stdlib/string/substring-after' );
     41 ```
     42 
     43 #### substringAfter( str, search\[, fromIndex] )
     44 
     45 Returns the part of a string after a specified substring.
     46 
     47 ```javascript
     48 var str = 'beep boop';
     49 var out = substringAfter( str, 'o' );
     50 // returns 'op'
     51 
     52 out = substringAfter( str, ' ' );
     53 // returns 'boop'
     54 ```
     55 
     56 By default, the search starts at the beginning of the string. To start searching from a different index, provide a `fromIndex` argument:
     57 
     58 ```javascript
     59 var str = 'boop baz boop';
     60 var out = substringAfter( str, 'o', 3 );
     61 // returns 'op'
     62 ```
     63 
     64 </section>
     65 
     66 <!-- /.usage -->
     67 
     68 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
     69 
     70 <section class="notes">
     71 
     72 ## Notes
     73 
     74 -   If a substring is not present in a provided string, the function returns an empty string.
     75 -   If provided an empty substring, the function returns the input string.
     76 -   If `fromIndex` is less than `0` or greater than `str.length`, the search starts at index `0` and `str.length`, respectively.
     77 
     78 </section>
     79 
     80 <!-- /.notes -->
     81 
     82 <!-- Package usage examples. -->
     83 
     84 <section class="examples">
     85 
     86 ## Examples
     87 
     88 <!-- eslint no-undef: "error" -->
     89 
     90 ```javascript
     91 var substringAfter = require( '@stdlib/string/substring-after' );
     92 
     93 var str = 'To be, or not to be, that is the question.';
     94 var out = substringAfter( str, ', ' );
     95 // returns 'or not to be, that is the question.'
     96 
     97 out = substringAfter( str, 'to be' );
     98 // returns ', that is the question.'
     99 
    100 out = substringAfter( str, 'question.' );
    101 // returns ''
    102 
    103 out = substringAfter( str, 'xyz' );
    104 // returns ''
    105 
    106 out = substringAfter( str, '' );
    107 // returns 'To be, or not to be, that is the question.'
    108 ```
    109 
    110 </section>
    111 
    112 <!-- /.examples -->
    113 
    114 <!-- Section for describing a command-line interface. -->
    115 
    116 * * *
    117 
    118 <section class="cli">
    119 
    120 ## CLI
    121 
    122 <!-- CLI usage documentation. -->
    123 
    124 <section class="usage">
    125 
    126 ### Usage
    127 
    128 ```text
    129 Usage: substring-after [options] --search=<string> [<string>]
    130 
    131 Options:
    132 
    133   -h,    --help                Print this message.
    134   -V,    --version             Print the package version.
    135          --search string       Search string.
    136          --from-index int      Start index. Default: 0.
    137          --split sep           Delimiter for stdin data. Default: '/\\r?\\n/'.
    138 ```
    139 
    140 </section>
    141 
    142 <!-- /.usage -->
    143 
    144 <!-- CLI usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    145 
    146 <section class="notes">
    147 
    148 ### Notes
    149 
    150 -   If the split separator is a [regular expression][mdn-regexp], ensure that the `split` option is either properly escaped or enclosed in quotes.
    151 
    152     ```bash
    153     # Not escaped...
    154     $ echo -n $'foo\nbar\nbaz' | substring-after --search a --split /\r?\n/
    155 
    156     # Escaped...
    157     $ echo -n $'foo\nbar\nbaz' | substring-after --search a --split /\\r?\\n/
    158     ```
    159 
    160 -   The implementation ignores trailing delimiters.
    161 
    162 </section>
    163 
    164 <!-- /.notes -->
    165 
    166 <!-- CLI usage examples. -->
    167 
    168 <section class="examples">
    169 
    170 ### Examples
    171 
    172 ```bash
    173 $ substring-after abcdefg --search d
    174 efg
    175 ```
    176 
    177 To use as a [standard stream][standard-streams],
    178 
    179 ```bash
    180 $ echo -n $'bar\nbaz' | substring-after --search b
    181 ar
    182 az
    183 ```
    184 
    185 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.
    186 
    187 ```bash
    188 $ echo -n 'bar\tbaz' | substring-after --search b --split '\t'
    189 ar
    190 az
    191 ```
    192 
    193 </section>
    194 
    195 <!-- /.examples -->
    196 
    197 </section>
    198 
    199 <!-- /.cli -->
    200 
    201 <!-- 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. -->
    202 
    203 <section class="references">
    204 
    205 </section>
    206 
    207 <!-- /.references -->
    208 
    209 <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
    210 
    211 <section class="related">
    212 
    213 * * *
    214 
    215 ## See Also
    216 
    217 -   <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>
    218 -   <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>
    219 -   <span class="package-name">[`@stdlib/string/substring-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>
    220 
    221 </section>
    222 
    223 <!-- /.related -->
    224 
    225 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    226 
    227 <section class="links">
    228 
    229 [standard-streams]: https://en.wikipedia.org/wiki/Standard_streams
    230 
    231 [mdn-regexp]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
    232 
    233 <!-- <related-links> -->
    234 
    235 [@stdlib/string/substring-before]: https://github.com/stdlib-js/string/tree/main/substring-before
    236 
    237 [@stdlib/string/substring-before-last]: https://github.com/stdlib-js/string/tree/main/substring-before-last
    238 
    239 [@stdlib/string/substring-after-last]: https://github.com/stdlib-js/string/tree/main/substring-after-last
    240 
    241 <!-- </related-links> -->
    242 
    243 </section>
    244 
    245 <!-- /.links -->