@treeviz/gedcom-parser 1.0.6 → 1.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/classes/date.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Locale } from "date-fns";
|
|
1
2
|
import type { IdType, MultiTag } from "../types/types";
|
|
2
3
|
import type { Range } from "../utils/range";
|
|
3
4
|
import { Common } from "./common";
|
|
@@ -17,7 +18,7 @@ export declare class CommonDate extends Common<string> {
|
|
|
17
18
|
assign<T extends Common | List = Common | List>(name: MultiTag, value: T, unique?: boolean): T;
|
|
18
19
|
private isValidDateFormat;
|
|
19
20
|
toNote(short?: boolean): string | undefined;
|
|
20
|
-
toValue(dateFormat?: string): string | undefined;
|
|
21
|
+
toValue(dateFormat?: string, locale?: Locale): string | undefined;
|
|
21
22
|
exportValue(): string;
|
|
22
23
|
inRange(range: Range, trueIfNoYear?: boolean): boolean;
|
|
23
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../src/classes/date.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../src/classes/date.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAKvC,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAGvD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EAAE,MAAM,EAA6B,MAAM,UAAU,CAAC;AAC7D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAkDnC,qBAAa,UAAW,SAAQ,MAAM,CAAC,MAAM,CAAC;IAC7C,OAAO,CAAC,KAAK,CAAC,CAAO;IAErB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;gBAGb,MAAM,CAAC,EAAE,UAAU,EACnB,EAAE,CAAC,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,MAAM,EACb,MAAM,CAAC,EAAE,MAAM;IAOhB,IAAI,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,EA0ElC;IAED,IAAI,KAAK,IA5EQ,MAAM,GAAG,SAAS,CA+FlC;IAED,IAAI,QAAQ,SAEX;IAED,MAAM,CAAC,CAAC,SAAS,MAAM,GAAG,IAAI,GAAG,MAAM,GAAG,IAAI,EAC7C,IAAI,EAAE,QAAQ,EACd,KAAK,EAAE,CAAC,EACR,MAAM,UAAQ;IAUf,OAAO,CAAC,iBAAiB;IAgBzB,MAAM,CAAC,KAAK,UAAO,GAAG,MAAM,GAAG,SAAS;IAUxC,OAAO,CAAC,UAAU,SAAgB,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAuBxE,WAAW;IAIX,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE,YAAY,UAAQ;CAG1C;AAED,eAAO,MAAM,gBAAgB,GAC5B,SAAS,UAAU,EACnB,KAAK,MAAM,EACX,OAAO,MAAM,EACb,SAAS,MAAM,KACb,aAAa,CAAC,UAAU,CAI1B,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,QAAQ,OAAO,KAAG,KAAK,IAAI,UAOvD,CAAC"}
|
package/dist/classes/date.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { format, isValid, parse } from "date-fns";
|
|
2
|
+
import { enUS } from "date-fns/locale";
|
|
2
3
|
import { getDateLocale } from "../factories/index.js";
|
|
3
4
|
import { ACCEPTED_DATE_FORMATS } from "../utils/date-formatter.js";
|
|
4
5
|
import { inRange } from "../utils/range.js";
|
|
@@ -12,7 +13,7 @@ const NOTE_MARKER = "####";
|
|
|
12
13
|
/**
|
|
13
14
|
* Format a date based on available components (DAY, MONTH, YEAR, NOTE)
|
|
14
15
|
*/
|
|
15
|
-
const formatDateWithComponents = (date, hasDay, hasMonth, hasYear, noteValue, baseFormat = "dd MMM yyyy") => {
|
|
16
|
+
const formatDateWithComponents = (date, hasDay, hasMonth, hasYear, noteValue, baseFormat = "dd MMM yyyy", locale) => {
|
|
16
17
|
const hasNote = baseFormat.includes("NOTE");
|
|
17
18
|
let validDateFormat = baseFormat.replace("NOTE", NOTE_MARKER);
|
|
18
19
|
if (!hasDay) {
|
|
@@ -28,7 +29,7 @@ const formatDateWithComponents = (date, hasDay, hasMonth, hasYear, noteValue, ba
|
|
|
28
29
|
.replace(/([.\-\s/])\1+/g, "$1")
|
|
29
30
|
.replace(/^[.\-\s/]+|[.\-\s/]+$/g, "");
|
|
30
31
|
const formattedDate = format(date, validDateFormat, {
|
|
31
|
-
locale: getDateLocale(),
|
|
32
|
+
locale: locale ? locale : getDateLocale(),
|
|
32
33
|
});
|
|
33
34
|
// Add NOTE prefix if it exists
|
|
34
35
|
return noteValue && hasNote
|
|
@@ -147,7 +148,7 @@ export class CommonDate extends Common {
|
|
|
147
148
|
}
|
|
148
149
|
return note;
|
|
149
150
|
}
|
|
150
|
-
toValue(dateFormat = "dd MMM yyyy") {
|
|
151
|
+
toValue(dateFormat = "dd MMM yyyy", locale) {
|
|
151
152
|
const hasDay = !!this.DAY?.value;
|
|
152
153
|
const hasMonth = !!this.MONTH?.value;
|
|
153
154
|
const hasYear = !!this.YEAR?.value;
|
|
@@ -156,10 +157,10 @@ export class CommonDate extends Common {
|
|
|
156
157
|
(!hasDay && !hasMonth && !hasYear)) {
|
|
157
158
|
return this._value;
|
|
158
159
|
}
|
|
159
|
-
return formatDateWithComponents(this._date, hasDay, hasMonth, hasYear, this.NOTE?.value, dateFormat);
|
|
160
|
+
return formatDateWithComponents(this._date, hasDay, hasMonth, hasYear, this.NOTE?.value, dateFormat, locale);
|
|
160
161
|
}
|
|
161
162
|
exportValue() {
|
|
162
|
-
return this.toValue("NOTE dd MMM yyyy");
|
|
163
|
+
return this.toValue("NOTE dd MMM yyyy", enUS);
|
|
163
164
|
}
|
|
164
165
|
inRange(range, trueIfNoYear = false) {
|
|
165
166
|
return inRange(this.YEAR?.value, range, trueIfNoYear);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@treeviz/gedcom-parser",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.7",
|
|
4
4
|
"description": "Lightweight, pluggable GEDCOM parser for JavaScript/TypeScript with optional caching and place matching. Zero browser dependencies.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|