-
Notifications
You must be signed in to change notification settings - Fork 24
helpers
Usage: $l.each(obj, function(key, value)[, testOwnProperties])
Alternative: $l.aeach for objects with 'length' property
$l.each(
{a: 1, b: 2},
function(i, item) { console.log(i + ' -> ' + item); }
);
prints
a -> 1
b -> 2
Usage: $l.map(obj, function(value, key)[, dontSkipReturns, testOwnProperties])
Alternative: $l.amap for objects with 'length' property
$l.map(
{a: 1, b: 2, c: 3},
function(item, i) { if (item >= 2) { return i; } }
);
returns ["b", "c"]
Usage: $l.index(obj, value[, testOwnProperties])
Alternative: $l.aindex for objects with 'length' property
$l.index(
{a: 1, b: 2, c: 3},
2
);
returns "b"
Usage: $l.extend(obj1, obj2)
// prints '{id: 1, name: 'eser', count: 5}'
console.log($l.extend({id: 1}, {name: 'eser', count: 5}));
Usage: $l.extendNs(obj1, namespace, obj2)
// prints '{id: 1, name: 'eser', count: 5}'
$l.extendNs($l, 'plugins.test', {id: 1, name: 'eser', count: 5})
console.log($l.plugins.test);
Usage: $l.getUniqueId()
console.log($l.getUniqueId()); // prints 'uid-1'
console.log($l.getUniqueId()); // prints 'uid-2'
Usage: $l.buildQueryString(values[, rfc3986])
var element = $l('#form');
var serialized = $l.form.serialize(element);
// prints name=eser&surname=ozvataf&title=software%20designer
console.log($l.buildQueryString(serialized));
Usage: $l.buildFormData(values)
var element = $l('#form');
var serialized = $l.form.serialize(element);
serialized.remember = '1';
// prints FormData object
console.log($l.buildFormData(serialized));
Usage: $l.format(format, arguments...)
var username = 'eser';
// prints 'name: eser'
console.log($l.format('name: %s', username));
Usage: $l.replaceAll(text, dictionary)
var dict = {'e': 'ii', 'a': 'o'};
// prints 'loroux.js hiilpiirs'
console.log($l.replaceAll('laroux.js helpers', dict));
Usage: $l.camelCase(value)
// prints 'textAlign'
console.log($l.camelCase('text-align'));
Usage: $l.antiCamelCase(value)
// prints 'text-align'
console.log($l.antiCamelCase('textAlign'));
Usage: $l.quoteAttr(value)
// prints '<br clear="all" />'
console.log($l.quoteAttr('<br clear="all" />'));
Usage: $l.random(min, max)
// prints a random number between 1 and 5
console.log($l.random(1, 5));
Usage: $l.column(obj, key)
var arr = [{id: 1, count: 5}, {id: 2, count: 12}];
// prints '[5, 12]'
console.log($l.column(arr, 'count'));
Usage: $l.shuffle(obj)
var arr = [1, 2, 3, 4, 5];
// prints '[3, 1, 2, 5, 4]'
console.log($l.shuffle(arr));
Usage: $l.duplicate(obj)
// prints '[5]'
console.log($l.duplicate([5]));
Usage: $l.getLength(obj)
// prints '3'
console.log($l.getLength({id: 1, name: 'eser', count: 5}));
Usage: $l.getElement(obj, key[, defaultValue, delimiter])
// prints '1'
console.log($l.getElement({id: 1, child: { a: 1 }}, 'child.a'));
Usage: $l.getKeysRecursive(obj[, delimiter, prefix, keys])
// prints '["id", "child", "child.a", "child.b"]'
console.log($l.getKeysRecursive({id: 1, child: { a: 1, b: 2 }}));
Please don't hesitate to submit issues and pull requests.