diff options
author | 张超杰 <1098626505@qq.com> | 2020-05-01 02:32:44 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-30 14:32:44 -0400 |
commit | 21f4c7f35c4a7d53e7aca1e531a362e881924edb (patch) | |
tree | 969ec0b3d0d7d060e1cf028c9abc1f2ccdc8c4a6 /std/fs | |
parent | f79cb08e0b9afa7609a353a464e0876d8c8a593c (diff) |
doc(std/fs): README.md (#4913)
Diffstat (limited to 'std/fs')
-rw-r--r-- | std/fs/README.md | 38 |
1 files changed, 19 insertions, 19 deletions
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 |