5
5
[ ![ Downloads] [ downloads-badge ]] [ downloads ]
6
6
[ ![ Size] [ size-badge ]] [ size ]
7
7
8
- Transform a “database” / simple (word, phrase) list from plain-text to
9
- JSON.
8
+ Transform a “database” / basic (word, phrase) list from plain text to JSON.
10
9
11
- ## Installation
10
+ ## Install
12
11
13
12
[ npm] [ ] :
14
13
15
- ``` bash
14
+ ``` sh
16
15
npm install plain-text-data-to-json
17
16
```
18
17
19
- ## Usage
18
+ ## Use
20
19
21
20
``` js
22
21
var fs = require (' fs' )
@@ -33,8 +32,9 @@ fs.writeFileSync('output.json', JSON.stringify(data, null, 2) + '\n')
33
32
34
33
### ` toJSON(value[, options]) `
35
34
36
- Transforms the given value (string) to JSON. Don’t like the default
37
- comment and property-value pair delimiters? Specify your own:
35
+ Transforms the given value (string) to JSON.
36
+ Don’t like the default comment and property-value pair delimiters?
37
+ Specify your own:
38
38
39
39
##### ` options `
40
40
@@ -45,34 +45,35 @@ Character to use for line-comments, `false` turns off comments (`string` or
45
45
46
46
###### ` options.delimiter `
47
47
48
- Character to use as delimiter between property-value pairs (` string ` ,
49
- default: ` ':' ` )
48
+ Character to use as delimiter between property-value pairs (` string ` , default:
49
+ ` ':' ` )
50
50
51
51
###### ` options.forgiving `
52
52
53
- How relaxed to be (` string ` or ` boolean ` , default: ` false ` ). When ` true ` ,
54
- doesn’t throw for duplicate keys. When ` "fix" ` , doesn’t throw for
55
- property-value pairs and overwrites (see [ errors] [ ] ).
53
+ How relaxed to be (` 'fix' ` or ` boolean ` , default: ` false ` ).
54
+ When ` true ` , doesn’t throw for duplicate keys.
55
+ When ` 'fix' ` , doesn’t throw for property-value pairs and overwrites (see
56
+ [ errors] [ ] ).
56
57
57
58
###### ` options.log `
58
59
59
60
Whether to log when ` forgiving ` ignores an error (` boolean ` , default: ` true ` ).
60
61
61
62
## Why
62
63
63
- I found myself rewriting a simple transformation over and over. This
64
- (verbosely named) project fixes that. It might not be useful, or too
65
- simple for others, but suites my use cases.
64
+ I found myself rewriting a simple transformation over and over.
65
+ This (verbosely named) project fixes that.
66
+ It might not be useful, or too simple for others, but suites my use cases.
66
67
67
- ## “Plain- text”
68
+ ## “Plain text”
68
69
69
- The term plain- text might be confusing. It’s actually more of some
70
- (sparingly specified) standard.
70
+ The term plain text might be confusing.
71
+ It’s actually more of some (sparingly specified) standard.
71
72
72
73
### Comments
73
74
74
- Use a percentage sign (by default) to specify a comment. The comment
75
- will last until the end of line.
75
+ Use a percentage sign (by default) to specify a comment.
76
+ The comment will last until the end of line.
76
77
77
78
``` txt
78
79
% This is a completely commented line.
@@ -81,11 +82,11 @@ unicorn % This is a partially commented line.
81
82
82
83
Yields:
83
84
84
- ``` json
85
- [" unicorn" ]
85
+ ``` js
86
+ [' unicorn' ]
86
87
```
87
88
88
- ### White Space
89
+ ### Whitespace
89
90
90
91
Initial or final white space (` \s ` ) is trimmed from values.
91
92
@@ -95,14 +96,14 @@ Initial or final white space (`\s`) is trimmed from values.
95
96
96
97
Yields:
97
98
98
- ``` json
99
- [" unicorn" ]
99
+ ``` js
100
+ [' unicorn' ]
100
101
```
101
102
102
103
### Empty lines
103
104
104
- Empty lines will be striped. This includes blank (white space only)
105
- lines.
105
+ Empty lines are striped.
106
+ This includes blank (whitespace only) lines.
106
107
107
108
``` txt
108
109
%%% this file contains a value. %%%
@@ -112,8 +113,8 @@ unicorn
112
113
113
114
Yields:
114
115
115
- ``` json
116
- [" unicorn" ]
116
+ ``` js
117
+ [' unicorn' ]
117
118
```
118
119
119
120
### Property-value pairs
@@ -126,8 +127,8 @@ unicorn : magic creature
126
127
127
128
Yields:
128
129
129
- ``` json
130
- {" unicorn" : " magic creature" }
130
+ ``` js
131
+ {unicorn: ' magic creature' }
131
132
```
132
133
133
134
### Values
@@ -151,8 +152,8 @@ Some errors are thrown when malformed “plain-text” is found, such as:
151
152
* When lines both with and without colons exist
152
153
* In arrays, when duplicate values exist (unless ` forgiving: true ` )
153
154
* In objects, when duplicate properties exist (unless ` forgiving: true ` )
154
- * In objects, when duplicate properties with different values exist
155
- (unless ` forgiving: "fix" ` )
155
+ * In objects, when duplicate properties with different values exist (unless
156
+ ` forgiving: "fix" ` )
156
157
157
158
## License
158
159
0 commit comments