Skip to content

Commit c78294d

Browse files
committed
Meta tweaks
1 parent 8a602ea commit c78294d

File tree

5 files changed

+90
-90
lines changed

5 files changed

+90
-90
lines changed

.gitattributes

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
* text=auto
2-
*.js text eol=lf
1+
* text=auto eol=lf

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

index.js

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,70 +7,70 @@ const makeDir = require('make-dir');
77
const pify = require('pify');
88
const detectIndent = require('detect-indent');
99

10-
const init = (fn, fp, data, opts) => {
11-
if (!fp) {
10+
const init = (fn, filePath, data, options) => {
11+
if (!filePath) {
1212
throw new TypeError('Expected a filepath');
1313
}
1414

1515
if (data === undefined) {
1616
throw new TypeError('Expected data to stringify');
1717
}
1818

19-
opts = Object.assign({
19+
options = Object.assign({
2020
indent: '\t',
2121
sortKeys: false
22-
}, opts);
22+
}, options);
2323

24-
if (opts.sortKeys) {
24+
if (options.sortKeys) {
2525
data = sortKeys(data, {
2626
deep: true,
27-
compare: typeof opts.sortKeys === 'function' && opts.sortKeys
27+
compare: typeof options.sortKeys === 'function' && options.sortKeys
2828
});
2929
}
3030

31-
return fn(fp, data, opts);
31+
return fn(filePath, data, options);
3232
};
3333

34-
const readFile = fp => pify(fs.readFile)(fp, 'utf8').catch(() => {});
34+
const readFile = filePath => pify(fs.readFile)(filePath, 'utf8').catch(() => {});
3535

36-
const main = (fp, data, opts) => {
37-
return (opts.detectIndent ? readFile(fp) : Promise.resolve())
38-
.then(str => {
39-
const indent = str ? detectIndent(str).indent : opts.indent;
40-
const json = JSON.stringify(data, opts.replacer, indent);
36+
const main = (filePath, data, options) => {
37+
return (options.detectIndent ? readFile(filePath) : Promise.resolve())
38+
.then(string => {
39+
const indent = string ? detectIndent(string).indent : options.indent;
40+
const json = JSON.stringify(data, options.replacer, indent);
4141

42-
return pify(writeFileAtomic)(fp, `${json}\n`, {mode: opts.mode});
42+
return pify(writeFileAtomic)(filePath, `${json}\n`, {mode: options.mode});
4343
});
4444
};
4545

46-
const mainSync = (fp, data, opts) => {
47-
let {indent} = opts;
46+
const mainSync = (filePath, data, options) => {
47+
let {indent} = options;
4848

49-
if (opts.detectIndent) {
49+
if (options.detectIndent) {
5050
try {
51-
const file = fs.readFileSync(fp, 'utf8');
51+
const file = fs.readFileSync(filePath, 'utf8');
5252
// eslint-disable-next-line prefer-destructuring
5353
indent = detectIndent(file).indent;
54-
} catch (err) {
55-
if (err.code !== 'ENOENT') {
56-
throw err;
54+
} catch (error) {
55+
if (error.code !== 'ENOENT') {
56+
throw error;
5757
}
5858
}
5959
}
6060

61-
const json = JSON.stringify(data, opts.replacer, indent);
61+
const json = JSON.stringify(data, options.replacer, indent);
6262

63-
return writeFileAtomic.sync(fp, `${json}\n`, {mode: opts.mode});
63+
return writeFileAtomic.sync(filePath, `${json}\n`, {mode: options.mode});
6464
};
6565

66-
const writeJsonFile = (fp, data, opts) => {
67-
return makeDir(path.dirname(fp), {fs})
68-
.then(() => init(main, fp, data, opts));
66+
const writeJsonFile = (filePath, data, options) => {
67+
return makeDir(path.dirname(filePath), {fs})
68+
.then(() => init(main, filePath, data, options));
6969
};
7070

7171
module.exports = writeJsonFile;
7272
module.exports.default = writeJsonFile;
73-
module.exports.sync = (fp, data, opts) => {
74-
makeDir.sync(path.dirname(fp), {fs});
75-
init(mainSync, fp, data, opts);
73+
module.exports.sync = (filePath, data, options) => {
74+
makeDir.sync(path.dirname(filePath), {fs});
75+
init(mainSync, filePath, data, options);
7676
};

package.json

Lines changed: 52 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,54 @@
11
{
2-
"name": "write-json-file",
3-
"version": "2.3.0",
4-
"description": "Stringify and write JSON to a file atomically",
5-
"license": "MIT",
6-
"repository": "sindresorhus/write-json-file",
7-
"author": {
8-
"name": "Sindre Sorhus",
9-
"email": "[email protected]",
10-
"url": "sindresorhus.com"
11-
},
12-
"engines": {
13-
"node": ">=6"
14-
},
15-
"scripts": {
16-
"test": "xo && ava"
17-
},
18-
"files": [
19-
"index.js",
20-
"index.d.ts"
21-
],
22-
"keywords": [
23-
"write",
24-
"json",
25-
"stringify",
26-
"file",
27-
"fs",
28-
"graceful",
29-
"stable",
30-
"sort",
31-
"newline",
32-
"indent",
33-
"atomic",
34-
"atomically"
35-
],
36-
"dependencies": {
37-
"detect-indent": "^5.0.0",
38-
"graceful-fs": "^4.1.2",
39-
"make-dir": "^1.0.0",
40-
"pify": "^3.0.0",
41-
"sort-keys": "^2.0.0",
42-
"write-file-atomic": "^2.0.0"
43-
},
44-
"devDependencies": {
45-
"ava": "*",
46-
"tempfile": "^2.0.0",
47-
"xo": "*"
48-
},
49-
"xo": {
50-
"ignores": [
51-
"index.d.ts"
52-
]
53-
}
2+
"name": "write-json-file",
3+
"version": "2.3.0",
4+
"description": "Stringify and write JSON to a file atomically",
5+
"license": "MIT",
6+
"repository": "sindresorhus/write-json-file",
7+
"author": {
8+
"name": "Sindre Sorhus",
9+
"email": "[email protected]",
10+
"url": "sindresorhus.com"
11+
},
12+
"engines": {
13+
"node": ">=6"
14+
},
15+
"scripts": {
16+
"test": "xo && ava"
17+
},
18+
"files": [
19+
"index.js",
20+
"index.d.ts"
21+
],
22+
"keywords": [
23+
"write",
24+
"json",
25+
"stringify",
26+
"file",
27+
"fs",
28+
"graceful",
29+
"stable",
30+
"sort",
31+
"newline",
32+
"indent",
33+
"atomic",
34+
"atomically"
35+
],
36+
"dependencies": {
37+
"detect-indent": "^5.0.0",
38+
"graceful-fs": "^4.1.2",
39+
"make-dir": "^1.0.0",
40+
"pify": "^4.0.0",
41+
"sort-keys": "^2.0.0",
42+
"write-file-atomic": "^2.0.0"
43+
},
44+
"devDependencies": {
45+
"ava": "*",
46+
"tempfile": "^2.0.0",
47+
"xo": "*"
48+
},
49+
"xo": {
50+
"ignores": [
51+
"index.d.ts"
52+
]
53+
}
5454
}

readme.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ $ npm install write-json-file
1717
```js
1818
const writeJsonFile = require('write-json-file');
1919

20-
writeJsonFile('foo.json', {foo: true}).then(() => {
21-
console.log('done');
22-
});
20+
(async () => {
21+
await writeJsonFile('foo.json', {foo: true});
22+
})();
2323
```
2424

2525

2626
## API
2727

28-
### writeJsonFile(filepath, data, [options])
28+
### writeJsonFile(filePath, data, [options])
2929

3030
Returns a `Promise`.
3131

32-
### writeJsonFile.sync(filepath, data, [options])
32+
### writeJsonFile.sync(filePath, data, [options])
3333

3434
#### options
3535

@@ -52,15 +52,15 @@ Detect indentation automatically if the file exists.
5252

5353
##### sortKeys
5454

55-
Type: `boolean` `function`<br>
55+
Type: `boolean` `Function`<br>
5656
Default: `false`
5757

5858
Sort the keys recursively.<br>
5959
Optionally pass in a [`compare`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort) function.
6060

6161
##### replacer
6262

63-
Type: `function`
63+
Type: `Function`
6464

6565
Passed into [`JSON.stringify`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#The_replacer_parameter).
6666

0 commit comments

Comments
 (0)