Giter Site home page Giter Site logo

indexeddb-image-cache's Introduction

indexeddb-image-cache Build

Oh yeah, we have Image Cache uses IndexedDB!

Pros:

  • No localStorage 5Mb size limit
  • Keep the cache as long as you want
  • Better for some expensive action cache (download/alogrithm calculated)

Arguments:

Thoughts:

  • Developers grab the wheel
  • Just for image/simple blob caching, CacheStorage only accessed by worker, it's complicated to use

Usage

npm i indexeddb-image-cache
import ImageCache from 'indexeddb-image-cache'

const BASE64 = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAIAQMAAAD+wSzIAAAABlBMVEX///+/v7+jQ3Y5AAAADklEQVQI12P4AIX8EAgALgAD/aNpbtEAAAAASUVORK5CYII';
const cache = new ImageCache({ version: 1 });
await cache.init();
await cache.putImage('trophy', BASE64);
// await cache.putBlob('blob', blobInstance)
// somewhere else
// it will return string by URL.createObjectURL()
// get blob easily by: let blob = await fetch(url).then(r => r.blob());
const image = await cache.getImage('trophy')
  • More usage see image-cache.test.ts file

Tech Stack

  • Vite
  • Vitest
  • Typescript

It includes test examples using vite test

COMMANDS

run build for local dist testing

npm run build

run tests

npm run test

check test coverage

npm run coverage

build npm release package

npm pack

Dry run the npm release package

npm pack --dry-run

run eslint

npm run lint

run and fix eslint issues found

npm run lint-and-fix

run prettier on your files

npm run pretty

clean up the codebase by runnning eslint and prettier

npm run clean-up

indexeddb-image-cache's People

Contributors

tcper avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.