Comparing version 0.0.3 to 0.0.4
@@ -24,2 +24,3 @@ const fs = require('fs-promise'); | ||
remove, | ||
delete: remove, | ||
}; |
@@ -19,2 +19,14 @@ const fs = require('fs-promise'); | ||
function read(file, options = {}) { | ||
const opts = Object.assign({}, options); | ||
if (!opts.encoding) { | ||
opts.encoding = 'utf8'; | ||
} | ||
return fs.readFile(file, opts); | ||
} | ||
function write(file, data, options) { | ||
return fs.outputFile(file, data, options); | ||
} | ||
module.exports = { | ||
@@ -25,2 +37,5 @@ path, | ||
remove, | ||
delete: remove, | ||
read, | ||
write, | ||
}; |
{ | ||
"name": "io-extra", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -38,2 +38,4 @@ # io-extra | ||
- [remove](#remove-file) | ||
- [read](#read-file) | ||
- [write](#write-file) | ||
@@ -91,2 +93,4 @@ ### resolve fullpath | ||
Alias: `delete()` | ||
Example: | ||
@@ -100,6 +104,45 @@ | ||
### read file | ||
**read(file, [encoding])** | ||
Reads the entire contents of a file. | ||
Promise contains the text of the file. | ||
encoding = (optional string) specifies the type of encoding to read the file. Possible encodings are 'ascii', 'utf8', and 'base64'. If no encoding is provided, the default is utf8. | ||
Example: | ||
```js | ||
const io = require('io-extra'); | ||
io.file.read('/tmp/myfile').then((text) => console.log(text)); | ||
``` | ||
### write file | ||
**write(file, data, [encoding])** | ||
Writes data to a file, replacing the file if it already exists. | ||
If the parent directory does not exist, it's created. | ||
Empty promise is returned. | ||
file = (string) filepath of the file to write to. | ||
data = (string or buffer) the data you want to write to the file. | ||
encoding = (optional string) the encoding of the data. Possible encodings are 'ascii', 'utf8', and 'base64'. If no encoding provided, then 'utf8' is assumed. | ||
Example: | ||
```js | ||
const io = require('io-extra'); | ||
io.file.write('/tmp/myfile', 'io-extra is easy!').then(() => console.log('file written.')); | ||
``` | ||
Directory | ||
------- | ||
- [path](#resolve-fullpath) | ||
- [path](#resolve-directory-fullpath) | ||
- [exists](#directory-exists) | ||
@@ -109,3 +152,3 @@ - [create](#create-directory) | ||
### resolve fullpath | ||
### resolve directory fullpath | ||
**path(directory)** | ||
@@ -161,2 +204,4 @@ | ||
Alias: `delete()` | ||
Example: | ||
@@ -163,0 +208,0 @@ |
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
7312
209
0
8
60