@ddunigma/node 2.0.0 → 2.0.2

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.
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Ddu64 = void 0;
4
- // Unified encoder (supports both fixed and variable length via usePowerOfTwo option)
5
4
  var Ddu64_1 = require("./Ddu64");
6
5
  Object.defineProperty(exports, "Ddu64", { enumerable: true, get: function () { return Ddu64_1.Ddu64; } });
@@ -1,4 +1,4 @@
1
- export type { DduOptions, BufferToDduBinaryResult, DduConstructorOptions, } from "./types";
1
+ export type { DduOptions, DduConstructorOptions, } from "./types";
2
2
  export { DduSetSymbol } from "./types";
3
3
  export { BaseDdu } from "./base";
4
4
  export { Ddu64 } from "./encoders";
package/dist/cjs/index.js CHANGED
@@ -1,12 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Ddu64 = exports.BaseDdu = exports.DduSetSymbol = void 0;
4
- // Export enums
5
4
  var types_1 = require("./types");
6
5
  Object.defineProperty(exports, "DduSetSymbol", { enumerable: true, get: function () { return types_1.DduSetSymbol; } });
7
- // Export base classes
8
6
  var base_1 = require("./base");
9
7
  Object.defineProperty(exports, "BaseDdu", { enumerable: true, get: function () { return base_1.BaseDdu; } });
10
- // Export encoders
11
8
  var encoders_1 = require("./encoders");
12
9
  Object.defineProperty(exports, "Ddu64", { enumerable: true, get: function () { return encoders_1.Ddu64; } });
@@ -3,10 +3,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.dduDefaultConstructorOptions = void 0;
4
4
  const DduEnums_1 = require("./DduEnums");
5
5
  const dduDefaultConstructorOptions = {
6
+ /** 기본 charset: DDU (한글 + 특수문자) */
6
7
  dduSetSymbol: DduEnums_1.DduSetSymbol.DDU,
8
+ /** 2의 제곱수 강제 */
7
9
  usePowerOfTwo: true,
10
+ /** 필요 문자 수: 8개 */
8
11
  requiredLength: 8,
12
+ /** 비트 길이: 3 (2^3 = 8) */
9
13
  bitLength: 3,
14
+ /** 빌드 에러 시 throw하지 않음 */
10
15
  useBuildErrorReturn: false,
11
16
  };
12
17
  exports.dduDefaultConstructorOptions = dduDefaultConstructorOptions;
@@ -1,24 +1,39 @@
1
1
  import { DduSetSymbol } from "./DduEnums";
2
2
  export interface CharSetConfig {
3
+ /** charset 식별 심볼 */
3
4
  symbol: DduSetSymbol;
5
+ /** 인코딩에 사용할 문자 배열 */
4
6
  charSet: string[];
7
+ /** 최대 필요 문자 수 */
5
8
  maxRequiredLength: number;
9
+ /** 비트 길이 (log2) */
6
10
  bitLength: number;
11
+ /** 패딩 문자 */
7
12
  paddingChar: string;
8
13
  }
9
14
  export interface DduOptions {
15
+ /** 압축 사용 여부 (zlib deflate) */
16
+ compress?: boolean;
17
+ /** 최대 디코딩 바이트 수 (Zip Bomb 방어) */
18
+ maxDecodedBytes?: number;
19
+ /** 최대 압축해제 바이트 수 (Zip Bomb 방어) */
20
+ maxDecompressedBytes?: number;
10
21
  }
11
- export interface DduConstructorOptions {
22
+ export interface DduConstructorOptions extends DduOptions {
23
+ /** 미리 정의된 charset 심볼 */
12
24
  dduSetSymbol?: DduSetSymbol;
25
+ /** 커스텀 charset 문자 배열 또는 문자열 */
13
26
  dduChar?: string[] | string;
27
+ /** 패딩 문자 */
14
28
  paddingChar?: string;
29
+ /** 필요 문자 수 */
15
30
  requiredLength?: number;
31
+ /** 비트 길이 */
16
32
  bitLength?: number;
33
+ /** 2의 제곱수 강제 여부 */
17
34
  usePowerOfTwo?: boolean;
35
+ /** 빌드 에러 시 throw 여부 */
18
36
  useBuildErrorReturn?: boolean;
37
+ /** Buffer 인코딩 방식 */
19
38
  encoding?: BufferEncoding;
20
39
  }
21
- export interface BufferToDduBinaryResult {
22
- dduBinary: string[];
23
- padding: number;
24
- }
@@ -1,20 +1,46 @@
1
- import { DduOptions, BufferToDduBinaryResult } from "../types";
1
+ import { DduOptions } from "../types";
2
2
  export declare abstract class BaseDdu {
3
3
  protected readonly defaultEncoding: BufferEncoding;
4
- protected readonly binaryLookup: string[];
5
- protected escapeRegExp(str: string): string;
6
- protected splitString(s: string, length: number): Generator<string>;
7
- protected getLargestPowerOfTwo(n: number): number;
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
+ */
8
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
+ */
9
19
  protected getBitLength(setLength: number): number;
10
- protected bufferToDduBinary(input: Buffer, bitLength: number): BufferToDduBinaryResult;
11
- protected dduBinaryToBuffer(decodedBin: string, paddingBits: number): Buffer;
20
+ /**
21
+ * 입력 데이터를 인코딩합니다.
22
+ * @param input - 인코딩할 문자열 또는 Buffer
23
+ * @param options - 인코딩 옵션
24
+ * @returns 인코딩된 문자열
25
+ */
12
26
  abstract encode(input: Buffer | string, options?: DduOptions): string;
27
+ /**
28
+ * 인코딩된 문자열을 Buffer로 디코딩합니다.
29
+ * @param input - 인코딩된 문자열
30
+ * @param options - 디코딩 옵션
31
+ * @returns 디코딩된 Buffer
32
+ */
13
33
  abstract decodeToBuffer(input: string, options?: DduOptions): Buffer;
34
+ /**
35
+ * 인코딩된 문자열을 원본 문자열로 디코딩합니다.
36
+ * @param input - 인코딩된 문자열
37
+ * @param options - 디코딩 옵션
38
+ * @returns 디코딩된 문자열
39
+ */
14
40
  abstract decode(input: string, options?: DduOptions): string;
15
41
  /**
16
- * 테스트 디버깅용 추상 메서드
17
- * 구현 클래스의 내부 상태 정보를 반환
42
+ * 현재 인코더의 charset 정보를 반환합니다.
43
+ * @returns charset 설정 정보 객체
18
44
  */
19
45
  abstract getCharSetInfo(): {
20
46
  charSet: string[];
@@ -1,48 +1,23 @@
1
1
  export class BaseDdu {
2
2
  defaultEncoding = "utf-8";
3
- binaryLookup = Array.from({ length: 256 }, (_, i) => i.toString(2).padStart(8, "0"));
4
- escapeRegExp(str) {
5
- return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
6
- }
7
- *splitString(s, length) {
8
- for (let i = 0; i < s.length; i += length) {
9
- yield s.slice(i, Math.min(i + length, s.length));
10
- }
11
- }
12
- getLargestPowerOfTwo(n) {
13
- return 2 ** Math.floor(Math.log2(n));
14
- }
3
+ /**
4
+ * 주어진 숫자보다 작거나 같은 가장 큰 2의 제곱수의 지수를 반환합니다.
5
+ * @param n - 대상 숫자
6
+ * @returns 2의 제곱수 지수 (예: n=8 → 3, n=64 → 6)
7
+ * @example getLargestPowerOfTwoExponent(8) // 3
8
+ * @example getLargestPowerOfTwoExponent(100) // 6
9
+ */
15
10
  getLargestPowerOfTwoExponent(n) {
16
11
  return Math.floor(Math.log2(n));
17
12
  }
13
+ /**
14
+ * charset 크기에 필요한 비트 길이를 계산합니다.
15
+ * @param setLength - charset 문자 수
16
+ * @returns 필요한 비트 수
17
+ * @example getBitLength(64) // 6
18
+ * @example getBitLength(100) // 7
19
+ */
18
20
  getBitLength(setLength) {
19
21
  return Math.ceil(Math.log2(setLength));
20
22
  }
21
- bufferToDduBinary(input, bitLength) {
22
- // 성능 최적화: reduce 대신 for loop + join 사용
23
- if (input.length === 0) {
24
- return { dduBinary: [], padding: 0 };
25
- }
26
- const binaryParts = new Array(input.length);
27
- for (let i = 0; i < input.length; i++) {
28
- binaryParts[i] = this.binaryLookup[input[i]];
29
- }
30
- const encodedBin = binaryParts.join("");
31
- const dduBinary = Array.from(this.splitString(encodedBin, bitLength));
32
- const padding = bitLength - dduBinary[dduBinary.length - 1].length;
33
- if (padding > 0) {
34
- dduBinary[dduBinary.length - 1] += "0".repeat(padding);
35
- }
36
- return { dduBinary, padding };
37
- }
38
- dduBinaryToBuffer(decodedBin, paddingBits) {
39
- if (paddingBits > 0) {
40
- decodedBin = decodedBin.slice(0, -paddingBits);
41
- }
42
- const buffer = [];
43
- for (let i = 0; i < decodedBin.length; i += 8) {
44
- buffer.push(parseInt(decodedBin.slice(i, i + 8), 2));
45
- }
46
- return Buffer.from(buffer);
47
- }
48
23
  }
@@ -1 +1 @@
1
- export { BaseDdu } from "./BaseDdu";
1
+ export { BaseDdu } from "./BaseDdu.js";
@@ -1,4 +1,18 @@
1
1
  import { CharSetConfig, DduSetSymbol } from "../types";
2
+ /**
3
+ * 심볼에 해당하는 charset 설정을 반환합니다.
4
+ * @param symbol - charset 심볼
5
+ * @returns CharSetConfig 또는 undefined
6
+ */
2
7
  export declare function getCharSet(symbol: DduSetSymbol): CharSetConfig | undefined;
8
+ /**
9
+ * 모든 사용 가능한 charset 심볼 목록을 반환합니다.
10
+ * @returns DduSetSymbol 배열
11
+ */
3
12
  export declare function getAllSymbols(): DduSetSymbol[];
13
+ /**
14
+ * 해당 심볼의 charset이 존재하는지 확인합니다.
15
+ * @param symbol - 확인할 charset 심볼
16
+ * @returns 존재 여부
17
+ */
4
18
  export declare function hasCharSet(symbol: DduSetSymbol): boolean;