lo

lightweight utility library for the browser

licenseMITgithublrsjng/lonpmlo
0.26.0

Lightweight utility library for the browser.

lo

// check if x is neither null nor undefined
lo.is(x)

lo.isArguments(x)
lo.isArray(x)
lo.isBoolean(x)
lo.isDate(x)
lo.isError(x)
lo.isFunction(x)
lo.isInstanceOf(x, fn)
lo.isNumber(x)
lo.isNumeric(x)
lo.isObject(x)
lo.isPlainObject(x)
lo.isRegExp(x)
lo.isString(x)
lo.isTypeOf(x, str)
lo.has(x, prop)
lo.hasLength(x)

lo.asArray(x)
lo.toArray(x)
lo.asFunction(x)

lo.size(x)
lo.keys(x)
lo.values(x)
lo.forEach(x, fn)
lo.forOwn(x, fn)
lo.each(x, fn)
lo.some(x, fn)
lo.every(x, fn)
lo.map(x, fn)
lo.filter(x, fn)
lo.reduce(x, fn, val)
lo.compact(x)
lo.indexOf(x, el)
lo.contains(x, el)
lo.uniq(x)

lo.cmp(x, y)
lo.sort(x, fn)
lo.sortBy(x, fn)

lo.isElement(x)
lo.isWindow(x)
lo.isDocument(x)
lo.isElDocWin(x)

// triggers as soon as page is ready, might be immediatly
lo.onReady(fn)

// triggers on window resize events
lo.onResize(fn)

// triggers right before and after print events
// useful for HDPI replacements
lo.onPrint(preFn, postFn)

lo.dom()

Creates a new dom instance, this is an array-like collection of HTML elements.

// create elements
lo.dom('<div><span>hi</span></div>')

// select via document.querySelectorAll
lo.dom('div')

// select HTML elements directly
lo.dom(el)
lo.dom([el1, el2])

dom methods are:

.each(fn)
.map(fn)
.find(selector)
.on(type, fn)
.off(type, fn)
.attr(key, value)
.rmAttr(key)
.val(value)
.html(str)
.text(str)
.clr()
.rm()
.rpl(arg)
.app(arg)
.appTo(arg)
.pre(arg)
.preTo(arg)
.cls(...names)
.hasCls(name)
.addCls(...names)
.rmCls(...names)

lo.binder()

Creates a new binder instance.

// no options here
lo.binder()

binder methods are:

.log()
.add(obj)
.set(obj)
.on(name, fn)
.collect(el)
Works best with JavaScript enabled!Works best in modern browsers!