time-to-botec

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

README.md (4610B)


      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 # snakecase
     22 
     23 > Convert a string to snake case.
     24 
     25 <!-- Package usage documentation. -->
     26 
     27 <section class="usage">
     28 
     29 ## Usage
     30 
     31 ```javascript
     32 var snakecase = require( '@stdlib/string/snakecase' );
     33 ```
     34 
     35 #### snakecase( str )
     36 
     37 Converts a string to snake case.
     38 
     39 ```javascript
     40 var str = snakecase( 'Foo Bar' );
     41 // returns 'foo_bar'
     42 
     43 str = snakecase( 'I am a tiny little house' );
     44 // returns 'i_am_a_tiny_little_house'
     45 
     46 str = snakecase( 'Hello World!' );
     47 // returns 'hello_world'
     48 ```
     49 
     50 </section>
     51 
     52 <!-- /.usage -->
     53 
     54 <!-- Package usage examples. -->
     55 
     56 <section class="examples">
     57 
     58 ## Examples
     59 
     60 ```javascript
     61 var snakecase = require( '@stdlib/string/snakecase' );
     62 
     63 var str = 'foo bar baz';
     64 var out = snakecase( str );
     65 // returns 'foo_bar_baz'
     66 
     67 str = 'foo_baz';
     68 out = snakecase( str );
     69 // returns 'foo_baz'
     70 
     71 str = 'foo_bar_baz!';
     72 out = snakecase( str );
     73 // returns 'foo_bar_baz'
     74 
     75 str = 'beep    boop!';
     76 out = snakecase( str );
     77 // returns 'beep_boop'
     78 
     79 str = 'foo-baz';
     80 out = snakecase( str );
     81 // returns 'foo_baz'
     82 
     83 str = 'Welcome! 😀';
     84 out = snakecase( str );
     85 // returns 'welcome_😀'
     86 ```
     87 
     88 </section>
     89 
     90 <!-- /.examples -->
     91 
     92 * * *
     93 
     94 <section class="cli">
     95 
     96 ## CLI
     97 
     98 <section class="usage">
     99 
    100 ### Usage
    101 
    102 ```text
    103 Usage: snakecase [options] [<string>]
    104 
    105 Options:
    106 
    107   -h,    --help                Print this message.
    108   -V,    --version             Print the package version.
    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 booP\nfooBar' | snakecase --split /\r?\n/
    127 
    128     # Escaped...
    129     $ echo -n $'beEp booP\nfooBar' | snakecase --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 $ snakecase 'hello world!'
    144 hello_world
    145 ```
    146 
    147 To use as a [standard stream][standard-streams],
    148 
    149 ```bash
    150 $ echo -n 'beEp booP' | snakecase
    151 beep_boop
    152 ```
    153 
    154 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.
    155 
    156 ```bash
    157 $ echo -n 'beEp booP\tfooBar' | snakecase --split '\t'
    158 beep_boop
    159 foo_bar
    160 ```
    161 
    162 </section>
    163 
    164 <!-- /.examples -->
    165 
    166 </section>
    167 
    168 <!-- /.cli -->
    169 
    170 <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->
    171 
    172 <section class="related">
    173 
    174 * * *
    175 
    176 ## See Also
    177 
    178 -   <span class="package-name">[`@stdlib/string/camelcase`][@stdlib/string/camelcase]</span><span class="delimiter">: </span><span class="description">convert a string to camel case.</span>
    179 -   <span class="package-name">[`@stdlib/string/constantcase`][@stdlib/string/constantcase]</span><span class="delimiter">: </span><span class="description">convert a string to constant case.</span>
    180 -   <span class="package-name">[`@stdlib/string/kebabcase`][@stdlib/string/kebabcase]</span><span class="delimiter">: </span><span class="description">convert a string to kebab case.</span>
    181 
    182 </section>
    183 
    184 <!-- /.related -->
    185 
    186 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->
    187 
    188 <section class="links">
    189 
    190 [standard-streams]: https://en.wikipedia.org/wiki/Standard_streams
    191 
    192 [mdn-regexp]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
    193 
    194 <!-- <related-links> -->
    195 
    196 [@stdlib/string/camelcase]: https://github.com/stdlib-js/string/tree/main/camelcase
    197 
    198 [@stdlib/string/constantcase]: https://github.com/stdlib-js/string/tree/main/constantcase
    199 
    200 [@stdlib/string/kebabcase]: https://github.com/stdlib-js/string/tree/main/kebabcase
    201 
    202 <!-- </related-links> -->
    203 
    204 </section>
    205 
    206 <!-- /.links -->