Oak Docs

Oak Core

The core contains functionality and properties common to oak packages. To install the core package use bower.

$ bower install oak

Documentation

Collections

each oak.each(stack, iterator[, context])

Convenience function for looping arrays and objects.

// Looping an array
var arr = ["one", "two", "three"];
oak.each(arr, function (item, index) {
    // Do something
});

// Loop and object
var obj = {one: "two", three: "four"};
oak.each(obj, function (key, val) {
    // Do something
});

strap oak.strap(*arguments), Array.strap(*arguments), HTMLElement.strap(*arguments), String.strap(*arguments)

Returns a collection of objects which functions can be applied to every item in the strap.

var largeButtons = oak.strap(".large-button");
// Also OK
var largeButtons = ".large-button".strap();

Existence

exists oak.exists(*arguments)

Helper that checks if a list of arguments exist. If any arguments are undefined, null, false or 0 it will return false.

// Returns, false
oak.exists(0);
// Return true
oak.exists(true, 1, 2);

defined oak.defined(*arguments)

Helper that checks if a list of arguments is defined. If any one of the arguments is undefined it returns false. Only returns true if all arguments are not undefined.

var
    myVar = "Hello World",
    fooBar = "Foo Bar";

// Returns true
oak.defined(myVar, fooBar);

myVar = undefined;

// Returns false
oak.defined(myVar, fooBar);

Extending

extend oak.extend(targ)

Allows the first argument to be extended with the properties of any subsequent arguments.

var Base = function () {

    this.init = function () {
        this.x = 20;
        this.y = 100;
    };

};

oak.extend(Base.prototype, {
    add: function () {
        return x + y;
    }
});

Exposed Methods

add strap.add(val)

Adds an item or array of items to a strap

var myStrap = oak.strap("li");
myStrap.add(oak.strap("div"));

each strap.each(iterator, context)

Convenience function for looping an oak strap

var myStrap = oak.strap("li");
oak.strap("li").each(function (item, index) {
    // Do something
});

extend strap.extend(*arguments)

Allows any object to be extended with the properties of the first argument

var myStrap = oak.strap();
myStrap.extend({});

Type checking

isArguments oak.isArguments(val)


isArray oak.isArray(val)


isDate oak.isDate(val)


isElement oak.isElement(val)


isEmpty oak.isEmpty(val)


isFunction oak.isElement(val)


isNode oak.isNode(val)


isNumber oak.isNumber(val)


isRegexp oak.isRegexp(val)


isStrap oak.isStrap(val)

Returns true if val is a strapped object.


isString oak.isString(val)


Utlities

privateKey oak.privateKey

A key specific to a user's session