@fhss-web-team/fuzzy-dates 1.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/LICENSE +21 -0
- package/README.md +52 -0
- package/dist/fuzzyDate/collate/collate.d.ts +2 -0
- package/dist/fuzzyDate/collate/collate.js +15 -0
- package/dist/fuzzyDate/fuzzyDate.d.ts +206 -0
- package/dist/fuzzyDate/fuzzyDate.js +220 -0
- package/dist/fuzzyDate/fuzzyDate.spec.d.ts +1 -0
- package/dist/fuzzyDate/fuzzyDate.spec.js +158 -0
- package/dist/fuzzyDate/gedcomX/toGedcomX.d.ts +2 -0
- package/dist/fuzzyDate/gedcomX/toGedcomX.js +31 -0
- package/dist/fuzzyDate/normalize/normalize.d.ts +2 -0
- package/dist/fuzzyDate/normalize/normalize.js +47 -0
- package/dist/fuzzyDate/parse/index.d.ts +187 -0
- package/dist/fuzzyDate/parse/index.js +91 -0
- package/dist/fuzzyDate/parse/inputDateFormats.d.ts +204 -0
- package/dist/fuzzyDate/parse/inputDateFormats.js +225 -0
- package/dist/fuzzyDate/parse/modifiers.d.ts +240 -0
- package/dist/fuzzyDate/parse/modifiers.js +193 -0
- package/dist/fuzzyDate/parse/stringToDate.d.ts +38 -0
- package/dist/fuzzyDate/parse/stringToDate.js +24 -0
- package/dist/fuzzyDate/types.d.ts +79 -0
- package/dist/fuzzyDate/types.js +88 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +46 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { err } from '../types';
|
|
2
|
+
import { dayMonthDigitYear, dayMonthStringYear, decade, monthDigitYear, monthStringDayYear, monthStringYear, year, yearMonthDigitDay, yearDayMonthString, yearMonthDigit, yearMonthString, yearMonthStringDay, } from './inputDateFormats';
|
|
3
|
+
export function stringToDate(dateInput) {
|
|
4
|
+
const parsers = [
|
|
5
|
+
year,
|
|
6
|
+
monthStringYear,
|
|
7
|
+
yearMonthString,
|
|
8
|
+
dayMonthStringYear,
|
|
9
|
+
monthStringDayYear,
|
|
10
|
+
yearMonthStringDay,
|
|
11
|
+
yearDayMonthString,
|
|
12
|
+
monthDigitYear,
|
|
13
|
+
yearMonthDigit,
|
|
14
|
+
dayMonthDigitYear,
|
|
15
|
+
yearMonthDigitDay,
|
|
16
|
+
decade,
|
|
17
|
+
];
|
|
18
|
+
for (const parseFormat of parsers) {
|
|
19
|
+
const result = parseFormat(dateInput);
|
|
20
|
+
if (result)
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
return err('Unknown date format.');
|
|
24
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
type Ok<T> = {
|
|
2
|
+
ok: true;
|
|
3
|
+
value: T;
|
|
4
|
+
};
|
|
5
|
+
type Err<E = unknown> = {
|
|
6
|
+
ok: false;
|
|
7
|
+
error: E;
|
|
8
|
+
};
|
|
9
|
+
export type Result<T, E> = Ok<T> | Err<E>;
|
|
10
|
+
export declare function ok<T = undefined>(value?: T): Ok<T>;
|
|
11
|
+
export declare function err<E>(error: E): Err<E>;
|
|
12
|
+
export declare const DATE_NEG_INFINITY: Date;
|
|
13
|
+
export declare const DATE_POS_INFINITY: Date;
|
|
14
|
+
export declare const FORMAT_ORDER: readonly ["YYYYs", "YYYY", "SEASON_YYYY", "MMMM_YYYY", "D_MMMM_YYYY"];
|
|
15
|
+
export type NormalFormat = (typeof FORMAT_ORDER)[number];
|
|
16
|
+
export declare const MODIFIER_ORDER: readonly ["BEFORE", "ABOUT", "NONE", "EARLY", "MID", "LATE", "FROM", "BETWEEN", "AFTER"];
|
|
17
|
+
export type FuzzyDateModifier = (typeof MODIFIER_ORDER)[number];
|
|
18
|
+
export type FuzzyDateValue = {
|
|
19
|
+
format: NormalFormat;
|
|
20
|
+
minDate: Date;
|
|
21
|
+
maxDate: Date;
|
|
22
|
+
};
|
|
23
|
+
export type FuzzyDateModel = {
|
|
24
|
+
original: string;
|
|
25
|
+
modifier: FuzzyDateModifier;
|
|
26
|
+
start: FuzzyDateValue;
|
|
27
|
+
end: FuzzyDateValue;
|
|
28
|
+
};
|
|
29
|
+
export declare const MONTH_SEASON_MAP: {
|
|
30
|
+
readonly spring: 3;
|
|
31
|
+
readonly summer: 6;
|
|
32
|
+
readonly fall: 9;
|
|
33
|
+
readonly autumn: 9;
|
|
34
|
+
readonly winter: 12;
|
|
35
|
+
};
|
|
36
|
+
export declare function isSeason(input: string): input is keyof typeof MONTH_SEASON_MAP;
|
|
37
|
+
export declare const SEASON_MONTH_MAP: {
|
|
38
|
+
readonly 1: "winter";
|
|
39
|
+
readonly 2: "winter";
|
|
40
|
+
readonly 3: "spring";
|
|
41
|
+
readonly 4: "spring";
|
|
42
|
+
readonly 5: "spring";
|
|
43
|
+
readonly 6: "summer";
|
|
44
|
+
readonly 7: "summer";
|
|
45
|
+
readonly 8: "summer";
|
|
46
|
+
readonly 9: "fall";
|
|
47
|
+
readonly 10: "fall";
|
|
48
|
+
readonly 11: "fall";
|
|
49
|
+
readonly 12: "winter";
|
|
50
|
+
};
|
|
51
|
+
export declare function isSeasonMonth(input: number): input is keyof typeof SEASON_MONTH_MAP;
|
|
52
|
+
export declare const MONTH_NAME_MAP: {
|
|
53
|
+
readonly jan: 1;
|
|
54
|
+
readonly january: 1;
|
|
55
|
+
readonly feb: 2;
|
|
56
|
+
readonly february: 2;
|
|
57
|
+
readonly mar: 3;
|
|
58
|
+
readonly march: 3;
|
|
59
|
+
readonly apr: 4;
|
|
60
|
+
readonly april: 4;
|
|
61
|
+
readonly may: 5;
|
|
62
|
+
readonly jun: 6;
|
|
63
|
+
readonly june: 6;
|
|
64
|
+
readonly jul: 7;
|
|
65
|
+
readonly july: 7;
|
|
66
|
+
readonly aug: 8;
|
|
67
|
+
readonly august: 8;
|
|
68
|
+
readonly sep: 9;
|
|
69
|
+
readonly sept: 9;
|
|
70
|
+
readonly september: 9;
|
|
71
|
+
readonly oct: 10;
|
|
72
|
+
readonly october: 10;
|
|
73
|
+
readonly nov: 11;
|
|
74
|
+
readonly november: 11;
|
|
75
|
+
readonly dec: 12;
|
|
76
|
+
readonly december: 12;
|
|
77
|
+
};
|
|
78
|
+
export declare function isMonth(input: string): input is keyof typeof MONTH_NAME_MAP;
|
|
79
|
+
export {};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
export function ok(value) {
|
|
2
|
+
return {
|
|
3
|
+
ok: true,
|
|
4
|
+
value,
|
|
5
|
+
};
|
|
6
|
+
}
|
|
7
|
+
export function err(error) {
|
|
8
|
+
return {
|
|
9
|
+
ok: false,
|
|
10
|
+
error,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export const DATE_NEG_INFINITY = new Date(-8640000000000000);
|
|
14
|
+
export const DATE_POS_INFINITY = new Date(8640000000000000);
|
|
15
|
+
export const FORMAT_ORDER = [
|
|
16
|
+
'YYYYs',
|
|
17
|
+
'YYYY',
|
|
18
|
+
'SEASON_YYYY',
|
|
19
|
+
'MMMM_YYYY',
|
|
20
|
+
'D_MMMM_YYYY',
|
|
21
|
+
];
|
|
22
|
+
export const MODIFIER_ORDER = [
|
|
23
|
+
'BEFORE',
|
|
24
|
+
'ABOUT',
|
|
25
|
+
'NONE',
|
|
26
|
+
'EARLY',
|
|
27
|
+
'MID',
|
|
28
|
+
'LATE',
|
|
29
|
+
'FROM',
|
|
30
|
+
'BETWEEN',
|
|
31
|
+
'AFTER',
|
|
32
|
+
];
|
|
33
|
+
export const MONTH_SEASON_MAP = {
|
|
34
|
+
spring: 3,
|
|
35
|
+
summer: 6,
|
|
36
|
+
fall: 9,
|
|
37
|
+
autumn: 9,
|
|
38
|
+
winter: 12,
|
|
39
|
+
};
|
|
40
|
+
export function isSeason(input) {
|
|
41
|
+
return Object.keys(MONTH_SEASON_MAP).includes(input);
|
|
42
|
+
}
|
|
43
|
+
export const SEASON_MONTH_MAP = {
|
|
44
|
+
1: 'winter',
|
|
45
|
+
2: 'winter',
|
|
46
|
+
3: 'spring',
|
|
47
|
+
4: 'spring',
|
|
48
|
+
5: 'spring',
|
|
49
|
+
6: 'summer',
|
|
50
|
+
7: 'summer',
|
|
51
|
+
8: 'summer',
|
|
52
|
+
9: 'fall',
|
|
53
|
+
10: 'fall',
|
|
54
|
+
11: 'fall',
|
|
55
|
+
12: 'winter',
|
|
56
|
+
};
|
|
57
|
+
export function isSeasonMonth(input) {
|
|
58
|
+
return input >= 1 && input <= 12;
|
|
59
|
+
}
|
|
60
|
+
export const MONTH_NAME_MAP = {
|
|
61
|
+
jan: 1,
|
|
62
|
+
january: 1,
|
|
63
|
+
feb: 2,
|
|
64
|
+
february: 2,
|
|
65
|
+
mar: 3,
|
|
66
|
+
march: 3,
|
|
67
|
+
apr: 4,
|
|
68
|
+
april: 4,
|
|
69
|
+
may: 5,
|
|
70
|
+
jun: 6,
|
|
71
|
+
june: 6,
|
|
72
|
+
jul: 7,
|
|
73
|
+
july: 7,
|
|
74
|
+
aug: 8,
|
|
75
|
+
august: 8,
|
|
76
|
+
sep: 9,
|
|
77
|
+
sept: 9,
|
|
78
|
+
september: 9,
|
|
79
|
+
oct: 10,
|
|
80
|
+
october: 10,
|
|
81
|
+
nov: 11,
|
|
82
|
+
november: 11,
|
|
83
|
+
dec: 12,
|
|
84
|
+
december: 12,
|
|
85
|
+
};
|
|
86
|
+
export function isMonth(input) {
|
|
87
|
+
return Object.keys(MONTH_NAME_MAP).includes(input);
|
|
88
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { FuzzyDate } from './fuzzyDate/fuzzyDate';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { FuzzyDate } from './fuzzyDate/fuzzyDate';
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fhss-web-team/fuzzy-dates",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Parses imprecise date strings into a structured form that can be normalized, indexed, searched, and ordered while preserving the original input.",
|
|
5
|
+
"homepage": "https://github.com/FHSS-Web-Team/CFHG-fuzzy-dates#readme",
|
|
6
|
+
"bugs": {
|
|
7
|
+
"url": "https://github.com/FHSS-Web-Team/CFHG-fuzzy-dates/issues"
|
|
8
|
+
},
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "git+https://github.com/FHSS-Web-Team/CFHG-fuzzy-dates.git"
|
|
12
|
+
},
|
|
13
|
+
"main": "./dist/index.js",
|
|
14
|
+
"module": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"import": "./dist/index.js"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist",
|
|
24
|
+
"README.md",
|
|
25
|
+
"LICENSE"
|
|
26
|
+
],
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"author": "",
|
|
29
|
+
"type": "module",
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "npm run clean && tsc",
|
|
32
|
+
"test": "vitest",
|
|
33
|
+
"test:run": "vitest run",
|
|
34
|
+
"clean": "rm -rf dist",
|
|
35
|
+
"prepublishOnly": "npm run clean && npm run build",
|
|
36
|
+
"preversion": "npm run build",
|
|
37
|
+
"postversion": "git push",
|
|
38
|
+
"deploy": "npm run build && npm publish --access public"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"prettier": "^3.6.2",
|
|
42
|
+
"ts-node": "^10.9.2",
|
|
43
|
+
"typescript": "^5.0.0",
|
|
44
|
+
"vitest": "^4.0.0"
|
|
45
|
+
}
|
|
46
|
+
}
|