mirror of
https://github.com/scratchfoundation/scratch-asset-types.git
synced 2024-11-14 19:15:04 -05:00
Supported asset detection and types for Scratch backend
ef21497c4d
Bump patch level |
||
---|---|---|
.github | ||
lib | ||
test | ||
.eslintignore | ||
.eslintrc.js | ||
.gitignore | ||
.npmignore | ||
.nvmrc | ||
index.js | ||
LICENSE | ||
Makefile | ||
package-lock.json | ||
package.json | ||
README.md | ||
TRADEMARK |
scratch-asset-types
A library for detecting types for Scratch backend services that is optimized for the specific file types that Scratch services depend on.
Usage:
Three possible use cases:
bufferCheck
, syncCheck
, asyncCheck
These will return null
if the type is not recognized.
If recognized, a JSON object will be returned of the form:
{ext: 'gif', mime: 'image/gif'}
Examples:
Synchronous check on if a filename includes an acceptable extension:
const assetTypes = require('scratch-asset-types');
const result = assetTypes.acceptableExtension('filename');
Synchronous check on a buffer:
const assetTypes = require('scratch-asset-types');
const result = assetTypes.bufferCheck(someBuffer);
Synchronous check on a filename:
const assetTypes = require('scratch-asset-types');
const result = assetTypes.syncCheck('full/path/to/filename');
Asynchronous check on a filename:
const assetTypes = require('scratch-asset-types');
assetTypes.asyncCheck('full/path/to/filename').then( ... );
There is no asynchronous check on a buffer as that would be highly inefficent.
Thanks to file-type
This library is derived from the more general file-type npm module.