@ms-cloudpack/json-utilities 0.0.3 → 0.0.5

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/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { readJson, readJsonSync } from './readJson.js';
2
+ export { writeJson, writeJsonSync } from './writeJson.js';
package/lib/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { readJson, readJsonSync } from './readJson.js';
2
+ export { writeJson, writeJsonSync } from './writeJson.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Reads JSON from a path and returns the object, or undefined if it does not exist or is unparsable.
3
+ */
4
+ export declare function readJson<TData>(path: string): Promise<TData | undefined>;
5
+ /**
6
+ * Synchronously reads JSON from a path and returns the object, or undefined if it does not exist
7
+ * or is unparsable.
8
+ */
9
+ export declare function readJsonSync<TData>(path: string): TData | undefined;
@@ -0,0 +1,30 @@
1
+ import fs from 'fs';
2
+ const { readFile } = fs.promises;
3
+ /**
4
+ * Reads JSON from a path and returns the object, or undefined if it does not exist or is unparsable.
5
+ */
6
+ export async function readJson(path) {
7
+ let result = undefined;
8
+ try {
9
+ result = JSON.parse(await readFile(path, 'utf8'));
10
+ }
11
+ catch {
12
+ /* no-op */
13
+ }
14
+ return result;
15
+ }
16
+ /**
17
+ * Synchronously reads JSON from a path and returns the object, or undefined if it does not exist
18
+ * or is unparsable.
19
+ */
20
+ export function readJsonSync(path) {
21
+ let result = undefined;
22
+ try {
23
+ result = JSON.parse(fs.readFileSync(path, 'utf8'));
24
+ }
25
+ catch {
26
+ /* no-op */
27
+ }
28
+ return result;
29
+ }
30
+ //# sourceMappingURL=readJson.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readJson.js","sourceRoot":"","sources":["../src/readJson.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AAEpB,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC;AAEjC;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAQ,IAAY;IAChD,IAAI,MAAM,GAAsB,SAAS,CAAC;IAE1C,IAAI;QACF,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC,CAAU,CAAC;KAC5D;IAAC,MAAM;QACN,WAAW;KACZ;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,YAAY,CAAQ,IAAY;IAC9C,IAAI,MAAM,GAAsB,SAAS,CAAC;IAE1C,IAAI;QACF,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAU,CAAC;KAC7D;IAAC,MAAM;QACN,WAAW;KACZ;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,11 @@
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.34.3"
9
+ }
10
+ ]
11
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Writes json to a path. Ensures the path exists.
3
+ */
4
+ export declare function writeJson(filePath: string, data: any): Promise<void>;
5
+ /**
6
+ * Synchronously writes json to a path. Ensures the path exists.
7
+ */
8
+ export declare function writeJsonSync(filePath: string, data: any): void;
@@ -0,0 +1,23 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { ensureDir, ensureDirSync } from 'fs-extra';
4
+ const { writeFile } = fs.promises;
5
+ /**
6
+ * Writes json to a path. Ensures the path exists.
7
+ */
8
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
9
+ export async function writeJson(filePath, data) {
10
+ const folderPath = path.dirname(filePath);
11
+ await ensureDir(folderPath);
12
+ await writeFile(filePath, JSON.stringify(data, null, 2), 'utf8');
13
+ }
14
+ /**
15
+ * Synchronously writes json to a path. Ensures the path exists.
16
+ */
17
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
+ export function writeJsonSync(filePath, data) {
19
+ const folderPath = path.dirname(filePath);
20
+ ensureDirSync(folderPath);
21
+ fs.writeFileSync(filePath, JSON.stringify(data, null, 2), 'utf8');
22
+ }
23
+ //# sourceMappingURL=writeJson.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writeJson.js","sourceRoot":"","sources":["../src/writeJson.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEpD,MAAM,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,QAAQ,CAAC;AAElC;;GAEG;AACH,8DAA8D;AAC9D,MAAM,CAAC,KAAK,UAAU,SAAS,CAAC,QAAgB,EAAE,IAAS;IACzD,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAE1C,MAAM,SAAS,CAAC,UAAU,CAAC,CAAC;IAC5B,MAAM,SAAS,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AACnE,CAAC;AAED;;GAEG;AACH,8DAA8D;AAC9D,MAAM,UAAU,aAAa,CAAC,QAAgB,EAAE,IAAS;IACvD,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAE1C,aAAa,CAAC,UAAU,CAAC,CAAC;IAC1B,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AACpE,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,8 @@
1
1
  {
2
2
  "name": "@ms-cloudpack/json-utilities",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "Helpers for reading/writing json files.",
5
+ "license": "MIT",
5
6
  "type": "module",
6
7
  "types": "./lib/index.d.ts",
7
8
  "sideEffects": false,
@@ -12,20 +13,21 @@
12
13
  }
13
14
  },
14
15
  "dependencies": {
15
- "fs-extra": "^10.1.0"
16
+ "fs-extra": "^11.0.0"
16
17
  },
17
18
  "devDependencies": {
18
19
  "@ms-cloudpack/eslint-config-base": "*",
19
- "@ms-cloudpack/scripts": "*",
20
- "@types/fs-extra": "9.0.13"
20
+ "@ms-cloudpack/scripts": "*"
21
21
  },
22
22
  "scripts": {
23
- "build": "just-scripts build",
24
- "build:watch": "just-scripts build:watch",
25
- "lint": "just-scripts lint",
26
- "lint:fix": "just-scripts lint:fix"
23
+ "api:update": "cloudpack-scripts api-update",
24
+ "api": "cloudpack-scripts api",
25
+ "build:watch": "cloudpack-scripts build-watch",
26
+ "build": "cloudpack-scripts build",
27
+ "lint:update": "cloudpack-scripts lint-update",
28
+ "lint": "cloudpack-scripts lint"
27
29
  },
28
30
  "files": [
29
- "/lib"
31
+ "lib/**/!(*.test.*)"
30
32
  ]
31
33
  }
package/CHANGELOG.json DELETED
@@ -1,43 +0,0 @@
1
- {
2
- "name": "@ms-cloudpack/json-utilities",
3
- "entries": [
4
- {
5
- "date": "Mon, 09 May 2022 23:39:20 GMT",
6
- "tag": "@ms-cloudpack/json-utilities_v0.0.3",
7
- "version": "0.0.3",
8
- "comments": {
9
- "none": [
10
- {
11
- "author": "dzearing@microsoft.com",
12
- "package": "@ms-cloudpack/json-utilities",
13
- "commit": "e68680ba160469e2aad19a0c1ef20de03bced434",
14
- "comment": "removing changes."
15
- }
16
- ],
17
- "patch": [
18
- {
19
- "author": "bot@renovateapp.com",
20
- "package": "@ms-cloudpack/json-utilities",
21
- "commit": "e68680ba160469e2aad19a0c1ef20de03bced434",
22
- "comment": "Cleaning up problems found with depcheck"
23
- }
24
- ]
25
- }
26
- },
27
- {
28
- "date": "Mon, 09 May 2022 18:54:56 GMT",
29
- "tag": "@ms-cloudpack/json-utilities_v0.0.2",
30
- "version": "0.0.2",
31
- "comments": {
32
- "patch": [
33
- {
34
- "author": "dzearing@microsoft.com",
35
- "package": "@ms-cloudpack/json-utilities",
36
- "commit": "13c322180c016e6c653d4694b9f3380adeb8ad6f",
37
- "comment": "Initial publish."
38
- }
39
- ]
40
- }
41
- }
42
- ]
43
- }
package/CHANGELOG.md DELETED
@@ -1,21 +0,0 @@
1
- # Change Log - @ms-cloudpack/json-utilities
2
-
3
- This log was last generated on Mon, 09 May 2022 23:39:20 GMT and should not be manually modified.
4
-
5
- <!-- Start content -->
6
-
7
- ## 0.0.3
8
-
9
- Mon, 09 May 2022 23:39:20 GMT
10
-
11
- ### Patches
12
-
13
- - Cleaning up problems found with depcheck (bot@renovateapp.com)
14
-
15
- ## 0.0.2
16
-
17
- Mon, 09 May 2022 18:54:56 GMT
18
-
19
- ### Patches
20
-
21
- - Initial publish. (dzearing@microsoft.com)