AppBuckets Main Utilities Package
npm install @appbuckets/rabbit#### Params
- Identity
- type: Constructor
- description: the parameters you can use to filter an array
- ...args
- type: any
- description: any arguments. The function takes all and put into an array to filter.
#### Examples
``javascript
arrayOf(String, 20, 15, true, 'string'); // [string]
arrayOf(Number, ['string'], {20, 14}, 20); // [20]
`
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.
- ...args
- type: any
- description: The function return true only if all the new array is the same of args array#### Examples
`javascript
allAre(String, 'string', 'string 2', 'string 3'); // trueallAre(String, 'string', 'string 2', 20) // false
`$3
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.
- ...args
- type: any
- description: The function return true only if the new array has length greater than zero#### Examples
`javascript
anyIs(String, 20, 14, 'string'); // trueanyIs(String, 20, 14, 60, ['string']); // false
`
$3
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
- comparisonObject
- type: Object
- description: Object to be compared
#### Examples
`javascript
const obj = { nome: 'Marco', cognome: 'Cavanna' };
const obj2 = { nome: 'Matteo', cognome: 'Ballarini', età: 20 };
checkObjectForeignKey(obj, obj2); // età
`$3
Create a new Regular Expression using regExpEscape function.#### Params
-
str
- type: string
- description: the string to pass to regExpEscape function.$3
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
- direction
- type: string
- description: The direction of the gradient
- default: diagonal
- 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)
- 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%)#### Examples
`javascript
getRandomGradient('gradientString', 'diagonal');
`$3
Return a Random Generated Token of 12 alphanumeric.#### Params
-
length
- type: number
- description: value that defines the Token length
- default: 12
#### Examples
`javascript
getRandomToken(20); //1n3ABC78z123qDfGH912
`$3
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
$3
Check if the user is using a browser.
Return 'true' or 'false'.$3
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$3
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$3
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$3
Check if the user is using a Tablet, by checking if in the isMobile() function
the includeTablets is true.$3
Check if the screen is a touchscreen, if it's true enable touchscreen function.$3
Check if the param passed is a string of, at least, one character;
Return 'true' or 'false'.
#### Params
- prop
- type: any
- description: passed paramater#### Examples
`javascript
let str = 'string';
let num = 20; isValidString(str); //true
isValidString(num); //false
`$3
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.
- base
- type: string
- description: The key from which to start the mapping.$3
Get a string and add an escape character next to a special char.#### Params
-
str
- type: string
- description: the string to escape to
#### Examples
`javascript
regExpEscape('house.garden+2.cat'); // house\.garden\+2\.cat
`$3
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
- next
- type: Object
- description: The second object to be compared$3
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.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. $3
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
___
$3
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
- value
- type: any
- description: The value the Methods will add to the path established
- default: null
___
$3
This Method removes, if it exists, a key Path from _key array#### Params
-
path
- type: string
- description: The path the Method will removes
___
$3
This Method return a value in the target Path given#### Params
-
path
- type: string
- description: the path where the Method search the value
- options
- type: Object
- plain
- type: boolean
- description:
- default: false
___
$3
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
- obj
- type: Object
- description: Object to concat
___
$3
This Method merge an Object on base Path#### Params
-
obj
- type: Object
- description: Object to merge
___
$3
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
- _keys_
- type: array
- description: The keys used to build the Object taken from _keys array
- default: this._keys
___
$3
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
___
$3
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
- 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
___
$3
This Method return a cloned AnotherObject
___
$3
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
- index
- type: Number
- description: The number representing the Index
- default: number
- array
- type: Array
- description: The array to map
- default: Array
- $context
- type: Array
- description: KeyMap Context
- default: this._keys
___
$3
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:
- value
- type: any`