Comparing version 0.4.3 to 0.5.0
@@ -7,15 +7,62 @@ /* | ||
Model is a regular Object with tighter semantics.. | ||
Attribute | ||
*/ | ||
var Recipe = nature.design( | ||
{ name: "ingredients", array: Object }, | ||
{ name: "dishType", scalar: "string" }, | ||
{ name: "region", scalar: "string" }, | ||
{ name: "method", array: "string" }, | ||
{ name: "cook", type: "function", value: function(){ | ||
// cook shit, yeah? | ||
}} | ||
); | ||
var Recipe = nature.design({ | ||
constructor: function(data){ | ||
nature.load(this, data); | ||
}, | ||
inherits: EventEmitter, | ||
attributes: [ | ||
{ name: "ingredients", collection: Ingredients }, | ||
{ name: "dishType" }, // default type: "string" | ||
{ name: "region" }, | ||
{ name: "minutes", type: Number }, | ||
{ name: "method", collection: MethodList } | ||
], | ||
prototype: { | ||
cook: function(){ this.emit("ready"); }, | ||
eat: function(){ } | ||
} | ||
}); | ||
/* Create, load data */ | ||
function Recipe(data){ | ||
nature.load(this, data); | ||
}; | ||
util.inherits(EventEmitter, Recipe); | ||
Recipe.prototype.cook = function(){ this.emit("ready"); }; | ||
Recipe.prototype.eat = function(){ }; | ||
Recipe.prototype.isValid = function(receipe) { | ||
return nature.instance(receipe).attributes.every(function(attr){ | ||
return attr.valid; | ||
}); | ||
} | ||
/* Naturise existing class.. instance "life" is now tracked, Recipe receives static | ||
methods like .valid */ | ||
var NaturisedRecipe = nature.design(Recipe, { | ||
attributes: [ | ||
{ name: "ingredients", collection: Ingredients }, | ||
{ name: "dishType" }, // default type: "string" | ||
{ name: "region" }, | ||
{ name: "minutes", type: Number }, | ||
{ name: "method", collection: MethodList } | ||
] | ||
}); | ||
function Ingredient(data){ | ||
nature.load(this, data); | ||
}; | ||
var NaturisedIngredient = nature.design(Ingredient, [ | ||
{ name: "ingredient" }, | ||
{ name: "quantity", type: Number }, | ||
{ name: "chopped", type: Boolean } | ||
]); | ||
/* Create, load data options */ | ||
var data = { | ||
ingredients: | ||
} | ||
var sauce = new Receipe(data); | ||
@@ -25,8 +72,7 @@ sauce._load(data); | ||
/* Test valid */ | ||
if (nature.valid(sauce){ | ||
}); | ||
// OR | ||
if (sauce._valid){ | ||
/* Test valid options*/ | ||
nature.valid(sauce) | ||
sauce._valid | ||
Recipe.isValid(sauce); | ||
@@ -38,11 +84,36 @@ } else { | ||
/* variants */ | ||
var Caracciera = nature.variant(Recipe, [ | ||
{ name: "region", criteria: /napoli|naples/i }, | ||
{ name: "onion", criteria: 1 }, | ||
{ name: "choppedTomatoCans", criteria: 1 }, | ||
{ name: "garlic", criteria: 2 } | ||
var Caracciera = nature.evolve(Recipe, [ | ||
{ name: "region", test: /Napoli|Sicilia/ }, | ||
{ name: "ingredients", type: CaraccieraIngredients } | ||
]); | ||
var CaraccieraIngredients = nature.design({ attributes: [ | ||
{ name: "onion", value: 1, test: lessThanThree, invalidMsg: "too much onion" }, | ||
{ name: "choppedTomatoCans", value: 1, test: 1 }, | ||
]}); | ||
// OR | ||
var CaraccieraIngredients = nature.collection({ | ||
tests: [ | ||
{ | ||
test: function(array){ | ||
return !array.some(function(ingr){ return ingr.name === "garlic"; }) | ||
}, | ||
failMsg: "NEVER include garlic" | ||
} | ||
], | ||
itemType: Ingredient, | ||
data: [ | ||
{ ingredient: "onion", quantity: 1 }, | ||
{ ingredient: "tomatoes", quantity: 4, chopped: true } | ||
] | ||
}); | ||
CaraccieraIngredients.push({ ingredient: "garlic", quantity: 1 }); | ||
nature.valid(caraccieraIngredients) // false | ||
caraccieraIngredients.remove({ ingredient: "garlic" }); | ||
nature.valid(caraccieraIngredients) // true | ||
/* mixture */ | ||
var RedSauce = nature.variant(Caracciera, Basil) | ||
var RedSauce = nature.merge(Caracciera, Basil) | ||
@@ -64,3 +135,6 @@ /* grouping */ | ||
/* Nature registery */ | ||
nature.classes = [] // constructors | ||
nature.life = {} // distionary of model metadata, keyed by the model instance | ||
// example: Bigot Machine, change person attributes, state event fires ("four-eyed speccy twat/jerk") |
@@ -276,8 +276,10 @@ "use strict"; | ||
} | ||
function setArray(incoming, target){ | ||
var arrayItems = incoming.slice(0), | ||
function setArray(array, target){ | ||
var arrayItems = array.slice(0), | ||
item, | ||
defaultValues = []; | ||
if (incoming === process.argv){ | ||
if (array === process.argv){ | ||
arrayItems.splice(0, 2); | ||
@@ -284,0 +286,0 @@ } |
exports.Model = require("./Model"); | ||
exports.Attribute = require("./Attribute"); | ||
exports.Design = require("./Design"); |
{ | ||
"name": "nature", | ||
"version": "0.4.3", | ||
"version": "0.5.0", | ||
"description": "Classify the things in your world and how they interact.", | ||
"main": "lib/nature.js", | ||
"scripts": { | ||
"test": "mocha --reporter spec test/*.js" | ||
"test": "mocha --reporter spec test/unit-*.js" | ||
}, | ||
@@ -16,4 +16,5 @@ "repository": "https://github.com/75lb/nature.git", | ||
"devDependencies": { | ||
"mocha": "~1.18" | ||
"mocha": "~1.18", | ||
"tape": "^2.13.1" | ||
} | ||
} |
[![view on npm](http://img.shields.io/npm/v/nature.svg)](https://www.npmjs.org/package/nature) | ||
![npm module downloads per month](http://img.shields.io/npm/dm/nature.svg) | ||
[![npm module downloads per month](http://img.shields.io/npm/dm/nature.svg)](https://www.npmjs.org/package/nature) | ||
[![Build Status](https://travis-ci.org/75lb/nature.svg?branch=master)](https://travis-ci.org/75lb/nature) | ||
@@ -9,2 +9,40 @@ [![Dependency Status](https://david-dm.org/75lb/nature.svg)](https://david-dm.org/75lb/nature) | ||
====== | ||
**big-ass rewrite in progress** | ||
abstract validation tests, for re-usabilty. | ||
Model | ||
----- | ||
A plain object with | ||
- validation per property | ||
- validation per whole object (e.g. values must not match) | ||
- observable, emit change events | ||
Command line parse | ||
------------------ | ||
- define which are boolean options | ||
- which is the default option | ||
- define alias | ||
- define description | ||
- free usage | ||
Collection | ||
---------- | ||
- validation (e.g. all files in a collection exist) | ||
nature module | ||
------------- | ||
provides extra features on models and collections.. | ||
- test valid: nature.isValid(model) | ||
- group: nature.group(model, [ "name", "type" ], "groupA") | ||
- mixin: nature.merge(commandLineArgs, fileArgs) | ||
- extract: nature.where(model, "fileArgs") | ||
- create | ||
var argv = nature.create([ | ||
{ name: "one", alias: "a" }, | ||
{ name: "files", alias: "a", required: true, defaultOption: true }, | ||
{ name: "verbose", type: "boolean" } | ||
]); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
86531
25
2079
48
2
1