async-assets
Advanced tools
Comparing version 0.0.1-alpha.1 to 0.0.1-alpha.1.1
{ | ||
"name": "async-assets", | ||
"version": "0.0.1-alpha.1", | ||
"version": "0.0.1-alpha.1.1", | ||
"description": "Async loading of css and javascript files", | ||
"main": "index.js", | ||
"main": "./src/index.js", | ||
"scripts": { | ||
@@ -7,0 +7,0 @@ "test": "echo \"Error: no test specified\" && exit 1" |
![](https://azabroflovski.uz/logo-sm.png) | ||
![Build](https://img.shields.io/badge/build-passing-brightgreen) ![Version](https://img.shields.io/badge/version-0.0.1-blue) ![License](https://img.shields.io/npm/l/async-assets?color=brightgreen) ![GitHub last commit](https://img.shields.io/github/last-commit/azabroflovski/async-assets) | ||
![Build](https://img.shields.io/badge/build-passing-brightgreen) ![Version](https://img.shields.io/badge/version-0.0.1.alpha-blue) ![License](https://img.shields.io/npm/l/async-assets?color=brightgreen) ![GitHub last commit](https://img.shields.io/github/last-commit/azabroflovski/async-assets) | ||
@@ -57,4 +57,14 @@ A simple, lightweight JavaScript API for asynchronous including assets. | ||
```html | ||
<script src="https://unpkg.com/async-assets/bundle.js"></script> | ||
<script src="https://unpkg.com/async-assets/bundle.js"></script> | ||
<!-- or --> | ||
<script src="https://unpkg.com/async-assets/bundle.min.js"></script> | ||
<script> | ||
try { | ||
const assets = await AsyncAssets('...') | ||
// do something | ||
} catch (err) { | ||
console.log('Something wrong', err) | ||
} | ||
</script> | ||
``` | ||
@@ -61,0 +71,0 @@ |
@@ -1,1 +0,61 @@ | ||
console.log('hello world'); | ||
class Asset { | ||
/** | ||
* Asset Class | ||
* @param props {Object} | ||
*/ | ||
constructor(props) { | ||
const { type, url } = props | ||
this.allowedTypes = [ | ||
'stylesheet', | ||
'style', | ||
'css', | ||
'javascript', | ||
'script', | ||
'js', | ||
] | ||
this.asset = { type, url } | ||
this.validate() | ||
} | ||
/** | ||
* Get asset full url | ||
* @return {string} | ||
*/ | ||
get url() { | ||
return this.asset.url | ||
} | ||
/** | ||
* Set asset url | ||
* @param value {string} | ||
*/ | ||
set url(value) { | ||
this.asset.url = value | ||
} | ||
/** | ||
* Check for valid asset type | ||
* @return {boolean} | ||
*/ | ||
get isValid() { | ||
return this.allowedTypes.includes(this.asset.type) | ||
} | ||
/** | ||
* Validate is allowed type | ||
* @return void | ||
*/ | ||
validate() { | ||
if (!this.isValid) { | ||
throw 'Invalid asset type. List of allowed types: ' + this.allowedTypes.join(',') | ||
} | ||
} | ||
} | ||
module.exports = Asset |
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
Found 1 instance in 1 package
4913
8
49
83
0