@domorium/validator 1.8.1 → 2.0.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 +187 -0
- package/README.md +21 -16
- package/dist/completion/dateSlot.d.ts +2 -1
- package/dist/document/gedcomDocument.d.ts +4 -6
- package/dist/index.cjs.js +2 -2
- package/dist/index.esm.js +766 -506
- package/dist/parser/lineIndex.d.ts +1 -0
- package/dist/validator/calendarDays.d.ts +8 -4
- package/dist/validator/calendars.d.ts +38 -0
- package/dist/validator/epoch.d.ts +11 -0
- package/dist/validator/rule-node.d.ts +3 -1
- package/dist/validator/validate.d.ts +8 -1
- package/package.json +1 -1
|
@@ -5,5 +5,6 @@ import type { Position } from "../types/position";
|
|
|
5
5
|
* per token, which is where most of a large document's memory went.
|
|
6
6
|
*/
|
|
7
7
|
export type LineIndex = Int32Array;
|
|
8
|
+
/** 5.5.1 ends a line with CR, LF, CR-LF or LF-CR. See #251. */
|
|
8
9
|
export declare function createLineIndex(text: string): LineIndex;
|
|
9
10
|
export declare function offsetToPosition(index: LineIndex, offset: number): Position;
|
|
@@ -2,10 +2,14 @@
|
|
|
2
2
|
* The part of a date the grammar cannot express: `31 FEB` is two well-formed
|
|
3
3
|
* tokens naming a day February does not have.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* Which calendars there are and which months each takes is the schema's, read
|
|
6
|
+
* through calendars.ts. What is here is the arithmetic the specification never
|
|
7
|
+
* states: how long a month is, and which years February gets a 29th in.
|
|
8
|
+
* GREGORIAN and JULIAN share the twelve month tags and their lengths and differ
|
|
9
|
+
* only in that rule, which is why one table serves both.
|
|
8
10
|
*/
|
|
11
|
+
import { GedcomScheme } from "../schemes/schema-types";
|
|
12
|
+
export declare const LENGTHS: Record<string, number>;
|
|
9
13
|
export interface ImpossibleDay {
|
|
10
14
|
day: number;
|
|
11
15
|
month: string;
|
|
@@ -14,4 +18,4 @@ export interface ImpossibleDay {
|
|
|
14
18
|
}
|
|
15
19
|
export declare function isLeapYear(year: number, calendar: string): boolean;
|
|
16
20
|
export declare function daysInMonth(month: string, year: number | null, calendar: string): number | null;
|
|
17
|
-
export declare function impossibleDays(value: string): ImpossibleDay[];
|
|
21
|
+
export declare function impossibleDays(scheme: GedcomScheme, value: string): ImpossibleDay[];
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one reader of the schema's `calendar` table, for everything that has to
|
|
3
|
+
* know which calendars there are, which months each takes and which epoch may
|
|
4
|
+
* close a year: the 5.5.1 date rules, the GEDCOM 7 date grammar, the day-length
|
|
5
|
+
* check and date completion.
|
|
6
|
+
*
|
|
7
|
+
* Month lengths are not here and not in the schema. The specification gives
|
|
8
|
+
* `day = Integer` and says no more, so a length is arithmetic rather than
|
|
9
|
+
* vocabulary; calendarDays.ts holds it, and a test binds its table to this one.
|
|
10
|
+
*/
|
|
11
|
+
import { GedcomScheme, GedcomTag } from "../schemes/schema-types";
|
|
12
|
+
/** An absent calendar means GREGORIAN, in both dialects. */
|
|
13
|
+
export declare const DEFAULT_CALENDAR: GedcomTag;
|
|
14
|
+
export interface Vocabulary {
|
|
15
|
+
/** Permitted months, or null where the schema describes no such calendar. */
|
|
16
|
+
months: Set<string> | null;
|
|
17
|
+
epochs: Set<string> | null;
|
|
18
|
+
}
|
|
19
|
+
export declare function vocabularyOf(scheme: GedcomScheme, calendar: GedcomTag): Vocabulary;
|
|
20
|
+
/**
|
|
21
|
+
* An extension tag that is not an alias is accepted in any of the three slots a
|
|
22
|
+
* calendar constrains: an extension calendar defines its own months and epochs,
|
|
23
|
+
* and rejecting an undeclared one here would report files this validator cannot
|
|
24
|
+
* prove wrong. An alias resolves to the standard tag it abbreviates and is held
|
|
25
|
+
* to the calendar's own vocabulary like any other standard tag.
|
|
26
|
+
*/
|
|
27
|
+
export declare function permits(vocabulary: Set<string> | null, token: string): boolean;
|
|
28
|
+
/** How 5.5.1 writes a calendar, which is the form completion has to offer. */
|
|
29
|
+
export declare function calendarEscape(calendar: string): string;
|
|
30
|
+
/** The calendar a token names, in either dialect's form, or null. */
|
|
31
|
+
export declare function calendarNamed(scheme: GedcomScheme, token: string): GedcomTag | null;
|
|
32
|
+
/** The leading calendar escape 5.5.1 puts in front of a date, and the rest. */
|
|
33
|
+
export declare function stripCalendarEscape(value: string): {
|
|
34
|
+
calendar: GedcomTag | null;
|
|
35
|
+
rest: string;
|
|
36
|
+
};
|
|
37
|
+
/** The tokens of a date, with an escape kept whole however it is spaced. */
|
|
38
|
+
export declare function dateTokens(value: string): string[];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 5.5.1 carries no epoch in `YEAR_GREG` at all. The only statement about one is
|
|
3
|
+
* prose — "A (B.C.) appended to the <YEAR> indicates a date before the birth of
|
|
4
|
+
* Christ" — with no dated example, so neither the spelling nor the delimiter is
|
|
5
|
+
* fixed, and exports write `BC`, `B.C.` and `BCE` alike. See issue #239.
|
|
6
|
+
*
|
|
7
|
+
* GEDCOM 7 pins its epoch in the schema, which date-v7.ts reads from there, so
|
|
8
|
+
* nothing below belongs to it.
|
|
9
|
+
*/
|
|
10
|
+
export declare const EPOCH_SRC = "(?:[Bb][Cc][Ee]|[Bb]\\.?[Cc]\\.?)";
|
|
11
|
+
export declare function isEpoch(token: string | undefined): boolean;
|
|
@@ -2,7 +2,8 @@ import { GedcomScheme, GedcomType } from "../schemes/schema-types";
|
|
|
2
2
|
import { ASTNode } from "../parser";
|
|
3
3
|
import { GedcomError } from "../types/errors";
|
|
4
4
|
import { ExtensionContext } from "./extensions";
|
|
5
|
-
type FieldType = "boolean" | "string" | "nonNegativeInteger" | "select" | "multiselect" | "date" | "date-v7" | "date-period" | "date-period-v7" | "date-exact" | "date-exact-v7" | "time" | "time-v7" | "pointer" | "age" | "personal-name" | "media-type" | "language-tag" | "tag-def" | null;
|
|
5
|
+
type FieldType = "boolean" | "string" | "nonNegativeInteger" | "select" | "multiselect" | "date" | "date-v7" | "date-period" | "date-period-v7" | "date-exact" | "date-exact-v7" | "time" | "time-v7" | "pointer" | "age" | "age-v7" | "personal-name" | "latitude" | "longitude" | "media-type" | "language-tag" | "tag-def" | null;
|
|
6
|
+
export declare const PAYLOAD_FIELD_TYPES: Record<string, Exclude<FieldType, null>>;
|
|
6
7
|
export declare class RuleNode {
|
|
7
8
|
private readonly scheme;
|
|
8
9
|
private readonly pointerMap;
|
|
@@ -27,5 +28,6 @@ export declare class RuleNode {
|
|
|
27
28
|
private getUniversalType;
|
|
28
29
|
getNodeType(node: ASTNode): GedcomType;
|
|
29
30
|
validate(node: ASTNode, _tagType?: GedcomType): GedcomError[];
|
|
31
|
+
collect(errors: GedcomError[], node: ASTNode, _tagType?: GedcomType): void;
|
|
30
32
|
}
|
|
31
33
|
export {};
|
|
@@ -2,6 +2,10 @@ import { GedcomType, GedcomScheme } from "../schemes/schema-types";
|
|
|
2
2
|
import { ASTNode } from "../parser";
|
|
3
3
|
import { GedcomError } from "../types/errors";
|
|
4
4
|
import { ExtensionContext } from "./extensions";
|
|
5
|
+
export declare function parseCardinality(str: string): {
|
|
6
|
+
min: number;
|
|
7
|
+
max: number;
|
|
8
|
+
} | null;
|
|
5
9
|
export declare function schemeFor(nodes: ASTNode[]): GedcomScheme;
|
|
6
10
|
export declare class GedcomValidator {
|
|
7
11
|
private readonly pointers;
|
|
@@ -12,5 +16,8 @@ export declare class GedcomValidator {
|
|
|
12
16
|
/** A fragment is not a document, so nothing is required of its root. */
|
|
13
17
|
fragment?: boolean);
|
|
14
18
|
setScheme(nodes: ASTNode[]): GedcomScheme;
|
|
15
|
-
validate(nodes: ASTNode[], parentType?: GedcomType, _scheme?: GedcomScheme): GedcomError[];
|
|
19
|
+
validate(nodes: ASTNode[], parentType?: GedcomType, _scheme?: GedcomScheme, parent?: ASTNode): GedcomError[];
|
|
20
|
+
collect(errors: GedcomError[], nodes: ASTNode[], parentType: GedcomType, scheme: GedcomScheme,
|
|
21
|
+
/** Absent at the root, where the start of the document is the honest place. */
|
|
22
|
+
parent?: ASTNode): void;
|
|
16
23
|
}
|