library under construction
Nature
The Nature library provides a class (Thing
) which creates objects with strict, per-property type and value checking. This enables more fine-grained classification base on type and state. Say you have a Person
class, with nature you can create a sub-class of Person
in a particular state, e.g. Drunkard
, Scoundrel
, Leader
etc. These Things can be reused, subclassed or merged with other Things to create new hybrids. The Thing
class adds these features to each new object:
- Type and value validation per property
- Data loading from the command line, environment, external file or plain object
- Merging and cloning
- Property grouping and filtering
- A general mechanism for duck typing
Synopsis
Enables you to write an API method like: (Scoundrel
and FlammableCar
are derivitives of Thing
)
exports.burnCar = function(arsonist){
var scoundrel = new Scoundrel(arsonist);
if (!scoundrel.valid){
throw new Error(scoundrel.validationMessages.join("\n"));
} else {
var car = new FlammableCar(process.env);
if (car.valid){
scoundrel.igniteCar(car);
}
}
}
Client code for the above is straight forward. In this case burnCar()
input is taken directly from the command line. You can also pass the environment (process.env
), an object literal or a Thing
instance.
var outdoors = require("outdoor-activity");
outdoors.burnCar(process.argv);
Then a simple command executes the outdoor activity:
$ CAR_MAKE=Vauxhall CAR_MODEL=Astra node outdoors.js --name Alfie --age 11 --litres 13 --compassion unknown
See the Thing docs for more detail..