Skip to content

Commit

Permalink
[breaking] ES2015ify and require Node.js 4
Browse files Browse the repository at this point in the history
  • Loading branch information
sindresorhus committed Nov 22, 2016
1 parent c72c5c1 commit 2bea1a2
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* text=auto
*.js text eol=lf
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
sudo: false
language: node_js
node_js:
- '6'
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
module.exports = function (buf) {

This comment has been minimized.

Copy link
@shamasis

shamasis Mar 21, 2017

now simple browserify will not work with it. 😭

can you add:

"browserify": {
    "transform": [["babelify", { "presets": ["latest"] }]]
  }

to package?

This comment has been minimized.

Copy link
@sindresorhus

sindresorhus Mar 21, 2017

Author Owner

#70

module.exports = buf => {
if (!(buf && buf.length > 1)) {
return null;
}
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"url": "sindresorhus.com"
},
"engines": {
"node": ">=0.10.0"
"node": ">=4"
},
"scripts": {
"test": "xo && ava"
Expand Down Expand Up @@ -99,5 +99,8 @@
"ava": "*",
"read-chunk": "^2.0.0",
"xo": "*"
},
"xo": {
"esnext": true
}
}
8 changes: 5 additions & 3 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ $ npm install --save file-type
##### Node.js

```js
const readChunk = require('read-chunk'); // npm install read-chunk
const readChunk = require('read-chunk');
const fileType = require('file-type');
const buffer = readChunk.sync('unicorn.png', 0, 262);

fileType(buffer);
//=> {ext: 'png', mime: 'image/png'}
```

or from a remote location:
Or from a remote location:

```js
const http = require('http');
Expand Down Expand Up @@ -61,11 +61,13 @@ xhr.send();

### fileType(buffer)

Returns an `Object` (or `null` when no match) with:
Returns an `Object` with:

- `ext` - one of the [supported file types](#supported-file-types)
- `mime` - the [MIME type](http://en.wikipedia.org/wiki/Internet_media_type)

Or `null` when no match.

#### buffer

Type: `Buffer` `Uint8Array`
Expand Down
19 changes: 9 additions & 10 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import fileType from './';
function check(ext, name) {
const file = path.join(__dirname, 'fixture', `${(name || 'fixture')}.${ext}`);
const fileInfo = fileType(readChunk.sync(file, 0, 262)) || {};

return fileInfo.ext;
}

Expand Down Expand Up @@ -83,16 +82,16 @@ const names = {
Z: ['fixture.tar']
};

function testFile(type, name) {
test(type, t => {
t.is(check(type, name), type);
});
function testFile(t, type, name) {
t.is(check(type, name), type);
}

types.forEach(type => {
if ({}.hasOwnProperty.call(names, type)) {
names[type].forEach(name => testFile(type, name));
for (const type of types) {
if (Object.prototype.hasOwnProperty.call(names, type)) {
for (const name of names[type]) {
test(type, testFile, type, name);
}
} else {
testFile(type);
test(type, testFile, type);
}
});
}

0 comments on commit 2bea1a2

Please sign in to comment.