README.md (4898B)
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 # kebabcase 22 23 > Convert a string to kebab case. 24 25 <!-- Package usage documentation. --> 26 27 <section class="usage"> 28 29 ## Usage 30 31 ```javascript 32 var kebabcase = require( '@stdlib/string/kebabcase' ); 33 ``` 34 35 #### kebabcase( str ) 36 37 Converts a string to kebab case. 38 39 ```javascript 40 var str = kebabcase( 'Foo Bar' ); 41 // returns 'foo-bar' 42 43 str = kebabcase( 'I am a tiny little house' ); 44 // returns 'i-am-a-tiny-little-house' 45 46 str = kebabcase( '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 kebabcase = require( '@stdlib/string/kebabcase' ); 62 63 var str = 'foo bar baz'; 64 var out = kebabcase( str ); 65 // returns 'foo-bar-baz' 66 67 str = 'foo_baz'; 68 out = kebabcase( str ); 69 // returns 'foo-baz' 70 71 str = 'foo-bar-baz!'; 72 out = kebabcase( str ); 73 // returns 'foo-bar-baz' 74 75 str = 'beep boop!'; 76 out = kebabcase( str ); 77 // returns 'beep-boop' 78 79 str = 'foo-baz'; 80 out = kebabcase( str ); 81 // returns 'foo-baz' 82 83 str = 'Welcome! 😀'; 84 out = kebabcase( 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: kebabcase [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\nisMobile' | kebabcase --split /\r?\n/ 127 128 # Escaped... 129 $ echo -n $'beEp booP\nisMobile' | kebabcase --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 $ kebabcase 'hello world!' 144 hello-world 145 ``` 146 147 To use as a [standard stream][standard-streams], 148 149 ```bash 150 $ echo -n 'beEp booP' | kebabcase 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\tisMobile' | kebabcase --split '\t' 158 beep-boop 159 is-mobile 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/pascalcase`][@stdlib/string/pascalcase]</span><span class="delimiter">: </span><span class="description">convert a string to Pascal case.</span> 181 - <span class="package-name">[`@stdlib/string/snakecase`][@stdlib/string/snakecase]</span><span class="delimiter">: </span><span class="description">convert a string to snake case.</span> 182 183 </section> 184 185 <!-- /.related --> 186 187 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 188 189 <section class="links"> 190 191 [standard-streams]: https://en.wikipedia.org/wiki/Standard_streams 192 193 [mdn-regexp]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions 194 195 <!-- <related-links> --> 196 197 [@stdlib/string/camelcase]: https://github.com/stdlib-js/string/tree/main/camelcase 198 199 [@stdlib/string/constantcase]: https://github.com/stdlib-js/string/tree/main/constantcase 200 201 [@stdlib/string/pascalcase]: https://github.com/stdlib-js/string/tree/main/pascalcase 202 203 [@stdlib/string/snakecase]: https://github.com/stdlib-js/string/tree/main/snakecase 204 205 <!-- </related-links> --> 206 207 </section> 208 209 <!-- /.links -->