-
Notifications
You must be signed in to change notification settings - Fork 633
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
doc: Add missing documentation #336
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
# fs | ||
|
||
fs module is made to provide helpers to manipulate the filesystem. | ||
|
||
## Usage | ||
|
||
All the following modules are exposed in `mod.ts` | ||
|
||
### emptyDir | ||
|
||
Ensures that a directory is empty. Deletes directory contents if the directory is not empty. | ||
If the directory does not exist, it is created. | ||
The directory itself is not deleted. | ||
|
||
```ts | ||
import { emptyDir, emptyDirSync } from "https://deno.land/std/fs/mod.ts"; | ||
|
||
emptyDir("./foo"); // returns a promise | ||
emptyDirSync("./foo"); // void | ||
``` | ||
|
||
### ensureDir | ||
|
||
Ensures that the directory exists. | ||
If the directory structure does not exist, it is created. Like mkdir -p. | ||
|
||
```ts | ||
import { ensureDir, ensureDirSync } from "https://deno.land/std/fs/mod.ts"; | ||
|
||
ensureDir("./bar"); // returns a promise | ||
ensureDirSync("./ensureDirSync"); // void | ||
``` | ||
|
||
### ensure_file | ||
|
||
Ensures that the file exists. | ||
If the file that is requested to be created is in directories | ||
that do not exist, these directories are created. | ||
If the file already exists, it is **NOT MODIFIED**. | ||
|
||
```ts | ||
import { ensureFile, ensureFileSync } from "https://deno.land/std/fs/mod.ts"; | ||
|
||
ensureFile("./folder/targetFile.dat"); // returns promise | ||
ensureFileSync("./folder/targetFile.dat"); // void | ||
``` | ||
|
||
### eol | ||
|
||
Detects and format the passed string for the targeted End Of Line character. | ||
|
||
```ts | ||
import { format, detect, EOL } from "https://deno.land/std/fs/mod.ts"; | ||
|
||
const CRLFinput = "deno\r\nis not\r\nnode"; | ||
const Mixedinput = "deno\nis not\r\nnode"; | ||
const LFinput = "deno\nis not\nnode"; | ||
const NoNLinput = "deno is not node"; | ||
|
||
detect(LFinput); // output EOL.LF | ||
detect(CRLFinput); // output EOL.CRLF | ||
detect(Mixedinput); // output EOL.CRLF | ||
detect(NoNLinput); // output null | ||
|
||
format(CRLFinput, EOL.LF); // output "deno\nis not\nnode" | ||
... | ||
``` | ||
|
||
### exists | ||
|
||
Test whether or not the given path exists by checking with the file system | ||
|
||
```ts | ||
import { exists, existsSync } from "https://deno.land/std/fs/mod.ts"; | ||
|
||
exists("./foo"); // returns a Promise<boolean> | ||
existsSync("./foo"); // returns boolean | ||
``` | ||
|
||
### glob | ||
|
||
Generate a regex based on glob pattern and options | ||
This was meant to be using the the `fs.walk` function | ||
but can be used anywhere else. | ||
|
||
```ts | ||
import { glob } from "https://deno.land/std/fs/mod.ts"; | ||
|
||
glob("foo/**/*.json", { | ||
flags: "g", | ||
extended: true, | ||
globstar: true | ||
}); // returns the regex to find all .json files in the folder foo | ||
``` | ||
|
||
### move | ||
|
||
Moves a file or directory. Overwrites it if option provided | ||
|
||
```ts | ||
import { move, moveSync } from "https://deno.land/std/fs/mod.ts"; | ||
|
||
move("./foo", "./bar"); // returns a promise | ||
moveSync("./foo", "./bar"); // void | ||
moveSync("./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"); | ||
``` | ||
|
||
### walk | ||
|
||
Iterate all files in a directory recursively. | ||
|
||
```ts | ||
import { walk, walkSync } from "https://deno.land/std/fs/mod.ts"; | ||
|
||
for (const fileInfo of walkSync()) { | ||
console.log(fileInfo.path); | ||
} | ||
|
||
// Async | ||
for (const fileInfo of walk()) { | ||
console.log(fileInfo.path); | ||
} | ||
``` | ||
|
||
### 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 | ||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here should be
ensureFile