From 2bea1a2b3e701c302fea92cf269b01ad0101b2ff Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Wed, 23 Nov 2016 01:15:13 +0700 Subject: [PATCH] [breaking] ES2015ify and require Node.js 4 --- .gitattributes | 1 + .travis.yml | 1 - index.js | 2 +- package.json | 5 ++++- readme.md | 8 +++++--- test.js | 19 +++++++++---------- 6 files changed, 20 insertions(+), 16 deletions(-) diff --git a/.gitattributes b/.gitattributes index 176a458f..391f0a4e 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ * text=auto +*.js text eol=lf diff --git a/.travis.yml b/.travis.yml index b18bae5a..97519af9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,3 @@ -sudo: false language: node_js node_js: - '6' diff --git a/index.js b/index.js index f498c10b..1ab7d271 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ 'use strict'; -module.exports = function (buf) { +module.exports = buf => { if (!(buf && buf.length > 1)) { return null; } diff --git a/package.json b/package.json index caf66d67..c0fa139a 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "url": "sindresorhus.com" }, "engines": { - "node": ">=0.10.0" + "node": ">=4" }, "scripts": { "test": "xo && ava" @@ -99,5 +99,8 @@ "ava": "*", "read-chunk": "^2.0.0", "xo": "*" + }, + "xo": { + "esnext": true } } diff --git a/readme.md b/readme.md index 32ecf09d..396e4904 100644 --- a/readme.md +++ b/readme.md @@ -17,7 +17,7 @@ $ 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); @@ -25,7 +25,7 @@ fileType(buffer); //=> {ext: 'png', mime: 'image/png'} ``` -or from a remote location: +Or from a remote location: ```js const http = require('http'); @@ -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` diff --git a/test.js b/test.js index 788d45e5..f3bbd2a4 100644 --- a/test.js +++ b/test.js @@ -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; } @@ -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); } -}); +}