url-safe-bitpacking 0.1.4 → 0.1.6

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 CHANGED
@@ -2,6 +2,16 @@
2
2
 
3
3
  Package for creating definitions of parametric models that can be stored as compactly as possible in a URL by storing it in a web-safe base-64 string. This pacakge is till very much WIP. Feel free to suggest by making an issue or pull-request [GitHub](https://github.com/JonasWard/url-safe-bitpacking).
4
4
 
5
+ ### goal for version 0.2
6
+
7
+ | what | code | tests | docs |
8
+ | ---------------------------------------------------- | -------- | -------- | -------- |
9
+ | data types | ✓ | ✓ | ✓ |
10
+ | nested object model | ✓ | ✓ | ¼ |
11
+ | updating model entries | ✓ | ✓ | |
12
+ | re-using data from old model on change in definition | ½ | ¼ | |
13
+ | flattening and reading of the objects | ✓ | ✓ | ¿ |
14
+
5
15
  ## concept
6
16
 
7
17
  The goal of this library is to offer a flexible, minimal and, variable object definition that can be stored in the browser URL. The main imagined use-case is parametric models that have nested and variable sub-object definitions.
@@ -40,7 +50,7 @@ DataEntryFactory.createInt(5, 3, 20, 'circleDivisions');
40
50
 
41
51
  ### float
42
52
 
43
- Floating points work very much like the integer type, with the main difference that one can also define a precision to define at what order of magnitude (from -3 to +3) the variable should be considered. The significand can be up to 20 bits, which eg. at precision -3 would allow a range of .001 to 1048.576. Floating points are assumed to be always positive.
53
+ Floating points work very much like the integer type, with the main difference that one can also define a precision to define at what order of magnitude (from -3 to +3) the variable should be considered. The significand can be up to 20 bits, which eg. at precision -3 would allow a range of .001 to 1048.576.
44
54
 
45
55
  ```typescript
46
56
  DataEntryFactory.createFloat(20, 10, 200, -1, 'shapePreProcessingWarptotal');
@@ -5,3 +5,4 @@ export declare enum DataType {
5
5
  INT = 3,
6
6
  FLOAT = 4
7
7
  }
8
+ export declare const getDataTypeName: (type: DataType) => string;
@@ -1,2 +1,2 @@
1
- import { BooleanData } from '../types/booleanData';
2
- export declare const create: () => BooleanData;
1
+ import { BooleanDataEntry } from '../types';
2
+ export declare const create: (value: boolean, name?: string, index?: number) => BooleanDataEntry;
@@ -1,2 +1,2 @@
1
- import { EnumData } from '../types/enumData';
2
- export declare const create: (max: number) => EnumData;
1
+ import { EnumDataEntry } from '../types';
2
+ export declare const create: (value: number, max?: number, name?: string, index?: number) => EnumDataEntry;
@@ -3,27 +3,10 @@ import { create as createInt } from './intFactory';
3
3
  import { create as createBoolean } from './booleanFactory';
4
4
  import { create as createVersion } from './versionFactory';
5
5
  import { create as createEnum } from './enumFactory';
6
- import { BooleanDescriptionWithValueType, IntDescriptionWithValueType, FloatDescriptionWithValueType, VersionDescriptionWithValueType, FloatDiscriptionType, BooleanDiscriptionType, VersionDiscriptionType, IntDiscriptionType, EnumDiscriptionType, EnumDescriptionWithValueType } from '../types/dataEntry';
7
- import { PrecisionRangeType } from '../types/floatData';
8
- import { VersionRangeType } from '../types/versionData';
9
- export declare class DataRangeDescriptionFactory {
10
- static createFloat: typeof createFloat;
11
- static createInt: typeof createInt;
12
- static createEnum: typeof createEnum;
13
- static createBoolean: typeof createBoolean;
14
- static createVersion: typeof createVersion;
15
- }
16
- export declare class DataDescriptionFactory {
17
- static createFloat: (min?: number, max?: number, precision?: PrecisionRangeType, name?: string, index?: number) => FloatDiscriptionType;
18
- static createInt: (min?: number, max?: number, name?: string, index?: number) => IntDiscriptionType;
19
- static createEnum: (max?: number, name?: string, index?: number) => EnumDiscriptionType;
20
- static createBoolean: (name?: string, index?: number) => BooleanDiscriptionType;
21
- static createVersion: (bits?: VersionRangeType, name?: string, index?: number) => VersionDiscriptionType;
22
- }
23
- export declare class DataEntryFactory {
24
- static createFloat: (value: number, min?: number, max?: number, precision?: PrecisionRangeType, name?: string, index?: number) => FloatDescriptionWithValueType;
25
- static createInt: (value: number, min?: number, max?: number, name?: string, index?: number) => IntDescriptionWithValueType;
26
- static createEnum: (value: number, max?: number, name?: string, index?: number) => EnumDescriptionWithValueType;
27
- static createBoolean: (value: boolean, name?: string, index?: number) => BooleanDescriptionWithValueType;
28
- static createVersion: (value: number, bits?: VersionRangeType, name?: string, index?: number) => VersionDescriptionWithValueType;
29
- }
6
+ export declare const DataEntryFactory: {
7
+ createFloat: typeof createFloat;
8
+ createInt: typeof createInt;
9
+ createEnum: typeof createEnum;
10
+ createBoolean: typeof createBoolean;
11
+ createVersion: typeof createVersion;
12
+ };
@@ -1,2 +1,3 @@
1
- import { FloatData, PrecisionRangeType } from '../types/floatData';
2
- export declare const create: (min: number, max: number, precision: PrecisionRangeType) => FloatData;
1
+ import { FloatDataEntry } from '../types';
2
+ import { PrecisionRangeType } from '../types/floatData';
3
+ export declare const create: (value: number, min?: number, max?: number, precision?: PrecisionRangeType, name?: string, index?: number) => FloatDataEntry;
@@ -1,2 +1,2 @@
1
- import { IntData } from '../types/intData';
2
- export declare const create: (min: number, max: number) => IntData;
1
+ import { IntDataEntry } from '../types';
2
+ export declare const create: (value: number, min?: number, max?: number, name?: string, index?: number) => IntDataEntry;
@@ -1,2 +1,3 @@
1
- import { VersionRangeType, VersionData } from '../types/versionData';
2
- export declare const create: (bits: VersionRangeType) => VersionData;
1
+ import { VersionDataEntry } from '../types';
2
+ import { VersionRangeType } from '../types/versionData';
3
+ export declare const create: (value: number, bits?: VersionRangeType, name?: string, index?: number) => VersionDataEntry;
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { ObjectGenerationOutputStatus, DataType } from './enums';
2
- export { DataRangeDescriptionFactory, DataDescriptionFactory, DataEntryFactory } from './factory';
2
+ export { DataEntryFactory } from './factory';
3
3
  export { getDefaultObject, updateDataEntry } from './objectmap';
4
4
  export { valueBitsParser, dataBitsParser, getBitsCount, dataBitsArrayParser, dataBitsStringifier, dataEntryCorrecting, parseBitsToBase64, parseBase64ToBits, dataArrayStringifier, } from './parsers';
5
- export { SingleLevelContentType, NestedContentDataType, NestedContentType, DoubleLevelContentType, NonEmptyValidEntryArrayType, OptionalEntryDataType, EnumEntryDataType, VersionArrayDefinitionType, PrecisionRangeType, SignificandMaxBits, FloatData, IntegerMaxBits, IntData, VersionRangeType, VersionData, GlobalVersion, BooleanData, DataRangeDescription, BooleanDiscriptionType, IntDiscriptionType, EnumDiscriptionType, FloatDiscriptionType, VersionDiscriptionType, DataDescription, BooleanDescriptionWithValueType, IntDescriptionWithValueType, EnumDescriptionWithValueType, FloatDescriptionWithValueType, VersionDescriptionWithValueType, DataEntry, DataEntryArray, SemanticlyNestedDataEntry, SemanticlyNestedDataDescription, ObjectGeneratorMethod, DefinitionGenerationObject, DefinitionNestedArray, DefinitionNestedGenerationObject, DefinitionSubObject, DefinitionArrayObject, VersionDefinitionObject, VersionEnumSemantics, ParserForVersion, VersionParsers, } from './types';
5
+ export { SingleLevelContentType, NestedContentDataType, NestedContentType, DoubleLevelContentType, NonEmptyValidEntryArrayType, OptionalEntryDataType, EnumEntryDataType, VersionArrayDefinitionType, PrecisionRangeType, SignificandMaxBits, FloatData, IntegerMaxBits, IntData, VersionRangeType, VersionData, BooleanData, DataEntry, DataEntryArray, SemanticlyNestedDataEntry, ObjectGeneratorMethod, DefinitionGenerationObject, DefinitionNestedArray, DefinitionNestedGenerationObject, DefinitionSubObject, DefinitionArrayObject, VersionDefinitionObject, VersionEnumSemantics, ParserForVersion, ParsersForVersionObject, } from './types';
6
6
  export {} from './update';
7
7
  export { interpolateEntryAt, getRelativeValue } from './utils';
package/dist/index.js CHANGED
@@ -27,18 +27,21 @@ var getBitsForIntegerNumber = (number, maxBits) => {
27
27
  };
28
28
 
29
29
  // src/factory/floatFactory.ts
30
- var create = (min, max, precision) => {
30
+ var create = (value, min = 0, max = 1, precision = 2, name = "", index = -1) => {
31
31
  const precisionMultiplier = 10 ** precision;
32
32
  const roundedMin = Math.floor(min * precisionMultiplier);
33
33
  const roundedMax = Math.ceil(max * precisionMultiplier);
34
34
  const delta = roundedMax - roundedMin;
35
35
  const significand = Math.max(1, getBitsForIntegerNumber(delta, SignificandMaxBits));
36
36
  return {
37
+ value,
37
38
  type: DataType.FLOAT,
38
39
  min: roundedMin / precisionMultiplier,
39
40
  max: roundedMax / precisionMultiplier,
40
41
  precision,
41
- significand
42
+ significand,
43
+ name,
44
+ index
42
45
  };
43
46
  };
44
47
 
@@ -46,7 +49,7 @@ var create = (min, max, precision) => {
46
49
  var IntegerMaxBits = 12;
47
50
 
48
51
  // src/factory/intFactory.ts
49
- var create2 = (min, max) => {
52
+ var create2 = (value, min = 0, max = 10, name = "", index = -1) => {
50
53
  if (!Number.isInteger(min) || !Number.isInteger(max))
51
54
  throw new Error("min and max must be integers");
52
55
  if (max - min < 1)
@@ -54,23 +57,26 @@ var create2 = (min, max) => {
54
57
  if (Math.abs(max - min) > 2 ** IntegerMaxBits - 1)
55
58
  throw new Error("max - min must be less than 1024");
56
59
  const bits = getBitsForIntegerNumber(max - min + 1, IntegerMaxBits);
57
- return { type: DataType.INT, min, max, bits };
60
+ return { value, type: DataType.INT, min, max, bits, name, index };
58
61
  };
59
62
 
60
63
  // src/factory/booleanFactory.ts
61
- var create3 = () => ({ type: DataType.BOOLEAN });
64
+ var create3 = (value, name = "", index = -1) => ({ value, type: DataType.BOOLEAN, name, index });
62
65
 
63
66
  // src/factory/versionFactory.ts
64
- var create4 = (bits) => ({
67
+ var create4 = (value, bits = 8, name = "", index = -1) => ({
68
+ value,
65
69
  type: DataType.VERSION,
66
- bits
70
+ bits,
71
+ name,
72
+ index
67
73
  });
68
74
 
69
75
  // src/types/enumData.ts
70
76
  var EnumMaxBits = 8;
71
77
 
72
78
  // src/factory/enumFactory.ts
73
- var create5 = (max) => {
79
+ var create5 = (value, max = 10, name = "", index = -1) => {
74
80
  if (!Number.isInteger(max))
75
81
  throw new Error("min and max must be integers");
76
82
  if (max < 1)
@@ -78,78 +84,17 @@ var create5 = (max) => {
78
84
  if (max > 2 ** EnumMaxBits - 1)
79
85
  throw new Error("max - min must be less than 256");
80
86
  const bits = getBitsForIntegerNumber(max + 1, EnumMaxBits);
81
- return { type: DataType.ENUM, max, bits };
87
+ return { value, type: DataType.ENUM, max, bits, name, index };
82
88
  };
83
89
 
84
90
  // src/factory/factory.ts
85
- class DataRangeDescriptionFactory {
86
- static createFloat = create;
87
- static createInt = create2;
88
- static createEnum = create5;
89
- static createBoolean = create3;
90
- static createVersion = create4;
91
- }
92
-
93
- class DataDescriptionFactory {
94
- static createFloat = (min = 0, max = 1, precision = 2, name = "", index = 0) => ({
95
- ...create(min, max, precision),
96
- name,
97
- index
98
- });
99
- static createInt = (min = 0, max = 10, name = "", index = 0) => ({
100
- ...create2(min, max),
101
- name,
102
- index
103
- });
104
- static createEnum = (max = 10, name = "", index = 0) => ({
105
- ...create5(max),
106
- name,
107
- index
108
- });
109
- static createBoolean = (name = "", index = 0) => ({
110
- ...create3(),
111
- name,
112
- index
113
- });
114
- static createVersion = (bits = 8, name = "", index = 0) => ({
115
- ...create4(bits),
116
- name,
117
- index
118
- });
119
- }
120
-
121
- class DataEntryFactory {
122
- static createFloat = (value, min = 0, max = 1, precision = 2, name = "", index = 0) => ({
123
- ...create(min, max, precision),
124
- value,
125
- name,
126
- index
127
- });
128
- static createInt = (value, min = 0, max = 10, name = "", index = 0) => ({
129
- ...create2(min, max),
130
- value,
131
- name,
132
- index
133
- });
134
- static createEnum = (value, max = 10, name = "", index = 0) => ({
135
- ...create5(max),
136
- value,
137
- name,
138
- index
139
- });
140
- static createBoolean = (value, name = "", index = 0) => ({
141
- ...create3(),
142
- value,
143
- name,
144
- index
145
- });
146
- static createVersion = (value, bits = 8, name = "", index = 0) => ({
147
- ...create4(bits),
148
- value,
149
- name,
150
- index
151
- });
152
- }
91
+ var DataEntryFactory = {
92
+ createFloat: create,
93
+ createInt: create2,
94
+ createEnum: create5,
95
+ createBoolean: create3,
96
+ createVersion: create4
97
+ };
153
98
  // src/parsers/intParser.ts
154
99
  var getBitsCount = (intData2) => intData2.bits;
155
100
  var rawValueParser = (stateString, bitCount) => {
@@ -309,17 +254,20 @@ var dataArrayStringifier = (dataEntryArray) => {
309
254
  };
310
255
 
311
256
  // src/objectmap/versionReading.ts
312
- var parameterOffset = 100;
313
- var nestedDataEntryArrayToObject = (definitionArrayObject, startIndex) => {
314
- const baseIndex = startIndex * parameterOffset;
315
- return Object.fromEntries(definitionArrayObject.map((value, i) => {
257
+ var currentObjectIndex = -1;
258
+ var nestedDataEntryArrayToObject = (definitionArrayObject) => {
259
+ currentObjectIndex = -1;
260
+ return internalNestedDataEntryArrayToObject(definitionArrayObject);
261
+ };
262
+ var internalNestedDataEntryArrayToObject = (definitionArrayObject) => {
263
+ return Object.fromEntries(definitionArrayObject.map((value) => {
316
264
  if (Array.isArray(value)) {
317
265
  if (value.length === 2)
318
- return [value[0], nestedDataEntryArrayToObject(value[1], baseIndex + i)];
266
+ return [value[0], internalNestedDataEntryArrayToObject(value[1])];
319
267
  else
320
- return [value[0], nestedDataEntryArrayToObject(value[2](value[1]), baseIndex + i)];
268
+ return [value[0], internalNestedDataEntryArrayToObject(value[2](value[1]))];
321
269
  }
322
- return [value.name, { ...value, index: baseIndex + i }];
270
+ return [value.name, { ...value, index: ++currentObjectIndex }];
323
271
  }));
324
272
  };
325
273
  var parseDownNestedDataDescription = (nestedDataDescription) => {
@@ -385,19 +333,24 @@ var updateValue6 = (original, update) => {
385
333
  return updateValue2(original, update);
386
334
  case DataType.ENUM:
387
335
  return updateValue3(original, update);
388
- case DataType.VERSION:
389
- return updateValue4(original, update);
390
336
  case DataType.BOOLEAN:
391
337
  return updateValue5(original, update);
338
+ case DataType.VERSION:
339
+ return updateValue4(original, update);
392
340
  }
393
341
  };
394
342
 
395
343
  // src/objectmap/versionUpdate.ts
344
+ var currentObjectIndex2 = 0;
345
+ var findExistingDataEntry = (dataEntry, dataEntryArray) => {
346
+ const dataEntryName = dataEntry.internalName ?? dataEntry.name;
347
+ return dataEntryArray.find((d) => (d.internalName ?? d.name) === dataEntryName);
348
+ };
396
349
  var dataEntryUpdating = (dataEntry, dataEntryArray) => {
397
- const existingDataEntry = dataEntryArray.find((d) => d.name === dataEntry.name);
350
+ const existingDataEntry = findExistingDataEntry(dataEntry, dataEntryArray);
398
351
  if (!existingDataEntry)
399
- return [dataEntry.name, dataEntry];
400
- return [dataEntry.name, updateValue6(dataEntry, existingDataEntry)];
352
+ return [dataEntry.name, { ...dataEntry, index: currentObjectIndex2++ }];
353
+ return [dataEntry.name, { ...updateValue6(dataEntry, existingDataEntry), index: currentObjectIndex2++ }];
401
354
  };
402
355
  var nestedDataEntryArrayUpdating = (definitionNestedArrray, dataEntryArray) => {
403
356
  const [keyString, nestedDefinitionArray] = definitionNestedArrray;
@@ -405,7 +358,7 @@ var nestedDataEntryArrayUpdating = (definitionNestedArrray, dataEntryArray) => {
405
358
  };
406
359
  var generationObjectUpdating = (definitionArrayObject, dataEntryArray) => {
407
360
  const [keyString, keyDataEntry, methodGenerator] = definitionArrayObject;
408
- const foundKeyDataEntry = dataEntryArray.find((d) => d.name === keyDataEntry.name);
361
+ const foundKeyDataEntry = findExistingDataEntry(keyDataEntry, dataEntryArray);
409
362
  const newKeyData = foundKeyDataEntry ? updateValue6(keyDataEntry, foundKeyDataEntry) : keyDataEntry;
410
363
  return [keyString, updateDataEntryObject(methodGenerator(newKeyData), dataEntryArray)];
411
364
  };
@@ -427,15 +380,15 @@ var updateDataEntryObject = (definitionArrayObject, dataArray) => {
427
380
  });
428
381
  return newNestedObject;
429
382
  };
430
- var getDefaultObject = (versionObjects, versionindex) => {
431
- const versionParser = versionObjects[versionindex];
432
- if (!versionParser)
383
+ var getDefaultObject = (versionParser, versionindex) => {
384
+ if (!versionParser.parsers[versionindex])
433
385
  throw new Error(`No parser for version ${versionindex} index`);
434
- return nestedDataEntryArrayToObject(versionParser.objectGeneratorParameters, 0);
386
+ return nestedDataEntryArrayToObject(versionParser.parsers[versionindex].objectGeneratorParameters);
435
387
  };
436
- var updateDataEntry = (data, newDataEntry, versionObjects) => {
388
+ var updateDataEntry = (data, newDataEntry, parsersForVersion) => {
389
+ currentObjectIndex2 = 0;
437
390
  const version = data.version;
438
- const versionParser = versionObjects[version.value];
391
+ const versionParser = parsersForVersion[version.value];
439
392
  if (!versionParser)
440
393
  throw new Error(`No parser for version ${version.value}`);
441
394
  const correctedDataEntry = dataEntryCorrecting(newDataEntry);
@@ -493,7 +446,5 @@ export {
493
446
  ObjectGenerationOutputStatus,
494
447
  IntegerMaxBits,
495
448
  DataType,
496
- DataRangeDescriptionFactory,
497
- DataEntryFactory,
498
- DataDescriptionFactory
449
+ DataEntryFactory
499
450
  };
@@ -6,9 +6,9 @@ export declare const singleLevelContentTypeIsDataEntry: (data: SingleLevelConten
6
6
  export declare const singleLevelContentTypeIsNestedContentDataType: (data: SingleLevelContentType) => boolean;
7
7
  export declare const singleLevelContentTypeIsEnumEntryDataType: (data: NestedContentType) => boolean;
8
8
  export declare const singleLevelContentTypeIsOptionalEntryDataType: (data: NestedContentType) => boolean;
9
- export declare const parseSingleLevelContentTypeToDefinitionSubObject: (data: SingleLevelContentType, currentIndex: number) => [number, DefinitionSubObject];
10
- export declare const parseNestedContentDataTypeToDefinitionNestedArray: (data: NestedContentDataType, currentIndex: number) => [number, DefinitionNestedArray | DefinitionNestedGenerationObject];
11
- export declare const parseEnumEntryDataTypeToDefinitionNestedGenerationObject: (data: EnumEntryDataType, name: string, currentIndex: number) => [number, DefinitionNestedGenerationObject];
12
- export declare const parseOptionalEntryDataTypeToDefinitionNestedGenerationObject: (data: OptionalEntryDataType, name: string, currentIndex: number) => [number, DefinitionNestedGenerationObject];
13
- export declare const parseDataEntry: (d: DataEntry, currentIndex: number) => [number, DataEntry];
9
+ export declare const parseSingleLevelContentTypeToDefinitionSubObject: (data: SingleLevelContentType, internalPrecedingName?: string) => DefinitionSubObject;
10
+ export declare const parseNestedContentDataTypeToDefinitionNestedArray: (data: NestedContentDataType, internalPrecedingName?: string) => DefinitionNestedArray | DefinitionNestedGenerationObject;
11
+ export declare const parseEnumEntryDataTypeToDefinitionNestedGenerationObject: (data: EnumEntryDataType, name: string, internalPrecedingName?: string) => DefinitionNestedGenerationObject;
12
+ export declare const parseOptionalEntryDataTypeToDefinitionNestedGenerationObject: (data: OptionalEntryDataType, name: string, internalPrecedingName?: string) => DefinitionNestedGenerationObject;
13
+ export declare const parseDataEntry: (d: DataEntry, internalPrecedingName?: string) => DataEntry;
14
14
  export declare const parseVersionArrayDefinitionTypeToVersionDefinitionObject: (v: VersionArrayDefinitionType) => VersionDefinitionObject;
@@ -1,6 +1,6 @@
1
- import { DataDescription } from '../types/dataEntry';
2
- import { SemanticlyNestedDataDescription, SemanticlyNestedDataEntry } from '../types/semanticlyNestedDataEntry';
3
- import { DefinitionArrayObject, ParserForVersion } from '../types/versionParser';
1
+ import { DataEntry } from '../types/dataEntry';
2
+ import { SemanticlyNestedDataEntry } from '../types/semanticlyNestedDataEntry';
3
+ import { DefinitionArrayObject, ParsersForVersionObject } from '../types/versionParser';
4
4
  /**
5
5
  * Method for finding the names of the variable data entries in the DefinitionArrayObject
6
6
  * @param definitionArrayObject - DefinitionArrayObject
@@ -10,12 +10,17 @@ export declare const getVariableStrings: (definitionArrayObject: DefinitionArray
10
10
  /**
11
11
  * Method that translates a DefinitionArrayObject into a SemanticlyNestedDataEntry
12
12
  * @param definitionArrayObject [DataEntry | [string, DefinitionArrayObject]]
13
- * @param startIndex
14
13
  * @returns
15
14
  */
16
- export declare const nestedDataEntryArrayToObject: (definitionArrayObject: DefinitionArrayObject, startIndex: number) => SemanticlyNestedDataEntry;
17
- export declare const parseUrlMethod: (url: string, parserVersions: ParserForVersion[]) => SemanticlyNestedDataEntry;
18
- export declare const parseDownNestedDataDescription: (nestedDataDescription: SemanticlyNestedDataDescription) => DataDescription[];
15
+ export declare const nestedDataEntryArrayToObject: (definitionArrayObject: DefinitionArrayObject) => SemanticlyNestedDataEntry;
16
+ /**
17
+ * Method to parse a url into a SemanticlyNestedDataEntry.
18
+ * @param url - the url to parse
19
+ * @param parserVersions - the object containing the version parsers
20
+ * @returns the parsed SemanticlyNestedDataEntry
21
+ */
22
+ export declare const parseUrlMethod: (url: string, parserVersions: ParsersForVersionObject) => SemanticlyNestedDataEntry;
23
+ export declare const parseDownNestedDataDescription: (nestedDataDescription: SemanticlyNestedDataEntry) => DataEntry[];
19
24
  /**
20
25
  * Method to get an URL descriptor from a SemanticlyNestedDataEntry
21
26
  * @param data: SemanticlyNestedDataEntry
@@ -1,6 +1,6 @@
1
1
  import { DataEntry, DataEntryArray } from '../types/dataEntry';
2
2
  import { SemanticlyNestedDataEntry } from '../types/semanticlyNestedDataEntry';
3
- import { DefinitionArrayObject, ParserForVersion } from '../types/versionParser';
3
+ import { DefinitionArrayObject, ParserForVersion, ParsersForVersionObject } from '../types/versionParser';
4
4
  /**
5
5
  * Method to parse a definitionArrayObject according to a given dataArray
6
6
  * @param definitionArrayObject
@@ -8,12 +8,19 @@ import { DefinitionArrayObject, ParserForVersion } from '../types/versionParser'
8
8
  * @returns - new SemanticlyNestedDataEntry
9
9
  */
10
10
  export declare const updateDataEntryObject: (definitionArrayObject: DefinitionArrayObject, dataArray: DataEntryArray) => SemanticlyNestedDataEntry;
11
- export declare const getDefaultObject: (versionObjects: ParserForVersion[], versionindex: number) => SemanticlyNestedDataEntry;
11
+ /**
12
+ * Get the default object for a given version
13
+ * @param versionParser - The parsers for all versions
14
+ * @param versionindex - The index of the version for which to get the default object
15
+ * @returns - The default object for the given version
16
+ * @throws - Error if no parser for the given version index
17
+ */
18
+ export declare const getDefaultObject: (versionParser: ParsersForVersionObject, versionindex: number) => SemanticlyNestedDataEntry;
12
19
  /**
13
20
  * Method that handles the updating of a single value in a SemanticlyNestedDataEntry object
14
21
  * @param data SemanticlyNestedDataEntry
15
22
  * @param newDataEntry updated DataEntry
16
- * @param versionObjects version object
23
+ * @param parsersForVersion version object
17
24
  * @returns a newly created object in case of a key data description, otherwise the same object with just the new Data Entry value updated
18
25
  */
19
- export declare const updateDataEntry: (data: SemanticlyNestedDataEntry, newDataEntry: DataEntry, versionObjects: ParserForVersion[]) => SemanticlyNestedDataEntry;
26
+ export declare const updateDataEntry: (data: SemanticlyNestedDataEntry, newDataEntry: DataEntry, parsersForVersion: ParserForVersion[]) => SemanticlyNestedDataEntry;
@@ -1,14 +1,14 @@
1
- import { DataDescription, DataEntry, DataEntryArray, DataRangeDescription } from '../types/dataEntry';
2
- export declare const valueBitsParser: (bitString: string, mapData: DataRangeDescription) => number | boolean;
3
- export declare const dataBitsParser: (rawString: string, mapData: DataDescription) => DataEntry;
4
- export declare const getBitsCount: (mapData: DataRangeDescription) => number;
1
+ import { DataEntryArray, DataEntry } from '../types/dataEntry';
2
+ export declare const valueBitsParser: (bitString: string, mapData: DataEntry) => number | boolean;
3
+ export declare const dataBitsParser: (rawString: string, mapData: DataEntry) => DataEntry;
4
+ export declare const getBitsCount: (mapData: DataEntry) => number;
5
5
  /**
6
6
  * Method to convert a bitstring into an array of data entries
7
7
  * @param bitString bitstring to parse into bits and then data entries
8
8
  * @param mapDataArray Data descriptions to map the bits to data entries
9
9
  * @returns array of data entries
10
10
  */
11
- export declare const dataBitsArrayParser: (bitString: string, mapDataArray: DataDescription[]) => DataEntryArray;
11
+ export declare const dataBitsArrayParser: (bitString: string, mapDataArray: DataEntry[]) => DataEntryArray;
12
12
  export declare const dataBitsStringifier: (data: DataEntry) => string;
13
13
  export declare const dataEntryCorrecting: (dataEntry: DataEntry) => DataEntry;
14
14
  export declare const parseBitsToBase64: (bits: string) => string;
@@ -1,4 +1,4 @@
1
- import { ParserForVersion } from '../types';
1
+ import { ParsersForVersionObject } from '../types';
2
2
  import { NestedContentDataType, OptionalEntryDataType, EnumEntryDataType, VersionArrayDefinitionType, NestedContentType } from '../types/arrayDefinitions';
3
3
  export declare const nestedContentDataType: NestedContentDataType;
4
4
  export declare const validOptionalEntryType: OptionalEntryDataType;
@@ -11,4 +11,4 @@ export declare const footprintDefinition: EnumEntryDataType;
11
11
  export declare const heightParsingDefinition: NestedContentType;
12
12
  export declare const shapePreProcessingDefinition: EnumEntryDataType;
13
13
  export declare const lucernaeTurici: VersionArrayDefinitionType;
14
- export declare const lucernaeTuriciVersions: ParserForVersion[];
14
+ export declare const lucernaeTuriciVersions: ParsersForVersionObject;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,4 @@
1
- import { DataEntry, VersionDescriptionWithValueType } from './dataEntry';
1
+ import { DataEntry, VersionDataEntry } from './dataEntry';
2
2
  export type SingleLevelContentType = DataEntry | NestedContentDataType;
3
3
  export type NestedContentDataType = [string, NestedContentType];
4
4
  export type NestedContentType = SingleLevelContentType[] | DoubleLevelContentType;
@@ -6,6 +6,6 @@ export type DoubleLevelContentType = OptionalEntryDataType | EnumEntryDataType;
6
6
  export type NonEmptyValidEntryArrayType = [SingleLevelContentType, ...SingleLevelContentType[]];
7
7
  export type OptionalEntryDataType = [boolean, NonEmptyValidEntryArrayType, []] | [boolean, [], NonEmptyValidEntryArrayType];
8
8
  export type EnumEntryDataType = [number, NonEmptyValidEntryArrayType, NonEmptyValidEntryArrayType, ...SingleLevelContentType[][]];
9
- export type VersionArrayDefinitionType = [VersionDescriptionWithValueType, ...SingleLevelContentType[]];
9
+ export type VersionArrayDefinitionType = [VersionDataEntry, ...SingleLevelContentType[]];
10
10
  export declare const INDEX_DELIMETER = "$";
11
11
  export declare const NAME_DELIMETER = "_";
@@ -1,4 +1,5 @@
1
1
  import { DataType } from '../enums/dataTypes';
2
- export interface BooleanData {
2
+ export type BooleanData = {
3
3
  type: DataType.BOOLEAN;
4
- }
4
+ value: boolean;
5
+ };
@@ -6,28 +6,16 @@ import { VersionData } from './versionData';
6
6
  export type Prettify<T> = {
7
7
  [K in keyof T]: T[K];
8
8
  };
9
- export type DataRangeDescription = VersionData | BooleanData | IntData | EnumData | FloatData;
10
- interface DataNamingDescription {
9
+ type DataDescription = {
11
10
  name: string;
11
+ internalName?: string;
12
12
  index: number;
13
- }
14
- export type BooleanDiscriptionType = Prettify<BooleanData & DataNamingDescription>;
15
- export type IntDiscriptionType = Prettify<IntData & DataNamingDescription>;
16
- export type EnumDiscriptionType = Prettify<EnumData & DataNamingDescription>;
17
- export type FloatDiscriptionType = Prettify<FloatData & DataNamingDescription>;
18
- export type VersionDiscriptionType = Prettify<VersionData & DataNamingDescription>;
19
- export type DataDescription = BooleanDiscriptionType | IntDiscriptionType | EnumDiscriptionType | FloatDiscriptionType | VersionDiscriptionType;
20
- interface DataEntryDescriptionBoolean {
21
- value: boolean;
22
- }
23
- interface DataEntryDescriptionNumeric {
24
- value: number;
25
- }
26
- export type BooleanDescriptionWithValueType = Prettify<BooleanData & DataNamingDescription & DataEntryDescriptionBoolean>;
27
- export type IntDescriptionWithValueType = Prettify<IntData & DataNamingDescription & DataEntryDescriptionNumeric>;
28
- export type EnumDescriptionWithValueType = Prettify<EnumData & DataNamingDescription & DataEntryDescriptionNumeric>;
29
- export type FloatDescriptionWithValueType = Prettify<FloatData & DataNamingDescription & DataEntryDescriptionNumeric>;
30
- export type VersionDescriptionWithValueType = Prettify<VersionData & DataNamingDescription & DataEntryDescriptionNumeric>;
31
- export type DataEntry = BooleanDescriptionWithValueType | IntDescriptionWithValueType | EnumDescriptionWithValueType | FloatDescriptionWithValueType | VersionDescriptionWithValueType;
13
+ };
14
+ export type BooleanDataEntry = Prettify<BooleanData & DataDescription>;
15
+ export type IntDataEntry = Prettify<IntData & DataDescription>;
16
+ export type EnumDataEntry = Prettify<EnumData & DataDescription>;
17
+ export type FloatDataEntry = Prettify<FloatData & DataDescription>;
18
+ export type VersionDataEntry = Prettify<VersionData & DataDescription>;
19
+ export type DataEntry = BooleanDataEntry | IntDataEntry | EnumDataEntry | FloatDataEntry | VersionDataEntry;
32
20
  export type DataEntryArray = DataEntry[];
33
21
  export {};
@@ -1,7 +1,8 @@
1
1
  import { DataType } from '../enums/dataTypes';
2
2
  export declare const EnumMaxBits = 8;
3
- export interface EnumData {
3
+ export type EnumData = {
4
4
  type: DataType.ENUM;
5
+ value: number;
5
6
  max: number;
6
7
  bits: number;
7
- }
8
+ };
@@ -1,10 +1,11 @@
1
1
  import { DataType } from '../enums/dataTypes';
2
2
  export type PrecisionRangeType = -3 | -2 | -1 | 0 | 1 | 2 | 3;
3
3
  export declare const SignificandMaxBits = 20;
4
- export interface FloatData {
4
+ export type FloatData = {
5
5
  type: DataType.FLOAT;
6
+ value: number;
6
7
  min: number;
7
8
  max: number;
8
9
  precision: PrecisionRangeType;
9
10
  significand: number;
10
- }
11
+ };
@@ -1,8 +1,9 @@
1
1
  import { DataType } from '../enums/dataTypes';
2
2
  export declare const IntegerMaxBits = 12;
3
- export interface IntData {
3
+ export type IntData = {
4
4
  type: DataType.INT;
5
+ value: number;
5
6
  min: number;
6
7
  max: number;
7
8
  bits: number;
8
- }
9
+ };
@@ -1,7 +1,4 @@
1
- import { DataDescription, DataEntry } from './dataEntry';
1
+ import { DataEntry } from './dataEntry';
2
2
  export type SemanticlyNestedDataEntry = {
3
3
  [key: string]: SemanticlyNestedDataEntry | DataEntry;
4
4
  };
5
- export type SemanticlyNestedDataDescription = {
6
- [key: string]: SemanticlyNestedDataDescription | DataDescription;
7
- };
@@ -1,10 +1,7 @@
1
1
  import { DataType } from '../enums/dataTypes';
2
2
  export type VersionRangeType = 4 | 6 | 8 | 10;
3
- export interface VersionData {
3
+ export type VersionData = {
4
4
  type: DataType.VERSION;
5
+ value: number;
5
6
  bits: VersionRangeType;
6
- }
7
- export interface GlobalVersion {
8
- type: DataType.VERSION;
9
- bits: 8;
10
- }
7
+ };
@@ -1,7 +1,7 @@
1
1
  import { ObjectGenerationOutputStatus } from '../enums/objectGenerationTypes';
2
- import { DataEntry, VersionDiscriptionType } from './dataEntry';
2
+ import { DataEntry, VersionDataEntry } from './dataEntry';
3
3
  import { SemanticlyNestedDataEntry } from './semanticlyNestedDataEntry';
4
- import { GlobalVersion, VersionRangeType } from './versionData';
4
+ import { VersionRangeType } from './versionData';
5
5
  /**
6
6
  * A method that generates a nested object based on a set of values
7
7
  * @param s - url bit string (optional)
@@ -14,7 +14,7 @@ export type DefinitionNestedArray = [string, DefinitionArrayObject];
14
14
  export type DefinitionNestedGenerationObject = [string, DataEntry, DefinitionGenerationObject];
15
15
  export type DefinitionSubObject = DataEntry | DefinitionNestedArray | DefinitionNestedGenerationObject;
16
16
  export type DefinitionArrayObject = DefinitionSubObject[];
17
- export type VersionDefinitionObject = [VersionDiscriptionType, ...DefinitionArrayObject];
17
+ export type VersionDefinitionObject = [VersionDataEntry, ...DefinitionArrayObject];
18
18
  export type VersionEnumSemantics = {
19
19
  [key: string]: {
20
20
  value: number;
@@ -22,13 +22,10 @@ export type VersionEnumSemantics = {
22
22
  }[];
23
23
  };
24
24
  export type ParserForVersion = {
25
- version: number;
26
- versionBitCount: VersionRangeType;
27
- versionName: string;
28
25
  versionEnumSemantics?: VersionEnumSemantics;
29
26
  objectGeneratorParameters: VersionDefinitionObject;
30
27
  };
31
- export type VersionParsers = {
32
- versionRange: GlobalVersion;
33
- versionParsers: ParserForVersion[];
28
+ export type ParsersForVersionObject = {
29
+ versionBitCount: VersionRangeType;
30
+ parsers: ParserForVersion[];
34
31
  };
@@ -1,2 +1,2 @@
1
- import { BooleanDescriptionWithValueType } from '../types/dataEntry';
2
- export declare const updateValue: (original: BooleanDescriptionWithValueType, update: BooleanDescriptionWithValueType) => BooleanDescriptionWithValueType;
1
+ import { BooleanDataEntry } from '../types/dataEntry';
2
+ export declare const updateValue: (original: BooleanDataEntry, update: BooleanDataEntry) => BooleanDataEntry;
@@ -1,2 +1,2 @@
1
- import { EnumDescriptionWithValueType } from '../types/dataEntry';
2
- export declare const updateValue: (original: EnumDescriptionWithValueType, update: EnumDescriptionWithValueType) => EnumDescriptionWithValueType;
1
+ import { EnumDataEntry } from '../types/dataEntry';
2
+ export declare const updateValue: (original: EnumDataEntry, update: EnumDataEntry) => EnumDataEntry;
@@ -1,2 +1,2 @@
1
- import { FloatDescriptionWithValueType } from '../types/dataEntry';
2
- export declare const updateValue: (original: FloatDescriptionWithValueType, update: FloatDescriptionWithValueType) => FloatDescriptionWithValueType;
1
+ import { FloatDataEntry } from '../types/dataEntry';
2
+ export declare const updateValue: (original: FloatDataEntry, update: FloatDataEntry) => FloatDataEntry;
@@ -1,2 +1,2 @@
1
- import { IntDescriptionWithValueType } from '../types/dataEntry';
2
- export declare const updateValue: (original: IntDescriptionWithValueType, update: IntDescriptionWithValueType) => IntDescriptionWithValueType;
1
+ import { IntDataEntry } from '../types/dataEntry';
2
+ export declare const updateValue: (original: IntDataEntry, update: IntDataEntry) => IntDataEntry;
@@ -1,2 +1,2 @@
1
- import { VersionDescriptionWithValueType } from '../types/dataEntry';
2
- export declare const updateValue: (original: VersionDescriptionWithValueType, update: VersionDescriptionWithValueType) => VersionDescriptionWithValueType;
1
+ import { VersionDataEntry } from '../types/dataEntry';
2
+ export declare const updateValue: (original: VersionDataEntry, update: VersionDataEntry) => VersionDataEntry;
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  "dist/*"
8
8
  ],
9
9
  "type": "module",
10
- "version": "0.1.4",
10
+ "version": "0.1.6",
11
11
  "author": "Jonas Ward",
12
12
  "description": "Library for creating web safe base64 objects with custom bith widths and dynamic values.",
13
13
  "scripts": {