diff --git a/.github/funding.yml b/.github/funding.yml deleted file mode 100644 index 7571333..0000000 --- a/.github/funding.yml +++ /dev/null @@ -1,2 +0,0 @@ -github: sindresorhus -tidelift: npm/write-json-file diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 441975c..6e98150 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,10 +10,12 @@ jobs: fail-fast: false matrix: node-version: - - 16 + - 22 + - 20 + - 18 steps: - - uses: actions/checkout@v2 - - uses: actions/setup-node@v2 + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - run: npm install diff --git a/index.d.ts b/index.d.ts index 6aaa2e6..7e6b956 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,12 +1,14 @@ export type Replacer = (this: unknown, key: string, value: unknown) => unknown; export type SortKeys = (a: string, b: string) => number; -export interface Options { +export type Options = { /** Indentation as a string or number of spaces. Pass in `undefined` for no formatting. + If you set both this and `detectIndent`, this value will be used when the indentation cannot be detected. + @default '\t' */ readonly indent?: string | number | undefined; @@ -38,7 +40,7 @@ export interface Options { @default 0o666 */ readonly mode?: number; -} +}; /** Stringify and write JSON to a file atomically. diff --git a/index.test-d.ts b/index.test-d.ts index f0ef6f7..8065eb0 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,5 +1,10 @@ import {expectType, expectAssignable} from 'tsd'; -import {writeJsonFile, writeJsonFileSync, Replacer, SortKeys} from './index.js'; +import { + writeJsonFile, + writeJsonFileSync, + type Replacer, + type SortKeys, +} from './index.js'; expectAssignable(() => 1); expectAssignable((a: string) => a.length); diff --git a/package.json b/package.json index e7c880e..c3e776d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "write-json-file", - "version": "5.0.0", + "version": "6.0.0", "description": "Stringify and write JSON to a file atomically", "license": "MIT", "repository": "sindresorhus/write-json-file", @@ -11,9 +11,13 @@ "url": "https://sindresorhus.com" }, "type": "module", - "exports": "./index.js", + "exports": { + "types": "./index.d.ts", + "default": "./index.js" + }, + "sideEffects": false, "engines": { - "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + "node": ">=18" }, "scripts": { "test": "xo && ava && tsd" @@ -37,15 +41,15 @@ "atomically" ], "dependencies": { - "detect-indent": "^7.0.0", - "is-plain-obj": "^4.0.0", + "detect-indent": "^7.0.1", + "is-plain-obj": "^4.1.0", "sort-keys": "^5.0.0", - "write-file-atomic": "^3.0.3" + "write-file-atomic": "^5.0.1" }, "devDependencies": { - "ava": "^3.15.0", - "tempy": "^1.0.1", - "tsd": "^0.17.0", - "xo": "^0.44.0" + "ava": "^6.1.3", + "tempy": "^2.0.0", + "tsd": "^0.31.1", + "xo": "^0.59.2" } } diff --git a/readme.md b/readme.md index a42c402..37214d5 100644 --- a/readme.md +++ b/readme.md @@ -6,8 +6,8 @@ Creates directories for you as needed. ## Install -``` -$ npm install write-json-file +```sh +npm install write-json-file ``` ## Usage @@ -24,7 +24,7 @@ await writeJsonFile('foo.json', {foo: true}); Returns a `Promise`. -### writeJsonFile.sync(filePath, data, options?) +### writeJsonFileSync(filePath, data, options?) #### options @@ -32,13 +32,15 @@ Type: `object` ##### indent -Type: `string | number`\ +Type: `string | number | undefined`\ Default: `'\t'` Indentation as a string or number of spaces. Pass in `undefined` for no formatting. +If you set both this and `detectIndent`, this value will be used when the indentation cannot be detected. + ##### detectIndent Type: `boolean`\ @@ -68,14 +70,7 @@ Default: `0o666` The [mode](https://en.wikipedia.org/wiki/File_system_permissions#Numeric_notation) used when writing the file. -## write-json-file for enterprise - -Available as part of the Tidelift Subscription. - -The maintainers of write-json-file and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/npm-write-json-file?utm_source=npm-write-json-file&utm_medium=referral&utm_campaign=enterprise&utm_term=repo) - ## Related - [load-json-file](https://github.com/sindresorhus/load-json-file) - Read and parse a JSON file - [make-dir](https://github.com/sindresorhus/make-dir) - Make a directory and its parents if needed -