What is java-properties?
The java-properties npm package is used for reading, writing, and manipulating Java-style .properties files. These files are commonly used for configuration purposes in Java applications.
What are java-properties's main functionalities?
Reading Properties
This feature allows you to read and load properties from a .properties file into a JavaScript object.
const properties = require('java-properties');
const config = properties.of('config.properties').load();
console.log(config);
Writing Properties
This feature allows you to write a JavaScript object as properties into a .properties file.
const properties = require('java-properties');
const config = { key1: 'value1', key2: 'value2' };
properties.of('config.properties').save(config);
Updating Properties
This feature allows you to update existing properties in a .properties file.
const properties = require('java-properties');
const config = properties.of('config.properties').load();
config.key1 = 'newValue';
properties.of('config.properties').save(config);
Deleting Properties
This feature allows you to delete properties from a .properties file.
const properties = require('java-properties');
const config = properties.of('config.properties').load();
delete config.key1;
properties.of('config.properties').save(config);
Other packages similar to java-properties
properties-reader
The properties-reader package is another tool for reading and manipulating .properties files. It offers similar functionality to java-properties but with a different API design. It allows for easy reading, updating, and saving of properties.
node-properties
The node-properties package provides functionality for parsing and stringifying .properties files. It is similar to java-properties but focuses more on the parsing and stringifying aspects rather than file manipulation.
config
The config package is a more general-purpose configuration management tool that supports multiple file formats, including .properties. It offers a broader range of features for managing application configurations compared to java-properties.
java-properties
Read Java .properties files. Supports adding dynamically some files and array key value (same key multiple times)
Getting Started
Install the module with: npm install java-properties
Documentation
var properties = require('java-properties');
var values = properties.of('values.properties');
values.get('a.key');
values.add('anotherfile.properties');
values.reset();
...
values.get('a.key', 'defaultValue');
...
values.getInt('a.int.key', 18);
...
values.getFloat('a.float.key', 18.23);
...
values.getBoolean('a.bool.key', true);
...
values.getKeys();
...
values.addFile('anotherFile.properties');
...
values.reset();
...
[ -- .properties file
an.array.key=value1
an.array.key=value2
]
values.get('an.array.key');
var myFile = new PropertiesFile(
'example.properties',
'arrayExample.properties');
myFile.get('arrayKey');
var myOtherFile = new PropertiesFile();
myOtherFile.addFile('example.properties');
myOtherFile.addFile('example2.properties');
Contributing
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 using Grunt.
Release History
- 0.1.0 Initial commit
- 0.1.5 Support empty strings
- 0.1.6 New API:
getKeys
- 0.1.7 New APIs:
addFile
and reset
- 0.1.8 Add array key (the same key many time in files)
- 0.2.0 Wrap features into a class to be able to have multiple running contexts
- 0.2.1 Add default value to get method. Add getInt and getFloat to get an integer or float value
- 0.2.2 Add getBoolean method to get a value as a boolean. Accepted values are true, TRUE, false, FALSE, 0, 1
- 0.2.3 Add getMatchingKeys method
- 0.2.4 Allow multi-line properties
- 0.2.5 Refactorings, no new features
- 0.2.6 FIX interpolation when a property is multivalued
- 0.2.7 Get only last value for int and boolean in case of multivalued attribute
- 0.2.8 FIX unicode \uxxxx char decoding
- 0.2.9 Allow multiple double quotation marks
- 0.2.10 fix bug with escaped : & = (thanks @Drapegnik)
License
Licensed under the MIT license.