crackle
v0.1.0
Published
JavaScript predicate, comparator, equality, and utility functions
Downloads
3
Readme
Crackle
JavaScript predicate, comparator, equality, and utility functions
Crackle is collection of useful JavaScript functions for both the browser and server. Specifically it focuses on collection predicate operations, such as "all or nothing" verification, and also makes working with sets of jQuery Objects easier.
##Getting started
###Node.js
Install Crackle with NPM (Node Package Manager).
$ npm install crackle
var Crackle = require('crackle');
###Web browser
Download and include crackle.min.js.
<script src="crackle.min.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8">
var values = [1, 2, 3];
var Is = Crackle.is;
if (Is(1).in(values)) {
alert(Crackle.not(values).in([1, 2, 3, 4, 5]));
}
</script>
##API
###Value predicates
.is(value).in(self)
Return true
if value self
exists in an Array that
.
.is(self).all(predicate)
Return true
if all values in Array self
satisfy Function predicate
.
.is(self).typeof(type)
Return true
if all values in Array self
satisfy String type
.
.is(self).instanceof(predicate)
Return true
if all values in Array self
are instanceof Constructor.
###Object predicates
.key(property).in(self)
Return true
if key
exists in Object self
.
.is(self).key(property).defined()
Return true
if key
exists for each Object in Array self
.
.is(self).key(property).all(predicate)
Return true
if Object[property]
satisfies Function predicate
for each Object in Array self
.
###jQuery
.parse(html)
Return jQuery Object (Array) from HTML String (Array).
.stringify(object)
Return HTML String (Array) from jQuery Object (Array).
.similar(self).to(that)
Return true
if DOM node self
and that
have the same HTML content or are the same ID.
###Utility
.not(self).in(that)
Return elements of Array self
not in Array that
.