0.4.1 • Published 10 years ago

lazy-docs v0.4.1

Weekly downloads
1
License
MIT
Repository
github
Last release
10 years ago

lazy-docs

functional documents for node.

functional documents (a function that returns a document) combines watching changes, document parsing and proxy.

documents only reload if changed and when requested, external changes only flag the file to refresh at next request.

var myfile=require("lazy-docs")()("test/resources/test.txt");
console.log(myfile());//sync mode
myfile((e,o)=>console.log("content:",e||o));//assync mode

usage

this module only exports a setup function, on setup a file creator function is returned. The file creator function should be used to create functional files

require("lazy-docs")(loader function);

where

loader function is optional (default to text load) and should be a function to parse the document from a string/buffer.

This will return a document loader function that expects a filename.

require("lazy-docs")(parser)(filename)

where

filename is a file name string

The loader function will return a functional document. You can associate it with a variable or call it directly

//default parser
var myfile=require("lazy-docs")(/*use default parser*/)("test/resources/test.txt");

then the file can be recalled and will update himself in case of external change

console.log(myfile());//sync mode
myfile(o=>console.log("content:",o));//assync mode

examples

text documents loader

var txtDoc=require('lazy-docs')();//setup for text format
var txt=txtDoc("test/resources/test.txt");//functional file
console.log(txt());//sync file content with cache and watcher
txt(o=>console.log(o));//assync file content with cache and watcher

libxmljs documents loader

var libxml=require('libxmljs');
var xmlDoc=require('lazy-docs')(libxml.parseXml);//setup for libxml documents
var xml=xmlDoc("test/resources/test.xml");
console.log(xml().toString());

closing a document stops watching the file, if you recall the document it will load and watch again

var file=require("lazy-docs")()("myfile.txt");
console.log(file());//print updated text file content
file.proxy.close();//stop watching the file

TODO LIST:

this module defaults to local sync/assync file system, see fProxy for more flexibility

0.4.1

10 years ago

0.4.0

10 years ago

0.3.1

10 years ago

0.3.0

10 years ago

0.2.1

10 years ago

0.2.0

10 years ago

0.1.8

10 years ago

0.1.7

10 years ago

0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.9

10 years ago

0.0.8

10 years ago

0.0.7

10 years ago

0.0.6

10 years ago

0.0.5

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago