UNPKG

@analytics/type-utils

Version:
3 lines (2 loc) 5.94 kB
var t="function",e="string",r="undefined",n="boolean",o="object",s="array",i="number",u="symbol",p="null",c="asyncFunction",a="generatorFunction",f=function(){},x="none",l="hidden",d="form",y="input",N="button",E="select",g=/^\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z)$/,m=/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/,O=/^\{[\s\S]*\}$|^\[[\s\S]*\]$/,b=typeof process!==r?process:{},A=b.env&&b.env.NODE_ENV||"",S="production"===A,v="staging"===A,T="development"===A,R=typeof document!==r,D=R&&"localhost"===window.location.hostname,h=null!=b.versions&&null!=b.versions.node,F=typeof Deno!==r&&typeof Deno.core!==r,L=typeof self===o&&self.constructor&&"DedicatedWorkerGlobalScope"===self.constructor.name,C=R&&"nodejs"===window.name||typeof navigator!==r&&typeof navigator.userAgent!==r&&(navigator.userAgent.includes("Node.js")||navigator.userAgent.includes("jsdom"));function I(t,e){return e.charAt(0)[t]()+e.slice(1)}var j=I.bind(null,"toUpperCase"),P=I.bind(null,"toLowerCase");function U(t){return k(t)?j(p):typeof t===o?$(t):Object.prototype.toString.call(t).slice(8,-1)}function _(t,e){void 0===e&&(e=!0);var r=U(t);return e?P(r):r}function B(t,e){return typeof e===t}var G=B.bind(null,t),w=B.bind(null,e),M=B.bind(null,r),z=B.bind(null,n),Z=B.bind(null,u);function k(t){return null===t}function Y(t){return _(t)===i&&!isNaN(t)}function H(t){return _(t)===s}function J(t){if(!X(t))return!1;for(var e=t;null!==Object.getPrototypeOf(e);)e=Object.getPrototypeOf(e);return Object.getPrototypeOf(t)===e}function X(t){return t&&(typeof t===o||null!==t)}function $(t){return G(t.constructor)?t.constructor.name:null}function W(t){return t instanceof Set}function V(t){return t instanceof Map}function q(t){return t instanceof Error||w(t.message)&&t.constructor&&Y(t.constructor.stackTraceLimit)}function K(t,e){if("object"!=typeof e||k(e))return!1;if(e instanceof t)return!0;var r=_(new t(""));if(q(e))for(;e;){if(_(e)===r)return!0;e=Object.getPrototypeOf(e)}return!1}var Q=K.bind(null,TypeError),tt=K.bind(null,SyntaxError);function et(t,e){var r=t instanceof Element||t instanceof HTMLDocument;return r&&e?rt(t,e):r}function rt(t,e){return void 0===e&&(e=""),t&&t.nodeName===e.toUpperCase()}function nt(t){var e=[].slice.call(arguments,1);return function(){return t.apply(void 0,[].slice.call(arguments).concat(e))}}var ot=nt(et,d),st=nt(et,N),it=nt(et,y),ut=nt(et,E);exports.ALL="*",exports.ANY="any",exports.ARRAY=s,exports.ASYNC_FUNCTION=c,exports.ASYNC_GENERATOR_FUNCTION="asyncGeneratorFunction",exports.BOOLEAN=n,exports.BUTTON=N,exports.CHANGE="change",exports.ENV=A,exports.ERROR="error",exports.FORM=d,exports.FUNCTION=t,exports.GENERATOR_FUNCTION=a,exports.HIDDEN=l,exports.INPUT=y,exports.NONE=x,exports.NULL=p,exports.NUMBER=i,exports.OBJECT=o,exports.PREFIX="__",exports.REGEX_EMAIL=m,exports.REGEX_ISO=g,exports.REGEX_JSON=O,exports.SELECT=E,exports.STRING=e,exports.SUBMIT="submit",exports.SYMBOL=u,exports.SYNTAX_ERROR="syntaxError",exports.TYPE_ERROR="typeError",exports.UNDEFINED=r,exports.ctorName=$,exports.ensureArray=function(t){return t?H(t)?t:[t]:[]},exports.getType=_,exports.getTypeName=U,exports.isArguments=function(t){try{if(Y(t.length)&&G(t.callee))return!0}catch(t){if(-1!==t.message.indexOf("callee"))return!0}return!1},exports.isArray=H,exports.isAsyncFunction=function(t){return _(t)===c},exports.isBoolean=z,exports.isBrowser=R,exports.isBuffer=function(t){return!(!t.constructor||!G(t.constructor.isBuffer))&&t.constructor.isBuffer(t)},exports.isButton=st,exports.isClass=function(t){return!!G(t)&&/^class /.test(Function.prototype.toString.call(t))},exports.isDate=function(t){return t instanceof Date||G(t.toDateString)&&G(t.getDate)&&G(t.setDate)},exports.isDefined=function(t){return!M(t)},exports.isDeno=F,exports.isDev=T,exports.isElement=et,exports.isEmail=function(t){return!(t.length>320)&&m.test(t)},exports.isEmpty=function(t){return!(!k(t)&&(H(t)?t.length:W(t)||V(t)?t.size:J(t)&&Object.keys(t).length))},exports.isError=q,exports.isErrorLike=function(t){return X(t)&&w(t.message)&&w(t.name)},exports.isFalse=function(t){return!1===t},exports.isFalsy=function(t){return!t},exports.isForm=ot,exports.isFunction=G,exports.isGenerator=function(t){return X(t)&&G(t.throw)&&G(t.return)&&G(t.next)},exports.isGeneratorFunction=function(t){return _(t)===a},exports.isHidden=function(t,e){if(!t||getComputedStyle(t).visibility===l)return!0;for(;t;){if(null!=e&&t===e)return!1;if(getComputedStyle(t).display===x)return!0;t=t.parentElement}return!1},exports.isInput=it,exports.isIsoDate=function(t){return g.test(t)},exports.isJsDom=C,exports.isJson=function(t){if(!w(t)||!O.test(t))return!1;try{JSON.parse(t)}catch(t){return!1}return!0},exports.isLocalHost=D,exports.isMap=V,exports.isMethod=function(t,e){return J(t)&&G(t[e])},exports.isNoOp=function(t){if(!G(t))return!1;var e=/{(\r|\n|\s)*}/gm,r=f+"";return r===(t.toString().match(e)||[""])[0].replace(e,r)},exports.isNode=h,exports.isNodeList=function(t){return NodeList.prototype.isPrototypeOf(t)},exports.isNodeType=rt,exports.isNull=k,exports.isNumber=Y,exports.isNumberLike=function(t){return!isNaN(parseFloat(t))},exports.isObject=J,exports.isObjectLike=X,exports.isPrimitive=function(t){if(k(t))return!0;switch(typeof t){case e:case i:case u:case r:case n:return!0;default:return!1}},exports.isProd=S,exports.isPromise=function(t){return!!t&&!!(!M(Promise)&&t instanceof Promise||t.then&&G(t.then))},exports.isRegex=function(t){return t instanceof RegExp},exports.isSelect=ut,exports.isSet=W,exports.isStaging=v,exports.isString=w,exports.isSymbol=Z,exports.isSyntaxError=tt,exports.isTrue=function(t){return!0===t},exports.isTruthy=function(t){return!(w(t)&&"false"===t.toLowerCase()||!t)},exports.isTypeError=Q,exports.isUndefined=M,exports.isWebWorker=L,exports.noOp=f; //# sourceMappingURL=analytics-util-types.cjs.map