Supported asset detection and types for Scratch backend
Find a file
Colby Gutierrez-Kraybill d33e1b58d6 Required for new tests
2022-03-15 11:37:38 -04:00
lib Add check on filename extension. Add SVG soft detection. 2022-03-11 15:49:28 -05:00
test Required for new tests 2022-03-15 11:37:38 -04:00
.eslintignore Add linting rules, add synchronous and asynchronous checks and appropriate 2018-01-17 10:53:16 -05:00
.eslintrc.js Add linting rules, add synchronous and asynchronous checks and appropriate 2018-01-17 10:53:16 -05:00
.gitignore Ignore the usual 2018-01-17 09:04:15 -05:00
.npmignore add travis support and npm handling support 2018-01-17 11:15:41 -05:00
.travis.yml move towards similar scratch travis building 2018-01-17 11:26:40 -05:00
index.js Add check on filename extension. Add SVG soft detection. 2022-03-11 15:49:28 -05:00
Makefile works with our existing list of types 2018-01-17 09:01:38 -05:00
package-lock.json Add linting rules, add synchronous and asynchronous checks and appropriate 2018-01-17 10:53:16 -05:00
package.json Add linting rules, add synchronous and asynchronous checks and appropriate 2018-01-17 10:53:16 -05:00
README.md Add check on filename extension. Add SVG soft detection. 2022-03-11 15:49:28 -05:00

scratch-asset-types Build Status

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.