1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-22 23:34:47 -05:00

doc(std/fs): README.md (#4913)

This commit is contained in:
张超杰 2020-05-01 02:32:44 +08:00 committed by GitHub
parent f79cb08e0b
commit 21f4c7f35c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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