4.0.0 • Published 2 years ago
@straw-hat/fancy-map v4.0.0
@straw-hat/fancy-map
Usage
- Reference guides Please use
yarn docs:reference
to generate the reference docs.
import * as fs from 'fs';
import { FancyMap } from '@straw-hat/fancy-map';
// It has all the functionalities of a Map
const map = new FancyMap<string, string>();
function readTemplate(key: string) {
// The callback will be trigger only when `key` is not found in the map.
// It could be useful to do some caching.
return fs.promises.readFile('some/path/to/file', { encoding: 'utf-8' });
}
await map.getOrSet('template', readTemplate);
// You could also use `getOrSetSync`