1.0.17 • Published 2 years ago

dok-file-utils v1.0.17

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

npm.io dok-file-utils

Dobuki's file utils. Just a simple way to load files

Those are browser APIs exposed as npm modules.

CodeQL

pages-build-deployment

Setup

Directly in web page

Include the scripts in html as follow:

<script src="https://unpkg.com/dok-file-utils/src/file-utils.js"></script>
<script src="https://unpkg.com/dok-file-utils/src/image-loader.js"></script>

Through NPM

Add to package.json:

  "dependencies": {
  	...
    "dok-file-utils": "^1.0.0",
    ...
  }

Use Browserify to make classes available in browser

In package.json:

  "scripts": {
  	...
    "browserify": "browserify browserify/main.js -s dok-lib -o public/gen/compact.js",
    ...
  },

In browserify/main.js:

const { FileUtils, ImageLoader } = require('dok-file-utils');

module.exports = {
  FileUtils,
  ImageLoader,
};

Components

FileUtils

Description

FileUtils is used to load files. It caches data for duplicate files loaded to avoid repeated loads.

Usage

const fileUtils = new FileUtils();
const json = await fileUtils.load("file.json");

ImageLoader

Description

ImageLoader is used for loading images. Like FileUtils, it caches images to avoid duplicate. ImageLoader tracks progress of downloaded images, and it uses Blob to provide a URL that can be reused to avoid multiple load of images.

Usage

const imageLoader = new ImageLoader({
			"assets/cursor.png": true,
		});
const image = await imageLoader.load("image.png");

const cursor = await imageLoader.load("assets/cursor.png");
// In this case, cursor.url is the URL of a block that can be reused. This is useful when using a changing cursor in CSS that points to an image, avoiding repeated load of that image.

Demo

demo

1.0.17

2 years ago

1.0.16

2 years ago

1.0.15

2 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.11

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.10

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago