codsen-utils
Version:
Various utility functions
20 lines (18 loc) • 8.56 kB
JavaScript
/**
* @name codsen-utils
* @fileoverview Various utility functions
* @version 1.6.4
* @author Roy Revelt, Codsen Ltd
* @license MIT
* {@link https://codsen.com/os/codsen-utils/}
*/
;var codsenUtils=(()=>{var J=Object.create;var w=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var $=Object.getPrototypeOf,L=Object.prototype.hasOwnProperty;var V=(e,n)=>()=>(n||e((n={exports:{}}).exports,n),n.exports),P=(e,n)=>{for(var o in n)w(e,o,{get:n[o],enumerable:!0})},g=(e,n,o,f)=>{if(n&&typeof n=="object"||typeof n=="function")for(let i of R(n))!L.call(e,i)&&i!==o&&w(e,i,{get:()=>n[i],enumerable:!(f=B(n,i))||f.enumerable});return e};var U=(e,n,o)=>(o=e!=null?J($(e)):{},g(n||!e||!e.__esModule?w(o,"default",{value:e,enumerable:!0}):o,e)),F=e=>g(w({},"__esModule",{value:!0}),e);var S=V((Be,A)=>{"use strict";A.exports=k;function m(e){return e instanceof Buffer?Buffer.from(e):new e.constructor(e.buffer.slice(),e.byteOffset,e.length)}function k(e){if(e=e||{},e.circles)return Q(e);return e.proto?f:o;function n(i,p){for(var t=Object.keys(i),r=new Array(t.length),a=0;a<t.length;a++){var s=t[a],l=i[s];typeof l!="object"||l===null?r[s]=l:l instanceof Date?r[s]=new Date(l):ArrayBuffer.isView(l)?r[s]=m(l):r[s]=p(l)}return r}function o(i){if(typeof i!="object"||i===null)return i;if(i instanceof Date)return new Date(i);if(Array.isArray(i))return n(i,o);if(i instanceof Map)return new Map(n(Array.from(i),o));if(i instanceof Set)return new Set(n(Array.from(i),o));var p={};for(var t in i)if(Object.hasOwnProperty.call(i,t)!==!1){var r=i[t];typeof r!="object"||r===null?p[t]=r:r instanceof Date?p[t]=new Date(r):r instanceof Map?p[t]=new Map(n(Array.from(r),o)):r instanceof Set?p[t]=new Set(n(Array.from(r),o)):ArrayBuffer.isView(r)?p[t]=m(r):p[t]=o(r)}return p}function f(i){if(typeof i!="object"||i===null)return i;if(i instanceof Date)return new Date(i);if(Array.isArray(i))return n(i,f);if(i instanceof Map)return new Map(n(Array.from(i),f));if(i instanceof Set)return new Set(n(Array.from(i),f));var p={};for(var t in i){var r=i[t];typeof r!="object"||r===null?p[t]=r:r instanceof Date?p[t]=new Date(r):r instanceof Map?p[t]=new Map(n(Array.from(r),f)):r instanceof Set?p[t]=new Set(n(Array.from(r),f)):ArrayBuffer.isView(r)?p[t]=m(r):p[t]=f(r)}return p}}function Q(e){var n=[],o=[];return e.proto?p:i;function f(t,r){for(var a=Object.keys(t),s=new Array(a.length),l=0;l<a.length;l++){var y=a[l],c=t[y];if(typeof c!="object"||c===null)s[y]=c;else if(c instanceof Date)s[y]=new Date(c);else if(ArrayBuffer.isView(c))s[y]=m(c);else{var x=n.indexOf(c);x!==-1?s[y]=o[x]:s[y]=r(c)}}return s}function i(t){if(typeof t!="object"||t===null)return t;if(t instanceof Date)return new Date(t);if(Array.isArray(t))return f(t,i);if(t instanceof Map)return new Map(f(Array.from(t),i));if(t instanceof Set)return new Set(f(Array.from(t),i));var r={};n.push(t),o.push(r);for(var a in t)if(Object.hasOwnProperty.call(t,a)!==!1){var s=t[a];if(typeof s!="object"||s===null)r[a]=s;else if(s instanceof Date)r[a]=new Date(s);else if(s instanceof Map)r[a]=new Map(f(Array.from(s),i));else if(s instanceof Set)r[a]=new Set(f(Array.from(s),i));else if(ArrayBuffer.isView(s))r[a]=m(s);else{var l=n.indexOf(s);l!==-1?r[a]=o[l]:r[a]=i(s)}}return n.pop(),o.pop(),r}function p(t){if(typeof t!="object"||t===null)return t;if(t instanceof Date)return new Date(t);if(Array.isArray(t))return f(t,p);if(t instanceof Map)return new Map(f(Array.from(t),p));if(t instanceof Set)return new Set(f(Array.from(t),p));var r={};n.push(t),o.push(r);for(var a in t){var s=t[a];if(typeof s!="object"||s===null)r[a]=s;else if(s instanceof Date)r[a]=new Date(s);else if(s instanceof Map)r[a]=new Map(f(Array.from(s),p));else if(s instanceof Set)r[a]=new Set(f(Array.from(s),p));else if(ArrayBuffer.isView(s))r[a]=m(s);else{var l=n.indexOf(s);l!==-1?r[a]=o[l]:r[a]=p(s)}}return n.pop(),o.pop(),r}}});var Ee={};P(Ee,{backslash:()=>Y,backtick:()=>ne,compareFn:()=>Oe,detectEol:()=>T,doublePrime:()=>X,ellipsis:()=>Z,existy:()=>ge,findAllIdx:()=>de,hairspace:()=>_,hasOwnProp:()=>Se,includes:()=>Ce,inlineTags:()=>De,intersection:()=>Ne,isBool:()=>we,isCurrencyChar:()=>M,isCurrencySymbol:()=>ie,isInt:()=>me,isLatinLetter:()=>se,isLetter:()=>b,isLowercaseLetter:()=>ae,isNull:()=>be,isNum:()=>ye,isNumberChar:()=>oe,isPlainObject:()=>d,isQuote:()=>fe,isRegExp:()=>E,isStr:()=>u,isUppercaseLetter:()=>pe,isWhitespaceChar:()=>le,leftDoubleQuote:()=>C,leftSingleQuote:()=>j,multiplicationSign:()=>te,omit:()=>Me,pullAll:()=>xe,punctuationChars:()=>re,rawMDash:()=>q,rawNDash:()=>W,rawNbsp:()=>H,rawReplacementMark:()=>ee,removeTrailingSlash:()=>ue,resolveEolSetting:()=>Ae,rightDoubleQuote:()=>N,rightSingleQuote:()=>D,singlePrime:()=>G,stringSplice:()=>ce,thinSpace:()=>z,uniq:()=>he,version:()=>K,voidTags:()=>je});var h="1.6.4";var O=U(S(),1),v=(0,O.default)(),K=h,j="\u2018",D="\u2019",C="\u201C",N="\u201D",W="\u2013",q="\u2014",H="\xA0",Z="\u2026",_="\u200A",z="\u2009",G="\u2032",X="\u2033",Y="\\",ee="\uFFFD",ne="`",te="\xD7",re=[".",",",";","!","?"];function oe(e){return u(e)&&e.charCodeAt(0)>=48&&e.charCodeAt(0)<=57}function M(e){return u(e)&&"\u060B$\u20BC\u17DB\xA5\u20A1\u20B1\xA3\u20AC\xA2\u20B9\uFDFC\u20AA\u20A9\u20AD\u20A8\u20AE\u20A6\u20BD\u20AB\u0E3F\u20A9\u20BA\u20B4".includes(e)}function ie(e){let n=new Set(["$U","$b","B/.","BZ$","Br","Bs","C$","CHF","Ft","Gs","J$","KM","K\u010D","L","MT","NT$","P","Q","R","R$","RD$","RM","Rp","S","S/.","TT$","Z$","kn","kr","lei","z\u0142","\u0192","\u0414\u0438\u043D.","\u0434\u0435\u043D","\u043B\u0432","\u062F.\u0625","Lek"]);return u(e)&&!!e.trim()&&(M(e)||n.has(e))}function b(e){return u(e)&&e.length===1&&e.toUpperCase()!==e.toLowerCase()}function se(e){return!!(e&&u(e)&&(e.charCodeAt(0)>64&&e.charCodeAt(0)<91||e.charCodeAt(0)>96&&e.charCodeAt(0)<123))}function fe(e){return u(e)&&(e==='"'||e==="'"||e===j||e===D||e===C||e===N)}function ae(e){return!u(e)||!b(e)?!1:e===e.toLowerCase()&&e!==e.toUpperCase()}function pe(e){return!u(e)||!b(e)?!1:e===e.toUpperCase()&&e!==e.toLowerCase()}function le(e){return!u(e)||!e?!1:!e[0].trim()}var ue=e=>u(e)&&e.length&&e.endsWith("/")?e.slice(0,-1).trim():e;function d(e){if(e==null||typeof e!="object")return!1;let n=Object.getPrototypeOf(e);return n!==null&&n!==Object.prototype&&Object.getPrototypeOf(n)!==null?!1:!(Symbol.iterator in e)&&!(Symbol.toStringTag in e)}function ce(e="",n=0,o=0,f=""){return n<0&&(n+=e.length,n<0&&(n=0)),e.slice(0,n)+(f||"")+e.slice(n+o)}function u(e){return typeof e=="string"}function ye(e){return Number.isFinite(e)}function me(e){return Number.isSafeInteger(e)&&e>=0}function we(e){return typeof e=="boolean"}function be(e){return e===null}function E(e){return e instanceof RegExp}function de(e,n){if(!u(e)||!u(n))return[];let o=[],f=-1;for(;(f=e.indexOf(n,f+1))>=0;)o.push(f);return o}function xe(e=[],n=[]){return!e||!Array.isArray(e)||!e.length?[]:!n||!Array.isArray(n)||!n.length?e:e.filter(o=>!n.includes(o))}function ge(e){return e!=null}function he(e){return[...new Set(e)]}function T(e){if(!(typeof e!="string"||!e)){if(e.includes(`\r
`))return`\r
`;if(e.includes(`
`))return`
`;if(e.includes("\r"))return"\r"}}function Ae(e,n,o=`
`){if(![`\r
`,"\r",`
`].includes(o))throw new Error(`codsen-utils/resolveEolSetting(): the input argument defaultEolChar should be one of EOL values: "\\n", "\\r", or "\\r\\n", but it was given as ${JSON.stringify(o,null,0)}`);return n==="crlf"?`\r
`:n==="cr"?"\r":n==="lf"?`
`:T(e)||o}function Se(e,n){return d(e)&&u(n)&&n in e}function Oe(e,n){return e.localeCompare(n)}var je=["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"],De=new Set(["a","abbr","acronym","audio","b","bdi","bdo","big","br","button","canvas","cite","code","data","datalist","del","dfn","em","embed","i","iframe","img","input","ins","kbd","label","map","mark","meter","noscript","object","output","picture","progress","q","ruby","s","samp","script","select","slot","small","span","strong","sub","sup","svg","template","textarea","time","u","tt","var","video","wbr"]);function Ce(e,n){return!Array.isArray(e)||!e.length?!1:e.some(o=>E(o)&&n.match(o)||typeof o=="string"&&n===o)}function Ne(e=[],n=[]){return!e||!n?[]:Array.from(new Set(Array.from(e).filter(o=>new Set(n).has(o))))}function Me(e,n=[]){if(!e)return e;if(!d(e))throw new Error(`codsen-utils/omit(): [THROW_ID_01] Input must be a plain object! It was given as ${JSON.stringify(e,null,4)} (typeof is "${typeof e}")`);let o=v(e);return n.forEach(f=>{delete o[f]}),o}return F(Ee);})();