arrayOf(Identity, ...args)
This function take an Identity as argument and filter the Array that contains all
the args.
The function create a new array containing all the arguments that have
the same prototypeOf
identity.
Params
-
Identity
-
type:
Constructor
- description: the parameters you can use to filter an array
-
type:
-
...args
-
type:
any
- description: any arguments. The function takes all and put into an array to filter.
-
type:
Examples
arrayOf(String, 20, 15, true, 'string'); // [string]
arrayOf(Number, ['string'], {20, 14}, 20); // [20]
allAre(Identity, ...args)
This function uses arrayOf()
and return true
if all the args passed have
the same prototype of Identity.
Params
-
Identity
-
type:
Constructor
- description: the parameter the function uses to filter the array of args.
-
type:
-
...args
-
type:
any
- description: The function return true only if all the new array is the same of args array
-
type:
Examples
allAre(String, 'string', 'string 2', 'string 3'); // true
allAre(String, 'string', 'string 2', 20) // false
anyIs(Identity, ...args)
This function uses arrayOf()
and return true
if at least one element of args have
the same prototype of Identity.
Params
-
Identity
-
type:
Constructor
- description: The parameter the function uses to filter the array of args.
-
type:
-
...args
-
type:
any
- description: The function return true only if the new array has length greater than zero
-
type:
Examples
anyIs(String, 20, 14, 'string'); // true
anyIs(String, 20, 14, 60, ['string']); // false
checkObjectForeignKey(matrixObject, comparisonObject)
Compare an object with a matrix object and check if in the
compared object there is a foreign or unrecognized key.
Params
-
matrixObject
-
type:
Object
- description: Matrix object to compare
-
type:
-
comparisonObject
-
type:
Object
- description: Object to be compared
-
type:
Examples
const obj = { nome: 'Marco', cognome: 'Cavanna' };
const obj2 = { nome: 'Matteo', cognome: 'Ballarini', età: 20 };
checkObjectForeignKey(obj, obj2); // età
escapedRegExp(str)
Create a new Regular Expression using regExpEscape
function.
Params
-
str
-
type:
string
-
description: the string to pass to
regExpEscape
function.
-
type:
getRandomGradient(name, direction, darkTextColor, lightTextColor)
Generate two strings, background
and color
, you can use in the stylesheet .css.
The function uses a string passed by params, and, if you want to use a text
inside the gradient, the function checks if is better to use a light text or a dark text.
Params
-
name
-
type:
string
- description: The string the function uses to generate the Gradient
-
type:
-
direction
-
type:
string
- description: The direction of the gradient
-
default:
diagonal
-
type:
-
darkTextColor
-
type:
string
- description: If the generated gradient is light the function apply a Dark Color to the text inside
-
default:
rgba(61, 66, 81, .95)
-
type:
-
lightTextColor
-
type:
string
- description: If the generated gradient is light the function apply a Light Color to the text inside
-
default:
hsl(212, 10%, 97%)
-
type:
Examples
getRandomGradient('gradientString', 'diagonal');
getRandomToken(length)
Return a Random Generated Token of 12 alphanumeric.
Params
-
length
-
type:
number
- description: value that defines the Token length
-
default:
12
-
type:
Examples
getRandomToken(20); //1n3ABC78z123qDfGH912
getScrollbarSize(recalculate)
Calculate a new size of the scrollbar, only if the user is using a Browser.
Params
-
recalculate
-
type:
boolean
-
description: if it is
true
the function recalculate the size of the scrollbar. -
default:
false
-
type:
isBrowser()
Check if the user is using a browser.
Return 'true' or 'false'.
isMobile(opts)
Check if the user is usign a mobile device.
If the device is a tablet set as true includeTablets
property.
Params
-
opts
-
type:
Object
- description: Contain all the options parameters
-
userAgent
-
type:
string
- description: the string that contain the information of user server
- default: if no user agent is passed it is picked from the Navigator
-
type:
-
type:
isObject(prop)
This function checks if the parameter passed is an Object, if it has it returns true. It controls if the prop
param is null, undefined, an array or a class, in this cases it returns false.
Params
-
prop
- description: the Object passed
isPromiseLike(obj)
Check if the param passed is a promise and if it is an object.
Return 'true' or 'false'
Params
-
obj
-
type:
any
- description: the variable passed to check if it's an object and a promise
-
type:
isTablet()
Check if the user is using a Tablet, by checking if in the isMobile()
function
the includeTablets
is true.
isTouch()
Check if the screen is a touchscreen, if it's true enable touchscreen function.
isValidString(prop)
Check if the param passed is a string of, at least, one character;
Return 'true' or 'false'.
Params
-
prop
-
type:
any
- description: passed paramater
-
type:
Examples
let str = 'string';
let num = 20;
isValidString(str); //true
isValidString(num); //false
mapObjectKeys(obj, base)
This function is called with two params: obj
, which is the object you want to map.
base
that is the key you want to start the map to. If in the object there is a key
that is an object, the function is re-launched, with the key as base
parameter.
Params
-
obj
-
type:
object
- description: the object you want to map.
-
type:
-
base
-
type:
string
- description: The key from which to start the mapping.
-
type:
regExpEscape(str)
Get a string and add an escape character next to a special char.
Params
-
str
-
type:
string
- description: the string to escape to
-
type:
Examples
regExpEscape('house.garden+2.cat'); // house\.garden\+2\.cat
shallowDiffers(prev, next)
This function check if the two objects passed by arguments differs from each other.
If the two objects are different the function return true
, otherwise return false
.
Params
-
prev
-
type:
Object
- description: The first object to be compared
-
type:
-
next
-
type:
Object
- description: The second object to be compared
-
type:
will(funcResult)
This is an asynchronous function. Get a function result (after it is invoked) and return
the result as an array of two elements: the first one is Promise error (if exists, else null).
the second one is the Promise result.
Params
-
funcResult
-
type:
Array\Promise
- description: If it is an array return Promise.all result; if it is a simple promise return result/error on promise.
-
type:
AnotherObject
This class permit to create a virtual object that contains all the
paramaters you passed.
It contains a lot of Methods that can be used to read, update and modify the Object as if it were a database.
constructor(startingObject)
The constructor function create a new Object using the parameter passed using the
logic as mapObjectKeys
function.
Params
-
startingObject
-
type:
Object
- description: The starting Object to create the new one
-
type:
set(path, value)
This Method adds a new key path and value to tehe _keys array. If the path
already exists it replaces the existance value.
Params
-
path
-
type:
string
- description: The path where the Method add the value
-
type:
-
value
-
type:
any
- description: The value the Methods will add to the path established
-
default:
null
-
type:
remove(path)
This Method removes, if it exists, a key Path from _key array
Params
-
path
-
type:
string
- description: The path the Method will removes
-
type:
get(path, options)
This Method return a value in the target Path given
Params
-
path
-
type:
string
- description: the path where the Method search the value
-
type:
-
options
-
type:
Object
-
plain
-
type:
boolean
- description:
-
default:
false
-
type:
-
type:
concat(_concatPath, obj)
This Method is a way to concat an Object or AnotherObject in a path. It places
an Object in a subpath.
Params
-
_concatPath
-
type:
string
- description: The path to use to concat Object
-
type:
-
obj
-
type:
Object
- description: Object to concat
-
type:
merge(obj)
This Method merge an Object on base Path
Params
-
obj
-
type:
Object
- description: Object to merge
-
type:
build(options)
This Method build an Object(or an Array) using the actual defined key in the _keys array
Params
-
options
-
type:
Object
- description: If no options Object is passed it takes some default options to make the build
-
default:
{ avoidError = true, _keys = this._keys } = {}
-
avoidError
-
type:
Boolean
-
description: An options to avoid the error. If it's
true
it skips the check -
default:
true
-
type:
-
_keys_
-
type:
array
- description: The keys used to build the Object taken from _keys array
-
default:
this._keys
-
type:
-
type:
mapKey({_keys})
This Method returns an Object containing all the keys and all the values
Params
-
_keys_
-
type:
array
- description: The array of keys to map
-
default:
this._keys
-
type:
diff(_object, options)
This Method returns an Object containing only the different keys and values from AnotherObject
. It compares the two Objects.
Params
-
obj
-
type:
Object
-
description: The Object to compare to
AnotherObject
-
type:
-
options
-
type:
Object
- description: Some options for comparison
-
default:
{ doubleSide = true }
-
doubleSide
-
type:
Boolean
- description: If it's true the Method will save the new Key found in the Object
-
default:
true
-
type:
-
type:
clone()
This Method return a cloned AnotherObject
filter($callback, $context)
This Method filter the AnotherObject
array, as the Filter array function.
It will actually changes the keys.
Params
-
$callback(key, index, array)
-
type:
Function
- description: The callback function invoked with the mapped parameters
-
key
-
type:
Object
- description: Object containing the key Map
-
default:
keyMap
-
type:
-
index
-
type:
Number
- description: The number representing the Index
-
default:
number
-
type:
-
array
-
type:
Array
- description: The array to map
-
default:
Array<KeyMap>
-
type:
-
type:
-
$context
-
type:
Array
- description: KeyMap Context
-
default:
this._keys
-
type:
map($callback, $context)
This Method map AnotherObject
values. This will actually change keys.
Params
-
$callback(path, value)
-
type:
Function
- description: The callback Function which is invoked with the mapped elements
-
path
-
type:
String
- description:
-
type:
-
value
-
type:
any
- description:
-
type:
-
type: