1.0.0 • Published 10 years ago

levo v1.0.0

Weekly downloads
3
License
Apache-2.0
Repository
github
Last release
10 years ago

node-levo

NPM

Build Status Coverage Status npm version


Levo lifts the experience of NodeJS programming by providing a set of essential enhancements.

npm install levo --save

Modules

Levo is composed of different modules, each providing useful functions for a particular set of requirements:

  1. fs
  2. util

fs

Functionality for file system related tasks.

var _fs = require('levo').fs;

WalkStream

var walk = new _fs.WalkStream('/my/dir');

The stream emits data events with Info objects, for each file/directory encountered. Also, any errors encountered are emitted as walkError events.

      walk.on('walkError',console.error);
      // console: EACCESS: no permission, scandir: /my/dir/root

      walk.on('data',console.log);
      // console: {name:'test.png', file:'/my/dir/test/png', depth:0, stats:{...}}

Behaviour can be configured by passing additional options parameter to constructor.

      // Example: recurse to a maximum depth of 5, and do not recurse into symlink directories.

      var noSymlinks = function(info){return ! info.isSymbolicLink();}

      var options = {maxdepth:5, lstat:true, recurseFilter: noSymlinks};

      var walk = new levo.fs.WalkStream('/my/dir',options);

      walk.on('data',console.log);

Options parameter may include the following settings if required: 1. maxDepth : number, limit recursion to this depth. 0 means no recursion. 2. lstat : if set to true, native lstat() is used instead of stat() to get file stats. 3. recurseFilter : function to filter directories to recurse. Called with directory Info, must return true to allow recursion.

Info

Holds information about a file entry processed during a directory walk.

Properties:

  • name - name of the file entry.
  • file - path of file entry.
  • depth - depth from root directory being walked. 0 being in root directory.
  • stats - file entry stats.

util

Utility helpers.

var _util = require('levo').util;

createRequire()

Returns a function that is similar to NodeJS require, in that it is used to load modules. However the returned function also looks for modules in directories that are passed to levo.require() as arguments.

var __require = _util.createRequire( __dirname, '/my/other/node/modules');

var user = __require('models/user');
var lib = __require('other-module')

The __require can also be set to global scope:

// before all other code, add root directory for lookup
global.__require = levo.require( __dirname);

for easy usage from anywhere in code:

// inside some other module
var app = __require("app");
1.1.0

9 years ago

1.0.0

10 years ago

0.1.0

10 years ago