@ms-cloudpack/json-utilities 0.1.7 → 0.1.9
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/lib/writeJson.d.ts.map +1 -1
- package/lib/writeJson.js +2 -3
- package/lib/writeJson.js.map +1 -1
- package/package.json +1 -2
- package/lib/tsdoc-metadata.json +0 -11
package/lib/writeJson.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"writeJson.d.ts","sourceRoot":"","sources":["../src/writeJson.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"writeJson.d.ts","sourceRoot":"","sources":["../src/writeJson.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAErD,MAAM,WAAW,gBAAiB,SAAQ,IAAI,CAAC,eAAe,EAAE,MAAM,CAAC;IACrE;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;;;;GAKG;AACH,wBAAsB,SAAS,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,GAAE,gBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CAmB9G;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,GAAE,gBAAqB,GAAG,IAAI,CAMnG"}
|
package/lib/writeJson.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import fs from 'fs';
|
|
2
|
-
import fsExtra from 'fs-extra';
|
|
3
2
|
import fsPromises from 'fs/promises';
|
|
4
3
|
import jju from 'jju';
|
|
5
4
|
import { JsonStreamStringify } from 'json-stream-stringify';
|
|
@@ -13,7 +12,7 @@ import { pipeline } from 'stream/promises';
|
|
|
13
12
|
*/
|
|
14
13
|
export async function writeJson(filePath, data, options = {}) {
|
|
15
14
|
const folderPath = path.dirname(filePath);
|
|
16
|
-
await
|
|
15
|
+
await fsPromises.mkdir(folderPath, { recursive: true });
|
|
17
16
|
let contents;
|
|
18
17
|
try {
|
|
19
18
|
contents = (options.fileHeaderComment ?? '') + stringify(filePath, data, options);
|
|
@@ -34,7 +33,7 @@ export async function writeJson(filePath, data, options = {}) {
|
|
|
34
33
|
*/
|
|
35
34
|
export function writeJsonSync(filePath, data, options = {}) {
|
|
36
35
|
const folderPath = path.dirname(filePath);
|
|
37
|
-
|
|
36
|
+
fs.mkdirSync(folderPath, { recursive: true });
|
|
38
37
|
const contents = (options.fileHeaderComment ?? '') + stringify(filePath, data, options);
|
|
39
38
|
fs.writeFileSync(filePath, contents, 'utf8');
|
|
40
39
|
}
|
package/lib/writeJson.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"writeJson.js","sourceRoot":"","sources":["../src/writeJson.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,
|
|
1
|
+
{"version":3,"file":"writeJson.js","sourceRoot":"","sources":["../src/writeJson.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,UAAU,MAAM,aAAa,CAAC;AACrC,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAY3C;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,QAAgB,EAAE,IAAa,EAAE,UAA4B,EAAE;IAC7F,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAC1C,MAAM,UAAU,CAAC,KAAK,CAAC,UAAU,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CA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,CAAC;IAEjC,IAAI,MAAM,IAAI,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QACtC,MAAM,eAAe,GAAG,EAAE,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;QAC1D,OAAO,GAAG,CAAC,MAAM,CAAC,eAAe,EAAE,IAAI,EAAE;YACvC,IAAI,EAAE,IAAI,KAAK,YAAY,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM;YAC9C,MAAM,EAAE,CAAC;YACT,KAAK,EAAE,GAAG;YACV,UAAU,EAAE,IAAI;YAChB,iBAAiB,EAAE,IAAI;SACxB,CAAC,CAAC;IACL,CAAC;IAED,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC;AAC9C,CAAC","sourcesContent":["import fs from 'fs';\nimport fsPromises from 'fs/promises';\nimport jju from 'jju';\nimport { JsonStreamStringify } from 'json-stream-stringify';\nimport path from 'path';\nimport { pipeline } from 'stream/promises';\nimport type { ReadJsonOptions } from './readJson.js';\n\nexport interface WriteJsonOptions extends Pick<ReadJsonOptions, 'mode'> {\n /**\n * If true, read the file (if it exists) and preserve as much of the original formatting as possible.\n * (For files with comments, `mode: 'permissive'` must also be set.)\n */\n update?: boolean;\n fileHeaderComment?: string;\n}\n\n/**\n * Writes json to a path. Ensures the path exists.\n *\n * If the JSON is very large (causing a RangeError \"Invalid string length\"), it will fall back to\n * stringifying and writing the object using a stream, provided that `update` is false/unset.\n */\nexport async function writeJson(filePath: string, data: unknown, options: WriteJsonOptions = {}): Promise<void> {\n const folderPath = path.dirname(filePath);\n await fsPromises.mkdir(folderPath, { recursive: true });\n\n let contents: string | undefined;\n try {\n contents = (options.fileHeaderComment ?? '') + stringify(filePath, data, options);\n await fsPromises.writeFile(filePath, contents, 'utf8');\n } catch (err) {\n if (!contents && err instanceof RangeError && !options.update) {\n // It's a giant object, so try a stream\n await pipeline(\n new JsonStreamStringify(data, undefined, 2, true),\n fs.createWriteStream(filePath, { encoding: 'utf8' }),\n );\n } else {\n throw err;\n }\n }\n}\n\n/**\n * Synchronously writes json to a path. Ensures the path exists.\n */\nexport function writeJsonSync(filePath: string, data: unknown, options: WriteJsonOptions = {}): void {\n const folderPath = path.dirname(filePath);\n fs.mkdirSync(folderPath, { recursive: true });\n\n const contents = (options.fileHeaderComment ?? '') + stringify(filePath, data, options);\n fs.writeFileSync(filePath, contents, 'utf8');\n}\n\nfunction stringify(filePath: string, data: unknown, options: WriteJsonOptions): string {\n const { update, mode } = options;\n\n if (update && fs.existsSync(filePath)) {\n const originalContent = fs.readFileSync(filePath, 'utf8');\n return jju.update(originalContent, data, {\n mode: mode === 'permissive' ? 'json5' : 'json',\n indent: 2,\n quote: '\"',\n quote_keys: true,\n no_trailing_comma: true,\n });\n }\n\n return JSON.stringify(data, null, 2) + '\\n';\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/json-utilities",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"description": "Helpers for reading/writing json files.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"fs-extra": "^11.2.0",
|
|
18
17
|
"jju": "^1.4.0",
|
|
19
18
|
"json-stream-stringify": "^3.1.4"
|
|
20
19
|
},
|
package/lib/tsdoc-metadata.json
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
|
2
|
-
// It should be published with your NPM package. It should not be tracked by Git.
|
|
3
|
-
{
|
|
4
|
-
"tsdocVersion": "0.12",
|
|
5
|
-
"toolPackages": [
|
|
6
|
-
{
|
|
7
|
-
"packageName": "@microsoft/api-extractor",
|
|
8
|
-
"packageVersion": "7.47.0"
|
|
9
|
-
}
|
|
10
|
-
]
|
|
11
|
-
}
|