Gathering detailed insights and metrics for utils-fs-read-properties
Gathering detailed insights and metrics for utils-fs-read-properties
Gathering detailed insights and metrics for utils-fs-read-properties
Gathering detailed insights and metrics for utils-fs-read-properties
npm install utils-fs-read-properties
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
1 Stars
3 Commits
3 Watching
1 Branches
1 Contributors
Updated on 22 Oct 2015
JavaScript (76.82%)
Makefile (23.18%)
Cumulative downloads
Total Downloads
Last day
-29%
103
Compared to previous day
Last week
-11.7%
508
Compared to previous week
Last month
-6.2%
2,304
Compared to previous month
Last year
-25.3%
28,864
Compared to previous year
Reads the entire contents of a .properties file.
1$ npm install utils-fs-read-properties
1var read = require( 'utils-fs-read-properties' );
Reads the entire contents of a .properties file.
1read( '/path/to/data.properties', onData ); 2 3function onData( error, data ) { 4 if ( error ) { 5 console.error( error ); 6 } else { 7 console.log( data ); 8 } 9}
The function
accepts the same options as properties#parse
, except path
is always true
.
1var opts = { 2 'sections': true 3}; 4 5read( '/path/to/data.properties', opts, onData ); 6 7function onData( error, data ) { 8 if ( error ) { 9 console.error( error ); 10 } else { 11 console.log( data ); 12 } 13}
Synchronously reads the contents of an entire .properties file.
1var out = read.sync( '/path/to/data.properties' ); 2if ( out instanceof Error ) { 3 throw out; 4} 5console.log( out );
The function
accepts the same options as fs.readFileSync()
as well as utils-properties-parse options.
1var path = require( 'path' ), 2 read = require( 'utils-fs-read-properties' ); 3 4var file = path.join( __dirname, 'config.properties' ); 5 6/** 7* .properties reviver. 8* 9* @param {String} key - .properties key 10* @param {String} value - .properties value 11* @param {String} section - .properties section 12* @returns {*} revived value 13*/ 14function reviver( key, value ) { 15 /* jshint validthis:true */ 16 var vals; 17 18 // Do not split section lines... 19 if ( this.isSection ) { 20 return this.assert(); 21 } 22 // Split comma-delimited strings... 23 if ( typeof value === 'string' ){ 24 vals = value.split( ',' ); 25 return ( vals.length === 1 ) ? value : vals; 26 } 27 // Do not split the rest of the lines: 28 return this.assert(); 29} 30 31// Sync: 32var data = read.sync( file, { 33 'sections': true, 34 'namespaces': true, 35 'reviver': reviver 36}); 37// returns <object> 38 39console.log( data instanceof Error ); 40// returns false 41 42data = read.sync( 'beepboop' ); 43// returns <error> 44 45console.log( data instanceof Error ); 46// returns true 47 48 49// Async: 50read( file, { 51 'sections': true, 52 'namespaces': true, 53 'reviver': reviver 54}, onRead ); 55read( 'beepboop', onRead ); 56 57function onRead( error, config ) { 58 if ( error ) { 59 if ( error.code === 'ENOENT' ) { 60 console.error( '.properties file does not exist.' ); 61 } else { 62 throw error; 63 } 64 } else { 65 console.log( 'Port: %s.', config.server.port ); 66 } 67}
To run the example code from the top-level application directory,
1$ node ./examples/index.js
Unit tests use the Mocha test framework with Chai assertions. To run the tests, execute the following command in the top-level application directory:
1$ make test
All new feature development should have corresponding unit tests to validate correct functionality.
This repository uses Istanbul as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:
1$ make test-cov
Istanbul creates a ./reports/coverage
directory. To access an HTML version of the report,
1$ make view-cov
Copyright © 2015. Athan Reines.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/3 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Score
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 More