@bluelovers/fs-json 1.0.14 → 1.0.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/README.md +81 -3
- package/package.json +4 -4
- package/index.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,34 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [1.0.16](https://github.com/bluelovers/ws-iconv/compare/@bluelovers/fs-json@1.0.15...@bluelovers/fs-json@1.0.16) (2026-03-01)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @bluelovers/fs-json
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [1.0.15](https://github.com/bluelovers/ws-iconv/compare/@bluelovers/fs-json@1.0.14...@bluelovers/fs-json@1.0.15) (2026-03-01)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### 📚 Documentation
|
|
19
|
+
|
|
20
|
+
* 为多个包添加全面的 JSDoc 文档和 README 更新 ([0d149e8](https://github.com/bluelovers/ws-iconv/commit/0d149e856aa9b274aca7fd7562776860c9d00473))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### 🚨 Tests
|
|
24
|
+
|
|
25
|
+
* **snap:** 更新跨套件測試快照並新增執行配置 ([06ad833](https://github.com/bluelovers/ws-iconv/commit/06ad833b318697003d731cc307205b9a70b1e094))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### ♻️ Chores
|
|
29
|
+
|
|
30
|
+
* Update jest config and add new files for testing ([f370583](https://github.com/bluelovers/ws-iconv/commit/f37058385c7bf24d3d0bc975c752f2f35cfe8356))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
6
34
|
## [1.0.14](https://github.com/bluelovers/ws-iconv/compare/@bluelovers/fs-json@1.0.13...@bluelovers/fs-json@1.0.14) (2024-08-29)
|
|
7
35
|
|
|
8
36
|
|
package/README.md
CHANGED
|
@@ -1,12 +1,90 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @bluelovers/fs-json
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Enhanced JSON file operations with final EOL (End of Line) support.
|
|
4
|
+
增強型 JSON 檔案操作,支援結尾換行符號(EOL)。
|
|
4
5
|
|
|
5
|
-
##
|
|
6
|
+
## Features / 功能
|
|
7
|
+
|
|
8
|
+
- Read and write JSON files / 讀寫 JSON 檔案
|
|
9
|
+
- Output JSON with auto directory creation / 輸出 JSON 並自動創建目錄
|
|
10
|
+
- Stringify JSON with final EOL option / 字串化 JSON 並支援結尾換行選項
|
|
11
|
+
- Parse JSON from string or Uint8Array / 從字串或 Uint8Array 解析 JSON
|
|
12
|
+
- Based on fs-extra and jsonfile / 基於 fs-extra 和 jsonfile
|
|
13
|
+
|
|
14
|
+
## Install / 安裝
|
|
6
15
|
|
|
7
16
|
```bash
|
|
8
17
|
yarn add @bluelovers/fs-json
|
|
9
18
|
yarn-tool add @bluelovers/fs-json
|
|
10
19
|
yt add @bluelovers/fs-json
|
|
20
|
+
pnpm add @bluelovers/fs-json
|
|
21
|
+
npm install @bluelovers/fs-json
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Quick Start / 快速開始
|
|
25
|
+
|
|
26
|
+
```typescript
|
|
27
|
+
import {
|
|
28
|
+
readJSON,
|
|
29
|
+
readJSONSync,
|
|
30
|
+
writeJSON,
|
|
31
|
+
writeJSONSync,
|
|
32
|
+
outputJSON,
|
|
33
|
+
outputJSONSync,
|
|
34
|
+
stringifyJSON,
|
|
35
|
+
parseJSON
|
|
36
|
+
} from '@bluelovers/fs-json';
|
|
37
|
+
|
|
38
|
+
// Read JSON / 讀取 JSON
|
|
39
|
+
const data = await readJSON('config.json');
|
|
40
|
+
const dataSync = readJSONSync('config.json');
|
|
41
|
+
|
|
42
|
+
// Write JSON / 寫入 JSON
|
|
43
|
+
await writeJSON('output.json', { key: 'value' });
|
|
44
|
+
writeJSONSync('output.json', { key: 'value' });
|
|
45
|
+
|
|
46
|
+
// Output JSON (creates directory if needed) / 輸出 JSON(必要時創建目錄)
|
|
47
|
+
await outputJSON('path/to/file.json', { key: 'value' });
|
|
48
|
+
outputJSONSync('path/to/file.json', { key: 'value' });
|
|
49
|
+
|
|
50
|
+
// Stringify with final EOL / 字串化並添加結尾換行
|
|
51
|
+
const jsonString = stringifyJSON({ key: 'value' });
|
|
52
|
+
console.log(jsonString); // '{"key":"value"}\n'
|
|
53
|
+
|
|
54
|
+
// Parse JSON / 解析 JSON
|
|
55
|
+
const obj = parseJSON('{"key":"value"}');
|
|
56
|
+
const objFromUint8 = parseJSON(new Uint8Array([123, 34, 107, 101, 121, 34, 58, 34, 118, 97, 108, 117, 101, 34, 125]));
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## API
|
|
60
|
+
|
|
61
|
+
### `readJSON(file, options?)` / `readJSONSync(file, options?)`
|
|
62
|
+
Reads a JSON file asynchronously or synchronously.
|
|
63
|
+
異步或同步讀取 JSON 檔案。
|
|
64
|
+
|
|
65
|
+
### `writeJSON(file, data, options?)` / `writeJSONSync(file, data, options?)`
|
|
66
|
+
Writes a JSON file asynchronously or synchronously.
|
|
67
|
+
異步或同步寫入 JSON 檔案。
|
|
68
|
+
|
|
69
|
+
### `outputJSON(file, data, options?)` / `outputJSONSync(file, data, options?)`
|
|
70
|
+
Writes a JSON file, creating the directory if it doesn't exist.
|
|
71
|
+
寫入 JSON 檔案,如果目錄不存在則自動創建。
|
|
72
|
+
|
|
73
|
+
### `stringifyJSON(data, options?)`
|
|
74
|
+
Stringifies data to JSON with final EOL support.
|
|
75
|
+
將資料字串化為 JSON,支援結尾換行。
|
|
76
|
+
|
|
77
|
+
### `parseJSON(stringOrUint8Array, reviver?)`
|
|
78
|
+
Parses JSON from string or Uint8Array.
|
|
79
|
+
從字串或 Uint8Array 解析 JSON。
|
|
80
|
+
|
|
81
|
+
### Options / 選項
|
|
82
|
+
|
|
83
|
+
```typescript
|
|
84
|
+
interface IWriteOptions {
|
|
85
|
+
finalEOL?: boolean; // Add final newline (default: true) / 添加結尾換行(預設:true)
|
|
86
|
+
spaces?: string | number; // Indentation / 縮排
|
|
87
|
+
// ... other fs-extra/jsonfile options
|
|
88
|
+
}
|
|
11
89
|
```
|
|
12
90
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bluelovers/fs-json",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "1.0.16",
|
|
4
|
+
"description": "Enhanced JSON file operations with final EOL support / 增強型 JSON 檔案操作,支援結尾換行符號",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"create-by-yarn-tool"
|
|
7
7
|
],
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
"lint": "ynpx --quiet eslint -- **/*.ts",
|
|
23
23
|
"test": "jest --passWithNoTests",
|
|
24
24
|
"test:jest": "jest --passWithNoTests",
|
|
25
|
+
"test:jest:coverage": "yarn run test:jest -- --coverage",
|
|
25
26
|
"test:jest:snapshot": "yarn run test:jest -- -u",
|
|
26
27
|
"test:mocha": "ynpx --quiet -p ts-node -p mocha mocha -- --require ts-node/register \"!(node_modules)/**/*.{test,spec}.{ts,tsx}\"",
|
|
27
28
|
"test:snapshot": "yarn run test -- -u",
|
|
@@ -51,9 +52,8 @@
|
|
|
51
52
|
"jsonfile": "^6.1.0",
|
|
52
53
|
"tslib": "^2"
|
|
53
54
|
},
|
|
54
|
-
"packageManager": "yarn@^1.22.11",
|
|
55
55
|
"publishConfig": {
|
|
56
56
|
"access": "public"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "6bcfe6a585ad7e5657a40a5b0727c6281b564b60"
|
|
59
59
|
}
|
package/index.js.map
DELETED
|
@@ -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AA;AAC3C,CAAC;AAED,SAAgB,aAAa,CAAC,IAAS,EAAE,OAAuB;IAE/D,OAAO,GAAG,mBAAmB,CAAC,OAAO,CAAC,CAAC;IACvC,OAAO,IAAA,iBAAS,EAAC,IAAI,EAAE,OAAc,CAAC,CAAA;AACvC,CAAC;AAED,SAAgB,SAAS,CAAC,kBAAuC,EAChE,OAAqD;IAGrD,OAAO,IAAI,CAAC,KAAK,CAAC,kBAAkB,CAAC,QAAQ,EAAE,EAAE,OAAO,CAAC,CAAA;AAC1D,CAAC","sourcesContent":["import {\n\toutputJSON as _outputJSON,\n\toutputJSONSync as _outputJSONSync,\n\treadJSON,\n\treadJSONSync,\n\twriteJSON as _writeJSON,\n\twriteJSONSync as _writeJSONSync,\n\tWriteOptions,\n} from 'fs-extra';\nimport { stringify } from 'jsonfile/utils';\nimport { JFWriteOptions } from 'jsonfile';\n\ndeclare module 'fs-extra'\n{\n\tinterface WriteOptions extends Exclude<JFWriteOptions, string | null>\n\t{\n\t\tfinalEOL?: boolean\n\t}\n}\n\nexport type IWriteOptions = WriteOptions & Exclude<JFWriteOptions, string | null>;\n\nexport function _handleWriteOptions(options?: IWriteOptions): IWriteOptions\n{\n\toptions ??= {};\n\toptions.finalEOL ??= true;\n\treturn options\n}\n\nexport {\n\treadJSON,\n\treadJSONSync,\n}\n\nexport function outputJSON(file: string, data: any, options?: IWriteOptions)\n{\n\toptions = _handleWriteOptions(options);\n\treturn _outputJSON(file, data, options)\n}\n\nexport function outputJSONSync(file: string, data: any, options?: IWriteOptions)\n{\n\toptions = _handleWriteOptions(options);\n\treturn _outputJSONSync(file, data, options)\n}\n\nexport function writeJSON(file: string, data: any, options?: IWriteOptions)\n{\n\toptions = _handleWriteOptions(options);\n\treturn _writeJSON(file, data, options)\n}\n\nexport function writeJSONSync(file: string, data: any, options?: IWriteOptions)\n{\n\toptions = _handleWriteOptions(options);\n\treturn _writeJSONSync(file, data, options)\n}\n\nexport function stringifyJSON(data: any, options?: IWriteOptions): string\n{\n\toptions = _handleWriteOptions(options);\n\treturn stringify(data, options as any)\n}\n\nexport function parseJSON(stringOrUint8Array: string | Uint8Array,\n\treviver?: (this: any, key: string, value: any) => any,\n): string\n{\n\treturn JSON.parse(stringOrUint8Array.toString(), reviver)\n}\n"]}
|