An open API service indexing awesome lists of open source software.

https://github.com/jonschlinkert/glob-size

Get the total size of a glob of files.
https://github.com/jonschlinkert/glob-size

bytes cli du files glob ls size space

Last synced: 3 months ago
JSON representation

Get the total size of a glob of files.

Awesome Lists containing this project

README

          

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

> Get the total size of a glob of files.

Please consider following this project's author, [Jon Schlinkert](https://github.com/jonschlinkert), and consider starring the project to show your :heart: and support.

## Install

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

```sh
$ npm install --save glob-size
```

This is similar to the UNIX `du` command (try `du -sh *` for example), but has a JavaScript API. This can be used in linters or build tools, etc. (this is also similar to doing something like `ls -l *`).

## CLI usage

```sh
$ gs
$ gs *
$ gs "**" -t
$ gs "**" -d node_modules

Options:
--cwd, -d directory to search from [default: "."]
--pattern, -p one or more glob patterns, comma-separated
--table, -t Show a text table of files sorted by size
--stats, -s log out the entire stats object with all files
--help Show help [boolean]
```

## API usage

```js
const size = require('glob-size');
```

**Params**

* `patterns` **{string|array}**
* `options` **{object}**
* `returns` **{promise}**

**Example**

```js
// get the size of all files in the cwd
size('*')
.then(console.log)
.catch(console.error)
```

### [.sync](index.js#L93)

Synchronously get the size of all files that match the given glob `patterns`.

**Params**

* `patterns` **{String|Array}**
* `options` **{Object}**
* `returns` **{Object}**

**Example**

```js
// get the size of all files in the cwd
const stats = size.sync('*');
console.log(stats);
```

### [.stats.top](index.js#L114)

Returns the top `n` files by size, sorted in ascending order. _(this method is exposed on the returned stats object)_

**Params**

* `n` **{Number}**: The number of files to return.
* `returns` **{Array}**: Array of the top `n` files

**Example**

```js
size('node_modules/**')
.then(stats => console.log(stats.top(25)))
.catch(console.error);
```

### [.stats.tableize](index.js#L151)

Create a text table from the `stats.files` array returned by the main export, or from the [.top](#top) method. _(this method is exposed on the returned stats object)_

**Params**

* `files` **{Array}**
* `returns` **{String}**

**Example**

```js
// tableize the 3 largest files in "node_modules/**"
size('node_modules/**')
.then(stats => console.log(stats.table(stats.top(3))))
.catch(console.error);

// tableize all files
size('node_modules/**')
.then(stats => console.log(stats.table(stats.files)))
.catch(console.error);
```

## Examples

The following examples assume the code is inside an `async` function.

```js
// get the size of all `.js` files in the cwd
console.log(await size('*.js'));

// get the size of all `.js` files in "./foo"
console.log(await size('*.js', { cwd: 'foo' }));

// show the 25 largest files in "node_modules/**"
const stats = await size('node_modules/**');
console.log(stats.top(25));

// show the 3 largest files in "node_modules/**"
const stats = await size('node_modules/**');
console.log(stats.top(3));

// show the 3 largest files in "node_modules/**"
const stats = await size('node_modules/**');
console.log(stats.top(3));

// tableize the 3 largest files in "node_modules/**"
const stats = await size('node_modules/**');
console.log(stats.table(stats.top(50)));

// tableize all files
const stats = await size('node_modules/**');
console.log(stats.table(stats.files));
```

## About

Contributing

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

Please read the [contributing guide](.github/contributing.md) for advice on opening issues, pull requests, and coding standards.

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
```

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
```

### Author

**Jon Schlinkert**

* [LinkedIn Profile](https://linkedin.com/in/jonschlinkert)
* [GitHub Profile](https://github.com/jonschlinkert)
* [Twitter Profile](https://twitter.com/jonschlinkert)

### License

Copyright © 2018, [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 May 16, 2018._