0.0.1-next.4 • Published 3 years ago
@hexatool/fs-copy v0.0.1-next.4
Installation
npm install --save @hexatool/fs-copyUsing yarn
yarn add @hexatool/fs-copyWhat it does
Copy a file or directory. The directory can have contents.
API
copy(src: string, dest: string, options?: CopyOptions): void
src- Type:
string. - Optional:
false. - Note: If
srcis a directory it will copy everything inside of this directory, not the entire directory itself.
- Type:
dest.- Type:
string. - Optional:
false. - Note: If
srcis a file,destcannot be a directory.
- Type:
options.- Type:
CopyOptions. - Optional:
true.
- Type:
CopyOptions
dereference. Dereference symlinks.- Type:
boolean. - Optional:
true. - Default
false.
- Type:
filter. Function to filter copied files/directories. Returntrueto copy the item,falseto ignore it.- Type:
(src: string, dest: string) => boolean. - Optional:
true.
- Type:
errorOnExist. Whenoverwriteisfalseand the destination exists, throw an error.- Type:
boolean. - Optional:
true. - Default
false.
- Type:
overwrite. Overwrite existing file or directory.- Type:
boolean. - Optional:
true. - Default
true.
Note that the copy operation will silently fail if you set this to
falseand the destination exists. Use theerrorOnExistoption to change this behavior.- Type:
preserveTimestamps. Whentrue, will set last modification and access times to the ones of the original source files. Whenfalse, timestamp behavior is OS-dependent.- Type:
boolean. - Optional:
true. - Default
false.
- Type:
Example
import copy from '@hexatool/fs-copy';
// copy file
copy('/tmp/myfile', '/tmp/mynewfile');
// copy directory, even if it has subdirectories or files
copy('/tmp/mydir', '/tmp/mynewdir');Using filter function
import copy from '@hexatool/fs-copy';
const filterFunc = (src: string, dest: string): boolean => {
// your logic here
// it will be copied if return true
}
copy('/tmp/mydir', '/tmp/mynewdir', { filter: filterFunc })Async function
import copy from '@hexatool/fs-copy/async';
// copy file
await copy('/tmp/myfile', '/tmp/mynewfile');
// copy directory, even if it has subdirectories or files
await copy('/tmp/mydir', '/tmp/mynewdir');Hexatool Code Quality Standards
Publishing this package we are committing ourselves to the following code quality standards:
- Respect Semantic Versioning: No breaking changes in patch or minor versions
- No surprises in transitive dependencies: Use the bare minimum dependencies needed to meet the purpose
- One specific purpose to meet without having to carry a bunch of unnecessary other utilities
- Tests as documentation and usage examples
- Well documented README showing how to install and use
- License favoring Open Source and collaboration
0.0.1-next.4
3 years ago
0.0.1-next.3
3 years ago
0.0.1-next.2
3 years ago
0.0.1-next.1
3 years ago
0.0.1-next.0
3 years ago