time-to-botec

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

README.md (4270B)


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