time-to-botec

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

README.md (4352B)


      1 <!--
      2 
      3 @license Apache-2.0
      4 
      5 Copyright (c) 2018 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 # removeFirst
     22 
     23 > Remove the first character(s) of a string.
     24 
     25 <section class="usage">
     26 
     27 ## Usage
     28 
     29 ```javascript
     30 var removeFirst = require( '@stdlib/string/remove-first' );
     31 ```
     32 
     33 #### removeFirst( str\[, n] )
     34 
     35 Removes the first character of a `string`.
     36 
     37 ```javascript
     38 var out = removeFirst( 'last man standing' );
     39 // returns 'ast man standing'
     40 
     41 out = removeFirst( 'Hidden Treasures' );
     42 // returns 'idden Treasures'
     43 ```
     44 
     45 If provided a second argument, the function removes the first `n` characters.
     46 
     47 ```javascript
     48 var out = removeFirst( 'foo bar', 4 );
     49 // returns 'bar'
     50 
     51 out = removeFirst( 'foo bar', 10 );
     52 // returns ''
     53 ```
     54 
     55 </section>
     56 
     57 <!-- /.usage -->
     58 
     59 <section class="examples">
     60 
     61 ## Examples
     62 
     63 <!-- eslint no-undef: "error" -->
     64 
     65 ```javascript
     66 var removeFirst = require( '@stdlib/string/remove-first' );
     67 
     68 var str = removeFirst( 'last man standing' );
     69 // returns 'ast man standing'
     70 
     71 str = removeFirst( 'presidential election' );
     72 // returns 'residential election'
     73 
     74 str = removeFirst( 'javaScript' );
     75 // returns 'avaScript'
     76 
     77 str = removeFirst( 'Hidden Treasures' );
     78 // returns 'idden Treasures'
     79 
     80 str = removeFirst( 'The Last of the Mohicans', 4 );
     81 // returns 'Last of the Mohicans'
     82 
     83 str = removeFirst( '🐶🐮🐷🐰🐸', 2 );
     84 // returns '🐷🐰🐸'
     85 
     86 str = removeFirst( '🐶🐮🐷🐰🐸', 10 );
     87 // returns ''
     88 ```
     89 
     90 </section>
     91 
     92 <!-- /.examples -->
     93 
     94 * * *
     95 
     96 <section class="cli">
     97 
     98 ## CLI
     99 
    100 <section class="usage">
    101 
    102 ### Usage
    103 
    104 ```text
    105 Usage: remove-first [options] [<string>]
    106 
    107 Options:
    108 
    109   -h,    --help                Print this message.
    110   -V,    --version             Print the package version.
    111          --n                   Number of characters to remove. Default: 1.
    112          --split sep           Delimiter for stdin data. Default: '/\\r?\\n/'.
    113 ```
    114 
    115 </section>
    116 
    117 <!-- /.usage -->
    118 
    119 <!-- CLI usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    120 
    121 <section class="notes">
    122 
    123 ### Notes
    124 
    125 -   If the split separator is a [regular expression][mdn-regexp], ensure that the `split` option is either properly escaped or enclosed in quotes.
    126 
    127     ```bash
    128     # Not escaped...
    129     $ echo -n $'beep\nboop' | remove-first --split /\r?\n/
    130 
    131     # Escaped...
    132     $ echo -n $'beep\nboop' | remove-first --split /\\r?\\n/
    133     ```
    134 
    135 -   The implementation ignores trailing delimiters.
    136 
    137 </section>
    138 
    139 <!-- /.notes -->
    140 
    141 <section class="examples">
    142 
    143 ### Examples
    144 
    145 ```bash
    146 $ remove-first beep
    147 eep
    148 ```
    149 
    150 To use as a [standard stream][standard-streams],
    151 
    152 ```bash
    153 $ echo -n 'beep\nboop' | remove-first --n=2
    154 be
    155 bo
    156 ```
    157 
    158 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.
    159 
    160 ```bash
    161 $ echo -n 'beep\tboop' | remove-first --split '\t'
    162 eep
    163 oop
    164 ```
    165 
    166 </section>
    167 
    168 <!-- /.examples -->
    169 
    170 </section>
    171 
    172 <!-- /.cli -->
    173 
    174 <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
    175 
    176 <section class="related">
    177 
    178 * * *
    179 
    180 ## See Also
    181 
    182 -   <span class="package-name">[`@stdlib/string/remove-last`][@stdlib/string/remove-last]</span><span class="delimiter">: </span><span class="description">remove the last character of a string.</span>
    183 
    184 </section>
    185 
    186 <!-- /.related -->
    187 
    188 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    189 
    190 <section class="links">
    191 
    192 [standard-streams]: https://en.wikipedia.org/wiki/Standard_streams
    193 
    194 [mdn-regexp]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
    195 
    196 <!-- <related-links> -->
    197 
    198 [@stdlib/string/remove-last]: https://github.com/stdlib-js/string/tree/main/remove-last
    199 
    200 <!-- </related-links> -->
    201 
    202 </section>
    203 
    204 <!-- /.links -->