New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

behavior-js

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

behavior-js

Simple objects that represent simple behavior

latest
Source
npmnpm
Version
1.0.7
Version published
Maintainers
1
Created
Source

behavior-js

NPM

Build Statusdependencies

Motivation

Provide a minimal way to represent a behavior, whether it's allowed and the exceptions to the allowance.

Installation

npm install behavior-js

Roadmap

  • Actions functions
  • Actions functions async and sequential evaluations

Usage

Instantiation

new Behavior(allowed : boolean, exceptions : string[] | string)

Single exception

Let

var Behavior = require('behavior-js');

// Whether the behavior is allowed
var politenessAllowed = true;

// The exception to the behavior
var politenessException = 'crude honesty';

Instantiation

var politeness = new Behavior(politenessAllowed,politenessException);

Multiple exceptions

Let

var Behavior = require('behavior-js');

// Whether the behavior is allowed
var leadershipAllowed = true;

// The exceptions to the behavior
var leadershipExceptions = [
	'ego',
	'superiority'
];

Instantiation

var leadership = new Behavior(leadershipAllowed,leadershipExceptions);

Evaluation

behavior.isAllowed(action : string) : boolean

Let

var Behavior = require('behavior-js');


// Whether the behavior is allowed
var agressionAllowed = false;

// The exceptions to the behavior
var agressionExceptions = [
	// These are good to have, will be allowed.
	'competitiveness',
	'power desire'
];

// The initialization
var agression = new Behavior(agressionAllowed,agressionExceptions);

Evaluation with an exempted value

// Returns true
agression.isAllowed('competitiveness');

Evaluation with a non-exempted value

// Returns false
agression.isAllowed('anger');

Sample use case

Problem

I have a library that parses url query parameters but I would like to prevent some parameters from getting parsed

Solution

Instantiation

var Behavior = require('behavior-js');

// These are the query parameters we want to prevent from getting parsed
var parsingExceptions = [
	'onSuccess',
	'isNewUser'
];

// We instantiate the behavior, allow it and pass it's exceptions
var parsing = new Behavior(true,parsingExceptions);

Usage

// .. somewhere in your awesome query parsing library
queryParser.parseParameter = function(name,value){
	if(parsing.isAllowed(name)){
		// Do your parsing with complete peace of mind
	}
}

Tests

All of the tests are written in Jasmine with the BDD process

Requirements

npm install gulp typescript tslint tsd -g

Run

npm test

Author: Joel Hernández

Keywords

behavior

FAQs

Package last updated on 13 Jan 2016

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