Methods
(static) betterRandom(minOrMax, maxopt) → {number}
Return a random number between 0 and a max value ora between two values.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
minOrMax |
number | If this is the only passed parameter thant it will be used as "max", and the return number will be between 0 and this number. If the max parameter is passed, then this parameter will be as lower limit. | |
max |
number |
<optional> |
The higher limit for the generate number. |
Returns:
- The random number generated.
- Type
- number
(static) betterRandomInt(minOrMax, maxopt)
Return a random integer number between 0 and a max value ora between two values. If not integer numbers are passed in, the result will be anyway an integer.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
minOrMax |
number | If this is the only passed parameter thant it will be used as "max", and the return number will be between 0 and this number. If the max parameter is passed, then this parameter will be as lower limit. | |
max |
number |
<optional> |
The higher limit for the generate number. |
(static) camelToDashed(inputString) → {string}
Convert a string with camel-cased text to a dash separated words. Each uppercase character will be considered as the word starter and lower-cased.
Parameters:
| Name | Type | Description |
|---|---|---|
inputString |
string | The camelCased string. |
Returns:
- The dash-converted string.
- Type
- string
(static) dashedToCamel(inputString) → {string}
Convert a string with dash as word separator to a camel-cased text. The first letter after each dash is upper-cased and joined with previous word.
Parameters:
| Name | Type | Description |
|---|---|---|
inputString |
string | The camelCased string. |
Returns:
- The camel-cased string.
- Type
- string
(static) generateGUID(prefixopt, suffixopt)
Generate a random GUID
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
prefix |
string |
<optional> |
- |
suffix |
string |
<optional> |
- |
(static) getDeepProperty(object, path) → {boolean|object|string|array|number|null|undefined}
Get a property value from an object. The property can be a sub-property of any property of the object. If the path identificates an unexisting property, this function returns undefined.
Parameters:
| Name | Type | Description |
|---|---|---|
object |
object | The object to read from the property value. |
path |
string | The dot-separated path that identify the route to follow to get to the property to read the value. |
Returns:
- The value of the property.
- Type
- boolean | object | string | array | number | null | undefined
(static) matchProperties(targetObject, sourceObject, optionsopt)
Replicate the property from the sourceObject into targetObject, with various options.
Parameters:
| Name | Type | Attributes | Description | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
targetObject |
object | The object that the properties will be copied onto. | ||||||||||||||||
sourceObject |
object | The object that cointains properties and values to be copied. | ||||||||||||||||
options |
object |
<optional> |
An object containing the options.
Properties
|
(static) safp()
Shorthand for the
searchArrayForProperty method.
- Source:
- See:
(static) searchArrayForProperty(list, property, value, searchTypeopt) → {object|array|number|null}
Search an array for an object that has the requested property with the given value. By default if a result is found it stops the loop and returns that item.
If no object matches the requested filter this method returns null.
Since the version 2.0.6 this method uses the faster Array.prototype.find method if is available and the parameters are compatible.
If no object matches the requested filter this method returns null.
Since the version 2.0.6 this method uses the faster Array.prototype.find method if is available and the parameters are compatible.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
list |
array | The array of objects to search into. | ||
property |
string | The name of the property to search in each object of the array. If a dot separated list (eg. "childs.name") is passed, the value param is compared to the last property of the path; for example if the "property" param is "childs.name", then the value param will compared to the "name" property of the "childs" property of each element in the array. | ||
value |
object | The value that will be used to check the given property. It must have same value and same type, since a comparison of type === is made. | ||
searchType |
boolean | string |
<optional> |
"first" | This can be one of "first", "all" or "index".
For compatibilty with previous version of this method, a boolean can be passed and if the value is true the method stops and return on the first occourence and therefore return a single object (like it was "first"), if is false, the method will return an array of object that match the filter (like it was "all"). If searchType is set to "all" or false, the method will return an array even if it matches only one object. |
Returns:
- Type
- object | array | number | null
(static) setDeepProperty(object, path)
Assign a property to an object. The property can be a sub-property of any property of the object. If the path parameters indicates a sub-property of a property that does not exists, the property and the sub-property will be both created.
Parameters:
| Name | Type | Description |
|---|---|---|
object |
object | The object on whom the property will be created or assigned a value. |
path |
string | - |
(static) zeroFill(number, length) → {string}
Return a string of
length characters representing the given number with leading zeros.
Parameters:
| Name | Type | Description |
|---|---|---|
number |
number | - |
length |
number | - |
Returns:
- The string representing the passed number with leading zeros.
- Type
- string