New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

lazy-docs

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lazy-docs

Lazy document proxy with watcher

latest
Source
npmnpm
Version
0.4.1
Version published
Maintainers
1
Created
Source

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

Keywords

document

FAQs

Package last updated on 10 Dec 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts