Skip to content

Commit aff7d62

Browse files
committed
Add stringify documentation
1 parent 9e3a8bb commit aff7d62

2 files changed

Lines changed: 36 additions & 7 deletions

File tree

README.md

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,30 +37,29 @@ javaProps.parseFile('./file.properties').then((props) => {
3737
## Documentation
3838

3939
<!-- jsdoc2md start -->
40-
<a name="javaProps"></a>
41-
4240
### javaProps
43-
**Example**
41+
**Example**
4442
```js
4543
const javaProps = require('java-props');
4644
```
4745

4846
* [javaProps](#javaProps)
4947
* [.parse(str)](#javaProps.parse) ⇒ <code>Object</code>
5048
* [.parseFile(path, [encoding])](#javaProps.parseFile) ⇒ <code>Promise.&lt;Object&gt;</code>
49+
* [.stringify(props)](#javaProps.stringify) ⇒ <code>String</code>
5150

5251
<a name="javaProps.parse"></a>
5352

5453
#### javaProps.parse(str) ⇒ <code>Object</code>
5554
Parses a .properties string, constructing a corresponding JavaScript object.
5655

57-
**Returns**: <code>Object</code> - The [Object](Object) corresponding to the given string
56+
**Returns**: <code>Object</code> - The [Object](Object) corresponding to the given string
5857

5958
| Param | Type | Description |
6059
| --- | --- | --- |
6160
| str | <code>String</code> | The string to parse as .properties |
6261

63-
**Example**
62+
**Example**
6463
```js
6564
const props = javaProps.parse('foo=Hello\nbar=World');
6665
console.log(props.foo + ' ' + props.bar);
@@ -71,14 +70,14 @@ console.log(props.foo + ' ' + props.bar);
7170
#### javaProps.parseFile(path, [encoding]) ⇒ <code>Promise.&lt;Object&gt;</code>
7271
Parses a .properties file, constructing a corresponding JavaScript object.
7372

74-
**Returns**: <code>Promise.&lt;Object&gt;</code> - The [Object](Object) corresponding to the given string
73+
**Returns**: <code>Promise.&lt;Object&gt;</code> - The [Object](Object) corresponding to the given string
7574

7675
| Param | Type | Default | Description |
7776
| --- | --- | --- | --- |
7877
| path | <code>String</code> \| <code>Buffer</code> \| <code>URL</code> \| <code>number</code> | | Filename or file descriptor |
7978
| [encoding] | <code>String</code> | <code>utf8</code> | File encoding |
8079

81-
**Example**
80+
**Example**
8281
```js
8382
javaProps.parseFile('./foobar.properties').then((props) => {
8483
console.log(props.foo + ' ' + props.bar);
@@ -99,6 +98,23 @@ async function fct() {
9998
}
10099
}
101100
```
101+
<a name="javaProps.stringify"></a>
102+
103+
#### javaProps.stringify(props) ⇒ <code>String</code>
104+
Convert a JavaScript object to the corresponding .properties string.
105+
106+
**Returns**: <code>String</code> - The .properties string corresponding to the given JavaScript object
107+
108+
| Param | Type | Description |
109+
| --- | --- | --- |
110+
| props | <code>Object</code> | The JavaScript object to convert |
111+
112+
**Example**
113+
```js
114+
const str = javaProps.stringify({'foo': 'Hello', 'bar': 'World'});
115+
console.log(str);
116+
// "foo: Hello\nbar: World\n"
117+
```
102118
<!-- jsdoc2md end -->
103119

104120
## Building

doc/documentation.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,17 @@ const javaProps = {
4646
*/
4747
parseFile: function (path, encoding) {
4848
},
49+
50+
/**
51+
* Convert a JavaScript object to the corresponding .properties string.
52+
*
53+
* @param {Object} props The JavaScript object to convert
54+
* @return {String} The .properties string corresponding to the given JavaScript object
55+
* @example
56+
* const str = javaProps.stringify({'foo': 'Hello', 'bar': 'World'});
57+
* console.log(str);
58+
* // "foo: Hello\nbar: World\n"
59+
*/
60+
stringify: function (props) {
61+
},
4962
};

0 commit comments

Comments
 (0)