@ddunigma/node
Version:
1 lines • 2.73 kB
JavaScript
'use strict';var chunkBCUBYE76_cjs=require('./chunk-BCUBYE76.cjs');var h=class s{static{chunkBCUBYE76_cjs.a(this,"CharsetBuilder");}chars=[];constructor(){}static create(){return new s}static fromUnicodeRange(r,e){return new s().addUnicodeRange(r,e)}static fromString(r){return new s().addString(r)}static base64(){return new s().addString("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")}static base32(){return new s().addString("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567")}static uppercase(){return s.fromUnicodeRange(65,90)}static lowercase(){return s.fromUnicodeRange(97,122)}static digits(){return s.fromUnicodeRange(48,57)}static hangulJamo(){return new s().addUnicodeRange(4352,4370).addUnicodeRange(4449,4469).addUnicodeRange(4520,4546)}addUnicodeRange(r,e){if(!Number.isInteger(r)||!Number.isInteger(e)||r<0||e>1114111||r>e)throw new RangeError("Unicode range must use integer code points with 0 <= start <= end <= 0x10FFFF");for(let t=r;t<=e;t++)this.chars.push(String.fromCodePoint(t));return this}addString(r){return typeof r=="string"?this.chars.push(...r):this.chars.push(...r),this}add(...r){return this.chars.push(...r),this}excludeConfusing(){let r=new Set(["0","O","o","1","l","I","i","|","L"]);return this.chars=this.chars.filter(e=>!r.has(e)),this}exclude(...r){let e=new Set(r);return this.chars=this.chars.filter(t=>!e.has(t)),this}excludeUrlUnsafe(){let r=new Set(["+","/","=","?","&","#","%"," "]);return this.chars=this.chars.filter(e=>!r.has(e)),this}unique(){return this.chars=[...new Set(this.chars)],this}shuffle(r){let e=r!==void 0?this.seededRandom(r):Math.random;for(let t=this.chars.length-1;t>0;t--){let i=Math.floor(e()*(t+1));[this.chars[t],this.chars[i]]=[this.chars[i],this.chars[t]];}return this}seededRandom(r){let e=r|0||1;return ()=>(e^=e<<13,e^=e>>17,e^=e<<5,(e>>>0)/4294967296)}limit(r){if(!Number.isSafeInteger(r)||r<0)throw new RangeError("Charset limit must be a non-negative safe integer");return this.chars=this.chars.slice(0,r),this}limitToPowerOfTwo(){let r=this.chars.length;if(r===0)return this;let e=1<<Math.floor(Math.log2(r));return this.chars=this.chars.slice(0,e),this}sort(){return this.chars.sort(),this}reverse(){return this.chars.reverse(),this}get length(){return this.chars.length}buildString(){return this.chars.join("")}build(){return [...this.chars]}buildWithPadding(r){let e=[...this.chars],t=r;if(!t){let i=["=",".","_","-","~","!"];for(let n of i)if(!e.includes(n)){t=n;break}if(!t)throw new Error("Cannot find suitable padding character")}if(t.length!==1)throw new Error("Padding character must be one UTF-16 code unit");if(e.includes(t))throw new Error("Padding character must not appear in charset");return {charset:e,padding:t}}};exports.a=h;