- Object-less versions of Array's prototype methods like .map()
- An each() function that works with all types of collections
- Functional polymorphism with multimethods
- An optional hierarchical type system that can be used with multimethods and by itself
- Defining simple schemas and validating data according to these schemas (minus the suckiness of XML Schema and the like)
- Higher-order functions that help you with composition
Install using NPM:
npm install enjoy-js
On the frontend, you can use ENJOY with either using.js:
Or without it:
Polymorphism with multimethods
Multimethods are methods that don't belong to classes; therefore there's no need to trap your data inside of classes.
each(collection, fn) iterates a collection like an array or object.
some(collection, fn) iterates a collection. It returns
true if some the
true for one of the items in the collection and breaks
the iteration in this case. If the callback returns
false for all the items,
In ENJOY.js, validating data can be done by using either the
valid(data, schema) function
or by creating a validator with the
validator(schema) function and then using the resulting
function to check the data.
isA(a, t) function and the
type(checker) function are both able to be used with schemas.
Schemas can contain pure data, as well as predicate functions and types, which are used to validate specific values in the data. This means the data may not include functions - but they shouldn't anyway.
Here's an example: