Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nature

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nature

Classify the things in your world and how they interact.

  • 0.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
269
decreased by-37.44%
Maintainers
1
Weekly downloads
 
Created
Source

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"));
        // throws:
        // The arsonist supplied must be a Scoundrel, you passed a Metrosexual
        // Invalid age 29: Must be between 11 and 19. 
        // Over 5 litres Gasoline required
        // Less compassion necessary.
    } else {
        var car = new FlammableCar(process.env);
        if (car.valid){
            // the Vauxhall Astra supplied in the environment is indeed flammable
            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..

githalytics.com alpha

FAQs

Package last updated on 06 Aug 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc