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