@streamline-pulse/formkrafter-core 0.29.0 → 0.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +2 -0
- package/dist/index.js +215 -3
- package/dist/index.js.map +9 -7
- package/dist/utils/registries.d.ts +21 -0
- package/dist/utils/units.d.ts +32 -0
- package/package.json +1 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public registries: vehicle plates and company registration numbers, each
|
|
3
|
+
* checked against a named format (per country, or a generic one).
|
|
4
|
+
*/
|
|
5
|
+
interface Format {
|
|
6
|
+
id: string;
|
|
7
|
+
label: string;
|
|
8
|
+
/** Tested against the compacted, upper-cased value. */
|
|
9
|
+
test: (value: string) => boolean;
|
|
10
|
+
/** Display form of a valid value (compacted input). */
|
|
11
|
+
format?: (value: string) => string;
|
|
12
|
+
}
|
|
13
|
+
export declare const PLATE_FORMATS: Format[];
|
|
14
|
+
export declare const REGISTRY_FORMATS: Format[];
|
|
15
|
+
/** Compact form kept in the data for plates (letters and digits only, upper case). */
|
|
16
|
+
export declare const compactPlate: (value: string) => string;
|
|
17
|
+
export declare function checkPlate(format: string, value: string): boolean;
|
|
18
|
+
export declare function formatPlate(format: string, value: string): string;
|
|
19
|
+
export declare function checkCompanyRegistry(format: string, value: string): boolean;
|
|
20
|
+
export declare function formatCompanyRegistry(format: string, value: string): string;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Measures: a number with a unit, kept with its value in the family's base
|
|
3
|
+
* unit so sums and averages stay meaningful whatever unit each answer used.
|
|
4
|
+
*/
|
|
5
|
+
export type MeasureFamily = "length" | "area" | "mass" | "volume" | "duration";
|
|
6
|
+
export interface MeasureUnit {
|
|
7
|
+
id: string;
|
|
8
|
+
/** Symbol shown to the user. */
|
|
9
|
+
symbol: string;
|
|
10
|
+
/** Multiply a value in this unit by `factor` to get the family's base unit. */
|
|
11
|
+
factor: number;
|
|
12
|
+
}
|
|
13
|
+
export interface MeasureValue {
|
|
14
|
+
value: number;
|
|
15
|
+
unit: string;
|
|
16
|
+
/** `value` converted to the family's base unit. */
|
|
17
|
+
base: number;
|
|
18
|
+
}
|
|
19
|
+
export declare const MEASURE_FAMILIES: Record<MeasureFamily, {
|
|
20
|
+
base: string;
|
|
21
|
+
units: MeasureUnit[];
|
|
22
|
+
}>;
|
|
23
|
+
export declare const measureFamilyOf: (value: unknown) => MeasureFamily;
|
|
24
|
+
/** The units of a family, restricted to `allowed` (comma-separated ids) when given. */
|
|
25
|
+
export declare function measureUnits(family: MeasureFamily, allowed?: unknown): MeasureUnit[];
|
|
26
|
+
export declare function unitOf(family: MeasureFamily, id: string): MeasureUnit | undefined;
|
|
27
|
+
/** Converts between two units of the same family; `undefined` when a unit is unknown. */
|
|
28
|
+
export declare function convertMeasure(family: MeasureFamily, value: number, from: string, to: string): number | undefined;
|
|
29
|
+
/** Builds the stored value: the number, its unit and the base-unit equivalent. */
|
|
30
|
+
export declare function measureValue(family: MeasureFamily, value: number, unit: string): MeasureValue | undefined;
|
|
31
|
+
/** Human form, e.g. `2,5 ha`. */
|
|
32
|
+
export declare function formatMeasure(family: MeasureFamily, value: MeasureValue | undefined, locale?: string): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamline-pulse/formkrafter-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.0",
|
|
4
4
|
"description": "Framework-agnostic core for FormKrafter: form specs, RFC 6902 ops with undo/redo, Ajv validation, sandboxed rules engine and injectable services",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|