-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
352 additions
and
52 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,3 +55,4 @@ npm-debug.log | |
.directory | ||
._* | ||
*.iml | ||
examples/city |
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,7 @@ | ||
{{#if package.main}} | ||
## API-reference | ||
|
||
### `require("m-io/fs")` | ||
|
||
{{{jsdoc 'fs.js' '#'}}} | ||
{{/if}} |
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,19 @@ | ||
This package is a replacement for the functions of {{npm 'q-io'}} that I use in my projects. I have use `q-io/fs` a lot since it has functions | ||
like `makeTree`, `listTree` and `removeTree`. Furthermore, its `read` and `write` function work with strings by default, which makes it easier to | ||
read text files. | ||
|
||
Sadly, `q-io@1` depends on {{npm 'collections'}}@1, which | ||
[overwrites the function `Array.prototype.find` with an implementation that does not match the ES6-spec](https://github.com/montagejs/collections/issues/139). | ||
This causes problems in {{npm 'jsdoc-parse'}}. This is another example of why [modifying objects you don’t own][zakas dont modify] | ||
is a bad practice. | ||
|
||
This problem *could* be solved by using `q-io@2` instead of version 1. This version has [other problems](https://github.com/kriskowal/q-io/pull/155) which were | ||
solved in version 1. It may be a silly feeling, but version 2 of `q-io` vseems not to receive too much care at the moment. | ||
|
||
Since I do not use many functions, I have decided to write a drop-in replacement for my own purposes, and this is it: `m-io`. | ||
If you like this and want to provide more methods for your needs, please go ahead and make a PR. | ||
|
||
|
||
|
||
|
||
[zakas dont modify]: https://www.nczonline.net/blog/2010/03/02/maintainable-javascript-dont-modify-objects-you-down-own/ |
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,16 @@ | ||
{{#if (exists 'examples/example.js')}} | ||
|
||
## Usage | ||
|
||
The following example demonstrates how to use this module: | ||
|
||
{{{example 'examples/example.js'}}} | ||
|
||
This will generate the following output | ||
|
||
{{{exec 'node example.js' cwd='examples/'}}} | ||
{{/if}} | ||
|
||
After deleting `city/usa`, the `city`-subtree looks liks this: | ||
|
||
{{dirTree 'examples' 'city/**'}} |
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,25 @@ | ||
var FS = require('../fs') | ||
|
||
// Create some files | ||
FS.makeTree('city/germany') | ||
.then(() => FS.write('city/germany/darmstadt.md', 'Darmstadt is nice')) | ||
.then(() => FS.makeTree('city/usa')) | ||
.then(() => FS.write('city/usa/new-york.md', 'New York is huge')) | ||
.then(() => FS.makeTree('city/france')) | ||
.then(() => FS.write('city/france/paris.md', 'Olala')) | ||
|
||
// List files | ||
.then(() => FS.listTree('city', (filename, stats) => stats.isFile())) | ||
.then((filelist) => console.log('List files:', filelist.sort())) | ||
|
||
// List dirs and files | ||
.then(() => FS.listTree('city')) | ||
.then((list) => console.log('List dirs and files:', list.sort())) | ||
|
||
// Read file contents | ||
.then(() => FS.read('city/usa/new-york.md')) | ||
.then((nyc) => console.log('Read file contents:', nyc)) | ||
|
||
// Remove subdir | ||
.then(() => FS.removeTree('city/usa')) | ||
.done(() => console.log('Done')) |
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
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 @@ | ||
c |
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 @@ | ||
cc |
Oops, something went wrong.