# res-manager

> A class for better loading and managing resources.

Latest version **0.9.0** (published 2018-01-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install res-manager
pnpm add res-manager
yarn add res-manager
bun add res-manager
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.9.0 |
| Published | 2018-01-08 |
| First published | 2017-11-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 8 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Maintainers | dtysky |
| Keywords | typescript, resources, loader, preload, resource-manager |

## Links

- npm: https://www.npmjs.com/package/res-manager
- Repository: https://github.com/dtysky/ResourceManager
- Homepage: https://github.com/dtysky/ResourceManager#readme
- Issues: https://github.com/dtysky/ResourceManager/issues
- npm.io page: https://npm.io/package/res-manager

## Dependencies (8)

- [react](https://npm.io/package/react.md) ^16.0.0
- [es6-shim](https://npm.io/package/es6-shim.md) ^0.35.3
- [react-dom](https://npm.io/package/react-dom.md) ^16.0.0
- [classnames](https://npm.io/package/classnames.md) ^2.2.5
- [@types/react](https://npm.io/package/@types/react.md) ^16.0.18
- [@types/es6-shim](https://npm.io/package/@types/es6-shim.md) ^0.31.32
- [@types/react-dom](https://npm.io/package/@types/react-dom.md) ^16.0.2
- [@types/classnames](https://npm.io/package/@types/classnames.md) ^2.2.3

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.9.0 (latest) — 2018-01-08
- 0.8.3 — 2018-01-08
- 0.8.2 — 2018-01-08
- 0.8.1 — 2018-01-08
- 0.8.0 — 2017-11-14

## README

# ResourceManager

A class for better loading and managing resources.

## Demo

[You can view the live demo here.](http://resource-manager.dtysky.moe)
## Usage

```shell
npm install res-manager --save
```

### IResourceEntry

This interface is used for describing a resource.

```ts
interface IResourceEntry {
  // a switch for preloading
  preload: boolean;
  // name of this resource
  name: string;
  // url of this resource
  src: string;
  // type of this resource
  type: 'image' | 'video' | 'audio';
  // weight of this resource
  weight: number;
}
```

### ResourceManager

Main class for managing resources.

|Method|Type|Description|
|-|-|-|
|constructor|() => ResourceManager|Constructor function.|
|registerOnProgress|(onProgress: (progress: number, string: string) => ResourceManager) => void|Register an callback for progress.|
|registerOnError|onError: (error: Error, current: string) => ResourceManager) => ResourceManager|Register an callback for error.|
|registerOnComplete|onComplete: () => ResourceManager) => ResourceManager|Register an callback for completing.|
|init|(list: IResourceEntry[], timeout?: number) => ResourceManager|Initialize manager by new resources and timeout.|
|load|(onProgress?: (progress: number, string: string) => void, onComplete?: () => void, onError?: (error: Error, current: string) => void) => ResourceManager|Trigger loading, you can register callbacks here.|
|getSrc|(name: string) => string|Get source by name.|
|reset|() => ResourceManager|Reset all options and state.|

|Accessors|Type|Description|
|-|-|-|
|progress|number|Progress of loading.|
|loadDone|boolean|If the loading was done.|

```ts
import {IResourceEntry}, ResourceManager from 'res-manager';

const resourceManager = new ResourceManager();
const resources: IResourceEntry = [
  {
    preload: true,
    name: 'H光大小姐',
    src: 'http://oekm6wrcq.bkt.clouddn.com/hh.png',
    type: 'image',
    weight: 1
  },
  {
    preload: true,
    name: '秦皇岛',
    src: 'http://oekm6wrcq.bkt.clouddn.com/秦皇岛.mp3',
    type: 'audio',
    weight: 1
  },
  {
    preload: true,
    name: 'bml2017',
    src: 'http://oekm6wrcq.bkt.clouddn.com/bml-h5.mp4',
    type: 'video',
    weight: 1
  }
];
resourceManager.load(
  (progress, current) => {
    console.log(current, progress);
  },
  (error, current) => {
    console.log(error, progress);
  }
);
const imgSrc = resourceManager.getSrc('H光大小姐');
```

## Contribute

### Development

Run:

```bash
npm run dev
```

then open `localhost:4444`.

### Build

Run:

```bash
npm run build
```

## License

Copyright © 2017, 戴天宇, Tianyu Dai (dtysky < dtysky@outlook.com >). All Rights Reserved.
This project is free software and released under the **[MIT License](https://opensource.org/licenses/MIT)**.

---
_Source: https://npm.io/package/res-manager · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
