mini; a small javascript programming library
compatibility pathches won't clober native methods (if present)
Functions
util
- JSON: normal JSON compat, std lib
- JSON.view: pretty print the non-method properties in an object
- Math.sum: returns the sum af all args. try Math.sum.apply(0, myArray);
- Math.sum: returns the average af all args. try Math.avg.apply(0, myArray);
tags
- el: gets an element by id
- els: gets an element's style object by elm's id
- Q: returns an array of tags from a css selector.optional 2nd arg: str or elm root.
- addevent: (tag,strEvent, fnEvent) the usual suspect
- tags: get tags into array by tag name
- aCSS: adds a new stylesheet from a string containing css text
- dom: several methods to simplify working with the dom:
- dom.div(nodeName, content) - quickly creates a new element with the value/innerHTML of content
- dom.attribs(elm, attribOb) - binds an object of attribs and properties to an element
- dom.create(nodeName, content, attribs) - a new element filled with content and bound to attribs object
- dom.prependChild(newChild, parentElement) - makes newChild the first sub-tag inside parentElement
- dom.text(elm) - returns the text content of an element. handles inputs and regular tags.
- dom.kill(elm) - removes an element from the document
- dom.encodeHTML(str) - allows source code to be display without parsing
- dom.getParent(elm, tagName) - finds the first tagName tag wrapping the element
- dom.replace(newNode, oldNode) - replaces one element with another
New Object Methods (not prototypes). see ecmaScript 5 docs for info.
- getPrototypeOf
- getOwnPropertyDescriptor
- getOwnPropertyNames
- create
- defineProperties
- keys
Array extras
- map: applies a function to each index of an array
- filter: filters array elements according to truthfulness of function's return
- indexOf: gives arrays an indexOf feature
- all other now-standard [] methods like some, every, reduce, reduceRight, lastIndexOf
- pluck: build a new array of objects from a passed array of keynames
- random: a random element of an array
- unique: returns a duplicate-free array
- valids: array without undefined elements
- _: a property of each element
- bind: adds propert(y/ies) /methods to each element
- iif: a conditional to filter an array of objects ex: tags("*").iif(".className=='active' ")
data handlers
- ping(url): send a GET request to any URL on any domain
- store(key, val): client-side persistence. if !! val then set else get key (ff+ie only)
- IO : file saving and loading. loads synchronous, saves asynch
- jsGet(url): simple remote scripting tag adder
- tmpl8: a substitution template using json: **key**- tmpl8( [{a:1},{a:4}] , "#: **a**\t") ="#: 1 #: 4 "
Object.toSource(): json serializer for all browsers
rakes
- obKeys: array of object's key names
- obMap: 2 column array from objects key and values : {k:v, k2:v2} => [ [k,v], [k2,v2] ]
- obVals: array of object's values
- obValsl: returns an array of objects from objects with native .length properties (like nodeLists and collections)
Includes F, a collection of logical and comparitive functions for functional programming.
F . Properties:
Shortcuts to common Globals(F.x):
A: Array
F: Function
S: String
N: Number
R: RegExp
B: Boolean
D: Document
I: parseInt (1 arg wrap)
//ex: F.A("a,b,c")//===["a", "b", "c"]
id: k
comparisons - [].filter(name,[varCompare]):
["min", "max", "equal", "even", "gt", "lt", "match", "not", "odd","same"]
types:
["isInt", "bytypes"]
filters:
[ "If": [1,2,3,4,2,3,4,2,3,5,4,76,5,3].filter(F.If("a>4")), //[5, 76, 5]
"ok": true if arg !== (null||undefined),
"unique" ]
transforms:
["tag", "sum", "times", "extract", "fill", "invoke", "run"]
//ex:[1,2,3].map(F.tag,"dan")
util methods:
F.keys({A:1,b:2})//["A", "b"]
[]. clean methods only:
avg : [3,5,9].clean(F.avg, [0], true)//5.6666
count: [3,5,3,6,3,9,3,2,3].clean(F.count,[0],1)[ 3 ]//==5 (threes)
zip: [1,2].clean(F.zip,[4,5])//==[[1, 4], [2, 5]]