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