README
Wyld
Wyld is a lightweight Javascript library that allows you to easily create input-output mappings.
This library is named after James Wyld.
Table of Contents
Installation
You can use any of the following Javascript package managers to install Wyld.
npm install wyld
bower install wyld
yarn add wyld
Usage
Use Wyld.Map
in conjunction with a configuration object to create your map.
var map = Wyld.Map({
// map configuration goes here
});
When you want to retrieve an output for a given input using the map, call the get
method.
var output = map.get(input);
Types of Mappings
Direct
To create a direct mapping from an exact input to an exact output, use a key-value assignment.
var map = Wyld.Map({
5: 10
});
map.get(5); // returns 10
Duplicate input keys will result in the last one being used.
var map = Wyld.Map({
5: 10,
5: 50
});
map.get(5); // returns 50
Conditional
To map multiple inputs to a single output based on whether or not the input satisfies a condition, use keys in quotes and include the relevant operator.
var map = Wyld.Map({
'>10': 10,
'<5': 5
});
map.get(50); // returns 10
map.get(2); // returns 5
The conditions supported are greater than >
, less than <
, greater than or equal to >=
, and less than or equal to <=
.
There are two ways to evaluate multiple conditions at once. The first is to use a single &
operator to separate conditions.
var map = Wyld.Map({
'>5&<10': 20,
});
map.get(7); // returns 20
The second way is to put a dollar sign $
in the key to represent the input and surround it with the conditions.
var map = Wyld.Map({
'5<