util-array-object-or-both
Version:
Validate and normalise user choice: array, object or both?
11 lines (9 loc) • 999 B
JavaScript
/**
* @name util-array-object-or-both
* @fileoverview Validate and normalise user choice: array, object or both?
* @version 5.0.14
* @author Roy Revelt, Codsen Ltd
* @license MIT
* {@link https://codsen.com/os/util-array-object-or-both/}
*/
import{includes as r}from"lodash-es";var s="5.0.14";var d=s,p={msg:"",optsVarName:"given variable"};function y(t,o){let a=["object","objects","obj","ob","o"],n=["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(a,t.toLowerCase().trim()))return"object";if(r(n,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};