Skip to content

Commit cba85dc

Browse files
committed
fix(docs): styling & API usage/examples
API usage/examples should use real functions (.sync/.async) README styling (headings/notes/etc) should be unified & more readable fixes issue #1
1 parent 1761be6 commit cba85dc

File tree

1 file changed

+62
-24
lines changed

1 file changed

+62
-24
lines changed

README.md

Lines changed: 62 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ CLI & Node wrapper around [javascript replace](https://developer.mozilla.org/en-
1111
* [Examples](#examples)
1212

1313
## Installation
14-
### yarn
14+
#### yarn
1515
```
1616
$ yarn add frs-replace
1717
```
1818

19-
### npm
19+
#### npm
2020
```
2121
$ npm install frs-replace
2222
```
2323

24-
### download
24+
#### download
2525
[zipped from FRS-replace Releases](https://github.com/FRSource/FRS-replace/releases)
2626

27-
### Node API usage
27+
## Node API usage
2828

2929
FRS-replace package provides 2 methods for synchronous / asynchronous (with promise and ES6 `async`/`await` syntax support) usage:
3030

@@ -48,7 +48,7 @@ Where `/* options */` is an object containing:
4848
| output | string | *undefined* | Path of an output file |
4949
| outputOptions | string or object | utf8 | Passed as options argument of [write's .sync](https://www.npmjs.com/package/write#sync) |
5050

51-
### CLI usage
51+
## CLI usage
5252

5353
```bash
5454
FRS-replace <regex> <replacement> [options]
@@ -72,63 +72,101 @@ FRS-replace <regex> <replacement> [options]
7272
| &#8209;h, &#8209;&#8209;help | boolean | *-* | Show help |
7373
| &#8209;v, &#8209;&#8209;version | boolean | *-* | Show version number |
7474

75-
### Examples
75+
## Examples
7676

7777
> Note: while most of examples is using synchronous API method, in all cases `.async` is applicable as well.
7878
79-
Replaces all `a` occurences with `b` from given `foo.js` and save result to `foo_replaced.js` :
79+
#### 1. Replace all `a` occurences with `b` from given `foo.js` and returns result / writes result to console :
8080

81-
##### API
81+
###### API
8282
```javascript
83-
require('FRS-replace').sync({
83+
const FRSReplace = require('FRS-replace')
84+
85+
/* synchronously */
86+
const resultSync = FRSReplace.sync({
8487
input : 'foo.js',
8588
regex : new RegExp('a', 'g'),
8689
replacement : 'b',
8790
output : 'foo_replaced.js'
8891
})
92+
// work with result here
93+
94+
/* asynchronously */
95+
FRSReplace.async({
96+
input : 'foo.js',
97+
regex : new RegExp('a', 'g'),
98+
replacement : 'b'
99+
})
100+
.then(resultAsync => {
101+
// work with result here */
102+
})
103+
104+
/* asynchronously ES6 syntax (must be runned inside async function) */
105+
const resultAsync = await FRSReplace.async({
106+
input : 'foo.js',
107+
regex : new RegExp('a', 'g'),
108+
replacement : 'b'
109+
})
110+
// work with result here */
111+
89112
```
90113

91-
##### CLI
114+
###### CLI
115+
```bash
116+
FRS-replace a b -i foo.js --stdout
117+
```
118+
119+
#### 2. Replace all `a` occurences with `b` from given `foo.js` and save result to `foo_replaced.js` :
120+
121+
###### API
122+
```javascript
123+
const result = require('FRS-replace').sync({
124+
input : 'foo.js',
125+
regex : new RegExp('a', 'g'),
126+
replacement : 'b',
127+
output : 'foo_replaced.js'
128+
})
129+
```
130+
131+
###### CLI
92132
```bash
93133
FRS-replace a b -i foo.js -o foo_replaced.js
94134
```
95135

96-
Replace all `a` occurences with `b` in given `abcd` and save result to `foo_replaced.js`
136+
#### 3. Replace all `a` occurences with `b` in given content string `abcd` and save result to `foo_replaced.js`
97137

98138
##### API
99139
```javascript
100-
require('FRS-replace').sync({
140+
const result = require('FRS-replace').sync({
101141
content : 'abcd',
102142
regex : new RegExp('a', 'g'),
103143
replacement : 'b',
104144
output : 'foo_replaced.js'
105145
})
106146
```
107147

108-
##### CLI
148+
###### CLI
109149
```bash
110150
FRS-replace a b --content abcd -o foo_replaced.js
111151
```
112152

113-
Replaces all `a` occurences with `b` from piped stream and save it to output file:
153+
#### 4. Replace all `a` occurences with `b` from piped stream and save it to output file:
114154

115-
##### CLI
155+
###### CLI
116156
```bash
117-
<read-file> | FRS-replace a b > <output file path>
157+
<read-file> | FRS-replace a b > <output-file-path>
118158
```
119159

120-
Replaces all `a` occurences with `b` from piped stream and pass it through `stdout` stream to next command
160+
#### 5. Replaces all `a` occurences with `b` from piped stream and pass it through `stdout` stream to next command
121161

122-
##### CLI
162+
###### CLI
123163
```bash
124-
<read-file> | FRS-replace a b | <next command>
164+
<read-file> | FRS-replace a b | <next-command>
125165
```
126166

127-
Both pipe & options styles can be mixed together, here - getting input from `i` argument and passing output down the stream to next command
167+
#### 6. Both pipe & options styles can be mixed together, here - getting input from `i` argument and passing output down the stream to next command
128168

129-
##### CLI
169+
###### CLI
130170
```bash
131-
FRS-replace a b -i foo.js | <next command>
171+
FRS-replace a b -i foo.js | <next-command>
132172
```
133-
134-

0 commit comments

Comments
 (0)