asterix-parser 1.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/LICENSE +21 -0
- package/README.md +36 -0
- package/build/src/main/app.d.ts +8 -0
- package/build/src/main/app.js +66 -0
- package/build/src/main/data/uap/cat021.d.ts +6 -0
- package/build/src/main/data/uap/cat021.js +216 -0
- package/build/src/main/util/common.d.ts +27 -0
- package/build/src/main/util/common.js +79 -0
- package/build/src/main/util/preprocess.d.ts +33 -0
- package/build/src/main/util/preprocess.js +82 -0
- package/build/src/main/util/process/cat021.d.ts +13 -0
- package/build/src/main/util/process/cat021.js +1785 -0
- package/build/src/main/util/varlen/cat021.d.ts +9 -0
- package/build/src/main/util/varlen/cat021.js +235 -0
- package/build/src/test/app.test.d.ts +1 -0
- package/build/src/test/app.test.js +14 -0
- package/jest.config.js +9 -0
- package/package.json +43 -0
- package/tsconfig.json +15 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CAT 021의 가변 데이터 길이
|
|
3
|
+
* @param bitArr 비트 데이터
|
|
4
|
+
* @param recordIndex record 인덱스
|
|
5
|
+
* @param dataItem 데이터 아이템 이름
|
|
6
|
+
* @returns 각 데이터 아이템의 길이
|
|
7
|
+
*/
|
|
8
|
+
declare const cat021VarLen: (bitArr: Uint8Array, recordIndex: number, dataItem: string) => number;
|
|
9
|
+
export { cat021VarLen };
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.cat021VarLen = void 0;
|
|
4
|
+
const preprocess_1 = require("../preprocess");
|
|
5
|
+
const common_1 = require("../common");
|
|
6
|
+
/**
|
|
7
|
+
* CAT 021의 가변 데이터 길이
|
|
8
|
+
* @param bitArr 비트 데이터
|
|
9
|
+
* @param recordIndex record 인덱스
|
|
10
|
+
* @param dataItem 데이터 아이템 이름
|
|
11
|
+
* @returns 각 데이터 아이템의 길이
|
|
12
|
+
*/
|
|
13
|
+
const cat021VarLen = (bitArr, recordIndex, dataItem) => {
|
|
14
|
+
switch (dataItem) {
|
|
15
|
+
case "di040":
|
|
16
|
+
case "di090":
|
|
17
|
+
case "di271":
|
|
18
|
+
return checkLastBit(bitArr, recordIndex);
|
|
19
|
+
case "di220":
|
|
20
|
+
return di220Len(bitArr, recordIndex);
|
|
21
|
+
case "di110":
|
|
22
|
+
return di110Len(bitArr, recordIndex);
|
|
23
|
+
case "di250":
|
|
24
|
+
return di250Len(bitArr, recordIndex);
|
|
25
|
+
case "di295":
|
|
26
|
+
return di295Len(bitArr, recordIndex);
|
|
27
|
+
case "SP":
|
|
28
|
+
case "RE":
|
|
29
|
+
return spAndReLen(bitArr, recordIndex);
|
|
30
|
+
default:
|
|
31
|
+
return 0;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
exports.cat021VarLen = cat021VarLen;
|
|
35
|
+
/**
|
|
36
|
+
* 마지막 비트를 보고 추가 확장이 있는지 판단
|
|
37
|
+
* CAT 021: 040, 090
|
|
38
|
+
* @param bitArr 바이트 값
|
|
39
|
+
* @param recordIndex record 시작 인덱스
|
|
40
|
+
* @returns 데이터 길이
|
|
41
|
+
*/
|
|
42
|
+
const checkLastBit = (bitArr, recordIndex) => {
|
|
43
|
+
// octet 개수
|
|
44
|
+
let octetCount = 0;
|
|
45
|
+
// 추가 확장 유무
|
|
46
|
+
let hasExtension = true;
|
|
47
|
+
while (hasExtension) {
|
|
48
|
+
const currentByte = bitArr[recordIndex++];
|
|
49
|
+
hasExtension = (currentByte & 1) != 0;
|
|
50
|
+
octetCount++;
|
|
51
|
+
}
|
|
52
|
+
return octetCount;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Primary Subfield를 통해 특정 Subfield가 추가
|
|
56
|
+
* Primary Subfield 최대 1개
|
|
57
|
+
* CAT 021: 220
|
|
58
|
+
* @param bitArr 바이트 값
|
|
59
|
+
* @param recordIndex record 시작 인덱스
|
|
60
|
+
* @returns 데이터 길이
|
|
61
|
+
*/
|
|
62
|
+
const di220Len = (bitArr, recordIndex) => {
|
|
63
|
+
const { bits, headerLen } = (0, preprocess_1.parseIndicator)(bitArr, recordIndex);
|
|
64
|
+
let diLength = headerLen;
|
|
65
|
+
if ((0, common_1.isBitSet)(bits, 1, headerLen)) {
|
|
66
|
+
// WS
|
|
67
|
+
diLength += 2;
|
|
68
|
+
}
|
|
69
|
+
if ((0, common_1.isBitSet)(bits, 2, headerLen)) {
|
|
70
|
+
// WD
|
|
71
|
+
diLength += 2;
|
|
72
|
+
}
|
|
73
|
+
if ((0, common_1.isBitSet)(bits, 3, headerLen)) {
|
|
74
|
+
// TMP
|
|
75
|
+
diLength += 2;
|
|
76
|
+
}
|
|
77
|
+
if ((0, common_1.isBitSet)(bits, 4, headerLen)) {
|
|
78
|
+
// TRB
|
|
79
|
+
diLength += 1;
|
|
80
|
+
}
|
|
81
|
+
return diLength;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Primary Subfield를 통해 특정 Subfield가 추가
|
|
85
|
+
* Primary Subfield 최대 1개
|
|
86
|
+
* CAT 021: 110
|
|
87
|
+
* @param bitArr 바이트 값
|
|
88
|
+
* @param recordIndex record 시작 인덱스
|
|
89
|
+
* @returns 데이터 길이
|
|
90
|
+
*/
|
|
91
|
+
const di110Len = (bitArr, recordIndex) => {
|
|
92
|
+
const { bits, headerLen } = (0, preprocess_1.parseIndicator)(bitArr, recordIndex);
|
|
93
|
+
// 헤더 길이
|
|
94
|
+
let diLength = headerLen;
|
|
95
|
+
// 실제 데이터 시작 위치
|
|
96
|
+
let dataStartIndex = recordIndex + headerLen;
|
|
97
|
+
if ((0, common_1.isBitSet)(bits, 1, headerLen)) {
|
|
98
|
+
// TIS
|
|
99
|
+
diLength += 1;
|
|
100
|
+
dataStartIndex += 1;
|
|
101
|
+
}
|
|
102
|
+
if ((0, common_1.isBitSet)(bits, 2, headerLen)) {
|
|
103
|
+
// TID
|
|
104
|
+
// 반복 횟수
|
|
105
|
+
const rep = bitArr[dataStartIndex];
|
|
106
|
+
diLength += (1 + (rep * 15));
|
|
107
|
+
}
|
|
108
|
+
return diLength;
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* 첫 rep 값으로 그 뒤의 8 octet이 반복
|
|
112
|
+
* CAT 021: 250
|
|
113
|
+
* @param bitArr 바이트 값
|
|
114
|
+
* @param recordIndex record 시작 인덱스
|
|
115
|
+
* @returns 데이터 길이
|
|
116
|
+
*/
|
|
117
|
+
const di250Len = (bitArr, recordIndex) => {
|
|
118
|
+
const rep = bitArr[recordIndex];
|
|
119
|
+
return 1 + (rep * 8);
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Primary Subfield를 통해 특정 Subfield가 추가
|
|
123
|
+
* Primary Subfield 최대 4개
|
|
124
|
+
* CAT 021: 295
|
|
125
|
+
* @param bitArr 바이트 값
|
|
126
|
+
* @param recordIndex record 시작 인덱스
|
|
127
|
+
* @returns 데이터 길이
|
|
128
|
+
*/
|
|
129
|
+
const di295Len = (bitArr, recordIndex) => {
|
|
130
|
+
const { bits, headerLen } = (0, preprocess_1.parseIndicator)(bitArr, recordIndex);
|
|
131
|
+
let diLength = headerLen;
|
|
132
|
+
if ((0, common_1.isBitSet)(bits, 1, headerLen)) {
|
|
133
|
+
// AOS
|
|
134
|
+
diLength += 1;
|
|
135
|
+
}
|
|
136
|
+
if ((0, common_1.isBitSet)(bits, 2, headerLen)) {
|
|
137
|
+
// TRD
|
|
138
|
+
diLength += 1;
|
|
139
|
+
}
|
|
140
|
+
if ((0, common_1.isBitSet)(bits, 3, headerLen)) {
|
|
141
|
+
// M3A
|
|
142
|
+
diLength += 1;
|
|
143
|
+
}
|
|
144
|
+
if ((0, common_1.isBitSet)(bits, 4, headerLen)) {
|
|
145
|
+
// QI
|
|
146
|
+
diLength += 1;
|
|
147
|
+
}
|
|
148
|
+
if ((0, common_1.isBitSet)(bits, 5, headerLen)) {
|
|
149
|
+
// TI
|
|
150
|
+
diLength += 1;
|
|
151
|
+
}
|
|
152
|
+
if ((0, common_1.isBitSet)(bits, 6, headerLen)) {
|
|
153
|
+
// MAM
|
|
154
|
+
diLength += 1;
|
|
155
|
+
}
|
|
156
|
+
if ((0, common_1.isBitSet)(bits, 7, headerLen)) {
|
|
157
|
+
// GH
|
|
158
|
+
diLength += 1;
|
|
159
|
+
}
|
|
160
|
+
if ((0, common_1.isBitSet)(bits, 8, headerLen)) {
|
|
161
|
+
// FL
|
|
162
|
+
diLength += 1;
|
|
163
|
+
}
|
|
164
|
+
if ((0, common_1.isBitSet)(bits, 9, headerLen)) {
|
|
165
|
+
// ISA
|
|
166
|
+
diLength += 1;
|
|
167
|
+
}
|
|
168
|
+
if ((0, common_1.isBitSet)(bits, 10, headerLen)) {
|
|
169
|
+
// ISA
|
|
170
|
+
diLength += 1;
|
|
171
|
+
}
|
|
172
|
+
if ((0, common_1.isBitSet)(bits, 11, headerLen)) {
|
|
173
|
+
// AS
|
|
174
|
+
diLength += 1;
|
|
175
|
+
}
|
|
176
|
+
if ((0, common_1.isBitSet)(bits, 12, headerLen)) {
|
|
177
|
+
// TAS
|
|
178
|
+
diLength += 1;
|
|
179
|
+
}
|
|
180
|
+
if ((0, common_1.isBitSet)(bits, 13, headerLen)) {
|
|
181
|
+
// MH
|
|
182
|
+
diLength += 1;
|
|
183
|
+
}
|
|
184
|
+
if ((0, common_1.isBitSet)(bits, 14, headerLen)) {
|
|
185
|
+
// BVR
|
|
186
|
+
diLength += 1;
|
|
187
|
+
}
|
|
188
|
+
if ((0, common_1.isBitSet)(bits, 15, headerLen)) {
|
|
189
|
+
// GVR
|
|
190
|
+
diLength += 1;
|
|
191
|
+
}
|
|
192
|
+
if ((0, common_1.isBitSet)(bits, 16, headerLen)) {
|
|
193
|
+
// GV
|
|
194
|
+
diLength += 1;
|
|
195
|
+
}
|
|
196
|
+
if ((0, common_1.isBitSet)(bits, 17, headerLen)) {
|
|
197
|
+
// TAR
|
|
198
|
+
diLength += 1;
|
|
199
|
+
}
|
|
200
|
+
if ((0, common_1.isBitSet)(bits, 18, headerLen)) {
|
|
201
|
+
// TI
|
|
202
|
+
diLength += 1;
|
|
203
|
+
}
|
|
204
|
+
if ((0, common_1.isBitSet)(bits, 19, headerLen)) {
|
|
205
|
+
// TS
|
|
206
|
+
diLength += 1;
|
|
207
|
+
}
|
|
208
|
+
if ((0, common_1.isBitSet)(bits, 20, headerLen)) {
|
|
209
|
+
// MET
|
|
210
|
+
diLength += 1;
|
|
211
|
+
}
|
|
212
|
+
if ((0, common_1.isBitSet)(bits, 21, headerLen)) {
|
|
213
|
+
// ROA
|
|
214
|
+
diLength += 1;
|
|
215
|
+
}
|
|
216
|
+
if ((0, common_1.isBitSet)(bits, 22, headerLen)) {
|
|
217
|
+
// ARA
|
|
218
|
+
diLength += 1;
|
|
219
|
+
}
|
|
220
|
+
if ((0, common_1.isBitSet)(bits, 23, headerLen)) {
|
|
221
|
+
// SCC
|
|
222
|
+
diLength += 1;
|
|
223
|
+
}
|
|
224
|
+
return diLength;
|
|
225
|
+
};
|
|
226
|
+
/**
|
|
227
|
+
* 첫 번째 패킷 데이터를 보고 데이터 전체 길이를 유추
|
|
228
|
+
* SP, RE
|
|
229
|
+
* @param bitArr 바이트 값
|
|
230
|
+
* @param recordIndex record 시작 인덱스
|
|
231
|
+
* @returns 데이터 길이
|
|
232
|
+
*/
|
|
233
|
+
const spAndReLen = (bitArr, recordIndex) => {
|
|
234
|
+
return bitArr[recordIndex];
|
|
235
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const app_1 = require("../main/app");
|
|
4
|
+
test('parse test: record count', () => {
|
|
5
|
+
const records = (0, app_1.parse)("150006800101");
|
|
6
|
+
expect(records.length).toBe(1);
|
|
7
|
+
});
|
|
8
|
+
test('parse test: specific data item - data item 010', () => {
|
|
9
|
+
const records = (0, app_1.parse)("150006800101");
|
|
10
|
+
const sac = records[0]['021_010_SAC'];
|
|
11
|
+
const sic = records[0]['021_010_SIC'];
|
|
12
|
+
expect(sac).toBe(1);
|
|
13
|
+
expect(sic).toBe(1);
|
|
14
|
+
});
|
package/jest.config.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "asterix-parser",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/chung5072/asterix-validator"
|
|
7
|
+
},
|
|
8
|
+
"description": "asterix-validator를 활용한 Asterix 데이터 파싱 모듈",
|
|
9
|
+
"main": "./build/src/main/app.js",
|
|
10
|
+
"types": "./build/src/main/app.d.ts",
|
|
11
|
+
"files": [
|
|
12
|
+
"build",
|
|
13
|
+
"jest.config.js",
|
|
14
|
+
"LICENSE",
|
|
15
|
+
"package-lock.json",
|
|
16
|
+
"package.json",
|
|
17
|
+
"README.md",
|
|
18
|
+
"tsconfig.json"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"test": "jest",
|
|
22
|
+
"build": "tsc",
|
|
23
|
+
"start": "nodemon -e ts --ignore build/ --exec \"npm run build && node ./build/src/main/app.js\""
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"asterix",
|
|
27
|
+
"asterix-parser"
|
|
28
|
+
],
|
|
29
|
+
"author": "chung5072",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"type": "commonjs",
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/jest": "^30.0.0",
|
|
34
|
+
"@types/node": "^25.0.3",
|
|
35
|
+
"jest": "^30.2.0",
|
|
36
|
+
"nodemon": "^3.1.11",
|
|
37
|
+
"ts-jest": "^29.4.6",
|
|
38
|
+
"typescript": "^5.9.3"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"asterix-validator": "^1.0.9"
|
|
42
|
+
}
|
|
43
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2016",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"rootDir": "./",
|
|
6
|
+
"resolveJsonModule": true,
|
|
7
|
+
"outDir": "./build",
|
|
8
|
+
"declaration": true,
|
|
9
|
+
"emitDeclarationOnly": false,
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true,
|
|
12
|
+
"strict": true
|
|
13
|
+
},
|
|
14
|
+
"include": ["src/**/*"]
|
|
15
|
+
}
|