diff --git a/.editorconfig b/.editorconfig index 86c8f59..1c6314a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,9 +7,6 @@ charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true -[package.json] +[*.yml] indent_style = space indent_size = 2 - -[*.md] -trim_trailing_whitespace = false diff --git a/.gitattributes b/.gitattributes index 176a458..391f0a4 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ * text=auto +*.js text eol=lf diff --git a/.gitignore b/.gitignore index 3c3629e..239ecff 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules +yarn.lock diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index 804f8af..0000000 --- a/.jshintrc +++ /dev/null @@ -1,13 +0,0 @@ -{ - "node": true, - "esnext": true, - "bitwise": true, - "camelcase": true, - "curly": true, - "immed": true, - "newcap": true, - "noarg": true, - "undef": true, - "unused": "vars", - "strict": true -} diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..43c97e7 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/.travis.yml b/.travis.yml index dedfc07..e0cc348 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,4 @@ -sudo: false language: node_js node_js: - - 'iojs' - - '0.12' - - '0.10' + - '8' + - '6' diff --git a/index.js b/index.js index b0caf5b..e3d4e92 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,8 @@ 'use strict'; -module.exports = function (buf) { - if (!buf || buf.length < 2) { +module.exports = buffer => { + if (!buffer || buffer.length < 2) { return false; } - return buf[0] === 66 && buf[1] === 77; + return buffer[0] === 66 && buffer[1] === 77; }; diff --git a/license b/license index 654d0bf..e7af2f7 100644 --- a/license +++ b/license @@ -1,21 +1,9 @@ -The MIT License (MIT) +MIT License Copyright (c) Sindre Sorhus (sindresorhus.com) -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/package.json b/package.json index fc52731..3ac76cf 100644 --- a/package.json +++ b/package.json @@ -1,43 +1,44 @@ { - "name": "is-bmp", - "version": "1.0.1", - "description": "Check if a Buffer/Uint8Array is a BMP image", - "license": "MIT", - "repository": "sindresorhus/is-bmp", - "author": { - "name": "Sindre Sorhus", - "email": "sindresorhus@gmail.com", - "url": "http://sindresorhus.com" - }, - "engines": { - "node": ">=0.10.0" - }, - "scripts": { - "test": "mocha" - }, - "files": [ - "index.js" - ], - "keywords": [ - "bmp", - "bitmap", - "graphics", - "image", - "img", - "pic", - "picture", - "photo", - "type", - "detect", - "check", - "is", - "exif", - "binary", - "buffer", - "uint8array" - ], - "devDependencies": { - "mocha": "*", - "read-chunk": "^1.0.0" - } + "name": "is-bmp", + "version": "1.0.1", + "description": "Check if a Buffer/Uint8Array is a BMP image", + "license": "MIT", + "repository": "sindresorhus/is-bmp", + "author": { + "name": "Sindre Sorhus", + "email": "sindresorhus@gmail.com", + "url": "sindresorhus.com" + }, + "engines": { + "node": ">=6" + }, + "scripts": { + "test": "xo && ava" + }, + "files": [ + "index.js" + ], + "keywords": [ + "bmp", + "bitmap", + "graphics", + "image", + "img", + "pic", + "picture", + "photo", + "type", + "detect", + "check", + "is", + "exif", + "binary", + "buffer", + "uint8array" + ], + "devDependencies": { + "ava": "*", + "read-chunk": "^2.1.0", + "xo": "*" + } } diff --git a/readme.md b/readme.md index 7a7e335..2af84fd 100644 --- a/readme.md +++ b/readme.md @@ -1,14 +1,12 @@ # is-bmp [![Build Status](https://travis-ci.org/sindresorhus/is-bmp.svg?branch=master)](https://travis-ci.org/sindresorhus/is-bmp) -> Check if a Buffer/Uint8Array is a [BMP](http://en.wikipedia.org/wiki/BMP_file_format) image - -Used by [image-type](https://github.com/sindresorhus/image-type). +> Check if a Buffer/Uint8Array is a [BMP](https://en.m.wikipedia.org/wiki/BMP_file_format) image ## Install -```sh -$ npm install --save is-bmp +``` +$ npm install is-bmp ``` @@ -17,9 +15,9 @@ $ npm install --save is-bmp ##### Node.js ```js -var readChunk = require('read-chunk'); // npm install read-chunk -var isBmp = require('is-bmp'); -var buffer = readChunk.sync('unicorn.bmp', 0, 2); +const readChunk = require('read-chunk'); +const isBmp = require('is-bmp'); +const buffer = readChunk.sync('unicorn.bmp', 0, 2); isBmp(buffer); //=> true @@ -28,11 +26,11 @@ isBmp(buffer); ##### Browser ```js -var xhr = new XMLHttpRequest(); +const xhr = new XMLHttpRequest(); xhr.open('GET', 'unicorn.bmp'); xhr.responseType = 'arraybuffer'; -xhr.onload = function () { +xhr.onload = () => { isBmp(new Uint8Array(this.response)); //=> true }; @@ -50,6 +48,11 @@ Accepts a Buffer (Node.js) or Uint8Array. It only needs the first 2 bytes. +## Related + +- [file-type](https://github.com/sindresorhus/file-type) - Detect the file type of a Buffer/Uint8Array + + ## License -MIT © [Sindre Sorhus](http://sindresorhus.com) +MIT © [Sindre Sorhus](https://sindresorhus.com) diff --git a/test.js b/test.js index 77c9fd4..d98ee7a 100644 --- a/test.js +++ b/test.js @@ -1,13 +1,10 @@ -'use strict'; -var assert = require('assert'); -var readChunk = require('read-chunk'); -var isBmp = require('./'); +import test from 'ava'; +import readChunk from 'read-chunk'; +import m from '.'; -function check(filename) { - return isBmp(readChunk.sync(filename, 0, 4)); -} +const check = filename => m(readChunk.sync(filename, 0, 4)); -it('should detect BMP from Buffer', function () { - assert(check('fixture.bmp')); - assert(!check('fixture.png')); +test('detects BMP from Buffer', t => { + t.true(check('fixture.bmp')); + t.false(check('fixture.png')); });