npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ionic-cache-src

v0.1.1

Published

Directive to cache files (images,videos, docs)

Downloads

12

Readme

ionic-cache-src

Ionic module for caching resources, works for any HTML tag, use storage and filesystem. Uses Ionic Storage so it supports IndexedDB, SQLite (Cordova), WebSQL

Basic Usage

  • As Directive (html) change src to cacheSrc

    <img cacheSrc="http://sample-videos.com/img/Sample-png-image-1mb.png"/>
    <div cacheSrc="http://sample-videos.com/img/Sample-jpg-image-500kb.jpg"></div>
    <video cacheSrc="http://sample-videos.com/video/mp4/240/big_buck_bunny_240p_1mb.mp4"></video>
  • You can use a preload image while the resource is downloading. It works for any tag. By default it uses a predefined image.

    <img [cacheSrc]="IMAGE_URL" [preImage]="PRELOAD_IMAGE_PATH" />

Installation

Via NPM

$ npm install --save ionic-cache-src @ionic/storage --save

or Yarn

$ yarn add ionic-cache-src @ionic/storage
  • Afterwards, you need to import the IonicCacheSrcModule in your module:
import { NgModule } from '@angular/core';
import { IonicStorageModule } from '@ionic/storage';
import { File } from '@ionic-native/file';
import { FileTransfer } from '@ionic-native/file-transfer';

import { IonicCacheSrcModule } from 'ionic-cache-src';

@NgModule({
    imports: [
        ...
        IonicStorageModule.forRoot(),
        IonicCacheSrcModule
    ],
    providers: [
        File,
        FileTransfer,
        ...
    ]
})
export class YourModule {};

Dependencies

Make sure to install the following ionic modules and cordova plugins:

Advanced Usage

  • Your typescript file. Use cache or cacheAll methods to fetch resources. (Note: Just first time, resource is downloaded and saved in filesystem)

    import { Component } from '@angular/core';
    import { CacheSrcService } from 'ionic-cache-src';
    
    @Component({
        selector: 'home-page',
        templateUrl: 'home.html'
    })
    export class HomePage {
      
        let paths: string[] = [];
    
        constructor(private _cacheSrv: CacheSrcService) {
            let images = [
                'http://sample-videos.com/img/Sample-png-image-500kb.png'
                'http://sample-videos.com/img/Sample-png-image-1mb.png'
                'http://sample-videos.com/img/Sample-jpg-image-500kb.jpg'
            ];
    
            // Use cache() for one resource
            this._cacheSrv.cacheAll(images)
                .subscribe(cacheItems => {
                    this.paths = cacheItems.map(item => item.path);
                });
        }
          
    }
  • Your html file

    <img *ngFor="let path of paths" [cacheSrc]="path"/>

Instance Members

- cache(url)

If not exists, saves a resource in storage and filesystem, otherwise, returns the saved item.

Param | Type | Description --- | --- | --- url | string | URL of the server to download the file, as encoded by encodeURI().

- cacheAll(urls)

Gets a list of resources and evaluates which of them not exists in storage and filesystem and starts download. Otherwise, returns all the saved items.

Param | Type | Description --- | --- | --- urls | string[] | List of URLs of the server to download the file, as encoded by encodeURI().

- find(url)

Returns a value of the first item in storage and filesystem that satisfies the provided url. Otherwise null is returned.

Param | Type | Description --- | --- | --- url | string | URL of the server to download the file, as encoded by encodeURI().

- remove(url)

Removes any item associated with this url. Returns the deleted item with status "deleted".

Param | Type | Description --- | --- | --- url | string | URL of the server to download the file, as encoded by encodeURI().

- clear()

Clears the entire ionic-cache-src storage and filesystem. Returns a list of items with status 'deleted'.

CacheItem

Param | Type | Description --- | --- | --- url | string | URL from where it was downloaded. key | string | Name of the saved file. path | string | File path of the saved resource. status | string | Shows "incomplete" while resource is downloading, "complete" once it is saved.

Supported Platforms

This module works with Ionic Framework (v >= 2.0), the supported platforms being:

  • Android
  • iOS

Contribution

  • Having an issue? or looking for support? Open an issue and we will get you the help you need.

Support this project

If you find this project useful, please star the repo to let people know that it's reliable. Also, share it with friends and colleagues that might find this useful as well. Thank you :smile: