Skip to content

Commit f2f3de3

Browse files
committed
docs: add constructor and factor field docs.
1 parent f2be7a2 commit f2f3de3

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

src/dynamicBuffer.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ export interface DynamicBufferOptions {
2424
*/
2525
encoding?: BufferEncoding;
2626

27+
/**
28+
* The factor value for buffer resizing. By default, the `resize` method will increase the
29+
* buffer size with the product of the current size and this factor value.
30+
*/
2731
factor?: number;
2832
}
2933

@@ -47,6 +51,9 @@ export class DynamicBuffer {
4751
*/
4852
private readonly DefaultInitialSize: number = 16;
4953

54+
/**
55+
* The default factor value for buffer resizing.
56+
*/
5057
private readonly DefaultResizeFactor: number = 0.75;
5158

5259
/**
@@ -74,14 +81,68 @@ export class DynamicBuffer {
7481
*/
7582
private encoding?: BufferEncoding;
7683

84+
/**
85+
* The factor value for buffer resizing.
86+
*/
7787
private factor: number;
7888

89+
/**
90+
* Create a DynamicBuffer with default settings.
91+
*
92+
* ```js
93+
* const buffer = new DynamicBuffer();
94+
*
95+
* // ...
96+
* ```
97+
*/
7998
constructor();
8099

100+
/**
101+
* Create a DynamicBuffer with the specific settings.
102+
*
103+
* ```js
104+
* const buffer = new DynamicBuffer({ size: 32, factor: 1 });
105+
* // set initial size to 32, and resize factor to 1.
106+
*
107+
* // ...
108+
* ```
109+
*
110+
* @param options Buffer settings.
111+
*/
81112
constructor(options: DynamicBufferOptions);
82113

114+
/**
115+
* Create a DynamicBuffer with the initial data and default settings.
116+
*
117+
* ```js
118+
* const buffer = new DynamicBuffer('Hello world');
119+
*
120+
* console.log(buffer.toString());
121+
* // Hello world
122+
*
123+
* // ...
124+
* ```
125+
*
126+
* @param data Initial data in the buffer.
127+
*/
83128
constructor(data: string);
84129

130+
/**
131+
* Create a DynamicBuffer with initial data and the specific settings.
132+
*
133+
* ```js
134+
* const buffer = new DynamicBuffer('Hello world', { size: 32 });
135+
* // set initial size to 32, and initial data is 'Hello world'.
136+
*
137+
* console.log(buffer.toString());
138+
* // Hello world
139+
*
140+
* // ...
141+
* ```
142+
*
143+
* @param data Initial data in the buffer.
144+
* @param options Buffer settings.
145+
*/
85146
constructor(data: string, options: DynamicBufferOptions);
86147

87148
constructor(

0 commit comments

Comments
 (0)