Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
java-properties
Advanced tools
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.
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);
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.
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.
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.
Read Java .properties files. Supports adding dynamically some files and array key value (same key multiple times)
Install the module with: npm install java-properties
var properties = require('java-properties');
var values = properties.of('values.properties');
//Read a value from the properties file
values.get('a.key'); //returns value of a.key
//Add an additional file's properties
values.add('anotherfile.properties');
//Clear out all values
values.reset();
...
// returns the value of a.key of 'defaultValue' if key is not found
values.get('a.key', 'defaultValue');
...
// returns the value of the a.int.key as an int or 18
values.getInt('a.int.key', 18);
...
// returns the value of the a.float.key as a float or 18.23
values.getFloat('a.float.key', 18.23);
...
// returns the value of the a.bool.key as an boolean. Parse true or false with any case or 0 or 1
values.getBoolean('a.bool.key', true);
...
// returns all the keys
values.getKeys();
...
// adds another file the properties list
values.addFile('anotherFile.properties');
...
// empty the keys previously loaded
values.reset();
...
[ -- .properties file
an.array.key=value1
an.array.key=value2
]
values.get('an.array.key'); // returns [value1, value2]
// Multiple contexts
var myFile = new PropertiesFile(
'example.properties',
'arrayExample.properties');
myFile.get('arrayKey');
var myOtherFile = new PropertiesFile();
myOtherFile.addFile('example.properties');
myOtherFile.addFile('example2.properties');
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.
getKeys
addFile
and reset
Licensed under the MIT license.
FAQs
Reads and interpolates Java .properties files
The npm package java-properties receives a total of 1,348,435 weekly downloads. As such, java-properties popularity was classified as popular.
We found that java-properties demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.