Skip to content

Commit 2618f7c

Browse files
committed
Use prettier for formatting
1 parent 5536927 commit 2618f7c

8 files changed

Lines changed: 93 additions & 75 deletions

File tree

.prettierrc.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module.exports = {
2+
trailingComma: 'es5',
3+
printWidth: 120,
4+
tabWidth: 4,
5+
semi: true,
6+
singleQuote: true,
7+
bracketSpacing: false,
8+
overrides: [
9+
{
10+
files: ['*.json', '*.yml'],
11+
options: {tabWidth: 2},
12+
},
13+
],
14+
};

.travis.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
language: node_js
22
node_js:
3-
- "16"
4-
- "14"
5-
- "12"
6-
- "10"
7-
- "8"
8-
- "6"
3+
- '16'
4+
- '14'
5+
- '12'
6+
- '10'
7+
- '8'
8+
- '6'
99
install:
10-
- npm install -g yarn
11-
- npm install -g codecov
12-
- yarn install
10+
- npm install -g yarn
11+
- npm install -g codecov
12+
- yarn install
1313
script:
14-
- yarn run test
15-
- '[[ "$(node -v)" == v6.* ]] && echo skip || codecov'
16-
- yarn run build
14+
- yarn run test
15+
- '[[ "$(node -v)" == v6.* ]] && echo skip || codecov'
16+
- yarn run build

README.md

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -44,50 +44,60 @@ javaProps
4444

4545
<!-- jsdoc2md start -->
4646

47-
* [javaProps](#javaProps)
48-
* [.parse(str)](#javaProps.parse) ⇒ <code>Object</code>
49-
* [.parseFile(path, [encoding])](#javaProps.parseFile) ⇒ <code>Promise.&lt;Object&gt;</code>
50-
* [.stringify(props)](#javaProps.stringify) ⇒ <code>String</code>
47+
- [javaProps](#javaProps)
48+
- [.parse(str)](#javaProps.parse) ⇒ <code>Object</code>
49+
- [.parseFile(path, [encoding])](#javaProps.parseFile) ⇒ <code>Promise.&lt;Object&gt;</code>
50+
- [.stringify(props)](#javaProps.stringify) ⇒ <code>String</code>
5151

5252
<a name="javaProps.parse"></a>
5353

5454
### javaProps.parse(str) ⇒ <code>Object</code>
55+
5556
Parses a .properties string, constructing a corresponding JavaScript object.
5657

57-
**Returns**: <code>Object</code> - The [Object](Object) corresponding to the given string
58+
**Returns**: <code>Object</code> - The [Object](Object) corresponding to the given string
59+
60+
| Param | Type | Description |
61+
| ----- | ------------------- | ---------------------------------- |
62+
| str | <code>String</code> | The string to parse as .properties |
5863

59-
| Param | Type | Description |
60-
| --- | --- | --- |
61-
| str | <code>String</code> | The string to parse as .properties |
64+
**Example**
6265

63-
**Example**
6466
```js
6567
const props = javaProps.parse('foo=Hello\nbar=World');
6668
console.log(props.foo + ' ' + props.bar);
6769
// "Hello World"
6870
```
71+
6972
<a name="javaProps.parseFile"></a>
7073

7174
### javaProps.parseFile(path, [encoding]) ⇒ <code>Promise.&lt;Object&gt;</code>
75+
7276
Parses a .properties file, constructing a corresponding JavaScript object.
7377

74-
**Returns**: <code>Promise.&lt;Object&gt;</code> - The [Object](Object) corresponding to the given string
78+
**Returns**: <code>Promise.&lt;Object&gt;</code> - The [Object](Object) corresponding to the given string
79+
80+
| Param | Type | Default | Description |
81+
| ---------- | ------------------------------------------------------------------------------------- | ----------------- | --------------------------- |
82+
| path | <code>String</code> \| <code>Buffer</code> \| <code>URL</code> \| <code>number</code> | | Filename or file descriptor |
83+
| [encoding] | <code>String</code> | <code>utf8</code> | File encoding |
7584

76-
| Param | Type | Default | Description |
77-
| --- | --- | --- | --- |
78-
| path | <code>String</code> \| <code>Buffer</code> \| <code>URL</code> \| <code>number</code> | | Filename or file descriptor |
79-
| [encoding] | <code>String</code> | <code>utf8</code> | File encoding |
85+
**Example**
8086

81-
**Example**
8287
```js
83-
javaProps.parseFile('./foobar.properties').then((props) => {
84-
console.log(props.foo + ' ' + props.bar);
85-
// "Hello World"
86-
}).catch((err) => {
87-
console.error(err);
88-
});
88+
javaProps
89+
.parseFile('./foobar.properties')
90+
.then((props) => {
91+
console.log(props.foo + ' ' + props.bar);
92+
// "Hello World"
93+
})
94+
.catch((err) => {
95+
console.error(err);
96+
});
8997
```
90-
*- or with async/await -*
98+
99+
_- or with async/await -_
100+
91101
```js
92102
async function fct() {
93103
try {
@@ -99,20 +109,23 @@ async function fct() {
99109
}
100110
}
101111
```
112+
102113
<a name="javaProps.stringify"></a>
103114

104115
### javaProps.stringify(props) ⇒ <code>String</code>
116+
105117
Convert a JavaScript object to the corresponding .properties string.
106118

107-
**Returns**: <code>String</code> - The .properties string corresponding to the given JavaScript object
119+
**Returns**: <code>String</code> - The .properties string corresponding to the given JavaScript object
108120

109-
| Param | Type | Description |
110-
| --- | --- | --- |
121+
| Param | Type | Description |
122+
| ----- | ------------------- | -------------------------------- |
111123
| props | <code>Object</code> | The JavaScript object to convert |
112124

113-
**Example**
125+
**Example**
126+
114127
```js
115-
const str = javaProps.stringify({'foo': 'Hello', 'bar': 'World'});
128+
const str = javaProps.stringify({foo: 'Hello', bar: 'World'});
116129
console.log(str);
117130
// "foo: Hello\nbar: World\n"
118131
```

jest.config.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,10 @@ module.exports = {
44
tsConfig: 'tsconfig.json',
55
},
66
},
7-
moduleFileExtensions: [
8-
'ts',
9-
'js',
10-
],
7+
moduleFileExtensions: ['ts', 'js'],
118
transform: {
129
'^.+\\.(ts|tsx)$': 'ts-jest',
1310
},
14-
testMatch: [
15-
'**/test/**/*.test.(ts|js)',
16-
],
11+
testMatch: ['**/test/**/*.test.(ts|js)'],
1712
testEnvironment: 'node',
1813
};

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
"build": "yarn run clean && yarn run build:ts",
2626
"build:ts": "tsc",
2727
"lint": "tslint -c ./tslint.json -p ./tsconfig.json",
28+
"format": "prettier -w ./src ./test/**.ts *.md *.json *.js *.yml",
2829
"test": "jest --coverage --verbose",
2930
"test:watch": "yarn run test -- --watchAll",
3031
"release": "yarn run lint && yarn run build && np"

test/java-props.test.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ const dataFiles = [
1515
describe('parse', () => {
1616
for (const file of dataFiles) {
1717
it('validate ' + file, async () => {
18-
const res = JSON.parse(fs.readFileSync(__dirname + '/data/' + file.replace('.dos', '') + '-result.json', 'utf8'));
18+
const res = JSON.parse(
19+
fs.readFileSync(__dirname + '/data/' + file.replace('.dos', '') + '-result.json', 'utf8')
20+
);
1921
const props = JavaProps.parse(fs.readFileSync(__dirname + '/data/' + file, 'utf8'));
2022
expect(props).toEqual(res);
2123
});
@@ -55,14 +57,14 @@ describe('stringify', () => {
5557

5658
it('must handle spacings', async () => {
5759
expectConvertBack({' key': 'value'});
58-
expectConvertBack({'key': ' value'});
60+
expectConvertBack({key: ' value'});
5961
expectConvertBack({'key ': 'value'});
60-
expectConvertBack({'key': 'value '});
62+
expectConvertBack({key: 'value '});
6163
expectConvertBack({' ke:y= ': ' = \\nval\\ue\n '});
6264
});
6365

6466
it('must skip non-own properties', async () => {
65-
const obj = {'key': 'value'};
67+
const obj = {key: 'value'};
6668
(Object.prototype as any).notAKey = 'x';
6769
expect(JavaProps.stringify(obj)).toBe('key: value\n');
6870
});
@@ -123,7 +125,9 @@ for (const isKey of [false, true]) {
123125
if (converts.hasOwnProperty(char)) {
124126
const repl = converts[char];
125127
it('must encode \\' + char, () => {
126-
expect(encodeLine('abc' + repl + 'def' + repl + 'ghi')).toBe('abc\\' + char + 'def\\' + char + 'ghi');
128+
expect(encodeLine('abc' + repl + 'def' + repl + 'ghi')).toBe(
129+
'abc\\' + char + 'def\\' + char + 'ghi'
130+
);
127131
});
128132
}
129133
}

tsconfig.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@
1111
"outDir": "dist",
1212
"baseUrl": ".",
1313
"paths": {
14-
"*": [
15-
"node_modules/*",
16-
"src/types/*"
17-
]
14+
"*": ["node_modules/*", "src/types/*"]
1815
}
1916
},
2017
"include": ["src/**/*.ts"]

tslint.json

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,20 @@
55
"array-type": [true, "array"],
66
"ban-types": {
77
"options": [
8-
["Object", "Avoid using the `Object` type. Did you mean `object`?"], [
8+
["Object", "Avoid using the `Object` type. Did you mean `object`?"],
9+
[
910
"Function",
1011
"Avoid using the `Function` type. Prefer a specific function type, like `() => void`, or use `ts.AnyFunction`."
11-
], ["Boolean", "Avoid using the `Boolean` type. Did you mean `boolean`?"],
12+
],
13+
["Boolean", "Avoid using the `Boolean` type. Did you mean `boolean`?"],
1214
["Number", "Avoid using the `Number` type. Did you mean `number`?"],
1315
["String", "Avoid using the `String` type. Did you mean `string`?"]
1416
]
1517
},
1618
"class-name": true,
17-
"comment-format": [
18-
true, "check-space"
19-
],
19+
"comment-format": [true, "check-space"],
2020
"curly": [true, "ignore-same-line"],
21-
"indent": [
22-
true, "spaces"
23-
],
21+
"indent": [true, "spaces"],
2422
"interface-name": [true, "never-prefix"],
2523
"interface-over-type-literal": true,
2624
"jsdoc-format": true,
@@ -33,34 +31,30 @@
3331
"no-unnecessary-qualifier": true,
3432
"no-var-keyword": true,
3533
"object-literal-shorthand": true,
36-
"one-line": [
37-
true, "check-open-brace", "check-whitespace"
38-
],
34+
"one-line": [true, "check-open-brace", "check-whitespace"],
3935
"prefer-const": true,
40-
"quotemark": [
41-
true, "single", "avoid-escape"
42-
],
36+
"quotemark": [true, "single", "avoid-escape"],
4337
"semicolon": [true, "always", "ignore-bound-class-methods"],
4438
"space-within-parens": true,
4539
"triple-equals": true,
4640
"typedef-whitespace": [
47-
true, {
41+
true,
42+
{
4843
"call-signature": "nospace",
4944
"index-signature": "nospace",
5045
"parameter": "nospace",
5146
"property-declaration": "nospace",
5247
"variable-declaration": "nospace"
53-
}, {
48+
},
49+
{
5450
"call-signature": "onespace",
5551
"index-signature": "onespace",
5652
"parameter": "onespace",
5753
"property-declaration": "onespace",
5854
"variable-declaration": "onespace"
5955
}
6056
],
61-
"whitespace": [
62-
true, "check-branch", "check-decl", "check-operator", "check-separator", "check-type"
63-
],
57+
"whitespace": [true, "check-branch", "check-decl", "check-operator", "check-separator", "check-type"],
6458
// Config different from tslint:latest
6559
"no-implicit-dependencies": [true, "dev"],
6660
"object-literal-key-quotes": [true, "consistent-as-needed"],
@@ -105,4 +99,4 @@
10599
"object-literal-sort-keys": false,
106100
"one-variable-per-declaration": false
107101
}
108-
}
102+
}

0 commit comments

Comments
 (0)