# magic-number

> Determine a file's type from its magic number.

Latest version **0.1.6** (published 2017-08-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install magic-number
pnpm add magic-number
yarn add magic-number
bun add magic-number
```

## 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.1.6 |
| Published | 2017-08-29 |
| First published | 2015-06-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/magic-number) |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Sam Saint-Pettersen |
| Maintainers | stpettersens |
| Keywords | magicnumber, magic, number, file, detection, type |

## Links

- npm: https://www.npmjs.com/package/magic-number
- Repository: https://github.com/stpettersens/node-magic-number
- Homepage: https://github.com/stpettersens/node-magic-number#readme
- Issues: https://github.com/stpettersens/node-magic-number/issues
- npm.io page: https://npm.io/package/magic-number

## 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.1.6 (latest) — 2017-08-29
- 0.1.5 — 2017-07-27
- 0.1.4 — 2015-07-09
- 0.1.3 — 2015-07-08
- 0.1.2 — 2015-06-28
- 0.1.0 — 2015-06-28

## README

#### Magic-number

[![Build Status](https://travis-ci.org/stpettersens/node-magic-number.svg?branch=master)](https://travis-ci.org/stpettersens/node-magic-number) [![npm version](https://badge.fury.io/js/magic-number.svg)](http://npmjs.org/package/magic-number) [![Development Dependency Status](https://david-dm.org/stpettersens/node-magic-number/dev-status.png?theme=shields.io)](https://david-dm.org/stpettersens/node-magic-number?type=dev) 

Node.js module to determine a file's type from its magic number.

Use from JavaScript:

```js
var magic = require('magic-number');
magic.detectFile('file.zip'); // ==> 'application/zip'
magic.detectFile('file.7z');  // ==> 'application/x-7z-compressed'
```

Use from [TypeScript](http://www.typescriptlang.org):

```ts
/// <require path="typings/magic-number.d.ts" />
import magic = require('magic-number');
magic.detectFile('file.zip'); // ==> 'application/zip'
magic.detectFile('file.7z');  // ==> 'application/x-7z-compressed'
```

Methods:

**magic.detectFile(file: string): string**

Parameter *file* is path string for the file to test.

**magic.detectType(data: any): string**

Parameter *data* is binary data for the file to test.

Returns a MIME type for the tested file, 'unknown' if file type is not detected or
message when file doesn't exist.

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