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](#exp_module_cacheDir--module.exports) : <code>Object</code> ⏏
* [~Frame](#module_cacheDir--module.exports..Frame)
* [.err(mess)](#module_cacheDir--module.exports..Frame+err) ⇒ <code>Object</code>
* [.warn(mess, that)](#module_cacheDir--module.exports..Frame+warn)
* [~Scan](#module_cacheDir--module.exports..Scan)
* [new Scan(options, cb)](#new_module_cacheDir--module.exports..Scan_new)
* [.valid(options)](#module_cacheDir--module.exports..Scan+valid)
* [.beforeValid(options)](#module_cacheDir--module.exports..Scan+beforeValid) ⇒ <code>Object</code>
* [.iterValid(options, k, v)](#module_cacheDir--module.exports..Scan+iterValid) ⇒ <code>boolean</code>
* [.isCorrectExt(file)](#module_cacheDir--module.exports..Scan+isCorrectExt) ⇒ <code>boolean</code>
* [.isAll()](#module_cacheDir--module.exports..Scan+isAll) ⇒ <code>boolean</code>
* [.run(cb)](#module_cacheDir--module.exports..Scan+run) ⇒ <code>\*</code>
* [~Swig](#module_cacheDir--module.exports..Swig)
* [.run(cb)](#module_cacheDir--module.exports..Swig+run)
* [.fileGet(dir, file, endFile)](#module_cacheDir--module.exports..Swig+fileGet)
* [.fileToRes(pathFile, dir, file, data, cb)](#module_cacheDir--module.exports..Swig+fileToRes)
* [.dataToRes(pathFile, dir, {Stringfile, {Stringdata, cb)](#module_cacheDir--module.exports..Swig+dataToRes) ⇒ <code>\*</code>
* [.oneLineBreak(data)](#module_cacheDir--module.exports..Swig+oneLineBreak) ⇒ <code>string</code> | <code>XML</code> | <code>\*</code> | <code>void</code>
* [~Reader](#module_cacheDir--module.exports..Reader)
* [.fileToRes(pathFile, dir, file, data, endFile)](#module_cacheDir--module.exports..Reader+fileToRes)
* [~Reuired](#module_cacheDir--module.exports..Reuired)
* [.beforeValid(options)](#module_cacheDir--module.exports..Reuired+beforeValid) ⇒ <code>Object</code>
* [.fileGet(dir, file, endFile)](#module_cacheDir--module.exports..Reuired+fileGet) ⇒ <code>\*</code>
* [~Cache](#module_cacheDir--module.exports..Cache)
module.exports : Object
⏏
Exports classesKind: Exported member
module.exports~Frame
It is a frame for other classesKind: inner class of
module.exports
* [.err(mess)](#module_cacheDir--module.exports..Frame+err) ⇒ <code>Object</code>
* [.warn(mess, that)](#module_cacheDir--module.exports..Frame+warn)
frame.err(mess) ⇒ Object
Return error object and set flag for stop processKind: instance method of
Frame
| Param | | --- | | mess |
frame.warn(mess, that)
Get text for messageKind: instance method of
Frame
| Param | Type | | --- | --- | | mess |
String
|
| that | Class
| module.exports~Scan
Search files in foldersKind: inner class of
module.exports
* [new Scan(options, cb)](#new_module_cacheDir--module.exports..Scan_new)
* [.valid(options)](#module_cacheDir--module.exports..Scan+valid)
* [.beforeValid(options)](#module_cacheDir--module.exports..Scan+beforeValid) ⇒ <code>Object</code>
* [.iterValid(options, k, v)](#module_cacheDir--module.exports..Scan+iterValid) ⇒ <code>boolean</code>
* [.isCorrectExt(file)](#module_cacheDir--module.exports..Scan+isCorrectExt) ⇒ <code>boolean</code>
* [.isAll()](#module_cacheDir--module.exports..Scan+isAll) ⇒ <code>boolean</code>
* [.run(cb)](#module_cacheDir--module.exports..Scan+run) ⇒ <code>\*</code>
new Scan(options, cb)
Set option to class and run callback| Param | Type | | --- | --- | | options |
object
|
| cb | function
| scan.valid(options)
Validates optionsKind: instance method of
Scan
| Param | Type | | --- | --- | | options |
Object
| scan.beforeValid(options) ⇒ Object
Hook before validates optionsKind: instance method of
Scan
| Param | Type | | --- | --- | | options |
Object
| scan.iterValid(options, k, v) ⇒ boolean
Hook for iter validates optionsKind: instance method of
Scan
| Param | Type | | --- | --- | | options |
Object
|
| k | String
|
| v | String
| scan.isCorrectExt(file) ⇒ boolean
Check extension fileKind: instance method of
Scan
| Param | Type | | --- | --- | | file |
String
| scan.isAll() ⇒ boolean
Check use all extensionKind: instance method of
Scan
scan.run(cb) ⇒ \*
Start search processKind: instance method of
Scan
| Param | Type | | --- | --- | | cb |
function
| module.exports~Swig
Get text swig template files and jon partialKind: inner class of
module.exports
* [.run(cb)](#module_cacheDir--module.exports..Swig+run)
* [.fileGet(dir, file, endFile)](#module_cacheDir--module.exports..Swig+fileGet)
* [.fileToRes(pathFile, dir, file, data, cb)](#module_cacheDir--module.exports..Swig+fileToRes)
* [.dataToRes(pathFile, dir, {Stringfile, {Stringdata, cb)](#module_cacheDir--module.exports..Swig+dataToRes) ⇒ <code>\*</code>
* [.oneLineBreak(data)](#module_cacheDir--module.exports..Swig+oneLineBreak) ⇒ <code>string</code> | <code>XML</code> | <code>\*</code> | <code>void</code>
swig.run(cb)
Start collected processKind: instance method of
Swig
| Param | Type | | --- | --- | | cb |
function
| swig.fileGet(dir, file, endFile)
Get text filesKind: instance method of
Swig
| Param | Type | | --- | --- | | dir |
String
|
| file | String
|
| endFile | function
| swig.fileToRes(pathFile, dir, file, data, cb)
Write text to resultKind: 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 resultKind: 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 breaksKind: instance method of
Swig
| Param | Type | | --- | --- | | data |
String
| module.exports~Reader
Get text any filesKind: inner class of
module.exports
reader.fileToRes(pathFile, dir, file, data, endFile)
Write text to resultKind: instance method of
Reader
| Param | Type | | --- | --- | | pathFile |
String
|
| dir | String
|
| file | String
|
| data | String
|
| endFile | function
| module.exports~Reuired
Get files via function requireKind: inner class of
module.exports
* [.beforeValid(options)](#module_cacheDir--module.exports..Reuired+beforeValid) ⇒ <code>Object</code>
* [.fileGet(dir, file, endFile)](#module_cacheDir--module.exports..Reuired+fileGet) ⇒ <code>\*</code>
reuired.beforeValid(options) ⇒ Object
Overwrite before validKind: instance method of
Reuired
| Param | Type | | --- | --- | | options |
String
| reuired.fileGet(dir, file, endFile) ⇒ \*
Overwrite fileGetKind: instance method of
Reuired
| Param | Type | | --- | --- | | dir |
String
|
| file | String
|
| endFile | function
| module.exports~Cache
Create object for saving dataKind: inner class of
module.exports