Skip to content

Commit e9ff15b

Browse files
committed
Add examples to documentation
1 parent beb6316 commit e9ff15b

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ Parses a .properties string, constructing a corresponding JavaScript object.
6060
| --- | --- | --- |
6161
| str | <code>String</code> | The string to parse as .properties |
6262

63+
**Example**
64+
```js
65+
const props = javaProps.parse('foo=Hello\nbar=World');
66+
console.log(props.foo + ' ' + props.bar);
67+
// "Hello World"
68+
```
6369
<a name="javaProps.parseFile"></a>
6470

6571
#### javaProps.parseFile(path, [encoding]) ⇒ <code>Promise.&lt;Object&gt;</code>
@@ -71,6 +77,28 @@ Parses a .properties file, constructing a corresponding JavaScript object.
7177
| --- | --- | --- | --- |
7278
| path | <code>String</code> \| <code>Buffer</code> \| <code>URL</code> \| <code>number</code> | | Filename or file descriptor |
7379
| [encoding] | <code>String</code> | <code>utf8</code> | File encoding |
80+
81+
**Example**
82+
```js
83+
javaProps.parseFile('./foobar.properties').then((props) => {
84+
console.log(props.foo + ' ' + props.bar);
85+
// "Hello World"
86+
}).catch((err) => {
87+
console.error(err);
88+
});
89+
```
90+
*- or with async/await -*
91+
```js
92+
async function fct() {
93+
try {
94+
const props = await javaProps.parseFile('./foobar.properties');
95+
console.log(props.foo + ' ' + props.bar);
96+
// "Hello World"
97+
} catch (err) {
98+
console.error(err);
99+
}
100+
}
101+
```
74102
<!-- jsdoc2md end -->
75103

76104
## Building

doc/documentation.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ const javaProps = {
88
*
99
* @param {String} str The string to parse as .properties
1010
* @return {Object} The {@link Object} corresponding to the given string
11+
* @example
12+
* const props = javaProps.parse('foo=Hello\nbar=World');
13+
* console.log(props.foo + ' ' + props.bar);
14+
* // "Hello World"
1115
*/
1216
parse: function (str) {
1317
},
@@ -18,6 +22,27 @@ const javaProps = {
1822
* @param {String | Buffer | URL | number} path Filename or file descriptor
1923
* @param {String} [encoding=utf8] File encoding
2024
* @return {Promise<Object>} The {@link Object} corresponding to the given string
25+
* @example
26+
* ```js
27+
* javaProps.parseFile('./foobar.properties').then((props) => {
28+
* console.log(props.foo + ' ' + props.bar);
29+
* // "Hello World"
30+
* }).catch((err) => {
31+
* console.error(err);
32+
* });
33+
* ```
34+
* *- or with async/await -*
35+
* ```js
36+
* async function fct() {
37+
* try {
38+
* const props = await javaProps.parseFile('./foobar.properties');
39+
* console.log(props.foo + ' ' + props.bar);
40+
* // "Hello World"
41+
* } catch (err) {
42+
* console.error(err);
43+
* }
44+
* }
45+
* ```
2146
*/
2247
parseFile: function (path, encoding) {
2348
},

0 commit comments

Comments
 (0)