1 | # java-properties
|
2 |
|
3 | ![travis](https://travis-ci.org/mattdsteele/java-properties.svg)
|
4 |
|
5 | Read Java .properties files. Supports adding dynamically some files and array key value (same key multiple times)
|
6 |
|
7 | ## Getting Started
|
8 |
|
9 | Install the module with: `npm install java-properties`
|
10 |
|
11 | ## Documentation
|
12 |
|
13 | ```javascript
|
14 | var properties = require('java-properties');
|
15 |
|
16 | // Reference a properties file
|
17 | var values = properties.of('values.properties');
|
18 |
|
19 | //Read a value from the properties file
|
20 | values.get('a.key'); //returns value of a.key
|
21 |
|
22 | //Add an additional file's properties
|
23 | values.add('anotherfile.properties');
|
24 |
|
25 | //Clear out all values
|
26 | values.reset();
|
27 | ...
|
28 | // returns the value of a.key of 'defaultValue' if key is not found
|
29 | values.get('a.key', 'defaultValue');
|
30 | ...
|
31 | // returns the value of the a.int.key as an int or 18
|
32 | values.getInt('a.int.key', 18);
|
33 | ...
|
34 | // returns the value of the a.float.key as a float or 18.23
|
35 | values.getFloat('a.float.key', 18.23);
|
36 | ...
|
37 | // returns the value of the a.bool.key as an boolean. Parse true or false with any case or 0 or 1
|
38 | values.getBoolean('a.bool.key', true);
|
39 | ...
|
40 | // returns all the keys
|
41 | values.getKeys();
|
42 | ...
|
43 | // adds another file the properties list
|
44 | values.addFile('anotherFile.properties');
|
45 | ...
|
46 | // empty the keys previously loaded
|
47 | values.reset();
|
48 | ...
|
49 | [ -- .properties file
|
50 | an.array.key=value1
|
51 | an.array.key=value2
|
52 | ]
|
53 | values.get('an.array.key'); // returns [value1, value2]
|
54 |
|
55 | // Multiple contexts
|
56 | var myFile = new PropertiesFile(
|
57 | 'example.properties',
|
58 | 'arrayExample.properties');
|
59 | myFile.get('arrayKey');
|
60 |
|
61 | var myOtherFile = new PropertiesFile();
|
62 | myOtherFile.addFile('example.properties');
|
63 | myOtherFile.addFile('example2.properties');
|
64 | ```
|
65 |
|
66 | ## Contributing
|
67 |
|
68 | In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.
|
69 |
|
70 | ## Release History
|
71 |
|
72 | - 0.1.0 Initial commit
|
73 | - 0.1.5 Support empty strings
|
74 | - 0.1.6 New API: `getKeys`
|
75 | - 0.1.7 New APIs: `addFile` and `reset`
|
76 | - 0.1.8 Add array key (the same key many time in files)
|
77 | - 0.2.0 Wrap features into a class to be able to have multiple running contexts
|
78 | - 0.2.1 Add default value to get method. Add getInt and getFloat to get an integer or float value
|
79 | - 0.2.2 Add getBoolean method to get a value as a boolean. Accepted values are true, TRUE, false, FALSE, 0, 1
|
80 | - 0.2.3 Add getMatchingKeys method
|
81 | - 0.2.4 Allow multi-line properties
|
82 | - 0.2.5 Refactorings, no new features
|
83 | - 0.2.6 FIX interpolation when a property is multivalued
|
84 | - 0.2.7 Get only last value for int and boolean in case of multivalued attribute
|
85 | - 0.2.8 FIX unicode \uxxxx char decoding
|
86 | - 0.2.9 Allow multiple double quotation marks
|
87 | - 0.2.10 fix bug with escaped : & = (thanks @Drapegnik)
|
88 | - 1.0.0 Rewrite as Typescript. Support Node 6+ only
|
89 |
|
90 | ## License
|
91 |
|
92 | Licensed under the MIT license.
|