Wiki

Clone wiki

qrvey_utils / Home

@qrvey/utils 1.0.1

Helper, Utils for all Qrvey Projects

dist/filters/adapters/transformFilters.js

transformFilters(oldFiltersObj, section)

Transform the old filters structure into the new one

Parameters
Name Type Description
oldFiltersObj Object an object with the old filters structure  
section String could be 'ANALYZE', 'PB', 'UM' or any other value. Deafult is 'ANYWHERE'  
Examples
const oldPreferenceFilters = {
  "WWXHAULtR-_-xYOQAdpqT__ENABLED": true,
  "WWXHAULtR-_-xYOQAdpqT__ALL--ENABLED": true,
  "WWXHAULtR-_-xYOQAdpqT__COLLAPSED": false,
  "WWXHAULtR-_-xYOQAdpqT__LABEL": "GLOBAL",
  "WWXHAULtR-_-xYOQAdpqT-_-AK4M8UV2": {
    "formulaId": null,
    "panelId": null,
    "values": [
      {
        "EQUALS": [
          {
            "id": "AK4M8UV2a0",
            "value": "A",
            "enabled": true,
            "imageUrl": null
          },
          {
            "id": "AK4M8UV2a1",
            "value": "B",
            "enabled": true,
            "imageUrl": null
          }
        ]
      }
    ],
    "bucketId": null,
    "text": "MC",
    "title": "MC",
    "type": "SINGLE_CHOICE",
    "qid": "AK4M8UV2",
    "dataset": {
      "sourceid": "xYOQAdpqT",
      "name": "Form All Questions",
      "qrveyid": "xYOQAdpqT",
      "text": "Form All Questions",
      "linkid": 0
    },
    "enabled": true,
    "linked": null
  }
};

const filterData = transformFilters(oldPreferenceFilters, 'ANALYZE');
Returns
  • Object an object with the new filters structure

dist/date/range/getDateRange.js

getDateRange(value, dateGroupLabel, withTime)

Get date range object from a string date value

Parameters
Name Type Description
value String string date value  
dateGroupLabel String could be 'YEAR', 'QUARTER', 'MONTH' or 'DAY'. Deafult is 'DAY'  
withTime Boolean determines if the date range will include time. Default is true  
Examples
// 1) Year:
getDateRange('2020', 'YEAR');
// Will return:
{
   from: '01/01/2020 00:00:00',
   to: '12/31/2020 23:59:59'
}

// 2) Quarter:
getDateRange('Q3 2020', 'QUARTER');
// Will return:
{
   from: '07/01/2020 00:00:00',
   to: '09/30/2020 23:59:59'
}

// 3) Month:
getDateRange('Oct 2020', 'MONTH');
// Will return:
{
   from: '10/01/2020 00:00:00',
   to: '10/31/2020 23:59:59'
}
Returns
  • Object an object with the date range with two string date properties: from and to

dist/general/array/delete.js

ArrayDelete(array, index)

Inmutable Array Item deletion

Parameters
Name Type Description
array Array List to loo for item to delte  
index Number position of item to delete  
Returns
  • new Array

dist/general/function/debounce.js

debounce(fn, time)

Delays invoking fn until after time milliseconds have elapsed since the last time the debounced function was invoked.

Parameters
Name Type Description
fn Function original Function  
time Number default 500ms  
Returns
  • Function debounced functions

dist/general/function/throttled.js

throttled(fn, time)

Make sure to only invokes fn at most once per every time milliseconds

Parameters
Name Type Description
fn Function original Function  
time Number default 500ms  
Returns
  • Function throttled function

dist/general/mix/importScripts.js

importScripts(scripts)

Import a set of external Scripts given the URL in both serie and cascade way

Parameters
Name Type Description
scripts Array.<String> Array.<Object> can be an array of string or an array of object with the follow structure:  
scripts.url String CDN URL  
scripts.namespace String Function (Optional) if is a String, that name is evaluated on Window[namespace] object otherwise the Function is invoked expecting a Thrutly value  
scripts.type String (Optional) it could be module of text/javascript. Default text/javascript  
scripts.noModule Boolean (Optional) add momodule attribute to script tag. Default false  
scripts.dependencies Array.<Object> an array with the same structure to load in cascade mode  
Examples
// 1) Simple script (paralell loading)
importScripts(['http://myscript.js', 'http://another.js']);

// 2) Loading `.js` and `.esm.js` script (parallel loading)
importScripts([
  { url: 'http://myscript.esm.js', type: 'module' },
  { url: 'http://myscript.js', noModule: true }
]);

// 3) import dependent scripts (cascade)
importScripts([
  { url: 'http://myscript.js', dependencies: ['http://myscript.plugin.js'] }
]);

// 4) mix
importScripts([
  { url: 'http://myscript.js', dependencies: ['http://myscript.plugin.js'] },
  { url: 'http://another.esm.js', type: 'module' },
  { url: 'http://another.js', noModule: true },
  'http://simplescript.js'
]);
Returns
  • Promise Promise when all script have been loaded

loadScript(url, type, noModule)

Creates the script element and appends to document.head return a Promise that is resolved when the script is loaded

Parameters
Name Type Description
url String Cdn Url  
type String (Optional) it could be module of text/javascript. Default text/javascript  
noModule boolean (Optional) add momodule attribute to script tag. Default false  
Returns
  • Void

dist/general/mix/isEmpty.js

isEmpty(obj)

return if an String, object or string is empty or not

Parameters
Name Type Description
obj Any  
Returns
  • boolean

dist/general/mix/isNull.js

isNull(arg)

return if a given variable is either null or undefined useful to avoid falsify validating Number Zero (0)

Parameters
Name Type Description
arg any  
Returns
  • Boolean

dist/general/mix/randomId.js

randomId(length)

create random unique string

Parameters
Name Type Description
length Number size of the generated string. Default 8  
Returns
  • String

dist/general/mix/size.js

size(obj)

get the length of an Array or String and also the number of first level attributes in an Object. For null or undefined argument the returned value will be 0.

Parameters
Name Type Description
obj Any  
Returns
  • Number

dist/general/object/get.js

get(obj, path, def)

Gets the value at path of obj. If the resolved value is undefined, the def is returned in its place.

Parameters
Name Type Description
obj  
path  
def  
Examples
 const object = { 'a': [{ 'b': { 'c': 3 } }] };
 get(object, 'a[0].b.c'); // => 3
 get(object, 'a.b.c', 'default'); // => 'default'
Returns
  • Void

dist/general/object/getAttribute.js

getAttribute(obj, key)

search for properties in different case styles such as: lower, upper, camel and pascal But for this, is required ask for a property in snake_case style

Parameters
Name Type Description
obj object object to look for  
key string String attribute in snake_case style  
Examples
getAttribute(obj, 'snake_case') //it search for: obj.snake_case || obj.snakeCase || obj.SnakeCase || obj.snakecase || obj.SNAKECASE
Returns
  • Void

dist/general/object/omit.js

omit(obj, props)

return a nwe Object excluding attributes in props list

Parameters
Name Type Description
obj Object base object  
props Array.<String> list of attribute to exclude  
Returns
  • Object clean object

dist/general/object/pick.js

pick(baseObject, keys)

return a new object just with attributes in keys list

Parameters
Name Type Description
baseObject Object base object  
keys Array.<String> list of attributes to preserve  
Returns
  • Object new object just with desired attributes

dist/general/string/capitalize.js

capitalize(text)

Upper case teh first letter of a given text

Parameters
Name Type Description
text String  
Returns
  • String

dist/typescript/decorators/Debounce.js

Debounce(time)

(Method Decorator) Debounce Class Method

Parameters
Name Type Description
time (optional) deafult 500  
Returns
  • Void

dist/typescript/decorators/Throttled.js

Throttled(time)

(Method Decorator) Throttled Class Method

Parameters
Name Type Description
time (optional) deafult 500  
Returns
  • Void

dist/stencil/decorators/Config.js

Config()

Stencil.js - Prop Decorator Get and Parse the Widget Configuration Object and also provide the ability to get properties in different case styles such as: lower, upper, camel and pascal But for this, is required ask for a property in snake_case style

Examples
\ @Config() @Prop() settings;

someMethod() {
 this.settings.snake_case //it search for: obj.snake_case || obj.snakeCase || obj.SnakeCase || obj.snakecase || obj.SNAKECASE
}
Returns
  • Void

dist/stencil/util/createRef.js

createRef()

lit implementation of React createRef (https://reactjs.org/docs/refs-and-the-dom.html)

Returns
  • function - Function to use in ref prop in html elements

dist/stencil/util/getConfig.js

getConfig(cfg)

verify the Config object type and try to return a parsed Object - In case cfg is a string, first try to make a JSON parse in other case try to find this string as a variable on Windows object - If cfg is a fuction, tis is invoked and parsed - Finally, if is an object, cfg is inmediatly returned

Parameters
Name Type Description
cfg  
Returns
  • Void

Documentation generated with doxdox.

Updated