-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require Node.js 6, add more image types, add TypeScript definition (#9)
- Loading branch information
1 parent
3fbcd9a
commit a1287d2
Showing
11 changed files
with
172 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
* text=auto | ||
*.js text eol=lf | ||
* text=auto eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules | ||
yarn.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package-lock=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
sudo: false | ||
language: node_js | ||
node_js: | ||
- '10' | ||
- '8' | ||
- '6' | ||
- '4' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/// <reference types="node"/> | ||
|
||
export type ImageType = | ||
| 'jpg' | ||
| 'png' | ||
| 'gif' | ||
| 'webp' | ||
| 'flif' | ||
| 'cr2' | ||
| 'tif' | ||
| 'bmp' | ||
| 'jxr' | ||
| 'psd' | ||
| 'ico' | ||
| 'bpg' | ||
| 'jp2' | ||
| 'jpm' | ||
| 'jpx' | ||
| 'heic' | ||
| 'cur' | ||
| 'dcm'; | ||
|
||
export interface ImageTypeResult { | ||
/** | ||
* One of the supported [file types](https://github.com/sindresorhus/image-type#supported-file-types). | ||
*/ | ||
ext: ImageType; | ||
|
||
/** | ||
* The detected [MIME type](https://en.wikipedia.org/wiki/Internet_media_type). | ||
*/ | ||
mime: string; | ||
} | ||
|
||
/** | ||
* Detect the image type of a `Buffer`/`Uint8Array`. | ||
* | ||
* @param input - Input to examine to determine the file type. It only needs the first `.minimumBytes` bytes. | ||
*/ | ||
declare const imageType: { | ||
(input: Buffer | Uint8Array): ImageTypeResult | null; | ||
|
||
/** | ||
* The minimum amount of bytes needed to detect a file type. Currently, it's 4100 bytes, but it can change, so don't hard-code it. | ||
*/ | ||
readonly minimumBytes: number; | ||
}; | ||
|
||
export default imageType; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import {expectType} from 'tsd-check'; | ||
import imageType, {ImageTypeResult, ImageType} from '.'; | ||
|
||
imageType(new Buffer([0xff, 0xd8, 0xff])); | ||
imageType(new Uint8Array([0xff, 0xd8, 0xff])); | ||
|
||
expectType<ImageTypeResult | null>(imageType(new Buffer([0xff, 0xd8, 0xff]))); | ||
expectType<ImageTypeResult | null>( | ||
imageType(new Uint8Array([0xff, 0xd8, 0xff])) | ||
); | ||
|
||
const result = imageType(new Buffer([0xff, 0xd8, 0xff])); | ||
if (result != null) { | ||
expectType<ImageType>(result.ext); | ||
expectType<string>(result.mime); | ||
} | ||
|
||
expectType<number>(imageType.minimumBytes); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,57 @@ | ||
{ | ||
"name": "image-type", | ||
"version": "3.0.0", | ||
"description": "Detect the image type of a Buffer/Uint8Array", | ||
"license": "MIT", | ||
"repository": "sindresorhus/image-type", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"keywords": [ | ||
"image", | ||
"img", | ||
"pic", | ||
"picture", | ||
"photo", | ||
"type", | ||
"detect", | ||
"check", | ||
"is", | ||
"exif", | ||
"binary", | ||
"buffer", | ||
"uint8array", | ||
"png", | ||
"jpg", | ||
"jpeg", | ||
"gif", | ||
"webp", | ||
"tif", | ||
"bmp", | ||
"jxr", | ||
"psd", | ||
"mime" | ||
], | ||
"dependencies": { | ||
"file-type": "^4.1.0" | ||
}, | ||
"devDependencies": { | ||
"ava": "*", | ||
"read-chunk": "^2.0.0", | ||
"xo": "*" | ||
} | ||
"name": "image-type", | ||
"version": "3.0.0", | ||
"description": "Detect the image type of a Buffer/Uint8Array", | ||
"license": "MIT", | ||
"repository": "sindresorhus/image-type", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=6" | ||
}, | ||
"scripts": { | ||
"test": "xo && ava && tsd-check" | ||
}, | ||
"files": [ | ||
"index.js", | ||
"index.d.ts" | ||
], | ||
"keywords": [ | ||
"image", | ||
"img", | ||
"pic", | ||
"picture", | ||
"photo", | ||
"type", | ||
"detect", | ||
"check", | ||
"is", | ||
"exif", | ||
"binary", | ||
"buffer", | ||
"uint8array", | ||
"png", | ||
"jpg", | ||
"jpeg", | ||
"gif", | ||
"webp", | ||
"tif", | ||
"bmp", | ||
"jxr", | ||
"psd", | ||
"mime" | ||
], | ||
"dependencies": { | ||
"file-type": "^10.9.0" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^11.10.4", | ||
"ava": "^1.3.1", | ||
"read-chunk": "^3.0.0", | ||
"tsd-check": "^0.3.0", | ||
"xo": "^0.24.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import test from 'ava'; | ||
import readChunk from 'read-chunk'; | ||
import m from './'; | ||
import imageType from '.'; | ||
|
||
const check = filename => m(readChunk.sync(filename, 0, 12)).ext; | ||
const check = filename => imageType(readChunk.sync(filename, 0, 12)).ext; | ||
|
||
test(t => { | ||
test('main', t => { | ||
t.is(check('fixture.png'), 'png'); | ||
t.is(check('fixture.psd'), 'psd'); | ||
}); |