brs-js 2.0.12 → 2.0.14

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.
Files changed (61) hide show
  1. package/dist/dist.js +1 -1
  2. package/dist/dist.js.map +1 -0
  3. package/dist/dist.node.js +1 -1
  4. package/dist/dist.node.js.map +1 -0
  5. package/dist/dist.web.js +1 -1
  6. package/dist/dist.web.js.map +1 -0
  7. package/package.json +1 -1
  8. package/.babelrc +0 -5
  9. package/.prettierrc +0 -7
  10. package/debug/Conf Spacestation.brs +0 -0
  11. package/debug/Electrks_Feminine_Challenge.brs +0 -0
  12. package/debug/a5bricks.brs +0 -0
  13. package/debug/a5p2.2.brs +0 -0
  14. package/debug/a5p2.brs +0 -0
  15. package/debug/audio.brs +0 -0
  16. package/debug/brick a5.brs +0 -0
  17. package/debug/brick qa.brs +0 -0
  18. package/debug/brickparty.brs +0 -0
  19. package/debug/brsv10.brs +0 -0
  20. package/debug/brsv10brick.brs +0 -0
  21. package/debug/bruteforce.js +0 -254
  22. package/debug/click brick.brs +0 -0
  23. package/debug/clone.html +0 -36
  24. package/debug/ctf_tileset.brs +0 -0
  25. package/debug/ctf_tileset_5.brs +0 -0
  26. package/debug/evil.brs +0 -0
  27. package/debug/evilwrite.js +0 -390
  28. package/debug/foo.txt +0 -3080
  29. package/debug/kenko_big.brs +0 -0
  30. package/debug/light.brs +0 -0
  31. package/debug/out.json +0 -105
  32. package/debug/read.js +0 -30
  33. package/debug/readSpeed.js +0 -32
  34. package/debug/readTest.js +0 -45
  35. package/debug/temp.brs +0 -0
  36. package/debug/western.brs +0 -0
  37. package/examples/ATCFort.brs +0 -0
  38. package/examples/read_example.html +0 -34
  39. package/examples/read_example.js +0 -21
  40. package/examples/write_example.js +0 -25
  41. package/examples/write_planet.html +0 -144
  42. package/examples/write_simplex.html +0 -82
  43. package/examples/write_wedge_sphere.html +0 -173
  44. package/src/constants.ts +0 -6
  45. package/src/index.ts +0 -15
  46. package/src/read.ts +0 -57
  47. package/src/read.v1.ts +0 -99
  48. package/src/read.v10.ts +0 -185
  49. package/src/read.v2.ts +0 -102
  50. package/src/read.v3.ts +0 -111
  51. package/src/read.v4.ts +0 -112
  52. package/src/read.v8.ts +0 -172
  53. package/src/read.v9.ts +0 -181
  54. package/src/types.ts +0 -341
  55. package/src/utils.ts +0 -651
  56. package/src/uuid.ts +0 -78
  57. package/src/write.ts +0 -287
  58. package/test/lib.test.js +0 -51
  59. package/test/utils.test.js +0 -209
  60. package/tsconfig.json +0 -18
  61. package/webpack.config.js +0 -64
package/src/uuid.ts DELETED
@@ -1,78 +0,0 @@
1
- // this code is modified from https://github.com/uuidjs/uuid
2
-
3
- import { Uuid } from './types';
4
-
5
- /*
6
- The MIT License (MIT)
7
-
8
- Copyright (c) 2010-2020 Robert Kieffer and other contributors
9
-
10
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15
- */
16
- const hexTable: string[] = Array.from({ length: 256 }).map((_, i) =>
17
- (i + 0x100).toString(16).substr(1)
18
- );
19
-
20
- // stringify uuid
21
- export function uuidStringify(arr: number[]): Uuid {
22
- return (
23
- hexTable[arr[0]] +
24
- hexTable[arr[1]] +
25
- hexTable[arr[2]] +
26
- hexTable[arr[3]] +
27
- '-' +
28
- hexTable[arr[4]] +
29
- hexTable[arr[5]] +
30
- '-' +
31
- hexTable[arr[6]] +
32
- hexTable[arr[7]] +
33
- '-' +
34
- hexTable[arr[8]] +
35
- hexTable[arr[9]] +
36
- '-' +
37
- hexTable[arr[10]] +
38
- hexTable[arr[11]] +
39
- hexTable[arr[12]] +
40
- hexTable[arr[13]] +
41
- hexTable[arr[14]] +
42
- hexTable[arr[15]]
43
- ).toLowerCase();
44
- }
45
-
46
- export function uuidParse(uuid: Uuid): Uint8Array {
47
- let v;
48
- const arr = new Uint8Array(16);
49
-
50
- // Parse ########-....-....-....-............
51
- arr[0] = (v = parseInt(uuid.slice(0, 8), 16)) >>> 24;
52
- arr[1] = (v >>> 16) & 0xff;
53
- arr[2] = (v >>> 8) & 0xff;
54
- arr[3] = v & 0xff;
55
-
56
- // Parse ........-####-....-....-............
57
- arr[4] = (v = parseInt(uuid.slice(9, 13), 16)) >>> 8;
58
- arr[5] = v & 0xff;
59
-
60
- // Parse ........-....-####-....-............
61
- arr[6] = (v = parseInt(uuid.slice(14, 18), 16)) >>> 8;
62
- arr[7] = v & 0xff;
63
-
64
- // Parse ........-....-....-####-............
65
- arr[8] = (v = parseInt(uuid.slice(19, 23), 16)) >>> 8;
66
- arr[9] = v & 0xff;
67
-
68
- // Parse ........-....-....-....-############
69
- // (Use "/" to avoid 32-bit truncation when bit-shifting high-order bytes)
70
- arr[10] = ((v = parseInt(uuid.slice(24, 36), 16)) / 0x10000000000) & 0xff;
71
- arr[11] = (v / 0x100000000) & 0xff;
72
- arr[12] = (v >>> 24) & 0xff;
73
- arr[13] = (v >>> 16) & 0xff;
74
- arr[14] = (v >>> 8) & 0xff;
75
- arr[15] = v & 0xff;
76
-
77
- return arr;
78
- }
package/src/write.ts DELETED
@@ -1,287 +0,0 @@
1
- import { DEFAULT_UUID, LATEST_VERSION, MAGIC, MAX_INT } from './constants';
2
- import {
3
- Brick,
4
- DefinedComponents,
5
- KnownComponents,
6
- Owner,
7
- WriteOptions,
8
- WriteSaveObject,
9
- } from './types';
10
- import { concat, isEqual, write } from './utils';
11
-
12
- const EMPTY_ARR = new Uint8Array([]);
13
-
14
- export const DEFAULT_COMPONENTS: DefinedComponents = {
15
- BCD_SpotLight: {
16
- version: 1,
17
- properties: {
18
- Rotation: 'Rotator',
19
- InnerConeAngle: 'Float',
20
- OuterConeAngle: 'Float',
21
- Brightness: 'Float',
22
- Radius: 'Float',
23
- Color: 'Color',
24
- bUseBrickColor: 'Boolean',
25
- bCastShadows: 'Boolean',
26
- },
27
- },
28
- BCD_PointLight: {
29
- version: 1,
30
- properties: {
31
- bMatchBrickShape: 'Boolean',
32
- Brightness: 'Float',
33
- Radius: 'Float',
34
- Color: 'Color',
35
- bUseBrickColor: 'Boolean',
36
- bCastShadows: 'Boolean',
37
- },
38
- },
39
- BCD_ItemSpawn: {
40
- version: 1,
41
- properties: {
42
- PickupClass: 'Class',
43
- bPickupEnabled: 'Boolean',
44
- bPickupRespawnOnMinigameReset: 'Boolean',
45
- PickupMinigameResetRespawnDelay: 'Float',
46
- bPickupAutoDisableOnPickup: 'Boolean',
47
- PickupRespawnTime: 'Float',
48
- PickupOffsetDirection: 'Byte',
49
- PickupOffsetDistance: 'Float',
50
- PickupRotation: 'Rotator',
51
- PickupScale: 'Float',
52
- bPickupAnimationEnabled: 'Boolean',
53
- PickupAnimationAxis: 'Byte',
54
- bPickupAnimationAxisLocal: 'Boolean',
55
- PickupSpinSpeed: 'Float',
56
- PickupBobSpeed: 'Float',
57
- PickupBobHeight: 'Float',
58
- PickupAnimationPhase: 'Float',
59
- },
60
- },
61
- BCD_Interact: {
62
- version: 1,
63
- properties: {
64
- bPlayInteractSound: 'Boolean',
65
- Message: 'String',
66
- ConsoleTag: 'String',
67
- },
68
- },
69
- BCD_AudioEmitter: {
70
- version: 1,
71
- properties: {
72
- AudioDescriptor: 'Object',
73
- VolumeMultiplier: 'Float',
74
- PitchMultiplier: 'Float',
75
- InnerRadius: 'Float',
76
- MaxDistance: 'Float',
77
- bSpatialization: 'Boolean',
78
- },
79
- },
80
- };
81
-
82
- export default function writeBrs(
83
- save: WriteSaveObject,
84
- options: WriteOptions = {}
85
- ) {
86
- if (typeof save !== 'object') {
87
- throw new Error('Expected save to be an object');
88
- }
89
-
90
- if (!Array.isArray(save.bricks) || save.bricks.length === 0) {
91
- throw new Error('Expected save to have bricks field');
92
- }
93
-
94
- if (save.bricks.length > MAX_INT) {
95
- throw new Error('Brick count out of range');
96
- }
97
-
98
- // compression is disabled by default
99
- const compress = options.compress ? write.compressed : write.uncompressed;
100
-
101
- // Convert from BGRA to RGBA
102
- const rgba = ([r, g, b, a]: number[]) => new Uint8Array([b, g, r, a]);
103
-
104
- // stored brick indices from components on the bricks
105
- const componentBrickOwnership: { [component_name: string]: number[] } = {};
106
-
107
- const numColors = Math.max(save.colors?.length ?? 0, 2);
108
- const numAssets = Math.max(save.brick_assets?.length ?? 0, 2);
109
- const numMats = Math.max(save.materials?.length ?? 0, 2);
110
- const numPhysMats = Math.max(save.physical_materials?.length ?? 0, 2);
111
-
112
- if (save.preview && !Array.isArray(save.preview))
113
- throw new Error('Expected preview to be an array');
114
-
115
- const buff = concat(
116
- // Write magic bytes
117
- MAGIC,
118
- write.u16(LATEST_VERSION),
119
- write.i32(save.game_version ?? 0),
120
-
121
- // Header 1
122
- compress(
123
- write.string(save.map ?? 'Unknown'),
124
- write.string(save.author?.name ?? 'Unknown'),
125
- write.string(save.description ?? ''),
126
- write.uuid(save.author?.id ?? DEFAULT_UUID),
127
- concat(
128
- write.string(save.host?.name ?? 'Unknown'),
129
- write.uuid(save.host?.id ?? DEFAULT_UUID)
130
- ),
131
- new Uint8Array(
132
- save.save_time &&
133
- (Array.isArray(save.save_time) ||
134
- save.save_time instanceof Uint8Array) &&
135
- save.save_time.length === 8
136
- ? save.save_time
137
- : [0, 0, 0, 0, 0, 0, 0, 0]
138
- ),
139
- write.i32(save.bricks.length)
140
- ),
141
-
142
- // Header 2
143
- compress(
144
- write.array(save.mods ?? [], write.string),
145
- write.array(save.brick_assets ?? ['PB_DefaultBrick'], write.string),
146
- write.array(save.colors ?? [], rgba),
147
- write.array(save.materials ?? ['BMC_Plastic'], write.string),
148
- write.array(
149
- save.brick_owners ?? [],
150
- ({ id = DEFAULT_UUID, name = 'Unknown', bricks = 0 }: Partial<Owner>) =>
151
- concat(write.uuid(id), write.string(name), write.i32(bricks))
152
- ),
153
- write.array(save.physical_materials ?? ['BPMC_Default'], write.string)
154
- ),
155
-
156
- // write the save preview if it exists
157
- concat(
158
- new Uint8Array([save.preview ? 1 : 0]),
159
- save.preview ? write.i32(save.preview.length) : EMPTY_ARR, // <- Sorry @Uxie https://i.imgur.com/hSRxdbf.png
160
- save.preview ?? EMPTY_ARR
161
- ),
162
-
163
- // Bricks
164
- compress(
165
- write
166
- .bits()
167
- .each(save.bricks, function (brick: Brick, i) {
168
- if (typeof brick !== 'object')
169
- throw new Error(`Expected save.bricks[${i}] to be an object`);
170
-
171
- if (!Array.isArray(brick.size) || brick.size.length !== 3)
172
- throw new Error(
173
- `Expected save.bricks[${i}].size to be an array of length 3`
174
- );
175
-
176
- if (!Array.isArray(brick.position) || brick.position.length !== 3)
177
- throw new Error(
178
- `Expected save.bricks[${i}].position to be an array of length 3`
179
- );
180
-
181
- this.align();
182
- this.int(brick.asset_name_index ?? 0, numAssets);
183
-
184
- const isNonProcedural = isEqual(brick.size, [0, 0, 0]);
185
- this.bit(!isNonProcedural);
186
- if (!isNonProcedural) {
187
- brick.size.map(s => this.uint_packed(s));
188
- }
189
- brick.position.map(s => this.int_packed(s));
190
- this.int(((brick.direction ?? 4) << 2) | (brick.rotation ?? 0), 24);
191
-
192
- if (typeof brick.collision === 'boolean') {
193
- this.bit(brick.collision);
194
- this.bit(brick.collision);
195
- this.bit(brick.collision);
196
- this.bit(true);
197
- } else {
198
- this.bit(brick.collision?.player ?? true);
199
- this.bit(brick.collision?.weapon ?? true);
200
- this.bit(brick.collision?.interaction ?? true);
201
- this.bit(brick.collision?.tool ?? true);
202
- }
203
-
204
- this.bit(brick?.visibility ?? true);
205
- this.int(brick?.material_index ?? 0, numMats);
206
- this.int(brick.physical_index ?? 0, numPhysMats);
207
- this.int(brick.material_intensity ?? 5, 11);
208
-
209
- if (typeof brick.color === 'number') {
210
- this.bit(false);
211
- this.int(brick.color, numColors);
212
- } else {
213
- this.bit(true);
214
- if (
215
- brick.color &&
216
- (!Array.isArray(brick.color) || brick.color.length < 3)
217
- )
218
- throw new Error(
219
- `Expected save.bricks[${i}].color to be an array of at least length 3`
220
- );
221
- this.bytes(
222
- new Uint8Array(brick.color.slice(0, 3) ?? [255, 255, 255])
223
- );
224
- }
225
-
226
- this.uint_packed(brick.owner_index ?? 1);
227
-
228
- // add all the brick indices to the components list
229
- for (const key in brick.components ?? {}) {
230
- componentBrickOwnership[key] ??= [];
231
- componentBrickOwnership[key].push(i);
232
- }
233
- })
234
- .finish()
235
- ),
236
-
237
- // write components section
238
- compress(
239
- write.array(
240
- Object.keys(save.components ?? DEFAULT_COMPONENTS).filter(
241
- name => componentBrickOwnership[name]
242
- ),
243
- name =>
244
- concat(
245
- write.string(name),
246
- write
247
- .bits()
248
- .self(function () {
249
- const component =
250
- save.components?.[name] ?? DEFAULT_COMPONENTS[name];
251
- const brick_indices = componentBrickOwnership[name];
252
- const properties = Object.entries(component.properties);
253
-
254
- // write version
255
- this.bytes(write.i32(component.version));
256
-
257
- // write bricks;
258
- this.array(brick_indices, i => {
259
- this.int(i, Math.max(save.bricks.length, 2));
260
- });
261
-
262
- // write properties
263
- this.array(properties, ([name, type]) => {
264
- this.string(name);
265
- this.string(type);
266
- });
267
-
268
- // read brick indices
269
- for (const i of brick_indices) {
270
- for (const [prop, type] of properties) {
271
- if (!(prop in (save.bricks[i].components?.[name] ?? {}))) {
272
- throw new Error(
273
- `Expected save.bricks[${i}].components[${name}] to have property '${prop}' of type '${type}'`
274
- );
275
- }
276
- this.unreal(type, save.bricks[i].components[name][prop]);
277
- }
278
- }
279
- this.align();
280
- })
281
- .finishSection()
282
- )
283
- )
284
- )
285
- );
286
- return buff;
287
- }
package/test/lib.test.js DELETED
@@ -1,51 +0,0 @@
1
- const { read, write } = require('..');
2
-
3
- // const uuid0 = '00000000-0000-0000-0000-000000000000';
4
- const uuid0 = '12345678-4321-1234-4321-123456789012';
5
- const save = {
6
- version: 10,
7
- map: 'Unknown',
8
- description: '',
9
- author: { id: uuid0, name: 'Test' },
10
- save_time: new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]),
11
- brick_count: 1,
12
- mods: [],
13
- preview: null,
14
- brick_assets: [],
15
- colors: [],
16
- components: {},
17
- game_version: 0,
18
- host: { id: uuid0, name: 'Test' },
19
- materials: ['BMC_Hologram', 'BMC_Plastic', 'BMC_Glow', 'BMC_Metallic'],
20
- physical_materials: ['BPMC_Default'],
21
- brick_owners: [{ id: uuid0, name: 'Test', bricks: 0 }],
22
- bricks: [
23
- {
24
- asset_name_index: 1,
25
- size: [10, 10, 10],
26
- position: [0, 0, 0],
27
- components: {},
28
- direction: 4,
29
- owner_index: 1,
30
- rotation: 0,
31
- collision: {
32
- player: true,
33
- interaction: true,
34
- tool: true,
35
- weapon: true,
36
- },
37
- visibility: true,
38
- material_index: 1,
39
- material_intensity: 5,
40
- physical_index: 0,
41
- color: [0, 0, 0],
42
- },
43
- ],
44
- };
45
- test('creating a brs from thin air', () => {
46
- expect(read(write(save))).toEqual(save);
47
- });
48
-
49
- test('reads no bricks when the option is passed in', () => {
50
- expect(read(write(save), { bricks: false })).toEqual({ ...save, bricks: [] });
51
- });
@@ -1,209 +0,0 @@
1
- const {
2
- utils: { read, write, subarray, chunk },
3
- } = require('..');
4
-
5
- describe('buffer read/writing', () => {
6
- // Generic testing of read and write
7
- const rwTest =
8
- fn =>
9
- (bytes, val, ...args) => {
10
- expect(read[fn](new Uint8Array(bytes), ...args)).toEqual(val);
11
- expect(write[fn](val, ...args)).toMatchObject(new Uint8Array(bytes));
12
- };
13
-
14
- // Testing both endiannesses for read and write
15
- const endianTest = fn => (bytes, val) => {
16
- // Little Endian (default)
17
- rwTest(fn)(bytes, val);
18
-
19
- // Big Endian
20
- rwTest(fn)(new Uint8Array(bytes).reverse(), val, false);
21
- };
22
-
23
- describe('byte manipulating util', () => {
24
- test('subarray', () => {
25
- const arr = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
26
- expect(subarray(arr, 2)).toMatchObject({ 0: 1, 1: 2 });
27
- expect(arr.brsOffset).toEqual(2);
28
- expect(subarray(arr, 4)).toMatchObject({ 0: 3, 1: 4, 2: 5, 3: 6 });
29
- expect(arr.brsOffset).toEqual(6);
30
- });
31
-
32
- test('chunk', () => {
33
- const arr = new Uint8Array([
34
- 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
35
- ]);
36
- expect(chunk(arr, 4)).toMatchObject([
37
- { 0: 1, 1: 2, 2: 3, 3: 4 },
38
- { 0: 5, 1: 6, 2: 7, 3: 8 },
39
- { 0: 9, 1: 10, 2: 11, 3: 12 },
40
- { 0: 13, 1: 14, 2: 15, 3: 16 },
41
- ]);
42
- });
43
- });
44
-
45
- describe('unsigned short', () => {
46
- const shortTest = endianTest('u16');
47
-
48
- test('00 00 -> 0', () => {
49
- const bytes = [0x00, 0x00];
50
- const val = 0;
51
-
52
- shortTest(bytes, val);
53
- });
54
-
55
- test('ff ff -> 65535', () => {
56
- const bytes = [0xff, 0xff];
57
- const val = 0xffff;
58
-
59
- shortTest(bytes, val);
60
- });
61
-
62
- test('01 20 -> 8193', () => {
63
- const bytes = [0x01, 0x20];
64
- const val = 0x2001;
65
-
66
- shortTest(bytes, val);
67
- });
68
- });
69
-
70
- describe('signed int', () => {
71
- const intTest = endianTest('i32');
72
-
73
- test('00 00 00 00 -> 0', () => {
74
- const bytes = [0x00, 0x00, 0x00, 0x00];
75
- const val = 0;
76
-
77
- intTest(bytes, val);
78
- });
79
-
80
- test('ff ff ff ff -> -1', () => {
81
- const bytes = [0xff, 0xff, 0xff, 0xff];
82
- const val = -1;
83
-
84
- intTest(bytes, val);
85
- });
86
-
87
- test('13 37 69 69 -> 322398569', () => {
88
- const bytes = [0x69, 0x69, 0x37, 0x13];
89
- const val = 322398569;
90
-
91
- intTest(bytes, val);
92
- });
93
- });
94
-
95
- describe('string', () => {
96
- test('04 00 00 00 66 6f 6f 00 -> "foo"', () => {
97
- const bytes = [0x04, 0x00, 0x00, 0x00, 0x66, 0x6f, 0x6f, 0x00];
98
- const val = 'foo';
99
-
100
- rwTest('string')(bytes, val);
101
- });
102
- });
103
-
104
- describe('uuid', () => {
105
- test('can parse uuid', () => {
106
- const bytes = [
107
- 205, 107, 157, 27, 45, 75, 253, 187, 141, 171, 93, 155, 237, 75, 189,
108
- 251,
109
- ];
110
- const uuid = '1b9d6bcd-bbfd-4b2d-9b5d-ab8dfbbd4bed';
111
-
112
- rwTest('uuid')(bytes, uuid);
113
- });
114
- });
115
-
116
- describe('array', () => {
117
- /*
118
- const bytes = [0x04, 0x00, 0x00, 0x00, 0x66, 0x6f, 0x6f, 0x00];
119
- const val = 'foo';
120
- */
121
- const read_byte = b => read.bytes(b, 1)[0];
122
-
123
- const arrTest = (bytes, arr, read_fn, write_fn) => {
124
- expect(read.array(new Uint8Array(bytes), read_fn)).toMatchObject(arr);
125
- expect(write.array(arr, write_fn)).toMatchObject(new Uint8Array(bytes));
126
- };
127
-
128
- test('00 00 00 00 -> []', () => {
129
- const bytes = [0x00, 0x00, 0x00, 0x00];
130
- const arr = [];
131
-
132
- arrTest(bytes, arr, read_byte, b => [b]);
133
- });
134
-
135
- test('03 00 00 00 01 02 03 -> [1, 2, 3]', () => {
136
- const bytes = [0x03, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03];
137
- const arr = [1, 2, 3];
138
-
139
- arrTest(bytes, arr, read_byte, b => [b]);
140
- });
141
-
142
- test('string array', () => {
143
- const str_bytes = [0x04, 0x00, 0x00, 0x00, 0x66, 0x6f, 0x6f, 0x00];
144
- const str = 'foo';
145
- const bytes = [
146
- 0x05,
147
- 0,
148
- 0,
149
- 0,
150
- ...str_bytes,
151
- ...str_bytes,
152
- ...str_bytes,
153
- ...str_bytes,
154
- ...str_bytes,
155
- ];
156
- const arr = [str, str, str, str, str];
157
- arrTest(bytes, arr, read.string, write.string);
158
- });
159
- });
160
-
161
- describe('bit reader', () => {
162
- it('reads bits', () => {
163
- const bits = read.bits([0b10101111]);
164
- expect(bits.bit()).toBe(true);
165
- expect(bits.bit()).toBe(true);
166
- expect(bits.bit()).toBe(true);
167
- expect(bits.bit()).toBe(true);
168
- expect(bits.bit()).toBe(false);
169
- expect(bits.bit()).toBe(true);
170
- expect(bits.bit()).toBe(false);
171
- expect(bits.bit()).toBe(true);
172
- });
173
-
174
- it('reads aligned bits', () => {
175
- const bits = read.bits([0b00000001, 0b10101111]);
176
- expect(bits.bit()).toBe(true);
177
- bits.align();
178
- expect(bits.bit()).toBe(true);
179
- expect(bits.bit()).toBe(true);
180
- expect(bits.bit()).toBe(true);
181
- expect(bits.bit()).toBe(true);
182
- expect(bits.bit()).toBe(false);
183
- expect(bits.bit()).toBe(true);
184
- expect(bits.bit()).toBe(false);
185
- expect(bits.bit()).toBe(true);
186
- });
187
-
188
- it('reads ints', () => {
189
- const bits = read.bits([0b11001111]);
190
- expect(bits.int(16)).toBe(15);
191
- expect(bits.int(16)).toBe(12);
192
- });
193
-
194
- it('reads floats', () => {
195
- const bits = read.bits([0x42, 0xf6, 0xe6, 0x66].reverse());
196
- expect(bits.float()).toBeCloseTo(123.45);
197
- });
198
-
199
- it('writes floats', () => {
200
- const bits = write.bits();
201
- bits.float(123.45);
202
- expect(bits.finish()).toStrictEqual(
203
- new Uint8Array([0x42, 0xf6, 0xe6, 0x66]).reverse()
204
- );
205
- });
206
-
207
- // TODO: tests for int_packed, uint_packed, bytes
208
- });
209
- });
package/tsconfig.json DELETED
@@ -1,18 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "allowJs": true,
4
- "baseUrl": ".",
5
- "declaration": true,
6
- "module": "es6",
7
- "moduleResolution": "node",
8
- "noImplicitAny": true,
9
- "outDir": "./dist/",
10
- "sourceMap": true,
11
- "declarationMap": true,
12
- "target": "es2020"
13
- },
14
- "exclude": [
15
- "node_modules/",
16
- "dist/",
17
- ]
18
- }
package/webpack.config.js DELETED
@@ -1,64 +0,0 @@
1
- const path = require('path');
2
-
3
- const mode = process.env.NODE_ENV || 'development';
4
-
5
- const config = {
6
- mode,
7
- cache: { type: 'filesystem' },
8
- resolve: {
9
- cacheWithContext: true,
10
- extensions: ['', '.js', '.ts'],
11
- },
12
- entry: path.resolve(__dirname, 'src/index.ts'),
13
- devtool: 'source-map',
14
- module: {
15
- rules: [
16
- {
17
- test: /\.ts$/,
18
- use: {
19
- loader: 'ts-loader',
20
- options: {
21
- experimentalFileCaching: true,
22
- },
23
- },
24
- exclude: /node_modules|dist/,
25
- },
26
- ],
27
- },
28
- resolve: {
29
- extensions: ['.ts', '.js'],
30
- },
31
- };
32
-
33
- module.exports = [
34
- {
35
- ...config,
36
- target: 'node',
37
- output: {
38
- path: path.resolve(__dirname, 'dist'),
39
- filename: 'dist.node.js',
40
- library: {
41
- type: 'commonjs2',
42
- },
43
- },
44
- },
45
- {
46
- ...config,
47
- target: 'web',
48
- output: {
49
- path: path.resolve(__dirname, 'dist'),
50
- filename: 'dist.js',
51
- },
52
- },
53
- {
54
- ...config,
55
- target: 'web',
56
- output: {
57
- path: path.resolve(__dirname, 'dist'),
58
- filename: 'dist.web.js',
59
- library: {
60
- type: 'commonjs2',
61
- },
62
- },
63
- },
64
- ];