mirror of
https://github.com/denoland/std.git
synced 2024-11-22 04:59:05 +00:00
remove unnecessary path.resolve in move/readJson/writeJson (#292)
This commit is contained in:
parent
59adafe867
commit
a00c51b05b
@ -1,5 +1,4 @@
|
||||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||
import * as path from "./path/mod.ts";
|
||||
import { exists, existsSync } from "./exists.ts";
|
||||
import { isSubdir } from "./utils.ts";
|
||||
|
||||
@ -13,9 +12,6 @@ export async function move(
|
||||
dest: string,
|
||||
options?: MoveOptions
|
||||
): Promise<void> {
|
||||
src = path.resolve(src);
|
||||
dest = path.resolve(dest);
|
||||
|
||||
const srcStat = await Deno.stat(src);
|
||||
|
||||
if (srcStat.isDirectory() && isSubdir(src, dest)) {
|
||||
@ -43,9 +39,6 @@ export function moveSync(
|
||||
dest: string,
|
||||
options?: MoveOptions
|
||||
): void {
|
||||
src = path.resolve(src);
|
||||
dest = path.resolve(dest);
|
||||
|
||||
const srcStat = Deno.statSync(src);
|
||||
|
||||
if (srcStat.isDirectory() && isSubdir(src, dest)) {
|
||||
|
@ -1,9 +1,7 @@
|
||||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||
import * as path from "./path/mod.ts";
|
||||
|
||||
/** Reads a JSON file and then parses it into an object */
|
||||
export async function readJson(filePath: string): Promise<any> {
|
||||
filePath = path.resolve(filePath);
|
||||
const decoder = new TextDecoder("utf-8");
|
||||
|
||||
const content = decoder.decode(await Deno.readFile(filePath));
|
||||
@ -18,7 +16,6 @@ export async function readJson(filePath: string): Promise<any> {
|
||||
|
||||
/** Reads a JSON file and then parses it into an object */
|
||||
export function readJsonSync(filePath: string): any {
|
||||
filePath = path.resolve(filePath);
|
||||
const decoder = new TextDecoder("utf-8");
|
||||
|
||||
const content = decoder.decode(Deno.readFileSync(filePath));
|
||||
|
@ -34,7 +34,7 @@ test(async function readInvalidJsonFile() {
|
||||
});
|
||||
});
|
||||
|
||||
test(async function readValidJsonFile() {
|
||||
test(async function readValidArrayJsonFile() {
|
||||
const invalidJsonFile = path.join(testdataDir, "json_valid_array.json");
|
||||
|
||||
const json = await readJson(invalidJsonFile);
|
||||
@ -42,7 +42,7 @@ test(async function readValidJsonFile() {
|
||||
assertEquals(json, ["1", "2", "3"]);
|
||||
});
|
||||
|
||||
test(async function readValidJsonFile() {
|
||||
test(async function readValidObjJsonFile() {
|
||||
const invalidJsonFile = path.join(testdataDir, "json_valid_obj.json");
|
||||
|
||||
const json = await readJson(invalidJsonFile);
|
||||
@ -50,6 +50,12 @@ test(async function readValidJsonFile() {
|
||||
assertEquals(json, { key1: "value1", key2: "value2" });
|
||||
});
|
||||
|
||||
test(async function readValidObjJsonFileWithRelativePath() {
|
||||
const json = await readJson("./fs/testdata/json_valid_obj.json");
|
||||
|
||||
assertEquals(json, { key1: "value1", key2: "value2" });
|
||||
});
|
||||
|
||||
test(function readJsonFileNotExistsSync() {
|
||||
const emptyJsonFile = path.join(testdataDir, "json_not_exists.json");
|
||||
|
||||
@ -74,7 +80,7 @@ test(function readInvalidJsonFile() {
|
||||
});
|
||||
});
|
||||
|
||||
test(function readValidJsonFile() {
|
||||
test(function readValidArrayJsonFileSync() {
|
||||
const invalidJsonFile = path.join(testdataDir, "json_valid_array.json");
|
||||
|
||||
const json = readJsonSync(invalidJsonFile);
|
||||
@ -82,10 +88,16 @@ test(function readValidJsonFile() {
|
||||
assertEquals(json, ["1", "2", "3"]);
|
||||
});
|
||||
|
||||
test(function readValidJsonFile() {
|
||||
test(function readValidObjJsonFileSync() {
|
||||
const invalidJsonFile = path.join(testdataDir, "json_valid_obj.json");
|
||||
|
||||
const json = readJsonSync(invalidJsonFile);
|
||||
|
||||
assertEquals(json, { key1: "value1", key2: "value2" });
|
||||
});
|
||||
|
||||
test(function readValidObjJsonFileSyncWithRelativePath() {
|
||||
const json = readJsonSync("./fs/testdata/json_valid_obj.json");
|
||||
|
||||
assertEquals(json, { key1: "value1", key2: "value2" });
|
||||
});
|
||||
|
@ -1,6 +1,5 @@
|
||||
// Copyright 2018-2019 the Deno authors. All rights reserved. MIT license.
|
||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||
import * as path from "./path/mod.ts";
|
||||
type Replacer = (key: string, value: any) => any;
|
||||
|
||||
export interface WriteJsonOptions {
|
||||
@ -14,8 +13,6 @@ export async function writeJson(
|
||||
object: any,
|
||||
options: WriteJsonOptions = {}
|
||||
): Promise<void> {
|
||||
filePath = path.resolve(filePath);
|
||||
|
||||
let contentRaw = "";
|
||||
|
||||
try {
|
||||
@ -38,8 +35,6 @@ export function writeJsonSync(
|
||||
object: any,
|
||||
options: WriteJsonOptions = {}
|
||||
): void {
|
||||
filePath = path.resolve(filePath);
|
||||
|
||||
let contentRaw = "";
|
||||
|
||||
try {
|
||||
|
Loading…
Reference in New Issue
Block a user