Matsuo IT Common JS Utils

Small, invisible additions

This library adds only small set of functions to underscore, Array and Date type. This additions are commonly used by other libraries used outside.

Underscore additional functions

Function Description
uncapitalize(str) Returns str with first case lower.
capitalize(str) Returns str with first case upper.
isDefined(object) Returns true if passed parameter is defined.
strContains(str, it) Returns true if first parameter contains second.
endsWith(str, suffix) Returns true if first parameter ends with suffix.
filterRequestData(obj) Removes from passed object all properties that value is empty string, null or undefined. Additionally removes all properties which name start from '$' - that are angular internal properties.
paramsObject(obj) Returns object that all properties are serialized to string.
toUrlParams(obj) Transforms object to url query part.
getByPath(object, path)

Returns object that is accessed by path in first parameter object. That is:

_.getByPath({ elem: { val: "x" }}, 'elem.val')
returns "x".

setByPath(object, path, value)

Sets property in object accessed by path to value. That means after:

_.setByPath({ elem: { val: {} }}, 'elem.val.foo', "x")
invoking elem.val.foo will return "x". If any part of path is undefined, nothing will be set.

getOrCreate(object, path)

Returns object that is accessed by path in first parameter object. That is:

_.getByPath({ elem: { val: "x" }}, 'elem.val')
returns "x".

If any part of path is undefined it will be created as empty object {}. Newly created object described by last part of path will be returned.

serializeObject(dom)

Returns serialized form of dom.

Array object extensions

Function Description
Array.prototype.pushArray(arr)

Pushes all elements of arr to this array.

Array.prototype.byProp(property, id)

Returns first element that has property equal to id.

Array.prototype.remove(element)

Removes first instance of element from this array.

Array.prototype.filter(fun)

Returns new array containing all elements for which fun(element) returns true.

Date object extensions

Function Description
Date.prototype.toISOString()

Date to ISO string serialization. Added to Date type only if it does not exist.

License

This project is licensed under terms of Apache 2.0 License