@ddunigma/node 1.1.6 → 1.1.9
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 +44 -0
- package/dist/cjs/base/BaseDdu.d.ts +13 -24
- package/dist/cjs/base/BaseDdu.js +0 -24
- package/dist/cjs/encoders/Ddu64.d.ts +18 -0
- package/dist/cjs/encoders/Ddu64.js +266 -172
- package/dist/mjs/base/BaseDdu.d.ts +13 -24
- package/dist/mjs/base/BaseDdu.js +0 -24
- package/dist/mjs/encoders/Ddu64.d.ts +18 -0
- package/dist/mjs/encoders/Ddu64.js +265 -168
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -64,6 +64,7 @@ const encoder4 = new Ddu64(undefined, undefined, {
|
|
|
64
64
|
const text = "안녕하세요";
|
|
65
65
|
const encoded = encoder1.encode(text);
|
|
66
66
|
const decoded = encoder1.decode(encoded);
|
|
67
|
+
const decodedBuffer = encoder1.decodeToBuffer(encoded);
|
|
67
68
|
```
|
|
68
69
|
|
|
69
70
|
### 커스텀 Charset 사용
|
|
@@ -82,4 +83,47 @@ const encoder = new Ddu64(koreanChars, "뭐");
|
|
|
82
83
|
const text = "안녕하세요12";
|
|
83
84
|
const encoded = encoder.encode(text);
|
|
84
85
|
const decoded = encoder.decode(encoded);
|
|
86
|
+
const decodedBuffer = encoder.decodeToBuffer(encoded);
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## API
|
|
90
|
+
|
|
91
|
+
### `new Ddu64(dduChar?, paddingChar?, options?)`
|
|
92
|
+
|
|
93
|
+
인코더 인스턴스를 생성합니다.
|
|
94
|
+
|
|
95
|
+
**Parameters:**
|
|
96
|
+
- `dduChar` (string | string[]): charset 문자열 또는 배열
|
|
97
|
+
- `paddingChar` (string): 패딩 문자
|
|
98
|
+
- `options` (DduOptions): 옵션 객체
|
|
99
|
+
- `dduSetSymbol`: 미리 정의된 charset 사용
|
|
100
|
+
- `encoding`: Buffer encoding (기본값: 'utf-8')
|
|
101
|
+
- `usePowerOfTwo`: 2의 제곱수 강제 여부
|
|
102
|
+
- `useBuildErrorReturn`: 에러 발생 시 throw 여부
|
|
103
|
+
|
|
104
|
+
### `encode(data: string | Buffer): string`
|
|
105
|
+
|
|
106
|
+
데이터를 인코딩
|
|
107
|
+
|
|
108
|
+
### `decode(encoded: string): string`
|
|
109
|
+
|
|
110
|
+
인코딩된 문자열을 디코딩
|
|
111
|
+
|
|
112
|
+
### `decodeToBuffer(encoded: string): Buffer`
|
|
113
|
+
|
|
114
|
+
인코딩된 문자열을 Buffer로 직접 디코딩
|
|
115
|
+
|
|
116
|
+
### `getCharSetInfo()`
|
|
117
|
+
|
|
118
|
+
현재 charset 정보를 반환
|
|
119
|
+
|
|
120
|
+
```typescript
|
|
121
|
+
{
|
|
122
|
+
charSet: string[];
|
|
123
|
+
paddingChar: string;
|
|
124
|
+
charLength: number;
|
|
125
|
+
bitLength: number;
|
|
126
|
+
usePowerOfTwo: boolean;
|
|
127
|
+
encoding: BufferEncoding;
|
|
128
|
+
}
|
|
85
129
|
```
|
|
@@ -1,38 +1,27 @@
|
|
|
1
1
|
import { DduOptions, BufferToDduBinaryResult } from "../types";
|
|
2
2
|
export declare abstract class BaseDdu {
|
|
3
3
|
protected readonly defaultEncoding: BufferEncoding;
|
|
4
|
-
/**
|
|
5
|
-
* 이진수 변환 룩업 테이블 (0-255 -> 8비트 이진 문자열)
|
|
6
|
-
*/
|
|
7
4
|
protected readonly binaryLookup: string[];
|
|
8
|
-
/**
|
|
9
|
-
* 정규표현식 특수문자 이스케이프
|
|
10
|
-
*/
|
|
11
5
|
protected escapeRegExp(str: string): string;
|
|
12
|
-
/**
|
|
13
|
-
* 문자열을 지정된 길이로 분할하는 제너레이터
|
|
14
|
-
*/
|
|
15
6
|
protected splitString(s: string, length: number): Generator<string>;
|
|
16
|
-
/**
|
|
17
|
-
* 2의 거듭제곱 길이 계산
|
|
18
|
-
*/
|
|
19
7
|
protected getLargestPowerOfTwo(n: number): number;
|
|
20
|
-
/**
|
|
21
|
-
* 2의 거듭제곱 지수 계산
|
|
22
|
-
*/
|
|
23
8
|
protected getLargestPowerOfTwoExponent(n: number): number;
|
|
24
|
-
/**
|
|
25
|
-
* 비트 길이 계산
|
|
26
|
-
*/
|
|
27
9
|
protected getBitLength(setLength: number): number;
|
|
28
|
-
/**
|
|
29
|
-
* Buffer를 DDU Binary 배열로 변환
|
|
30
|
-
*/
|
|
31
10
|
protected bufferToDduBinary(input: Buffer, bitLength: number): BufferToDduBinaryResult;
|
|
32
|
-
/**
|
|
33
|
-
* DDU Binary를 Buffer로 변환
|
|
34
|
-
*/
|
|
35
11
|
protected dduBinaryToBuffer(decodedBin: string, paddingBits: number): Buffer;
|
|
36
12
|
abstract encode(input: Buffer | string, options?: DduOptions): string;
|
|
13
|
+
abstract decodeToBuffer(input: string, options?: DduOptions): Buffer;
|
|
37
14
|
abstract decode(input: string, options?: DduOptions): string;
|
|
15
|
+
/**
|
|
16
|
+
* 테스트 및 디버깅용 추상 메서드
|
|
17
|
+
* 구현 클래스의 내부 상태 정보를 반환
|
|
18
|
+
*/
|
|
19
|
+
abstract getCharSetInfo(): {
|
|
20
|
+
charSet: string[];
|
|
21
|
+
paddingChar: string;
|
|
22
|
+
charLength: number;
|
|
23
|
+
bitLength: number;
|
|
24
|
+
usePowerOfTwo: boolean;
|
|
25
|
+
encoding: BufferEncoding;
|
|
26
|
+
};
|
|
38
27
|
}
|
package/dist/cjs/base/BaseDdu.js
CHANGED
|
@@ -4,46 +4,25 @@ exports.BaseDdu = void 0;
|
|
|
4
4
|
class BaseDdu {
|
|
5
5
|
constructor() {
|
|
6
6
|
this.defaultEncoding = "utf-8";
|
|
7
|
-
/**
|
|
8
|
-
* 이진수 변환 룩업 테이블 (0-255 -> 8비트 이진 문자열)
|
|
9
|
-
*/
|
|
10
7
|
this.binaryLookup = Array.from({ length: 256 }, (_, i) => i.toString(2).padStart(8, "0"));
|
|
11
8
|
}
|
|
12
|
-
/**
|
|
13
|
-
* 정규표현식 특수문자 이스케이프
|
|
14
|
-
*/
|
|
15
9
|
escapeRegExp(str) {
|
|
16
10
|
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
17
11
|
}
|
|
18
|
-
/**
|
|
19
|
-
* 문자열을 지정된 길이로 분할하는 제너레이터
|
|
20
|
-
*/
|
|
21
12
|
*splitString(s, length) {
|
|
22
13
|
for (let i = 0; i < s.length; i += length) {
|
|
23
14
|
yield s.slice(i, Math.min(i + length, s.length));
|
|
24
15
|
}
|
|
25
16
|
}
|
|
26
|
-
/**
|
|
27
|
-
* 2의 거듭제곱 길이 계산
|
|
28
|
-
*/
|
|
29
17
|
getLargestPowerOfTwo(n) {
|
|
30
18
|
return Math.pow(2, Math.floor(Math.log2(n)));
|
|
31
19
|
}
|
|
32
|
-
/**
|
|
33
|
-
* 2의 거듭제곱 지수 계산
|
|
34
|
-
*/
|
|
35
20
|
getLargestPowerOfTwoExponent(n) {
|
|
36
21
|
return Math.floor(Math.log2(n));
|
|
37
22
|
}
|
|
38
|
-
/**
|
|
39
|
-
* 비트 길이 계산
|
|
40
|
-
*/
|
|
41
23
|
getBitLength(setLength) {
|
|
42
24
|
return Math.ceil(Math.log2(setLength));
|
|
43
25
|
}
|
|
44
|
-
/**
|
|
45
|
-
* Buffer를 DDU Binary 배열로 변환
|
|
46
|
-
*/
|
|
47
26
|
bufferToDduBinary(input, bitLength) {
|
|
48
27
|
// 성능 최적화: reduce 대신 for loop + join 사용
|
|
49
28
|
if (input.length === 0) {
|
|
@@ -61,9 +40,6 @@ class BaseDdu {
|
|
|
61
40
|
}
|
|
62
41
|
return { dduBinary, padding };
|
|
63
42
|
}
|
|
64
|
-
/**
|
|
65
|
-
* DDU Binary를 Buffer로 변환
|
|
66
|
-
*/
|
|
67
43
|
dduBinaryToBuffer(decodedBin, paddingBits) {
|
|
68
44
|
if (paddingBits > 0) {
|
|
69
45
|
decodedBin = decodedBin.slice(0, -paddingBits);
|
|
@@ -10,12 +10,30 @@ export declare class Ddu64 extends BaseDdu {
|
|
|
10
10
|
protected readonly dduBinaryLookup: Map<string, number>;
|
|
11
11
|
private readonly isPredefinedCharSet;
|
|
12
12
|
private readonly effectiveBitLength;
|
|
13
|
+
private readonly maxBinaryValue;
|
|
13
14
|
private readonly binaryChunkToIntFn;
|
|
14
15
|
private readonly indexToBinaryCache;
|
|
15
16
|
constructor(dduChar?: string[] | string, paddingChar?: string, dduOptions?: DduConstructorOptions);
|
|
16
17
|
private normalizeCharSet;
|
|
18
|
+
private resolveInitialCharSet;
|
|
19
|
+
private getFallbackCharSet;
|
|
20
|
+
private shouldUsePowerOfTwo;
|
|
21
|
+
private getCharSetOrThrow;
|
|
17
22
|
private getBinaryFromIndex;
|
|
18
23
|
private validateCombinationDuplicates;
|
|
19
24
|
encode(input: Buffer | string, _options?: DduOptions): string;
|
|
25
|
+
decodeToBuffer(input: string, _options?: DduOptions): Buffer;
|
|
20
26
|
decode(input: string, _options?: DduOptions): string;
|
|
27
|
+
/**
|
|
28
|
+
* 테스트 및 디버깅용 getter 메서드
|
|
29
|
+
* 인코더의 내부 상태 정보를 반환
|
|
30
|
+
*/
|
|
31
|
+
getCharSetInfo(): {
|
|
32
|
+
charSet: string[];
|
|
33
|
+
paddingChar: string;
|
|
34
|
+
charLength: number;
|
|
35
|
+
bitLength: number;
|
|
36
|
+
usePowerOfTwo: boolean;
|
|
37
|
+
encoding: BufferEncoding;
|
|
38
|
+
};
|
|
21
39
|
}
|