@arcosmos/astronomy 0.0.0-stage → 0.1.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/LICENSE +202 -0
- package/README.md +227 -2
- package/dist/angles.d.ts +51 -0
- package/dist/angles.d.ts.map +1 -0
- package/dist/angles.js +261 -0
- package/dist/angles.js.map +1 -0
- package/dist/constants.d.ts +35 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +44 -0
- package/dist/constants.js.map +1 -0
- package/dist/coordinates.d.ts +213 -0
- package/dist/coordinates.d.ts.map +1 -0
- package/dist/coordinates.js +474 -0
- package/dist/coordinates.js.map +1 -0
- package/dist/distance.d.ts +26 -0
- package/dist/distance.d.ts.map +1 -0
- package/dist/distance.js +54 -0
- package/dist/distance.js.map +1 -0
- package/dist/errors.d.ts +24 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +24 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/kinds.d.ts +86 -0
- package/dist/kinds.d.ts.map +1 -0
- package/dist/kinds.js +29 -0
- package/dist/kinds.js.map +1 -0
- package/dist/parse-unit.d.ts +11 -0
- package/dist/parse-unit.d.ts.map +1 -0
- package/dist/parse-unit.js +222 -0
- package/dist/parse-unit.js.map +1 -0
- package/dist/quantity.d.ts +150 -0
- package/dist/quantity.d.ts.map +1 -0
- package/dist/quantity.js +452 -0
- package/dist/quantity.js.map +1 -0
- package/dist/rounding.d.ts +18 -0
- package/dist/rounding.d.ts.map +1 -0
- package/dist/rounding.js +35 -0
- package/dist/rounding.js.map +1 -0
- package/dist/time.d.ts +100 -0
- package/dist/time.d.ts.map +1 -0
- package/dist/time.js +448 -0
- package/dist/time.js.map +1 -0
- package/dist/units.d.ts +394 -0
- package/dist/units.d.ts.map +1 -0
- package/dist/units.js +353 -0
- package/dist/units.js.map +1 -0
- package/package.json +44 -3
- package/src/angles.ts +286 -0
- package/src/constants.ts +51 -0
- package/src/coordinates.ts +591 -0
- package/src/distance.ts +58 -0
- package/src/errors.ts +27 -0
- package/src/index.ts +27 -0
- package/src/kinds.ts +110 -0
- package/src/parse-unit.ts +230 -0
- package/src/quantity.ts +539 -0
- package/src/rounding.ts +33 -0
- package/src/time.ts +511 -0
- package/src/units.ts +445 -0
package/dist/errors.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/** A unit written in a form the parser doesn't accept, or a symbol it doesn't know. */
|
|
2
|
+
export class UnitParseError extends Error {
|
|
3
|
+
name = 'UnitParseError';
|
|
4
|
+
}
|
|
5
|
+
/** Two units of different kinds, such as a length and a time, which no factor converts. */
|
|
6
|
+
export class UnitConversionError extends Error {
|
|
7
|
+
name = 'UnitConversionError';
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Arithmetic the uncertainties don't allow as given: an asymmetric error, percentiles, or a
|
|
11
|
+
* limit, where first-order propagation isn't defined. The message says what to do instead.
|
|
12
|
+
*/
|
|
13
|
+
export class UncertaintyError extends Error {
|
|
14
|
+
name = 'UncertaintyError';
|
|
15
|
+
}
|
|
16
|
+
/** Text that isn't a number followed by a unit. */
|
|
17
|
+
export class QuantityParseError extends Error {
|
|
18
|
+
name = 'QuantityParseError';
|
|
19
|
+
}
|
|
20
|
+
/** Text that isn't a time: not ISO 8601, not a J or B year, or an impossible date. */
|
|
21
|
+
export class TimeParseError extends Error {
|
|
22
|
+
name = 'TimeParseError';
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,MAAM,OAAO,cAAe,SAAQ,KAAK;IACrB,IAAI,GAAG,gBAAgB,CAAA;CAC1C;AAED,2FAA2F;AAC3F,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC1B,IAAI,GAAG,qBAAqB,CAAA;CAC/C;AAED;;;GAGG;AACH,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACvB,IAAI,GAAG,kBAAkB,CAAA;CAC5C;AAED,mDAAmD;AACnD,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IACzB,IAAI,GAAG,oBAAoB,CAAA;CAC9C;AAED,sFAAsF;AACtF,MAAM,OAAO,cAAe,SAAQ,KAAK;IACrB,IAAI,GAAG,gBAAgB,CAAA;CAC1C"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { type AngleUnit, type FormatAngleOptions, formatAngle, parseAngle } from './angles.ts';
|
|
2
|
+
export * from './constants.ts';
|
|
3
|
+
export { distanceFromParallax, distanceModulus, distanceModulusPc, parallaxDistancePc } from './distance.ts';
|
|
4
|
+
export type { Mat3, Vec3 } from '@arcosmos/erfa';
|
|
5
|
+
export { type AngleInput, type Equinox, FRAME_COMPONENTS, FRAME_PROPER_MOTIONS, type FrameName, type MotionInput, SkyCoord, type SkyCoordInput, type SkyCoordStyle, type StarAt, frameRotation, moveStar, skyCoord, } from './coordinates.ts';
|
|
6
|
+
export { QuantityParseError, TimeParseError, UncertaintyError, UnitConversionError, UnitParseError } from './errors.ts';
|
|
7
|
+
export { COMPOUND_KINDS, type ConvertibleKind, type KindOf, LOG_KINDS, type SymbolOf, type TargetKind, type UnitTarget, type UnitText, } from './kinds.ts';
|
|
8
|
+
export { parseUnit, unit } from './parse-unit.ts';
|
|
9
|
+
export { type AsymmetricUncertainty, type EllipseUncertainty, type EllipseUncertaintyJSON, type KindOfQuantity, type Limit, type MeasurementLike, type PercentileUncertainty, Quantity, type QuantityJSON, type QuantityOptions, type SymmetricUncertainty, type SymmetrizeRule, type Uncertainty, type UncertaintyJSON, fromMeasurement, parseQuantity, q, } from './quantity.ts';
|
|
10
|
+
export { roundToSignificant, roundToUncertainty } from './rounding.ts';
|
|
11
|
+
export { Time, type TimeFormat, type TimeInput, type TimeOptions, type TimeScale, time } from './time.ts';
|
|
12
|
+
export { BASE_UNITS, DEFINITIONS, DIMENSIONLESS, type Kind, type KnownKind, type LinearKind, type LogPart, PREFIXES, Unit, } from './units.ts';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,kBAAkB,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAC9F,cAAc,gBAAgB,CAAA;AAC9B,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAC5G,YAAY,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAA;AAChD,OAAO,EACL,KAAK,UAAU,EAAE,KAAK,OAAO,EAAE,gBAAgB,EAAE,oBAAoB,EAAE,KAAK,SAAS,EAAE,KAAK,WAAW,EAAE,QAAQ,EACjH,KAAK,aAAa,EAAE,KAAK,aAAa,EAAE,KAAK,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,GACvF,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AACvH,OAAO,EACL,cAAc,EAAE,KAAK,eAAe,EAAE,KAAK,MAAM,EAAE,SAAS,EAAE,KAAK,QAAQ,EAAE,KAAK,UAAU,EAAE,KAAK,UAAU,EAAE,KAAK,QAAQ,GAC7H,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EACL,KAAK,qBAAqB,EAAE,KAAK,kBAAkB,EAAE,KAAK,sBAAsB,EAAE,KAAK,cAAc,EAAE,KAAK,KAAK,EACjH,KAAK,eAAe,EAAE,KAAK,qBAAqB,EAAE,QAAQ,EAAE,KAAK,YAAY,EAC7E,KAAK,eAAe,EAAE,KAAK,oBAAoB,EAAE,KAAK,cAAc,EAAE,KAAK,WAAW,EAAE,KAAK,eAAe,EAC5G,eAAe,EAAE,aAAa,EAAE,CAAC,GAClC,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AACtE,OAAO,EAAE,IAAI,EAAE,KAAK,UAAU,EAAE,KAAK,SAAS,EAAE,KAAK,WAAW,EAAE,KAAK,SAAS,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AACzG,OAAO,EACL,UAAU,EAAE,WAAW,EAAE,aAAa,EAAE,KAAK,IAAI,EAAE,KAAK,SAAS,EAAE,KAAK,UAAU,EAAE,KAAK,OAAO,EAAE,QAAQ,EAAE,IAAI,GACjH,MAAM,YAAY,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// @arcosmos/astronomy: units and quantities with uncertainties, angles, directions on the sky
|
|
2
|
+
// in Astropy's frames with their space motion, and times in Astropy's scales, built on
|
|
3
|
+
// @arcosmos/erfa. No key, no network: it runs the same in a browser, Node, Deno, Bun or a Worker.
|
|
4
|
+
export { formatAngle, parseAngle } from './angles.js';
|
|
5
|
+
export * from './constants.js';
|
|
6
|
+
export { distanceFromParallax, distanceModulus, distanceModulusPc, parallaxDistancePc } from './distance.js';
|
|
7
|
+
export { FRAME_COMPONENTS, FRAME_PROPER_MOTIONS, SkyCoord, frameRotation, moveStar, skyCoord, } from './coordinates.js';
|
|
8
|
+
export { QuantityParseError, TimeParseError, UncertaintyError, UnitConversionError, UnitParseError } from './errors.js';
|
|
9
|
+
export { COMPOUND_KINDS, LOG_KINDS, } from './kinds.js';
|
|
10
|
+
export { parseUnit, unit } from './parse-unit.js';
|
|
11
|
+
export { Quantity, fromMeasurement, parseQuantity, q, } from './quantity.js';
|
|
12
|
+
export { roundToSignificant, roundToUncertainty } from './rounding.js';
|
|
13
|
+
export { Time, time } from './time.js';
|
|
14
|
+
export { BASE_UNITS, DEFINITIONS, DIMENSIONLESS, PREFIXES, Unit, } from './units.js';
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,8FAA8F;AAC9F,uFAAuF;AACvF,kGAAkG;AAClG,OAAO,EAA2C,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAC9F,cAAc,gBAAgB,CAAA;AAC9B,OAAO,EAAE,oBAAoB,EAAE,eAAe,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAE5G,OAAO,EAC0B,gBAAgB,EAAE,oBAAoB,EAAoC,QAAQ,EAC5D,aAAa,EAAE,QAAQ,EAAE,QAAQ,GACvF,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AACvH,OAAO,EACL,cAAc,EAAqC,SAAS,GAC7D,MAAM,YAAY,CAAA;AACnB,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EAE6C,QAAQ,EAE1D,eAAe,EAAE,aAAa,EAAE,CAAC,GAClC,MAAM,eAAe,CAAA;AACtB,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AACtE,OAAO,EAAE,IAAI,EAAqE,IAAI,EAAE,MAAM,WAAW,CAAA;AACzG,OAAO,EACL,UAAU,EAAE,WAAW,EAAE,aAAa,EAA4D,QAAQ,EAAE,IAAI,GACjH,MAAM,YAAY,CAAA"}
|
package/dist/kinds.d.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { DEFINITIONS, Kind, LinearKind, PREFIXES, Unit } from './units.ts';
|
|
2
|
+
type Definitions = typeof DEFINITIONS;
|
|
3
|
+
type Canonical = keyof Definitions;
|
|
4
|
+
/** Each canonical symbol and alias, with its kind. */
|
|
5
|
+
type SymbolKinds = {
|
|
6
|
+
[S in Canonical]: Definitions[S]['kind'];
|
|
7
|
+
} & {
|
|
8
|
+
[S in Canonical as Definitions[S] extends {
|
|
9
|
+
aliases: readonly (infer A extends string)[];
|
|
10
|
+
} ? A : never]: Definitions[S]['kind'];
|
|
11
|
+
};
|
|
12
|
+
type Prefix = keyof typeof PREFIXES;
|
|
13
|
+
type Prefixable = {
|
|
14
|
+
[S in Canonical]: Definitions[S] extends {
|
|
15
|
+
prefixes: true;
|
|
16
|
+
} ? S : never;
|
|
17
|
+
}[Canonical];
|
|
18
|
+
/** Logarithmic symbols. */
|
|
19
|
+
export declare const LOG_KINDS: {
|
|
20
|
+
readonly mag: 'magnitude';
|
|
21
|
+
readonly dex: 'dex';
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Compound units written often enough that the type system should know their kind. Written
|
|
25
|
+
* exactly as here; the same unit written another way is typed as any Kind.
|
|
26
|
+
*/
|
|
27
|
+
export declare const COMPOUND_KINDS: {
|
|
28
|
+
readonly '': 'dimensionless';
|
|
29
|
+
readonly 'km/s': 'speed';
|
|
30
|
+
readonly 'm/s': 'speed';
|
|
31
|
+
readonly 'cm/s': 'speed';
|
|
32
|
+
readonly 'au/d': 'speed';
|
|
33
|
+
readonly 'mas/yr': 'angular speed';
|
|
34
|
+
readonly 'arcsec/yr': 'angular speed';
|
|
35
|
+
readonly 'deg/d': 'angular speed';
|
|
36
|
+
readonly 'cm/s^2': 'acceleration';
|
|
37
|
+
readonly 'm/s^2': 'acceleration';
|
|
38
|
+
readonly 'W/m^2': 'energy flux';
|
|
39
|
+
readonly 'erg/(cm^2 s)': 'energy flux';
|
|
40
|
+
readonly 'erg/s': 'power';
|
|
41
|
+
readonly 'g/cm^3': 'mass density';
|
|
42
|
+
readonly 'kg/m^3': 'mass density';
|
|
43
|
+
readonly 'deg^2': 'solid angle';
|
|
44
|
+
readonly 'arcmin^2': 'solid angle';
|
|
45
|
+
readonly 'arcsec^2': 'solid angle';
|
|
46
|
+
readonly 'log10(L_sun)': 'log(power)';
|
|
47
|
+
readonly 'log10(cm/s^2)': 'log(acceleration)';
|
|
48
|
+
};
|
|
49
|
+
type LogKinds = typeof LOG_KINDS;
|
|
50
|
+
type CompoundKinds = typeof COMPOUND_KINDS;
|
|
51
|
+
/** The kinds a prefixed symbol could have: "km" is "length"; never when no prefix fits. */
|
|
52
|
+
type PrefixedKind<S extends string, P extends Prefix = Prefix> = P extends Prefix ? S extends `${P}${infer B extends Prefixable}` ? SymbolKinds[B] : never : never;
|
|
53
|
+
/** The kind of log10 of a unit of kind K: "log(power)" for log10(W). */
|
|
54
|
+
type LogKindOf<K> = [K] extends [LinearKind] ? `log(${K & LinearKind})` : Kind;
|
|
55
|
+
/** The kind of a unit written as S, or Kind when the type system can't tell. */
|
|
56
|
+
export type KindOf<S extends string> = string extends S ? Kind : S extends keyof SymbolKinds ? SymbolKinds[S] : S extends keyof LogKinds ? LogKinds[S] : S extends keyof CompoundKinds ? CompoundKinds[S] : S extends `log10(${infer X})` ? LogKindOf<KindOf<X>> : [PrefixedKind<S>] extends [never] ? Kind : PrefixedKind<S>;
|
|
57
|
+
/** Every unit the type system knows, with its kind. */
|
|
58
|
+
type KnownSymbols = keyof SymbolKinds | `${Prefix}${Prefixable}` | keyof LogKinds | keyof CompoundKinds;
|
|
59
|
+
/** The units of kind K the type system knows, for completion and checking: SymbolOf<"length"> includes "pc" and "km". */
|
|
60
|
+
export type SymbolOf<K extends string> = {
|
|
61
|
+
[S in keyof SymbolKinds]: SymbolKinds[S] extends K ? S : never;
|
|
62
|
+
}[keyof SymbolKinds] | {
|
|
63
|
+
[B in Prefixable]: SymbolKinds[B] extends K ? `${Prefix}${B}` : never;
|
|
64
|
+
}[Prefixable] | {
|
|
65
|
+
[S in keyof LogKinds]: LogKinds[S] extends K ? S : never;
|
|
66
|
+
}[keyof LogKinds] | {
|
|
67
|
+
[S in keyof CompoundKinds]: CompoundKinds[S] extends K ? S : never;
|
|
68
|
+
}[keyof CompoundKinds] | (K extends `log(${infer L extends LinearKind})` ? `log10(${SymbolOf<L>})` : never);
|
|
69
|
+
/** The kinds a quantity of kind K converts to: its own, and magnitudes and dex to each other. */
|
|
70
|
+
export type ConvertibleKind<K extends string> = K | (K extends 'magnitude' ? 'dex' : never) | (K extends 'dex' ? 'magnitude' : never);
|
|
71
|
+
/**
|
|
72
|
+
* The kinds a quantity of kind K converts to with `to`: ConvertibleKind's, and between log10 of
|
|
73
|
+
* a unit and the unit, and mag and dex and a plain number.
|
|
74
|
+
*/
|
|
75
|
+
export type ConversionKind<K extends string> = ConvertibleKind<K> | (K extends `log(${infer L extends LinearKind})` ? L : never) | (K extends Exclude<LinearKind, 'dimensionless'> ? `log(${K})` : never) | (K extends 'magnitude' | 'dex' ? 'dimensionless' : never) | (K extends 'dimensionless' ? 'magnitude' | 'dex' : never);
|
|
76
|
+
/**
|
|
77
|
+
* What a unit argument of kind K may be: a known unit of that kind, written out, for a known
|
|
78
|
+
* kind; any text for a kind the type system can't tell.
|
|
79
|
+
*/
|
|
80
|
+
export type UnitText<K extends string> = string extends K ? string : SymbolOf<K>;
|
|
81
|
+
/** A unit a quantity of kind K converts to, as text or a Unit. */
|
|
82
|
+
export type UnitTarget<K extends string> = UnitText<ConversionKind<K>> | Unit<ConversionKind<K>>;
|
|
83
|
+
/** The kind of a unit given as text or as a Unit. */
|
|
84
|
+
export type TargetKind<T> = T extends Unit<infer K> ? K : T extends string ? KindOf<T> : Kind;
|
|
85
|
+
export type { KnownSymbols };
|
|
86
|
+
//# sourceMappingURL=kinds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kinds.d.ts","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AAM,MAAM,QAAQ,CAAC,CAAC,SAAS,MAAM,IAAI,MAAM,SAAS,CAAC,GAAG,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;AAEhF,kEAAkE;AAClE,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,MAAM,IAAI,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAA;AAEhG,qDAAqD;AACrD,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAAC,SAAS,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,SAAS,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,CAAA;AAE7F,YAAY,EAAE,YAAY,EAAE,CAAA"}
|
package/dist/kinds.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** Logarithmic symbols. */
|
|
2
|
+
export const LOG_KINDS = { mag: 'magnitude', dex: 'dex' };
|
|
3
|
+
/**
|
|
4
|
+
* Compound units written often enough that the type system should know their kind. Written
|
|
5
|
+
* exactly as here; the same unit written another way is typed as any Kind.
|
|
6
|
+
*/
|
|
7
|
+
export const COMPOUND_KINDS = {
|
|
8
|
+
'': 'dimensionless',
|
|
9
|
+
'km/s': 'speed',
|
|
10
|
+
'm/s': 'speed',
|
|
11
|
+
'cm/s': 'speed',
|
|
12
|
+
'au/d': 'speed',
|
|
13
|
+
'mas/yr': 'angular speed',
|
|
14
|
+
'arcsec/yr': 'angular speed',
|
|
15
|
+
'deg/d': 'angular speed',
|
|
16
|
+
'cm/s^2': 'acceleration',
|
|
17
|
+
'm/s^2': 'acceleration',
|
|
18
|
+
'W/m^2': 'energy flux',
|
|
19
|
+
'erg/(cm^2 s)': 'energy flux',
|
|
20
|
+
'erg/s': 'power',
|
|
21
|
+
'g/cm^3': 'mass density',
|
|
22
|
+
'kg/m^3': 'mass density',
|
|
23
|
+
'deg^2': 'solid angle',
|
|
24
|
+
'arcmin^2': 'solid angle',
|
|
25
|
+
'arcsec^2': 'solid angle',
|
|
26
|
+
'log10(L_sun)': 'log(power)',
|
|
27
|
+
'log10(cm/s^2)': 'log(acceleration)',
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=kinds.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kinds.js","sourceRoot":"","sources":["../src/kinds.ts"],"names":[],"mappings":"AAmBA,2BAA2B;AAC3B,MAAM,CAAC,MAAM,SAAS,GAAG,EAAE,GAAG,EAAE,WAAW,EAAE,GAAG,EAAE,KAAK,EAAW,CAAA;AAElE;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,EAAE,EAAE,eAAe;IACnB,MAAM,EAAE,OAAO;IACf,KAAK,EAAE,OAAO;IACd,MAAM,EAAE,OAAO;IACf,MAAM,EAAE,OAAO;IACf,QAAQ,EAAE,eAAe;IACzB,WAAW,EAAE,eAAe;IAC5B,OAAO,EAAE,eAAe;IACxB,QAAQ,EAAE,cAAc;IACxB,OAAO,EAAE,cAAc;IACvB,OAAO,EAAE,aAAa;IACtB,cAAc,EAAE,aAAa;IAC7B,OAAO,EAAE,OAAO;IAChB,QAAQ,EAAE,cAAc;IACxB,QAAQ,EAAE,cAAc;IACxB,OAAO,EAAE,aAAa;IACtB,UAAU,EAAE,aAAa;IACzB,UAAU,EAAE,aAAa;IACzB,cAAc,EAAE,YAAY;IAC5B,eAAe,EAAE,mBAAmB;CACG,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { KindOf } from './kinds.ts';
|
|
2
|
+
import { type Kind, Unit } from './units.ts';
|
|
3
|
+
/** Reads a unit from text, such as "km/s". Throws a UnitParseError for text it can't read. */
|
|
4
|
+
export declare function parseUnit(text: string): Unit;
|
|
5
|
+
/**
|
|
6
|
+
* A unit from its text: `unit("km/s")`. Typed by its kind where the type system knows it; give
|
|
7
|
+
* the kind to name it otherwise, checked when it runs: `unit("au/yr", "speed")`.
|
|
8
|
+
*/
|
|
9
|
+
export declare function unit<const S extends string>(text: S): Unit<KindOf<S>>;
|
|
10
|
+
export declare function unit<K extends Kind>(text: string, kind: K): Unit<K>;
|
|
11
|
+
//# sourceMappingURL=parse-unit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-unit.d.ts","sourceRoot":"","sources":["../src/parse-unit.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACxC,OAAO,EAAiB,KAAK,IAAI,EAAY,IAAI,EAAc,MAAM,YAAY,CAAA;AAoMjF,8FAA8F;AAC9F,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAO5C;AAED;;;GAGG;AACH,wBAAgB,IAAI,CAAC,KAAK,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;AACtE,wBAAgB,IAAI,CAAC,CAAC,SAAS,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
// Reading units from text: "km/s", "mas/yr", "erg/(cm^2 s)", "m s-1", "log10(cm/s^2)".
|
|
2
|
+
//
|
|
3
|
+
// Symbols are multiplied by a space or `*`, and divided by `/`. A power follows `^` or `**`,
|
|
4
|
+
// or is written straight after the symbol ("m2", "s-1"), and may be a fraction: "m^(1/2)",
|
|
5
|
+
// "m^0.5" (written back as a fraction). After a `/`, a product needs parentheses: "W/(m^2 Hz)", or "W/m^2/Hz". Read either
|
|
6
|
+
// way, "W/m^2 Hz" is a guess, so it's an error rather than a choice made silently.
|
|
7
|
+
//
|
|
8
|
+
// mag and dex are logarithmic, and so is log10(X), Astropy's dex(X) (also read here). A
|
|
9
|
+
// logarithmic unit can't be part of a product.
|
|
10
|
+
import { UnitParseError } from './errors.js';
|
|
11
|
+
import { DIMENSIONLESS, REGISTRY, Unit, symbolUnit } from './units.js';
|
|
12
|
+
const SYMBOL = /^[A-Za-z_µμ]+/;
|
|
13
|
+
const ATTACHED_POWER = /^[-+]?\d+(?![.\d])/;
|
|
14
|
+
const NUMBER = /^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?/;
|
|
15
|
+
function tokenize(text) {
|
|
16
|
+
const tokens = [];
|
|
17
|
+
let rest = text;
|
|
18
|
+
while (rest.length) {
|
|
19
|
+
const c = rest[0];
|
|
20
|
+
if (/^\s/.test(rest)) {
|
|
21
|
+
rest = rest.replace(/^\s+/, '');
|
|
22
|
+
tokens.push({ type: ' ' });
|
|
23
|
+
}
|
|
24
|
+
else if (rest.startsWith('**')) {
|
|
25
|
+
tokens.push({ type: '^' });
|
|
26
|
+
rest = rest.slice(2);
|
|
27
|
+
}
|
|
28
|
+
else if (c === '(' || c === ')' || c === '/' || c === '*' || c === '^') {
|
|
29
|
+
tokens.push({ type: c });
|
|
30
|
+
rest = rest.slice(1);
|
|
31
|
+
}
|
|
32
|
+
else if (/^(?:log10|dex)\s*\(/.test(rest)) {
|
|
33
|
+
tokens.push({ type: 'log' });
|
|
34
|
+
rest = rest.replace(/^(?:log10|dex)\s*/, '');
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
const symbol = SYMBOL.exec(rest)?.[0];
|
|
38
|
+
if (symbol) {
|
|
39
|
+
rest = rest.slice(symbol.length);
|
|
40
|
+
const power = ATTACHED_POWER.exec(rest)?.[0];
|
|
41
|
+
if (power)
|
|
42
|
+
rest = rest.slice(power.length);
|
|
43
|
+
tokens.push({ type: 'symbol', text: symbol.replace(/[µμ]/g, 'u'), power: power ? Number(power) : null });
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
const number = NUMBER.exec(rest)?.[0];
|
|
47
|
+
if (!number)
|
|
48
|
+
throw new UnitParseError(`Unexpected "${c}" in the unit "${text}"`);
|
|
49
|
+
tokens.push({ type: 'number', text: number });
|
|
50
|
+
rest = rest.slice(number.length);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// A space is a product only between two factors: drop it at either end and around operators.
|
|
54
|
+
return tokens.filter((token, i) => {
|
|
55
|
+
if (token.type !== ' ')
|
|
56
|
+
return true;
|
|
57
|
+
const before = tokens[i - 1]?.type;
|
|
58
|
+
const after = tokens[i + 1]?.type;
|
|
59
|
+
const operand = (t) => t === 'symbol' || t === 'number' || t === 'log';
|
|
60
|
+
return (before === ')' || operand(before)) && (after === '(' || operand(after));
|
|
61
|
+
}).map((token) => (token.type === ' ' ? { type: '*' } : token));
|
|
62
|
+
}
|
|
63
|
+
class Parser {
|
|
64
|
+
i = 0;
|
|
65
|
+
tokens;
|
|
66
|
+
text;
|
|
67
|
+
constructor(tokens, text) {
|
|
68
|
+
this.tokens = tokens;
|
|
69
|
+
this.text = text;
|
|
70
|
+
}
|
|
71
|
+
parse() {
|
|
72
|
+
if (this.tokens.length === 0)
|
|
73
|
+
return DIMENSIONLESS;
|
|
74
|
+
const unit = this.expression(true);
|
|
75
|
+
if (this.i < this.tokens.length)
|
|
76
|
+
throw this.error(`Unexpected "${this.describe(this.tokens[this.i])}"`);
|
|
77
|
+
return unit;
|
|
78
|
+
}
|
|
79
|
+
/** A product, then any number of `/ factor`. */
|
|
80
|
+
expression(top) {
|
|
81
|
+
let unit = this.product(top);
|
|
82
|
+
while (this.peek()?.type === '/') {
|
|
83
|
+
this.i++;
|
|
84
|
+
unit = this.combine(unit, this.factor(false), 'div');
|
|
85
|
+
if (this.peek()?.type === '*') {
|
|
86
|
+
throw this.error('After "/", put a product in parentheses: write "W/(m^2 Hz)" or "W/m^2/Hz"');
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return unit;
|
|
90
|
+
}
|
|
91
|
+
product(top) {
|
|
92
|
+
let unit = this.factor(top);
|
|
93
|
+
while (this.peek()?.type === '*') {
|
|
94
|
+
this.i++;
|
|
95
|
+
unit = this.combine(unit, this.factor(false), 'times');
|
|
96
|
+
}
|
|
97
|
+
return unit;
|
|
98
|
+
}
|
|
99
|
+
/** An atom and its power. A logarithmic unit is allowed only where it is the whole unit. */
|
|
100
|
+
factor(top) {
|
|
101
|
+
const token = this.next();
|
|
102
|
+
let unit;
|
|
103
|
+
if (token?.type === 'symbol') {
|
|
104
|
+
unit = this.symbol(token.text);
|
|
105
|
+
if (token.power !== null)
|
|
106
|
+
unit = this.power(unit, token.power);
|
|
107
|
+
}
|
|
108
|
+
else if (token?.type === 'number') {
|
|
109
|
+
// Only the 1 of "1/s", or a 1 alone: "1 pc" would be a value misread as part of the unit.
|
|
110
|
+
if (Number(token.text) !== 1 || !(this.peek()?.type === '/' || (top && this.atEnd()))) {
|
|
111
|
+
throw this.error(`A number in a unit can only be the 1 of "1/s", not "${token.text}" here`);
|
|
112
|
+
}
|
|
113
|
+
unit = DIMENSIONLESS;
|
|
114
|
+
}
|
|
115
|
+
else if (token?.type === 'log') {
|
|
116
|
+
this.expect('(');
|
|
117
|
+
const physical = this.expression(false);
|
|
118
|
+
this.expect(')');
|
|
119
|
+
unit = Unit.logarithmic('dex', physical);
|
|
120
|
+
}
|
|
121
|
+
else if (token?.type === '(') {
|
|
122
|
+
unit = this.expression(false);
|
|
123
|
+
this.expect(')');
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
throw this.error(token ? `Unexpected "${this.describe(token)}"` : 'The unit ends too soon');
|
|
127
|
+
}
|
|
128
|
+
if (this.peek()?.type === '^') {
|
|
129
|
+
this.i++;
|
|
130
|
+
unit = this.power(unit, this.exponent());
|
|
131
|
+
}
|
|
132
|
+
if (unit.isLogarithmic && !(top && this.atEnd())) {
|
|
133
|
+
throw this.error(`${unit} is logarithmic and can't be multiplied, divided or raised to a power`);
|
|
134
|
+
}
|
|
135
|
+
return unit;
|
|
136
|
+
}
|
|
137
|
+
symbol(text) {
|
|
138
|
+
if (text === 'mag' || text === 'dex')
|
|
139
|
+
return Unit.logarithmic(text, DIMENSIONLESS);
|
|
140
|
+
const entry = REGISTRY.get(text);
|
|
141
|
+
if (!entry)
|
|
142
|
+
throw this.error(`Unknown unit "${text}"`);
|
|
143
|
+
return symbolUnit(text, entry);
|
|
144
|
+
}
|
|
145
|
+
/** A number, signed, or a fraction in parentheses: "2", "-1", "0.5", "(1/2)", "(-3/2)". */
|
|
146
|
+
exponent() {
|
|
147
|
+
const token = this.next();
|
|
148
|
+
if (token?.type === 'number')
|
|
149
|
+
return Number(token.text);
|
|
150
|
+
if (token?.type === '(') {
|
|
151
|
+
const top = this.next();
|
|
152
|
+
if (top?.type !== 'number')
|
|
153
|
+
throw this.error('A power in parentheses must be a number or a fraction');
|
|
154
|
+
let value = Number(top.text);
|
|
155
|
+
if (this.peek()?.type === '/') {
|
|
156
|
+
this.i++;
|
|
157
|
+
const bottom = this.next();
|
|
158
|
+
if (bottom?.type !== 'number' || Number(bottom.text) === 0)
|
|
159
|
+
throw this.error('A fractional power needs a non-zero denominator');
|
|
160
|
+
value /= Number(bottom.text);
|
|
161
|
+
}
|
|
162
|
+
this.expect(')');
|
|
163
|
+
return value;
|
|
164
|
+
}
|
|
165
|
+
throw this.error('A power must follow "^"');
|
|
166
|
+
}
|
|
167
|
+
power(unit, n) {
|
|
168
|
+
if (unit.isLogarithmic)
|
|
169
|
+
throw this.error(`${unit} is logarithmic and can't be raised to a power`);
|
|
170
|
+
return unit.pow(n);
|
|
171
|
+
}
|
|
172
|
+
combine(a, b, op) {
|
|
173
|
+
if (a.isLogarithmic || b.isLogarithmic) {
|
|
174
|
+
throw this.error(`${a.isLogarithmic ? a : b} is logarithmic and can't be multiplied or divided`);
|
|
175
|
+
}
|
|
176
|
+
return op === 'times' ? a.times(b) : a.div(b);
|
|
177
|
+
}
|
|
178
|
+
atEnd() {
|
|
179
|
+
return this.i >= this.tokens.length;
|
|
180
|
+
}
|
|
181
|
+
peek() {
|
|
182
|
+
return this.tokens[this.i];
|
|
183
|
+
}
|
|
184
|
+
next() {
|
|
185
|
+
return this.tokens[this.i++];
|
|
186
|
+
}
|
|
187
|
+
expect(type) {
|
|
188
|
+
const token = this.next();
|
|
189
|
+
if (token?.type !== type)
|
|
190
|
+
throw this.error(`Expected "${type}"`);
|
|
191
|
+
}
|
|
192
|
+
describe(token) {
|
|
193
|
+
if (!token)
|
|
194
|
+
return 'the end';
|
|
195
|
+
if (token.type === 'symbol' || token.type === 'number')
|
|
196
|
+
return token.text;
|
|
197
|
+
return token.type === 'log' ? 'log10' : token.type;
|
|
198
|
+
}
|
|
199
|
+
error(message) {
|
|
200
|
+
return new UnitParseError(`${message} (in the unit "${this.text}")`);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
const cache = new Map();
|
|
204
|
+
/** Reads a unit from text, such as "km/s". Throws a UnitParseError for text it can't read. */
|
|
205
|
+
export function parseUnit(text) {
|
|
206
|
+
const cached = cache.get(text);
|
|
207
|
+
if (cached)
|
|
208
|
+
return cached;
|
|
209
|
+
const parsed = new Parser(tokenize(text), text).parse();
|
|
210
|
+
if (cache.size >= 1000)
|
|
211
|
+
cache.clear();
|
|
212
|
+
cache.set(text, parsed);
|
|
213
|
+
return parsed;
|
|
214
|
+
}
|
|
215
|
+
export function unit(text, kind) {
|
|
216
|
+
const parsed = parseUnit(text);
|
|
217
|
+
if (kind !== undefined && parsed.kind !== kind) {
|
|
218
|
+
throw new UnitParseError(`"${text}" is a unit of ${parsed.kind}, not ${kind}`);
|
|
219
|
+
}
|
|
220
|
+
return parsed;
|
|
221
|
+
}
|
|
222
|
+
//# sourceMappingURL=parse-unit.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-unit.js","sourceRoot":"","sources":["../src/parse-unit.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,EAAE;AACF,6FAA6F;AAC7F,2FAA2F;AAC3F,2HAA2H;AAC3H,mFAAmF;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,IAAI;QAAE,KAAK,CAAC,KAAK,EAAE,CAAA;IACrC,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,CAAA;IACvB,OAAO,MAAM,CAAA;AACf,CAAC;AAQD,MAAM,UAAU,IAAI,CAAC,IAAY,EAAE,IAAa;IAC9C,MAAM,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC,CAAA;IAC9B,IAAI,IAAI,KAAK,SAAS,IAAI,MAAM,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;QAC/C,MAAM,IAAI,cAAc,CAAC,IAAI,IAAI,kBAAkB,MAAM,CAAC,IAAI,SAAS,IAAI,EAAE,CAAC,CAAA;IAChF,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import type { ConvertibleKind, KindOf, TargetKind, UnitTarget } from './kinds.ts';
|
|
2
|
+
import { type Kind, Unit } from './units.ts';
|
|
3
|
+
/** A one-sigma error, in the value's unit. */
|
|
4
|
+
export interface SymmetricUncertainty {
|
|
5
|
+
readonly kind: 'symmetric';
|
|
6
|
+
readonly value: number;
|
|
7
|
+
}
|
|
8
|
+
/** Upper and lower errors, in the value's unit: plus >= 0, minus <= 0. Either may be unknown. */
|
|
9
|
+
export interface AsymmetricUncertainty {
|
|
10
|
+
readonly kind: 'asymmetric';
|
|
11
|
+
readonly plus: number | null;
|
|
12
|
+
readonly minus: number | null;
|
|
13
|
+
}
|
|
14
|
+
/** The 16th and 84th percentiles of a distribution whose median is the value, in its unit. */
|
|
15
|
+
export interface PercentileUncertainty {
|
|
16
|
+
readonly kind: 'percentiles';
|
|
17
|
+
readonly p16: number | null;
|
|
18
|
+
readonly p84: number | null;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* An error ellipse, as SIMBAD gives for a proper motion: the uncertainty of the motion as a
|
|
22
|
+
* vector, so both of its components carry the same ellipse. Its axes are one-sigma errors in
|
|
23
|
+
* the value's unit, and `angle_deg` is the major axis's position angle, east of north, in
|
|
24
|
+
* degrees. Any part may be unknown.
|
|
25
|
+
*/
|
|
26
|
+
export interface EllipseUncertainty {
|
|
27
|
+
readonly kind: 'error_ellipse';
|
|
28
|
+
readonly major: number | null;
|
|
29
|
+
readonly minor: number | null;
|
|
30
|
+
readonly angle_deg: number | null;
|
|
31
|
+
}
|
|
32
|
+
/** An uncertainty in the form its source publishes it. */
|
|
33
|
+
export type Uncertainty = SymmetricUncertainty | AsymmetricUncertainty | PercentileUncertainty | EllipseUncertainty;
|
|
34
|
+
/** An error ellipse as the API writes it: its axes in `unit`, which may differ from the value's. */
|
|
35
|
+
export interface EllipseUncertaintyJSON extends EllipseUncertainty {
|
|
36
|
+
readonly unit: string | null;
|
|
37
|
+
}
|
|
38
|
+
/** An uncertainty as the API writes it. */
|
|
39
|
+
export type UncertaintyJSON = Exclude<Uncertainty, EllipseUncertainty> | EllipseUncertaintyJSON;
|
|
40
|
+
/** Set when a value is a limit rather than a measurement. */
|
|
41
|
+
export type Limit = 'upper' | 'lower';
|
|
42
|
+
export interface QuantityOptions {
|
|
43
|
+
/** A one-sigma error, in the value's unit. 0 for an exact value. */
|
|
44
|
+
readonly sigma?: number;
|
|
45
|
+
/** Any other form of uncertainty. Give this or sigma, not both. */
|
|
46
|
+
readonly uncertainty?: Uncertainty | null;
|
|
47
|
+
readonly limit?: Limit | null;
|
|
48
|
+
}
|
|
49
|
+
/** A quantity as JSON, in the shape of the API's measurements. Dimensionless is a null unit. */
|
|
50
|
+
export interface QuantityJSON {
|
|
51
|
+
readonly value: number;
|
|
52
|
+
readonly unit: string | null;
|
|
53
|
+
readonly uncertainty: UncertaintyJSON | null;
|
|
54
|
+
readonly limit?: Limit;
|
|
55
|
+
}
|
|
56
|
+
/** How symmetrized() turns asymmetric errors into one: the larger side, or the mean of the two. */
|
|
57
|
+
export type SymmetrizeRule = 'larger' | 'mean';
|
|
58
|
+
/**
|
|
59
|
+
* A value with a unit, and its uncertainty if known. `K` is its kind, such as "length", where
|
|
60
|
+
* the type system can tell. Make one with `q(10, "ly")`. Immutable: every operation returns a
|
|
61
|
+
* new quantity.
|
|
62
|
+
*/
|
|
63
|
+
export declare class Quantity<K extends string = Kind> {
|
|
64
|
+
readonly value: number;
|
|
65
|
+
readonly unit: Unit<K>;
|
|
66
|
+
/** Null when no uncertainty is known. */
|
|
67
|
+
readonly uncertainty: Uncertainty | null;
|
|
68
|
+
/** Set when the value is an upper or lower limit rather than a measurement. */
|
|
69
|
+
readonly limit: Limit | null;
|
|
70
|
+
constructor(value: number, unit: Unit<K>, uncertainty?: Uncertainty | null, limit?: Limit | null);
|
|
71
|
+
/** The kind of quantity, such as "length". */
|
|
72
|
+
get kind(): K;
|
|
73
|
+
/** The one-sigma error when the uncertainty is symmetric; null otherwise. */
|
|
74
|
+
get sigma(): number | null;
|
|
75
|
+
/**
|
|
76
|
+
* The quantity in another unit of the same kind: `q(10, "ly").to("pc")`. Exact, uncertainty
|
|
77
|
+
* included. Magnitudes and dex convert to each other, and log10 of a unit to the unit
|
|
78
|
+
* (`q(5.25, "log10(L_sun)").to("L_sun")`) and back, each end of an error converted.
|
|
79
|
+
*/
|
|
80
|
+
to<Q extends Quantity<string>, const T extends UnitTarget<KindOfQuantity<Q>>>(this: Q, target: T): Quantity<TargetKind<T>>;
|
|
81
|
+
/** The value in another unit: `q(10, "ly").valueIn("pc")`. */
|
|
82
|
+
valueIn<Q extends Quantity<string>>(this: Q, target: UnitTarget<KindOfQuantity<Q>>): number;
|
|
83
|
+
/** The same quantity typed as kind K2, checked when it runs: `a.div(b).as("speed")`. */
|
|
84
|
+
as<K2 extends Kind>(kind: K2): Quantity<K2>;
|
|
85
|
+
/** The sum, in this quantity's unit. Sigmas add in quadrature. */
|
|
86
|
+
plus<Q extends Quantity<string>>(this: Q, other: Quantity<ConvertibleKind<KindOfQuantity<Q>>>): Quantity<KindOfQuantity<Q>>;
|
|
87
|
+
/** The difference, in this quantity's unit. Sigmas add in quadrature. */
|
|
88
|
+
minus<Q extends Quantity<string>>(this: Q, other: Quantity<ConvertibleKind<KindOfQuantity<Q>>>): Quantity<KindOfQuantity<Q>>;
|
|
89
|
+
/** Times a number, which is exact, or times a quantity, with first-order propagation. */
|
|
90
|
+
times(factor: number): Quantity<K>;
|
|
91
|
+
times(other: Quantity<string>): Quantity;
|
|
92
|
+
/** Divided by a number, which is exact, or by a quantity, with first-order propagation. */
|
|
93
|
+
div(divisor: number): Quantity<K>;
|
|
94
|
+
div(other: Quantity<string>): Quantity;
|
|
95
|
+
/** To a power, with first-order propagation: sigma times |n a^(n-1)|. */
|
|
96
|
+
pow(n: number): Quantity;
|
|
97
|
+
/** The negative of the quantity. Plus and minus swap, as do upper and lower limits. */
|
|
98
|
+
negate(): Quantity<K>;
|
|
99
|
+
/**
|
|
100
|
+
* The quantity with a symmetric sigma in place of asymmetric errors or percentiles: the
|
|
101
|
+
* larger side (the API's rule for its derived values), or the mean of the two. Null when
|
|
102
|
+
* either side is unknown. An error ellipse is refused: its error along one component
|
|
103
|
+
* depends on which component this is, which the quantity doesn't know.
|
|
104
|
+
*/
|
|
105
|
+
symmetrized(rule?: SymmetrizeRule): Quantity<K>;
|
|
106
|
+
/**
|
|
107
|
+
* -1, 0 or 1 as this quantity is less than, equal to or greater than the other, uncertainties
|
|
108
|
+
* aside. A magnitude and a dex don't compare: mag runs the other way, so neither order would
|
|
109
|
+
* be the obvious one.
|
|
110
|
+
*/
|
|
111
|
+
compare<Q extends Quantity<string>>(this: Q, other: Quantity<KindOfQuantity<Q>>): number;
|
|
112
|
+
/** "1.2 ± 0.1 mas", "0.5 +0.2 -0.1 M_jup", "< 3 M_earth". */
|
|
113
|
+
toString(): string;
|
|
114
|
+
/** The quantity in the API's shape. An error ellipse names its unit, the value's. */
|
|
115
|
+
toJSON(): QuantityJSON;
|
|
116
|
+
/** Scaled by a number: exact, carrying every form of uncertainty but an ellipse, and the limit. */
|
|
117
|
+
private scaled;
|
|
118
|
+
}
|
|
119
|
+
/** The kind of a quantity type: KindOfQuantity<Quantity<"length">> is "length". */
|
|
120
|
+
export type KindOfQuantity<Q> = Q extends Quantity<infer K> ? K : never;
|
|
121
|
+
/**
|
|
122
|
+
* Refuses limits, asymmetric errors, percentiles and error ellipses, which first-order
|
|
123
|
+
* propagation doesn't define. @internal Not part of the package's API (distance.ts uses it).
|
|
124
|
+
*/
|
|
125
|
+
export declare function requireArithmetic(q: Quantity<string>, verb: string): void;
|
|
126
|
+
/**
|
|
127
|
+
* A quantity: `q(10, "ly")`, `q(1.2, "mas", { sigma: 0.1 })`. Typed by the unit's kind where
|
|
128
|
+
* the type system knows it.
|
|
129
|
+
*/
|
|
130
|
+
export declare function q<const S extends string>(value: number, unit: S, options?: QuantityOptions): Quantity<KindOf<S>>;
|
|
131
|
+
export declare function q<K extends string>(value: number, unit: Unit<K>, options?: QuantityOptions): Quantity<K>;
|
|
132
|
+
/** A measurement as the Arcosmos API returns it (only the fields read here). */
|
|
133
|
+
export interface MeasurementLike {
|
|
134
|
+
readonly value: number | string;
|
|
135
|
+
readonly unit: string | null;
|
|
136
|
+
readonly uncertainty?: Uncertainty | UncertaintyJSON | null;
|
|
137
|
+
readonly limit?: Limit | null;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* A quantity from one of the API's measurements, with its uncertainty and limit. An error
|
|
141
|
+
* ellipse (SIMBAD's proper motions) is kept, its axes in the value's unit. A label (such as a
|
|
142
|
+
* spectral type) isn't a quantity, and throws.
|
|
143
|
+
*/
|
|
144
|
+
export declare function fromMeasurement(measurement: MeasurementLike): Quantity;
|
|
145
|
+
/**
|
|
146
|
+
* A quantity from text: "10 ly", "-1.46 mag", "1.2 ± 0.1 mas" (or "+/-"). A number alone is
|
|
147
|
+
* dimensionless. Throws a QuantityParseError, or a UnitParseError for an unknown unit.
|
|
148
|
+
*/
|
|
149
|
+
export declare function parseQuantity(text: string): Quantity;
|
|
150
|
+
//# sourceMappingURL=quantity.d.ts.map
|
|
@@ -0,0 +1 @@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