Skip to content

Commit 4e909ae

Browse files
added pipeline and improved
1 parent ce94be2 commit 4e909ae

12 files changed

Lines changed: 2757 additions & 2060 deletions

File tree

.github/workflows/ci-cd.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
branches: ["main"]
8+
9+
env:
10+
CI: false
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
environment:
16+
name: github-pages
17+
url: ${{ steps.deployment.outputs.page_url }}
18+
19+
permissions:
20+
contents: "read"
21+
id-token: "write"
22+
pages: "write"
23+
actions: "write"
24+
checks: "write"
25+
deployments: "write"
26+
strategy:
27+
matrix:
28+
node-version: [24]
29+
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
30+
31+
steps:
32+
- uses: actions/checkout@v6
33+
- name: Install pnpm
34+
uses: pnpm/action-setup@v4
35+
with:
36+
version: 10
37+
- name: Use Node.js ${{ matrix.node-version }}
38+
uses: actions/setup-node@v6
39+
with:
40+
node-version: ${{ matrix.node-version }}
41+
- name: Install dependencies
42+
# Using npm ci is generally faster than running npm i because it caches dependencies
43+
run: |
44+
pnpm install
45+
- name: Test
46+
run: pnpm test
47+
48+
- name: Build the app
49+
run: |
50+
pnpm run build
51+
52+
- name: Stage deploy directory
53+
run: |
54+
mkdir -p deploy
55+
cp index.html deploy/
56+
cp -r dist deploy/
57+
58+
- name: Setup Pages
59+
uses: actions/configure-pages@v5
60+
- name: Upload artifact
61+
uses: actions/upload-pages-artifact@v3
62+
with:
63+
path: "deploy/"
64+
- name: Deploy to GitHub Pages
65+
id: deployment
66+
uses: actions/deploy-pages@v4
67+
env:
68+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Release
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
release:
9+
runs-on: ubuntu-latest
10+
11+
permissions:
12+
contents: read
13+
id-token: write # required for npm provenance
14+
15+
steps:
16+
- uses: actions/checkout@v6
17+
18+
- name: Install pnpm
19+
uses: pnpm/action-setup@v4
20+
with:
21+
version: 10
22+
23+
- name: Use Node.js
24+
uses: actions/setup-node@v6
25+
with:
26+
node-version: 24
27+
registry-url: https://registry.npmjs.org
28+
29+
- name: Install dependencies
30+
run: pnpm install
31+
32+
- name: Test
33+
run: pnpm test
34+
35+
- name: Build
36+
run: pnpm run build
37+
38+
- name: Publish to npm
39+
run: npm publish

.prettierrc.json

Lines changed: 0 additions & 8 deletions
This file was deleted.

README.md

Lines changed: 74 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,100 @@
1-
Convert Java `.properties` files to JSON (using JavaScript).
1+
Convert Java `.properties` files to JSON (using JavaScript/TypeScript).
22

3-
supports array creation.
3+
Supports nested objects, arrays, Unicode escape sequences, and type coercion.
44

5-
The function `propertiesToJSON` takes a string and returns
6-
a JavaScript object.
5+
## Install
76

8-
### use
7+
```sh
8+
# pnpm
9+
pnpm add js-properties-to-json
910

11+
# npm
12+
npm i js-properties-to-json
1013
```
11-
propertiesToJSON(data, {
12-
jsonAsString: false,
13-
convertToJsonTree : false,
14-
parseNumber:false,
15-
parseBooleanNullUndefined:false,
16-
});
14+
15+
## Usage
16+
17+
```ts
18+
import propertiesToJSON from 'js-properties-to-json';
19+
// or CommonJS:
20+
// const propertiesToJSON = require('js-properties-to-json');
21+
22+
const result = propertiesToJSON(`
23+
# comment
24+
server.host=localhost
25+
server.port=8080
26+
`);
27+
// { 'server.host': 'localhost', 'server.port': '8080' }
1728
```
1829

19-
### Read a local file in `node`:
30+
### Read a local file in Node.js
2031

2132
```js
22-
const fs = require('fs');
23-
const path = require('path');
24-
const filePath = path.join(__dirname, 'sample.properties');
25-
const propertiesToJSON = require('properties-to-json');;
26-
27-
fs.readFile(filePath, { encoding: 'utf-8' }, (err, data) => {
28-
if (!err) {
29-
console.log(propertiesToJSON(data));
30-
}
31-
});
33+
import fs from 'fs';
34+
import propertiesToJSON from 'js-properties-to-json';
35+
36+
const data = fs.readFileSync('app.properties', 'utf-8');
37+
console.log(propertiesToJSON(data, { convertToJsonTree: true, parseNumber: true }));
3238
```
3339

34-
### Read a remote file in the browser:
40+
### Read a remote file in the browser
3541

3642
```js
3743
import propertiesToJSON from 'js-properties-to-json';
3844

39-
const propsFile = new Request('<link-to-properties-file>');
40-
41-
const props = fetch(propsFile)
42-
.then((response) => {
43-
return response.text();
44-
})
45-
.then((text) => {
46-
const propsText = propertiesToJSON(text);
47-
console.log(propsText);
48-
return propsText;
49-
});
45+
const text = await fetch('/app.properties').then((r) => r.text());
46+
console.log(propertiesToJSON(text));
5047
```
5148

52-
### Available options
49+
## Options
50+
51+
```ts
52+
import propertiesToJSON, { type Options } from 'js-properties-to-json';
53+
```
54+
55+
| Option | Default | Description |
56+
| :-------------------------: | :-----: | :------------------------------------------------------------------------------------------: |
57+
| `jsonAsString` | `false` | Return the result as a JSON string instead of an object |
58+
| `convertToJsonTree` | `false` | Convert dotted keys into nested objects — e.g. `a.b=c``{ a: { b: "c" } }` |
59+
| `parseNumber` | `false` | Coerce numeric strings to numbers — e.g. `port=8080``{ port: 8080 }` |
60+
| `parseBooleanNullUndefined` | `false` | Coerce `"true"`, `"false"`, `"null"`, `"undefined"` to their JS equivalents (case-sensitive) |
61+
62+
## Examples
5363

54-
| Option | Default&#160;value | Description |
55-
| :-----------------------: | :----------------: | :------------------------------------------------------------------------------------------: |
56-
| jsonAsString | false | return json as a string |
57-
| convertToJsonTree | false | convert properties to json tree eg `a.b=c` to `{ "a.b": c }` if false or `{ "a": {"b": c} }` |
58-
| parseNumber | false | parse value to number e.g - `a=1` to `{ a: "1" }` or `{ a: 1 }` |
59-
| parseBooleanNullUndefined | false | parse string value of `null`, `true`, `false`, `undefined` |
64+
| Properties | JSON |
65+
| ------------------ | ---------------------------------- |
66+
| `a=b` | `{ "a": "b" }` |
67+
| `a:b` | `{ "a": "b" }` |
68+
| `a = b` | `{ "a": "b" }` |
69+
| `a[0]=x` | `{ "a": ["x"] }` |
70+
| `a[1][1]=b` | `{ "a": [null, [null, "b"]] }` |
71+
| `a.b.c=d` | `{ "a": { "b": { "c": "d" } } }` (requires `convertToJsonTree`) |
72+
| `k=\u00e9` | `{ "k": "é" }` |
73+
| `k=hello\tworld` | `{ "k": "hello\tworld" }` |
6074

61-
### Examples
75+
## Supported escape sequences
6276

63-
| Properties | JSON |
64-
| ----------- | ---------------------------------- |
65-
| `a=b` | `{ "a": "b" }` |
66-
| `a[1][1]=b` | `{ "a": [ null, [ null, "b" ] ] }` |
77+
| Sequence | Result |
78+
| ------------- | ----------------------- |
79+
| `\uXXXX` | Unicode character (hex) |
80+
| `\t` | Tab |
81+
| `\n` | Newline |
82+
| `\r` | Carriage return |
83+
| `\f` | Form feed |
84+
| `\\` | Literal backslash |
85+
| `\=`, `\:` | Literal `=` or `:` in a key |
6786

68-
### How do I get it?
87+
## Limitations
6988

70-
1. `npm i js-properties-to-json`
89+
- Whitespace-only key separators (e.g. `key value`) are not supported — use `=` or `:`.
90+
- Inline comments (e.g. `key=value # comment`) are not supported; the `# comment` becomes part of the value.
91+
- `parseBooleanNullUndefined` is case-sensitive: `"True"` stays as a string.
7192

72-
### online converter
93+
## Online converter
7394

74-
[link](https://mehimanshupatil.github.io/propertiesToJSON/)
95+
[https://mehimanshupatil.github.io/propertiesToJSON/](https://mehimanshupatil.github.io/propertiesToJSON/)
7596

76-
### inspiration
97+
## Inspiration
7798

78-
[https://github.com/ryanpcmcquen/propertiesToJSON](https://github.com/ryanpcmcquen/propertiesToJSON)
79-
[https://github.com/jeanpaulattard/json-to-properties](https://github.com/jeanpaulattard/json-to-properties)
99+
- [ryanpcmcquen/propertiesToJSON](https://github.com/ryanpcmcquen/propertiesToJSON)
100+
- [jeanpaulattard/json-to-properties](https://github.com/jeanpaulattard/json-to-properties)

0 commit comments

Comments
 (0)