@naturalcycles/nodejs-lib 15.134.0 → 15.135.0

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/dist/fs/fs2.d.ts CHANGED
@@ -25,15 +25,15 @@ declare class FS2 {
25
25
  writeFile(filePath: string, data: string | Uint8Array, opt?: WriteFileOptions): void;
26
26
  writeFileAsync(filePath: string, data: string | Uint8Array, opt?: WriteFileOptions): Promise<void>;
27
27
  writePrettyJson(filePath: string, data: any): void;
28
- writeJson(filePath: string, data: any, opt?: JsonOptions): void;
28
+ writeJson(filePath: string, data: any): void;
29
29
  writePrettyJsonAsync(filePath: string, data: any): Promise<void>;
30
- writeJsonAsync(filePath: string, data: any, opt?: JsonOptions): Promise<void>;
30
+ writeJsonAsync(filePath: string, data: any): Promise<void>;
31
31
  appendFile(filePath: string, data: string | Uint8Array): void;
32
32
  appendFileAsync(filePath: string, data: string | Uint8Array): Promise<void>;
33
33
  outputPrettyJson(filePath: string, data: any): void;
34
- outputJson(filePath: string, data: any, opt?: JsonOptions): void;
34
+ outputJson(filePath: string, data: any): void;
35
35
  outputPrettyJsonAsync(filePath: string, data: any): Promise<void>;
36
- outputJsonAsync(filePath: string, data: any, opt?: JsonOptions): Promise<void>;
36
+ outputJsonAsync(filePath: string, data: any): Promise<void>;
37
37
  outputFile(filePath: string, data: string | Uint8Array): void;
38
38
  outputFileAsync(filePath: string, data: string | Uint8Array): Promise<void>;
39
39
  pathExists(filePath: string): boolean;
@@ -79,7 +79,4 @@ declare class FS2 {
79
79
  createReadStream: typeof fs.createReadStream;
80
80
  }
81
81
  export declare const fs2: FS2;
82
- export interface JsonOptions {
83
- spaces?: number;
84
- }
85
82
  export {};
package/dist/fs/fs2.js CHANGED
@@ -62,17 +62,19 @@ class FS2 {
62
62
  await fsp.writeFile(filePath, data, opt);
63
63
  }
64
64
  writePrettyJson(filePath, data) {
65
- this.writeJson(filePath, data, prettyJsonOptions);
65
+ const str = stringifyPretty(data);
66
+ fs.writeFileSync(filePath, str);
66
67
  }
67
- writeJson(filePath, data, opt) {
68
- const str = stringify(data, opt);
68
+ writeJson(filePath, data) {
69
+ const str = JSON.stringify(data);
69
70
  fs.writeFileSync(filePath, str);
70
71
  }
71
72
  async writePrettyJsonAsync(filePath, data) {
72
- await this.writeJsonAsync(filePath, data, prettyJsonOptions);
73
+ const str = stringifyPretty(data);
74
+ await fsp.writeFile(filePath, str);
73
75
  }
74
- async writeJsonAsync(filePath, data, opt) {
75
- const str = stringify(data, opt);
76
+ async writeJsonAsync(filePath, data) {
77
+ const str = JSON.stringify(data);
76
78
  await fsp.writeFile(filePath, str);
77
79
  }
78
80
  appendFile(filePath, data) {
@@ -82,17 +84,19 @@ class FS2 {
82
84
  await fsp.appendFile(filePath, data);
83
85
  }
84
86
  outputPrettyJson(filePath, data) {
85
- this.outputJson(filePath, data, prettyJsonOptions);
87
+ const str = stringifyPretty(data);
88
+ this.outputFile(filePath, str);
86
89
  }
87
- outputJson(filePath, data, opt) {
88
- const str = stringify(data, opt);
90
+ outputJson(filePath, data) {
91
+ const str = JSON.stringify(data);
89
92
  this.outputFile(filePath, str);
90
93
  }
91
94
  async outputPrettyJsonAsync(filePath, data) {
92
- await this.outputJsonAsync(filePath, data, prettyJsonOptions);
95
+ const str = stringifyPretty(data);
96
+ await this.outputFileAsync(filePath, str);
93
97
  }
94
- async outputJsonAsync(filePath, data, opt) {
95
- const str = stringify(data, opt);
98
+ async outputJsonAsync(filePath, data) {
99
+ const str = JSON.stringify(data);
96
100
  await this.outputFileAsync(filePath, str);
97
101
  }
98
102
  outputFile(filePath, data) {
@@ -276,8 +280,7 @@ class FS2 {
276
280
  createReadStream = fs.createReadStream;
277
281
  }
278
282
  export const fs2 = new FS2();
279
- const prettyJsonOptions = { spaces: 2 };
280
- function stringify(data, opt) {
281
- // If pretty-printing is enabled (spaces) - also add a newline at the end (to match our prettier config)
282
- return JSON.stringify(data, null, opt?.spaces) + (opt?.spaces ? '\n' : '');
283
+ function stringifyPretty(data) {
284
+ // Add a newline at the end (to match our prettier config)
285
+ return JSON.stringify(data, null, 2) + '\n';
283
286
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
3
  "type": "module",
4
- "version": "15.134.0",
4
+ "version": "15.135.0",
5
5
  "dependencies": {
6
6
  "@naturalcycles/js-lib": "^15",
7
7
  "@standard-schema/spec": "^1",
package/src/fs/fs2.ts CHANGED
@@ -78,20 +78,22 @@ class FS2 {
78
78
  }
79
79
 
80
80
  writePrettyJson(filePath: string, data: any): void {
81
- this.writeJson(filePath, data, prettyJsonOptions)
81
+ const str = stringifyPretty(data)
82
+ fs.writeFileSync(filePath, str)
82
83
  }
83
84
 
84
- writeJson(filePath: string, data: any, opt?: JsonOptions): void {
85
- const str = stringify(data, opt)
85
+ writeJson(filePath: string, data: any): void {
86
+ const str = JSON.stringify(data)
86
87
  fs.writeFileSync(filePath, str)
87
88
  }
88
89
 
89
90
  async writePrettyJsonAsync(filePath: string, data: any): Promise<void> {
90
- await this.writeJsonAsync(filePath, data, prettyJsonOptions)
91
+ const str = stringifyPretty(data)
92
+ await fsp.writeFile(filePath, str)
91
93
  }
92
94
 
93
- async writeJsonAsync(filePath: string, data: any, opt?: JsonOptions): Promise<void> {
94
- const str = stringify(data, opt)
95
+ async writeJsonAsync(filePath: string, data: any): Promise<void> {
96
+ const str = JSON.stringify(data)
95
97
  await fsp.writeFile(filePath, str)
96
98
  }
97
99
 
@@ -104,20 +106,22 @@ class FS2 {
104
106
  }
105
107
 
106
108
  outputPrettyJson(filePath: string, data: any): void {
107
- this.outputJson(filePath, data, prettyJsonOptions)
109
+ const str = stringifyPretty(data)
110
+ this.outputFile(filePath, str)
108
111
  }
109
112
 
110
- outputJson(filePath: string, data: any, opt?: JsonOptions): void {
111
- const str = stringify(data, opt)
113
+ outputJson(filePath: string, data: any): void {
114
+ const str = JSON.stringify(data)
112
115
  this.outputFile(filePath, str)
113
116
  }
114
117
 
115
118
  async outputPrettyJsonAsync(filePath: string, data: any): Promise<void> {
116
- await this.outputJsonAsync(filePath, data, prettyJsonOptions)
119
+ const str = stringifyPretty(data)
120
+ await this.outputFileAsync(filePath, str)
117
121
  }
118
122
 
119
- async outputJsonAsync(filePath: string, data: any, opt?: JsonOptions): Promise<void> {
120
- const str = stringify(data, opt)
123
+ async outputJsonAsync(filePath: string, data: any): Promise<void> {
124
+ const str = JSON.stringify(data)
121
125
  await this.outputFileAsync(filePath, str)
122
126
  }
123
127
 
@@ -324,13 +328,7 @@ class FS2 {
324
328
 
325
329
  export const fs2 = new FS2()
326
330
 
327
- const prettyJsonOptions: JsonOptions = { spaces: 2 }
328
-
329
- export interface JsonOptions {
330
- spaces?: number
331
- }
332
-
333
- function stringify(data: any, opt?: JsonOptions): string {
334
- // If pretty-printing is enabled (spaces) - also add a newline at the end (to match our prettier config)
335
- return JSON.stringify(data, null, opt?.spaces) + (opt?.spaces ? '\n' : '')
331
+ function stringifyPretty(data: any): string {
332
+ // Add a newline at the end (to match our prettier config)
333
+ return JSON.stringify(data, null, 2) + '\n'
336
334
  }