-
Notifications
You must be signed in to change notification settings - Fork 0
/
stringList.cjs
1 lines (1 loc) · 9.44 KB
/
stringList.cjs
1
"use strict";var g=Object.defineProperty;var s=(r,e)=>g(r,"name",{value:e,configurable:!0});var l=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var h=l(a=>{"use strict";Object.defineProperty(a,"__esModule",{value:!0});function b(r,e){for(var t in e)Object.defineProperty(r,t,{enumerable:!0,get:e[t]})}s(b,"_export");b(a,{ARRAY_IN_PLACE_MUTATION:s(function(){return _},"ARRAY_IN_PLACE_MUTATION"),SL:s(function(){return p},"SL")});var o=s((r,e)=>{if(r&&e&&Object.isFrozen(r)){/* c8 ignore next 3 @preserve */return Object.freeze(e)}return e},"freezeIfImmutable"),u=s(()=>typeof console=="object"&&console&&typeof console.warn=="function"&&(typeof window>"u"&&typeof process=="object"&&process&&typeof process.env=="object"&&process.env&&!0&&"production"&&!1||typeof window=="object"&&window&&"__NEXT_DATA__"in window&&typeof window.__NEXT_DATA__=="object"&&window.__NEXT_DATA__&&"runtimeConfig"in window.__NEXT_DATA__&&typeof window.__NEXT_DATA__.runtimeConfig=="object"&&window.__NEXT_DATA__.runtimeConfig&&"environment"in window.__NEXT_DATA__.runtimeConfig&&typeof window.__NEXT_DATA__.runtimeConfig.environment=="string"&&window.__NEXT_DATA__.runtimeConfig.environment!=="prod"),"shouldWarn"),p=class r extends Array{static{s(this,"SL")}enum;constructor(...e){let t=[],n=[];for(let i of e.flat())typeof i=="string"&&(t.push([i,i]),n.push(i));super(...n),this.enum=Object.fromEntries(t),Object.freeze(this.enum),Object.defineProperty(this,"enum",{writable:!0,configurable:!1,enumerable:!1})}includes(e,t=0){return this.length===0?!1:t!==0&&typeof t=="number"&&(t>0||t>=this.length*-1)?super.includes(e,t):typeof this.enum[e]=="string"}concat(...e){return o(this,new r(...super.concat.apply(this,e.flat())))}concatList(e){return this.concat(...e)}toSorted(){return o(this,new r(...super.toSorted.apply(this,arguments)))}toReversed(){return o(this,new r(...super.toReversed.apply(this,arguments)))}toSpliced(){return o(this,new r(...super.toSpliced.apply(this,arguments)))}slice(){return o(this,new r(...super.slice.apply(this,arguments)))}without(...e){let t=e.flat().map(n=>typeof n=="string"?n:typeof n=="number"?String(n):void 0);return o(this,new r(...this.filter(n=>!t.includes(n))))}withTrim(){return o(this,new r(...super.map(e=>e.trim())))}withPrefix(e=""){return o(this,new r(...super.map(t=>`${e}${t}`)))}withSuffix(e=""){return o(this,new r(...super.map(t=>`${t}${e}`)))}withReplace(e,t=void 0){return o(this,new r(...super.map(n=>n.replace(e,t))))}withReplaceAll(e,t=void 0){return o(this,new r(...super.map(n=>n.replaceAll(e,t))))}toLowerCase(){return o(this,new r(...super.map(e=>e.toLowerCase())))}toUpperCase(){return o(this,new r(...super.map(e=>e.toUpperCase())))}toCapitalize(){return this.withReplace(/\b\w/g,e=>e.toUpperCase())}toUnCapitalize(){return this.withReplace(/\b\w/g,e=>e.toLowerCase())}value(e){if(typeof e!="string")throw new Error(`Invalid value ${e}`);if(this.enum[e]===e)return this.enum[e];throw new Error(`Invalid value ${e}`)}mutable(){return Array.from(this)}toRecordValue(e=void 0,...t){return Object.assign({},...t,Object.fromEntries(super.map(n=>{try{return[n,typeof e=="object"&&e!==null?Array.isArray(e)?[...e]:typeof structuredClone=="function"?structuredClone(e):{...e}:e]}catch{return[n,e]}})))}mapAsObject(e){return Object.fromEntries(super.map(t=>[t,e(t)]))}toRecordType(e="any",t=void 0,...n){return Object.assign({},...n,Object.fromEntries(super.map(i=>{try{return[i,typeof t=="object"&&t!==null?Array.isArray(t)?[...t]:typeof structuredClone=="function"?structuredClone(t):{...t}:t]}catch{return[i,t]}})))}asMap(){return new Map(super.map(e=>[e,e]))}asSet(){return new Set(this)}asObject(){return Object.assign({},...super.map(e=>({[e]:e})))}map(){let e=this.mutable();return e.map.apply(e,arguments)}filter(){let e=this.mutable();return e.filter.apply(e,arguments)}reduce(){let e=this.mutable();return e.reduce.apply(e,arguments)}reduceRight(){let e=this.mutable();return e.reduceRight.apply(e,arguments)}flat(){let e=this.mutable();return e.flat.apply(e,arguments)}flatMap(){let e=this.mutable();return e.flatMap.apply(e,arguments)}with(){let e=this.mutable();return e.with.apply(e,arguments)}push(){if(u()&&console.warn("Using push() 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."),Object.isFrozen(this))throw new Error("Cannot set properties on a frozen object");{let e=this.mutable();e.push.apply(e,arguments),super.push.apply(this,arguments),this.enum=Object.fromEntries(this.map(t=>[t,t])),Object.freeze(this.enum)}return this.length}shift(){if(u()&&console.warn("Using shift() 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."),Object.isFrozen(this))throw new Error("Cannot set properties on a frozen object");{let e=this.mutable(),t=e.shift.apply(e,arguments);return super.shift.apply(this,arguments),this.enum=Object.fromEntries(this.map(n=>[n,n])),Object.freeze(this.enum),t}}unshift(){if(u()&&console.warn("Using unshift() 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."),Object.isFrozen(this))throw new Error("Cannot set properties on a frozen object");{let e=this.mutable();e.unshift.apply(e,arguments),super.unshift.apply(this,arguments),this.enum=Object.fromEntries(this.map(t=>[t,t])),Object.freeze(this.enum)}return this.length}copyWithin(){if(u()&&console.warn("Using copyWithin() 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."),Object.isFrozen(this))throw new Error("Cannot set properties on a frozen object");{let e=this.mutable();e.copyWithin.apply(e,arguments),super.copyWithin.apply(this,arguments),this.enum=Object.fromEntries(this.map(t=>[t,t])),Object.freeze(this.enum)}return this}pop(){if(u()&&console.warn("Using pop() 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."),Object.isFrozen(this))throw new Error("Cannot set properties on a frozen object");{let e=this.mutable(),t=e.pop.apply(e,arguments);return super.pop.apply(this,arguments),this.enum=Object.fromEntries(this.map(n=>[n,n])),Object.freeze(this.enum),t}}fill(){if(u()&&console.warn("Using fill() 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."),Object.isFrozen(this))throw new Error("Cannot set properties on a frozen object");{let e=this.mutable();e.fill.apply(e,arguments),super.fill.apply(this,arguments),this.enum=Object.fromEntries(this.map(t=>[t,t])),Object.freeze(this.enum)}return this}splice(){if(u()&&console.warn("Using splice() 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."),Object.isFrozen(this))throw new Error("Cannot set properties on a frozen object");{let e=this.mutable(),t=e.splice.apply(e,arguments);return super.splice.apply(this,arguments),this.enum=Object.fromEntries(this.map(n=>[n,n])),Object.freeze(this.enum),t}}reverse(){if(u()&&console.warn("Using reverse() 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."),Object.isFrozen(this))throw new Error("Cannot set properties on a frozen object");{let e=this.mutable();e.reverse.apply(e,arguments),super.reverse.apply(this,arguments),this.enum=Object.fromEntries(this.map(t=>[t,t])),Object.freeze(this.enum)}return this}},_=Object.freeze({push:"push",unshift:"unshift",shift:"shift",copyWithin:"copyWithin",pop:"pop",fill:"fill",splice:"splice",reverse:"reverse"})});var m=l(c=>{"use strict";Object.defineProperty(c,"__esModule",{value:!0});function j(r,e){for(var t in e)Object.defineProperty(r,t,{enumerable:!0,get:e[t]})}s(j,"_export");j(c,{stringListMutable:s(function(){return f},"stringListMutable"),stringListReadonly:s(function(){return A},"stringListReadonly")});var E=h();function f(...r){let e=r,t=r.some(n=>typeof n!="string");return r.length&&t&&(typeof console=="object"&&console&&typeof console.warn=="function"&&(typeof window>"u"&&typeof process=="object"&&process&&typeof process.env=="object"&&process.env&&!1||typeof window=="object"&&window&&"__NEXT_DATA__"in window&&typeof window.__NEXT_DATA__=="object"&&window.__NEXT_DATA__&&"runtimeConfig"in window.__NEXT_DATA__&&typeof window.__NEXT_DATA__.runtimeConfig=="object"&&window.__NEXT_DATA__.runtimeConfig&&"environment"in window.__NEXT_DATA__.runtimeConfig&&typeof window.__NEXT_DATA__.runtimeConfig.environment=="string"&&window.__NEXT_DATA__.runtimeConfig.environment!=="prod")&&console.warn(`Unexpected type in stringList(${typeof t}). Casting all arguments to string type.`),e=r.flatMap(n=>Array.isArray(n)?n.filter(i=>typeof i=="string"||typeof i=="number").map(i=>String(i)):typeof n=="string"?[n]:typeof n=="number"?[String(n)]:[])),new E.SL(...e)}s(f,"stringListMutable");function A(...r){return Object.freeze(f(...r))}s(A,"stringListReadonly")});Object.defineProperty(exports,"__esModule",{value:!0});function O(r,e){for(var t in e)Object.defineProperty(r,t,{enumerable:!0,get:e[t]})}s(O,"_export");O(exports,{default:s(function(){return T},"default"),sl:s(function(){return y},"sl"),stringList:s(function(){return d},"stringList")});var w=m(),d=w.stringListMutable,y=w.stringListMutable,T={stringList:d,sl:y};