Sprout Shared React Library
This is a repository for sprout shared react library
Installation
Run npm i @wbc-sprout/shared-react
to install with npm or yarn add @wbc-sprout/shared-react
to install with yarn
Configurations
regExp
Kind: global constant
Properties
Name | Type |
---|---|
NUMBER | RegExp |
POSITIVE_NUMBER | RegExp |
POSITIVE_NUMBER_DECIMAL_POINT | RegExp |
RegExp |
|
PHONE_NUMBER | RegExp |
ALPHA_NUMERIC | RegExp |
ALPHA_NUMERIC_COMMA_DOT | RegExp |
ALPHA_NUMERIC_PLANE | RegExp |
PASSWORD | RegExp |
URL | RegExp |
Utility Functions
-
isTypeOf(varToCheck, type) ⇒
*
|boolean
-
getDistinctFrequency(array) ⇒
Object
-
isValidBase64Image(base64) ⇒
string
|*
-
Check if a string is a valid base64
-
pickFromObject(obj, acceptedKeys) ⇒
Object
|*
-
To create a new object containing a specified key from an existing object
-
discardFromObject(obj, forbiddenKeys) ⇒
Object
|*
-
To create a new object that does not contain a specified key from an existing object
-
leadingZero(num, [size]) ⇒
string
*
| boolean
isTypeOf(varToCheck, type) ⇒ Kind: global function
Returns: *
| boolean
- check - the strict type of a variable
Param | Type | Description |
---|---|---|
varToCheck | * |
variable to check its type |
type | string |
The type to check against |
Object
getDistinctFrequency(array) ⇒ Kind: global function
Returns: Object
- Frequency counter
Param | Type | Description |
---|---|---|
array |
Array | string
|
The port to normalize |
string
| *
isValidBase64Image(base64) ⇒ Check if a string is a valid base64
Kind: global function
Returns: string
| *
- If the string is base64 formatted
Param | Type | Description |
---|---|---|
base64 | string |
the base 64 string |
Object
| *
pickFromObject(obj, acceptedKeys) ⇒ To create a new object containing a specified key from an existing object
Kind: global function
Returns: Object
| *
- Newly created object
Param | Type | Description |
---|---|---|
obj | Object |
object to pick key value pair from |
acceptedKeys | Array.<string> |
the keys to pick from the object |
Object
| *
discardFromObject(obj, forbiddenKeys) ⇒ To create a new object that does not contain a specified key from an existing object
Kind: global function
Returns: Object
| *
- Newly created object
Param | Type | Description |
---|---|---|
obj | Object |
Object to create from |
forbiddenKeys | Array.<string> |
the keys that should not exist in the new object |
string
leadingZero(num, [size]) ⇒ Kind: global function
Returns: string
- Padded number
Param | Type | Default |
---|---|---|
num | number |
|
[size] | number |
2 |
Cookie
Constants
Typedefs
-
CookieInit ⇒
*
-
To initialize cookie
-
CookieGet ⇒
*
-
To get data in cookie
-
CookieGetObject ⇒
Object
-
To get object data in cookie
-
CookiePut ⇒
*
-
To put data in cookie
-
CookiePutObject ⇒
*
-
To put Object data in cookie
-
CookieRemoveAll ⇒
*
-
To remove all cookies
-
CookieRemoveAllExcept ⇒
*
-
To remove all cookies except specific ones
-
CookieRemove ⇒
*
-
To remove a cookie by its key
-
CookieGetAll ⇒
Object
-
To get all cookie
Cookie
new Cookie(method)
Returns: Object
- Cookie Instance
Param | Type |
---|---|
method | string |
appCookie
Kind: global constant
Properties
Name | Type |
---|---|
init | CookieInit |
getObject | CookieGetObject |
removeAll | CookieRemoveAll |
getAll | CookieGetAll |
removeAllExcept | CookieRemoveAllExcept |
get | CookieGet |
putObject | CookiePutObject |
put | CookiePut |
remove | CookieRemove |
appLocalStorage
Kind: global constant
Properties
Name | Type |
---|---|
init | CookieInit |
getObject | CookieGetObject |
removeAll | CookieRemoveAll |
getAll | CookieGetAll |
removeAllExcept | CookieRemoveAllExcept |
get | CookieGet |
putObject | CookiePutObject |
put | CookiePut |
remove | CookieRemove |
*
CookieInit ⇒ To initialize cookie
Kind: global typedef
Returns: *
- Null
*
CookieGet ⇒ To get data in cookie
Kind: global typedef
Returns: *
- Cookie Data
Param | Type |
---|---|
key | string |
Object
CookieGetObject ⇒ To get object data in cookie
Kind: global typedef
Returns: Object
- Cookie Data
Param | Type |
---|---|
key | string |
*
CookiePut ⇒ To put data in cookie
Kind: global typedef
Returns: *
- Null
Param | Type | Default |
---|---|---|
key | string |
|
value | string |
|
[path] | string |
"/" |
[expireIn] | number |
*
CookiePutObject ⇒ To put Object data in cookie
Kind: global typedef
Returns: *
- Null
Param | Type | Default |
---|---|---|
key | string |
|
value | string |
|
[path] | string |
"/" |
[expireIn] | number |
*
CookieRemoveAll ⇒ To remove all cookies
Kind: global typedef
Returns: *
- Null
Param | Type | Default |
---|---|---|
[path] | string |
"/" |
*
CookieRemoveAllExcept ⇒ To remove all cookies except specific ones
Kind: global typedef
Returns: *
- Null
Param | Type | Default |
---|---|---|
exceptionKeys | Array.<string> |
|
[path] | string |
"/" |
*
CookieRemove ⇒ To remove a cookie by its key
Kind: global typedef
Returns: *
- Null
Param | Type | Default |
---|---|---|
key | string |
|
[path] | string |
"/" |
Object
CookieGetAll ⇒ To get all cookie
Kind: global typedef
Returns: Object
- Cookie Data
URLs
-
replaceDynamics(route, dynamic_obj, [identifier]) ⇒
string
-
updateQueryParams(route, params, [customIdentifier]) ⇒
string
-
extractQueryParams(uri) ⇒
Object
-
hardRedirect(url) ⇒
*
-
attachAccessTokenToUrlQueryParams(url) ⇒
string
|*
-
attachPreviousQuery(url, [checkFor]) ⇒
string
|*
string
replaceDynamics(route, dynamic_obj, [identifier]) ⇒ Kind: global function
Returns: string
- the url
Param | Type | Default |
---|---|---|
route | string |
|
dynamic_obj | Object |
|
[identifier] | string |
"@" |
string
updateQueryParams(route, params, [customIdentifier]) ⇒ Kind: global function
Returns: string
- The updated url with the query params attached
Param | Type |
---|---|
route | string |
params | Object |
[customIdentifier] | string |
Object
extractQueryParams(uri) ⇒ Kind: global function
Returns: Object
- queryObject
Param | Type |
---|---|
uri | string |
*
hardRedirect(url) ⇒ Kind: global function
Returns: *
- Null
Param | Type |
---|---|
url | string |
string
| *
attachAccessTokenToUrlQueryParams(url) ⇒ Kind: global function
Returns: string
| *
- url
Param | Type |
---|---|
url | string |
string
| *
attachPreviousQuery(url, [checkFor]) ⇒ Kind: global function
Returns: string
| *
- url
Param | Type | Description |
---|---|---|
url | string |
URL |
[checkFor] | string |
Previous query to attach |
Hooks
-
useRequest(config) ⇒
Array.<{makeRequest: function(), error: *}>
-
makeRequest() ⇒
Promise.<*>
Array.<{makeRequest: function(), error: *}>
useRequest(config) ⇒ Kind: global function
Returns: Array.<{makeRequest: function(), error: *}>
- Hook data
Param | Type |
---|---|
config | Object |
config.url | string |
config.method | string |
config.body | Object |
config.onSuccess | function |
config.onError | function |
Promise.<*>
makeRequest() ⇒ Kind: global function
Returns: Promise.<*>
- The request data