README.md (3240B)
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 # Remove Words 22 23 > Remove a list of words from a string. 24 25 <section class="intro"> 26 27 </section> 28 29 <!-- /.intro --> 30 31 <section class="usage"> 32 33 ## Usage 34 35 ```javascript 36 var removeWords = require( '@stdlib/string/remove-words' ); 37 ``` 38 39 #### removeWords( str, words\[, ignoreCase] ) 40 41 Removes all occurrences of the given `words` from a `string`. 42 43 ```javascript 44 var str = 'beep boop Foo bar'; 45 var out = removeWords( str, [ 'boop', 'foo' ] ); 46 // returns 'beep Foo bar' 47 ``` 48 49 By default, words are removed from an input `string` in case of an exact match. To perform a case-insensitive replace operation, set `ignoreCase` to `true`. 50 51 ```javascript 52 var str = 'beep boop Foo bar'; 53 var out = removeWords( str, [ 'boop', 'foo' ], true ); 54 // returns 'beep bar' 55 ``` 56 57 </section> 58 59 <!-- /.usage --> 60 61 <section class="examples"> 62 63 ## Examples 64 65 <!-- eslint no-undef: "error" --> 66 67 ```javascript 68 var removeWords = require( '@stdlib/string/remove-words' ); 69 var stopwords = require( '@stdlib/datasets/stopwords-en' ); 70 var inmap = require( '@stdlib/utils/inmap' ); 71 var spam = require( '@stdlib/datasets/spam-assassin' ); 72 73 var corpus = spam(); 74 var words = stopwords(); 75 76 function remove( mail, idx ) { 77 var newText = removeWords( mail.text, words ); 78 console.log( 'After removing stop words, email %d contains %d characters. Originally, it contained %d.', idx, newText.length, mail.text.length ); 79 mail.text = newText; 80 } 81 82 inmap( corpus, remove ); 83 ``` 84 85 </section> 86 87 <!-- /.examples --> 88 89 * * * 90 91 <section class="cli"> 92 93 ## CLI 94 95 <section class="usage"> 96 97 ### Usage 98 99 ```text 100 Usage: remove-words [options] [<string>] --words=<string> 101 102 Options: 103 104 -h, --help Print this message. 105 -V, --version Print the package version. 106 --words w1,w2,... Comma-separated list of words. 107 --ignore-case Perform case-insensitive replace operation. 108 ``` 109 110 </section> 111 112 <!-- /.usage --> 113 114 <section class="examples"> 115 116 ### Examples 117 118 ```bash 119 $ remove-words 'beep! boop!!!' --words='beep,boop' 120 ! !!! 121 ``` 122 123 To use as a [standard stream][standard-streams], 124 125 ```bash 126 $ echo -n 'beep! boop!!!' | remove-words --words='BEEP,BOOP' --ignore-case 127 ! !!! 128 ``` 129 130 </section> 131 132 <!-- /.examples --> 133 134 </section> 135 136 <!-- /.cli --> 137 138 <!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> 139 140 <section class="related"> 141 142 </section> 143 144 <!-- /.related --> 145 146 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 147 148 <section class="links"> 149 150 [standard-streams]: https://en.wikipedia.org/wiki/Standard_streams 151 152 </section> 153 154 <!-- /.links -->