Installations
npm install properties-reader
Developer
steveukx
Developer Guide
Module System
CommonJS
Min. Node Version
>=14
Typescript Support
No
Node Version
18.17.1
NPM Version
9.6.7
Statistics
77 Stars
111 Commits
33 Forks
5 Watching
11 Branches
6 Contributors
Updated on 04 Sept 2024
Bundle Size
7.67 kB
Minified
2.83 kB
Minified + Gzipped
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
68,600,344
Last day
3.1%
152,956
Compared to previous day
Last week
2.3%
799,377
Compared to previous week
Last month
13%
3,315,913
Compared to previous month
Last year
52.8%
28,975,769
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
Dev Dependencies
3
Properties-Reader
An ini file compatible properties reader for Node.JS
Installation
The easiest installation is through NPM:
npm install properties-reader
API
Read properties from a file:
var propertiesReader = require('properties-reader');
var properties = propertiesReader('/path/to/properties.file');
The properties are then accessible either by fully qualified name, or if the property names are in dot-delimited notation, they can be access as an object:
// fully qualified name
var property = properties.get('some.property.name');
// by object path
var property = properties.path().some.property.name;
To read more than one file, chain calls to the .append()
method:
properties.append('/another.file').append('/yet/another.file');
To read properties from a string, use the .read()
method:
properties.read('some.property = Value \n another.property = Another Value');
To set a single property into the properties object, use .set()
:
properties.set('property.name', 'Property Value');
When reading a .ini
file, sections are created by having a line that contains just a section name in square
brackets. The section name is then prefixed to all property names that follow it until another section name is found
to replace the current section.
# contents of properties file
[main]
some.thing = foo
[blah]
some.thing = bar
// reading these back from the properties reader
properties.get('main.some.thing') == 'foo';
properties.get('blah.some.thing') == 'bar';
// looping through the properties reader
properties.each((key, value) => {
// called for each item in the reader,
// first with key=main.some.thing, value=foo
// next with key=blah.some.thing, value=bar
});
// get all properties at once
expect(properties.getAllProperties()).toEqual({
'main.some.thing': 'foo',
'blah.some.thing': 'bar',
})
Checking for the current number of properties that have been read into the reader:
var propertiesCount = properties.length;
The length is calculated on request, so if accessing this in a loop an efficiency would be achieved by caching the value.
When duplicate names are found in the properties, the first one read will be replaced with the later one.
To get the complete set of properties, either loop through them with the .each((key, value) => {})
iterator or
use the convenience method getAllProperties
to return the complete set of flattened properties.
Saving changes
Once a file has been read and changes made, saving those changes to another file is as simple as running:
1// async/await ES6 2const propertiesReader = require('properties-reader'); 3const props = propertiesReader(filePath, {writer: { saveSections: true }}); 4await props.save(filePath); 5 6// ES5 callback styles 7props.save(filePath, function then(err, data) { ... }); 8 9// ES5 promise style 10props.save(filePath).then(onSaved, onSaveError);
To output the properties without any section headings, set the saveSections
option to false
Data Types
Properties will automatically be converted to their regular data types when they represent true/false or numeric
values. To get the original value without any parsing / type coercion applied, use properties.getRaw('path.to.prop')
.
FAQ / Breaking Changes
Duplicate Section Headings
From version 2.0.0
the default behaviour relating to multiple [section]
blocks with the same name has changed
so combine the items of each same-named section into the one section. This is only visible when saving the items
(via reader.save()
).
To restore the previous behaviour which would allow duplicate [...]
blocks to be created, supply an appender
configuration with the property allowDuplicateSections
set to true
.
1const propertiesReader = require('properties-reader'); 2const props = propertiesReader(filePath, 'utf-8', { allowDuplicateSections: true });
Contributions
If you find bugs or want to change functionality, feel free to fork and pull request.
Stable Version
The latest stable version of the package.
Stable Version
2.3.0
CRITICAL
1
9.8/10
Summary
Properties-Reader before v2.2.0 vulnerable to prototype pollution
Affected Versions
< 2.2.0
Patched Versions
2.2.0
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
8 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/17 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/changesets.yml:1
- Info: topLevel 'contents' permission set to 'read': .github/workflows/ci.yml:10
- Warn: no topLevel permission defined: .github/workflows/no-response.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/changesets.yml:13: update your workflow using https://app.stepsecurity.io/secureworkflow/steveukx/properties/changesets.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/changesets.yml:17: update your workflow using https://app.stepsecurity.io/secureworkflow/steveukx/properties/changesets.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/changesets.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/steveukx/properties/changesets.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/steveukx/properties/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/steveukx/properties/ci.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/no-response.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/steveukx/properties/no-response.yml/main?enable=pin
- Info: 0 out of 4 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 2 third-party GitHubAction dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 19 are checked with a SAST tool
Score
3
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to properties-reader
@types/properties-reader
TypeScript definitions for properties-reader
grunt-properties-reader
Grunt plugin that reads java properties files.
@resource-sentry/reader-properties
Resource Sentry Properties Reader.
@smithy/chunked-blob-reader
[![NPM version](https://img.shields.io/npm/v/@smithy/chunked-blob-reader/latest.svg)](https://www.npmjs.com/package/@smithy/chunked-blob-reader) [![NPM downloads](https://img.shields.io/npm/dm/@smithy/chunked-blob-reader.svg)](https://www.npmjs.com/packag