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

dir_cache

v1.0.3

Published

This cache files in folders

Downloads

260

Readme

cacheDir

This module is needed for caching data. It can search for files with certain extension in folders. Collect file contents or contents could be through a flaw require function. Also caches template files swigJs.

Installation


npm install utils-igor

example


var dirCache = require('./index');
var async = require('async');
var ut = require('util');

async.series([

        (done) => {
            console.log('Test scan all file in folder');
            dirCache.scan({dirs : 'for-example/views1'}, (e, scan) => {

                if (e) {
                    console.log('Error initail', e);
                    return done();
                }

                scan.run((e, res) => {
                    console.log('err ', e);
                    console.log('res ', ut.inspect(res, false,  null));
                    done();
                });
            }) ;
        },

        (done)  => {
            console.log('Test read two folders. Get only html files');
            dirCache.read({
                dirs : ['for-example/views1', 'for-example/views'],
                exts : ['.html']
            }, (e, scan) => {

                if (e) {
                    console.log('Error initail', e);
                    return done();
                }

                scan.run((e, res) => {
                    console.log('err ', e);
                    console.log('res ', ut.inspect(res, false,  null));
                    done();
                });
            }) ;

        },

        (done)  => {
            console.log('Test get files for swig');
            dirCache.swig({
                dirs : 'for-example/views1',
                exts : '.html'
            }, (e, scan) => {

                if (e) {
                    console.log('Error initail', e);
                    return done();
                }

                scan.run((e, res) => {
                    console.log('err ', e);
                    console.log('res ', ut.inspect(res, false,  null));
                    done();
                });
            }) ;

        },

        (done) => {
            console.log('Test get files for required js, json and call exporst if is function');
            dirCache.required({
                dirs : 'for-example/controllers'
            }, (e, scan) => {

                if (e) {
                    console.log('Error initail', e);
                    return done();
                }

                scan.run((e, res) => {
                    console.log('err ', e);
                    console.log('res ', ut.inspect(res, false,  null));
                    done();
                });
            }) ;

        },

    (done) => {
        console.log('Test get files for required js');
        dirCache.required({
            dirs : 'for-example/controllers',
            isCall : false,
            exts : '.js'
        }, (e, scan) => {

            if (e) {
                console.log('Error initail', e);
                return done();
            }

            scan.run((e, res) => {
                console.log('err ', e);
                console.log('res ', ut.inspect(res, false,  null));
                done();
            });
        }) ;

    },

    (done) => {
        console.log('Test get files for required js with call with a specified method');
        dirCache.required({
            dirs : 'for-example/controllers',
            isCall : false,
            call : 'init',
            exts : '.js'
        }, (e, scan) => {

            if (e) {
                console.log('Error initail', e);
                return done();
            }

            scan.run((e, res) => {
                console.log('err ', e);
                console.log('res ', ut.inspect(res, false,  null));
                done();
            });
        }) ;

    }

], function (e) {
    console.log('The end :)');
});

module.exports : Object

Exports classes

Kind: Exported member

module.exports~Frame

It is a frame for other classes

Kind: inner class of module.exports

frame.err(mess) ⇒ Object

Return error object and set flag for stop process

Kind: instance method of Frame

| Param | | --- | | mess |

frame.warn(mess, that)

Get text for message

Kind: instance method of Frame

| Param | Type | | --- | --- | | mess | String | | that | Class |

module.exports~Scan

Search files in folders

Kind: inner class of module.exports

new Scan(options, cb)

Set option to class and run callback

| Param | Type | | --- | --- | | options | object | | cb | function |

scan.valid(options)

Validates options

Kind: instance method of Scan

| Param | Type | | --- | --- | | options | Object |

scan.beforeValid(options) ⇒ Object

Hook before validates options

Kind: instance method of Scan

| Param | Type | | --- | --- | | options | Object |

scan.iterValid(options, k, v) ⇒ boolean

Hook for iter validates options

Kind: instance method of Scan

| Param | Type | | --- | --- | | options | Object | | k | String | | v | String |

scan.isCorrectExt(file) ⇒ boolean

Check extension file

Kind: instance method of Scan

| Param | Type | | --- | --- | | file | String |

scan.isAll() ⇒ boolean

Check use all extension

Kind: instance method of Scan

scan.run(cb) ⇒ *

Start search process

Kind: instance method of Scan

| Param | Type | | --- | --- | | cb | function |

module.exports~Swig

Get text swig template files and jon partial

Kind: inner class of module.exports

swig.run(cb)

Start collected process

Kind: instance method of Swig

| Param | Type | | --- | --- | | cb | function |

swig.fileGet(dir, file, endFile)

Get text files

Kind: instance method of Swig

| Param | Type | | --- | --- | | dir | String | | file | String | | endFile | function |

swig.fileToRes(pathFile, dir, file, data, cb)

Write text to result

Kind: instance method of Swig

| Param | Type | | --- | --- | | pathFile | String | | dir | String | | file | String | | data | String | | cb | function |

swig.dataToRes(pathFile, dir, {Stringfile, {Stringdata, cb) ⇒ *

Write data to result

Kind: instance method of Swig

| Param | Type | | --- | --- | | pathFile | String | | dir | String | | {Stringfile | | | {Stringdata | | | cb | function |

swig.oneLineBreak(data) ⇒ string | XML | * | void

Clears data from the extra line breaks

Kind: instance method of Swig

| Param | Type | | --- | --- | | data | String |

module.exports~Reader

Get text any files

Kind: inner class of module.exports

reader.fileToRes(pathFile, dir, file, data, endFile)

Write text to result

Kind: instance method of Reader

| Param | Type | | --- | --- | | pathFile | String | | dir | String | | file | String | | data | String | | endFile | function |

module.exports~Reuired

Get files via function require

Kind: inner class of module.exports

reuired.beforeValid(options) ⇒ Object

Overwrite before valid

Kind: instance method of Reuired

| Param | Type | | --- | --- | | options | String |

reuired.fileGet(dir, file, endFile) ⇒ *

Overwrite fileGet

Kind: instance method of Reuired

| Param | Type | | --- | --- | | dir | String | | file | String | | endFile | function |

module.exports~Cache

Create object for saving data

Kind: inner class of module.exports