UNPKG

util-array-object-or-both

Version:

Validate and normalise user choice: array, object or both?

11 lines (9 loc) 985 B
/** * @name util-array-object-or-both * @fileoverview Validate and normalise user choice: array, object or both? * @version 5.1.3 * @author Roy Revelt * @license MIT * {@link https://codsen.com/os/util-array-object-or-both/} */ import{includes as r}from"lodash-es";var s="5.1.3";var d=s,p={msg:"",optsVarName:"given variable"};function y(t,o){let n=["object","objects","obj","ob","o"],a=["array","arrays","arr","aray","arr","a"],i=["any","all","everything","both","either","each","whatever","whatevs","e"],e={...p,...o};if(e?.msg?.length&&(e.msg=`${e.msg.trim()} `),e.optsVarName!=="given variable"&&(e.optsVarName=`variable "${e.optsVarName}"`),r(n,t.toLowerCase().trim()))return"object";if(r(a,t.toLowerCase().trim()))return"array";if(r(i,t.toLowerCase().trim()))return"any";throw new TypeError(`${e.msg}The ${e.optsVarName} was customised to an unrecognised value: ${t}. Please check it against the API documentation.`)}export{y as arrObjOrBoth,p as defaults,d as version};