@tempo-kit/plugin-dialects 0.0.0-stage → 2.0.0-rc.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/CHANGELOG.md +115 -0
- package/LICENSE +21 -0
- package/README.md +65 -2
- package/dist/compiler/dotnet.compiler.d.ts +28 -0
- package/dist/compiler/go.compiler.d.ts +28 -0
- package/dist/compiler/ldml.compiler.d.ts +28 -0
- package/dist/compiler/mysql.compiler.d.ts +21 -0
- package/dist/compiler/oracle.compiler.d.ts +39 -0
- package/dist/compiler/php.compiler.d.ts +30 -0
- package/dist/compiler/shared.compiler.d.ts +86 -0
- package/dist/compiler/sheet.compiler.d.ts +32 -0
- package/dist/compiler/strftime.compiler.d.ts +28 -0
- package/dist/constants.d.ts +54 -0
- package/dist/engine/convert.d.ts +14 -0
- package/dist/engine/dialect.registry.d.ts +40 -0
- package/dist/engine/dialect.shim.d.ts +4 -0
- package/dist/engine/explain.d.ts +13 -0
- package/dist/engine/export.d.ts +12 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.global.min.js +1 -0
- package/dist/index.js +5791 -0
- package/dist/install.d.ts +2 -0
- package/dist/install.global.min.js +1 -0
- package/dist/install.js +5794 -0
- package/dist/types.d.ts +152 -0
- package/package.json +70 -5
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ValueOf } from 'tempo-kit/library';
|
|
2
|
+
import { type Dialect } from '../constants.js';
|
|
3
|
+
import type { DialectOptions } from '../compiler/shared.compiler.js';
|
|
4
|
+
/**
|
|
5
|
+
* Detects the dialect from a format mask string if not explicitly supplied.
|
|
6
|
+
* Checks strftime, Go, then Oracle heuristics outside single-quoted literals, falling back to LDML.
|
|
7
|
+
* PHP and Moment require an explicit dialect.
|
|
8
|
+
*
|
|
9
|
+
* @param dialectOrOptions - A dialect name or zero-argument supplier, or an object with a `dialect` value
|
|
10
|
+
* @throws Errors from evaluating a dialect supplier propagate to the caller.
|
|
11
|
+
*/
|
|
12
|
+
export declare function detectDialect(mask: string, dialectOrOptions?: any): Dialect;
|
|
13
|
+
export declare const MOMENT_TOKENS: readonly ["YYYY", "YY", "GGGG", "GG", "gggg", "gg", "DDDD", "DDDo", "DDD", "DD", "Do", "D", "dddd", "ddd", "dd", "do", "d", "Mo", "WW", "Wo", "W", "ww", "w", "Qo", "ZZ", "Z", "E", "e", "A", "a", "X", "x", "LLLL", "llll", "LLL", "lll", "LTS", "LT", "LL", "ll", "L", "l"];
|
|
14
|
+
export type MomentToken = ValueOf<typeof MOMENT_TOKENS>;
|
|
15
|
+
/**
|
|
16
|
+
* Maps Moment.js token specifiers to their equivalent Unicode LDML targets.
|
|
17
|
+
*
|
|
18
|
+
* In Moment.js, `GGGG`/`GG` represent ISO-8601 week-numbering year (mapping to LDML `YYYY`/`YY`),
|
|
19
|
+
* `WW`/`W` represent ISO-8601 week of year (mapping to LDML `ww`/`w`), and `E` represents
|
|
20
|
+
* 1-indexed ISO weekday (mapping to LDML `e`). Locale-dependent week tokens (`gggg`, `gg`, `ww`, `w`)
|
|
21
|
+
* are deliberately omitted without mapping so they trigger unsupported-token errors, as Tempo
|
|
22
|
+
* strictly standardizes on ISO week rules.
|
|
23
|
+
*/
|
|
24
|
+
export declare const MOMENT_TO_LDML_MAP: Readonly<Record<string, string>>;
|
|
25
|
+
/**
|
|
26
|
+
* Translates a Moment.js format mask into standard LDML.
|
|
27
|
+
*/
|
|
28
|
+
export declare function translateMomentToLdml(mask: string): string;
|
|
29
|
+
/**
|
|
30
|
+
* Formats a date using the appropriate dialect compiler.
|
|
31
|
+
*/
|
|
32
|
+
export declare function formatWithDialect(zdt: Temporal.ZonedDateTime, mask: string, options?: DialectOptions): string;
|
|
33
|
+
/**
|
|
34
|
+
* Parses an input string with a dialect mask, detecting the dialect when omitted.
|
|
35
|
+
* Returns undefined when the selected parser rejects input, including unsupported Oracle parse tokens.
|
|
36
|
+
*
|
|
37
|
+
* @param options - Dialect and parser defaults, including `today`, `timeZone` (UTC by default), and `calendar` (iso8601 by default)
|
|
38
|
+
* @throws Errors from evaluating a dialect supplier propagate; Temporal construction failures return undefined.
|
|
39
|
+
*/
|
|
40
|
+
export declare function parseWithDialect(input: string, mask: string, options?: DialectOptions): Temporal.ZonedDateTime | undefined;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ExplainResult, ExplainedToken, ExplainOptions } from '../types.js';
|
|
2
|
+
export type { ExplainedToken, ExplainResult, ExplainOptions };
|
|
3
|
+
/**
|
|
4
|
+
* Translates external dialect masks into native Tempo format patterns (`{yyyy}-{mm}-{dd}`)
|
|
5
|
+
* and returns detailed token explanations to aid incremental migration.
|
|
6
|
+
* Unmapped text is retained; Oracle FM/FX modifiers are omitted from the pattern.
|
|
7
|
+
*
|
|
8
|
+
* @param dialectOrOptions - A dialect name or supplier, or an object with `dialect`; omitted values use detection
|
|
9
|
+
* @returns A deeply frozen result whose string form is the translated pattern. An empty `tempo` mapping
|
|
10
|
+
* identifies a recognized token without a native equivalent or an Oracle FM/FX modifier.
|
|
11
|
+
* @throws Errors from evaluating a dialect supplier propagate to the caller.
|
|
12
|
+
*/
|
|
13
|
+
export declare function explain(mask: string, dialectOrOptions?: any): ExplainResult;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ExportResult } from '../types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Exports a native Tempo format pattern into the corresponding external dialect format model.
|
|
4
|
+
* Unsupported tokens remain in the pattern. Go literal conflicts and fractional tokens without
|
|
5
|
+
* a preceding decimal point are also reported as unsupported. Adjacency conflicts between
|
|
6
|
+
* successive tokens are not detected.
|
|
7
|
+
*
|
|
8
|
+
* @param dialectOrOptions - Target dialect name or supplier, or an object with `dialect`; defaults to LDML
|
|
9
|
+
* @returns A deeply frozen result with token mappings and an `unsupported` list; its string form is the pattern
|
|
10
|
+
* @throws Errors from evaluating a dialect supplier propagate to the caller.
|
|
11
|
+
*/
|
|
12
|
+
export declare function exportDialect(tempoMask: string, dialectOrOptions?: any): ExportResult;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type TempoPlugin } from 'tempo-kit/plugin/sdk';
|
|
2
|
+
import { DIALECT, DIALECT_ALIAS, normalizeDialect, type Dialect, type DialectAlias } from './constants.js';
|
|
3
|
+
import { detectDialect, formatWithDialect, parseWithDialect } from './engine/dialect.registry.js';
|
|
4
|
+
import { formatLdml, parseLdml, LDML_TOKENS, type LdmlToken } from './compiler/ldml.compiler.js';
|
|
5
|
+
import { formatStrftime, parseStrftime, STRFTIME_SPECIFIERS, type StrftimeSpecifier } from './compiler/strftime.compiler.js';
|
|
6
|
+
import { formatOracle, parseOracle, ORACLE_TOKENS, ORACLE_UNSUPPORTED_PARSE_TOKENS, type OracleToken } from './compiler/oracle.compiler.js';
|
|
7
|
+
import { formatPhp, parsePhp, PHP_TOKENS, type PhpToken } from './compiler/php.compiler.js';
|
|
8
|
+
import { formatGo, parseGo } from './compiler/go.compiler.js';
|
|
9
|
+
import { formatMysql, parseMysql, MYSQL_SPECIFIERS, type MysqlSpecifier } from './compiler/mysql.compiler.js';
|
|
10
|
+
import { formatDotNet, parseDotNet, DOTNET_TOKENS, type DotNetSpecifier } from './compiler/dotnet.compiler.js';
|
|
11
|
+
import { formatSheet, parseSheet, SHEET_TOKENS, type SheetSpecifier } from './compiler/sheet.compiler.js';
|
|
12
|
+
import { validateResolvedDateFields, type ExtractedDateMetadata } from './compiler/shared.compiler.js';
|
|
13
|
+
import { MOMENT_TOKENS, MOMENT_TO_LDML_MAP, type MomentToken } from './engine/dialect.registry.js';
|
|
14
|
+
import { explain } from './engine/explain.js';
|
|
15
|
+
import { exportDialect } from './engine/export.js';
|
|
16
|
+
import { convertDialect } from './engine/convert.js';
|
|
17
|
+
import type { ConvertOptions, ConvertResult, DialectsInstanceNamespace, DialectsStaticNamespace, ExplainOptions, ExplainResult, ExplainedToken, ExportOptions, ExportResult, ExportedToken } from './types.js';
|
|
18
|
+
export { DIALECT, DIALECT_ALIAS, normalizeDialect, detectDialect, formatWithDialect, parseWithDialect, formatLdml, parseLdml, LDML_TOKENS, formatStrftime, parseStrftime, STRFTIME_SPECIFIERS, formatOracle, parseOracle, ORACLE_TOKENS, ORACLE_UNSUPPORTED_PARSE_TOKENS, formatPhp, parsePhp, PHP_TOKENS, formatGo, parseGo, formatMysql, parseMysql, MYSQL_SPECIFIERS, formatDotNet, parseDotNet, DOTNET_TOKENS, formatSheet, parseSheet, SHEET_TOKENS, validateResolvedDateFields, MOMENT_TOKENS, MOMENT_TO_LDML_MAP, explain, exportDialect, convertDialect, };
|
|
19
|
+
export type { ConvertOptions, ConvertResult, ExtractedDateMetadata, Dialect, DialectAlias, DialectsInstanceNamespace, DialectsStaticNamespace, ExplainOptions, ExplainResult, ExplainedToken, ExportOptions, ExportResult, ExportedToken, LdmlToken, StrftimeSpecifier, OracleToken, PhpToken, MomentToken, MysqlSpecifier, DotNetSpecifier, SheetSpecifier, };
|
|
20
|
+
/**
|
|
21
|
+
* ## DialectsPlugin
|
|
22
|
+
* Extends Tempo with external format dialects (Unicode LDML, Luxon, Moment, POSIX strftime, Oracle/SQL TO_CHAR).
|
|
23
|
+
*/
|
|
24
|
+
export declare const DialectsPlugin: TempoPlugin;
|
|
25
|
+
export declare const dialectsPlugin: TempoPlugin;
|
|
26
|
+
export default DialectsPlugin;
|