@garfish/loader
TypeScript icon, indicating that this package has built-in type declarations

1.18.0 • Public • Published

@garfish/loader

NPM version

Usage

import { Loader } from '@garfish/loader';

const loader = new Loader({
  maxSize: 1024 * 1024 * 15, // default number is "1024 * 1024 * 15"
});

loader.hooks.usePlugin({
  name: 'test-plugin1',

  beforeLoad({ url, config }) {
    // You can changed the request config
    if (url.includes('xx')) {
      url = url.replace('xx', '');
    }
    return { url, config };
  },

  loaded(data) {
    const { result, value } = data;
    data.n = 1;
    return data;
  },
});

loader.hooks.usePlugin({
  name: 'test-plugin2',

  loaded(data) {
    console.log(data.n); // 1
    // The "data.value" will be cached this time.
    // So, you can transform the request result.
    return data;
  },
});

loader.load({scope: 'appName', url: 'https://xxx'}).then((result) => {
  console.log(result); // 2
});

Clear cache

const loader = new Loader();

loader.clear('appName'); // Clear all cached resources under "appName"
loader.clear('appName', 'js'); // Clear all "js" cache resources under "appName"

loader.clearAll(); // Clear all cached resources
loader.clearAll('css'); // Clear all "css" cached resources

Readme

Keywords

Package Sidebar

Install

npm i @garfish/loader

Weekly Downloads

794

Version

1.18.0

License

MIT

Unpacked Size

42.3 kB

Total Files

6

Last publish

Collaborators

  • reothues
  • aishiguang
  • cttrevor
  • shawzhou
  • jiadi0801
  • jsongo
  • rustle
  • zengkp