@@ -20,10 +20,10 @@ npm install js-java-properties
20
20
Parses correctly file contents as a string into lines.
21
21
22
22
``` ts
23
- import properties from ' js-java-properties' ;
23
+ import * as properties from ' js-java-properties'
24
24
25
- const props = properties .parse (' key1=value1\n key2 = value2\n key3: value3' );
26
- console .log (props );
25
+ const props = properties .parse (' key1=value1\n key2 = value2\n key3: value3' )
26
+ console .log (props )
27
27
// { lines: [ 'key1=value1', 'key2 = value2', 'key3: value3' ] }
28
28
```
29
29
@@ -32,13 +32,13 @@ console.log(props);
32
32
Formats property lines into string.
33
33
34
34
``` ts
35
- import properties from ' js-java-properties' ;
35
+ import * as properties from ' js-java-properties'
36
36
37
- const props = properties .empty ();
38
- props .lines .push (' key1=value1' , ' key2 = value2' , ' key3: value3' );
37
+ const props = properties .empty ()
38
+ props .lines .push (' key1=value1' , ' key2 = value2' , ' key3: value3' )
39
39
40
- const output = properties .stringify (props );
41
- console .log (output );
40
+ const output = properties .stringify (props )
41
+ console .log (output )
42
42
// 'key1=value1\nkey2 = value2\nkey3: value3\n'
43
43
```
44
44
@@ -48,7 +48,7 @@ Iterate over every key-value pair. Note that if file contains duplicate keys,
48
48
they are returned here as well.
49
49
50
50
``` ts
51
- import properties from ' js-java-properties' ;
51
+ import * as properties from ' js-java-properties'
52
52
53
53
const props = properties .empty ()
54
54
props .lines .push (' key1=value1' , ' key2 = value2' , ' key3: value3' )
@@ -69,27 +69,27 @@ Use `toObject` or `toMap` methods to convert it into readable object.
69
69
In case there are duplicate keys, last one is returned.
70
70
71
71
``` ts
72
- import properties from ' js-java-properties' ;
72
+ import * as properties from ' js-java-properties'
73
73
74
- const props = properties .empty ();
75
- props .lines .push (' key1=value1' , ' key2 = value2' , ' key3: value3' );
74
+ const props = properties .empty ()
75
+ props .lines .push (' key1=value1' , ' key2 = value2' , ' key3: value3' )
76
76
77
- console .log (properties .get (props , ' key2' ));
77
+ console .log (properties .get (props , ' key2' ))
78
78
// 'value2'
79
79
```
80
80
81
81
### Converting to object or map
82
82
83
83
``` ts
84
- import properties from ' js-java-properties' ;
84
+ import * as properties from ' js-java-properties'
85
85
86
- const props = properties .empty ();
87
- props .lines .push (' key1=value1' , ' key2 = value2' , ' key3: value3' );
86
+ const props = properties .empty ()
87
+ props .lines .push (' key1=value1' , ' key2 = value2' , ' key3: value3' )
88
88
89
- console .log (properties .toObject (props ));
89
+ console .log (properties .toObject (props ))
90
90
// { key1: 'value1', key2: 'value2', key3: 'value3' }
91
91
92
- console .log (properties .toMap (props ));
92
+ console .log (properties .toMap (props ))
93
93
// Map(3) { 'key1' => 'value1', 'key2' => 'value2', 'key3' => 'value3' }
94
94
```
95
95
@@ -101,25 +101,25 @@ Empty string still counts as a value.
101
101
If there are duplicate keys in the list, all but first one are removed.
102
102
103
103
``` ts
104
- import properties from ' js-java-properties' ;
104
+ import * as properties from ' js-java-properties'
105
105
106
- const props = properties .empty ();
107
- props .lines .push (' key1=value1' , ' key2 = value2' , ' key3: value3' );
106
+ const props = properties .empty ()
107
+ props .lines .push (' key1=value1' , ' key2 = value2' , ' key3: value3' )
108
108
109
- properties .set (props , ' key2' , ' new-value' );
110
- console .log (properties .stringify (props ));
109
+ properties .set (props , ' key2' , ' new-value' )
110
+ console .log (properties .stringify (props ))
111
111
// 'key1=value1\nkey2 = new-value\nkey3: value3\n'
112
112
113
- properties .set (props , ' new-key' , ' new-value' );
114
- console .log (properties .stringify (props ));
113
+ properties .set (props , ' new-key' , ' new-value' )
114
+ console .log (properties .stringify (props ))
115
115
// 'key1=value1\nkey2 = new-value\nkey3: value3\nnew-key=new-value\n'
116
116
117
- properties .set (props , ' new-key' , ' new-value' , {separator: ' :' });
118
- console .log (properties .stringify (props ));
117
+ properties .set (props , ' new-key' , ' new-value' , {separator: ' :' })
118
+ console .log (properties .stringify (props ))
119
119
// 'key1=value1\nkey2 = new-value\nkey3: value3\nnew-key:new-value\n'
120
120
121
- properties .set (props , ' key3' , undefined );
122
- console .log (properties .stringify (props ));
121
+ properties .set (props , ' key3' , undefined )
122
+ console .log (properties .stringify (props ))
123
123
// 'key1=value1\nkey2 = new-value\n'
124
124
```
125
125
@@ -128,13 +128,13 @@ console.log(properties.stringify(props));
128
128
Removes given key and value. If there are duplicate keys in the list, all are removed.
129
129
130
130
``` ts
131
- import properties from ' js-java-properties' ;
131
+ import * as properties from ' js-java-properties'
132
132
133
- const props = properties .empty ();
134
- props .lines .push (' key1=value1' , ' key2 = value2' , ' key3: value3' );
133
+ const props = properties .empty ()
134
+ props .lines .push (' key1=value1' , ' key2 = value2' , ' key3: value3' )
135
135
136
- properties .remove (props , ' key2' );
137
- console .log (properties .stringify (props ));
136
+ properties .remove (props , ' key2' )
137
+ console .log (properties .stringify (props ))
138
138
// 'key1=value1\nkey3: value3\n'
139
139
```
140
140
0 commit comments