Skip to content

Commit

Permalink
Add missing examples
Browse files Browse the repository at this point in the history
  • Loading branch information
nknapp committed Dec 19, 2016
1 parent 8618a38 commit a2f6d7a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ FS.makeTree('city/germany')
.then(() => FS.makeTree('city/france'))
.then(() => FS.write('city/france/paris.md', 'Olala'))

// Existance of files
.then(() => FS.exists('city'))
.then((exists) => console.log('Directory city exists?', exists))

.then(() => FS.exists('something-else'))
.then((exists) => console.log('Directory something-else exists?', exists))

// Directory listings
.then(() => FS.list('city'))
.then((list) => console.log("Directory entries of city", list.sort()))

// List files
.then(() => FS.listTree('city', (filename, stats) => stats.isFile()))
.then((filelist) => console.log('List files:', filelist.sort()))
Expand All @@ -68,6 +79,9 @@ FS.makeTree('city/germany')
This will generate the following output

```
Directory city exists? true
Directory something-else exists? false
Directory entries of city [ 'france', 'germany', 'usa' ]
List files: [ 'city/france/paris.md',
'city/germany/darmstadt.md',
'city/usa/new-york.md' ]
Expand Down Expand Up @@ -101,11 +115,25 @@ city
## fs

* [fs](#module_fs)
* [.exists(existsPath)](#module_fs.exists) ⇒ <code>Promise.&lt;boolean&gt;</code>
* [.listTree(directoryPath, filter)](#module_fs.listTree) ⇒ <code>Promise.&lt;Array.&lt;string&gt;&gt;</code>
* [.list(directoryPath)](#module_fs.list) ⇒ <code>Promise.&lt;Array.&lt;string&gt;&gt;</code>
* [.makeTree(aPath, [mode])](#module_fs.makeTree)
* [.read(aPath)](#module_fs.read)

<a name="module_fs.exists"></a>

### .exists(existsPath) ⇒ <code>Promise.&lt;boolean&gt;</code>
Custom implementation of [q-io/fs#exists](http://documentup.com/kriskowal/q-io#lexistsPath)
to avoid dependency on q-io

**Kind**: static method of <code>[fs](#module_fs)</code>
**Returns**: <code>Promise.&lt;boolean&gt;</code> - a promise for the existance (true/false) of the file/dir at the path

| Param | Type | Description |
| --- | --- | --- |
| existsPath | <code>string</code> | the path to check |

<a name="module_fs.listTree"></a>

### .listTree(directoryPath, filter) ⇒ <code>Promise.&lt;Array.&lt;string&gt;&gt;</code>
Expand Down
11 changes: 11 additions & 0 deletions examples/example.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ FS.makeTree('city/germany')
.then(() => FS.makeTree('city/france'))
.then(() => FS.write('city/france/paris.md', 'Olala'))

// Existance of files
.then(() => FS.exists('city'))
.then((exists) => console.log('Directory city exists?', exists))

.then(() => FS.exists('something-else'))
.then((exists) => console.log('Directory something-else exists?', exists))

// Directory listings
.then(() => FS.list('city'))
.then((list) => console.log('Directory entries of city', list.sort()))

// List files
.then(() => FS.listTree('city', (filename, stats) => stats.isFile()))
.then((filelist) => console.log('List files:', filelist.sort()))
Expand Down

0 comments on commit a2f6d7a

Please sign in to comment.