Comparing version 0.0.7 to 0.0.8
@@ -19,2 +19,18 @@ const fs = require('fs-promise'); | ||
function rename(src, dest, overwrite = true) { | ||
const func = () => fs.rename(src, dest).then(() => path(dest)); | ||
if (overwrite) { | ||
return func(); | ||
} | ||
return exists(dest).then((alreadyExists) => { | ||
if (alreadyExists) { | ||
return path(dest); | ||
} | ||
return func(); | ||
}); | ||
} | ||
function copy(src, dest, options = {}) { | ||
@@ -42,3 +58,4 @@ const opts = Object.keys(options) | ||
delete: remove, | ||
rename, | ||
copy, | ||
}; |
{ | ||
"name": "io-extra", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -197,2 +197,3 @@ # io-extra | ||
- [remove](#remove-directory) | ||
- [rename](#rename-directory) | ||
- [copy](#copy-directory) | ||
@@ -263,2 +264,19 @@ | ||
### rename directory | ||
**rename(src, dest, [overwrite])** | ||
Renames a directory. Promise returns the full path of the destination directory. | ||
- overwrite: (optional boolean) overwrite existing directory, default is `true`. | ||
Example: | ||
```js | ||
const io = require('io-extra'); | ||
io.directory.rename('/tmp', '/bak') | ||
.then((directory) => console.log('directory renamed to ' + directory)); | ||
``` | ||
### copy directory | ||
@@ -265,0 +283,0 @@ |
11706
108
308