-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* use ES2015 code * add object-key version
- Loading branch information
Showing
3 changed files
with
34 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'use strict'; | ||
|
||
var fileType = require('file-type'); | ||
|
||
var types = { | ||
png: true, | ||
jpg: true, | ||
tif: true, | ||
webp: true | ||
} | ||
|
||
module.exports = function isCwebpReadable(buf) { | ||
var type = fileType(buf); | ||
|
||
if (!type) { | ||
return false; | ||
} | ||
|
||
return !!types[type.ext]; | ||
}; |
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,24 +1,29 @@ | ||
/* globals set, suite, bench */ | ||
'use strict'; | ||
|
||
var main = require('..'); | ||
var indexOf = require('./index-of.js'); | ||
var regex = require('./regex.js'); | ||
const main = require('..'); | ||
const indexOf = require('./index-of.js'); | ||
const keys = require('./keys.js'); | ||
const regex = require('./regex.js'); | ||
|
||
var fixture = new Buffer(100); | ||
const fixture = new Buffer(100); | ||
|
||
suite('Detect file type', function() { | ||
suite('Detect file type', () => { | ||
set('iterations', 30000); | ||
|
||
bench('logical OR (current version)', function() { | ||
bench('logical OR (current version)', () => { | ||
main(fixture); | ||
}); | ||
|
||
bench('array.indexOf', function() { | ||
bench('array.indexOf', () => { | ||
indexOf(fixture); | ||
}); | ||
|
||
bench('regular expression', function() { | ||
bench('keys', () => { | ||
regex(fixture); | ||
}); | ||
|
||
bench('regular expression', () => { | ||
regex(fixture); | ||
}); | ||
}); |
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