README
ku4node-kernel
kodmunkiā¢ utilities for node kernel is a node plugin for OO JavaScript development.
ku4node-kernel contains numerous useful classes including collections, math, geometry, and numerous common design patterns.
Dependencies
None
Documentation
The following is documentation for each class in the ku4node-kernel library organized by common domain to follow the directory structure found in /src. All constructors are empty unless otherwise noted.
Class
Class is a foundational class that numerous other classes inherit from offering the subclasses a common property API that includes get(), set(), and property() which is a getter/setter. It also exposes the inheritance API. To subclass JavaScript classes using the kernel Class one would first create their class and then subclass as follows:
var kernel = require("ku4node-kernel),
$class = kernel.class;
function myClass() {
myClass.base.call(this); //This line scopes the class hierarchy.
}
myClass.prototype = {
/*All prototype methods go here*/
};
$class.extend(myClass, $class); //We are creating our subclass here.
module.exports = function() { return new myClass(); } //We are exposing myClass for use here
With the above implementation. A developer can now call $myApp.myClass() from within their application to instantiate a new myClass that contains get(), set(), and property(). Also, it is important to note that many ku4* classes can be inherited using the same convention as class. For example, to inherit from $mediator, a developer would simply replace $class.extend(myClass, $class) in the example above with $class.extend(myClass, $mediator.Class)
Base
math
Convenient math operations, and some that fix some odd bugs.
API | Return | Description |
---|---|---|
round(value:Number, nearest:Number) | Number | Rounds value to the nearest, where nearest is the base 10 exponent to which to round |
roundUp(value:Number, nearest:Number) | Number | Rounds value up to the nearest, where nearest is the base 10 exponent to which to round |
roundDown(value:Number, nearest:Number) | Number | Rounds value down to the nearest, where nearest is the base 10 exponent to which to round |
roundTowardZero(value:Number, nearest:Number) | Number | Rounds value toward zero to the nearest, where nearest is the base 10 exponent to which to round |
str
Convenient string operations.
API | Return | Description |
---|---|---|
trimStart(value:String) | String | Returns a string with leading whitespace trimmed. |
trimEnd(value:String) | String | Returns a string with trailing whitespace trimmed. |
trim(value:String) | String | Returns a string with leading and trailing whitespace trimmed. |
format(value:String, ...:String) | String | Returns a string replacing the format placeholders with the following arguments. |
render(value:String, obj:object) | String | Returns a string replacing the format placeholders with the values of the key, value pairs in the following object argument. |
encodeBase64(value:String) | String | Returns a base 64 encoded string from value. |
decodeBase64(value:String) | String | Returns a string from a base 64 encoded value. |
parse(value:Number, ...:Number) | String | Returns a string from the character code arguments. |
uid
A 32 character random unique ID.
Account
emailAddress
API | Return | Description |
---|---|---|
local() | String | Returns the local portion of the email address. |
domain() | String | Returns the domain portion of the email address. |
topLevelDomain() | String | Returns the top level domain portion of the email address. |
equals(other:emailAddress) | Boolean | Returns true if the email addresses are equal. |
toString() | String | Returns a string representation of the email address. |
parse(string:String) | emailAddress | Returns an email address containing the corresponding components. |
phoneNumber
API | Return | Description |
---|---|---|
value() | Number | Returns a number value of the phone number. |
equals(other:phoneNumber) | Boolean | Returns true if the this is equal to other. |
toStringWithFormat(format:String) | String | Returns a string value replacing each instance of "#" with the subsequent number in the value. Example: $phoneNumber(2224441234).toStringWithFormat("(###) ###-####") == "(222) 444-1234" |
parse(string:String) | phoneNumber | Returns a phoneNumber with corresponding value. |
properName
API | Return | Description |
---|---|---|
first() | String | Returns the first name. |
middle() | String | Returns the middle name. |
last() | String | Returns the last name. |
full() | String | Returns the first middle and last name concatenated with space character separators. |
initials() | String | Returns the first letter of each name part capitalized and followed by a . character and a space character separator. |
equals(other_properName_) | String | Returns true if each part of this is equal to the corresponding part of other. |
toStringWithFormat(format:String) | String | Returns a string formatted with the passed format. The rules are: {F} = first name, {f} = first initial, {M} = middle name, {m} = middle initial, {L} = last name, {l} = last initial. Example $properName("John", "Jacob", "Doe").toStringWithFormat("{L} {F}, {m}.") == "Doe John, J." |
Collections
hash
API | Return | Description |
---|---|---|
count() | Number | Returns the number of items in the hash. |
keys() | Array | Returns an array of all keys. |
values() | Array | Returns an array of all values. |
add(key:String, value:Object) | this | Adds value to hash with key. |
update(key:String, value:Object) | this | Updates the value at key. |
remove(key:String) | this | Removes the key, value pair that has key. |
clear() | this | Removes all key, value pairs. |
findKey(value:Object) | String | Returns the key for value. |
findValue(key:String) | Object | Returns the value at key. |
each(func:function, scope:Object?) | this | Calls func for each item in the hash passing the object {"key": key, "value": value} on each pass. If scope is passed function will be called in the passed scope. |
quit() | this | Breaks the call. |
contains(value:hash/object) | Boolean | Returns true if the hash contains the passed value. |
containsKey(key:String) | Boolean | Returns true if the hash contains the key. |
containsValue(value:Object) | Boolean | Returns true if the hash contains the value. |
isEmpty() | Boolean | Returns true if the hash is empty. |
merge(other:hash/object) | hash | Returns a new hash contains key, value pairs are a combination of the current hash and other giving precedence to the current hash for common keys. |
meld(other:hash/object) | hash | Returns a new hash contains key, value pairs are a combination of the current hash and other giving precedence to the other hash for common keys. |
replicate() | hash | Returns a copy of the current hash. |
toObject() | object | Returns an object that contains key, value pairs equivalent to the key, value pairs of the current hash. |
list
API | Return | Description |
---|---|---|
count() | Number | Returns the number of items in the list. |
add(item:Object, value:Object) | this | Adds value to list with key. |
remove(item:Object) | this | Removes the item. |
clear() | this | Removes all items. |
find(index:Number) | String | Returns the key for value. |
each(func:function, scope:Object?) | this | Calls func for each item in the list passing the item on each pass. If scope is passed function will be called in the passed scope. |
quit() | this | Breaks the call. |
contains(item:Object) | Boolean | Returns true if the list contains the value. |
toArray() | object | Returns an array that contains items equivalent to the items of the current list. |
Datetime
dayPoint
API | Return | Description |
---|---|---|
value() | Date | Returns the Date value |
day() | Number | Returns the zero indexed day of the week |
date() | Number | Returns the date |
month() | Number | Returns the month |
year() | Number | Returns the year |
isWeekday() | Boolean | Returns true if the day is 1-5 |
isWeekend() | Boolean | Returns true if the day is 0 or 6 |
isLeapYear() | Boolean | Returns true if the year contains a 29th day in the second month |
nextDay() | dayPoint | Returns the next day |
prevDay() | dayPoint | Returns the previous day |
add(years:Number, months:Number, days:Number) | dayPoint | |
firstDayOfMonth() | dayPoint | Returns the first day of the current month |
LastDayOfMonth() | dayPoint | Returns the last day of the current month |
isBefore(other:dayPoint) | Boolean | Returns true if other is earlier than this dayPoint |
isAfter(other:dayPoint) | Boolean | Returns true if other is later than this dayPoint |
equals(other:dayPoint) | Boolean | Returns true if other is equal to than this dayPoint |
toString() | String | Returns the string value of the dayPoint |
toStringWithFormat(format:String) | String | Returns a string formatted per the passed format. Example: $dayPoint(2013, 5, 24).toStringWithFormat("mm/dd/yy") == "05/24/13" |
toDate() | Date | Returns a Date value |
toJson() | String | Returns the JSON string value |
canParse(string:String) | Boolean | Returns true if the string can be parsed into a dayPoint |
parse(string:String) | dayPoint | Returns a dayPoint with the appropriate value |
tryParse(string:String) | dayPoint | Returns a dayPoint with the appropriate value or null if the string value cannot be parsed |
today() | dayPoint | Returns a dayPoint with the value, today |
assumeNow(dayPoint:dayPoint) | void | Sets today as dayPoint. Can be very useful in testing application features that are date dependent. This feature allows the development of date dependent features without the need to manipulate system time. |
Finance
money
API | Return | Description |
---|---|---|
cents() | Number | Returns the fractional value of the money. |
dollars() | Number | Returns the whole value of the money. |
type() | String | Returns the denomination. " |