README.md (5284B)
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 # acronym 22 23 > Generate an acronym for a given string. 24 25 <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> 26 27 <section class="intro"> 28 29 </section> 30 31 <!-- /.intro --> 32 33 <!-- Package usage documentation. --> 34 35 <section class="usage"> 36 37 ## Usage 38 39 ```javascript 40 var acronym = require( '@stdlib/string/acronym' ); 41 ``` 42 43 #### acronym( str\[, options] ) 44 45 Generates an acronym for a given string. 46 47 ```javascript 48 var out = acronym( 'the quick brown fox' ); 49 // returns 'QBF' 50 51 out = acronym( 'Hard-boiled eggs' ); 52 // returns 'HBE' 53 ``` 54 55 The function accepts the following `options`: 56 57 - **stopwords**: list of custom stop words. If not specified, the function uses a default set of stop words from the English language that were deemed words one would likely want to exclude from the acronym generation (a subset of the stop words from [@stdlib/datasets/stopwords-en][@stdlib/datasets/stopwords-en]). 58 59 By default, the function uses a list of common English stop words. To use a custom list, set the `stopwords` option. 60 61 ```javascript 62 var out = acronym( 'the quick brown fox', { 63 'stopwords': [] 64 }); 65 // returns 'TQBF' 66 67 out = acronym( 'the quick brown fox', { 68 'stopwords': [ 'the', 'quick', 'brown', 'fox' ] 69 }); 70 // returns '' 71 ``` 72 73 </section> 74 75 <!-- /.usage --> 76 77 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 78 79 <section class="notes"> 80 81 </section> 82 83 <!-- /.notes --> 84 85 <!-- Package usage examples. --> 86 87 <section class="examples"> 88 89 ## Examples 90 91 <!-- eslint no-undef: "error" --> 92 93 ```javascript 94 var acronym = require( '@stdlib/string/acronym' ); 95 96 var str = 'Test-driven development'; 97 var out = acronym( str ); 98 // returns 'TDD' 99 100 str = 'Industrial Business Machines'; 101 out = acronym( str ); 102 // returns 'IBM' 103 104 str = 'National Aeronautics and Space Administration'; 105 out = acronym( str ); 106 // returns 'NASA' 107 108 str = 'To be determined...'; 109 out = acronym( str, { 110 'stopwords': [] 111 }); 112 // returns 'TBD' 113 ``` 114 115 </section> 116 117 <!-- /.examples --> 118 119 <!-- Section for describing a command-line interface. --> 120 121 * * * 122 123 <section class="cli"> 124 125 ## CLI 126 127 <!-- CLI usage documentation. --> 128 129 <section class="usage"> 130 131 ### Usage 132 133 ```text 134 Usage: acronym [options] [<string>] 135 136 Options: 137 138 -h, --help Print this message. 139 -V, --version Print the package version. 140 --stopwords str Comma-separated list of custom stop words. 141 --split sep Delimiter for stdin data. Default: '/\\r?\\n/'. 142 ``` 143 144 </section> 145 146 <!-- /.usage --> 147 148 <!-- CLI usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 149 150 <section class="notes"> 151 152 ### Notes 153 154 - If the split separator is a [regular expression][mdn-regexp], ensure that the `split` option is either properly escaped or enclosed in quotes. 155 156 ```bash 157 # Not escaped... 158 $ echo -n $'quick brown fox\nAlpha-Centauri' | acronym --split /\r?\n/ 159 160 # Escaped... 161 $ echo -n $'quick brown fox\nAlpha-Centauri' | acronym --split /\\r?\\n/ 162 ``` 163 164 - The implementation ignores trailing delimiters. 165 166 </section> 167 168 <!-- /.notes --> 169 170 <!-- CLI usage examples. --> 171 172 <section class="examples"> 173 174 ### Examples 175 176 ```bash 177 $ acronym 'the quick brown fox' 178 QBF 179 ``` 180 181 To use as a [standard stream][standard-streams], 182 183 ```bash 184 $ echo -n 'the quick brown fox'' | acronym 185 QBF 186 ``` 187 188 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. 189 190 ```bash 191 $ echo -n 'quick brown fox\tAlpha-Centauri' | acronym --split '\t' 192 QBF 193 AC 194 ``` 195 196 </section> 197 198 <!-- /.examples --> 199 200 </section> 201 202 <!-- /.cli --> 203 204 <!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 205 206 <section class="references"> 207 208 </section> 209 210 <!-- /.references --> 211 212 <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> 213 214 <section class="related"> 215 216 </section> 217 218 <!-- /.related --> 219 220 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 221 222 <section class="links"> 223 224 [standard-streams]: https://en.wikipedia.org/wiki/Standard_streams 225 226 [mdn-regexp]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions 227 228 [@stdlib/datasets/stopwords-en]: https://www.npmjs.com/package/@stdlib/datasets-stopwords-en 229 230 </section> 231 232 <!-- /.links -->