# compute-dims

> Computes array dimensions.

Latest version **1.1.0** (published 2018-11-13) · MIT license · 0 weekly downloads

## Install

```sh
npm install compute-dims
pnpm add compute-dims
yarn add compute-dims
bun add compute-dims
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2018-11-13 |
| First published | 2014-11-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 8.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Athan Reines |
| Maintainers | kgryte |
| Keywords | compute.io, compute, computation, array, utilities, utils, dimensions, size, shape, dims |

## Links

- npm: https://www.npmjs.com/package/compute-dims
- Repository: https://github.com/compute-io/dims
- Homepage: https://github.com/compute-io/dims#readme
- Issues: https://github.com/compute-io/dims/issues
- npm.io page: https://npm.io/package/compute-dims

## Dependencies (5)

- [utils-copy](https://npm.io/package/utils-copy.md) ^1.0.0
- [validate.io-array](https://npm.io/package/validate.io-array.md) ^1.0.6
- [validate.io-matrix-like](https://npm.io/package/validate.io-matrix-like.md) ^1.0.2
- [validate.io-ndarray-like](https://npm.io/package/validate.io-ndarray-like.md) ^1.0.0
- [validate.io-positive-integer](https://npm.io/package/validate.io-positive-integer.md) ^1.0.0

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2018-11-13
- 1.0.0 — 2014-11-22
- 0.0.0 — 2014-11-22

## README

dims
===
[![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Coverage Status][coveralls-image]][coveralls-url] [![Dependencies][dependencies-image]][dependencies-url]

> Computes dimensions for arrays and matrices.


## Installation

``` bash
$ npm install compute-dims
```

For use in the browser, use [browserify](https://github.com/substack/node-browserify).


## Usage


``` javascript
var dims = require( 'compute-dims' );
```

#### dims( x[, max] )

Computes dimensions of `x`. `x` may be either an [`array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) (including nested `arrays`) or a [`matrix`](https://github.com/dstructs/matrix).

``` javascript
var matrix = require( 'dstructs-matrix' ),
	data,
	d;

data = [ 1, 2 ];
d = dims( data );
// returns [2]

data = [ [1,2], [1,2] ];
d = dims( data );
// returns [2,2]

data = matrix( [1,2,3,4], [2,2] )
d = dims( data );
// returns [2,2]
```

If an `array` element has a dimension inconsistent with other elements, the function returns `null`.

``` javascript
data = [ [1,2], [1] ];
d = dims( data );
// returns null
```

To limit the number of dimensions returned, set the `max` option.

``` javascript
data = [ [[1,2], [3,4]] ]; // 1x2x2
d = dims( data, 2 );
// returns [1,2]

data = [ [[1,2], [3,4,5,6,7,8]] ];
d = dims( data );
// returns null

d = dims( data, 2 );
// returns [1,2]

data = matrix( [1,2,3,4], [2,2] );
d = dims( data, 1 );
// returns [2]
```


## Examples

To run the example code from the top-level application directory,

``` bash
$ node ./examples/index.js
```


## Tests

### Unit

Unit tests use the [Mocha](http://mochajs.org) test framework with [Chai](http://chaijs.com) assertions. To run the tests, execute the following command in the top-level application directory:

``` bash
$ make test
```

All new feature development should have corresponding unit tests to validate correct functionality.


### Test Coverage

This repository uses [Istanbul](https://github.com/gotwarlost/istanbul) as its code coverage tool. To generate a test coverage report, execute the following command in the top-level application directory:

``` bash
$ make test-cov
```

Istanbul creates a `./reports/coverage` directory. To access an HTML version of the report,

``` bash
$ make view-cov
```


---
## License

[MIT license](http://opensource.org/licenses/MIT).


## Copyright

Copyright &copy; 2014-2015. The [Compute.io](https://github.com/compute-io) Authors.

[npm-image]: http://img.shields.io/npm/v/compute-dims.svg
[npm-url]: https://npmjs.org/package/compute-dims

[travis-image]: http://img.shields.io/travis/compute-io/dims/master.svg
[travis-url]: https://travis-ci.org/compute-io/dims

[coveralls-image]: https://img.shields.io/coveralls/compute-io/dims/master.svg
[coveralls-url]: https://coveralls.io/r/compute-io/dims?branch=master

[dependencies-image]: http://img.shields.io/david/compute-io/dims.svg
[dependencies-url]: https://david-dm.org/compute-io/dims

[dev-dependencies-image]: http://img.shields.io/david/dev/compute-io/dims.svg
[dev-dependencies-url]: https://david-dm.org/dev/compute-io/dims

[github-issues-image]: http://img.shields.io/github/issues/compute-io/dims.svg
[github-issues-url]: https://github.com/compute-io/dims/issues

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