Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

java-props

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

java-props

Read Java .properties files (using the same specification), without useless additional features.

  • 2.1.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3K
decreased by-7.39%
Maintainers
1
Weekly downloads
 
Created
Source

java-props · Build Status codecov npm version

Read/Parse Java .properties files (using the same specification) in Javascript / Node.js.

Note for TypeScript users: This module build and provide its TypeScript declarations files (.d.ts).

Getting Started

Node.js · Install the module with:

npm i --save java-props

Quick Example

# file.properties
a = Hello World
b : Node.js\u00AE
c value
d=foo\
  bar
const javaProps = require('java-props');

javaProps.parseFile('./file.properties').then((props) => {
    console.log(props);
    // { a: 'Hello World', b: 'Node.js®', c: 'value', d: 'foobar' }
}).catch((err) => {
    console.error(err)
});

Documentation

javaProps

Example

const javaProps = require('java-props');

javaProps.parse(str) ⇒ Object

Parses a .properties string, constructing a corresponding JavaScript object.

Returns: Object - The Object corresponding to the given string

ParamTypeDescription
strStringThe string to parse as .properties

Example

const props = javaProps.parse('foo=Hello\nbar=World');
console.log(props.foo + ' ' + props.bar);
// "Hello World"

javaProps.parseFile(path, [encoding]) ⇒ Promise.<Object>

Parses a .properties file, constructing a corresponding JavaScript object.

Returns: Promise.<Object> - The Object corresponding to the given string

ParamTypeDefaultDescription
pathString | Buffer | URL | numberFilename or file descriptor
[encoding]Stringutf8File encoding

Example

javaProps.parseFile('./foobar.properties').then((props) => {
    console.log(props.foo + ' ' + props.bar);
    // "Hello World"
}).catch((err) => {
    console.error(err);
});

- or with async/await -

async function fct() {
    try {
        const props = await javaProps.parseFile('./foobar.properties');
        console.log(props.foo + ' ' + props.bar);
        // "Hello World"
    } catch (err) {
        console.error(err);
    }
}

javaProps.stringify(props) ⇒ String

Convert a JavaScript object to the corresponding .properties string.

Returns: String - The .properties string corresponding to the given JavaScript object

ParamTypeDescription
propsObjectThe JavaScript object to convert

Example

const str = javaProps.stringify({'foo': 'Hello', 'bar': 'World'});
console.log(str);
// "foo: Hello\nbar: World\n"

Building

This project uses TypeScript. To create javascript sources run:

npm run build

To generate the documentation, edit documentation.js then run:

# npm install -g jsdoc-to-markdown
jsdoc2md --partial doc/scope.hbs --files doc/documentation.js --heading-depth 3 | xclip -selection c

and copy the result inside this README.

Testing

Run the unit tests (no need to run build before, they use the typescript files):

npm run test

Contributing

Contributions are welcome. Unfortunately there is no documentation on the codestyle yet, so look at the existing sources and do the same.

The goal is to keep a simple project without unnecessary (non essential) features. Don't hesitate to open an issue before to discuss about your idea.

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

See also the list of contributors who participated in this project.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Keywords

FAQs

Package last updated on 18 Jul 2020

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc