node-bauer-factory
General utilities for nodejs.
Installation
npm install bauer-factory
Usage
var factory = ;
.type
Returned value can be string, number, boolean, date, regexp, error, array, object, arguments, null, undefined or function.
// returns type of given argumentvar type = factorytypearg;
.isNull
factory// same asfactorytypearg === "null"
.isDefined
factory// same asfactorytypearg !== "undefined"
.isUndefined
factory// same asfactorytypearg === "undefined"
.isDate
factory// same asfactorytypearg === "date"
.isError
factory// same asfactorytypearg === "error"
.isBoolean
factory// same asfactorytypearg === "boolean"
.isArray
factory// same asfactorytypearg === "array"
.isNumber
factory// same asfactorytypearg === "number"
.isString
factory// same asfactorytypearg === "string"
.isObject
factory// same asfactorytypearg === "object"
.isRegExp
factory// same asfactorytypearg === "regexp"
.isFunction
factory// same asfactorytypearg === "function"
.isArguments
factory// same asfactorytypearg === "arguments"
.createMethod
Accepts an object containing types/lengths as keys and values as functions.
var func = factory;
Letters are taken as the first character of the argument's type as returned by factory.type
. Any combination can be used to route the function execution. This takes priority over argument's length routing.
var func = factory;
Numbers are taken as the length of the arguments object. Nested rules are supported.
var func = factory;
Underscore holds the default code. If no rule is matched and there's no _
throws an ReferenceError
.
var func = factory;
Strings can be used as code. They are converted to functions internally with the defined arguments.
var func = factory;
If the code does not use any external vars its possible to optimize the generated function by passing a second argument as true
.
var optimized = factory; // tell factory.method that this function does not use any external var
.createClass
Creates a class with given methods, constructor and inheritance.
var Bauer = factory;
The created class can be instantiated and inherited just like any other class.
var jack = ; jack; jack; jack;
.createObject
Creates a class just like .class does and returns an instance of it.
// accepts same arguments as .createClassvar jack = factory;