Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bezoerb/asset-resolver
Find an asset in a set of locations
https://github.com/bezoerb/asset-resolver
Last synced: 14 days ago
JSON representation
Find an asset in a set of locations
- Host: GitHub
- URL: https://github.com/bezoerb/asset-resolver
- Owner: bezoerb
- License: mit
- Created: 2015-09-22T21:15:52.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2023-04-24T18:11:51.000Z (over 1 year ago)
- Last Synced: 2024-04-28T19:06:04.746Z (7 months ago)
- Language: JavaScript
- Size: 1.77 MB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: readme.md
- Changelog: changelog.md
- License: license
Awesome Lists containing this project
README
[![NPM version][npm-image]][npm-url] [![Build Status][ci-image]][ci-url] [![Coverage Status][coveralls-image]][coveralls-url] [![dependencies Status][depstat-image]][depstat-url] [![devDependencies Status Status][devdepstat-image]][devdepstat-url]
# asset-resolver
> Helper module to find an asset in a set of locations
## Install
```
$ npm install --save asset-resolver
```## Usage
```js
const resolver = require('asset-resolver');resolver.getResource('my.svg', {
base: ['some/directory', 'http://some.domain/assets']
}).then(function(resource) {
console.log(resource)
});
//=> { path: http://some.domain/assets/my.svg', mime: 'image/svg+xml', contents: ' ... ' }
```## API
### resolver(input, [options])
#### input
* Type: `string`
The filename
#### options
##### base
* Type: `string`, `array`
* Default: `[process.cwd()]`
* Required: `false`
* Example: `['http://domain.de/', 'http://domain.de/styles', 'app/images', '**/images/']`List of directories/URLs where we should start looking for assets (supports globbing on directories).
##### filter
* Type: `function`
* Default: `function(){ return true; }`
* Required: `false`
* Example:```js
resolver.getResource('my.svg',{
base: ['some/directory', 'http://some.domain/assets'],
filter: function (resource) {
return filesize(resource) < maxFileSize;
}
}).then(function(resource) {
console.log(resource)
});
```List of directories/URLs where we should start looking for assets.
## CLI
```
$ npm install --global asset-resolver
``````
$ asset-resolver --helpUsage
asset-resolver [input]Options
-b --base List of directories/URLs where we should start looking for assets. [Default: process.cwd()]Examples
$ asset-resolver 'my.svg' -b 'some/directory' -b 'http://some.domain/assets'
...
```## License
MIT © [Ben Zörb](http://sommerlaune.com)
[npm-url]: https://www.npmjs.com/package/asset-resolver
[npm-image]: https://img.shields.io/npm/v/asset-resolver.svg[ci-url]: https://github.com/bezoerb/asset-resolver/actions?workflow=Tests
[ci-image]: https://github.com/bezoerb/asset-resolver/workflows/Tests/badge.svg[depstat-url]: https://david-dm.org/bezoerb/asset-resolver
[depstat-image]: https://img.shields.io/david/bezoerb/asset-resolver.svg[devdepstat-url]: https://david-dm.org/bezoerb/asset-resolver?type=dev
[devdepstat-image]: https://img.shields.io/david/dev/bezoerb/asset-resolver.svg[coveralls-url]: https://coveralls.io/github/bezoerb/asset-resolver?branch=master
[coveralls-image]: https://img.shields.io/coveralls/github/bezoerb/asset-resolver/master.svg