https://github.com/ryanpcmcquen/propertiestojson
Convert Java .properties files to JSON (using JavaScript).
https://github.com/ryanpcmcquen/propertiestojson
hacktoberfest java javascript json
Last synced: 11 months ago
JSON representation
Convert Java .properties files to JSON (using JavaScript).
- Host: GitHub
- URL: https://github.com/ryanpcmcquen/propertiestojson
- Owner: ryanpcmcquen
- License: mpl-2.0
- Created: 2018-02-05T23:07:05.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2021-10-30T10:46:45.000Z (over 4 years ago)
- Last Synced: 2024-11-03T18:35:11.451Z (over 1 year ago)
- Topics: hacktoberfest, java, javascript, json
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/properties-to-json
- Size: 29.3 KB
- Stars: 13
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Convert Java `.properties` files to JSON (using JavaScript).
The function `propertiesToJSON` takes a string and returns
a JavaScript object.
### Read a local file in `node`:
```js
const fs = require("fs");
const path = require("path");
const filePath = path.join(__dirname, "sample.properties");
const propertiesToJSON = require("properties-to-json");
fs.readFile(filePath, { encoding: "utf-8" }, (err, data) => {
if (!err) {
console.log(propertiesToJSON(data));
}
});
```
### Read a remote file in the browser:
```js
const propertiesToJSON = require("properties-to-json");
const propsFile = new Request(
"https://gitcdn.link/repo/ryanpcmcquen/propertiesToJSON/master/sample.properties"
);
const props = fetch(propsFile)
.then((response) => {
return response.text();
})
.then((text) => {
const propsText = propertiesToJSON(text);
console.log(propsText);
return propsText;
});
```
### How do I get it?
1. `yarn add properties-to-json`
2. Profit.