From 21f4c7f35c4a7d53e7aca1e531a362e881924edb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E8=B6=85=E6=9D=B0?= <1098626505@qq.com> Date: Fri, 1 May 2020 02:32:44 +0800 Subject: doc(std/fs): README.md (#4913) --- std/fs/README.md | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'std/fs') diff --git a/std/fs/README.md b/std/fs/README.md index 8d1be54bf..288f1922f 100644 --- a/std/fs/README.md +++ b/std/fs/README.md @@ -143,6 +143,24 @@ const f = await readJson("./foo.json"); const foo = readJsonSync("./foo.json"); ``` +### writeJson + +Writes an object to a JSON file. + +**WriteJsonOptions** + +- replacer : An array of strings and numbers that acts as a approved list for + selecting the object properties that will be stringified. +- space : Adds indentation, white space, and line break characters to the + return-value JSON text to make it easier to read. + +```ts +import { writeJson, writeJsonSync } from "https://deno.land/std/fs/mod.ts"; + +writeJson("./target.dat", { foo: "bar" }, { spaces: 2 }); // returns a promise +writeJsonSync("./target.dat", { foo: "bar" }, { replacer: ["foo"] }); // void +``` + ### walk Iterate all files in a directory recursively. @@ -164,24 +182,6 @@ async function printFilesNames() { printFilesNames().then(() => console.log("Done!")); ``` -### writeJson - -Writes an object to a JSON file. - -**WriteJsonOptions** - -- replacer : An array of strings and numbers that acts as a approved list for - selecting the object properties that will be stringified. -- space : Adds indentation, white space, and line break characters to the - return-value JSON text to make it easier to read. - -```ts -import { writeJson, writeJsonSync } from "https://deno.land/std/fs/mod.ts"; - -writeJson("./target.dat", { foo: "bar" }, { spaces: 2 }); // returns a promise -writeJsonSync("./target.dat", { foo: "bar" }, { replacer: ["foo"] }); // void -``` - ### readFileStr Read file and output it as a string. @@ -194,7 +194,7 @@ Read file and output it as a string. import { readFileStr, readFileStrSync } from "https://deno.land/std/fs/mod.ts"; readFileStr("./target.dat", { encoding: "utf8" }); // returns a promise -readFileStrSync("./target.dat", { encoding: "utf8" }); // void +readFileStrSync("./target.dat", { encoding: "utf8" }); // string ``` ### writeFileStr -- cgit v1.2.3