@ddunigma/node 2.1.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +178 -229
- package/dist/DduStream-NP3CMCKK.js +2 -0
- package/dist/chunk-FVBZKVPE.js +4 -0
- package/dist/index.cjs +7 -0
- package/dist/index.d.cts +784 -0
- package/dist/index.d.ts +784 -0
- package/dist/index.js +5 -0
- package/package.json +39 -16
- package/dist/cjs/base/BaseDdu.d.ts +0 -53
- package/dist/cjs/base/BaseDdu.js +0 -29
- package/dist/cjs/base/index.d.ts +0 -1
- package/dist/cjs/base/index.js +0 -5
- package/dist/cjs/charSets/index.d.ts +0 -18
- package/dist/cjs/charSets/index.js +0 -4385
- package/dist/cjs/encoders/Ddu64.d.ts +0 -302
- package/dist/cjs/encoders/Ddu64.js +0 -1308
- package/dist/cjs/encoders/index.d.ts +0 -1
- package/dist/cjs/encoders/index.js +0 -5
- package/dist/cjs/index.d.ts +0 -5
- package/dist/cjs/index.js +0 -16
- package/dist/cjs/package.json +0 -3
- package/dist/cjs/types/DduDefaultTypes.d.ts +0 -3
- package/dist/cjs/types/DduDefaultTypes.js +0 -17
- package/dist/cjs/types/DduEnums.d.ts +0 -6
- package/dist/cjs/types/DduEnums.js +0 -10
- package/dist/cjs/types/DduInterface.d.ts +0 -91
- package/dist/cjs/types/DduInterface.js +0 -2
- package/dist/cjs/types/index.d.ts +0 -3
- package/dist/cjs/types/index.js +0 -19
- package/dist/cjs/utils/CharsetBuilder.d.ts +0 -129
- package/dist/cjs/utils/CharsetBuilder.js +0 -246
- package/dist/cjs/utils/DduPipeline.d.ts +0 -114
- package/dist/cjs/utils/DduPipeline.js +0 -229
- package/dist/cjs/utils/DduStream.d.ts +0 -64
- package/dist/cjs/utils/DduStream.js +0 -221
- package/dist/cjs/utils/crypto.d.ts +0 -30
- package/dist/cjs/utils/crypto.js +0 -84
- package/dist/cjs/utils/index.d.ts +0 -3
- package/dist/cjs/utils/index.js +0 -12
- package/dist/mjs/base/BaseDdu.d.ts +0 -53
- package/dist/mjs/base/BaseDdu.js +0 -23
- package/dist/mjs/base/index.d.ts +0 -1
- package/dist/mjs/base/index.js +0 -1
- package/dist/mjs/charSets/index.d.ts +0 -18
- package/dist/mjs/charSets/index.js +0 -4380
- package/dist/mjs/encoders/Ddu64.d.ts +0 -302
- package/dist/mjs/encoders/Ddu64.js +0 -1343
- package/dist/mjs/encoders/index.d.ts +0 -1
- package/dist/mjs/encoders/index.js +0 -1
- package/dist/mjs/index.d.ts +0 -5
- package/dist/mjs/index.js +0 -4
- package/dist/mjs/package.json +0 -3
- package/dist/mjs/types/DduDefaultTypes.d.ts +0 -3
- package/dist/mjs/types/DduDefaultTypes.js +0 -14
- package/dist/mjs/types/DduEnums.d.ts +0 -6
- package/dist/mjs/types/DduEnums.js +0 -7
- package/dist/mjs/types/DduInterface.d.ts +0 -91
- package/dist/mjs/types/DduInterface.js +0 -1
- package/dist/mjs/types/index.d.ts +0 -3
- package/dist/mjs/types/index.js +0 -3
- package/dist/mjs/utils/CharsetBuilder.d.ts +0 -129
- package/dist/mjs/utils/CharsetBuilder.js +0 -241
- package/dist/mjs/utils/DduPipeline.d.ts +0 -114
- package/dist/mjs/utils/DduPipeline.js +0 -223
- package/dist/mjs/utils/DduStream.d.ts +0 -64
- package/dist/mjs/utils/DduStream.js +0 -225
- package/dist/mjs/utils/crypto.d.ts +0 -30
- package/dist/mjs/utils/crypto.js +0 -78
- package/dist/mjs/utils/index.d.ts +0 -3
- package/dist/mjs/utils/index.js +0 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import {m,k as k$1,d,c,e,g,i,j,h,l,f,b,a}from'./chunk-FVBZKVPE.js';export{o as DduDecodeStream,n as DduEncodeStream,q as createDecodeStream,p as createEncodeStream}from'./chunk-FVBZKVPE.js';import {brotliCompressSync,constants,deflateSync,brotliDecompressSync,inflateSync}from'zlib';import {createHash,randomBytes,createCipheriv,createDecipheriv}from'crypto';import {Transform}from'stream';var q=(r=>(r.DDU="ddu",r.DDU_V1="ddu_v1",r.ONECHARSET="oneCharSet",r))(q||{}),G={dduSetSymbol:"ddu",usePowerOfTwo:true,requiredLength:64,bitLength:6};var ue={symbol:"ddu",charSet:["\uB70C","\uB568","\uC774","\uC6B0","\uC57C","\uB4C0","\uB31C","\uB3A8"],codaChar:["","\u3131","\u3132","\u3137","\u3148","\u3147","\u3145","\u3146"],maxRequiredLength:64,bitLength:6,paddingChar:"\uBB50",useRepeatPadding:true},he={symbol:"ddu_v1",charSet:["\uB70C","\uB568","\uC774","\uC6B0","\uC57C","!","?","."],maxRequiredLength:8,bitLength:3,paddingChar:"\uBB50"},fe={symbol:"oneCharSet",charSet:["A","s","q","r","0","z","3","t","y","1","5","2","4","E","B","C","Q","F","R","T","U","W","V","X","Y","Z","b","a","c","d","D","G","L","H","I","-","J","K","M","O","N","f","e","h","g","P","i","S","k","l","m","u","j","v","n","o","p","9","w","6","7","8","x","_"],paddingChar:"=",maxRequiredLength:64,bitLength:6};function T(y){switch(y){case "ddu":return ue;case "ddu_v1":return he;case "oneCharSet":return fe;default:return}}function P(y){return createHash("sha256").update(y).digest()}function O(y,e){let t=randomBytes(12),r=createCipheriv("aes-256-gcm",e,t),o=Buffer.concat([r.update(y),r.final()]),c=r.getAuthTag();return Buffer.concat([t,c,o])}function z(y,e){if(y.length<28)throw new Error("[decrypt] Invalid encrypted data: too short");let t=y.subarray(0,12),r=y.subarray(12,28),o=y.subarray(28),c=createDecipheriv("aes-256-gcm",e,t);return c.setAuthTag(r),Buffer.concat([c.update(o),c.final()])}function de(y,e){if(y.length<28)throw new Error("[decrypt] Invalid encrypted stream data: too short");let t=y.subarray(0,12),r=y.subarray(y.length-16),o=y.subarray(12,y.length-16),c=createDecipheriv("aes-256-gcm",e,t);return c.setAuthTag(r),Buffer.concat([c.update(o),c.final()])}function x(y,e,t="brotli decompress"){if(e===Number.POSITIVE_INFINITY)return brotliDecompressSync(y);try{let r=brotliDecompressSync(y,{maxOutputLength:e});if(r.length>e)throw new Error(`[${t}] Decompressed data exceeds limit. Size: ${r.length} bytes, Limit: ${e} bytes`);return r}catch(r){let o=r,c=String(o?.message??"").toLowerCase();throw String(o?.code??"")==="ERR_BUFFER_TOO_LARGE"||c.includes("cannot create a buffer larger")||c.includes("buffer larger than")||c.includes("output length")?new Error(`[${t}] Decompressed data exceeds limit. Limit: ${e} bytes`,{cause:r}):r}}function U(y,e,t="inflate"){if(e===Number.POSITIVE_INFINITY)return inflateSync(y);try{return inflateSync(y,{maxOutputLength:e})}catch(r){let o=r,c=String(o?.message??""),s=String(o?.code??"");if(c.toLowerCase().includes("maxoutputlength")||c.toLowerCase().includes("unknown option")||s==="ERR_INVALID_ARG_VALUE"){let d=inflateSync(y);if(d.length>e)throw new Error(`[${t}] Decompressed data exceeds limit. Size: ${d.length} bytes, Limit: ${e} bytes`,{cause:r});return d}throw s==="ERR_BUFFER_TOO_LARGE"||c.toLowerCase().includes("output length")||c.toLowerCase().includes("buffer too large")?new Error(`[${t}] Decompressed data exceeds limit. Limit: ${e} bytes`,{cause:r}):r}}var I=class extends Transform{cipher;constructor(e){super();let t=randomBytes(12);this.cipher=createCipheriv("aes-256-gcm",e,t),this.push(t);}_transform(e,t,r){let o=this.cipher.update(e);o.length>0&&this.push(o),r();}_flush(e){try{let t=this.cipher.final();t.length>0&&this.push(t),this.push(this.cipher.getAuthTag()),e();}catch(t){e(t instanceof Error?t:new Error(String(t)));}}},M=class extends Transform{keyHash;iv=null;decipher=null;tail=Buffer.alloc(0);constructor(e){super(),this.keyHash=e;}_transform(e,t,r){if(this.tail=Buffer.concat([this.tail,e]),!this.iv&&this.tail.length>=12&&(this.iv=this.tail.subarray(0,12),this.decipher=createDecipheriv("aes-256-gcm",this.keyHash,this.iv),this.tail=this.tail.subarray(12)),this.decipher&&this.tail.length>16){let o=this.tail.length-16,c=this.tail.subarray(0,o);this.tail=this.tail.subarray(o);try{let s=this.decipher.update(c);s.length>0&&this.push(s);}catch(s){return r(s instanceof Error?s:new Error(String(s)))}}r();}_flush(e){if(!this.decipher||this.tail.length!==16)return e(new Error("[GcmDecryptStream] Invalid encrypted data: too short or no auth tag"));try{this.decipher.setAuthTag(this.tail);let t=this.decipher.final();t.length>0&&this.push(t),e();}catch(t){e(t instanceof Error?t:new Error(String(t)));}}};var w=8,$=255,ye=65536,Ce=64*1024*1024,Se=64*1024*1024,v={START:0,ENCRYPT:15,CHECKSUM:20,COMPRESS:40,ENCODE:50,DONE:100},k={START:0,DECODE:20,DECOMPRESS:50,CHECKSUM:70,DECRYPT:85,DONE:100},A=class{defaultEncoding="utf-8";dduChar;paddingChar;bitLength;usePowerOfTwo;encoding;defaultCompress;defaultMaxDecodedBytes;defaultMaxDecompressedBytes;dduBinaryLookup=new Map;isPredefinedCharSet;effectiveBitLength;maxBinaryValue;fastAsciiLookup=null;useAsciiLookup=false;urlSafe;encryptionKeyHash;defaultChecksum;defaultChunkSize;defaultChunkSeparator;defaultCompressionLevel;defaultCompressionAlgorithm;useRepeatPadding;constructor(e,t,r){let o=r?.throwOnError??r?.useBuildErrorReturn??false,c=this.resolveInitialCharSet(e,t,r,o),s=this.normalizeCharSet(c,o,r);this.dduChar=s.charSet,this.paddingChar=s.padding,this.isPredefinedCharSet=s.isPredefined,this.encoding=r?.encoding??this.defaultEncoding,this.defaultCompress=r?.compress??false,this.defaultMaxDecodedBytes=this.normalizeLimit(r?.maxDecodedBytes,Ce,o,"maxDecodedBytes"),this.defaultMaxDecompressedBytes=this.normalizeLimit(r?.maxDecompressedBytes,Se,o,"maxDecompressedBytes");let d=this.dduChar.length;this.usePowerOfTwo=d>0&&(d&d-1)===0;let n=this.getBitLength(d);this.bitLength=this.usePowerOfTwo?this.getLargestPowerOfTwoExponent(d):n,this.effectiveBitLength=this.usePowerOfTwo?this.bitLength:n,this.maxBinaryValue=this.effectiveBitLength<31?1<<this.effectiveBitLength:Math.pow(2,this.effectiveBitLength);{let h=true;for(let a=0;a<d;a++)if(this.dduChar[a].charCodeAt(0)>=128){h=false;break}if(h){this.fastAsciiLookup=new Int16Array(128).fill(-1);for(let a=0;a<d;a++)this.fastAsciiLookup[this.dduChar[a].charCodeAt(0)]=a;this.useAsciiLookup=true;}}for(let h=0;h<d;h++)this.dduBinaryLookup.set(this.dduChar[h],h);this.isPredefinedCharSet||this.validateCombinationDuplicates(this.dduChar,this.paddingChar,d);let i=r?.urlSafe??false;this.urlSafe=i?this.isUrlSafeCompatible(this.dduChar,this.paddingChar,o):false,this.encryptionKeyHash=r?.encryptionKey?P(r.encryptionKey):void 0,this.defaultChecksum=r?.checksum??false,this.defaultChunkSize=r?.chunkSize,this.defaultChunkSeparator=r?.chunkSeparator??`
|
|
2
|
+
`,this.defaultCompressionAlgorithm=r?.compressionAlgorithm??"deflate",this.defaultCompressionLevel=m(r?.compressionLevel,this.defaultCompressionAlgorithm),this.useRepeatPadding=r?.useRepeatPadding??c.useRepeatPadding??false;}encode(e,t){return this.encodeInternal(e,t).encoded}encodeInternal(e$1,t){let r=t?.compress??this.defaultCompress,o=t?.checksum??this.defaultChecksum,c$1=(t?.encrypt??true)&&!!this.encryptionKeyHash,s=t?.omitFooter??false,d$1=t?.chunkSize??this.defaultChunkSize,n=t?.chunkSeparator??this.defaultChunkSeparator,i$1=t?.onProgress,h=!!d$1&&d$1>0&&!o&&!this.urlSafe,a=typeof e$1=="string"?Buffer.from(e$1,this.encoding):e$1,u=a.length;i$1&&i$1({processedBytes:0,totalBytes:u,percent:v.START,stage:"start"});let f=false;c$1&&(a=this.encryptData(a),f=true,i$1&&i$1({processedBytes:0,totalBytes:u,percent:v.ENCRYPT,stage:"encrypt"}));let m$1="";o&&(m$1=k$1(a),i$1&&i$1({processedBytes:0,totalBytes:u,percent:v.CHECKSUM,stage:"checksum"}));let l="",p;if(r){let C=t?.compressionAlgorithm??this.defaultCompressionAlgorithm,S=C==="brotli",b=m(t?.compressionLevel??this.defaultCompressionLevel,C),B=S?brotliCompressSync(a,{params:{[constants.BROTLI_PARAM_QUALITY]:Math.min(11,Math.max(0,b))}}):deflateSync(a,{level:Math.min(9,Math.max(0,b))});p=B.length,B.length<a.length&&(a=B,l=S?d:c),i$1&&i$1({processedBytes:Math.floor(u*.4),totalBytes:u,percent:v.COMPRESS,stage:"compress"});}i$1&&i$1({processedBytes:Math.floor(u*.5),totalBytes:u,percent:v.ENCODE,stage:"encode"});let g$1=this.encodeFast(a,l,f,s,h?d$1:void 0,h?n:void 0);return o&&m$1&&(g$1=g$1+e+m$1),this.urlSafe&&(g$1=g(g$1)),!h&&d$1&&d$1>0&&(g$1=i(g$1,d$1,n)),i$1&&i$1({processedBytes:u,totalBytes:u,percent:v.DONE,stage:"done"}),{encoded:g$1,compressedSize:p}}decodeToBuffer(e,t){let r=t?.checksum??this.defaultChecksum,o=t?.compress!==false,c=t?.encrypt!==false,s=t?.onProgress,d=e,n=e.length;s&&s({processedBytes:0,totalBytes:n,percent:k.START,stage:"start"});let i=t?.chunkSeparator??this.defaultChunkSeparator;d=j(d,i),this.urlSafe&&(d=h(d));let h$1=null;if(r){let C=l(d);h$1=C.checksum,d=C.data;}let{cleanedInput:a,paddingBits:u,compressionAlgorithm:f,isEncrypted:m}=this.parseFooter(d);if(m&&c&&!this.encryptionKeyHash)throw new Error("[Ddu64 decode] Encrypted payload requires an encryptionKey");this.assertEncodedInputAligned(a);let l$1=this.normalizeLimit(t?.maxDecodedBytes,this.defaultMaxDecodedBytes,true,"maxDecodedBytes"),p=this.estimateDecodedBytes(a.length,u);if(p>l$1)throw new Error(`[Ddu64 decode] Decoded output exceeds limit. Estimated: ${p} bytes, Limit: ${l$1} bytes`);s&&s({processedBytes:Math.floor(n*.2),totalBytes:n,percent:k.DECODE,stage:"decode"});let g=this.decodeFast(a,u);if(f&&o){s&&s({processedBytes:Math.floor(n*.5),totalBytes:n,percent:k.DECOMPRESS,stage:"decompress"});let C=this.normalizeLimit(t?.maxDecompressedBytes,this.defaultMaxDecompressedBytes,true,"maxDecompressedBytes");f==="brotli"||t?.compressionAlgorithm==="brotli"||!t?.compressionAlgorithm&&this.defaultCompressionAlgorithm==="brotli"?g=x(g,C,"Ddu64 decode"):g=this.inflateWithLimit(g,C);}if(h$1){s&&s({processedBytes:Math.floor(n*.7),totalBytes:n,percent:k.CHECKSUM,stage:"checksum"});let C=k$1(g);if(C!==h$1)throw new Error(`[Ddu64 decode] Checksum mismatch. Expected: ${h$1}, Got: ${C}`)}return m&&this.encryptionKeyHash&&c&&(s&&s({processedBytes:Math.floor(n*.85),totalBytes:n,percent:k.DECRYPT,stage:"decrypt"}),g=this.decryptData(g)),s&&s({processedBytes:n,totalBytes:n,percent:k.DONE,stage:"done"}),g}decode(e,t){return this.decodeToBuffer(e,t).toString(this.encoding)}decodeStreamToBuffer(e,t){let r=t?.compress!==false,o=t?.encrypt!==false,{decoded:c,compressionAlgorithm:s,isEncrypted:d}=this.decodeRaw(e,t),n=c;if(d&&this.encryptionKeyHash&&o&&(n=this.decryptStreamData(n)),s&&r){let i=this.normalizeLimit(t?.maxDecompressedBytes,this.defaultMaxDecompressedBytes,true,"maxDecompressedBytes");s==="brotli"?n=x(n,i,"Ddu64 decode"):n=this.inflateWithLimit(n,i);}return n}decodeRaw(e,t){let r=t?.chunkSeparator??this.defaultChunkSeparator,o=j(e,r),{cleanedInput:c,paddingBits:s,compressionAlgorithm:d,isEncrypted:n}=this.parseFooter(o);if(n&&t?.encrypt!==false&&!this.encryptionKeyHash)throw new Error("[Ddu64 decode] Encrypted payload requires an encryptionKey");this.assertEncodedInputAligned(c);let i=this.normalizeLimit(t?.maxDecodedBytes,this.defaultMaxDecodedBytes,true,"maxDecodedBytes"),h=this.estimateDecodedBytes(c.length,s);if(h>i)throw new Error(`[Ddu64 decode] Decoded output exceeds limit. Estimated: ${h} bytes, Limit: ${i} bytes`);return {decoded:this.decodeFast(c,s),compressionAlgorithm:d,isEncrypted:n}}getCharSetInfo(){return {charSet:[...this.dduChar],paddingChar:this.paddingChar,bitLength:this.bitLength,usePowerOfTwo:this.usePowerOfTwo,encoding:this.encoding,defaultCompress:this.defaultCompress,defaultMaxDecodedBytes:this.defaultMaxDecodedBytes,defaultMaxDecompressedBytes:this.defaultMaxDecompressedBytes,urlSafe:this.urlSafe,hasEncryptionKey:!!this.encryptionKeyHash,defaultChecksum:this.defaultChecksum,defaultChunkSize:this.defaultChunkSize,defaultChunkSeparator:this.defaultChunkSeparator,defaultCompressionLevel:this.defaultCompressionLevel,defaultCompressionAlgorithm:this.defaultCompressionAlgorithm}}encodeRawBuffer(e,t){let r=t?.compressionAlgorithm==="brotli"?d:t?.compressionAlgorithm==="deflate"?c:"";return this.encodeFast(e,r,t?.encrypted,t?.omitFooter)}getStats(e,t){let r=t?.compress??this.defaultCompress,c=(typeof e=="string"?Buffer.from(e,this.encoding):e).length,{encoded:s,compressedSize:d}=this.encodeInternal(e,t),n=s.length,i=c>0?n/c:0,h=r&&d!==void 0&&c>0?d/c:void 0;return {originalSize:c,encodedSize:n,compressedSize:d,compressionRatio:h,expansionRatio:i,charsetSize:this.dduChar.length,bitLength:this.bitLength}}async encodeAsync(e,t){let r=typeof e=="string"?Buffer.from(e,this.encoding):e,o=64*1024,c=t?.compress??this.defaultCompress,s=t?.checksum??this.defaultChecksum,d=(t?.encrypt??true)&&!!this.encryptionKeyHash;if(r.length<=o||c||s||d||this.urlSafe)return new Promise((i,h)=>{setImmediate(()=>{try{i(this.encode(r,t));}catch(a){h(a);}});});let{createEncodeStream:n}=await import('./DduStream-NP3CMCKK.js');return new Promise((i,h)=>{let a=n(this,t),u=[];a.on("data",l=>u.push(l.toString())),a.on("end",()=>i(u.join(""))),a.on("error",h);let f=0;function m(){try{for(;f<r.length;){let l=Math.min(f+o,r.length),p=r.subarray(f,l);if(f=l,!a.write(p)){a.once("drain",m);return}if(f%(o*16)===0){setImmediate(m);return}}a.end();}catch(l){a.destroy(l);}}m();})}async decodeAsync(e,t){return (await this.decodeToBufferAsync(e,t)).toString(this.encoding)}async decodeToBufferAsync(e,t){let c=(t?.checksum??this.defaultChecksum)||this.urlSafe||!!this.defaultChunkSize||!!t?.chunkSize;if(e.length<=65536)return new Promise((h,a)=>{setImmediate(()=>{try{h(this.decodeToBuffer(e,t));}catch(u){a(u);}});});let s=c?null:this.parseFooter(e),d=(t?.compress??this.defaultCompress)||!!s?.compressionAlgorithm,n=(t?.encrypt??true)&&!!this.encryptionKeyHash||!!s?.isEncrypted;if(c||d||n)return new Promise((h,a)=>{setImmediate(()=>{try{h(this.decodeToBuffer(e,t));}catch(u){a(u);}});});let{createDecodeStream:i}=await import('./DduStream-NP3CMCKK.js');return new Promise((h,a)=>{let u=i(this,t),f=[];u.on("data",p=>f.push(p)),u.on("end",()=>h(Buffer.concat(f))),u.on("error",a);let m=0;function l(){try{for(;m<e.length;){let p=Math.min(m+65536,e.length),g=e.slice(m,p);if(m=p,!u.write(g)){u.once("drain",l);return}if(m%(65536*16)===0){setImmediate(l);return}}u.end();}catch(p){u.destroy(p);}}l();})}encryptData(e){if(!this.encryptionKeyHash)throw new Error("[Ddu64 encrypt] Encryption key is not set");return O(e,this.encryptionKeyHash)}decryptData(e){if(!this.encryptionKeyHash)throw new Error("[Ddu64 decrypt] Encryption key is not set");return z(e,this.encryptionKeyHash)}decryptStreamData(e){if(!this.encryptionKeyHash)throw new Error("[Ddu64 decrypt] Encryption key is not set");return de(e,this.encryptionKeyHash)}createEncryptionStream(){if(this.encryptionKeyHash)return new I(this.encryptionKeyHash)}createDecryptionStream(){if(this.encryptionKeyHash)return new M(this.encryptionKeyHash)}getLargestPowerOfTwoExponent(e){return Math.floor(Math.log2(e))}getBitLength(e){return Math.ceil(Math.log2(e))}normalizeLimit(e,t,r,o){if(e===void 0)return t;if(e===Number.POSITIVE_INFINITY)return Number.POSITIVE_INFINITY;if(!Number.isFinite(e)||e<=0){if(r)throw new Error(`[Ddu64 options] Invalid ${o}. Must be a positive finite number or Infinity.`);return t}return Math.floor(e)}estimateDecodedBytes(e,t){if(e===0)return 0;if(t<0||t>=this.effectiveBitLength)throw new Error(`[Ddu64 decode] Invalid padding bits: ${t}`);let r=this.usePowerOfTwo?1:2,c=Math.ceil(e/r)*this.effectiveBitLength-t;if(c<0)throw new Error("[Ddu64 decode] Invalid decoded bit length");return Math.ceil(c/w)}assertEncodedInputAligned(e){if(!this.usePowerOfTwo&&e.length%2!==0)throw new Error(`[Ddu64 decode] Invalid encoded length for variable charset. Expected multiple of 2, got ${e.length}`)}inflateWithLimit(e,t){return U(e,t,"Ddu64 decode")}parseFooter(e){let t=e.length,r=this.paddingChar,o=r.length,c$1={cleanedInput:e,paddingBits:0,isEncrypted:false};if(t<o)return c$1;let d$1=Math.max(0,this.effectiveBitLength-1).toString().length;for(let n=Math.min(d$1,t);n>=1;n--){let i=t-n,h=true;for(let g=i;g<t;g++){let C=e.charCodeAt(g);if(C<48||C>57){h=false;break}}if(!h)continue;let a=e.substring(i),u=parseInt(a,10);if(Number.isNaN(u)||u<0||u>=this.effectiveBitLength||a!==u.toString())continue;let f$1=i,m=false,l;f$1>=f.length&&e.substring(f$1-f.length,f$1)===f&&(m=true,f$1-=f.length),f$1>=c.length&&e.substring(f$1-c.length,f$1)===c?(l="deflate",f$1-=c.length):f$1>=d.length&&e.substring(f$1-d.length,f$1)===d&&(l="brotli",f$1-=d.length);let p=f$1-o;if(p>=0&&e.substring(p,f$1)===r)return {cleanedInput:e.substring(0,p),paddingBits:u,compressionAlgorithm:l,isEncrypted:m}}if(e.endsWith(r)){let n=0,i=t;for(;i>=o&&e.substring(i-o,i)===r;)n++,i-=o;if(n>0){let h=n*2;if(h<this.effectiveBitLength)return {cleanedInput:e.substring(0,i),paddingBits:h,isEncrypted:false}}}return c$1}encodeFast(e,t,r,o=false,c,s){let d=e.length;if(d===0)return "";let{dduChar:n,effectiveBitLength:i,paddingChar:h}=this,a=n.length,u=d*w,f$1=Math.ceil(u/i),m=this.usePowerOfTwo?f$1:f$1*2,l=new Array(m+3),p=0,g=0,C=0;if(this.usePowerOfTwo){let S=(1<<i)-1;for(let b=0;b<d;b++)for(g=g<<w|e[b],C+=w;C>=i;)C-=i,l[p++]=n[g>>C&S],g&=(1<<C)-1;}else for(let S=0;S<d;S++)for(g=g<<w|e[S],C+=w;C>=i;){C-=i;let b=g>>C,B=b/a|0;l[p++]=n[B],l[p++]=n[b-B*a],g&=(1<<C)-1;}if(C>0){let S=i-C,b=g<<S;if(this.usePowerOfTwo)l[p++]=n[b];else {let B=b/a|0;l[p++]=n[B],l[p++]=n[b-B*a];}if(this.useRepeatPadding&&!t&&!r){if(!o){let B=S>>1;for(let W=0;W<B;W++)l[p++]=h;}}else {if(o)throw new Error("[Ddu64 encode] Cannot omit footer when padding bits remain");l[p++]=h,l[p++]=t+(r?f:"")+S.toString();}}else !o&&(t||r)&&(l[p++]=h,l[p++]=t+(r?f:"")+"0");return this.serializeEncodedParts(l,p,c,s)}decodeFast(e,t){let r=e.length;if(r===0)return Buffer.alloc(0);let{effectiveBitLength:o}=this,c=this.dduChar.length,s=this.usePowerOfTwo?1:2,d=Math.ceil(r/s),n=Math.ceil((d*o-t)/w),i=new Uint8Array(n+1),h=0,a=0,u=0;if(this.usePowerOfTwo)if(this.useAsciiLookup&&this.fastAsciiLookup){let f=this.fastAsciiLookup;for(let m=0;m<r;m+=s){let l=e.charCodeAt(m),p=l<128?f[l]:-1;if(p<0)throw new Error(`[Ddu64 decode] Invalid character "${e[m]}" at ${m}`);for(a=a<<o|p,u+=o,m+s>=r&&t>0&&(a>>=t,u-=t);u>=w;)u-=w,i[h++]=a>>u&$,a&=(1<<u)-1;}}else {let f=this.dduBinaryLookup;for(let m=0;m<r;m+=s){let l=e[m],p=f.get(l);if(p===void 0)throw new Error(`[Ddu64 decode] Invalid character "${l}" at ${m}`);for(a=a<<o|p,u+=o,m+s>=r&&t>0&&(a>>=t,u-=t);u>=w;)u-=w,i[h++]=a>>u&$,a&=(1<<u)-1;}}else if(this.useAsciiLookup&&this.fastAsciiLookup){let f=this.fastAsciiLookup,m=this.maxBinaryValue;for(let l=0;l<r;l+=s){let p=e.charCodeAt(l),g=e.charCodeAt(l+1),C=p<128?f[p]:-1,S=g<128?f[g]:-1;if(C<0)throw new Error(`[Ddu64 decode] Invalid character "${e[l]}" at ${l}`);if(S<0)throw new Error(`[Ddu64 decode] Invalid character "${e[l+1]}" at ${l+1}`);let b=C*c+S;if(b>=m)throw new Error(`[Ddu64 decode] Value ${b} exceeds range`);for(a=a<<o|b,u+=o,l+s>=r&&t>0&&(a>>=t,u-=t);u>=w;)u-=w,i[h++]=a>>u&$,a&=(1<<u)-1;}}else {let f=this.dduBinaryLookup;for(let m=0;m<r;m+=s){let l=e[m],p=e[m+1],g=f.get(l),C=f.get(p);if(g===void 0)throw new Error(`[Ddu64 decode] Invalid character "${l}" at ${m}`);if(C===void 0)throw new Error(`[Ddu64 decode] Invalid character "${p}" at ${m+1}`);let S=g*c+C;if(S>=this.maxBinaryValue)throw new Error(`[Ddu64 decode] Value ${S} exceeds range`);for(a=a<<o|S,u+=o,m+s>=r&&t>0&&(a>>=t,u-=t);u>=w;)u-=w,i[h++]=a>>u&$,a&=(1<<u)-1;}}return Buffer.from(i.subarray(0,h))}serializeEncodedParts(e,t,r,o){if(e.length=t,!r||r<=0)return e.join("");let c=o??this.defaultChunkSeparator,s=[],d=0;for(let n=0;n<t;n++){let i=e[n],h=0;for(;h<i.length;){let a=r-d,u=Math.min(a,i.length-h);s.push(i.slice(h,h+u)),h+=u,d+=u,d===r&&(h<i.length||n<t-1)&&(s.push(c),d=0);}}return s.join("")}normalizeCharSet(e,t,r){let o=[e,null];for(let s of o){let d=s?{...s}:this.getFallbackCharSet(r);try{let n=d.charSet,i=d.requiredLength,h=Array.from(new Set(n));if(h.length!==n.length){if(t){let f=n.filter((m,l)=>n.indexOf(m)!==l);throw new Error(`[Ddu64 normalizeCharSet] Character set contains duplicate characters: [${[...new Set(f)].join(", ")}]`)}n=h,d.isPredefined||(i=n.length);}if(n.length<i)throw new Error(`[Ddu64 normalizeCharSet] Insufficient characters. Required: ${i}, Has: ${n.length}`);if(i<2)throw new Error("[Ddu64 normalizeCharSet] At least 2 unique characters required.");if(n.length===0)throw new Error("[Ddu64 normalizeCharSet] Empty charset.");if(n.find(f=>f.length!==1)){if(t)throw new Error("[Ddu64 normalizeCharSet] Multi-character symbols are not supported. All charset characters must have length 1.");continue}if(n.length>ye){if(t)throw new Error("[Ddu64 normalizeCharSet] Charset size exceeds maximum supported size of 65536.");continue}if(d.padding.length!==1)throw new Error(`[Ddu64 normalizeCharSet] Padding length mismatch. Expected 1, got ${d.padding.length}`);if(n.includes(d.padding)){if(t)throw new Error(`[Ddu64 normalizeCharSet] Padding character "${d.padding}" conflicts with charset.`);n=n.filter(f=>f!==d.padding);}for(let f of n)if(f.includes(`
|
|
3
|
+
`)||f.includes("\r"))throw new Error("[Ddu64 normalizeCharSet] Newline and carriage return characters are reserved for chunk normalization and cannot be used in charset.");if(d.padding.includes(`
|
|
4
|
+
`)||d.padding.includes("\r"))throw new Error("[Ddu64 normalizeCharSet] Newline and carriage return characters are reserved for chunk normalization and cannot be used in padding.");return {charSet:n.length===i?n:n.slice(0,i),padding:d.padding,isPredefined:d.isPredefined}}catch(n){if(t)throw n}}let c=this.getFallbackCharSet(r);return {charSet:c.charSet.slice(0,c.requiredLength),padding:c.padding,isPredefined:true}}resolveInitialCharSet(e,t,r,o){let c=(s,d,n,i,h)=>{if(this.shouldUsePowerOfTwo(n,r?.usePowerOfTwo)&&n>0){let f=this.getLargestPowerOfTwoExponent(n),m=1<<f;return {charSet:s.length===m?s:s.slice(0,m),padding:d,requiredLength:m,bitLength:f,isPredefined:i,useRepeatPadding:h}}return {charSet:s.length===n?s:s.slice(0,n),padding:d,requiredLength:n,bitLength:n>0?this.getBitLength(n):0,isPredefined:i,useRepeatPadding:h}};try{let s=e??r?.dduChar,d=t??r?.paddingChar;if(s){if(!d)throw new Error("[Ddu64 Constructor] paddingChar is required when dduChar is provided.");let a=typeof s=="string"?[...s.trim()]:[...s],u=r?.codaChar,f=u?!0:r?.useRepeatPadding??!1;if(u&&u.length>0&&(a=b(a,u)),o&&new Set(a).size!==a.length){let p=a.filter((g,C)=>a.indexOf(g)!==C);throw new Error(`[Ddu64 Constructor] Character set contains duplicate characters: [${[...new Set(p)].join(", ")}]`)}let m=r?.requiredLength??a.length;if(a.length<m)throw new Error("[Ddu64 Constructor] Insufficient characters.");return c(a,d,m,!1,f)}let n=r?.dduSetSymbol??G.dduSetSymbol??"ddu",i=this.getCharSetOrThrow(n),h=i.codaChar?b(i.charSet,i.codaChar):i.charSet;return c(h,i.paddingChar,i.maxRequiredLength,!0,i.useRepeatPadding)}catch(s){if(o)throw s;return this.getFallbackCharSet(r)}}getFallbackCharSet(e){let t=e?.dduSetSymbol??G.dduSetSymbol??"oneCharSet",r=T(t)??T("oneCharSet");if(!r)throw new Error("Critical: No fallback CharSet available");return {charSet:r.codaChar?b(r.charSet,r.codaChar):r.charSet,padding:r.paddingChar,requiredLength:r.maxRequiredLength,bitLength:r.bitLength,isPredefined:true,useRepeatPadding:r.useRepeatPadding}}shouldUsePowerOfTwo(e,t){return t!==void 0?t?e>0:false:e>0&&(e&e-1)===0}getCharSetOrThrow(e){let t=T(e);if(!t)throw new Error(`CharSet with symbol ${e} not found`);return t}isUrlSafeCompatible(e,t,r){let o=a;for(let c of o){for(let s of e)if(s.includes(c)){let d=`[Ddu64 Constructor] URL-Safe mode conflict: charset character "${s}" contains "${c}" which conflicts with URL-safe encoding.`;if(r)throw new Error(d);return false}if(t.includes(c)){let s=`[Ddu64 Constructor] URL-Safe mode conflict: padding character "${t}" contains "${c}" which conflicts with URL-safe encoding.`;if(r)throw new Error(s);return false}}return true}validateCombinationDuplicates(e,t,r){if(r>256)return;let o=Math.min(e.length,r),c=e.slice(0,o),s=new Set,d=(n,i)=>{if(s.has(n))throw new Error(`Combination conflict: ${i}`);s.add(n);};for(let n=0;n<c.length;n++)s.add(c[n]);s.add(t);for(let n=0;n<c.length;n++){let i=c[n];for(let h=0;h<c.length;h++)d(i+c[h],`"${i}" + "${c[h]}"`);d(i+t,`"${i}" + padding`),d(t+i,`padding + "${i}"`);}d(t+t,"double padding");}};var N=class y{chars=[];constructor(){}static create(){return new y}static fromUnicodeRange(e,t){return new y().addUnicodeRange(e,t)}static fromString(e){return new y().addString(e)}static base64(){return new y().addString("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/")}static base32(){return new y().addString("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567")}static uppercase(){return y.fromUnicodeRange(65,90)}static lowercase(){return y.fromUnicodeRange(97,122)}static digits(){return y.fromUnicodeRange(48,57)}static hangulJamo(){return new y().addUnicodeRange(4352,4370).addUnicodeRange(4449,4469).addUnicodeRange(4520,4546)}addUnicodeRange(e,t){for(let r=e;r<=t;r++)this.chars.push(String.fromCodePoint(r));return this}addString(e){return typeof e=="string"?this.chars.push(...e):this.chars.push(...e),this}add(...e){return this.chars.push(...e),this}excludeConfusing(){let e=new Set(["0","O","o","1","l","I","i","|","L"]);return this.chars=this.chars.filter(t=>!e.has(t)),this}exclude(...e){let t=new Set(e);return this.chars=this.chars.filter(r=>!t.has(r)),this}excludeUrlUnsafe(){let e=new Set(["+","/","=","?","&","#","%"," "]);return this.chars=this.chars.filter(t=>!e.has(t)),this}unique(){return this.chars=[...new Set(this.chars)],this}shuffle(e){let t=e!==void 0?this.seededRandom(e):Math.random;for(let r=this.chars.length-1;r>0;r--){let o=Math.floor(t()*(r+1));[this.chars[r],this.chars[o]]=[this.chars[o],this.chars[r]];}return this}seededRandom(e){let t=e|0||1;return ()=>(t^=t<<13,t^=t>>17,t^=t<<5,(t>>>0)/4294967296)}limit(e){return this.chars=this.chars.slice(0,e),this}limitToPowerOfTwo(){let e=this.chars.length;if(e===0)return this;let t=1<<Math.floor(Math.log2(e));return this.chars=this.chars.slice(0,t),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(e){let t=[...this.chars],r=e;if(!r){let o=["=",".","_","-","~","!"];for(let c of o)if(!t.includes(c)){r=c;break}if(!r)throw new Error("Cannot find suitable padding character")}return {charset:t,padding:r}}};var K=class y{steps=[];compress(e=9,t="deflate"){return this.steps.push({type:"compress",level:e,algorithm:t}),this}decompress(e,t="deflate"){return this.steps.push({type:"decompress",maxDecompressedBytes:e,algorithm:t}),this}encrypt(e){return this.steps.push({type:"encrypt",key:e}),this}decrypt(e){return this.steps.push({type:"decrypt",key:e}),this}encode(e){return this.steps.push({type:"encode",encoder:e}),this}decode(e){return this.steps.push({type:"decode",encoder:e}),this}encodeWith(e,t,r){let o=new A(e,t,r);return this.encode(o)}transform(e){return this.steps.push({type:"transform",fn:e}),this}transformString(e){return this.steps.push({type:"transformString",fn:e}),this}reverse(){let e=new y;return e.steps=this.steps.slice().reverse().map(t=>{switch(t.type){case "compress":return {type:"decompress",algorithm:t.algorithm};case "decompress":return {type:"compress",level:9,algorithm:t.algorithm};case "encrypt":return {type:"decrypt",key:t.key};case "decrypt":return {type:"encrypt",key:t.key};case "encode":return {type:"decode",encoder:t.encoder};case "decode":return {type:"encode",encoder:t.encoder};case "transform":case "transformString":throw new Error(`[DduPipeline reverse] Cannot reverse "${t.type}" step. Custom transform functions are not reversible. Use explicit encode/decode pairs instead.`)}}),e}process(e){let t=e;for(let r of this.steps)t=this.executeStep(r,t);return t}processToString(e,t="utf-8"){let r=this.process(e);return typeof r=="string"?r:r.toString(t)}processToBuffer(e,t="utf-8"){let r=this.process(e);return Buffer.isBuffer(r)?r:Buffer.from(r,t)}executeStep(e,t){switch(e.type){case "compress":return this.compressData(this.toBuffer(t),e.level??9,e.algorithm??"deflate");case "decompress":return this.decompressData(this.toBuffer(t),e.maxDecompressedBytes,e.algorithm??"deflate");case "encrypt":return this.encryptData(this.toBuffer(t),e.key);case "decrypt":return this.decryptData(this.toBuffer(t),e.key);case "encode":return e.encoder.encode(this.toBuffer(t));case "decode":return e.encoder.decodeToBuffer(this.toString(t));case "transform":return e.fn(this.toBuffer(t));case "transformString":return e.fn(this.toString(t))}}toBuffer(e){return typeof e=="string"?Buffer.from(e,"utf-8"):e}toString(e){return typeof e=="string"?e:e.toString("utf-8")}compressData(e,t,r){return r==="brotli"?brotliCompressSync(e,{params:{[constants.BROTLI_PARAM_QUALITY]:Math.min(11,Math.max(0,t))}}):deflateSync(e,{level:Math.min(9,Math.max(0,t))})}decompressData(e,t,r="deflate"){if(r==="brotli"){let o=t??Number.POSITIVE_INFINITY;return x(e,o,"DduPipeline decompress")}return U(e,t??Number.POSITIVE_INFINITY,"DduPipeline decompress")}encryptData(e,t){return O(e,P(t))}decryptData(e,t){return z(e,P(t))}get stepCount(){return this.steps.length}clone(){let e=new y;return e.steps=[...this.steps],e}clear(){return this.steps=[],this}};export{N as CharsetBuilder,A as Ddu64,K as DduPipeline,q as DduSetSymbol};//# sourceMappingURL=index.js.map
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,41 +1,64 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ddunigma/node",
|
|
3
|
-
"version": "
|
|
4
|
-
"main": "dist/
|
|
5
|
-
"module": "dist/
|
|
6
|
-
"types": "dist/
|
|
3
|
+
"version": "3.0.0",
|
|
4
|
+
"main": "dist/index.cjs",
|
|
5
|
+
"module": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
7
|
"type": "module",
|
|
8
|
+
"sideEffects": false,
|
|
9
|
+
"engines": {
|
|
10
|
+
"node": ">=18.0.0"
|
|
11
|
+
},
|
|
8
12
|
"scripts": {
|
|
9
|
-
"build": "
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"test
|
|
13
|
-
"test:
|
|
14
|
-
"
|
|
13
|
+
"build": "tsup",
|
|
14
|
+
"bench": "node --expose-gc --import tsx benchmarks/encoding-benchmark.ts",
|
|
15
|
+
"pack:check": "node scripts/verify-pack.mjs",
|
|
16
|
+
"test": "vitest run",
|
|
17
|
+
"test:watch": "vitest",
|
|
18
|
+
"test:coverage": "vitest run --coverage",
|
|
19
|
+
"lint": "eslint src eslint.config.mjs tsup.config.ts",
|
|
20
|
+
"lint:fix": "eslint src eslint.config.mjs tsup.config.ts --fix",
|
|
21
|
+
"format": "prettier --write src/",
|
|
22
|
+
"test:all": "vitest run"
|
|
15
23
|
},
|
|
16
24
|
"exports": {
|
|
17
25
|
".": {
|
|
18
26
|
"import": {
|
|
19
|
-
"types": "./dist/
|
|
20
|
-
"default": "./dist/
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"default": "./dist/index.js"
|
|
21
29
|
},
|
|
22
30
|
"require": {
|
|
23
|
-
"types": "./dist/
|
|
24
|
-
"default": "./dist/
|
|
31
|
+
"types": "./dist/index.d.cts",
|
|
32
|
+
"default": "./dist/index.cjs"
|
|
25
33
|
}
|
|
26
34
|
}
|
|
27
35
|
},
|
|
36
|
+
"files": [
|
|
37
|
+
"dist",
|
|
38
|
+
"!dist/**/*.map"
|
|
39
|
+
],
|
|
28
40
|
"repository": {
|
|
29
41
|
"type": "git",
|
|
30
|
-
"url": "https://github.com/parkjh2568/ddunigma-node.git"
|
|
42
|
+
"url": "git+https://github.com/parkjh2568/ddunigma-node.git"
|
|
43
|
+
},
|
|
44
|
+
"publishConfig": {
|
|
45
|
+
"access": "public"
|
|
31
46
|
},
|
|
32
47
|
"author": "",
|
|
33
48
|
"license": "BSD-2-Clause",
|
|
34
49
|
"description": "",
|
|
35
50
|
"devDependencies": {
|
|
51
|
+
"@eslint/js": "^10.0.1",
|
|
36
52
|
"@types/node": "^22.13.0",
|
|
53
|
+
"@vitest/coverage-v8": "^4.1.2",
|
|
54
|
+
"eslint": "^10.2.0",
|
|
55
|
+
"globals": "^17.4.0",
|
|
56
|
+
"prettier": "^3.8.1",
|
|
57
|
+
"tsup": "^8.5.1",
|
|
37
58
|
"tsx": "^4.19.2",
|
|
38
|
-
"typescript": "^5.7.3"
|
|
59
|
+
"typescript": "^5.7.3",
|
|
60
|
+
"typescript-eslint": "^8.58.0",
|
|
61
|
+
"vitest": "^4.1.2"
|
|
39
62
|
},
|
|
40
63
|
"keywords": [
|
|
41
64
|
"ddu",
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { DduOptions } from "../types";
|
|
2
|
-
export declare abstract class BaseDdu {
|
|
3
|
-
protected readonly defaultEncoding: BufferEncoding;
|
|
4
|
-
/**
|
|
5
|
-
* 주어진 숫자보다 작거나 같은 가장 큰 2의 제곱수의 지수를 반환합니다.
|
|
6
|
-
* @param n - 대상 숫자
|
|
7
|
-
* @returns 2의 제곱수 지수 (예: n=8 → 3, n=64 → 6)
|
|
8
|
-
* @example getLargestPowerOfTwoExponent(8) // 3
|
|
9
|
-
* @example getLargestPowerOfTwoExponent(100) // 6
|
|
10
|
-
*/
|
|
11
|
-
protected getLargestPowerOfTwoExponent(n: number): number;
|
|
12
|
-
/**
|
|
13
|
-
* charset 크기에 필요한 비트 길이를 계산합니다.
|
|
14
|
-
* @param setLength - charset 문자 수
|
|
15
|
-
* @returns 필요한 비트 수
|
|
16
|
-
* @example getBitLength(64) // 6
|
|
17
|
-
* @example getBitLength(100) // 7
|
|
18
|
-
*/
|
|
19
|
-
protected getBitLength(setLength: number): number;
|
|
20
|
-
/**
|
|
21
|
-
* 입력 데이터를 인코딩합니다.
|
|
22
|
-
* @param input - 인코딩할 문자열 또는 Buffer
|
|
23
|
-
* @param options - 인코딩 옵션
|
|
24
|
-
* @returns 인코딩된 문자열
|
|
25
|
-
*/
|
|
26
|
-
abstract encode(input: Buffer | string, options?: DduOptions): string;
|
|
27
|
-
/**
|
|
28
|
-
* 인코딩된 문자열을 Buffer로 디코딩합니다.
|
|
29
|
-
* @param input - 인코딩된 문자열
|
|
30
|
-
* @param options - 디코딩 옵션
|
|
31
|
-
* @returns 디코딩된 Buffer
|
|
32
|
-
*/
|
|
33
|
-
abstract decodeToBuffer(input: string, options?: DduOptions): Buffer;
|
|
34
|
-
/**
|
|
35
|
-
* 인코딩된 문자열을 원본 문자열로 디코딩합니다.
|
|
36
|
-
* @param input - 인코딩된 문자열
|
|
37
|
-
* @param options - 디코딩 옵션
|
|
38
|
-
* @returns 디코딩된 문자열
|
|
39
|
-
*/
|
|
40
|
-
abstract decode(input: string, options?: DduOptions): string;
|
|
41
|
-
/**
|
|
42
|
-
* 현재 인코더의 charset 정보를 반환합니다.
|
|
43
|
-
* @returns charset 설정 정보 객체
|
|
44
|
-
*/
|
|
45
|
-
abstract getCharSetInfo(): {
|
|
46
|
-
charSet: string[];
|
|
47
|
-
paddingChar: string;
|
|
48
|
-
charLength: number;
|
|
49
|
-
bitLength: number;
|
|
50
|
-
usePowerOfTwo: boolean;
|
|
51
|
-
encoding: BufferEncoding;
|
|
52
|
-
};
|
|
53
|
-
}
|
package/dist/cjs/base/BaseDdu.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BaseDdu = void 0;
|
|
4
|
-
class BaseDdu {
|
|
5
|
-
constructor() {
|
|
6
|
-
this.defaultEncoding = "utf-8";
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* 주어진 숫자보다 작거나 같은 가장 큰 2의 제곱수의 지수를 반환합니다.
|
|
10
|
-
* @param n - 대상 숫자
|
|
11
|
-
* @returns 2의 제곱수 지수 (예: n=8 → 3, n=64 → 6)
|
|
12
|
-
* @example getLargestPowerOfTwoExponent(8) // 3
|
|
13
|
-
* @example getLargestPowerOfTwoExponent(100) // 6
|
|
14
|
-
*/
|
|
15
|
-
getLargestPowerOfTwoExponent(n) {
|
|
16
|
-
return Math.floor(Math.log2(n));
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* charset 크기에 필요한 비트 길이를 계산합니다.
|
|
20
|
-
* @param setLength - charset 문자 수
|
|
21
|
-
* @returns 필요한 비트 수
|
|
22
|
-
* @example getBitLength(64) // 6
|
|
23
|
-
* @example getBitLength(100) // 7
|
|
24
|
-
*/
|
|
25
|
-
getBitLength(setLength) {
|
|
26
|
-
return Math.ceil(Math.log2(setLength));
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
exports.BaseDdu = BaseDdu;
|
package/dist/cjs/base/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { BaseDdu } from "./BaseDdu";
|
package/dist/cjs/base/index.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { CharSetConfig, DduSetSymbol } from "../types";
|
|
2
|
-
/**
|
|
3
|
-
* 심볼에 해당하는 charset 설정을 반환합니다.
|
|
4
|
-
* @param symbol - charset 심볼
|
|
5
|
-
* @returns CharSetConfig 또는 undefined
|
|
6
|
-
*/
|
|
7
|
-
export declare function getCharSet(symbol: DduSetSymbol): CharSetConfig | undefined;
|
|
8
|
-
/**
|
|
9
|
-
* 모든 사용 가능한 charset 심볼 목록을 반환합니다.
|
|
10
|
-
* @returns DduSetSymbol 배열
|
|
11
|
-
*/
|
|
12
|
-
export declare function getAllSymbols(): DduSetSymbol[];
|
|
13
|
-
/**
|
|
14
|
-
* 해당 심볼의 charset이 존재하는지 확인합니다.
|
|
15
|
-
* @param symbol - 확인할 charset 심볼
|
|
16
|
-
* @returns 존재 여부
|
|
17
|
-
*/
|
|
18
|
-
export declare function hasCharSet(symbol: DduSetSymbol): boolean;
|