-
Notifications
You must be signed in to change notification settings - Fork 0
/
stringList.cjs
1 lines (1 loc) · 3.35 KB
/
stringList.cjs
1
var a=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var m=Object.getOwnPropertyNames;var c=Object.prototype.hasOwnProperty;var d=(e,t)=>{for(var r in t)a(e,r,{get:t[r],enumerable:!0})},y=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of m(t))!c.call(e,i)&&i!==r&&a(e,i,{get:()=>t[i],enumerable:!(n=h(t,i))||n.enumerable});return e};var w=e=>y(a({},"__esModule",{value:!0}),e);var b={};d(b,{default:()=>g,sl:()=>f,stringList:()=>l});module.exports=w(b);var s=(e,t)=>{if(e&&t&&Object.isFrozen(e)){/* c8 ignore next 3 @preserve */return Object.freeze(t)}return t},u=class e extends Array{infered={Union:void 0,Tuple:void 0,Mutable:void 0,Unsorted:void 0};enum;hasEmpty=!1;constructor(...t){let r=[],n=[],i=!1;for(let p of t.flat())typeof p=="string"&&(p===""&&(i=!0),r.push([p,p]),n.push(p));super(...n),this.hasEmpty=i,this.enum=Object.fromEntries(r),this.hasEmpty&&(this.enum[""]=""),Object.freeze(this.enum)}concat(...t){return s(this,new e(...super.concat.apply(this,t.flat())))}concatList(t){return this.concat(...t)}toSorted(){return s(this,new e(...super.toSorted.apply(this,arguments)))}toReversed(){return s(this,new e(...super.toReversed.apply(this,arguments)))}reverse(){return s(this,new e(...super.reverse.apply(this,arguments)))}toSpliced(){return s(this,new e(...super.toSpliced.apply(this,arguments)))}slice(){return s(this,new e(...super.slice.apply(this,arguments)))}without(){let t=Array.from(arguments).flatMap(r=>Array.isArray(r)?r.filter(n=>typeof n=="string"):typeof r=="string"?[r]:[]);return s(this,new e(...this.filter(r=>!t.includes(r))))}withTrim(){return s(this,new e(...super.map(t=>t.trim())))}withPrefix(t=""){return s(this,new e(...super.map(r=>`${t}${r}`)))}withSuffix(t=""){return s(this,new e(...super.map(r=>`${r}${t}`)))}withReplace(t,r=void 0){return s(this,new e(...super.map(n=>n.replace(t,r))))}withReplaceAll(t,r=void 0){return s(this,new e(...super.map(n=>n.replaceAll(t,r))))}toLowerCase(){return s(this,new e(...super.map(t=>t.toLowerCase())))}toUpperCase(){return s(this,new e(...super.map(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"&&(this.enum[t]||this.hasEmpty&&t===""))return t;throw new Error(`Invalid value ${t}`)}mutable(){return Array.from(this)}toRecordValue(t=void 0,...r){return Object.assign({},...r,Object.fromEntries(super.map(n=>[n,t])))}toRecordType(t="any",r=void 0,...n){return Object.assign({},...n,Object.fromEntries(super.map(i=>[i,r])))}map(){let t=this.mutable();return t.map.apply(t,arguments)}filter(){let t=this.mutable();return t.filter.apply(t,arguments)}reduce(){let t=this.mutable();return t.reduce.apply(t,arguments)}reduceRight(){let t=this.mutable();return t.reduceRight.apply(t,arguments)}flat(){let t=this.mutable();return t.flat.apply(t,arguments)}flatMap(){let t=this.mutable();return t.flatMap.apply(t,arguments)}with(){let t=this.mutable();return t.with.apply(t,arguments)}},E=Object.freeze({push:"push",unshift:"unshift",shift:"shift",copyWithin:"copyWithin",pop:"pop",fill:"fill",splice:"splice"});function o(...e){let t=e,r=e.some(n=>typeof n!="string");return e.length&&r&&(typeof window>"u",t=e.flatMap(n=>Array.isArray(n)?n.filter(i=>typeof i=="string"):typeof n=="string"?[n]:typeof n=="number"?[String(n)]:[])),new u(...t)}var l=o,f=o,g={stringList:l,sl:f};