blurhash-map
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

blurhash-map

npm package Build Status Downloads Issues Code Coverage Commitizen Friendly Semantic Release

blurhash-map

Install

npm install blurhash-map

Usage

import { BlurHashMap, BlurHashMapConfig } from 'blurhash-map';
const config: BlurHashMapConfig = {
  assetsRoot: 'assets/images/samples',
  hashMapJsonPath: 'test/fixtures/lib/hashmap.json',
  imageExtensions: 'jpg,png,jpeg',
  components: { x: 4, y: 3 },
};
const blurHashMap = new BlurHashMap(config);
blurHashMap.init();
// Now, there should be files created next to images
// with the same name but having `.hash` suffix. You should commit these files
// to avoid re-generate them next time you run `BlurHashMap`.

API

BlurHashMap(config)

config

Type: BlurHashMapConfig

assetsRoot: string; // Required. Where to find the images hashMapJsonPath: string; // Required. Where to save generated JSON imageExtensions: Array; // Optional. Define which image files. Default : 'jpg' | 'jpeg' | 'png' | 'bmp' | 'webp' components?: { x: number; y: number }; // Optional between 1-9. Default {x:4,y:3}. Higher is more detailed blur but longer string

init()

Initialize BlurHashMap asynchronously. Creates .hash files and generates hash-map.json.

generateOrDelete(imageOrHashFilePath: string, skipIfHasHash = false)

Generates a hash file if image is found. If Image is not found, deletes the .hash file of it.

getShortPath(file: string): string

Returns the relative path of the given file to the assetsRoot

async createJson(): Promise

Creates hash-map.json from the found .hash files

/blurhash-map/

    Package Sidebar

    Install

    npm i blurhash-map

    Weekly Downloads

    6

    Version

    1.2.0

    License

    MIT

    Unpacked Size

    364 kB

    Total Files

    20

    Last publish

    Collaborators

    • npmre