adofai 2.9.14 → 2.9.17
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 +2 -95
- package/dist/src/effectProcessor.js +2 -38
- package/dist/src/filter/effectProcessor.d.ts +32 -0
- package/dist/src/filter/effectProcessor.js +54 -0
- package/dist/src/filter/presets.d.ts +10 -0
- package/dist/src/filter/presets.js +75 -0
- package/dist/src/format.js +1 -4
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.js +5 -49
- package/dist/src/parser/ArrayBufferParser.js +9 -20
- package/dist/src/parser/BufferParser.js +9 -20
- package/dist/src/parser/BufferParserX.d.ts +23 -0
- package/dist/src/parser/BufferParserX.js +77 -0
- package/dist/src/parser/FileParser.d.ts +9 -0
- package/dist/src/parser/FileParser.js +30 -0
- package/dist/src/parser/Parser.js +1 -4
- package/dist/src/parser/StringParser.d.ts +50 -0
- package/dist/src/parser/StringParser.js +4 -9
- package/dist/src/parser/index.js +3 -9
- package/dist/src/parser.js +6 -15
- package/dist/src/pathdata/index.d.ts +8 -0
- package/dist/src/pathdata/index.js +6 -0
- package/dist/src/pathdata.js +1 -4
- package/dist/src/presets.js +5 -9
- package/dist/src/structure/Level.js +15 -56
- package/dist/src/structure/format.d.ts +8 -0
- package/dist/src/structure/format.js +44 -0
- package/dist/src/structure/interfaces.js +1 -3
- package/dist/src/structure.js +2 -5
- package/dist/umd/index.js +2 -0
- package/dist/umd/index.js.LICENSE.txt +1 -0
- package/package.json +8 -5
- package/dist/src/effectProcessor.js.map +0 -1
- package/dist/src/format.js.map +0 -1
- package/dist/src/index.js.map +0 -1
- package/dist/src/parser/ArrayBufferParser.js.map +0 -1
- package/dist/src/parser/BufferParser.js.map +0 -1
- package/dist/src/parser/Parser.js.map +0 -1
- package/dist/src/parser/StringParser.js.map +0 -1
- package/dist/src/parser/index.js.map +0 -1
- package/dist/src/parser.js.map +0 -1
- package/dist/src/pathdata.js.map +0 -1
- package/dist/src/presets.js.map +0 -1
- package/dist/src/structure/Level.js.map +0 -1
- package/dist/src/structure/interfaces.js.map +0 -1
- package/dist/src/structure.js.map +0 -1
package/README.md
CHANGED
|
@@ -104,102 +104,9 @@ fs.writeFileSync('output.adofai',content)
|
|
|
104
104
|
See interfaces to see all data.
|
|
105
105
|
|
|
106
106
|
```ts
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
[key: string]: any;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
export interface LevelOptions {
|
|
113
|
-
pathData?: string;
|
|
114
|
-
angleData?: number[];
|
|
115
|
-
actions: AdofaiEvent[];
|
|
116
|
-
settings: Record<string, any>;
|
|
117
|
-
decorations: AdofaiEvent[];
|
|
118
|
-
[key: string]: any;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
export interface EventCallback {
|
|
122
|
-
guid: string;
|
|
123
|
-
callback: Function;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export interface GuidCallback {
|
|
127
|
-
eventName: string;
|
|
128
|
-
callback: Function;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export interface Tile {
|
|
132
|
-
direction?: number;
|
|
133
|
-
angle?: number;
|
|
134
|
-
actions: AdofaiEvent[];
|
|
135
|
-
addDecorations?: AdofaiEvent[];
|
|
136
|
-
_lastdir?: number;
|
|
137
|
-
twirl?: number;
|
|
138
|
-
position?: number[];
|
|
139
|
-
extraProps?: Record<string, any>;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export interface ParseProvider {
|
|
143
|
-
parse(t: string): LevelOptions;
|
|
144
|
-
}
|
|
145
|
-
```
|
|
107
|
+
//Get AngleDatas:
|
|
108
|
+
const angleDatas = file.angleData;
|
|
146
109
|
|
|
147
|
-
For Level:
|
|
148
110
|
|
|
149
|
-
```ts
|
|
150
|
-
import { AdofaiEvent, LevelOptions, Tile, ParseProvider } from './interfaces';
|
|
151
|
-
export declare class Level {
|
|
152
|
-
private _events;
|
|
153
|
-
private guidCallbacks;
|
|
154
|
-
private guidCounter;
|
|
155
|
-
private _options;
|
|
156
|
-
private _provider?;
|
|
157
|
-
angleData: number[];
|
|
158
|
-
actions: AdofaiEvent[];
|
|
159
|
-
settings: Record<string, any>;
|
|
160
|
-
__decorations: AdofaiEvent[];
|
|
161
|
-
tiles: Tile[];
|
|
162
|
-
private _angleDir;
|
|
163
|
-
private _twirlCount;
|
|
164
|
-
constructor(opt: string | LevelOptions, provider?: ParseProvider);
|
|
165
|
-
generateGUID(): string;
|
|
166
|
-
load(): Promise<boolean>;
|
|
167
|
-
on(eventName: string, callback: Function): string;
|
|
168
|
-
trigger(eventName: string, data: any): void;
|
|
169
|
-
off(guid: string): void;
|
|
170
|
-
private _createArray;
|
|
171
|
-
private _changeAngle;
|
|
172
|
-
private _parsechangedAngle;
|
|
173
|
-
private _filterByFloor;
|
|
174
|
-
private _flattenAngleDatas;
|
|
175
|
-
private _flattenActionsWithFloor;
|
|
176
|
-
private _filterByFloorwithDeco;
|
|
177
|
-
private _flattenDecorationsWithFloor;
|
|
178
|
-
private _parseAngle;
|
|
179
|
-
filterActionsByEventType(en: string): {
|
|
180
|
-
index: number;
|
|
181
|
-
action: AdofaiEvent;
|
|
182
|
-
}[];
|
|
183
|
-
getActionsByIndex(en: string, index: number): {
|
|
184
|
-
count: number;
|
|
185
|
-
actions: AdofaiEvent[];
|
|
186
|
-
};
|
|
187
|
-
calculateTileCoordinates(): void;
|
|
188
|
-
floorOperation(info?: {
|
|
189
|
-
type: 'append' | 'insert' | 'delete';
|
|
190
|
-
direction: number;
|
|
191
|
-
id?: number;
|
|
192
|
-
}): void;
|
|
193
|
-
appendFloor(args: {
|
|
194
|
-
direction: number;
|
|
195
|
-
}): void;
|
|
196
|
-
clearDeco(): boolean;
|
|
197
|
-
clearEffect(presetName: string): void;
|
|
198
|
-
clearEvent(preset: {
|
|
199
|
-
type: string;
|
|
200
|
-
events: string[];
|
|
201
|
-
}): void;
|
|
202
|
-
export(type: 'string' | 'object', indent?: number, useAdofaiStyle?: boolean): string | Record<string, any>;
|
|
203
|
-
}
|
|
204
111
|
|
|
205
112
|
```
|
|
@@ -1,39 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
const presets = __importStar(require("./presets"));
|
|
1
|
+
import * as presets from './presets';
|
|
37
2
|
/**
|
|
38
3
|
* @param {Array} tiles ADOFAI Tiles from ADOFAI.Level
|
|
39
4
|
* @returns {Array} new Tiles
|
|
@@ -86,5 +51,4 @@ const effectProcessor = {
|
|
|
86
51
|
clearEvents,
|
|
87
52
|
keepEvents
|
|
88
53
|
};
|
|
89
|
-
|
|
90
|
-
//# sourceMappingURL=effectProcessor.js.map
|
|
54
|
+
export default effectProcessor;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
interface Tile {
|
|
2
|
+
addDecorations?: any[];
|
|
3
|
+
actions?: Action[];
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
}
|
|
6
|
+
interface Action {
|
|
7
|
+
eventType: string;
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* @param {Array} tiles ADOFAI Tiles from ADOFAI.Level
|
|
12
|
+
* @returns {Array} new Tiles
|
|
13
|
+
*/
|
|
14
|
+
declare function clearDecorations(tiles: Tile[]): Tile[];
|
|
15
|
+
/**
|
|
16
|
+
* @param {Array} eventTypes Eventlist to remove
|
|
17
|
+
* @param {Array} tiles ADOFAI Tiles from ADOFAI.Level
|
|
18
|
+
* @returns {Array} new Tiles
|
|
19
|
+
*/
|
|
20
|
+
declare function clearEvents(eventTypes: string[], tiles: Tile[]): Tile[];
|
|
21
|
+
/**
|
|
22
|
+
* @param {Array} eventTypes Eventlist to keep
|
|
23
|
+
* @param {Array} tiles ADOFAI Tiles from ADOFAI.Level
|
|
24
|
+
* @returns {Array} new Tiles
|
|
25
|
+
*/
|
|
26
|
+
declare function keepEvents(eventTypes: string[], tiles: Tile[]): Tile[];
|
|
27
|
+
declare const effectProcessor: {
|
|
28
|
+
clearDecorations: typeof clearDecorations;
|
|
29
|
+
clearEvents: typeof clearEvents;
|
|
30
|
+
keepEvents: typeof keepEvents;
|
|
31
|
+
};
|
|
32
|
+
export default effectProcessor;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as presets from './presets';
|
|
2
|
+
/**
|
|
3
|
+
* @param {Array} tiles ADOFAI Tiles from ADOFAI.Level
|
|
4
|
+
* @returns {Array} new Tiles
|
|
5
|
+
*/
|
|
6
|
+
function clearDecorations(tiles) {
|
|
7
|
+
if (!Array.isArray(tiles)) {
|
|
8
|
+
throw new Error('Arguments are not supported.');
|
|
9
|
+
}
|
|
10
|
+
return tiles.map(tile => {
|
|
11
|
+
const newTile = Object.assign({}, tile);
|
|
12
|
+
if (newTile.hasOwnProperty('addDecorations')) {
|
|
13
|
+
newTile.addDecorations = [];
|
|
14
|
+
}
|
|
15
|
+
if (Array.isArray(newTile.actions)) {
|
|
16
|
+
newTile.actions = newTile.actions.filter(action => !presets.preset_inner_no_deco.events.includes(action.eventType));
|
|
17
|
+
}
|
|
18
|
+
return newTile;
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* @param {Array} eventTypes Eventlist to remove
|
|
23
|
+
* @param {Array} tiles ADOFAI Tiles from ADOFAI.Level
|
|
24
|
+
* @returns {Array} new Tiles
|
|
25
|
+
*/
|
|
26
|
+
function clearEvents(eventTypes, tiles) {
|
|
27
|
+
return tiles.map(tile => {
|
|
28
|
+
const newTile = Object.assign({}, tile);
|
|
29
|
+
if (Array.isArray(newTile.actions)) {
|
|
30
|
+
newTile.actions = newTile.actions.filter(action => !eventTypes.includes(action.eventType));
|
|
31
|
+
}
|
|
32
|
+
return newTile;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* @param {Array} eventTypes Eventlist to keep
|
|
37
|
+
* @param {Array} tiles ADOFAI Tiles from ADOFAI.Level
|
|
38
|
+
* @returns {Array} new Tiles
|
|
39
|
+
*/
|
|
40
|
+
function keepEvents(eventTypes, tiles) {
|
|
41
|
+
return tiles.map(tile => {
|
|
42
|
+
const newTile = Object.assign({}, tile);
|
|
43
|
+
if (Array.isArray(newTile.actions)) {
|
|
44
|
+
newTile.actions = newTile.actions.filter(action => eventTypes.includes(action.eventType));
|
|
45
|
+
}
|
|
46
|
+
return newTile;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
const effectProcessor = {
|
|
50
|
+
clearDecorations,
|
|
51
|
+
clearEvents,
|
|
52
|
+
keepEvents
|
|
53
|
+
};
|
|
54
|
+
export default effectProcessor;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface Preset {
|
|
2
|
+
type: 'include' | 'exclude' | "special";
|
|
3
|
+
events: string[];
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
}
|
|
6
|
+
export declare const preset_noeffect: Preset;
|
|
7
|
+
export declare const preset_noholds: Preset;
|
|
8
|
+
export declare const preset_nomovecamera: Preset;
|
|
9
|
+
export declare const preset_noeffect_completely: Preset;
|
|
10
|
+
export declare const preset_inner_no_deco: Preset;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export const preset_noeffect = {
|
|
2
|
+
type: 'exclude', events: [
|
|
3
|
+
'Flash',
|
|
4
|
+
'SetFilter',
|
|
5
|
+
'SetFilterAdvanced',
|
|
6
|
+
'HallOfMirrors',
|
|
7
|
+
'Bloom',
|
|
8
|
+
'ScalePlanets',
|
|
9
|
+
'ScreenTile',
|
|
10
|
+
'ScreenScroll',
|
|
11
|
+
'ShakeScreen'
|
|
12
|
+
]
|
|
13
|
+
};
|
|
14
|
+
export const preset_noholds = {
|
|
15
|
+
type: 'exclude', events: [
|
|
16
|
+
'Hold',
|
|
17
|
+
]
|
|
18
|
+
};
|
|
19
|
+
export const preset_nomovecamera = {
|
|
20
|
+
type: 'exclude', events: [
|
|
21
|
+
'MoveCamera',
|
|
22
|
+
]
|
|
23
|
+
};
|
|
24
|
+
export const preset_noeffect_completely = {
|
|
25
|
+
type: 'exclude', events: [
|
|
26
|
+
"AddDecoration",
|
|
27
|
+
"AddText",
|
|
28
|
+
"AddObject",
|
|
29
|
+
"Checkpoint",
|
|
30
|
+
"SetHitsound",
|
|
31
|
+
"PlaySound",
|
|
32
|
+
"SetPlanetRotation",
|
|
33
|
+
"ScalePlanets",
|
|
34
|
+
"ColorTrack",
|
|
35
|
+
"AnimateTrack",
|
|
36
|
+
"RecolorTrack",
|
|
37
|
+
"MoveTrack",
|
|
38
|
+
"PositionTrack",
|
|
39
|
+
"MoveDecorations",
|
|
40
|
+
"SetText",
|
|
41
|
+
"SetObject",
|
|
42
|
+
"SetDefaultText",
|
|
43
|
+
"CustomBackground",
|
|
44
|
+
"Flash",
|
|
45
|
+
"MoveCamera",
|
|
46
|
+
"SetFilter",
|
|
47
|
+
"HallOfMirrors",
|
|
48
|
+
"ShakeScreen",
|
|
49
|
+
"Bloom",
|
|
50
|
+
"ScreenTile",
|
|
51
|
+
"ScreenScroll",
|
|
52
|
+
"SetFrameRate",
|
|
53
|
+
"RepeatEvents",
|
|
54
|
+
"SetConditionalEvents",
|
|
55
|
+
"EditorComment",
|
|
56
|
+
"Bookmark",
|
|
57
|
+
"Hold",
|
|
58
|
+
"SetHoldSound",
|
|
59
|
+
//"MultiPlanet",
|
|
60
|
+
//"FreeRoam",
|
|
61
|
+
//"FreeRoamTwirl",
|
|
62
|
+
//"FreeRoamRemove",
|
|
63
|
+
"Hide",
|
|
64
|
+
"ScaleMargin",
|
|
65
|
+
"ScaleRadius"
|
|
66
|
+
]
|
|
67
|
+
};
|
|
68
|
+
export const preset_inner_no_deco = {
|
|
69
|
+
type: "special", events: [
|
|
70
|
+
"MoveDecorations",
|
|
71
|
+
"SetText",
|
|
72
|
+
"SetObject",
|
|
73
|
+
"SetDefaultText"
|
|
74
|
+
]
|
|
75
|
+
};
|
package/dist/src/format.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
1
|
/**
|
|
4
2
|
* @param {object} obj - JSON Object
|
|
5
3
|
* @param {number} indent - No usage
|
|
@@ -43,5 +41,4 @@ function formatAsSingleLine(obj) {
|
|
|
43
41
|
const entries = keys.map(key => JSON.stringify(key) + ': ' + formatAsSingleLine(obj[key])).join(', ');
|
|
44
42
|
return '{' + entries + '}';
|
|
45
43
|
}
|
|
46
|
-
|
|
47
|
-
//# sourceMappingURL=format.js.map
|
|
44
|
+
export default exportAsADOFAI;
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import pathData from './pathdata';
|
|
2
2
|
import * as Parsers from './parser';
|
|
3
3
|
import Level, * as Structure from './structure';
|
|
4
|
-
import * as Presets from './presets';
|
|
4
|
+
import * as Presets from './filter/presets';
|
|
5
5
|
export { pathData, Parsers, Level, Structure, Presets };
|
package/dist/src/index.js
CHANGED
|
@@ -1,49 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.Presets = exports.Structure = exports.Level = exports.Parsers = exports.pathData = void 0;
|
|
40
|
-
const pathdata_1 = __importDefault(require("./pathdata"));
|
|
41
|
-
exports.pathData = pathdata_1.default;
|
|
42
|
-
const Parsers = __importStar(require("./parser"));
|
|
43
|
-
exports.Parsers = Parsers;
|
|
44
|
-
const structure_1 = __importStar(require("./structure")), Structure = structure_1;
|
|
45
|
-
exports.Level = structure_1.default;
|
|
46
|
-
exports.Structure = Structure;
|
|
47
|
-
const Presets = __importStar(require("./presets"));
|
|
48
|
-
exports.Presets = Presets;
|
|
49
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import pathData from './pathdata';
|
|
2
|
+
import * as Parsers from './parser';
|
|
3
|
+
import Level, * as Structure from './structure';
|
|
4
|
+
import * as Presets from './filter/presets';
|
|
5
|
+
export { pathData, Parsers, Level, Structure, Presets };
|
|
@@ -1,38 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ArrayBufferParser = void 0;
|
|
7
|
-
exports.stripBOM = stripBOM;
|
|
8
|
-
exports.normalizeJsonArrayBuffer = normalizeJsonArrayBuffer;
|
|
9
|
-
exports.decodeStringFromUTF8BOM = decodeStringFromUTF8BOM;
|
|
10
|
-
const Parser_1 = __importDefault(require("./Parser"));
|
|
11
|
-
const StringParser_1 = __importDefault(require("./StringParser"));
|
|
1
|
+
import Parser from "./Parser";
|
|
2
|
+
import StringParser from "./StringParser";
|
|
12
3
|
const BOM = new Uint8Array([0xef, 0xbb, 0xbf]);
|
|
13
4
|
const COMMA = new Uint8Array([44]); // ASCII for ','
|
|
14
|
-
class ArrayBufferParser extends
|
|
5
|
+
export class ArrayBufferParser extends Parser {
|
|
15
6
|
parse(input) {
|
|
16
7
|
if (typeof input === "string") {
|
|
17
|
-
return
|
|
8
|
+
return StringParser.prototype.parse.call(StringParser.prototype, input);
|
|
18
9
|
}
|
|
19
10
|
else {
|
|
20
|
-
return
|
|
11
|
+
return StringParser.prototype.parse.call(StringParser.prototype, decodeStringFromUTF8BOM(normalizeJsonArrayBuffer(stripBOM(input))));
|
|
21
12
|
}
|
|
22
13
|
}
|
|
23
14
|
stringify(obj) {
|
|
24
15
|
return JSON.stringify(obj);
|
|
25
16
|
}
|
|
26
17
|
}
|
|
27
|
-
|
|
28
|
-
function stripBOM(buffer) {
|
|
18
|
+
export function stripBOM(buffer) {
|
|
29
19
|
const view = new Uint8Array(buffer);
|
|
30
20
|
if (view.length >= 3 && view[0] === BOM[0] && view[1] === BOM[1] && view[2] === BOM[2]) {
|
|
31
21
|
return buffer.slice(3);
|
|
32
22
|
}
|
|
33
23
|
return buffer;
|
|
34
24
|
}
|
|
35
|
-
function normalizeJsonArrayBuffer(buffer) {
|
|
25
|
+
export function normalizeJsonArrayBuffer(buffer) {
|
|
36
26
|
const view = new Uint8Array(buffer);
|
|
37
27
|
let builder = [];
|
|
38
28
|
let last = "other";
|
|
@@ -100,10 +90,9 @@ function normalizeJsonArrayBuffer(buffer) {
|
|
|
100
90
|
}
|
|
101
91
|
return result.buffer;
|
|
102
92
|
}
|
|
103
|
-
function decodeStringFromUTF8BOM(buffer) {
|
|
93
|
+
export function decodeStringFromUTF8BOM(buffer) {
|
|
104
94
|
const strippedBuffer = stripBOM(buffer);
|
|
105
95
|
const decoder = new TextDecoder('utf-8');
|
|
106
96
|
return decoder.decode(strippedBuffer);
|
|
107
97
|
}
|
|
108
|
-
|
|
109
|
-
//# sourceMappingURL=ArrayBufferParser.js.map
|
|
98
|
+
export default ArrayBufferParser;
|
|
@@ -1,14 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.BufferParser = void 0;
|
|
7
|
-
exports.stripBOM = stripBOM;
|
|
8
|
-
exports.normalizeJsonBuffer = normalizeJsonBuffer;
|
|
9
|
-
exports.decodeStringFromUTF8BOM = decodeStringFromUTF8BOM;
|
|
10
|
-
const Parser_1 = __importDefault(require("./Parser"));
|
|
11
|
-
const StringParser_1 = __importDefault(require("./StringParser"));
|
|
1
|
+
import Parser from "./Parser";
|
|
2
|
+
import StringParser from "./StringParser";
|
|
12
3
|
let BOM;
|
|
13
4
|
let COMMA;
|
|
14
5
|
try {
|
|
@@ -20,27 +11,26 @@ catch (e) {
|
|
|
20
11
|
BOM = { equals: () => false, subarray: () => null };
|
|
21
12
|
COMMA = { equals: () => false, subarray: () => null };
|
|
22
13
|
}
|
|
23
|
-
class BufferParser extends
|
|
14
|
+
export class BufferParser extends Parser {
|
|
24
15
|
parse(input) {
|
|
25
16
|
if (typeof input === "string") {
|
|
26
|
-
return
|
|
17
|
+
return StringParser.prototype.parse.call(StringParser.prototype, input);
|
|
27
18
|
}
|
|
28
19
|
else {
|
|
29
|
-
return
|
|
20
|
+
return StringParser.prototype.parse.call(StringParser.prototype, decodeStringFromUTF8BOM(normalizeJsonBuffer(stripBOM(input))));
|
|
30
21
|
}
|
|
31
22
|
}
|
|
32
23
|
stringify(obj) {
|
|
33
24
|
return JSON.stringify(obj);
|
|
34
25
|
}
|
|
35
26
|
}
|
|
36
|
-
|
|
37
|
-
function stripBOM(buffer) {
|
|
27
|
+
export function stripBOM(buffer) {
|
|
38
28
|
if (buffer.length >= 3 && BOM.equals(buffer.subarray(0, 3))) {
|
|
39
29
|
return buffer.subarray(3);
|
|
40
30
|
}
|
|
41
31
|
return buffer;
|
|
42
32
|
}
|
|
43
|
-
function normalizeJsonBuffer(text) {
|
|
33
|
+
export function normalizeJsonBuffer(text) {
|
|
44
34
|
let builder = [];
|
|
45
35
|
let last = "other";
|
|
46
36
|
let from = 0;
|
|
@@ -96,8 +86,7 @@ function normalizeJsonBuffer(text) {
|
|
|
96
86
|
builder.push(text.subarray(from));
|
|
97
87
|
return Buffer.concat(builder);
|
|
98
88
|
}
|
|
99
|
-
function decodeStringFromUTF8BOM(buffer) {
|
|
89
|
+
export function decodeStringFromUTF8BOM(buffer) {
|
|
100
90
|
return stripBOM(buffer).toString("utf-8");
|
|
101
91
|
}
|
|
102
|
-
|
|
103
|
-
//# sourceMappingURL=BufferParser.js.map
|
|
92
|
+
export default BufferParser;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import Parser from "./Parser";
|
|
2
|
+
/**
|
|
3
|
+
* 用于解析和序列化 ArrayBuffer 数据的解析器
|
|
4
|
+
*/
|
|
5
|
+
declare class BufferParserX extends Parser<ArrayBuffer, any> {
|
|
6
|
+
/**
|
|
7
|
+
* 解析 ArrayBuffer 为对象
|
|
8
|
+
* @param buffer 输入的 ArrayBuffer
|
|
9
|
+
* @param reviver 可选的 reviver 函数
|
|
10
|
+
*/
|
|
11
|
+
parse(buffer: ArrayBuffer, reviver?: (key: string, value: any) => any): any;
|
|
12
|
+
/**
|
|
13
|
+
* 序列化对象为 ArrayBuffer
|
|
14
|
+
* @param value 要序列化的对象
|
|
15
|
+
* @param replacer 可选的 replacer 函数
|
|
16
|
+
* @param space 可选的缩进
|
|
17
|
+
*/
|
|
18
|
+
stringify(value: any, replacer?: (key: string, value: any) => any, space?: string | number): ArrayBuffer;
|
|
19
|
+
private static _decodeUtf8;
|
|
20
|
+
private static _encodeUtf8;
|
|
21
|
+
private static _applyReviver;
|
|
22
|
+
}
|
|
23
|
+
export default BufferParserX;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import Parser from "./Parser";
|
|
2
|
+
import { ParserX, Serializer } from "./StringParser";
|
|
3
|
+
/**
|
|
4
|
+
* 用于解析和序列化 ArrayBuffer 数据的解析器
|
|
5
|
+
*/
|
|
6
|
+
class BufferParserX extends Parser {
|
|
7
|
+
/**
|
|
8
|
+
* 解析 ArrayBuffer 为对象
|
|
9
|
+
* @param buffer 输入的 ArrayBuffer
|
|
10
|
+
* @param reviver 可选的 reviver 函数
|
|
11
|
+
*/
|
|
12
|
+
parse(buffer, reviver) {
|
|
13
|
+
if (!buffer)
|
|
14
|
+
return null;
|
|
15
|
+
const text = BufferParserX._decodeUtf8(buffer);
|
|
16
|
+
const result = new StringParserX(text).parseValue();
|
|
17
|
+
if (typeof reviver === "function") {
|
|
18
|
+
return BufferParserX._applyReviver("", result, reviver);
|
|
19
|
+
}
|
|
20
|
+
console.log(result);
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* 序列化对象为 ArrayBuffer
|
|
25
|
+
* @param value 要序列化的对象
|
|
26
|
+
* @param replacer 可选的 replacer 函数
|
|
27
|
+
* @param space 可选的缩进
|
|
28
|
+
*/
|
|
29
|
+
stringify(value, replacer, space) {
|
|
30
|
+
const serializer = new SerializerX(replacer, space);
|
|
31
|
+
const str = serializer.serialize(value);
|
|
32
|
+
return BufferParserX._encodeUtf8(str);
|
|
33
|
+
}
|
|
34
|
+
static _decodeUtf8(buffer) {
|
|
35
|
+
return new TextDecoder().decode(new Uint8Array(buffer));
|
|
36
|
+
}
|
|
37
|
+
static _encodeUtf8(str) {
|
|
38
|
+
return new TextEncoder().encode(str).buffer;
|
|
39
|
+
}
|
|
40
|
+
static _applyReviver(key, value, reviver) {
|
|
41
|
+
if (value && typeof value === "object") {
|
|
42
|
+
if (Array.isArray(value)) {
|
|
43
|
+
for (let i = 0; i < value.length; i++) {
|
|
44
|
+
value[i] = BufferParserX._applyReviver(i.toString(), value[i], reviver);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
for (const prop in value) {
|
|
49
|
+
if (Object.prototype.hasOwnProperty.call(value, prop)) {
|
|
50
|
+
value[prop] = BufferParserX._applyReviver(prop, value[prop], reviver);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return reviver(key, value);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// StringParserX 仅用于内部解析字符串,逻辑与 StringParser 类似,但只暴露 parseValue 方法
|
|
59
|
+
class StringParserX {
|
|
60
|
+
constructor(text) {
|
|
61
|
+
// @ts-ignore
|
|
62
|
+
this.parser = new ParserX(text);
|
|
63
|
+
}
|
|
64
|
+
parseValue() {
|
|
65
|
+
return this.parser.parseValue();
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
class SerializerX {
|
|
69
|
+
constructor(replacer, space) {
|
|
70
|
+
// @ts-ignore
|
|
71
|
+
this.serializer = new Serializer(replacer, space);
|
|
72
|
+
}
|
|
73
|
+
serialize(obj) {
|
|
74
|
+
return this.serializer.serialize(obj);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
export default BufferParserX;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import StringParser from './StringParser';
|
|
2
|
+
declare abstract class FileParser<TOutput = any> {
|
|
3
|
+
protected fileContent: string;
|
|
4
|
+
protected parser: StringParser;
|
|
5
|
+
preload(filePath: string): Promise<void>;
|
|
6
|
+
parse(): TOutput;
|
|
7
|
+
stringify(obj: TOutput): string;
|
|
8
|
+
}
|
|
9
|
+
export default FileParser;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import StringParser from './StringParser';
|
|
11
|
+
class FileParser {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.fileContent = '';
|
|
14
|
+
this.parser = new StringParser();
|
|
15
|
+
}
|
|
16
|
+
preload(filePath) {
|
|
17
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
18
|
+
const fs = yield import('fs/promises');
|
|
19
|
+
this.fileContent = yield fs.readFile(filePath, 'utf-8');
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
parse() {
|
|
23
|
+
return this.parser.parse(this.fileContent);
|
|
24
|
+
}
|
|
25
|
+
;
|
|
26
|
+
stringify(obj) {
|
|
27
|
+
return this.parser.stringify(obj);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export default FileParser;
|