@budiauktioner/buildi-primitives 0.2.0 → 0.2.1
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/CHANGELOG.md +12 -0
- package/PARITY.md +1 -1
- package/dist/cjs/internal/scan-boundaries.js +26 -0
- package/dist/cjs/internal/scan-boundaries.js.map +7 -0
- package/dist/cjs/measurement/area.js +2 -1
- package/dist/cjs/measurement/area.js.map +2 -2
- package/dist/cjs/measurement/data-size.js +1 -1
- package/dist/cjs/measurement/data-size.js.map +1 -1
- package/dist/cjs/measurement/electric-charge.js +1 -1
- package/dist/cjs/measurement/electric-charge.js.map +1 -1
- package/dist/cjs/measurement/electric-current.js +1 -1
- package/dist/cjs/measurement/electric-current.js.map +1 -1
- package/dist/cjs/measurement/energy.js +1 -1
- package/dist/cjs/measurement/energy.js.map +1 -1
- package/dist/cjs/measurement/flow-rate.js +1 -1
- package/dist/cjs/measurement/flow-rate.js.map +1 -1
- package/dist/cjs/measurement/frequency.js +1 -1
- package/dist/cjs/measurement/frequency.js.map +1 -1
- package/dist/cjs/measurement/length.js +1 -1
- package/dist/cjs/measurement/length.js.map +1 -1
- package/dist/cjs/measurement/luminance.js +1 -1
- package/dist/cjs/measurement/luminance.js.map +1 -1
- package/dist/cjs/measurement/luminous-flux.js +4 -1
- package/dist/cjs/measurement/luminous-flux.js.map +2 -2
- package/dist/cjs/measurement/percentage.js +1 -1
- package/dist/cjs/measurement/percentage.js.map +1 -1
- package/dist/cjs/measurement/power.js +7 -3
- package/dist/cjs/measurement/power.js.map +2 -2
- package/dist/cjs/measurement/pressure.js +1 -1
- package/dist/cjs/measurement/pressure.js.map +1 -1
- package/dist/cjs/measurement/rotational-speed.js +1 -1
- package/dist/cjs/measurement/rotational-speed.js.map +1 -1
- package/dist/cjs/measurement/sound-level.js +5 -1
- package/dist/cjs/measurement/sound-level.js.map +2 -2
- package/dist/cjs/measurement/speed.js +1 -1
- package/dist/cjs/measurement/speed.js.map +1 -1
- package/dist/cjs/measurement/temperature.js +1 -1
- package/dist/cjs/measurement/temperature.js.map +2 -2
- package/dist/cjs/measurement/torque.js +1 -1
- package/dist/cjs/measurement/torque.js.map +1 -1
- package/dist/cjs/measurement/voltage.js +1 -1
- package/dist/cjs/measurement/voltage.js.map +1 -1
- package/dist/cjs/measurement/volume.js +1 -1
- package/dist/cjs/measurement/volume.js.map +1 -1
- package/dist/cjs/measurement/weight.js +1 -1
- package/dist/cjs/measurement/weight.js.map +1 -1
- package/dist/esm/internal/scan-boundaries.js +6 -0
- package/dist/esm/internal/scan-boundaries.js.map +7 -0
- package/dist/esm/measurement/area.js +2 -1
- package/dist/esm/measurement/area.js.map +2 -2
- package/dist/esm/measurement/data-size.js +1 -1
- package/dist/esm/measurement/data-size.js.map +1 -1
- package/dist/esm/measurement/electric-charge.js +1 -1
- package/dist/esm/measurement/electric-charge.js.map +1 -1
- package/dist/esm/measurement/electric-current.js +1 -1
- package/dist/esm/measurement/electric-current.js.map +1 -1
- package/dist/esm/measurement/energy.js +1 -1
- package/dist/esm/measurement/energy.js.map +1 -1
- package/dist/esm/measurement/flow-rate.js +1 -1
- package/dist/esm/measurement/flow-rate.js.map +1 -1
- package/dist/esm/measurement/frequency.js +1 -1
- package/dist/esm/measurement/frequency.js.map +1 -1
- package/dist/esm/measurement/length.js +1 -1
- package/dist/esm/measurement/length.js.map +1 -1
- package/dist/esm/measurement/luminance.js +1 -1
- package/dist/esm/measurement/luminance.js.map +1 -1
- package/dist/esm/measurement/luminous-flux.js +4 -1
- package/dist/esm/measurement/luminous-flux.js.map +2 -2
- package/dist/esm/measurement/percentage.js +1 -1
- package/dist/esm/measurement/percentage.js.map +1 -1
- package/dist/esm/measurement/power.js +7 -3
- package/dist/esm/measurement/power.js.map +2 -2
- package/dist/esm/measurement/pressure.js +1 -1
- package/dist/esm/measurement/pressure.js.map +1 -1
- package/dist/esm/measurement/rotational-speed.js +1 -1
- package/dist/esm/measurement/rotational-speed.js.map +1 -1
- package/dist/esm/measurement/sound-level.js +5 -1
- package/dist/esm/measurement/sound-level.js.map +2 -2
- package/dist/esm/measurement/speed.js +1 -1
- package/dist/esm/measurement/speed.js.map +1 -1
- package/dist/esm/measurement/temperature.js +1 -1
- package/dist/esm/measurement/temperature.js.map +2 -2
- package/dist/esm/measurement/torque.js +1 -1
- package/dist/esm/measurement/torque.js.map +1 -1
- package/dist/esm/measurement/voltage.js +1 -1
- package/dist/esm/measurement/voltage.js.map +1 -1
- package/dist/esm/measurement/volume.js +1 -1
- package/dist/esm/measurement/volume.js.map +1 -1
- package/dist/esm/measurement/weight.js +1 -1
- package/dist/esm/measurement/weight.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,18 @@ All notable changes to the TypeScript port of `Buildi.Primitives` will be
|
|
|
4
4
|
documented here. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
5
5
|
and this package adheres to [Semantic Versioning](https://semver.org/).
|
|
6
6
|
|
|
7
|
+
## [0.2.1] - 2026-08-07
|
|
8
|
+
|
|
9
|
+
### Fixed
|
|
10
|
+
|
|
11
|
+
- The 21 `Measurement` scanners matched on ASCII word boundaries, so a unit
|
|
12
|
+
abbreviation followed by a non-ASCII letter ended the match and produced a
|
|
13
|
+
false positive. In Swedish prose this was common enough to matter:
|
|
14
|
+
`24 månader` scanned as `24 m`, `3 tågresor` as `3 t`, and `123 väger` as
|
|
15
|
+
`123 V`. They now use Unicode-aware boundaries, matching .NET, where `\b`
|
|
16
|
+
is Unicode-aware already. `Vehicle` and `Product` scanners were already
|
|
17
|
+
correct; this closes the same gap in `Measurement`.
|
|
18
|
+
|
|
7
19
|
## [0.2.0] - 2026-08-07
|
|
8
20
|
|
|
9
21
|
### Added
|
package/PARITY.md
CHANGED
|
@@ -8,7 +8,7 @@ exactly how much of that surface is implemented here.
|
|
|
8
8
|
| | |
|
|
9
9
|
| ----------------- | -------------------------- |
|
|
10
10
|
| .NET baseline | `Buildi.Primitives` 0.21.0 |
|
|
11
|
-
| This package | `0.2.
|
|
11
|
+
| This package | `0.2.1` |
|
|
12
12
|
| Namespaces ported | 13 of 13 |
|
|
13
13
|
| Types ported | 200 of 200 |
|
|
14
14
|
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var scan_boundaries_exports = {};
|
|
20
|
+
__export(scan_boundaries_exports, {
|
|
21
|
+
WORD_BOUNDARY: () => WORD_BOUNDARY
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(scan_boundaries_exports);
|
|
24
|
+
const WORD = String.raw`[\p{L}\p{N}_]`;
|
|
25
|
+
const WORD_BOUNDARY = String.raw`(?:(?<=${WORD})(?!${WORD})|(?<!${WORD})(?=${WORD}))`;
|
|
26
|
+
//# sourceMappingURL=scan-boundaries.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/internal/scan-boundaries.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * The Unicode-aware equivalent of a trailing `\\b` for the scanner patterns.\n *\n * JavaScript's `\\b` and `\\w` are ASCII-only even under `/u`, so `24 m` inside\n * `24 m\u00E5nader` looks like a complete match. .NET's are Unicode-aware, and .NET\n * is the behavioural spec.\n *\n * Where a unit ends in a letter or digit \u2014 which is all of them but one \u2014\n * `(?![\\p{L}\\p{N}_])` says the same thing, and the patterns use that directly.\n * This constant exists for the sound level `dB(A)` form, which ends in `)`. A\n * word boundary is a *transition*, not a plain lookahead: after a non-word\n * character it demands that the next character *be* a word character. That is\n * why .NET reads `69 dB(A) vid drift` as `69 dB` rather than `69 dB(A)`, and\n * the vectors generated from it expect exactly that.\n *\n * Internal; not re-exported publicly.\n */\n\nconst WORD = String.raw`[\\p{L}\\p{N}_]`;\n\nexport const WORD_BOUNDARY = String.raw`(?:(?<=${WORD})(?!${WORD})|(?<!${WORD})(?=${WORD}))`;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBA,MAAM,OAAO,OAAO;AAEb,MAAM,gBAAgB,OAAO,aAAa,IAAI,OAAO,IAAI,SAAS,IAAI,OAAO,IAAI;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -28,8 +28,9 @@ var import_text_candidate = require("../text-scanning/text-candidate.js");
|
|
|
28
28
|
var import_text_candidate_category = require("../text-scanning/text-candidate-category.js");
|
|
29
29
|
var import_text_match_confidence = require("../text-scanning/text-match-confidence.js");
|
|
30
30
|
var import_area_unit = require("./area-unit.js");
|
|
31
|
+
const B = String.raw`(?![\p{L}\p{N}_])`;
|
|
31
32
|
const SCAN_PATTERN = new RegExp(
|
|
32
|
-
String.raw`(
|
|
33
|
+
String.raw`(?<![\p{L}\p{N}_])(?:[+-]\s*)?\d+[0-9 .,]*\s*(?:(?:mm|cm|km|m)(?:²|2)|ha${B}|hectare${B}|hectares${B}|hektar${B}|acre${B}|acres${B}|sq\s*ft${B}|sq\s*in${B}|sq\s*yd${B}|kvadrat(?:millimeter|centimeter|meter|kilometer|fot|tum|yard)${B})`,
|
|
33
34
|
"giu"
|
|
34
35
|
);
|
|
35
36
|
class Area extends import_quantity.Quantity {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/measurement/area.ts"],
|
|
4
|
-
"sourcesContent": ["import { Decimal } from \"../internal/decimal.js\";\nimport type { MeasurementUnitIndex } from \"../internal/measurement-unit.js\";\nimport { Quantity, tryParseQuantity } from \"../internal/quantity.js\";\nimport type { PrimitiveTypeInfo } from \"../primitive-type-info.js\";\nimport { TextCandidate } from \"../text-scanning/text-candidate.js\";\nimport { TextCandidateCategory } from \"../text-scanning/text-candidate-category.js\";\nimport { TextMatchConfidence } from \"../text-scanning/text-match-confidence.js\";\nimport { AreaUnit } from \"./area-unit.js\";\n\n/** Options for {@link Area.format} and {@link Area.normalize}. */\nexport interface AreaFormatOptions {\n fallbackToTrimmedInputWhenInvalid?: boolean;\n /** Convert to this unit instead of preserving the parsed one. */\n unit?: AreaUnit;\n /** Round to this many fractional digits, away from zero. */\n decimals?: number;\n}\n\nconst SCAN_PATTERN = new RegExp(\n String.raw`(
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAwB;AAExB,sBAA2C;AAE3C,4BAA8B;AAC9B,qCAAsC;AACtC,mCAAoC;AACpC,uBAAyB;
|
|
4
|
+
"sourcesContent": ["import { Decimal } from \"../internal/decimal.js\";\nimport type { MeasurementUnitIndex } from \"../internal/measurement-unit.js\";\nimport { Quantity, tryParseQuantity } from \"../internal/quantity.js\";\nimport type { PrimitiveTypeInfo } from \"../primitive-type-info.js\";\nimport { TextCandidate } from \"../text-scanning/text-candidate.js\";\nimport { TextCandidateCategory } from \"../text-scanning/text-candidate-category.js\";\nimport { TextMatchConfidence } from \"../text-scanning/text-match-confidence.js\";\nimport { AreaUnit } from \"./area-unit.js\";\n\n/** Options for {@link Area.format} and {@link Area.normalize}. */\nexport interface AreaFormatOptions {\n fallbackToTrimmedInputWhenInvalid?: boolean;\n /** Convert to this unit instead of preserving the parsed one. */\n unit?: AreaUnit;\n /** Round to this many fractional digits, away from zero. */\n decimals?: number;\n}\n\n// Only the spelled-out units take a boundary; the `m\u00B2` and `m2` forms end in a\n// character that already terminates the match, as in .NET.\nconst B = String.raw`(?![\\p{L}\\p{N}_])`;\n\nconst SCAN_PATTERN = new RegExp(\n String.raw`(?<![\\p{L}\\p{N}_])(?:[+-]\\s*)?\\d+[0-9 .,]*\\s*(?:(?:mm|cm|km|m)(?:\u00B2|2)|ha${B}|hectare${B}|hectares${B}|hektar${B}|acre${B}|acres${B}|sq\\s*ft${B}|sq\\s*in${B}|sq\\s*yd${B}|kvadrat(?:millimeter|centimeter|meter|kilometer|fot|tum|yard)${B})`,\n \"giu\",\n);\n\n/**\n * A area stored internally in square meters,\n * parsed from any supported unit and convertible between all of them.\n */\nexport class Area extends Quantity<AreaUnit> {\n static readonly typeInfo: PrimitiveTypeInfo = Object.freeze({\n englishName: \"Area\",\n localizedName: \"Yta\",\n emoji: \"\uD83D\uDCD0\",\n sources: Object.freeze([\n \"https://www.bipm.org/en/measurement-units/si-base-units\",\n \"https://en.wikipedia.org/wiki/Conversion_of_units\",\n ]),\n });\n\n protected get units(): MeasurementUnitIndex<AreaUnit> {\n return AreaUnit.index;\n }\n\n protected withBaseValue(baseValue: Decimal, unit: AreaUnit): this {\n return new Area(baseValue, unit) as this;\n }\n\n get squareMillimeters(): number {\n return this.in(AreaUnit.SquareMillimeter);\n }\n get squareCentimeters(): number {\n return this.in(AreaUnit.SquareCentimeter);\n }\n get squareMeters(): number {\n return this.in(AreaUnit.SquareMeter);\n }\n get squareKilometers(): number {\n return this.in(AreaUnit.SquareKilometer);\n }\n get hectares(): number {\n return this.in(AreaUnit.Hectare);\n }\n get acres(): number {\n return this.in(AreaUnit.Acre);\n }\n get squareFeet(): number {\n return this.in(AreaUnit.SquareFoot);\n }\n get squareInches(): number {\n return this.in(AreaUnit.SquareInch);\n }\n get squareYards(): number {\n return this.in(AreaUnit.SquareYard);\n }\n\n /** Creates a area from a value and unit. */\n static create(value: number | Decimal, unit: AreaUnit): Area {\n AreaUnit.index.assertOwns(unit);\n const amount = value instanceof Decimal ? value : Area.decimalOf(value);\n return new Area(unit.toBase(amount), unit);\n }\n\n static fromSquareMillimeters(value: number | Decimal): Area {\n return Area.create(value, AreaUnit.SquareMillimeter);\n }\n static fromSquareCentimeters(value: number | Decimal): Area {\n return Area.create(value, AreaUnit.SquareCentimeter);\n }\n static fromSquareMeters(value: number | Decimal): Area {\n return Area.create(value, AreaUnit.SquareMeter);\n }\n static fromSquareKilometers(value: number | Decimal): Area {\n return Area.create(value, AreaUnit.SquareKilometer);\n }\n static fromHectares(value: number | Decimal): Area {\n return Area.create(value, AreaUnit.Hectare);\n }\n static fromAcres(value: number | Decimal): Area {\n return Area.create(value, AreaUnit.Acre);\n }\n static fromSquareFeet(value: number | Decimal): Area {\n return Area.create(value, AreaUnit.SquareFoot);\n }\n static fromSquareInches(value: number | Decimal): Area {\n return Area.create(value, AreaUnit.SquareInch);\n }\n static fromSquareYards(value: number | Decimal): Area {\n return Area.create(value, AreaUnit.SquareYard);\n }\n\n static tryParse(input: string | null | undefined): Area | null {\n const parsed = tryParseQuantity(input, AreaUnit.index);\n return parsed === null ? null : new Area(parsed.baseValue, parsed.unit);\n }\n\n static parse(input: string): Area {\n const result = Area.tryParse(input);\n if (result === null) throw new Error(\"Invalid area.\");\n return result;\n }\n\n static isValid(input: string | null | undefined): boolean {\n return Area.tryParse(input) !== null;\n }\n\n /** Display form in the parsed unit, or `null` when the input is invalid. */\n static format(input: string | null | undefined, options?: AreaFormatOptions): string | null {\n const parsed = Area.tryParse(input);\n if (parsed !== null) {\n if (options?.unit !== undefined || options?.decimals !== undefined) {\n return parsed.toStringInUnit(options.unit ?? parsed.originalUnit, options.decimals);\n }\n return parsed.toString();\n }\n return Area.fallback(input, options);\n }\n\n /** The value in square meters, or `null` when the input is invalid. */\n static normalize(input: string | null | undefined, options?: AreaFormatOptions): string | null {\n const parsed = Area.tryParse(input);\n if (parsed !== null) return parsed.toNormalizedString();\n return Area.fallback(input, options);\n }\n\n static isNormalized(input: string | null | undefined): boolean {\n return input != null && Area.normalize(input) === input;\n }\n\n static findCandidatesInText(text: string): readonly TextCandidate<Area>[] {\n if (!text) return [];\n\n const out: TextCandidate<Area>[] = [];\n const pattern = new RegExp(SCAN_PATTERN.source, SCAN_PATTERN.flags);\n let match: RegExpExecArray | null;\n\n while ((match = pattern.exec(text)) !== null) {\n const value = Area.tryParse(match[0]);\n if (value === null) continue;\n out.push(\n new TextCandidate<Area>({\n startIndex: match.index,\n length: match[0].length,\n originalText: match[0],\n typeName: \"Area\",\n category: TextCandidateCategory.Measurement,\n normalizedForm: value.toNormalizedString(),\n formattedForm: value.toString(),\n maskedForm: maskArea(value),\n confidence: TextMatchConfidence.Medium,\n value,\n }),\n );\n }\n\n return out;\n }\n\n private static fallback(\n input: string | null | undefined,\n options?: AreaFormatOptions,\n ): string | null {\n if (options?.fallbackToTrimmedInputWhenInvalid !== true) return null;\n if (input == null) return null;\n const trimmed = input.trim();\n return trimmed.length > 0 ? trimmed : null;\n }\n\n private static decimalOf(value: number): Decimal {\n const parsed = Decimal.fromNumber(value);\n if (parsed === null) throw new Error(`Value cannot be represented as a area: ${value}`);\n return parsed;\n }\n}\n\n/** Returns a masked area, e.g. `10 m\u00B2` becomes `*** m\u00B2`. */\nexport function maskArea(value: Area): string {\n return `*** ${value.originalUnit.symbol}`;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAwB;AAExB,sBAA2C;AAE3C,4BAA8B;AAC9B,qCAAsC;AACtC,mCAAoC;AACpC,uBAAyB;AAazB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e,MAAM,SAAS;AAAA,UAC9B,YAAY,SAAS,KAAK;AAAA,UAC1B,YAAY,iDAAoB;AAAA,UAChC;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,OAAe,SACb,OACA,SACe;AACf,QAAI,SAAS,sCAAsC,KAAM,QAAO;AAChE,QAAI,SAAS,KAAM,QAAO;AAC1B,UAAM,UAAU,MAAM,KAAK;AAC3B,WAAO,QAAQ,SAAS,IAAI,UAAU;AAAA,EACxC;AAAA,EAEA,OAAe,UAAU,OAAwB;AAC/C,UAAM,SAAS,uBAAQ,WAAW,KAAK;AACvC,QAAI,WAAW,KAAM,OAAM,IAAI,MAAM,0CAA0C,KAAK,EAAE;AACtF,WAAO;AAAA,EACT;AACF;AAGO,SAAS,SAAS,OAAqB;AAC5C,SAAO,OAAO,MAAM,aAAa,MAAM;AACzC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -29,7 +29,7 @@ var import_text_candidate_category = require("../text-scanning/text-candidate-ca
|
|
|
29
29
|
var import_text_match_confidence = require("../text-scanning/text-match-confidence.js");
|
|
30
30
|
var import_data_size_unit = require("./data-size-unit.js");
|
|
31
31
|
const SCAN_PATTERN = new RegExp(
|
|
32
|
-
String.raw`(
|
|
32
|
+
String.raw`(?<![\p{L}\p{N}_])(?:[+-]\s*)?\d+[0-9 .,]*\s*(?:exbibytes|exbibyte|exabytes|exabyte|pebibytes|pebibyte|petabytes|petabyte|tebibytes|tebibyte|terabytes|terabyte|gibibytes|gibibyte|gigabytes|gigabyte|mebibytes|mebibyte|megabytes|megabyte|kibibytes|kibibyte|kilobytes|kilobyte|EiB|PiB|TiB|GiB|MiB|KiB|EB|PB|TB|GB|MB|KB|bytes|byte|B)(?![\p{L}\p{N}_])`,
|
|
33
33
|
"giu"
|
|
34
34
|
);
|
|
35
35
|
class DataSize extends import_quantity.Quantity {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/measurement/data-size.ts"],
|
|
4
|
-
"sourcesContent": ["import { Decimal } from \"../internal/decimal.js\";\nimport type { MeasurementUnitIndex } from \"../internal/measurement-unit.js\";\nimport { Quantity, tryParseQuantity } from \"../internal/quantity.js\";\nimport type { PrimitiveTypeInfo } from \"../primitive-type-info.js\";\nimport { TextCandidate } from \"../text-scanning/text-candidate.js\";\nimport { TextCandidateCategory } from \"../text-scanning/text-candidate-category.js\";\nimport { TextMatchConfidence } from \"../text-scanning/text-match-confidence.js\";\nimport { DataSizeUnit } from \"./data-size-unit.js\";\n\n/** Options for {@link DataSize.format} and {@link DataSize.normalize}. */\nexport interface DataSizeFormatOptions {\n fallbackToTrimmedInputWhenInvalid?: boolean;\n /** Convert to this unit instead of preserving the parsed one. */\n unit?: DataSizeUnit;\n /** Round to this many fractional digits, away from zero. */\n decimals?: number;\n}\n\nconst SCAN_PATTERN = new RegExp(\n String.raw`(
|
|
4
|
+
"sourcesContent": ["import { Decimal } from \"../internal/decimal.js\";\nimport type { MeasurementUnitIndex } from \"../internal/measurement-unit.js\";\nimport { Quantity, tryParseQuantity } from \"../internal/quantity.js\";\nimport type { PrimitiveTypeInfo } from \"../primitive-type-info.js\";\nimport { TextCandidate } from \"../text-scanning/text-candidate.js\";\nimport { TextCandidateCategory } from \"../text-scanning/text-candidate-category.js\";\nimport { TextMatchConfidence } from \"../text-scanning/text-match-confidence.js\";\nimport { DataSizeUnit } from \"./data-size-unit.js\";\n\n/** Options for {@link DataSize.format} and {@link DataSize.normalize}. */\nexport interface DataSizeFormatOptions {\n fallbackToTrimmedInputWhenInvalid?: boolean;\n /** Convert to this unit instead of preserving the parsed one. */\n unit?: DataSizeUnit;\n /** Round to this many fractional digits, away from zero. */\n decimals?: number;\n}\n\nconst SCAN_PATTERN = new RegExp(\n String.raw`(?<![\\p{L}\\p{N}_])(?:[+-]\\s*)?\\d+[0-9 .,]*\\s*(?:exbibytes|exbibyte|exabytes|exabyte|pebibytes|pebibyte|petabytes|petabyte|tebibytes|tebibyte|terabytes|terabyte|gibibytes|gibibyte|gigabytes|gigabyte|mebibytes|mebibyte|megabytes|megabyte|kibibytes|kibibyte|kilobytes|kilobyte|EiB|PiB|TiB|GiB|MiB|KiB|EB|PB|TB|GB|MB|KB|bytes|byte|B)(?![\\p{L}\\p{N}_])`,\n \"giu\",\n);\n\n/**\n * A data size stored internally in bytes,\n * parsed from any supported unit and convertible between all of them.\n */\nexport class DataSize extends Quantity<DataSizeUnit> {\n static readonly typeInfo: PrimitiveTypeInfo = Object.freeze({\n englishName: \"Data Size\",\n localizedName: \"Datastorlek\",\n emoji: \"\uD83D\uDCBE\",\n sources: Object.freeze([\n \"https://www.bipm.org/en/publications/si-brochure\",\n \"https://www.iec.ch/standardsonline/iec-standard/iec-60027-2\",\n ]),\n });\n\n protected get units(): MeasurementUnitIndex<DataSizeUnit> {\n return DataSizeUnit.index;\n }\n\n protected withBaseValue(baseValue: Decimal, unit: DataSizeUnit): this {\n return new DataSize(baseValue, unit) as this;\n }\n\n get bytes(): number {\n return this.in(DataSizeUnit.Byte);\n }\n get kilobytes(): number {\n return this.in(DataSizeUnit.Kilobyte);\n }\n get megabytes(): number {\n return this.in(DataSizeUnit.Megabyte);\n }\n get gigabytes(): number {\n return this.in(DataSizeUnit.Gigabyte);\n }\n get terabytes(): number {\n return this.in(DataSizeUnit.Terabyte);\n }\n get petabytes(): number {\n return this.in(DataSizeUnit.Petabyte);\n }\n get exabytes(): number {\n return this.in(DataSizeUnit.Exabyte);\n }\n get kibibytes(): number {\n return this.in(DataSizeUnit.Kibibyte);\n }\n get mebibytes(): number {\n return this.in(DataSizeUnit.Mebibyte);\n }\n get gibibytes(): number {\n return this.in(DataSizeUnit.Gibibyte);\n }\n get tebibytes(): number {\n return this.in(DataSizeUnit.Tebibyte);\n }\n get pebibytes(): number {\n return this.in(DataSizeUnit.Pebibyte);\n }\n get exbibytes(): number {\n return this.in(DataSizeUnit.Exbibyte);\n }\n\n /** Creates a data size from a value and unit. */\n static create(value: number | Decimal, unit: DataSizeUnit): DataSize {\n DataSizeUnit.index.assertOwns(unit);\n const amount = value instanceof Decimal ? value : DataSize.decimalOf(value);\n return new DataSize(unit.toBase(amount), unit);\n }\n\n static fromBytes(value: number | Decimal): DataSize {\n return DataSize.create(value, DataSizeUnit.Byte);\n }\n static fromKilobytes(value: number | Decimal): DataSize {\n return DataSize.create(value, DataSizeUnit.Kilobyte);\n }\n static fromMegabytes(value: number | Decimal): DataSize {\n return DataSize.create(value, DataSizeUnit.Megabyte);\n }\n static fromGigabytes(value: number | Decimal): DataSize {\n return DataSize.create(value, DataSizeUnit.Gigabyte);\n }\n static fromTerabytes(value: number | Decimal): DataSize {\n return DataSize.create(value, DataSizeUnit.Terabyte);\n }\n static fromPetabytes(value: number | Decimal): DataSize {\n return DataSize.create(value, DataSizeUnit.Petabyte);\n }\n static fromExabytes(value: number | Decimal): DataSize {\n return DataSize.create(value, DataSizeUnit.Exabyte);\n }\n static fromKibibytes(value: number | Decimal): DataSize {\n return DataSize.create(value, DataSizeUnit.Kibibyte);\n }\n static fromMebibytes(value: number | Decimal): DataSize {\n return DataSize.create(value, DataSizeUnit.Mebibyte);\n }\n static fromGibibytes(value: number | Decimal): DataSize {\n return DataSize.create(value, DataSizeUnit.Gibibyte);\n }\n static fromTebibytes(value: number | Decimal): DataSize {\n return DataSize.create(value, DataSizeUnit.Tebibyte);\n }\n static fromPebibytes(value: number | Decimal): DataSize {\n return DataSize.create(value, DataSizeUnit.Pebibyte);\n }\n static fromExbibytes(value: number | Decimal): DataSize {\n return DataSize.create(value, DataSizeUnit.Exbibyte);\n }\n\n static tryParse(input: string | null | undefined): DataSize | null {\n const parsed = tryParseQuantity(input, DataSizeUnit.index);\n return parsed === null ? null : new DataSize(parsed.baseValue, parsed.unit);\n }\n\n static parse(input: string): DataSize {\n const result = DataSize.tryParse(input);\n if (result === null) throw new Error(\"Invalid data size.\");\n return result;\n }\n\n static isValid(input: string | null | undefined): boolean {\n return DataSize.tryParse(input) !== null;\n }\n\n /** Display form in the parsed unit, or `null` when the input is invalid. */\n static format(input: string | null | undefined, options?: DataSizeFormatOptions): string | null {\n const parsed = DataSize.tryParse(input);\n if (parsed !== null) {\n if (options?.unit !== undefined || options?.decimals !== undefined) {\n return parsed.toStringInUnit(options.unit ?? parsed.originalUnit, options.decimals);\n }\n return parsed.toString();\n }\n return DataSize.fallback(input, options);\n }\n\n /** The value in bytes, or `null` when the input is invalid. */\n static normalize(\n input: string | null | undefined,\n options?: DataSizeFormatOptions,\n ): string | null {\n const parsed = DataSize.tryParse(input);\n if (parsed !== null) return parsed.toNormalizedString();\n return DataSize.fallback(input, options);\n }\n\n static isNormalized(input: string | null | undefined): boolean {\n return input != null && DataSize.normalize(input) === input;\n }\n\n static findCandidatesInText(text: string): readonly TextCandidate<DataSize>[] {\n if (!text) return [];\n\n const out: TextCandidate<DataSize>[] = [];\n const pattern = new RegExp(SCAN_PATTERN.source, SCAN_PATTERN.flags);\n let match: RegExpExecArray | null;\n\n while ((match = pattern.exec(text)) !== null) {\n const value = DataSize.tryParse(match[0]);\n if (value === null) continue;\n out.push(\n new TextCandidate<DataSize>({\n startIndex: match.index,\n length: match[0].length,\n originalText: match[0],\n typeName: \"DataSize\",\n category: TextCandidateCategory.Measurement,\n normalizedForm: value.toNormalizedString(),\n formattedForm: value.toString(),\n maskedForm: maskDataSize(value),\n confidence: TextMatchConfidence.Medium,\n value,\n }),\n );\n }\n\n return out;\n }\n\n private static fallback(\n input: string | null | undefined,\n options?: DataSizeFormatOptions,\n ): string | null {\n if (options?.fallbackToTrimmedInputWhenInvalid !== true) return null;\n if (input == null) return null;\n const trimmed = input.trim();\n return trimmed.length > 0 ? trimmed : null;\n }\n\n private static decimalOf(value: number): Decimal {\n const parsed = Decimal.fromNumber(value);\n if (parsed === null) throw new Error(`Value cannot be represented as a data size: ${value}`);\n return parsed;\n }\n}\n\n/** Returns a masked data size, e.g. `10 B` becomes `*** B`. */\nexport function maskDataSize(value: DataSize): string {\n return `*** ${value.originalUnit.symbol}`;\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAwB;AAExB,sBAA2C;AAE3C,4BAA8B;AAC9B,qCAAsC;AACtC,mCAAoC;AACpC,4BAA6B;AAW7B,MAAM,eAAe,IAAI;AAAA,EACvB,OAAO;AAAA,EACP;AACF;AAMO,MAAM,iBAAiB,yBAAuB;AAAA,EACnD,OAAgB,WAA8B,OAAO,OAAO;AAAA,IAC1D,aAAa;AAAA,IACb,eAAe;AAAA,IACf,OAAO;AAAA,IACP,SAAS,OAAO,OAAO;AAAA,MACrB;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AAAA,EAED,IAAc,QAA4C;AACxD,WAAO,mCAAa;AAAA,EACtB;AAAA,EAEU,cAAc,WAAoB,MAA0B;AACpE,WAAO,IAAI,SAAS,WAAW,IAAI;AAAA,EACrC;AAAA,EAEA,IAAI,QAAgB;AAClB,WAAO,KAAK,GAAG,mCAAa,IAAI;AAAA,EAClC;AAAA,EACA,IAAI,YAAoB;AACtB,WAAO,KAAK,GAAG,mCAAa,QAAQ;AAAA,EACtC;AAAA,EACA,IAAI,YAAoB;AACtB,WAAO,KAAK,GAAG,mCAAa,QAAQ;AAAA,EACtC;AAAA,EACA,IAAI,YAAoB;AACtB,WAAO,KAAK,GAAG,mCAAa,QAAQ;AAAA,EACtC;AAAA,EACA,IAAI,YAAoB;AACtB,WAAO,KAAK,GAAG,mCAAa,QAAQ;AAAA,EACtC;AAAA,EACA,IAAI,YAAoB;AACtB,WAAO,KAAK,GAAG,mCAAa,QAAQ;AAAA,EACtC;AAAA,EACA,IAAI,WAAmB;AACrB,WAAO,KAAK,GAAG,mCAAa,OAAO;AAAA,EACrC;AAAA,EACA,IAAI,YAAoB;AACtB,WAAO,KAAK,GAAG,mCAAa,QAAQ;AAAA,EACtC;A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AAO,MAAM,aAAa,MAAM;AACzC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -29,7 +29,7 @@ var import_text_candidate_category = require("../text-scanning/text-candidate-ca
|
|
|
29
29
|
var import_text_match_confidence = require("../text-scanning/text-match-confidence.js");
|
|
30
30
|
var import_electric_charge_unit = require("./electric-charge-unit.js");
|
|
31
31
|
const SCAN_PATTERN = new RegExp(
|
|
32
|
-
String.raw`(
|
|
32
|
+
String.raw`(?<![\p{L}\p{N}_])(?:[+-]\s*)?\d+[0-9 .,]*\s*(?:mAh|Ah|C)(?![\p{L}\p{N}_])`,
|
|
33
33
|
"giu"
|
|
34
34
|
);
|
|
35
35
|
class ElectricCharge extends import_quantity.Quantity {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/measurement/electric-charge.ts"],
|
|
4
|
-
"sourcesContent": ["import { Decimal } from \"../internal/decimal.js\";\nimport type { MeasurementUnitIndex } from \"../internal/measurement-unit.js\";\nimport { Quantity, tryParseQuantity } from \"../internal/quantity.js\";\nimport type { PrimitiveTypeInfo } from \"../primitive-type-info.js\";\nimport { TextCandidate } from \"../text-scanning/text-candidate.js\";\nimport { TextCandidateCategory } from \"../text-scanning/text-candidate-category.js\";\nimport { TextMatchConfidence } from \"../text-scanning/text-match-confidence.js\";\nimport { ElectricChargeUnit } from \"./electric-charge-unit.js\";\n\n/** Options for {@link ElectricCharge.format} and {@link ElectricCharge.normalize}. */\nexport interface ElectricChargeFormatOptions {\n fallbackToTrimmedInputWhenInvalid?: boolean;\n /** Convert to this unit instead of preserving the parsed one. */\n unit?: ElectricChargeUnit;\n /** Round to this many fractional digits, away from zero. */\n decimals?: number;\n}\n\nconst SCAN_PATTERN = new RegExp(\n String.raw`(
|
|
4
|
+
"sourcesContent": ["import { Decimal } from \"../internal/decimal.js\";\nimport type { MeasurementUnitIndex } from \"../internal/measurement-unit.js\";\nimport { Quantity, tryParseQuantity } from \"../internal/quantity.js\";\nimport type { PrimitiveTypeInfo } from \"../primitive-type-info.js\";\nimport { TextCandidate } from \"../text-scanning/text-candidate.js\";\nimport { TextCandidateCategory } from \"../text-scanning/text-candidate-category.js\";\nimport { TextMatchConfidence } from \"../text-scanning/text-match-confidence.js\";\nimport { ElectricChargeUnit } from \"./electric-charge-unit.js\";\n\n/** Options for {@link ElectricCharge.format} and {@link ElectricCharge.normalize}. */\nexport interface ElectricChargeFormatOptions {\n fallbackToTrimmedInputWhenInvalid?: boolean;\n /** Convert to this unit instead of preserving the parsed one. */\n unit?: ElectricChargeUnit;\n /** Round to this many fractional digits, away from zero. */\n decimals?: number;\n}\n\nconst SCAN_PATTERN = new RegExp(\n String.raw`(?<![\\p{L}\\p{N}_])(?:[+-]\\s*)?\\d+[0-9 .,]*\\s*(?:mAh|Ah|C)(?![\\p{L}\\p{N}_])`,\n \"giu\",\n);\n\n/**\n * A electric charge stored internally in ampere-hours,\n * parsed from any supported unit and convertible between all of them.\n */\nexport class ElectricCharge extends Quantity<ElectricChargeUnit> {\n static readonly typeInfo: PrimitiveTypeInfo = Object.freeze({\n englishName: \"Electric Charge\",\n localizedName: \"Elektrisk laddning\",\n emoji: \"\uD83D\uDD0B\",\n sources: Object.freeze([\n \"https://www.bipm.org/en/measurement-units/si-derived-units\",\n \"https://en.wikipedia.org/wiki/Ampere-hour\",\n ]),\n });\n\n protected get units(): MeasurementUnitIndex<ElectricChargeUnit> {\n return ElectricChargeUnit.index;\n }\n\n protected withBaseValue(baseValue: Decimal, unit: ElectricChargeUnit): this {\n return new ElectricCharge(baseValue, unit) as this;\n }\n\n get milliampereHours(): number {\n return this.in(ElectricChargeUnit.MilliampereHour);\n }\n get ampereHours(): number {\n return this.in(ElectricChargeUnit.AmpereHour);\n }\n get coulombs(): number {\n return this.in(ElectricChargeUnit.Coulomb);\n }\n\n /** Creates a electric charge from a value and unit. */\n static create(value: number | Decimal, unit: ElectricChargeUnit): ElectricCharge {\n ElectricChargeUnit.index.assertOwns(unit);\n const amount = value instanceof Decimal ? value : ElectricCharge.decimalOf(value);\n return new ElectricCharge(unit.toBase(amount), unit);\n }\n\n static fromMilliampereHours(value: number | Decimal): ElectricCharge {\n return ElectricCharge.create(value, ElectricChargeUnit.MilliampereHour);\n }\n static fromAmpereHours(value: number | Decimal): ElectricCharge {\n return ElectricCharge.create(value, ElectricChargeUnit.AmpereHour);\n }\n static fromCoulombs(value: number | Decimal): ElectricCharge {\n return ElectricCharge.create(value, ElectricChargeUnit.Coulomb);\n }\n\n static tryParse(input: string | null | undefined): ElectricCharge | null {\n const parsed = tryParseQuantity(input, ElectricChargeUnit.index);\n return parsed === null ? null : new ElectricCharge(parsed.baseValue, parsed.unit);\n }\n\n static parse(input: string): ElectricCharge {\n const result = ElectricCharge.tryParse(input);\n if (result === null) throw new Error(\"Invalid electric charge.\");\n return result;\n }\n\n static isValid(input: string | null | undefined): boolean {\n return ElectricCharge.tryParse(input) !== null;\n }\n\n /** Display form in the parsed unit, or `null` when the input is invalid. */\n static format(\n input: string | null | undefined,\n options?: ElectricChargeFormatOptions,\n ): string | null {\n const parsed = ElectricCharge.tryParse(input);\n if (parsed !== null) {\n if (options?.unit !== undefined || options?.decimals !== undefined) {\n return parsed.toStringInUnit(options.unit ?? parsed.originalUnit, options.decimals);\n }\n return parsed.toString();\n }\n return ElectricCharge.fallback(input, options);\n }\n\n /** The value in ampere-hours, or `null` when the input is invalid. */\n static normalize(\n input: string | null | undefined,\n options?: ElectricChargeFormatOptions,\n ): string | null {\n const parsed = ElectricCharge.tryParse(input);\n if (parsed !== null) return parsed.toNormalizedString();\n return ElectricCharge.fallback(input, options);\n }\n\n static isNormalized(input: string | null | undefined): boolean {\n return input != null && ElectricCharge.normalize(input) === input;\n }\n\n static findCandidatesInText(text: string): readonly TextCandidate<ElectricCharge>[] {\n if (!text) return [];\n\n const out: TextCandidate<ElectricCharge>[] = [];\n const pattern = new RegExp(SCAN_PATTERN.source, SCAN_PATTERN.flags);\n let match: RegExpExecArray | null;\n\n while ((match = pattern.exec(text)) !== null) {\n const value = ElectricCharge.tryParse(match[0]);\n if (value === null) continue;\n out.push(\n new TextCandidate<ElectricCharge>({\n startIndex: match.index,\n length: match[0].length,\n originalText: match[0],\n typeName: \"ElectricCharge\",\n category: TextCandidateCategory.Measurement,\n normalizedForm: value.toNormalizedString(),\n formattedForm: value.toString(),\n maskedForm: maskElectricCharge(value),\n confidence: TextMatchConfidence.Medium,\n value,\n }),\n );\n }\n\n return out;\n }\n\n private static fallback(\n input: string | null | undefined,\n options?: ElectricChargeFormatOptions,\n ): string | null {\n if (options?.fallbackToTrimmedInputWhenInvalid !== true) return null;\n if (input == null) return null;\n const trimmed = input.trim();\n return trimmed.length > 0 ? trimmed : null;\n }\n\n private static decimalOf(value: number): Decimal {\n const parsed = Decimal.fromNumber(value);\n if (parsed === null)\n throw new Error(`Value cannot be represented as a electric charge: ${value}`);\n return parsed;\n }\n}\n\n/** Returns a masked electric charge, e.g. `10 Ah` becomes `*** Ah`. */\nexport function maskElectricCharge(value: ElectricCharge): string {\n return `*** ${value.originalUnit.symbol}`;\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAwB;AAExB,sBAA2C;AAE3C,4BAA8B;AAC9B,qCAAsC;AACtC,mCAAoC;AACpC,kCAAmC;AAWnC,MAAM,eAAe,IAAI;AAAA,EACvB,OAAO;AAAA,EACP;AACF;AAMO,MAAM,uBAAuB,yBAA6B;AAAA,EAC/D,OAAgB,WAA8B,OAAO,OAAO;AAAA,IAC1D,aAAa;AAAA,IACb,eAAe;AAAA,IACf,OAAO;AAAA,IACP,SAAS,OAAO,OAAO;AAAA,MACrB;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AAAA,EAED,IAAc,QAAkD;AAC9D,WAAO,+CAAmB;AAAA,EAC5B;AAAA,EAEU,cAAc,WAAoB,MAAgC;AAC1E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AAC1B,UAAM,UAAU,MAAM,KAAK;AAC3B,WAAO,QAAQ,SAAS,IAAI,UAAU;AAAA,EACxC;AAAA,EAEA,OAAe,UAAU,OAAwB;AAC/C,UAAM,SAAS,uBAAQ,WAAW,KAAK;AACvC,QAAI,WAAW;AACb,YAAM,IAAI,MAAM,qDAAqD,KAAK,EAAE;AAC9E,WAAO;AAAA,EACT;AACF;AAGO,SAAS,mBAAmB,OAA+B;AAChE,SAAO,OAAO,MAAM,aAAa,MAAM;AACzC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -29,7 +29,7 @@ var import_text_candidate_category = require("../text-scanning/text-candidate-ca
|
|
|
29
29
|
var import_text_match_confidence = require("../text-scanning/text-match-confidence.js");
|
|
30
30
|
var import_electric_current_unit = require("./electric-current-unit.js");
|
|
31
31
|
const SCAN_PATTERN = new RegExp(
|
|
32
|
-
String.raw`(
|
|
32
|
+
String.raw`(?<![\p{L}\p{N}_])(?:[+-]\s*)?\d+[0-9 .,]*\s*(?:µA|uA|mA|kA|A)(?![\p{L}\p{N}_])`,
|
|
33
33
|
"giu"
|
|
34
34
|
);
|
|
35
35
|
class ElectricCurrent extends import_quantity.Quantity {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/measurement/electric-current.ts"],
|
|
4
|
-
"sourcesContent": ["import { Decimal } from \"../internal/decimal.js\";\nimport type { MeasurementUnitIndex } from \"../internal/measurement-unit.js\";\nimport { Quantity, tryParseQuantity } from \"../internal/quantity.js\";\nimport type { PrimitiveTypeInfo } from \"../primitive-type-info.js\";\nimport { TextCandidate } from \"../text-scanning/text-candidate.js\";\nimport { TextCandidateCategory } from \"../text-scanning/text-candidate-category.js\";\nimport { TextMatchConfidence } from \"../text-scanning/text-match-confidence.js\";\nimport { ElectricCurrentUnit } from \"./electric-current-unit.js\";\n\n/** Options for {@link ElectricCurrent.format} and {@link ElectricCurrent.normalize}. */\nexport interface ElectricCurrentFormatOptions {\n fallbackToTrimmedInputWhenInvalid?: boolean;\n /** Convert to this unit instead of preserving the parsed one. */\n unit?: ElectricCurrentUnit;\n /** Round to this many fractional digits, away from zero. */\n decimals?: number;\n}\n\nconst SCAN_PATTERN = new RegExp(\n String.raw`(
|
|
4
|
+
"sourcesContent": ["import { Decimal } from \"../internal/decimal.js\";\nimport type { MeasurementUnitIndex } from \"../internal/measurement-unit.js\";\nimport { Quantity, tryParseQuantity } from \"../internal/quantity.js\";\nimport type { PrimitiveTypeInfo } from \"../primitive-type-info.js\";\nimport { TextCandidate } from \"../text-scanning/text-candidate.js\";\nimport { TextCandidateCategory } from \"../text-scanning/text-candidate-category.js\";\nimport { TextMatchConfidence } from \"../text-scanning/text-match-confidence.js\";\nimport { ElectricCurrentUnit } from \"./electric-current-unit.js\";\n\n/** Options for {@link ElectricCurrent.format} and {@link ElectricCurrent.normalize}. */\nexport interface ElectricCurrentFormatOptions {\n fallbackToTrimmedInputWhenInvalid?: boolean;\n /** Convert to this unit instead of preserving the parsed one. */\n unit?: ElectricCurrentUnit;\n /** Round to this many fractional digits, away from zero. */\n decimals?: number;\n}\n\nconst SCAN_PATTERN = new RegExp(\n String.raw`(?<![\\p{L}\\p{N}_])(?:[+-]\\s*)?\\d+[0-9 .,]*\\s*(?:\u00B5A|uA|mA|kA|A)(?![\\p{L}\\p{N}_])`,\n \"giu\",\n);\n\n/**\n * A electric current stored internally in amperes,\n * parsed from any supported unit and convertible between all of them.\n */\nexport class ElectricCurrent extends Quantity<ElectricCurrentUnit> {\n static readonly typeInfo: PrimitiveTypeInfo = Object.freeze({\n englishName: \"Electric Current\",\n localizedName: \"Elektrisk str\u00F6m\",\n emoji: \"\u26A1\",\n sources: Object.freeze([\n \"https://www.bipm.org/en/measurement-units/si-base-units\",\n \"https://en.wikipedia.org/wiki/Ampere\",\n ]),\n });\n\n protected get units(): MeasurementUnitIndex<ElectricCurrentUnit> {\n return ElectricCurrentUnit.index;\n }\n\n protected withBaseValue(baseValue: Decimal, unit: ElectricCurrentUnit): this {\n return new ElectricCurrent(baseValue, unit) as this;\n }\n\n get microamperes(): number {\n return this.in(ElectricCurrentUnit.Microampere);\n }\n get milliamperes(): number {\n return this.in(ElectricCurrentUnit.Milliampere);\n }\n get amperes(): number {\n return this.in(ElectricCurrentUnit.Ampere);\n }\n get kiloamperes(): number {\n return this.in(ElectricCurrentUnit.Kiloampere);\n }\n\n /** Creates a electric current from a value and unit. */\n static create(value: number | Decimal, unit: ElectricCurrentUnit): ElectricCurrent {\n ElectricCurrentUnit.index.assertOwns(unit);\n const amount = value instanceof Decimal ? value : ElectricCurrent.decimalOf(value);\n return new ElectricCurrent(unit.toBase(amount), unit);\n }\n\n static fromMicroamperes(value: number | Decimal): ElectricCurrent {\n return ElectricCurrent.create(value, ElectricCurrentUnit.Microampere);\n }\n static fromMilliamperes(value: number | Decimal): ElectricCurrent {\n return ElectricCurrent.create(value, ElectricCurrentUnit.Milliampere);\n }\n static fromAmperes(value: number | Decimal): ElectricCurrent {\n return ElectricCurrent.create(value, ElectricCurrentUnit.Ampere);\n }\n static fromKiloamperes(value: number | Decimal): ElectricCurrent {\n return ElectricCurrent.create(value, ElectricCurrentUnit.Kiloampere);\n }\n\n static tryParse(input: string | null | undefined): ElectricCurrent | null {\n const parsed = tryParseQuantity(input, ElectricCurrentUnit.index);\n return parsed === null ? null : new ElectricCurrent(parsed.baseValue, parsed.unit);\n }\n\n static parse(input: string): ElectricCurrent {\n const result = ElectricCurrent.tryParse(input);\n if (result === null) throw new Error(\"Invalid electric current.\");\n return result;\n }\n\n static isValid(input: string | null | undefined): boolean {\n return ElectricCurrent.tryParse(input) !== null;\n }\n\n /** Display form in the parsed unit, or `null` when the input is invalid. */\n static format(\n input: string | null | undefined,\n options?: ElectricCurrentFormatOptions,\n ): string | null {\n const parsed = ElectricCurrent.tryParse(input);\n if (parsed !== null) {\n if (options?.unit !== undefined || options?.decimals !== undefined) {\n return parsed.toStringInUnit(options.unit ?? parsed.originalUnit, options.decimals);\n }\n return parsed.toString();\n }\n return ElectricCurrent.fallback(input, options);\n }\n\n /** The value in amperes, or `null` when the input is invalid. */\n static normalize(\n input: string | null | undefined,\n options?: ElectricCurrentFormatOptions,\n ): string | null {\n const parsed = ElectricCurrent.tryParse(input);\n if (parsed !== null) return parsed.toNormalizedString();\n return ElectricCurrent.fallback(input, options);\n }\n\n static isNormalized(input: string | null | undefined): boolean {\n return input != null && ElectricCurrent.normalize(input) === input;\n }\n\n static findCandidatesInText(text: string): readonly TextCandidate<ElectricCurrent>[] {\n if (!text) return [];\n\n const out: TextCandidate<ElectricCurrent>[] = [];\n const pattern = new RegExp(SCAN_PATTERN.source, SCAN_PATTERN.flags);\n let match: RegExpExecArray | null;\n\n while ((match = pattern.exec(text)) !== null) {\n const value = ElectricCurrent.tryParse(match[0]);\n if (value === null) continue;\n out.push(\n new TextCandidate<ElectricCurrent>({\n startIndex: match.index,\n length: match[0].length,\n originalText: match[0],\n typeName: \"ElectricCurrent\",\n category: TextCandidateCategory.Measurement,\n normalizedForm: value.toNormalizedString(),\n formattedForm: value.toString(),\n maskedForm: maskElectricCurrent(value),\n confidence: TextMatchConfidence.Medium,\n value,\n }),\n );\n }\n\n return out;\n }\n\n private static fallback(\n input: string | null | undefined,\n options?: ElectricCurrentFormatOptions,\n ): string | null {\n if (options?.fallbackToTrimmedInputWhenInvalid !== true) return null;\n if (input == null) return null;\n const trimmed = input.trim();\n return trimmed.length > 0 ? trimmed : null;\n }\n\n private static decimalOf(value: number): Decimal {\n const parsed = Decimal.fromNumber(value);\n if (parsed === null)\n throw new Error(`Value cannot be represented as a electric current: ${value}`);\n return parsed;\n }\n}\n\n/** Returns a masked electric current, e.g. `10 A` becomes `*** A`. */\nexport function maskElectricCurrent(value: ElectricCurrent): string {\n return `*** ${value.originalUnit.symbol}`;\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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,aAAa,QAAQ,aAAa,KAAK;AAClE,QAAI;AAEJ,YAAQ,QAAQ,QAAQ,KAAK,IAAI,OAAO,MAAM;AAC5C,YAAM,QAAQ,gBAAgB,SAAS,MAAM,CAAC,CAAC;AAC/C,UAAI,UAAU,KAAM;AACpB,UAAI;AAAA,QACF,IAAI,oCAA+B;AAAA,UACjC,YAAY,MAAM;AAAA,UAClB,QAAQ,MAAM,CAAC,EAAE;AAAA,UACjB,cAAc,MAAM,CAAC;AAAA,UACrB,UAAU;AAAA,UACV,UAAU,qDAAsB;AAAA,UAChC,gBAAgB,MAAM,mBAAmB;AAAA,UACzC,eAAe,MAAM,SAAS;AAAA,UAC9B,YAAY,oBAAoB,KAAK;AAAA,UACrC,YAAY,iDAAoB;AAAA,UAChC;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,OAAe,SACb,OACA,SACe;AACf,QAAI,SAAS,sCAAsC,KAAM,QAAO;AAChE,QAAI,SAAS,KAAM,QAAO;AAC1B,UAAM,UAAU,MAAM,KAAK;AAC3B,WAAO,QAAQ,SAAS,IAAI,UAAU;AAAA,EACxC;AAAA,EAEA,OAAe,UAAU,OAAwB;AAC/C,UAAM,SAAS,uBAAQ,WAAW,KAAK;AACvC,QAAI,WAAW;AACb,YAAM,IAAI,MAAM,sDAAsD,KAAK,EAAE;AAC/E,WAAO;AAAA,EACT;AACF;AAGO,SAAS,oBAAoB,OAAgC;AAClE,SAAO,OAAO,MAAM,aAAa,MAAM;AACzC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -29,7 +29,7 @@ var import_text_candidate_category = require("../text-scanning/text-candidate-ca
|
|
|
29
29
|
var import_text_match_confidence = require("../text-scanning/text-match-confidence.js");
|
|
30
30
|
var import_energy_unit = require("./energy-unit.js");
|
|
31
31
|
const SCAN_PATTERN = new RegExp(
|
|
32
|
-
String.raw`(
|
|
32
|
+
String.raw`(?<![\p{L}\p{N}_])(?:[+-]\s*)?\d+[0-9 .,]*\s*(?:TWh|GWh|MWh|kWh|TJ|GJ|MJ|kJ|kcal|Wh|BTU|cal|J)(?![\p{L}\p{N}_])`,
|
|
33
33
|
"giu"
|
|
34
34
|
);
|
|
35
35
|
class Energy extends import_quantity.Quantity {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/measurement/energy.ts"],
|
|
4
|
-
"sourcesContent": ["import { Decimal } from \"../internal/decimal.js\";\nimport type { MeasurementUnitIndex } from \"../internal/measurement-unit.js\";\nimport { Quantity, tryParseQuantity } from \"../internal/quantity.js\";\nimport type { PrimitiveTypeInfo } from \"../primitive-type-info.js\";\nimport { TextCandidate } from \"../text-scanning/text-candidate.js\";\nimport { TextCandidateCategory } from \"../text-scanning/text-candidate-category.js\";\nimport { TextMatchConfidence } from \"../text-scanning/text-match-confidence.js\";\nimport { EnergyUnit } from \"./energy-unit.js\";\n\n/** Options for {@link Energy.format} and {@link Energy.normalize}. */\nexport interface EnergyFormatOptions {\n fallbackToTrimmedInputWhenInvalid?: boolean;\n /** Convert to this unit instead of preserving the parsed one. */\n unit?: EnergyUnit;\n /** Round to this many fractional digits, away from zero. */\n decimals?: number;\n}\n\nconst SCAN_PATTERN = new RegExp(\n String.raw`(
|
|
4
|
+
"sourcesContent": ["import { Decimal } from \"../internal/decimal.js\";\nimport type { MeasurementUnitIndex } from \"../internal/measurement-unit.js\";\nimport { Quantity, tryParseQuantity } from \"../internal/quantity.js\";\nimport type { PrimitiveTypeInfo } from \"../primitive-type-info.js\";\nimport { TextCandidate } from \"../text-scanning/text-candidate.js\";\nimport { TextCandidateCategory } from \"../text-scanning/text-candidate-category.js\";\nimport { TextMatchConfidence } from \"../text-scanning/text-match-confidence.js\";\nimport { EnergyUnit } from \"./energy-unit.js\";\n\n/** Options for {@link Energy.format} and {@link Energy.normalize}. */\nexport interface EnergyFormatOptions {\n fallbackToTrimmedInputWhenInvalid?: boolean;\n /** Convert to this unit instead of preserving the parsed one. */\n unit?: EnergyUnit;\n /** Round to this many fractional digits, away from zero. */\n decimals?: number;\n}\n\nconst SCAN_PATTERN = new RegExp(\n String.raw`(?<![\\p{L}\\p{N}_])(?:[+-]\\s*)?\\d+[0-9 .,]*\\s*(?:TWh|GWh|MWh|kWh|TJ|GJ|MJ|kJ|kcal|Wh|BTU|cal|J)(?![\\p{L}\\p{N}_])`,\n \"giu\",\n);\n\n/**\n * A energy stored internally in joules,\n * parsed from any supported unit and convertible between all of them.\n */\nexport class Energy extends Quantity<EnergyUnit> {\n static readonly typeInfo: PrimitiveTypeInfo = Object.freeze({\n englishName: \"Energy\",\n localizedName: \"Energi\",\n emoji: \"\u26A1\",\n sources: Object.freeze([\n \"https://www.bipm.org/en/measurement-units/si-derived-units\",\n \"https://en.wikipedia.org/wiki/Conversion_of_units\",\n ]),\n });\n\n protected get units(): MeasurementUnitIndex<EnergyUnit> {\n return EnergyUnit.index;\n }\n\n protected withBaseValue(baseValue: Decimal, unit: EnergyUnit): this {\n return new Energy(baseValue, unit) as this;\n }\n\n get joules(): number {\n return this.in(EnergyUnit.Joule);\n }\n get kilojoules(): number {\n return this.in(EnergyUnit.Kilojoule);\n }\n get megajoules(): number {\n return this.in(EnergyUnit.Megajoule);\n }\n get gigajoules(): number {\n return this.in(EnergyUnit.Gigajoule);\n }\n get terajoules(): number {\n return this.in(EnergyUnit.Terajoule);\n }\n get wattHours(): number {\n return this.in(EnergyUnit.WattHour);\n }\n get kilowattHours(): number {\n return this.in(EnergyUnit.KilowattHour);\n }\n get megawattHours(): number {\n return this.in(EnergyUnit.MegawattHour);\n }\n get gigawattHours(): number {\n return this.in(EnergyUnit.GigawattHour);\n }\n get terawattHours(): number {\n return this.in(EnergyUnit.TerawattHour);\n }\n get calories(): number {\n return this.in(EnergyUnit.Calorie);\n }\n get kilocalories(): number {\n return this.in(EnergyUnit.Kilocalorie);\n }\n get btus(): number {\n return this.in(EnergyUnit.Btu);\n }\n\n /** Creates a energy from a value and unit. */\n static create(value: number | Decimal, unit: EnergyUnit): Energy {\n EnergyUnit.index.assertOwns(unit);\n const amount = value instanceof Decimal ? value : Energy.decimalOf(value);\n return new Energy(unit.toBase(amount), unit);\n }\n\n static fromJoules(value: number | Decimal): Energy {\n return Energy.create(value, EnergyUnit.Joule);\n }\n static fromKilojoules(value: number | Decimal): Energy {\n return Energy.create(value, EnergyUnit.Kilojoule);\n }\n static fromMegajoules(value: number | Decimal): Energy {\n return Energy.create(value, EnergyUnit.Megajoule);\n }\n static fromGigajoules(value: number | Decimal): Energy {\n return Energy.create(value, EnergyUnit.Gigajoule);\n }\n static fromTerajoules(value: number | Decimal): Energy {\n return Energy.create(value, EnergyUnit.Terajoule);\n }\n static fromWattHours(value: number | Decimal): Energy {\n return Energy.create(value, EnergyUnit.WattHour);\n }\n static fromKilowattHours(value: number | Decimal): Energy {\n return Energy.create(value, EnergyUnit.KilowattHour);\n }\n static fromMegawattHours(value: number | Decimal): Energy {\n return Energy.create(value, EnergyUnit.MegawattHour);\n }\n static fromGigawattHours(value: number | Decimal): Energy {\n return Energy.create(value, EnergyUnit.GigawattHour);\n }\n static fromTerawattHours(value: number | Decimal): Energy {\n return Energy.create(value, EnergyUnit.TerawattHour);\n }\n static fromCalories(value: number | Decimal): Energy {\n return Energy.create(value, EnergyUnit.Calorie);\n }\n static fromKilocalories(value: number | Decimal): Energy {\n return Energy.create(value, EnergyUnit.Kilocalorie);\n }\n static fromBtus(value: number | Decimal): Energy {\n return Energy.create(value, EnergyUnit.Btu);\n }\n\n static tryParse(input: string | null | undefined): Energy | null {\n const parsed = tryParseQuantity(input, EnergyUnit.index);\n return parsed === null ? null : new Energy(parsed.baseValue, parsed.unit);\n }\n\n static parse(input: string): Energy {\n const result = Energy.tryParse(input);\n if (result === null) throw new Error(\"Invalid energy.\");\n return result;\n }\n\n static isValid(input: string | null | undefined): boolean {\n return Energy.tryParse(input) !== null;\n }\n\n /** Display form in the parsed unit, or `null` when the input is invalid. */\n static format(input: string | null | undefined, options?: EnergyFormatOptions): string | null {\n const parsed = Energy.tryParse(input);\n if (parsed !== null) {\n if (options?.unit !== undefined || options?.decimals !== undefined) {\n return parsed.toStringInUnit(options.unit ?? parsed.originalUnit, options.decimals);\n }\n return parsed.toString();\n }\n return Energy.fallback(input, options);\n }\n\n /** The value in joules, or `null` when the input is invalid. */\n static normalize(input: string | null | undefined, options?: EnergyFormatOptions): string | null {\n const parsed = Energy.tryParse(input);\n if (parsed !== null) return parsed.toNormalizedString();\n return Energy.fallback(input, options);\n }\n\n static isNormalized(input: string | null | undefined): boolean {\n return input != null && Energy.normalize(input) === input;\n }\n\n static findCandidatesInText(text: string): readonly TextCandidate<Energy>[] {\n if (!text) return [];\n\n const out: TextCandidate<Energy>[] = [];\n const pattern = new RegExp(SCAN_PATTERN.source, SCAN_PATTERN.flags);\n let match: RegExpExecArray | null;\n\n while ((match = pattern.exec(text)) !== null) {\n const value = Energy.tryParse(match[0]);\n if (value === null) continue;\n out.push(\n new TextCandidate<Energy>({\n startIndex: match.index,\n length: match[0].length,\n originalText: match[0],\n typeName: \"Energy\",\n category: TextCandidateCategory.Measurement,\n normalizedForm: value.toNormalizedString(),\n formattedForm: value.toString(),\n maskedForm: maskEnergy(value),\n confidence: TextMatchConfidence.Medium,\n value,\n }),\n );\n }\n\n return out;\n }\n\n private static fallback(\n input: string | null | undefined,\n options?: EnergyFormatOptions,\n ): string | null {\n if (options?.fallbackToTrimmedInputWhenInvalid !== true) return null;\n if (input == null) return null;\n const trimmed = input.trim();\n return trimmed.length > 0 ? trimmed : null;\n }\n\n private static decimalOf(value: number): Decimal {\n const parsed = Decimal.fromNumber(value);\n if (parsed === null) throw new Error(`Value cannot be represented as a energy: ${value}`);\n return parsed;\n }\n}\n\n/** Returns a masked energy, e.g. `10 J` becomes `*** J`. */\nexport function maskEnergy(value: Energy): string {\n return `*** ${value.originalUnit.symbol}`;\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;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import_text_candidate_category = require("../text-scanning/text-candidate-ca
|
|
|
29
29
|
var import_text_match_confidence = require("../text-scanning/text-match-confidence.js");
|
|
30
30
|
var import_flow_rate_unit = require("./flow-rate-unit.js");
|
|
31
31
|
const SCAN_PATTERN = new RegExp(
|
|
32
|
-
String.raw`(
|
|
32
|
+
String.raw`(?<![\p{L}\p{N}_])(?:[+-]\s*)?\d+[0-9 .,]*\s*(?:m[³3]/(?:h|min|tim)|l/(?:s|min|h|timme)|gal/min|gpm)(?![\p{L}\p{N}_])`,
|
|
33
33
|
"giu"
|
|
34
34
|
);
|
|
35
35
|
class FlowRate extends import_quantity.Quantity {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/measurement/flow-rate.ts"],
|
|
4
|
-
"sourcesContent": ["import { Decimal } from \"../internal/decimal.js\";\nimport type { MeasurementUnitIndex } from \"../internal/measurement-unit.js\";\nimport { Quantity, tryParseQuantity } from \"../internal/quantity.js\";\nimport type { PrimitiveTypeInfo } from \"../primitive-type-info.js\";\nimport { TextCandidate } from \"../text-scanning/text-candidate.js\";\nimport { TextCandidateCategory } from \"../text-scanning/text-candidate-category.js\";\nimport { TextMatchConfidence } from \"../text-scanning/text-match-confidence.js\";\nimport { FlowRateUnit } from \"./flow-rate-unit.js\";\n\n/** Options for {@link FlowRate.format} and {@link FlowRate.normalize}. */\nexport interface FlowRateFormatOptions {\n fallbackToTrimmedInputWhenInvalid?: boolean;\n /** Convert to this unit instead of preserving the parsed one. */\n unit?: FlowRateUnit;\n /** Round to this many fractional digits, away from zero. */\n decimals?: number;\n}\n\nconst SCAN_PATTERN = new RegExp(\n String.raw`(
|
|
4
|
+
"sourcesContent": ["import { Decimal } from \"../internal/decimal.js\";\nimport type { MeasurementUnitIndex } from \"../internal/measurement-unit.js\";\nimport { Quantity, tryParseQuantity } from \"../internal/quantity.js\";\nimport type { PrimitiveTypeInfo } from \"../primitive-type-info.js\";\nimport { TextCandidate } from \"../text-scanning/text-candidate.js\";\nimport { TextCandidateCategory } from \"../text-scanning/text-candidate-category.js\";\nimport { TextMatchConfidence } from \"../text-scanning/text-match-confidence.js\";\nimport { FlowRateUnit } from \"./flow-rate-unit.js\";\n\n/** Options for {@link FlowRate.format} and {@link FlowRate.normalize}. */\nexport interface FlowRateFormatOptions {\n fallbackToTrimmedInputWhenInvalid?: boolean;\n /** Convert to this unit instead of preserving the parsed one. */\n unit?: FlowRateUnit;\n /** Round to this many fractional digits, away from zero. */\n decimals?: number;\n}\n\nconst SCAN_PATTERN = new RegExp(\n String.raw`(?<![\\p{L}\\p{N}_])(?:[+-]\\s*)?\\d+[0-9 .,]*\\s*(?:m[\u00B33]/(?:h|min|tim)|l/(?:s|min|h|timme)|gal/min|gpm)(?![\\p{L}\\p{N}_])`,\n \"giu\",\n);\n\n/**\n * A flow rate stored internally in liters per minute,\n * parsed from any supported unit and convertible between all of them.\n */\nexport class FlowRate extends Quantity<FlowRateUnit> {\n static readonly typeInfo: PrimitiveTypeInfo = Object.freeze({\n englishName: \"Flow Rate\",\n localizedName: \"Fl\u00F6de\",\n emoji: \"\uD83C\uDF0A\",\n sources: Object.freeze([\"https://en.wikipedia.org/wiki/Volumetric_flow_rate\"]),\n });\n\n protected get units(): MeasurementUnitIndex<FlowRateUnit> {\n return FlowRateUnit.index;\n }\n\n protected withBaseValue(baseValue: Decimal, unit: FlowRateUnit): this {\n return new FlowRate(baseValue, unit) as this;\n }\n\n get litersPerSecond(): number {\n return this.in(FlowRateUnit.LitersPerSecond);\n }\n get litersPerMinute(): number {\n return this.in(FlowRateUnit.LitersPerMinute);\n }\n get litersPerHour(): number {\n return this.in(FlowRateUnit.LitersPerHour);\n }\n get cubicMetersPerHour(): number {\n return this.in(FlowRateUnit.CubicMetersPerHour);\n }\n get cubicMetersPerMinute(): number {\n return this.in(FlowRateUnit.CubicMetersPerMinute);\n }\n get gallonsPerMinute(): number {\n return this.in(FlowRateUnit.GallonsPerMinute);\n }\n\n /** Creates a flow rate from a value and unit. */\n static create(value: number | Decimal, unit: FlowRateUnit): FlowRate {\n FlowRateUnit.index.assertOwns(unit);\n const amount = value instanceof Decimal ? value : FlowRate.decimalOf(value);\n return new FlowRate(unit.toBase(amount), unit);\n }\n\n static fromLitersPerSecond(value: number | Decimal): FlowRate {\n return FlowRate.create(value, FlowRateUnit.LitersPerSecond);\n }\n static fromLitersPerMinute(value: number | Decimal): FlowRate {\n return FlowRate.create(value, FlowRateUnit.LitersPerMinute);\n }\n static fromLitersPerHour(value: number | Decimal): FlowRate {\n return FlowRate.create(value, FlowRateUnit.LitersPerHour);\n }\n static fromCubicMetersPerHour(value: number | Decimal): FlowRate {\n return FlowRate.create(value, FlowRateUnit.CubicMetersPerHour);\n }\n static fromCubicMetersPerMinute(value: number | Decimal): FlowRate {\n return FlowRate.create(value, FlowRateUnit.CubicMetersPerMinute);\n }\n static fromGallonsPerMinute(value: number | Decimal): FlowRate {\n return FlowRate.create(value, FlowRateUnit.GallonsPerMinute);\n }\n\n static tryParse(input: string | null | undefined): FlowRate | null {\n const parsed = tryParseQuantity(input, FlowRateUnit.index);\n return parsed === null ? null : new FlowRate(parsed.baseValue, parsed.unit);\n }\n\n static parse(input: string): FlowRate {\n const result = FlowRate.tryParse(input);\n if (result === null) throw new Error(\"Invalid flow rate.\");\n return result;\n }\n\n static isValid(input: string | null | undefined): boolean {\n return FlowRate.tryParse(input) !== null;\n }\n\n /** Display form in the parsed unit, or `null` when the input is invalid. */\n static format(input: string | null | undefined, options?: FlowRateFormatOptions): string | null {\n const parsed = FlowRate.tryParse(input);\n if (parsed !== null) {\n if (options?.unit !== undefined || options?.decimals !== undefined) {\n return parsed.toStringInUnit(options.unit ?? parsed.originalUnit, options.decimals);\n }\n return parsed.toString();\n }\n return FlowRate.fallback(input, options);\n }\n\n /** The value in liters per minute, or `null` when the input is invalid. */\n static normalize(\n input: string | null | undefined,\n options?: FlowRateFormatOptions,\n ): string | null {\n const parsed = FlowRate.tryParse(input);\n if (parsed !== null) return parsed.toNormalizedString();\n return FlowRate.fallback(input, options);\n }\n\n static isNormalized(input: string | null | undefined): boolean {\n return input != null && FlowRate.normalize(input) === input;\n }\n\n static findCandidatesInText(text: string): readonly TextCandidate<FlowRate>[] {\n if (!text) return [];\n\n const out: TextCandidate<FlowRate>[] = [];\n const pattern = new RegExp(SCAN_PATTERN.source, SCAN_PATTERN.flags);\n let match: RegExpExecArray | null;\n\n while ((match = pattern.exec(text)) !== null) {\n const value = FlowRate.tryParse(match[0]);\n if (value === null) continue;\n out.push(\n new TextCandidate<FlowRate>({\n startIndex: match.index,\n length: match[0].length,\n originalText: match[0],\n typeName: \"FlowRate\",\n category: TextCandidateCategory.Measurement,\n normalizedForm: value.toNormalizedString(),\n formattedForm: value.toString(),\n maskedForm: maskFlowRate(value),\n confidence: TextMatchConfidence.Medium,\n value,\n }),\n );\n }\n\n return out;\n }\n\n private static fallback(\n input: string | null | undefined,\n options?: FlowRateFormatOptions,\n ): string | null {\n if (options?.fallbackToTrimmedInputWhenInvalid !== true) return null;\n if (input == null) return null;\n const trimmed = input.trim();\n return trimmed.length > 0 ? trimmed : null;\n }\n\n private static decimalOf(value: number): Decimal {\n const parsed = Decimal.fromNumber(value);\n if (parsed === null) throw new Error(`Value cannot be represented as a flow rate: ${value}`);\n return parsed;\n }\n}\n\n/** Returns a masked flow rate, e.g. `10 L/min` becomes `*** L/min`. */\nexport function maskFlowRate(value: FlowRate): string {\n return `*** ${value.originalUnit.symbol}`;\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAwB;AAExB,sBAA2C;AAE3C,4BAA8B;AAC9B,qCAAsC;AACtC,mCAAoC;AACpC,4BAA6B;AAW7B,MAAM,eAAe,IAAI;AAAA,EACvB,OAAO;AAAA,EACP;AACF;AAMO,MAAM,iBAAiB,yBAAuB;AAAA,EACnD,OAAgB,WAA8B,OAAO,OA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AC5E,QAAI,CAAC,KAAM,QAAO,CAAC;AAEnB,UAAM,MAAiC,CAAC;AACxC,UAAM,UAAU,IAAI,OAAO,aAAa,QAAQ,aAAa,KAAK;AAClE,QAAI;AAEJ,YAAQ,QAAQ,QAAQ,KAAK,IAAI,OAAO,MAAM;AAC5C,YAAM,QAAQ,SAAS,SAAS,MAAM,CAAC,CAAC;AACxC,UAAI,UAAU,KAAM;AACpB,UAAI;AAAA,QACF,IAAI,oCAAwB;AAAA,UAC1B,YAAY,MAAM;AAAA,UAClB,QAAQ,MAAM,CAAC,EAAE;AAAA,UACjB,cAAc,MAAM,CAAC;AAAA,UACrB,UAAU;AAAA,UACV,UAAU,qDAAsB;AAAA,UAChC,gBAAgB,MAAM,mBAAmB;AAAA,UACzC,eAAe,MAAM,SAAS;AAAA,UAC9B,YAAY,aAAa,KAAK;AAAA,UAC9B,YAAY,iDAAoB;AAAA,UAChC;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,OAAe,SACb,OACA,SACe;AACf,QAAI,SAAS,sCAAsC,KAAM,QAAO;AAChE,QAAI,SAAS,KAAM,QAAO;AAC1B,UAAM,UAAU,MAAM,KAAK;AAC3B,WAAO,QAAQ,SAAS,IAAI,UAAU;AAAA,EACxC;AAAA,EAEA,OAAe,UAAU,OAAwB;AAC/C,UAAM,SAAS,uBAAQ,WAAW,KAAK;AACvC,QAAI,WAAW,KAAM,OAAM,IAAI,MAAM,+CAA+C,KAAK,EAAE;AAC3F,WAAO;AAAA,EACT;AACF;AAGO,SAAS,aAAa,OAAyB;AACpD,SAAO,OAAO,MAAM,aAAa,MAAM;AACzC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -29,7 +29,7 @@ var import_text_candidate_category = require("../text-scanning/text-candidate-ca
|
|
|
29
29
|
var import_text_match_confidence = require("../text-scanning/text-match-confidence.js");
|
|
30
30
|
var import_frequency_unit = require("./frequency-unit.js");
|
|
31
31
|
const SCAN_PATTERN = new RegExp(
|
|
32
|
-
String.raw`(
|
|
32
|
+
String.raw`(?<![\p{L}\p{N}_])(?:[+-]\s*)?\d+[0-9 .,]*\s*(?:THz|GHz|MHz|kHz|Hz|rpm|rev/min|varv/min|r/min)(?![\p{L}\p{N}_])`,
|
|
33
33
|
"giu"
|
|
34
34
|
);
|
|
35
35
|
class Frequency extends import_quantity.Quantity {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/measurement/frequency.ts"],
|
|
4
|
-
"sourcesContent": ["import { Decimal } from \"../internal/decimal.js\";\nimport type { MeasurementUnitIndex } from \"../internal/measurement-unit.js\";\nimport { Quantity, tryParseQuantity } from \"../internal/quantity.js\";\nimport type { PrimitiveTypeInfo } from \"../primitive-type-info.js\";\nimport { TextCandidate } from \"../text-scanning/text-candidate.js\";\nimport { TextCandidateCategory } from \"../text-scanning/text-candidate-category.js\";\nimport { TextMatchConfidence } from \"../text-scanning/text-match-confidence.js\";\nimport { FrequencyUnit } from \"./frequency-unit.js\";\n\n/** Options for {@link Frequency.format} and {@link Frequency.normalize}. */\nexport interface FrequencyFormatOptions {\n fallbackToTrimmedInputWhenInvalid?: boolean;\n /** Convert to this unit instead of preserving the parsed one. */\n unit?: FrequencyUnit;\n /** Round to this many fractional digits, away from zero. */\n decimals?: number;\n}\n\nconst SCAN_PATTERN = new RegExp(\n String.raw`(
|
|
4
|
+
"sourcesContent": ["import { Decimal } from \"../internal/decimal.js\";\nimport type { MeasurementUnitIndex } from \"../internal/measurement-unit.js\";\nimport { Quantity, tryParseQuantity } from \"../internal/quantity.js\";\nimport type { PrimitiveTypeInfo } from \"../primitive-type-info.js\";\nimport { TextCandidate } from \"../text-scanning/text-candidate.js\";\nimport { TextCandidateCategory } from \"../text-scanning/text-candidate-category.js\";\nimport { TextMatchConfidence } from \"../text-scanning/text-match-confidence.js\";\nimport { FrequencyUnit } from \"./frequency-unit.js\";\n\n/** Options for {@link Frequency.format} and {@link Frequency.normalize}. */\nexport interface FrequencyFormatOptions {\n fallbackToTrimmedInputWhenInvalid?: boolean;\n /** Convert to this unit instead of preserving the parsed one. */\n unit?: FrequencyUnit;\n /** Round to this many fractional digits, away from zero. */\n decimals?: number;\n}\n\nconst SCAN_PATTERN = new RegExp(\n String.raw`(?<![\\p{L}\\p{N}_])(?:[+-]\\s*)?\\d+[0-9 .,]*\\s*(?:THz|GHz|MHz|kHz|Hz|rpm|rev/min|varv/min|r/min)(?![\\p{L}\\p{N}_])`,\n \"giu\",\n);\n\n/**\n * A frequency stored internally in hertz,\n * parsed from any supported unit and convertible between all of them.\n */\nexport class Frequency extends Quantity<FrequencyUnit> {\n static readonly typeInfo: PrimitiveTypeInfo = Object.freeze({\n englishName: \"Frequency\",\n localizedName: \"Frekvens\",\n emoji: \"\uD83D\uDCE1\",\n sources: Object.freeze([\n \"https://www.bipm.org/en/measurement-units/si-derived-units\",\n \"https://en.wikipedia.org/wiki/Conversion_of_units\",\n ]),\n });\n\n protected get units(): MeasurementUnitIndex<FrequencyUnit> {\n return FrequencyUnit.index;\n }\n\n protected withBaseValue(baseValue: Decimal, unit: FrequencyUnit): this {\n return new Frequency(baseValue, unit) as this;\n }\n\n get hertz(): number {\n return this.in(FrequencyUnit.Hertz);\n }\n get kilohertz(): number {\n return this.in(FrequencyUnit.Kilohertz);\n }\n get megahertz(): number {\n return this.in(FrequencyUnit.Megahertz);\n }\n get gigahertz(): number {\n return this.in(FrequencyUnit.Gigahertz);\n }\n get terahertz(): number {\n return this.in(FrequencyUnit.Terahertz);\n }\n get rpm(): number {\n return this.in(FrequencyUnit.RevolutionsPerMinute);\n }\n\n /** Creates a frequency from a value and unit. */\n static create(value: number | Decimal, unit: FrequencyUnit): Frequency {\n FrequencyUnit.index.assertOwns(unit);\n const amount = value instanceof Decimal ? value : Frequency.decimalOf(value);\n return new Frequency(unit.toBase(amount), unit);\n }\n\n static fromHertz(value: number | Decimal): Frequency {\n return Frequency.create(value, FrequencyUnit.Hertz);\n }\n static fromKilohertz(value: number | Decimal): Frequency {\n return Frequency.create(value, FrequencyUnit.Kilohertz);\n }\n static fromMegahertz(value: number | Decimal): Frequency {\n return Frequency.create(value, FrequencyUnit.Megahertz);\n }\n static fromGigahertz(value: number | Decimal): Frequency {\n return Frequency.create(value, FrequencyUnit.Gigahertz);\n }\n static fromTerahertz(value: number | Decimal): Frequency {\n return Frequency.create(value, FrequencyUnit.Terahertz);\n }\n static fromRpm(value: number | Decimal): Frequency {\n return Frequency.create(value, FrequencyUnit.RevolutionsPerMinute);\n }\n\n static tryParse(input: string | null | undefined): Frequency | null {\n const parsed = tryParseQuantity(input, FrequencyUnit.index);\n return parsed === null ? null : new Frequency(parsed.baseValue, parsed.unit);\n }\n\n static parse(input: string): Frequency {\n const result = Frequency.tryParse(input);\n if (result === null) throw new Error(\"Invalid frequency.\");\n return result;\n }\n\n static isValid(input: string | null | undefined): boolean {\n return Frequency.tryParse(input) !== null;\n }\n\n /** Display form in the parsed unit, or `null` when the input is invalid. */\n static format(input: string | null | undefined, options?: FrequencyFormatOptions): string | null {\n const parsed = Frequency.tryParse(input);\n if (parsed !== null) {\n if (options?.unit !== undefined || options?.decimals !== undefined) {\n return parsed.toStringInUnit(options.unit ?? parsed.originalUnit, options.decimals);\n }\n return parsed.toString();\n }\n return Frequency.fallback(input, options);\n }\n\n /** The value in hertz, or `null` when the input is invalid. */\n static normalize(\n input: string | null | undefined,\n options?: FrequencyFormatOptions,\n ): string | null {\n const parsed = Frequency.tryParse(input);\n if (parsed !== null) return parsed.toNormalizedString();\n return Frequency.fallback(input, options);\n }\n\n static isNormalized(input: string | null | undefined): boolean {\n return input != null && Frequency.normalize(input) === input;\n }\n\n static findCandidatesInText(text: string): readonly TextCandidate<Frequency>[] {\n if (!text) return [];\n\n const out: TextCandidate<Frequency>[] = [];\n const pattern = new RegExp(SCAN_PATTERN.source, SCAN_PATTERN.flags);\n let match: RegExpExecArray | null;\n\n while ((match = pattern.exec(text)) !== null) {\n const value = Frequency.tryParse(match[0]);\n if (value === null) continue;\n out.push(\n new TextCandidate<Frequency>({\n startIndex: match.index,\n length: match[0].length,\n originalText: match[0],\n typeName: \"Frequency\",\n category: TextCandidateCategory.Measurement,\n normalizedForm: value.toNormalizedString(),\n formattedForm: value.toString(),\n maskedForm: maskFrequency(value),\n confidence: TextMatchConfidence.Medium,\n value,\n }),\n );\n }\n\n return out;\n }\n\n private static fallback(\n input: string | null | undefined,\n options?: FrequencyFormatOptions,\n ): string | null {\n if (options?.fallbackToTrimmedInputWhenInvalid !== true) return null;\n if (input == null) return null;\n const trimmed = input.trim();\n return trimmed.length > 0 ? trimmed : null;\n }\n\n private static decimalOf(value: number): Decimal {\n const parsed = Decimal.fromNumber(value);\n if (parsed === null) throw new Error(`Value cannot be represented as a frequency: ${value}`);\n return parsed;\n }\n}\n\n/** Returns a masked frequency, e.g. `10 Hz` becomes `*** Hz`. */\nexport function maskFrequency(value: Frequency): string {\n return `*** ${value.originalUnit.symbol}`;\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAwB;AAExB,sBAA2C;AAE3C,4BAA8B;AAC9B,qCAAsC;AACtC,mCAAoC;AACpC,4BAA8B;AAW9B,MAAM,eAAe,IAAI;AAAA,EACvB,OAAO;AAAA,EACP;AACF;AAMO,MAAM,kBAAkB,yBAAwB;AAAA,EACrD,OAAgB,WAA8B,OAAO,OAAO;AAAA,IAC1D,aAAa;AAAA,IACb,eAAe;AAAA,IACf,OAAO;AAAA,IACP,SAAS,OAAO,OAAO;AAAA,MACrB;AAAA,MACA;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AAAA,EAED,IAAc,QAA6C;AACzD,WAAO,oCAAc;AAAA,EACvB;AAAA,EAEU,cAAc,WAAoB,MAA2B;AACrE,WAAO,IAAI,UAAU,WAAW,IAAI;AAAA,EACtC;AAAA,EAE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AA,UAClB,QAAQ,MAAM,CAAC,EAAE;AAAA,UACjB,cAAc,MAAM,CAAC;AAAA,UACrB,UAAU;AAAA,UACV,UAAU,qDAAsB;AAAA,UAChC,gBAAgB,MAAM,mBAAmB;AAAA,UACzC,eAAe,MAAM,SAAS;AAAA,UAC9B,YAAY,cAAc,KAAK;AAAA,UAC/B,YAAY,iDAAoB;AAAA,UAChC;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,OAAe,SACb,OACA,SACe;AACf,QAAI,SAAS,sCAAsC,KAAM,QAAO;AAChE,QAAI,SAAS,KAAM,QAAO;AAC1B,UAAM,UAAU,MAAM,KAAK;AAC3B,WAAO,QAAQ,SAAS,IAAI,UAAU;AAAA,EACxC;AAAA,EAEA,OAAe,UAAU,OAAwB;AAC/C,UAAM,SAAS,uBAAQ,WAAW,KAAK;AACvC,QAAI,WAAW,KAAM,OAAM,IAAI,MAAM,+CAA+C,KAAK,EAAE;AAC3F,WAAO;AAAA,EACT;AACF;AAGO,SAAS,cAAc,OAA0B;AACtD,SAAO,OAAO,MAAM,aAAa,MAAM;AACzC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -28,7 +28,7 @@ var import_text_candidate = require("../text-scanning/text-candidate.js");
|
|
|
28
28
|
var import_text_candidate_category = require("../text-scanning/text-candidate-category.js");
|
|
29
29
|
var import_text_match_confidence = require("../text-scanning/text-match-confidence.js");
|
|
30
30
|
var import_length_unit = require("./length-unit.js");
|
|
31
|
-
const SCAN_PATTERN = /(
|
|
31
|
+
const SCAN_PATTERN = /(?<![\p{L}\p{N}_])(?:[+-]\s*)?\d+[0-9 .,]*\s*(?:µm|nm|mm|cm|dm|km|mi|ft|yd|nmi|mil|in|m)(?![\p{L}\p{N}_])/giu;
|
|
32
32
|
class Length extends import_quantity.Quantity {
|
|
33
33
|
static typeInfo = Object.freeze({
|
|
34
34
|
englishName: "Length",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/measurement/length.ts"],
|
|
4
|
-
"sourcesContent": ["import { Decimal } from \"../internal/decimal.js\";\nimport type { MeasurementUnitIndex } from \"../internal/measurement-unit.js\";\nimport { Quantity, tryParseQuantity } from \"../internal/quantity.js\";\nimport type { PrimitiveTypeInfo } from \"../primitive-type-info.js\";\nimport { TextCandidate } from \"../text-scanning/text-candidate.js\";\nimport { TextCandidateCategory } from \"../text-scanning/text-candidate-category.js\";\nimport { TextMatchConfidence } from \"../text-scanning/text-match-confidence.js\";\nimport { LengthUnit } from \"./length-unit.js\";\n\n/** Options for {@link Length.format} and {@link Length.normalize}. */\nexport interface LengthFormatOptions {\n fallbackToTrimmedInputWhenInvalid?: boolean;\n /** Convert to this unit instead of preserving the parsed one. */\n unit?: LengthUnit;\n /** Round to this many fractional digits, away from zero. */\n decimals?: number;\n}\n\nconst SCAN_PATTERN =\n /(
|
|
4
|
+
"sourcesContent": ["import { Decimal } from \"../internal/decimal.js\";\nimport type { MeasurementUnitIndex } from \"../internal/measurement-unit.js\";\nimport { Quantity, tryParseQuantity } from \"../internal/quantity.js\";\nimport type { PrimitiveTypeInfo } from \"../primitive-type-info.js\";\nimport { TextCandidate } from \"../text-scanning/text-candidate.js\";\nimport { TextCandidateCategory } from \"../text-scanning/text-candidate-category.js\";\nimport { TextMatchConfidence } from \"../text-scanning/text-match-confidence.js\";\nimport { LengthUnit } from \"./length-unit.js\";\n\n/** Options for {@link Length.format} and {@link Length.normalize}. */\nexport interface LengthFormatOptions {\n fallbackToTrimmedInputWhenInvalid?: boolean;\n /** Convert to this unit instead of preserving the parsed one. */\n unit?: LengthUnit;\n /** Round to this many fractional digits, away from zero. */\n decimals?: number;\n}\n\nconst SCAN_PATTERN =\n /(?<![\\p{L}\\p{N}_])(?:[+-]\\s*)?\\d+[0-9 .,]*\\s*(?:\u00B5m|nm|mm|cm|dm|km|mi|ft|yd|nmi|mil|in|m)(?![\\p{L}\\p{N}_])/giu;\n\n/**\n * A length stored internally in meters, parsed from any supported unit format\n * such as `10 km`, `5.5 cm` or `3 ft`, and convertible between metric and\n * imperial units.\n *\n * Sources:\n * - https://www.bipm.org/en/measurement-units/si-base-units \u2014 meter definition\n * - https://en.wikipedia.org/wiki/Conversion_of_units\n */\nexport class Length extends Quantity<LengthUnit> {\n static readonly typeInfo: PrimitiveTypeInfo = Object.freeze({\n englishName: \"Length\",\n localizedName: \"L\u00E4ngd\",\n emoji: \"\uD83D\uDCCF\",\n sources: Object.freeze([\n \"https://www.bipm.org/en/measurement-units/si-base-units\",\n \"https://en.wikipedia.org/wiki/Conversion_of_units\",\n ]),\n });\n\n protected get units(): MeasurementUnitIndex<LengthUnit> {\n return LengthUnit.index;\n }\n\n protected withBaseValue(baseValue: Decimal, unit: LengthUnit): this {\n return new Length(baseValue, unit) as this;\n }\n\n get nanometers(): number {\n return this.in(LengthUnit.Nanometer);\n }\n get micrometers(): number {\n return this.in(LengthUnit.Micrometer);\n }\n get millimeters(): number {\n return this.in(LengthUnit.Millimeter);\n }\n get centimeters(): number {\n return this.in(LengthUnit.Centimeter);\n }\n get decimeters(): number {\n return this.in(LengthUnit.Decimeter);\n }\n get meters(): number {\n return this.in(LengthUnit.Meter);\n }\n get kilometers(): number {\n return this.in(LengthUnit.Kilometer);\n }\n get inches(): number {\n return this.in(LengthUnit.Inch);\n }\n get feet(): number {\n return this.in(LengthUnit.Foot);\n }\n get yards(): number {\n return this.in(LengthUnit.Yard);\n }\n get miles(): number {\n return this.in(LengthUnit.Mile);\n }\n get nauticalMiles(): number {\n return this.in(LengthUnit.NauticalMile);\n }\n /** The value in Swedish miles, where 1 mil is 10 km. */\n get swedishMiles(): number {\n return this.in(LengthUnit.SwedishMile);\n }\n\n /** Creates a length from a value and unit. */\n static create(value: number | Decimal, unit: LengthUnit): Length {\n LengthUnit.index.assertOwns(unit);\n const amount = value instanceof Decimal ? value : Length.decimalOf(value);\n return new Length(unit.toBase(amount), unit);\n }\n\n static fromNanometers(value: number | Decimal): Length {\n return Length.create(value, LengthUnit.Nanometer);\n }\n static fromMicrometers(value: number | Decimal): Length {\n return Length.create(value, LengthUnit.Micrometer);\n }\n static fromMillimeters(value: number | Decimal): Length {\n return Length.create(value, LengthUnit.Millimeter);\n }\n static fromCentimeters(value: number | Decimal): Length {\n return Length.create(value, LengthUnit.Centimeter);\n }\n static fromDecimeters(value: number | Decimal): Length {\n return Length.create(value, LengthUnit.Decimeter);\n }\n static fromMeters(value: number | Decimal): Length {\n return Length.create(value, LengthUnit.Meter);\n }\n static fromKilometers(value: number | Decimal): Length {\n return Length.create(value, LengthUnit.Kilometer);\n }\n static fromInches(value: number | Decimal): Length {\n return Length.create(value, LengthUnit.Inch);\n }\n static fromFeet(value: number | Decimal): Length {\n return Length.create(value, LengthUnit.Foot);\n }\n static fromYards(value: number | Decimal): Length {\n return Length.create(value, LengthUnit.Yard);\n }\n static fromMiles(value: number | Decimal): Length {\n return Length.create(value, LengthUnit.Mile);\n }\n static fromNauticalMiles(value: number | Decimal): Length {\n return Length.create(value, LengthUnit.NauticalMile);\n }\n static fromSwedishMiles(value: number | Decimal): Length {\n return Length.create(value, LengthUnit.SwedishMile);\n }\n\n static tryParse(input: string | null | undefined): Length | null {\n const parsed = tryParseQuantity(input, LengthUnit.index, LengthUnit.tryParse);\n return parsed === null ? null : new Length(parsed.baseValue, parsed.unit);\n }\n\n static parse(input: string): Length {\n const result = Length.tryParse(input);\n if (result === null) throw new Error(\"Invalid length.\");\n return result;\n }\n\n static isValid(input: string | null | undefined): boolean {\n return Length.tryParse(input) !== null;\n }\n\n /**\n * Returns a display-friendly string such as `10 km`, preserving the parsed\n * unit unless `unit` is given. Returns `null` when the input is invalid.\n */\n static format(input: string | null | undefined, options?: LengthFormatOptions): string | null {\n const parsed = Length.tryParse(input);\n if (parsed !== null) {\n if (options?.unit !== undefined || options?.decimals !== undefined) {\n return parsed.toStringInUnit(options.unit ?? parsed.originalUnit, options.decimals);\n }\n return parsed.toString();\n }\n return Length.fallback(input, options);\n }\n\n /** Returns the value in meters, e.g. `10000 m`. Returns `null` when invalid. */\n static normalize(input: string | null | undefined, options?: LengthFormatOptions): string | null {\n const parsed = Length.tryParse(input);\n if (parsed !== null) return parsed.toNormalizedString();\n return Length.fallback(input, options);\n }\n\n static isNormalized(input: string | null | undefined): boolean {\n return input != null && Length.normalize(input) === input;\n }\n\n static findCandidatesInText(text: string): readonly TextCandidate<Length>[] {\n if (!text) return [];\n\n const out: TextCandidate<Length>[] = [];\n const pattern = new RegExp(SCAN_PATTERN.source, SCAN_PATTERN.flags);\n let match: RegExpExecArray | null;\n\n while ((match = pattern.exec(text)) !== null) {\n const value = Length.tryParse(match[0]);\n if (value === null) continue;\n out.push(\n new TextCandidate<Length>({\n startIndex: match.index,\n length: match[0].length,\n originalText: match[0],\n typeName: \"Length\",\n category: TextCandidateCategory.Measurement,\n normalizedForm: value.toNormalizedString(),\n formattedForm: value.toString(),\n maskedForm: maskLength(value),\n confidence: TextMatchConfidence.Medium,\n value,\n }),\n );\n }\n\n return out;\n }\n\n private static fallback(\n input: string | null | undefined,\n options?: LengthFormatOptions,\n ): string | null {\n if (options?.fallbackToTrimmedInputWhenInvalid !== true) return null;\n if (input == null) return null;\n const trimmed = input.trim();\n return trimmed.length > 0 ? trimmed : null;\n }\n\n private static decimalOf(value: number): Decimal {\n const parsed = Decimal.fromNumber(value);\n if (parsed === null) throw new Error(`Value cannot be represented as a length: ${value}`);\n return parsed;\n }\n}\n\n/** Returns a masked length, e.g. `10 km` becomes `*** km`. */\nexport function maskLength(length: Length): string {\n return `*** ${length.originalUnit.symbol}`;\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAwB;AAExB,sBAA2C;AAE3C,4BAA8B;AAC9B,qCAAsC;AACtC,mCAAoC;AACpC,yBAA2B;AAW3B,MAAM,eACJ;AAWK,MAAM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nB,UAAM,MAA+B,CAAC;AACtC,UAAM,UAAU,IAAI,OAAO,aAAa,QAAQ,aAAa,KAAK;AAClE,QAAI;AAEJ,YAAQ,QAAQ,QAAQ,KAAK,IAAI,OAAO,MAAM;AAC5C,YAAM,QAAQ,OAAO,SAAS,MAAM,CAAC,CAAC;AACtC,UAAI,UAAU,KAAM;AACpB,UAAI;AAAA,QACF,IAAI,oCAAsB;AAAA,UACxB,YAAY,MAAM;AAAA,UAClB,QAAQ,MAAM,CAAC,EAAE;AAAA,UACjB,cAAc,MAAM,CAAC;AAAA,UACrB,UAAU;AAAA,UACV,UAAU,qDAAsB;AAAA,UAChC,gBAAgB,MAAM,mBAAmB;AAAA,UACzC,eAAe,MAAM,SAAS;AAAA,UAC9B,YAAY,WAAW,KAAK;AAAA,UAC5B,YAAY,iDAAoB;AAAA,UAChC;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAAA,EAEA,OAAe,SACb,OACA,SACe;AACf,QAAI,SAAS,sCAAsC,KAAM,QAAO;AAChE,QAAI,SAAS,KAAM,QAAO;AAC1B,UAAM,UAAU,MAAM,KAAK;AAC3B,WAAO,QAAQ,SAAS,IAAI,UAAU;AAAA,EACxC;AAAA,EAEA,OAAe,UAAU,OAAwB;AAC/C,UAAM,SAAS,uBAAQ,WAAW,KAAK;AACvC,QAAI,WAAW,KAAM,OAAM,IAAI,MAAM,4CAA4C,KAAK,EAAE;AACxF,WAAO;AAAA,EACT;AACF;AAGO,SAAS,WAAW,QAAwB;AACjD,SAAO,OAAO,OAAO,aAAa,MAAM;AAC1C;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -30,7 +30,7 @@ var import_text_candidate_category = require("../text-scanning/text-candidate-ca
|
|
|
30
30
|
var import_text_match_confidence = require("../text-scanning/text-match-confidence.js");
|
|
31
31
|
var import_luminance_unit = require("./luminance-unit.js");
|
|
32
32
|
const SCAN_PATTERN = new RegExp(
|
|
33
|
-
String.raw`(
|
|
33
|
+
String.raw`(?<![\p{L}\p{N}_])(?:[+-]\s*)?\d+[0-9 .,]*\s*(?:kcd/m²|kcd/m2|cd/m²|cd/m2|knits?|nits?)(?![\p{L}\p{N}_])`,
|
|
34
34
|
"giu"
|
|
35
35
|
);
|
|
36
36
|
class Luminance extends import_quantity.Quantity {
|