Provide a bunch of most needed high level javascript utility functions, which will work in every browser and in nodejs. The Goal is to make writing shared code easier. The dream is to be also dependency N1 for all node modules, to avoid that every module implements its own "each", "extend" etc. methods.
- high level api with lots of sugar
- focused on speed (benchmarks for every test case)
- no native prototype extensions, no global namespace polution (be compartible to insecure env)
- use of ecma5 features if available and be ecma5 compatible if possible
- don't reinvent the wheel, if there are parts of libs we could use - do it
- every function is as standalone as possible, to reduce dependencies (only if code overhead is minimal)
- no performance overhead for the server because of client support
- well tested
- community driven
- intelligent build tool (include only what you need)
npm
$ npm install sharedjs
git
$ git clone https://github.com/kof/sharedjs.git
$ git submodule update --init
var $ = require("sharedjs");
Iterates over array, object or string, calls callback function once per data element. Quit the loop using "return false;" inside of callback.
data
- object, array or stringcallback
- functioncontext
- object optional
Similar ecma 5 concepts are:
- Array.prototype.forEach https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/forEach
- Array.prototype.some https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/some
- Array.prototype.every https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/every
Merge the contents of two or more objects together into the first object.
-
deep
If true, the merge becomes recursive. -
target
The object to extend. It will receive the new properties. -
object1
An object containing additional properties to merge in. -
objectN
Additional objects containing properties to merge in.var object = $.extend({}, object1, object2);
Inspierd by jQuery http://api.jquery.com/jQuery.extend/
Creates a new function that, when called, itself calls this function in the context of the provided this value, with a given sequence of arguments preceding any provided when the new function was called.
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind
Inherit the prototype methods from one constructor into another. This concept is used in nodejs "util" module and googles closure library.
Validate any type of data. Throws error if data can't pass validation schema.
data
can be any data type, f.e. string, number, object, array, argumentsschema
string, array or object containing schema definitionssilent
silent mode switch - no errors will be threw