-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
45 lines (37 loc) · 983 Bytes
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const fs = require('./');
// 1. Read file text.
async function example1() {
var text = fs.readFileTextSync('.npmignore');
var text = await fs.readFileText('.npmignore');
// → # Source only
// → .gitmodules
// → .github/
// → .docs/
// → ...
}
// example1();
// 2. Read JSON file.
async function example2() {
var json = fs.readJsonSync('package.json');
var json = await fs.readJson('package.json');
// → {
// → name: 'extra-fs',
// → version: '3.0.27',
// → description: 'Useful additions to inbuilt fs module.',
// → ...
// → }
}
// example2();
// 3. Assert that a file exists.
async function example3() {
if (!(await fs.exists('LICENSE'))) throw 'May I see you license sir?';
await fs.assertExists('LICENSE');
}
// example3();
// 4. Get contents of a directory.
async function example4() {
var contents = fs.readdirSync('src');
var contents = await fs.readdir('src');
// → [ 'index.ts' ]
}
example4();