Skip to content

Commit e8de8e9

Browse files
committed
update README.md
1 parent 8f88611 commit e8de8e9

File tree

2 files changed

+63
-64
lines changed

2 files changed

+63
-64
lines changed

README.md

+62-63
Original file line numberDiff line numberDiff line change
@@ -8,30 +8,30 @@ An easy and fast in-memory string builder for Node.js.
88
## Code Example
99

1010
```javascript
11-
const StringBuilder = require('node-stringbuilder');
12-
var sb = new StringBuilder('Hi');
13-
sb.appendLine(',').append('This is a simple example demonstrating how to use this module.');
11+
const StringBuilder = require("node-stringbuilder");
12+
const sb = new StringBuilder("Hi");
13+
sb.appendLine(",").append("This is a simple example demonstrating how to use this module.");
1414
console.log(sb.toString()); // Hi,
1515
// This is a simple example demonstrating how to use this module.
16-
sb.insert('Text can be added into any position of this builder.');
17-
sb.replace(53, 118, 'Or replace the existing text.');
16+
sb.insert("Text can be added into any position of this builder.");
17+
sb.replace(53, 118, "Or replace the existing text.");
1818
console.log(sb.toString()); // Text can be added into any position of this builder.HOr replace the existing text.
19-
sb.deleteCharAt(52).insert(52, ' ');
19+
sb.deleteCharAt(52).insert(52, " ");
2020
console.log(sb.toString()); // Text can be added into any position of this builder. Or replace the existing text.
21-
sb.toLowerCase().replaceAll('text', 'string');
21+
sb.toLowerCase().replaceAll("text", "string");
2222
console.log(sb.toString()); // string can be added into any position of this builder. or replace the existing string.
2323
console.log(sb.clone().reverse().toString()); // .gnirts gnitsixe eht ecalper ro .redliub siht fo noitisop yna otni dedda eb nac gnirts
2424
console.log(sb.toString(0, 19)); // string can be added
2525
console.log(sb.length()); // 86
2626
console.log(sb.count()); // 15
27-
console.log(sb.indexOf('is')); // Uint32Array [ 43, 72 ]
28-
console.log(sb.indexOfSkip('is')); // Uint32Array [ 43, 72 ]
29-
console.log(sb.lastIndexOf('is')); // Uint32Array [ 72, 43 ]
27+
console.log(sb.indexOf("is")); // Uint32Array [ 43, 72 ]
28+
console.log(sb.indexOfSkip("is")); // Uint32Array [ 43, 72 ]
29+
console.log(sb.lastIndexOf("is")); // Uint32Array [ 72, 43 ]
3030
console.log(sb.indexOfRegExp(/is/g)); // { index: [ 43, 72 ], lastIndex: [ 45, 74 ] }
31-
console.log(sb.repeat().indexOf('is')); // Uint32Array [ 43, 72, 129, 158 ]
31+
console.log(sb.repeat().indexOf("is")); // Uint32Array [ 43, 72, 129, 158 ]
3232
sb.substring(11, 37);
3333
console.log(sb.toString()); // be added into any position
34-
console.log(sb.equalsIgnoreCase('be Added into Any position')); // true
34+
console.log(sb.equalsIgnoreCase("be Added into Any position")); // true
3535
console.log(sb.toBuffer()); // UTF-8 encoded
3636
```
3737

@@ -42,7 +42,7 @@ console.log(sb.toBuffer()); // UTF-8 encoded
4242
* Multiple types of data are allowed to input.
4343
* Strings
4444
* Buffers(UTF-8 encoded)
45-
* Instances of this StringBuilder module
45+
* Instances of this `StringBuilder` module
4646
* ReadStream(to read file)
4747
* Numbers, booleans, other objects
4848
* Fast string search algorithm([Boyer-Moore-MagicLen](https://magiclen.org/boyer-moore-magiclen/))
@@ -58,50 +58,50 @@ Import this module by using `require` function.
5858
const StringBuilder = require('node-stringbuilder');
5959
```
6060

61-
Use `new` operator or `from` function to create a StringBuilder instance.
61+
Use `new` operator or `from` function to create a `StringBuilder` instance.
6262

6363
```javascript
64-
var sb1 = new StringBuilder();
65-
// or
66-
var sb2 = StringBuilder.from();
64+
const sb1 = new StringBuilder();
65+
// or
66+
const sb2 = StringBuilder.from();
6767
```
6868

69-
When creating an instance of StringBuilder, you can initialize the text and capacity.
69+
When creating an instance of `StringBuilder`, you can initialize the text and capacity.
7070

7171
```javascript
72-
var sb = StringBuilder.from('First', 4096);
72+
const sb = StringBuilder.from("First", 4096);
7373
```
7474

75-
By default, a block of buffer space used by StringBuilder is 128 characters. The space of the buffer can be expanded or shrinked by blocks.
75+
By default, a block of buffer space used by `StringBuilder` is 128 characters. The space of the buffer can be expanded or shrinked by blocks.
7676

7777
```javascript
7878
// To expand
79-
var newCapacity = 65536;
79+
const newCapacity = 65536;
8080
sb.expandCapacity(newCapacity);
8181
// To shrink
8282
sb.shrinkCapacity();
8383
```
8484

85-
If some text are added into StringBuilder, StringBuilder will check its space. And if the space is too small, it will re-alloc a bigger one automatically. This re-allocation has overheads, if it does this frequently, your program may be slowed down. Therefore, if you can predict the length of your text, please set the capacity when creating a StringBuilder instance.
85+
If some text are added into `StringBuilder`, `StringBuilder` will check its space. And if the space is too small, it will re-alloc a bigger one automatically. This re-allocation has overheads, if it does this frequently, your program may be slowed down. Therefore, if you can predict the length of your text, please set the capacity when creating a `StringBuilder` instance.
8686

8787
### Append
8888

8989
Concat text.
9090

9191
```javascript
92-
sb.append('string').append(123).append(false).append(fs.createReadStream(path));
92+
sb.append("string").append(123).append(false).append(fs.createReadStream(path));
9393
```
9494

9595
Add a new line after append.
9696

9797
```javascript
98-
sb.appendLine('string');
98+
sb.appendLine("string");
9999
```
100100

101101
Append text repeatedly.
102102

103103
```javascript
104-
sb.appendRepeat('string', 3);
104+
sb.appendRepeat("string", 3);
105105
```
106106

107107
Append a file asynchronizely.
@@ -115,29 +115,34 @@ await sb.appendReadStream(fs.createReadStream(path));
115115
Insert text to any position.
116116

117117
```javascript
118-
sb.insert('string'); // To the head.
119-
sb.insert(5, 'string');
118+
sb.insert("string"); // To the head.
119+
sb.insert(5, "string");
120120
```
121121

122122
### Replace
123123

124124
Replace text to the position in a range of index.
125125

126126
```javascript
127-
sb.replace(4, 15, 'string');
127+
sb.replace(4, 15, "string");
128128
```
129129

130130
Replace existing substrings to another.
131131

132132
```javascript
133-
sb.replacePattern('old', 'new');
134-
sb.replacePattern('old', 'new', offset, limit);
133+
sb.replacePattern("old", "new");
134+
sb.replacePattern(
135+
"old",
136+
"new",
137+
offset,
138+
limit
139+
);
135140
```
136141

137142
Replace all existing substrings to another.
138143

139144
```javascript
140-
sb.replaceAll('old', 'new');
145+
sb.replaceAll("old", "new");
141146
```
142147

143148
### Delete
@@ -207,90 +212,90 @@ sb.repeat(1);
207212

208213
### Expand Capacity
209214

210-
Expand the capacity of this StringBuilder.
215+
Expand the capacity of this `StringBuilder`.
211216

212217
```javascript
213-
sb.expandCapacity(4096).append('string');
218+
sb.expandCapacity(4096).append("string");
214219
```
215220

216221
Expand and get the updated capacity,
217222

218223
```javascript
219-
var capacity = sb.expandCapacity(4096, true);
224+
const capacity = sb.expandCapacity(4096, true);
220225
```
221226

222227
### Shrink Capacity
223228

224-
Shrink the capacity of this StringBuilder.
229+
Shrink the capacity of this `StringBuilder`.
225230

226231
```javascript
227-
sb.shrinkCapacity().clone().append('string');
232+
sb.shrinkCapacity().clone().append("string");
228233
```
229234

230235
Shrink and get the updated capacity,
231236

232237
```javascript
233-
var capacity = sb.shrinkCapacity(true);
238+
const capacity = sb.shrinkCapacity(true);
234239
```
235240

236241
### Get Current Text Length
237242

238-
To get the length of this StringBuilder,
243+
To get the length of this `StringBuilder`,
239244

240245
```javascript
241-
var length = sb.length();
246+
const length = sb.length();
242247
```
243248

244249
### Get Current Capacity
245250

246-
To get the length of this StringBuilder,
251+
To get the length of this `StringBuilder`,
247252

248253
```javascript
249-
var capacity = sb.capacity();
254+
const capacity = sb.capacity();
250255
```
251256

252257
### Count the words
253258

254259
To count the words,
255260

256261
```javascript
257-
var words = sb.count();
262+
const words = sb.count();
258263
```
259264

260265
### Build String
261266

262267
Build a string of a specific range of index.
263268

264269
```javascript
265-
var str = sb.toString(4, 10);
270+
const str = sb.toString(4, 10);
266271
```
267272

268273
Build a UTF-8 buffer of a specific range of index.
269274

270275
```javascript
271-
var buffer = sb.toBuffer(4, 10);
276+
const buffer = sb.toBuffer(4, 10);
272277
```
273278

274279
To get the full text,
275280

276281
```javascript
277-
var text = sb.toString();
278-
var buffer = sb.toBuffer();
282+
const text = sb.toString();
283+
const buffer = sb.toBuffer();
279284
```
280285

281286
To get one character at a specific index,
282287

283288
```javascript
284-
var c = sb.charAt(4);
289+
const c = sb.charAt(4);
285290
```
286291

287292
### Search String
288293

289294
Search substrings from the head,
290295

291296
```javascript
292-
var indexArray = sb.indexOf('string');
293-
var indexArray2 = sb.indexOf('string', offset, limit);
297+
const indexArray = sb.indexOf("string");
298+
const indexArray2 = sb.indexOf("string", offset, limit);
294299
```
295300

296301
Search substrings from the head by using RegExp,
@@ -302,38 +307,38 @@ var indexArray = sb.indexOf(/string/g);
302307
Search substrings from the end,
303308

304309
```javascript
305-
var indexArray = sb.lastIndexOf('string');
310+
const indexArray = sb.lastIndexOf("string");
306311
```
307312

308313
### Equals
309314

310315
Determine whether the two strings are the same.
311316

312317
```javascript
313-
var equal = sb.equals('string');
318+
const equal = sb.equals("string");
314319
```
315320

316321
To ignore the case of letters,
317322

318323
```javascript
319-
var equal = sb.equalsIgnoreCase('string');
324+
const equal = sb.equalsIgnoreCase("string");
320325
```
321326

322327
Determine whether it starts or ends with a specific pattern.
323328

324329
```javascript
325-
var start = sb.startsWith('string');
326-
var end = sb.endsWith('string');
330+
const start = sb.startsWith("string");
331+
const end = sb.endsWith("string");
327332
```
328333

329334
RegExp is not supported in `startsWith` and `endsWith` methods.
330335

331336
### Clone
332337

333-
Clone this StringBuilder.
338+
Clone this `StringBuilder`.
334339

335340
```javascript
336-
var newSB = sb.clone();
341+
const newSB = sb.clone();
337342
```
338343

339344
## Tests
@@ -424,10 +429,4 @@ According to the result of benchmark, if you just want to append a few different
424429

425430
## License
426431

427-
[MIT](LICENSE)
428-
429-
## To Do
430-
431-
* More test cases
432-
433-
If you can help me do this as collaborators, I will be grateful.
432+
[MIT](LICENSE)

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-stringbuilder",
3-
"version": "2.2.5",
3+
"version": "2.2.6",
44
"description": "An easy and fast in-memory string builder for Node.js.",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)