@naturalcycles/nodejs-lib 13.0.0 → 13.0.1

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.
@@ -120,23 +120,27 @@ function _outputFileSync(filePath, data) {
120
120
  fs.writeFileSync(filePath, data);
121
121
  }
122
122
  exports._outputFileSync = _outputFileSync;
123
+ function stringify(data, opt) {
124
+ // If pretty-printing is enabled (spaces) - also add a newline at the end (to match our prettier config)
125
+ return JSON.stringify(data, null, opt?.spaces) + (opt?.spaces ? '\n' : '');
126
+ }
123
127
  async function _writeJson(filePath, data, opt) {
124
- const str = JSON.stringify(data, null, opt?.spaces);
128
+ const str = stringify(data, opt);
125
129
  await fsp.writeFile(filePath, str);
126
130
  }
127
131
  exports._writeJson = _writeJson;
128
132
  function _writeJsonSync(filePath, data, opt) {
129
- const str = JSON.stringify(data, null, opt?.spaces);
133
+ const str = stringify(data, opt);
130
134
  fs.writeFileSync(filePath, str);
131
135
  }
132
136
  exports._writeJsonSync = _writeJsonSync;
133
137
  async function _outputJson(filePath, data, opt) {
134
- const str = JSON.stringify(data, null, opt?.spaces);
138
+ const str = stringify(data, opt);
135
139
  await _outputFile(filePath, str);
136
140
  }
137
141
  exports._outputJson = _outputJson;
138
142
  function _outputJsonSync(filePath, data, opt) {
139
- const str = JSON.stringify(data, null, opt?.spaces);
143
+ const str = stringify(data, opt);
140
144
  _outputFileSync(filePath, str);
141
145
  }
142
146
  exports._outputJsonSync = _outputJsonSync;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@naturalcycles/nodejs-lib",
3
- "version": "13.0.0",
3
+ "version": "13.0.1",
4
4
  "scripts": {
5
5
  "prepare": "husky install",
6
6
  "docs-serve": "vuepress dev docs",
package/src/fs/fs.util.ts CHANGED
@@ -126,23 +126,28 @@ export function _outputFileSync(filePath: string, data: string | Buffer): void {
126
126
  fs.writeFileSync(filePath, data)
127
127
  }
128
128
 
129
+ function stringify(data: any, opt?: JsonOptions): string {
130
+ // If pretty-printing is enabled (spaces) - also add a newline at the end (to match our prettier config)
131
+ return JSON.stringify(data, null, opt?.spaces) + (opt?.spaces ? '\n' : '')
132
+ }
133
+
129
134
  export async function _writeJson(filePath: string, data: any, opt?: JsonOptions): Promise<void> {
130
- const str = JSON.stringify(data, null, opt?.spaces)
135
+ const str = stringify(data, opt)
131
136
  await fsp.writeFile(filePath, str)
132
137
  }
133
138
 
134
139
  export function _writeJsonSync(filePath: string, data: any, opt?: JsonOptions): void {
135
- const str = JSON.stringify(data, null, opt?.spaces)
140
+ const str = stringify(data, opt)
136
141
  fs.writeFileSync(filePath, str)
137
142
  }
138
143
 
139
144
  export async function _outputJson(filePath: string, data: any, opt?: JsonOptions): Promise<void> {
140
- const str = JSON.stringify(data, null, opt?.spaces)
145
+ const str = stringify(data, opt)
141
146
  await _outputFile(filePath, str)
142
147
  }
143
148
 
144
149
  export function _outputJsonSync(filePath: string, data: any, opt?: JsonOptions): void {
145
- const str = JSON.stringify(data, null, opt?.spaces)
150
+ const str = stringify(data, opt)
146
151
  _outputFileSync(filePath, str)
147
152
  }
148
153