summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCasper Beyer <caspervonb@pm.me>2020-09-08 00:04:29 +0800
committerGitHub <noreply@github.com>2020-09-07 18:04:29 +0200
commitd4b6b25def76f5891b953266692e2a98bc302c1c (patch)
tree19390fa46e02fa118b1eaee21c7d3273a333bcb6
parent1cd226750065e6101c0a38694ff9f96a40b437d0 (diff)
BREAKING(std/fs): remove readJson and readJsonSync (#7255)
-rw-r--r--std/fs/README.md11
-rw-r--r--std/fs/mod.ts1
-rw-r--r--std/fs/read_json.ts29
-rw-r--r--std/fs/read_json_test.ts110
4 files changed, 0 insertions, 151 deletions
diff --git a/std/fs/README.md b/std/fs/README.md
index b31d20814..48fc55675 100644
--- a/std/fs/README.md
+++ b/std/fs/README.md
@@ -118,17 +118,6 @@ copySync("./foo", "./existingFolder", { overwrite: true });
// Will overwrite existingFolder
```
-### readJson
-
-Reads a JSON file and then parses it into an object
-
-```ts
-import { readJson, readJsonSync } from "https://deno.land/std/fs/mod.ts";
-
-const f = await readJson("./foo.json");
-const foo = readJsonSync("./foo.json");
-```
-
### writeJson
Writes an object to a JSON file.
diff --git a/std/fs/mod.ts b/std/fs/mod.ts
index e49d24bac..2e39146a9 100644
--- a/std/fs/mod.ts
+++ b/std/fs/mod.ts
@@ -8,7 +8,6 @@ export * from "./exists.ts";
export * from "./expand_glob.ts";
export * from "./move.ts";
export * from "./copy.ts";
-export * from "./read_json.ts";
export * from "./write_json.ts";
export * from "./walk.ts";
export * from "./eol.ts";
diff --git a/std/fs/read_json.ts b/std/fs/read_json.ts
deleted file mode 100644
index aa7a0a477..000000000
--- a/std/fs/read_json.ts
+++ /dev/null
@@ -1,29 +0,0 @@
-// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-
-/** Reads a JSON file and then parses it into an object */
-export async function readJson(filePath: string): Promise<unknown> {
- const decoder = new TextDecoder("utf-8");
-
- const content = decoder.decode(await Deno.readFile(filePath));
-
- try {
- return JSON.parse(content);
- } catch (err) {
- err.message = `${filePath}: ${err.message}`;
- throw err;
- }
-}
-
-/** Reads a JSON file and then parses it into an object */
-export function readJsonSync(filePath: string): unknown {
- const decoder = new TextDecoder("utf-8");
-
- const content = decoder.decode(Deno.readFileSync(filePath));
-
- try {
- return JSON.parse(content);
- } catch (err) {
- err.message = `${filePath}: ${err.message}`;
- throw err;
- }
-}
diff --git a/std/fs/read_json_test.ts b/std/fs/read_json_test.ts
deleted file mode 100644
index c910c6334..000000000
--- a/std/fs/read_json_test.ts
+++ /dev/null
@@ -1,110 +0,0 @@
-// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
-import {
- assertEquals,
- assertThrowsAsync,
- assertThrows,
-} from "../testing/asserts.ts";
-import * as path from "../path/mod.ts";
-import { readJson, readJsonSync } from "./read_json.ts";
-
-const testdataDir = path.resolve("fs", "testdata");
-
-Deno.test("readJsonFileNotExists", async function (): Promise<void> {
- const emptyJsonFile = path.join(testdataDir, "json_not_exists.json");
-
- await assertThrowsAsync(
- async (): Promise<void> => {
- await readJson(emptyJsonFile);
- },
- );
-});
-
-Deno.test("readEmptyJsonFile", async function (): Promise<void> {
- const emptyJsonFile = path.join(testdataDir, "json_empty.json");
-
- await assertThrowsAsync(
- async (): Promise<void> => {
- await readJson(emptyJsonFile);
- },
- );
-});
-
-Deno.test("readInvalidJsonFile", async function (): Promise<void> {
- const invalidJsonFile = path.join(testdataDir, "json_invalid.json");
-
- await assertThrowsAsync(
- async (): Promise<void> => {
- await readJson(invalidJsonFile);
- },
- );
-});
-
-Deno.test("readValidArrayJsonFile", async function (): Promise<void> {
- const invalidJsonFile = path.join(testdataDir, "json_valid_array.json");
-
- const json = await readJson(invalidJsonFile);
-
- assertEquals(json, ["1", "2", "3"]);
-});
-
-Deno.test("readValidObjJsonFile", async function (): Promise<void> {
- const invalidJsonFile = path.join(testdataDir, "json_valid_obj.json");
-
- const json = await readJson(invalidJsonFile);
-
- assertEquals(json, { key1: "value1", key2: "value2" });
-});
-
-Deno.test("readValidObjJsonFileWithRelativePath", async function (): Promise<
- void
-> {
- const json = await readJson("./fs/testdata/json_valid_obj.json");
-
- assertEquals(json, { key1: "value1", key2: "value2" });
-});
-
-Deno.test("readJsonFileNotExistsSync", function (): void {
- const emptyJsonFile = path.join(testdataDir, "json_not_exists.json");
-
- assertThrows((): void => {
- readJsonSync(emptyJsonFile);
- });
-});
-
-Deno.test("readEmptyJsonFileSync", function (): void {
- const emptyJsonFile = path.join(testdataDir, "json_empty.json");
-
- assertThrows((): void => {
- readJsonSync(emptyJsonFile);
- });
-});
-
-Deno.test("readInvalidJsonFile", function (): void {
- const invalidJsonFile = path.join(testdataDir, "json_invalid.json");
-
- assertThrows((): void => {
- readJsonSync(invalidJsonFile);
- });
-});
-
-Deno.test("readValidArrayJsonFileSync", function (): void {
- const invalidJsonFile = path.join(testdataDir, "json_valid_array.json");
-
- const json = readJsonSync(invalidJsonFile);
-
- assertEquals(json, ["1", "2", "3"]);
-});
-
-Deno.test("readValidObjJsonFileSync", function (): void {
- const invalidJsonFile = path.join(testdataDir, "json_valid_obj.json");
-
- const json = readJsonSync(invalidJsonFile);
-
- assertEquals(json, { key1: "value1", key2: "value2" });
-});
-
-Deno.test("readValidObjJsonFileSyncWithRelativePath", function (): void {
- const json = readJsonSync("./fs/testdata/json_valid_obj.json");
-
- assertEquals(json, { key1: "value1", key2: "value2" });
-});