Skip to content

Commit 2bea1a2

Browse files
committed
[breaking] ES2015ify and require Node.js 4
1 parent c72c5c1 commit 2bea1a2

File tree

6 files changed

+20
-16
lines changed

6 files changed

+20
-16
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
* text=auto
2+
*.js text eol=lf

.travis.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
sudo: false
21
language: node_js
32
node_js:
43
- '6'

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
module.exports = function (buf) {
2+
module.exports = buf => {
33
if (!(buf && buf.length > 1)) {
44
return null;
55
}

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"url": "sindresorhus.com"
1111
},
1212
"engines": {
13-
"node": ">=0.10.0"
13+
"node": ">=4"
1414
},
1515
"scripts": {
1616
"test": "xo && ava"
@@ -99,5 +99,8 @@
9999
"ava": "*",
100100
"read-chunk": "^2.0.0",
101101
"xo": "*"
102+
},
103+
"xo": {
104+
"esnext": true
102105
}
103106
}

readme.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ $ npm install --save file-type
1717
##### Node.js
1818

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

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

28-
or from a remote location:
28+
Or from a remote location:
2929

3030
```js
3131
const http = require('http');
@@ -61,11 +61,13 @@ xhr.send();
6161

6262
### fileType(buffer)
6363

64-
Returns an `Object` (or `null` when no match) with:
64+
Returns an `Object` with:
6565

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

69+
Or `null` when no match.
70+
6971
#### buffer
7072

7173
Type: `Buffer` `Uint8Array`

test.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import fileType from './';
66
function check(ext, name) {
77
const file = path.join(__dirname, 'fixture', `${(name || 'fixture')}.${ext}`);
88
const fileInfo = fileType(readChunk.sync(file, 0, 262)) || {};
9-
109
return fileInfo.ext;
1110
}
1211

@@ -83,16 +82,16 @@ const names = {
8382
Z: ['fixture.tar']
8483
};
8584

86-
function testFile(type, name) {
87-
test(type, t => {
88-
t.is(check(type, name), type);
89-
});
85+
function testFile(t, type, name) {
86+
t.is(check(type, name), type);
9087
}
9188

92-
types.forEach(type => {
93-
if ({}.hasOwnProperty.call(names, type)) {
94-
names[type].forEach(name => testFile(type, name));
89+
for (const type of types) {
90+
if (Object.prototype.hasOwnProperty.call(names, type)) {
91+
for (const name of names[type]) {
92+
test(type, testFile, type, name);
93+
}
9594
} else {
96-
testFile(type);
95+
test(type, testFile, type);
9796
}
98-
});
97+
}

0 commit comments

Comments
 (0)