-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringList.min.cjs
More file actions
1 lines (1 loc) · 7.58 KB
/
stringList.min.cjs
File metadata and controls
1 lines (1 loc) · 7.58 KB
1
var u=Object.defineProperty;var w=Object.getOwnPropertyDescriptor;var b=Object.getOwnPropertyNames;var d=Object.prototype.hasOwnProperty;var j=(s,n,t)=>n in s?u(s,n,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[n]=t;var l=(s,n)=>u(s,"name",{value:n,configurable:!0});var O=(s,n)=>{for(var t in n)u(s,t,{get:n[t],enumerable:!0})},E=(s,n,t,e)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of b(n))!d.call(s,r)&&r!==t&&u(s,r,{get:()=>n[r],enumerable:!(e=w(n,r))||e.enumerable});return s};var z=s=>E(u({},"__esModule",{value:!0}),s);var m=(s,n,t)=>j(s,typeof n!="symbol"?n+"":n,t);var v={};O(v,{default:()=>N,sl:()=>A,stringList:()=>g});module.exports=z(v);var p=l((s,n)=>{if(s&&n&&Object.isFrozen(s)){/* c8 ignore next 3 @preserve */return Object.freeze(n)}return n},"freezeIfImmutable"),c=l(s=>`Using ${s}() method on a string list will mutate the original list in place. The code relying on this list will behave unexpectedly and may lead to unsafe execution.`,"mutationWarning"),y=typeof console=="object"&&typeof console.warn=="function"&&typeof window>"u"&&typeof process=="object"&&typeof process.env=="object"&&typeof process.env.STRING_LITERAL_LIST_DEBUG<"u"&&!0&&"production"&&!1,o=class o extends Array{constructor(t){super();m(this,"enum");if(this.enum=Object.create(null),Array.isArray(t)&&t.length>0)for(let r=0;r<t.length;r+=2e3){let i=Array.prototype.slice.call(t,r,r+2e3).filter(a=>typeof a=="string"||typeof a=="number").map(a=>String(a));Array.prototype.push.apply(this,i),Object.assign(this.enum,Object.fromEntries(i.map(a=>[a,a])))}Object.defineProperty(this,"enum",{writable:!0,configurable:!1,enumerable:!1})}includes(t,e=0){return this.length===0||e>=this.length||!Object.prototype.hasOwnProperty.call(this.enum,t)?!1:e!==0&&typeof e=="number"&&(e>0||e>=this.length*-1)?Array.prototype.includes.call(this,t,e):!0}concat(...t){return p(this,new o(Array.prototype.concat.apply(this,t.flat())))}concatList(t){return p(this,new o(Array.prototype.concat.apply(this,t)))}toSorted(){return p(this,new o(Array.prototype.toSorted.apply(this,arguments)))}toReversed(){return p(this,new o(Array.prototype.toReversed.apply(this,arguments)))}toSpliced(){return p(this,new o(Array.prototype.toSpliced.apply(this,arguments)))}slice(){return p(this,new o(Array.prototype.slice.apply(Array.from(this),arguments)))}without(...t){return p(this,new o(Array.prototype.filter.call(this,e=>!t.find(r=>Array.isArray(r)?r.find(i=>e===(typeof i=="number"?String(i):i))!==void 0:e===(typeof r=="number"?String(r):r)))))}pick(...t){return t.length===0?this:p(this,new o(Array.prototype.filter.call(this,e=>t.find(r=>e===(typeof r=="number"?String(r):r)))))}withTrim(){return p(this,new o(Array.prototype.map.call(this,t=>t.trim())))}withPrefix(t=""){return p(this,new o(Array.prototype.map.call(this,e=>`${t}${e}`)))}withSuffix(t=""){return p(this,new o(Array.prototype.map.call(this,e=>`${e}${t}`)))}withReplace(t,e=void 0){return p(this,new o(Array.prototype.map.call(this,r=>r.replace(t,e))))}withReplaceAll(t,e=void 0){return p(this,new o(Array.prototype.map.call(this,r=>r.replaceAll(t,e))))}toLowerCase(){return p(this,new o(Array.prototype.map.call(this,t=>t.toLowerCase())))}toUpperCase(){return p(this,new o(Array.prototype.map.call(this,t=>t.toUpperCase())))}toCapitalize(){return this.withReplace(/\b\w/g,t=>t.toUpperCase())}toUnCapitalize(){return this.withReplace(/\b\w/g,t=>t.toLowerCase())}value(t){if(typeof t!="string"||!Object.prototype.hasOwnProperty.call(this.enum,t))throw new Error(`Invalid value ${t}`);return this.enum[t]}mutable(){return Array.prototype.slice.call(Array.from(this))}compat(){return this}happy(){return this}stringList(){return this}toRecordValue(t=void 0,...e){return Object.assign({},...e,Object.fromEntries(super.map.call(this,r=>{try{return[r,typeof t=="object"&&t!==null?Array.isArray(t)?t.slice():typeof structuredClone=="function"?structuredClone(t):Object.assign(Object.create(null),t):t]}catch(i){return[r,t]}})))}mapAsObject(t){return Object.fromEntries(Array.prototype.map.call(this,e=>[e,t(e)]))}toRecordType(t="any",e=void 0,...r){return Object.assign({},...r,Object.fromEntries(Array.prototype.map.call(this,i=>{try{return[i,typeof e=="object"&&e!==null?Array.isArray(e)?[...e]:typeof structuredClone=="function"?structuredClone(e):{...e}:e]}catch(a){return[i,e]}})))}asMap(){return new Map(Object.entries(this.enum))}asSet(){return new Set(Array.from(this))}asObject(){return Object.assign({},this.enum)}map(){return Array.prototype.map.apply(Array.from(this),arguments)}filter(){return Array.prototype.filter.apply(Array.from(this),arguments)}reduce(){return Array.prototype.reduce.apply(Array.from(this),arguments)}reduceRight(){return Array.prototype.reduceRight.apply(Array.from(this),arguments)}flat(){return Array.prototype.flat.apply(Array.from(this),arguments)}flatMap(){return Array.prototype.flatMap.apply(Array.from(this),arguments)}with(){return Array.prototype.with.apply(Array.from(this),arguments)}push(){if(y&&console.warn(c("push")),!Object.isFrozen(this))Array.prototype.push.apply(this,arguments),this.enum=Object.fromEntries(Array.prototype.map.call(this,t=>[t,t]));else throw new Error("Cannot set properties on a frozen object");return this.length}shift(){if(y&&console.warn(c("shift")),Object.isFrozen(this))throw new Error("Cannot set properties on a frozen object");{let t=Array.prototype.shift.apply(this,arguments);return this.enum=Object.fromEntries(Object.entries(this.enum).filter(([e])=>e!==t)),t}}unshift(){if(y&&console.warn(c("unshift")),!Object.isFrozen(this))Array.prototype.unshift.apply(this,arguments),this.enum=Object.assign(Object.create(null),this.enum,Object.fromEntries(Array.from(arguments).map(t=>[t,t])));else throw new Error("Cannot set properties on a frozen object");return this.length}copyWithin(){if(y&&console.warn(c("copyWithin")),!Object.isFrozen(this))Array.prototype.copyWithin.apply(this,Array.from(arguments)),this.enum=Object.fromEntries(Array.prototype.map.call(this,t=>[t,t]));else throw new Error("Cannot set properties on a frozen object");return this}pop(){if(y&&console.warn(c("pop")),Object.isFrozen(this))throw new Error("Cannot set properties on a frozen object");{let t=super.pop();return this.enum=Object.fromEntries(Array.prototype.map.call(this,e=>[e,e])),t}}fill(){if(y&&console.warn(c("fill")),!Object.isFrozen(this))Array.prototype.fill.apply(this,arguments),this.enum=Object.fromEntries(Array.prototype.map.call(this,t=>[t,t]));else throw new Error("Cannot set properties on a frozen object");return this}splice(){if(y&&console.warn(c("splice")),Object.isFrozen(this))throw new Error("Cannot set properties on a frozen object");{let t=this.mutable(),e=t.splice.apply(t,arguments);return super.splice.apply(this,arguments),this.enum=Object.fromEntries(Array.prototype.map.call(this,r=>[r,r])),e}}reverse(){if(y&&console.warn(c("reverse")),!Object.isFrozen(this))Array.prototype.reverse.apply(this,arguments);else throw new Error("Cannot set properties on a frozen object");return this}};l(o,"SL");var h=o,R=Object.freeze({push:"push",unshift:"unshift",shift:"shift",copyWithin:"copyWithin",pop:"pop",fill:"fill",splice:"splice",reverse:"reverse"});var C=typeof console=="object"&&typeof console.warn=="function"&&typeof window>"u"&&typeof process=="object"&&typeof process.env=="object"&&typeof process.env.STRING_LITERAL_LIST_DEBUG<"u"&&!0&&"production"&&!1;function f(){let s=arguments.length>0?Array.isArray(arguments[0])?arguments[0]:arguments.length?Array.from(arguments):[]:[];if(C){let n=s.some(t=>typeof t!="string");s.length&&n&&console.warn(`Unexpected type in stringList(${typeof n}). Casting all arguments to string type.`)}return new h(s)}l(f,"stringListMutable");var g=f,A=f,N={stringList:g,sl:A};