Global

Methods

argumentsToArray(args) → {Array}

Convert arguments to array.
Parameters:
Name Type Description
args arguments The arguments object.
Source:
Returns:
The array.
Type
Array

arrayChunk(array, chunkSize) → {Array}

Split an array into chunks.
Parameters:
Name Type Description
array Array The array.
chunkSize Number The chunk size.
Source:
Returns:
An array of chunks.
Type
Array

binaryInsert(value, array, comparatoropt, rejectDuplicatesopt)

Inserts a value into a sorted array using an iterative binary search to find the insertion index. 'rejectDuplicates' defines the behaviour when the value that will be inserted is already in the array.
Parameters:
Name Type Attributes Default Description
value * The value to insert.
array Array The array.
comparator function <optional>
_numericComparator An optional comparator, it will be called with two values and must return 1 if the first is greater than the second, 0 if they are equals or -1 if the second is greater than the first one.
rejectDuplicates Boolean <optional>
false Specify if duplicated values will be rejected.
Source:

binarySearch(value, array, comparatoropt, leftopt, rightopt) → {Number}

Find a value into a sorted array using an iterative binary search.
Parameters:
Name Type Attributes Default Description
value * The value to search.
array Array The array.
comparator function <optional>
_numericComparator An optional comparator, it will be called with two values and must return 1 if the first is greater than the second, 0 if they are equals or -1 if the second is greater than the first one.
left Number <optional>
0 The left index.
right Number <optional>
array.length-1 The right index.
Source:
Returns:
The index if the value was found or -1.
Type
Number

clearArray(array)

Empty the content of an array.
Parameters:
Name Type Description
array Array The array to clear.
Source:

clearObject(object)

Empty the content of an object. It uses "delete" so the object will be converted into a hash table mode (slow properties).
Parameters:
Name Type Description
object Object The plain object to clear.
Source:
See:

cloneDate(date) → {Date}

Clone a Date object.
Parameters:
Name Type Description
date Date The original Date object.
Source:
Returns:
The cloned Date.
Type
Date

cloneObject(object) → {Object|Array}

Deep copy of object or array.
Parameters:
Name Type Description
object Object | Array The object or array.
Source:
Returns:
The cloned object.
Type
Object | Array

concatArrays(dest, source)

Add all the elements in source at the end of dest.
Parameters:
Name Type Description
dest Array The destiny array.
source Array The source array.
Source:

copyArray(array, startopt, endopt) → {Array}

Shallow copy of an array.
Parameters:
Name Type Attributes Default Description
array Array The array to copy.
start Number <optional>
0 The start inclusive index.
end Number <optional>
array.length The end exclusive index.
Source:
Returns:
The copied array.
Type
Array

dateToMysql(dateopt) → {String}

Date object to mysql date string.
Parameters:
Name Type Attributes Default Description
date Date <optional>
new Date() The date object.
Source:
Returns:
The mysql string.
Type
String

dateToString(dateopt) → {String}

Date object to readable date string.
Parameters:
Name Type Attributes Default Description
date Date <optional>
new Date() The date object.
Source:
Returns:
The date string.
Type
String

endsWith(string, suffix) → {boolean}

Check if a string ends by a given suffix.
Parameters:
Name Type Description
string String The string.
suffix String The suffix.
Source:
Returns:
If the string ends by suffix of not.
Type
boolean

equals(value, other) → {Boolean}

Performs a deep comparison between two values to determine if they are equivalent. Plain objects and arrays will be recursively iterated and primitive values and references will be compared using the identity operator (===). Even though it's still a bit slower than JSON.stringify(), this method works well with unsorted objects.
Parameters:
Name Type Description
value Object | Array The first value.
other Object | Array The other value to compare against.
Source:
Returns:
If the objects are equal or not.
Type
Boolean

error(messageopt, constructoropt) → {Error}

Fast error builder, it doesn't have a real stacktrace but is x10 faster than new Error().
Parameters:
Name Type Attributes Default Description
message String <optional>
'' The error message.
constructor function <optional>
Error Optional constructor for custom errors.
Source:
Returns:
An Error instance.
Type
Error

escapeRegExp(string) → {String}

Escapes a regex expression string.
Parameters:
Name Type Description
string String The string to be escaped.
Source:
Returns:
The escaped string.
Type
String

get(object, path, defopt) → {*}

Get the value using a path in an object.
Parameters:
Name Type Attributes Description
object Object | Array The object or array.
path String | Array The path.
def * <optional>
Value to return if no value is found in path.
Source:
Returns:
The found value in path.
Type
*

getMiddleNumber(a, b, c) → {Number}

Get the middle value.
Parameters:
Name Type Description
a Number The first number.
b Number The second number.
c Number The third number.
Source:
Returns:
The middle number.
Type
Number

groupBy(data, keys, iterateeopt) → {Object}

Group an array of objects using the values of a list of keys. Usage:
  var array = [{lang:'spanish', age: 2}, {lang:'spanish', age:5}, {lang:'english', age:25}]
  ut.groupBy(array, 'lang', function(obj) { return obj.age; })
  return -> { spanish: [ 2, 5 ], english: [ 25 ] }
Parameters:
Name Type Attributes Description
data Array.<Object> An array of objects.
keys String | Array.<String> The key or keys to group by.
iteratee function <optional>
A function to modify the final grouped objects.
Source:
Returns:
The grouped object.
Type
Object

inRange(val, minopt, maxopt) → {Boolean}

Check if a value is inside of a given range.
Parameters:
Name Type Attributes Default Description
val Number | String | Array | Object The value.
min Number <optional>
-Infinity Min inclusive value.
max Number <optional>
Infinity Max inclusive value.
Source:
Returns:
If the value is inside of the given range or not.
Type
Boolean

intersectSorted(array1, array2, comparatoropt) → {Array}

Intersect two sorted arrays.
Parameters:
Name Type Attributes Default Description
array1 Array The first array.
array2 Array The second array.
comparator function <optional>
_numericComparator An optional comparator, it will be called with two values and must return 1 if the first is greater than the second, 0 if they are equals or -1 if the second is greater than the first one.
Source:
Returns:
The interected array.
Type
Array

isBoolean(value) → {Boolean}

If is a Boolean or not.
Parameters:
Name Type Description
value * The value.
Source:
Returns:
If is a Boolean or not.
Type
Boolean

isDate(value) → {Boolean}

If is a Date or not.
Parameters:
Name Type Description
value * The value.
Source:
Returns:
If is a Date or not.
Type
Boolean

isDateString(string) → {Boolean}

If is a string value representing a date. The string should be in a format recognized by the Date.parse().
Parameters:
Name Type Description
string String The string.
Source:
Returns:
If is a valid date string or not.
Type
Boolean

isFunction(value) → {Boolean}

If is Function or not.
Parameters:
Name Type Description
value * The value.
Source:
Returns:
If is a Function or not.
Type
Boolean

isHexString(string) → {Boolean}

Check whether a string represent a hexadecimal string or not.
Parameters:
Name Type Description
string String The string.
Source:
Returns:
If is a valid hexadecimal string or not.
Type
Boolean

isInteger(number) → {Boolean}

Check if a number is an integer or not.
Parameters:
Name Type Description
number Number The number to check.
Source:
Returns:
If the number is an integer.
Type
Boolean

isNaN(number) → {Boolean}

Checks if a number is NaN. Taken from link.
Parameters:
Name Type Description
number number The number to ckeck.
Source:
Returns:
If the number is NaN.
Type
Boolean

isNaNOrInfinity(number) → {Boolean}

Checks if a number is NaN, Infinity or -Infinity. Taken from link.
Parameters:
Name Type Description
number Number The number to ckeck.
Source:
Returns:
If the number is NaN, Infinity or -Infinity.
Type
Boolean

isNumber(value) → {Boolean}

If is a Number or not.
Parameters:
Name Type Description
value * The value.
Source:
Returns:
If is a Number or not.
Type
Boolean

isNumeric(value) → {Boolean}

If value has a numeric value or not. It can be a Number or a String.
Parameters:
Name Type Description
value * The value.
Source:
Returns:
If has a numeric value or not.
Type
Boolean

isObject(value) → {Boolean}

If is an Object or not.
Parameters:
Name Type Description
value * The value.
Source:
Returns:
If is an Object or not.
Type
Boolean

isPlainObject(value) → {Boolean}

If is a plain object (not an array) or not.
Parameters:
Name Type Description
value * The value.
Source:
Returns:
If is an Object and not an Array.
Type
Boolean

isRegExp(value) → {Boolean}

If is a RegExp or not.
Parameters:
Name Type Description
value * The value.
Source:
Returns:
If is a RegExp or not.
Type
Boolean

isString(value) → {Boolean}

If is a String or not.
Parameters:
Name Type Description
value * The value.
Source:
Returns:
If is a String or not.
Type
Boolean

isValidNumber(value) → {Boolean}

If is a Number or not. NaN, Infinity or -Infinity aren't considered valid numbers.
Parameters:
Name Type Description
value * The value.
Source:
Returns:
If is a Number or not.
Type
Boolean

logN(base, value) → {Number}

Calculate the log using a given base and value.
Parameters:
Name Type Description
base Number The base.
value Number The value.
Source:
Returns:
The log result.
Type
Number

mergeObjects(dest, source)

Merge the source object into dest. This function only works for object, arrays and primitive data types, references will be copied.
Parameters:
Name Type Description
dest Object | Array The destiny object or array.
source Object | Array The source object or array.
Source:

now() → {String}

Get the actual date as a readable string.
Source:
Returns:
A readable date string.
Type
String

numberToString(number) → {String}

Convert a number to string.
Parameters:
Name Type Description
number Number The number.
Source:
Returns:
The string.
Type
String

numDigits(integer, baseopt) → {Number}

Get the number of digits in a number. See link.
Parameters:
Name Type Attributes Default Description
integer Number The integer.
base Number <optional>
10 The base of the number.
Source:
Returns:
The number of digits.
Type
Number

objectChunk(object, chunkSize) → {Array.<Object>}

Divide an object into chunks by keys number.
Parameters:
Name Type Description
object Object The object.
chunkSize Number The max key number per chunk.
Source:
Returns:
An array of chunks objects.
Type
Array.<Object>

objectLength(object) → {Number}

Counts and returns the length of the given object.
Parameters:
Name Type Description
object Object The object.
Source:
Returns:
The length of the object.
Type
Number

paddingBoth(string, pad, length) → {String}

Add a left and right padding to string.
Parameters:
Name Type Description
string String The string.
pad String The pad.
length Number The length final length.
Source:
Returns:
The padded string.
Type
String

paddingLeft(string, pad, length) → {String}

Add a left padding to string.
Parameters:
Name Type Description
string String The string.
pad String The pad.
length Number The length final length.
Source:
Returns:
The padded string.
Type
String

paddingRight(string, pad, length) → {String}

Add a right padding to string.
Parameters:
Name Type Description
string String The string.
pad String The pad.
length Number The length final length.
Source:
Returns:
The padded string.
Type
String

randomArray(length, dataGeneratoropt) → {Array}

Return a random array of generated elements by dataGenerator.
Parameters:
Name Type Attributes Default Description
length Number The length.
dataGenerator function <optional>
_defaultDataGenerator The data generator.
Source:
Returns:
The array.
Type
Array

randomArrayItem(array, startopt, endopt) → {*}

Returns a random value within the provided array.
Parameters:
Name Type Attributes Default Description
array Array The array.
start Number <optional>
0 The start inclusive index.
end Number <optional>
array.length The end exclusive index.
Source:
Returns:
A random item.
Type
*

randomBoolean() → {Boolean}

Returns a random boolean.
Source:
Returns:
The random boolean.
Type
Boolean

randomNumber(min, max) → {Number}

Get a random number.
Parameters:
Name Type Description
min Number The inclusive min value.
max Number The exclusive max value.
Source:
Returns:
The random number.
Type
Number

randomObject(lengths, keyGeneratoropt, valueGeneratoropt) → {Object}

Get a random object.
Parameters:
Name Type Attributes Default Description
lengths Array.<Number> | Number Number of items per level.
keyGenerator function <optional>
_defaultKeyGenerator The key generator.
valueGenerator function <optional>
_defaultValueGenerator The value generator.
Source:
Returns:
The random object.
Type
Object

randomString(size, caseInsensitiveopt) → {String}

Return a random alphanumeric string.
Parameters:
Name Type Attributes Default Description
size Number The size
caseInsensitive Boolean <optional>
false If true, only lower case letters will be returned.
Source:
Returns:
The random string.
Type
String

repeat(string, times) → {String}

Repeat a string N times.
Parameters:
Name Type Description
string String The string to repeat.
times Number The times to repeat.
Source:
Returns:
The repeated string.
Type
String

replaceAll(string, substr, newSubstr, ignoreCaseopt) → {String}

Replace all ocurrences in string.
Parameters:
Name Type Attributes Default Description
string String The string.
substr String The substring to be replaced.
newSubstr String The String that replaces the substr param.
ignoreCase Boolean <optional>
false If ignore case or not.
Source:
Returns:
The final string.
Type
String

sort(array, comparatoropt, leftopt, rightopt)

Recursive quicksort using Hoare partitioning with random pivot and cut off to insertion sort.
Parameters:
Name Type Attributes Default Description
array Array The array to sort.
comparator function <optional>
_numericComparator An optional comparator, it will be called with two values and must return 1 if the first is greater than the second, 0 if they are equals or -1 if the second is greater than the first one.
left Number <optional>
0 The left index.
right Number <optional>
array.length-1 the right index.
Source:

spliceOne(array, index)

About 1.5x faster than the two-arg version of Array#splice(). This algorithm was taken from the core of Node.js.
Parameters:
Name Type Description
array Array The array.
index Number The element to remove.
Source:

splitPath(path) → {Array}

Splits an object path into an array of tokens.
Parameters:
Name Type Description
path String the object path.
Source:
Returns:
The path tokens.
Type
Array

startsWith(string, prefix) → {boolean}

Check if a string starts by a given prefix.
Parameters:
Name Type Description
string String The string.
prefix String The prefix.
Source:
Returns:
If the string starts by prefix of not.
Type
boolean

stringChunk(string, chunkSize) → {Array}

Split a string into chunks.
Parameters:
Name Type Description
string String The string.
chunkSize Number The chunk size.
Source:
Returns:
An array of chunks.
Type
Array

stringToNumber(string) → {Number}

Convert a string to a number.
Parameters:
Name Type Description
string String The string.
Source:
Returns:
The number.
Type
Number

swap(array, from, to)

Swap the two values in an array.
Parameters:
Name Type Description
array Array The array.
from Number From index.
to Number To index.
Source:

test(fn, timesopt, labelopt)

Execute a function N times and print the execution time.
Parameters:
Name Type Attributes Default Description
fn function The function to execute.
times Number <optional>
1 How many times to execute.
label String <optional>
'Default label' A label to be used in the log string.
Source:

toFastProperties(object) → {Object}

Converts a deoptimized object (dictionary mode) into an optimized object (fast mode). Objects are deoptimized when you use them like a hash table like deleting properties. You can check it using the native function "%HasFastProperties(object)" running nodejs with the flag "--allow-natives-syntax". This code was taken from the module "bluebird".
Parameters:
Name Type Description
object Object The object to optimize.
Source:
Returns:
Reference to the same object.
Type
Object

truncateNumber(number) → {Number}

Truncates the number. This method is as fast as "number | 0" but it's able to handle correctly numbers greater than 2^31 or lower than -2^31.
Parameters:
Name Type Description
number Number The number to be truncated.
Source:
Returns:
The truncated number.
Type
Number

updateObject(dest, value, path)

Update an object or array using a given path string.
Parameters:
Name Type Description
dest Object | Array The object or array to update.
value * The value to place in path.
path String | Array The path where to place the new value.
Source: