README.md (3584B)
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 # reverseString 22 23 > Reverse a string. 24 25 <section class="usage"> 26 27 ## Usage 28 29 ```javascript 30 var reverseString = require( '@stdlib/string/reverse' ); 31 ``` 32 33 #### reverseString( str ) 34 35 Reverses a `string`. 36 37 ```javascript 38 var out = reverseString( 'last man standing' ); 39 // returns 'gnidnats nam tsal' 40 41 out = reverseString( 'Hidden Treasures' ); 42 // returns 'serusaerT neddiH' 43 44 out = reverseString( 'Lorem ipsum 𝌆 dolor sit ameͨ͆t.' ); 45 // returns '.teͨ͆ma tis rolod 𝌆 muspi meroL' 46 ``` 47 48 </section> 49 50 <!-- /.usage --> 51 52 <section class="notes"> 53 54 </section> 55 56 <!-- /.notes --> 57 58 <section class="examples"> 59 60 ## Examples 61 62 <!-- eslint no-undef: "error" --> 63 64 ```javascript 65 var reverseString = require( '@stdlib/string/reverse' ); 66 67 var str = reverseString( 'last man standing' ); 68 // returns 'gnidnats nam tsal' 69 70 str = reverseString( 'presidential election' ); 71 // returns 'noitcele laitnediserp' 72 73 str = reverseString( 'javaScript' ); 74 // returns 'tpircSavaj' 75 76 str = reverseString( 'Hidden Treasures' ); 77 // returns 'serusaerT neddiH' 78 ``` 79 80 </section> 81 82 <!-- /.examples --> 83 84 * * * 85 86 <section class="cli"> 87 88 ## CLI 89 90 <section class="usage"> 91 92 ### Usage 93 94 ```text 95 Usage: reverse [options] [<string>] 96 97 Options: 98 99 -h, --help Print this message. 100 -V, --version Print the package version. 101 --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. 102 ``` 103 104 </section> 105 106 <!-- /.usage --> 107 108 <!-- CLI usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 109 110 <section class="notes"> 111 112 ### Notes 113 114 - If the split separator is a [regular expression][mdn-regexp], ensure that the `split` option is either properly escaped or enclosed in quotes. 115 116 ```bash 117 # Not escaped... 118 $ echo -n $'beep\nboop' | reverse --split /\r?\n/ 119 120 # Escaped... 121 $ echo -n $'beep\nboop' | reverse --split /\\r?\\n/ 122 ``` 123 124 - The implementation ignores trailing delimiters. 125 126 </section> 127 128 <!-- /.notes --> 129 130 <section class="examples"> 131 132 ### Examples 133 134 ```bash 135 $ reverse foobar 136 raboof 137 ``` 138 139 To use as a [standard stream][standard-streams], 140 141 ```bash 142 $ echo -n 'foobar' | reverse 143 raboof 144 ``` 145 146 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. 147 148 ```bash 149 $ echo -n 'foobar\tbaz' | reverse --split '\t' 150 raboof 151 zab 152 ``` 153 154 </section> 155 156 <!-- /.examples --> 157 158 </section> 159 160 <!-- /.cli --> 161 162 <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> 163 164 <section class="related"> 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 [mdn-regexp]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions 175 176 [standard-streams]: https://en.wikipedia.org/wiki/Standard_streams 177 178 </section> 179 180 <!-- /.links -->