url-safe-bitpacking 0.1.12 → 0.1.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.
- package/README.md +7 -9
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -2
- package/dist/types/stateValueModel.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -11,16 +11,14 @@ Package for creating definitions of parametric models that can be stored as comp
|
|
|
11
11
|
| updating model entries | ✓ | ✓ | |
|
|
12
12
|
| re-using data from old model on change in definition | ½ | ¼ | |
|
|
13
13
|
| flattening and reading of the objects | ✓ | ✓ | ¿ |
|
|
14
|
+
| arrays (both bit-level as arrays of objects) | ½ | ½ | |
|
|
15
|
+
| utility to create StateValueType | | | |
|
|
14
16
|
|
|
15
17
|
## concept
|
|
16
18
|
|
|
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.
|
|
19
|
+
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. The library heavily relies on the bitpacking of custom bitwidth numeric values. Because of that, the biggest trade-off for this library is legibility. Without the related object definition, it would be impossible to reconstruct the state. The big advantage though is the ability to store rather many variables in a very condensed URL, allowing to store all information in rather short urls which then can be used for qr code generation.
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
The big advantage though is the ability to store rather many variables in a very condensed URL, allowing to store all information in rather short urls which then can be used for qr code generation.
|
|
22
|
-
|
|
23
|
-
## data types
|
|
21
|
+
## bit-level data types
|
|
24
22
|
|
|
25
23
|
Currently, there are 4 data types implemented (+1 special case for safety). All data entries have a name that will behave as an attribute name in the object.
|
|
26
24
|
|
|
@@ -64,11 +62,11 @@ There is also a Version object which is a special case of the enum data type and
|
|
|
64
62
|
DataEntryFactory.createVersion(0, 8, 'version');
|
|
65
63
|
```
|
|
66
64
|
|
|
67
|
-
## attribute
|
|
65
|
+
## nested attribute definitions
|
|
68
66
|
|
|
69
|
-
|
|
67
|
+
More often than not in parametric models, certain data belongs together. It can also happen that the specific state of some values will have an impact on other ones being present (or which ranges are allowed). To be able to deal with this there is the option to nest data. I tried to come with an as concise yet versatile way of defining the object definitions.
|
|
70
68
|
|
|
71
|
-
|
|
69
|
+
### single nes
|
|
72
70
|
|
|
73
71
|
For the Double Nested arrays there are currently two variations: either an Optional type, which only accepts two values of which is an empty array and will be toggle on/off in relation to a certain boolean data entry.
|
|
74
72
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { DataType } from './enums';
|
|
2
2
|
export { DataEntryFactory } from './factory';
|
|
3
|
-
export { SingleLevelContentType, NestedContentDataType, NestedContentType, DoubleLevelContentType, NonEmptyValidEntryArrayType, OptionalEntryDataType, EnumEntryDataType, PrecisionRangeType, SignificandMaxBits, FloatData, IntegerMaxBits, IntData, VersionRangeType, VersionData, BooleanData, DataEntry, DataEntryArray, } from './types';
|
|
4
|
-
export { createParserObject, getStateValue, getBase64String } from './objectmap';
|
|
3
|
+
export { SingleLevelContentType, NestedContentDataType, NestedContentType, DoubleLevelContentType, NonEmptyValidEntryArrayType, OptionalEntryDataType, EnumEntryDataType, PrecisionRangeType, SignificandMaxBits, FloatData, IntegerMaxBits, IntData, VersionRangeType, VersionData, BooleanData, DataEntry, DataEntryArray, StateDataType, StateValueType, EnumSemantics, DerivativeStateDataType, } from './types';
|
|
4
|
+
export { createParserObject, getStateValue, getBase64String, getDataEntryArray } from './objectmap';
|
|
5
5
|
export { parseBase64ToBits } from './parsers';
|
|
6
6
|
export { interpolateEntryAt, getRelativeValue } from './utils';
|
package/dist/index.js
CHANGED
|
@@ -459,7 +459,7 @@ var getStateDataFromSingleLevelContentType = (slct, prefix) => {
|
|
|
459
459
|
if (singleLevelContentTypeIsDataEntry(slct))
|
|
460
460
|
return (additionalData) => internalGetDataEntry(slct, prefix, additionalData);
|
|
461
461
|
else if (singleLevelContentTypeIsNestedContentDataType(slct))
|
|
462
|
-
return getStateDataFromNestedContentType(slct[1], prefix
|
|
462
|
+
return getStateDataFromNestedContentType(slct[1], `${prefix}_${slct[0]}`, slct[0]);
|
|
463
463
|
throw new Error("this is an invalid output value, wonder why?");
|
|
464
464
|
};
|
|
465
465
|
var getGenerationMethodForSingleLevelContentTypeArray = (slct) => {
|
|
@@ -488,7 +488,7 @@ var getParserMethodForVersionDefinition = (vadt, versionBits, defaultVersion) =>
|
|
|
488
488
|
const versionEntry = DataEntryFactory.createVersion(versionIndex, versionBits, "version");
|
|
489
489
|
return getGenerationMethodForSingleLevelContentTypeArray([versionEntry, ...versionDefinition])(additionalData);
|
|
490
490
|
};
|
|
491
|
-
var getUpdaterMethodForVersionDefinition = (parser) => (state, entryToUpdate) => parser([entryToUpdate, ...getDataEntryArray(state)]);
|
|
491
|
+
var getUpdaterMethodForVersionDefinition = (parser) => (state, entryToUpdate) => parser([...Array.isArray(entryToUpdate) ? entryToUpdate : [entryToUpdate], ...getDataEntryArray(state)]);
|
|
492
492
|
var getStringifyMethodForVersionDefinition = (parser) => (data) => getBase64String(parser(data));
|
|
493
493
|
var createParserObject = (versionContent, maximumExpectedVersions, defaultVersion, enumSemanticsMapping, attributeSemanticsMapping, exposedVersions) => {
|
|
494
494
|
const versionBitCount = getVersionValueRangeValueForNumber(maximumExpectedVersions);
|
|
@@ -547,6 +547,7 @@ export {
|
|
|
547
547
|
interpolateEntryAt,
|
|
548
548
|
getStateValue,
|
|
549
549
|
getRelativeValue,
|
|
550
|
+
getDataEntryArray,
|
|
550
551
|
getBase64String,
|
|
551
552
|
createParserObject,
|
|
552
553
|
SignificandMaxBits,
|
|
@@ -19,7 +19,7 @@ export type StateDataGenerationMethod = (additionalData?: DataEntryArray | strin
|
|
|
19
19
|
export type DataEntryParsingReturnType = [DataEntryArray | string | undefined, [string, DataEntry]];
|
|
20
20
|
export type InternalStateDataGenerationMethod = (additionalData?: DataEntryArray | string) => [DataEntryArray | string | undefined, [string, DataEntry | StateDataType | DerivativeStateDataType]];
|
|
21
21
|
export type ExposedParserStateDataMethod = (additionalData?: StateDataType | DataEntryArray | string) => StateDataType;
|
|
22
|
-
export type UpdateStateDataMethod = (state: StateDataType, entryToUpdate: DataEntry) => StateDataType;
|
|
22
|
+
export type UpdateStateDataMethod = (state: StateDataType, entryToUpdate: DataEntry | DataEntry[]) => StateDataType;
|
|
23
23
|
export type StringifyStateDataMethod = (data: StateDataType | DataEntryArray) => string;
|
|
24
24
|
export type VersionContentDefinition = SingleLevelContentType[][];
|
|
25
25
|
export type VersionHandler = {
|