# happycode-storage
**Repository Path**: happycoding-cx/happycode-storage
## Basic Information
- **Project Name**: happycode-storage
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: BSD-3-Clause
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2022-01-18
- **Last Updated**: 2022-05-25
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
## happycode-storage
#### Happycode Storage is a library for loading and storing project and asset files for Happycode 3.0
[](https://travis-ci.org/LLK/happycode-storage)
[](https://coveralls.io/github/LLK/happycode-storage?branch=develop)
[](https://greenkeeper.io/)
## Installation
This requires you to have Node.js installed.
In your own Node.js environment/application:
```bash
npm install https://gitee.com/happycoding-cx/happycode-storage.git
```
If you want to edit/play yourself (requires Git):
```bash
git clone https://gitee.com/happycoding-cx/happycode-storage.git
cd happycode-storage
npm install
```
## Using happycode-storage
### From HTML
```html
```
### From Node.js / Webpack
```js
var storage = require('happycode-storage');
// continue to "Storage API Quick Start" section below
```
### Storage API Quick Start
Once you have an instance of `happycode-storage`, add some web sources. For each source you'll need to provide a function
to generate a URL for a supported type of asset:
```js
/**
* @param {Asset} asset - calculate a URL for this asset.
* @returns {string} a URL to download a project asset (PNG, WAV, etc.)
*/
var getAssetUrl = function (asset) {
var assetUrlParts = [
'https://assets.example.com/path/to/assets/',
asset.assetId,
'.',
asset.dataFormat,
'/get/'
];
return assetUrlParts.join('');
};
```
Then, let the storage module know about your source:
```js
storage.addWebStore(
[AssetType.ImageVector, AssetType.ImageBitmap, AssetType.Sound],
getAssetUrl);
```
If you're using ES6 you may be able to simplify all of the above quite a bit:
```js
storage.addWebStore(
[AssetType.ImageVector, AssetType.ImageBitmap, AssetType.Sound],
asset => `https://assets.example.com/path/to/assets/${asset.assetId}.${asset.dataFormat}/get/`);
```
Once the storage module is aware of the sources you need, you can start loading assets:
```js
storage.load(AssetType.Sound, soundId).then(function (soundAsset) {
// `soundAsset` is an `Asset` object. File contents are stored in `soundAsset.data`.
});
```
If you'd like to use `happycode-storage` with `happycode-vm` you must "attach" the storage module to the VM:
```js
vm.attachStorage(storage);
```
## Testing
To run all tests:
```bash
npm test
```
To show test coverage:
```bash
npm run coverage
```
## Committing
This project uses [semantic release](https://github.com/semantic-release/semantic-release)
to ensure version bumps follow semver so that projects using the config don't
break unexpectedly.
In order to automatically determine the type of version bump necessary, semantic
release expects commit messages to be formatted following
[conventional-changelog](https://github.com/bcoe/conventional-changelog-standard/blob/master/convention.md).
```
():