Skip to content

ajuste/jaune-util

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build StatusCoverage Status

jaune-util package

Set of utilities such as reflection, validators and time among others

Install

npm install jaune-util

Run tests

npm test

Reflection

Reflection gives you the possibility to obtain / call / instantiate members with a string expression. This means you don`t need to know prototypes before hand.

Get a reference by name

You can get a reference by name easily:

var evaluateName = require('jaune-util').Reflection.evaluateName

evaluateName('foo.bar', { foo : { bar : 'my bar' } }); // 'my bar'

Get a reference by requiring a path

Obtain a reference of a module by requering a it`s path. Imagine you have the following tree:

root |--my_module |--test

var evaluateName = require('jaune-util').Reflection.evaluateName

evaluateName('r[(/my_module)]'); // my_module exports

Get a reference by requiring a module

Obtain a reference of a module that exists inside your node_modules:

var evaluateName = require('jaune-util').Reflection.evaluateName

evaluateName('m[(/assert)]'); // requires assert module

Get the result by calling a function

You can call a function with a full path; plus you can specify params:

var evaluateName = require('jaune-util').Reflection.evaluateName

evaluateName('foo.fn.c[(p1, p2)]', {foo: { fn: function(arg1, arg2) { return arg1 + arg2; } }, p1: 2, p2: 10 }) // returns 12

Get the result of creating an instance

You can an instance with a full path; plus you can specify params:

var evaluateName = require('jaune-util').Reflection.evaluateName

evaluateName('foo.fn.i[(p1, p2)]', {
  foo: {
    fn: function(arg1, arg2) {
      this.arg1 = arg1 + 10;
      this.arg2 = arg2 + 10;
    }
  },
  p1: 2, p2: 10 }) // returns {arg1: 12, arg2: 20}