# copy

> Copy files or directories using globs.

Latest version **0.3.2** (published 2018-05-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install copy
pnpm add copy
yarn add copy
bun add copy
```

Provides the commands `copy`, `copy-cli`.

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.2 |
| Published | 2018-05-14 |
| First published | 2012-10-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/copy) |
| Module format | CommonJS |
| Node | >=0.10.0 |
| Dependencies | 14 |
| Unpacked size | 25.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 93 |
| Author | Jon Schlinkert |
| Maintainers | doowb, jonschlinkert |
| Keywords | async, copy, file, file-system, fs, glob, move, path, pattern, promise, stream, sync, system |

## Links

- npm: https://www.npmjs.com/package/copy
- Repository: https://github.com/jonschlinkert/copy
- Issues: https://github.com/jonschlinkert/copy/issues
- npm.io page: https://npm.io/package/copy

## Dependencies (14)

- [log-ok](https://npm.io/package/log-ok.md) ^0.1.1
- [mkdirp](https://npm.io/package/mkdirp.md) ^0.5.1
- [matched](https://npm.io/package/matched.md) ^0.4.1
- [to-file](https://npm.io/package/to-file.md) ^0.2.0
- [bluebird](https://npm.io/package/bluebird.md) ^3.4.1
- [has-glob](https://npm.io/package/has-glob.md) ^0.1.1
- [async-each](https://npm.io/package/async-each.md) ^1.0.0
- [lazy-cache](https://npm.io/package/lazy-cache.md) ^2.0.1
- [glob-parent](https://npm.io/package/glob-parent.md) ^2.0.0
- [graceful-fs](https://npm.io/package/graceful-fs.md) ^4.1.4
- [is-absolute](https://npm.io/package/is-absolute.md) ^0.2.5
- [resolve-dir](https://npm.io/package/resolve-dir.md) ^0.1.0
- [file-contents](https://npm.io/package/file-contents.md) ^0.3.1
- [extend-shallow](https://npm.io/package/extend-shallow.md) ^2.0.1

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 0.3.2 (latest) — 2018-05-14
- 0.3.1 — 2017-09-01
- 0.3.0 — 2016-07-26
- 0.2.3 — 2016-06-20
- 0.2.2 — 2016-06-19
- 0.2.1 — 2016-06-19
- 0.2.0 — 2016-03-23
- 0.1.3 — 2015-11-25
- 0.1.2 — 2015-09-14
- 0.1.1 — 2015-07-16
- 0.1.0 — 2015-07-03
- 0.0.1 — 2012-10-05
- 0.0.0 — 2012-10-04

## README

# copy [![NPM version](https://img.shields.io/npm/v/copy.svg?style=flat)](https://www.npmjs.com/package/copy) [![NPM monthly downloads](https://img.shields.io/npm/dm/copy.svg?style=flat)](https://npmjs.org/package/copy)  [![NPM total downloads](https://img.shields.io/npm/dt/copy.svg?style=flat)](https://npmjs.org/package/copy) [![Linux Build Status](https://img.shields.io/travis/jonschlinkert/copy.svg?style=flat&label=Travis)](https://travis-ci.org/jonschlinkert/copy) [![Windows Build Status](https://img.shields.io/appveyor/ci/jonschlinkert/copy.svg?style=flat&label=AppVeyor)](https://ci.appveyor.com/project/jonschlinkert/copy)

> Copy files or directories using globs.

## Table of Contents

- [Install](#install)
- [Usage](#usage)
- [Examples](#examples)
- [API](#api)
- [CLI](#cli)
- [History](#history)
- [About](#about)

_(TOC generated by [verb](https://github.com/verbose/verb) using [markdown-toc](https://github.com/jonschlinkert/markdown-toc))_

## Install

Install with [npm](https://www.npmjs.com/):

```sh
$ npm install --save copy
```

## Usage

```js
var copy = require('copy');
```

See the [API documentation](#api) for usage details and available methods.

## Examples

The main export is a function that takes:

* `src` - glob pattern or file path(s)
* `dest` - the destination directory
* `cb` - callback function

```js
copy('*.js', 'foo', function(err, files) {
  if (err) throw err;
  // `files` is an array of the files that were copied
});
```

**Usage with [gulp](http://gulpjs.com)**

In your project's gulpfile.js:

```js
var gulp = require('gulp');
var copy = require('copy');

gulp.task('default', function (cb) {
  copy('fixtures/*.txt', 'actual', cb);
});
```

## API

### [copy](index.js#L27)

Copy a filepath, vinyl file, array of files, or glob of files to the given destination `directory`, with `options` and callback function that exposes `err` and the array of vinyl files that are created by the copy operation.

**Params**

* `patterns` **{String|Object|Array}**: Filepath(s), vinyl file(s) or glob of files.
* `dir` **{String}**: Destination directory
* `options` **{Object|Function}**: or callback function
* `cb` **{Function}**: Callback function if no options are specified

**Example**

```js
copy('*.js', 'dist', function(err, file) {
  // exposes the vinyl `file` created when the file is copied
});
```

### [.copy.each](index.js#L79)

Copy an array of files to the given destination `directory`, with `options` and callback function that exposes `err` and the array of vinyl files that are created by the copy operation.

**Params**

* `files` **{Array}**: Filepaths or vinyl files.
* `dir` **{String}**: Destination directory
* `options` **{Object|Function}**: or callback function
* `cb` **{Function}**: Callback function if no options are specified

**Example**

```js
copy.each(['foo.txt', 'bar.txt', 'baz.txt'], 'dist', function(err, files) {
  // exposes the vinyl `files` created when the files are copied
});
```

### [.copy.one](index.js#L132)

Copy a single `file` to the given `dest` directory, using the specified options and callback function.

**Params**

* `file` **{String|Object}**: Filepath or vinyl file
* `dir` **{String}**: Destination directory
* `options` **{Object|Function}**: or callback function
* `cb` **{Function}**: Callback function if no options are specified

**Example**

```js
copy.one('foo.txt', 'dist', function(err, file) {
  if (err) throw err;
  // exposes the vinyl `file` that is created when the file is copied
});
```

## CLI

To use the CLI, install `copy` globally with the following command:

```js
$ npm install --global copy
```

This adds `copy` to your system path, allowing the `copy` command to be executed anywhere.

**CLI usage**

```sh
$ copy <patterns> <dir>
```

* `patterns`: glob pattern or array of file paths
* `dir`: destination directory

**Example**

Copy* all files with the `.js` extension to the `foo` directory

```sh
$ copy *.js foo
```

*Note that glob patterns may need to be wrapped in quotes depending on the shell you're using.

## History

**v0.2.0 - breaking changes**

* The API was changed in 0.2.0. please review the [API documentation](#api)

## About

### Related projects

* [expand-config](https://www.npmjs.com/package/expand-config): Expand tasks, targets and files in a declarative configuration. | [homepage](https://github.com/jonschlinkert/expand-config "Expand tasks, targets and files in a declarative configuration.")
* [expand-files](https://www.npmjs.com/package/expand-files): Expand glob patterns in a declarative configuration into src-dest mappings. | [homepage](https://github.com/jonschlinkert/expand-files "Expand glob patterns in a declarative configuration into src-dest mappings.")
* [expand-target](https://www.npmjs.com/package/expand-target): Expand target definitions in a declarative configuration. | [homepage](https://github.com/jonschlinkert/expand-target "Expand target definitions in a declarative configuration.")
* [expand-task](https://www.npmjs.com/package/expand-task): Expand and normalize task definitions in a declarative configuration. | [homepage](https://github.com/jonschlinkert/expand-task "Expand and normalize task definitions in a declarative configuration.")
* [export-files](https://www.npmjs.com/package/export-files): node.js utility for exporting a directory of files as modules. | [homepage](https://github.com/jonschlinkert/export-files "node.js utility for exporting a directory of files as modules.")
* [write](https://www.npmjs.com/package/write): Write data to a file, replacing the file if it already exists and creating any… [more](https://github.com/jonschlinkert/write) | [homepage](https://github.com/jonschlinkert/write "Write data to a file, replacing the file if it already exists and creating any intermediate directories if they don't already exist. Thin wrapper around node's native fs methods.")

### Contributing

Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](../../issues/new).

### Contributors

| **Commits** | **Contributor** |  
| --- | --- |  
| 61 | [jonschlinkert](https://github.com/jonschlinkert) |  
| 2  | [joakimbeng](https://github.com/joakimbeng) |  
| 1  | [bleathem](https://github.com/bleathem) |  
| 1  | [doowb](https://github.com/doowb) |  
| 1  | [gsantiago](https://github.com/gsantiago) |  
| 1  | [SoulRIver2015](https://github.com/SoulRIver2015) |  

### Building docs

_(This project's readme.md is generated by [verb](https://github.com/verbose/verb-generate-readme), please don't edit the readme directly. Any changes to the readme must be made in the [.verb.md](.verb.md) readme template.)_

To generate the readme, run the following command:

```sh
$ npm install -g verbose/verb#dev verb-generate-readme && verb
```

### Running tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

```sh
$ npm install && npm test
```

### Author

**Jon Schlinkert**

* [github/jonschlinkert](https://github.com/jonschlinkert)
* [twitter/jonschlinkert](https://twitter.com/jonschlinkert)

### License

Copyright © 2017, [Jon Schlinkert](https://github.com/jonschlinkert).
Released under the [MIT License](LICENSE).

***

_This file was generated by [verb-generate-readme](https://github.com/verbose/verb-generate-readme), v0.6.0, on September 01, 2017._

---
_Source: https://npm.io/package/copy · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
