0.8.0 • Published 11 months ago

memo-again v0.8.0

Weekly downloads
478
License
MIT
Repository
-
Last release
11 months ago

Two-level memoizer with promises stores function values in memory and/or file caches. Writes to memory and file caches can be independently changed on demand. The file cache is stored in the application local folder by default, so you may want to add local/ to .gitignore.

Memoizer

For more examples, see test/memoizer.js

const { Memoizer } = require("memo-again");
var f = x=>42+x;
var mzr = new Memoizer();
var fmemo = mzr.memoize(f);

fmemo(0); // 42 
fmemo(0); // 42 (cached)
fmemo(1); // 43
fmemo(1); // 43 (cached)

Files

File iterators and more...

Iterate over all files in directory (async)

Async generator permits precise control of thread usage.

    var files = [];
    for await (let f of Files.files(FILES_DIR)) {
        files.unshift(f);
    }
    // [ "hello", "sub/basement", "universe", ]
Customize file iteration

Async generator provides fs.Stats

    var opts = {
        root: FILES_DIR,
        stats: true, // return fs.Stats object
        absolute: true, // return absolute filepath
    }
    for await (let f of Files.files(FILES_DIR)) {
        console.log(JSON.stringify(f));
        // {path:..., stats:...}
    }
Spread-syntax initialization (sync-only)

Sync generator uses fs sync methods and can be slower.

    var files = [...Files.filesSync(FILES_DIR)];
    // [ "hello", "sub/basement", "universe", ]
Application folder

The application that uses this library

console.log(Files.APP_DIR);
// /home/somebody/myapp
Local folder

Use "local" folder for application data. Remember to add it to .gitignore

console.log(Files.LOCAL_DIR);
// /home/somebody/myapp/local
0.8.0

11 months ago

0.7.0

11 months ago

0.5.0

2 years ago

0.6.0

2 years ago

0.4.0

3 years ago

0.3.12

4 years ago

0.3.11

4 years ago

0.3.10

4 years ago

0.3.9

4 years ago

0.3.8

4 years ago

0.3.6

4 years ago

0.3.5

4 years ago

0.3.3

4 years ago

0.3.1

4 years ago

0.2.1

4 years ago

0.2.3

4 years ago

0.2.0

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.5

4 years ago

0.1.4

4 years ago