@resumekit/schema 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.
@@ -0,0 +1,118 @@
1
+ const norm = (value) => String(value ?? '')
2
+ .toLowerCase()
3
+ .replace(/[^a-z0-9]/g, '');
4
+ /**
5
+ * What makes two entries the SAME entry, per section.
6
+ *
7
+ * A role is its employer and when it began — not its title or bullets, which a
8
+ * tailored resume rewrites, so a reworded role is still recognised as the one
9
+ * already on the page. Everything else is recognised by the name it is listed
10
+ * under.
11
+ */
12
+ export function entryIdentity(section, item) {
13
+ if (typeof item === 'string')
14
+ return norm(item);
15
+ const it = (item ?? {});
16
+ switch (section) {
17
+ case 'experience':
18
+ return `${norm(it['company'])}|${String(it['start'] ?? '').slice(0, 7)}`;
19
+ case 'education':
20
+ return `${norm(it['school'])}|${norm(it['degree'])}`;
21
+ case 'skills':
22
+ return norm(it['category']);
23
+ case 'links':
24
+ return norm(String(it['url'] ?? '').replace(/^https?:\/\/(www\.)?/i, ''));
25
+ case 'languages':
26
+ return norm(it['name']);
27
+ case 'achievements':
28
+ case 'courses':
29
+ case 'passions':
30
+ return norm(it['title']);
31
+ case 'certifications':
32
+ return norm(item);
33
+ }
34
+ }
35
+ /** The profile's entries of `section` that `present` does not already carry. */
36
+ export function libraryCandidates(section, present, library) {
37
+ const available = (library?.[section] ?? []);
38
+ if (available.length === 0)
39
+ return [];
40
+ const have = new Set(present.map((item) => entryIdentity(section, item)));
41
+ return available.filter((item) => {
42
+ const key = entryIdentity(section, item);
43
+ return key.length > 0 && key !== '|' && !have.has(key);
44
+ });
45
+ }
46
+ /** How an entry is named in a list: a title and, when there is one, a detail line. */
47
+ export function describeLibraryEntry(section, item) {
48
+ if (typeof item === 'string')
49
+ return { title: item };
50
+ const it = (item ?? {});
51
+ const s = (key) => typeof it[key] === 'string' ? it[key] : '';
52
+ const joined = (...parts) => parts.filter(Boolean).join(' · ') || undefined;
53
+ switch (section) {
54
+ case 'experience':
55
+ return {
56
+ title: s('title') || s('company'),
57
+ detail: joined(s('company'), [s('start'), s('end')].filter(Boolean).join(' – ')),
58
+ };
59
+ case 'education':
60
+ return {
61
+ title: s('school'),
62
+ detail: joined([s('degree'), s('field')].filter(Boolean).join(', '), s('end')),
63
+ };
64
+ case 'skills': {
65
+ const items = Array.isArray(it['items']) ? it['items'] : [];
66
+ return {
67
+ title: s('category') || 'Skills',
68
+ detail: items.slice(0, 6).join(', ') || undefined,
69
+ };
70
+ }
71
+ case 'links':
72
+ return {
73
+ title: s('label') || s('url'),
74
+ detail: s('label') ? s('url') : undefined,
75
+ };
76
+ case 'languages':
77
+ return { title: s('name'), detail: s('level') || undefined };
78
+ default:
79
+ return { title: s('title'), detail: s('description') || undefined };
80
+ }
81
+ }
82
+ const sameText = (text) => text
83
+ .toLowerCase()
84
+ .replace(/[^a-z0-9]+/g, ' ')
85
+ .trim();
86
+ /** The profile's version of a role on the resume: same employer, same start. */
87
+ export function libraryRole(role, library) {
88
+ const key = entryIdentity('experience', role);
89
+ if (key === '|')
90
+ return undefined;
91
+ return library?.experience.find((entry) => entryIdentity('experience', entry) === key);
92
+ }
93
+ /**
94
+ * The bullets the profile holds for this role that the resume's version of it
95
+ * does not — compared by their words, so a bullet that differs only in
96
+ * punctuation or case is not offered twice.
97
+ */
98
+ export function libraryBullets(role, present, library) {
99
+ const match = libraryRole(role, library);
100
+ if (!match)
101
+ return [];
102
+ const have = new Set(present.map(sameText));
103
+ return match.bullets.filter((bullet) => {
104
+ const key = sameText(bullet);
105
+ return key.length > 0 && !have.has(key);
106
+ });
107
+ }
108
+ /**
109
+ * Everything the profile can add, seen from one role: more of this role, and
110
+ * other roles. One answer for both, so a role already on the page never hides
111
+ * the bullets the resume left out of it.
112
+ */
113
+ export function experienceOffer(role, present, library) {
114
+ return {
115
+ bullets: libraryBullets(role, role.bullets ?? [], library),
116
+ roles: libraryCandidates('experience', present, library),
117
+ };
118
+ }
@@ -0,0 +1,11 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * The languages a document can be drawn in. A closed set: adding a language is
4
+ * adding it here and a catalog in `@resumekit/react`.
5
+ */
6
+ export declare const LocaleSchema: z.ZodEnum<{
7
+ en: "en";
8
+ es: "es";
9
+ }>;
10
+ export type Locale = z.infer<typeof LocaleSchema>;
11
+ //# sourceMappingURL=locale.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locale.d.ts","sourceRoot":"","sources":["../src/locale.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;GAGG;AACH,eAAO,MAAM,YAAY;;;EAAuB,CAAC;AACjD,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC"}
package/dist/locale.js ADDED
@@ -0,0 +1,6 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * The languages a document can be drawn in. A closed set: adding a language is
4
+ * adding it here and a catalog in `@resumekit/react`.
5
+ */
6
+ export const LocaleSchema = z.enum(['en', 'es']);
@@ -0,0 +1,122 @@
1
+ import type { ResumeObject } from './resume.js';
2
+ /**
3
+ * Whether a résumé's dates read the way a recruiter expects them to.
4
+ *
5
+ * The rules are NOT invented here. Both are already in the knowledge base, and
6
+ * both already bind the writer through `GUIDE`:
7
+ *
8
+ * - `reverse-chronological` — "List experience and education in reverse
9
+ * chronological order", because "recruiters expect the most recent, most
10
+ * relevant role first within a six-second scan".
11
+ * - `date-format` — "YYYY-MM, and 'Present' for the current role".
12
+ *
13
+ * What was missing is that neither bound the CANDIDATE. The editor lets them add
14
+ * a role, drag it anywhere and type any date into it, so a résumé could be
15
+ * exported with 2019 above 2024, or with a role that ends before it starts, and
16
+ * the first reader to notice was the recruiter doing the six-second scan.
17
+ *
18
+ * Pure and framework-free: no I/O, no model call, no clock. Comparing two dates
19
+ * is arithmetic, and a check the product can make itself must not become a
20
+ * billable request.
21
+ *
22
+ * @pii Reads employment dates and returns PATHS and an enum — never a date, and
23
+ * never anything that identifies the candidate.
24
+ */
25
+ /** What was noticed about a date. */
26
+ export type DateIssueKind =
27
+ /** The range ends before it starts. */
28
+ 'ends-before-start'
29
+ /** This entry is more recent than the one above it. */
30
+ | 'out-of-order';
31
+ export interface DateIssue {
32
+ kind: DateIssueKind;
33
+ /** The entry this is about, e.g. `experience.1`. */
34
+ entryPath: string;
35
+ /** The fields to mark, e.g. `['experience.1.start', 'experience.1.end']`. */
36
+ fields: string[];
37
+ }
38
+ /**
39
+ * The word for a role that has not ended, in each language a resume can be
40
+ * translated to. Stored `Present` in English; a translation writes the target
41
+ * language's word instead, from this table rather than the model, so it costs
42
+ * nothing and reads the same in every resume.
43
+ */
44
+ export declare const PRESENT_WORDS: {
45
+ readonly en: "Present";
46
+ readonly es: "Actualidad";
47
+ readonly fr: "Aujourd'hui";
48
+ readonly de: "Heute";
49
+ readonly pt: "Atual";
50
+ readonly it: "Presente";
51
+ readonly nl: "Heden";
52
+ readonly pl: "Obecnie";
53
+ readonly ro: "Prezent";
54
+ readonly ru: "Настоящее время";
55
+ readonly uk: "Дотепер";
56
+ readonly tr: "Günümüz";
57
+ readonly sv: "Nu";
58
+ readonly zh: "至今";
59
+ readonly ja: "現在";
60
+ readonly ko: "현재";
61
+ readonly hi: "वर्तमान";
62
+ readonly id: "Sekarang";
63
+ };
64
+ /** Whether an end date says the role has not ended, in any language. */
65
+ export declare function isPresentDate(value: string | undefined): boolean;
66
+ /**
67
+ * A date reduced to a number that sorts, or `null` when it cannot be read.
68
+ *
69
+ * `null` is the important return. A candidate mid-keystroke has `20`, and a
70
+ * résumé written like the reference one has `Feb 2024` — neither is wrong, and
71
+ * reporting either as an error would be the editor refusing a document that is
72
+ * perfectly good. Only what can be READ is judged; everything else is left
73
+ * alone. That is why this returns `null` rather than `0` or `NaN`.
74
+ *
75
+ * `Present` is the LARGEST value rather than today's date, deliberately: it
76
+ * means "has not ended", which outranks any month a candidate could type, and
77
+ * using a clock here would make the same résumé report differently tomorrow.
78
+ */
79
+ export declare function dateOrder(value: string | undefined): number | null;
80
+ /**
81
+ * Every date in a résumé that disagrees with the chronological rules.
82
+ *
83
+ * Sections are checked INDEPENDENTLY: experience running most-recent-first says
84
+ * nothing about education, and a section nobody has dated yet must not suppress
85
+ * the check on one that is complete.
86
+ */
87
+ export declare function resumeDateIssues(resume: ResumeObject): DateIssue[];
88
+ /**
89
+ * The same check, over the order the document is actually DRAWN in.
90
+ *
91
+ * This replaces a version that scanned `experience.<n>.start` keys and walked
92
+ * them by `n`, and that was wrong in the one case the feature exists for.
93
+ *
94
+ * A path follows the JOB, not the position: a résumé the candidate has
95
+ * reordered renders `experience.2` in first place, and its fields keep saying
96
+ * `experience.2.*` so a stored edit follows the role rather than the slot. So
97
+ * the path index says where an entry STARTED, and reverse-chronological order
98
+ * is a claim about where it is NOW. Walking by index compared entries in an
99
+ * order nobody was looking at — and reported nothing on the very document a
100
+ * candidate had just dragged into the wrong order, which is exactly when they
101
+ * need telling.
102
+ *
103
+ * The caller passes the prefixes in drawn order, taken from the same
104
+ * `collectionOrder` the document lays itself out with, so the check and the
105
+ * page cannot disagree about which entry is above which.
106
+ *
107
+ * @param sections one array of entry path prefixes per section, each in the
108
+ * order the section is drawn — e.g. `[['experience.2', 'experience.0']]`.
109
+ * @param valueAt reads a field's current value, live from the editor.
110
+ */
111
+ export declare function dateIssuesInDrawnOrder(sections: readonly (readonly string[])[], valueAt: (path: string) => string | undefined): Map<string, DateIssueKind>;
112
+ /** What the editor says about each kind, in the candidate's terms. */
113
+ export declare const DATE_ISSUE_MESSAGE: Record<DateIssueKind, string>;
114
+ /**
115
+ * The issues keyed by the FIELD path each one marks.
116
+ *
117
+ * Keyed by path because that is the address a field already knows itself by, so
118
+ * a field can ask "is there anything about me?" without knowing the résumé's
119
+ * shape — and every template gets this without being edited.
120
+ */
121
+ export declare function dateIssuesByField(resume: ResumeObject): Map<string, DateIssueKind>;
122
+ //# sourceMappingURL=resume-dates.d.ts.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aAAa,CAAC,CAU5B"}
@@ -0,0 +1,185 @@
1
+ /**
2
+ * The word for a role that has not ended, in each language a resume can be
3
+ * translated to. Stored `Present` in English; a translation writes the target
4
+ * language's word instead, from this table rather than the model, so it costs
5
+ * nothing and reads the same in every resume.
6
+ */
7
+ export const PRESENT_WORDS = {
8
+ en: 'Present',
9
+ es: 'Actualidad',
10
+ fr: "Aujourd'hui",
11
+ de: 'Heute',
12
+ pt: 'Atual',
13
+ it: 'Presente',
14
+ nl: 'Heden',
15
+ pl: 'Obecnie',
16
+ ro: 'Prezent',
17
+ ru: 'Настоящее время',
18
+ uk: 'Дотепер',
19
+ tr: 'Günümüz',
20
+ sv: 'Nu',
21
+ zh: '至今',
22
+ ja: '現在',
23
+ ko: '현재',
24
+ hi: 'वर्तमान',
25
+ id: 'Sekarang',
26
+ };
27
+ const PRESENT = new Set(Object.values(PRESENT_WORDS).map((word) => word.toLocaleLowerCase()));
28
+ /** Whether an end date says the role has not ended, in any language. */
29
+ export function isPresentDate(value) {
30
+ return PRESENT.has((value ?? '').trim().toLocaleLowerCase());
31
+ }
32
+ /**
33
+ * A date reduced to a number that sorts, or `null` when it cannot be read.
34
+ *
35
+ * `null` is the important return. A candidate mid-keystroke has `20`, and a
36
+ * résumé written like the reference one has `Feb 2024` — neither is wrong, and
37
+ * reporting either as an error would be the editor refusing a document that is
38
+ * perfectly good. Only what can be READ is judged; everything else is left
39
+ * alone. That is why this returns `null` rather than `0` or `NaN`.
40
+ *
41
+ * `Present` is the LARGEST value rather than today's date, deliberately: it
42
+ * means "has not ended", which outranks any month a candidate could type, and
43
+ * using a clock here would make the same résumé report differently tomorrow.
44
+ */
45
+ export function dateOrder(value) {
46
+ const text = (value ?? '').trim();
47
+ if (!text)
48
+ return null;
49
+ if (isPresentDate(text))
50
+ return Number.POSITIVE_INFINITY;
51
+ /* `YYYY-MM`, and `YYYY` alone — a degree is routinely dated by year, and a
52
+ year is perfectly comparable against a month in another entry. */
53
+ const iso = /^(\d{4})(?:-(\d{1,2}))?$/.exec(text);
54
+ if (iso) {
55
+ const year = Number(iso[1]);
56
+ const month = iso[2] ? Number(iso[2]) : 1;
57
+ if (month < 1 || month > 12)
58
+ return null;
59
+ return year * 12 + (month - 1);
60
+ }
61
+ return null;
62
+ }
63
+ /**
64
+ * The issues in one section's entries.
65
+ *
66
+ * Ordering is judged on the START date, which is what "reverse chronological"
67
+ * orders by: two roles that both ended in 2024 are ordered by which began more
68
+ * recently, and a current role has no end to order by at all.
69
+ *
70
+ * An entry whose start cannot be read is SKIPPED rather than treated as zero —
71
+ * and skipped without breaking the chain, so a half-typed row in the middle does
72
+ * not make every row beneath it look out of order. The comparison is against the
73
+ * last entry that could be read.
74
+ */
75
+ function sectionIssues(entries, path) {
76
+ const issues = [];
77
+ let previousStart = null;
78
+ entries.forEach((entry, i) => {
79
+ const entryPath = `${path}.${i}`;
80
+ const start = dateOrder(entry.start);
81
+ const end = dateOrder(entry.end);
82
+ if (start !== null && end !== null && end < start) {
83
+ issues.push({
84
+ kind: 'ends-before-start',
85
+ entryPath,
86
+ fields: [`${entryPath}.start`, `${entryPath}.end`],
87
+ });
88
+ }
89
+ if (start === null)
90
+ return;
91
+ if (previousStart !== null && start > previousStart) {
92
+ issues.push({
93
+ kind: 'out-of-order',
94
+ entryPath,
95
+ fields: [`${entryPath}.start`],
96
+ });
97
+ }
98
+ previousStart = start;
99
+ });
100
+ return issues;
101
+ }
102
+ /**
103
+ * Every date in a résumé that disagrees with the chronological rules.
104
+ *
105
+ * Sections are checked INDEPENDENTLY: experience running most-recent-first says
106
+ * nothing about education, and a section nobody has dated yet must not suppress
107
+ * the check on one that is complete.
108
+ */
109
+ export function resumeDateIssues(resume) {
110
+ return [
111
+ ...sectionIssues(resume.experience ?? [], 'experience'),
112
+ ...sectionIssues(resume.education ?? [], 'education'),
113
+ ];
114
+ }
115
+ /**
116
+ * The same check, over the order the document is actually DRAWN in.
117
+ *
118
+ * This replaces a version that scanned `experience.<n>.start` keys and walked
119
+ * them by `n`, and that was wrong in the one case the feature exists for.
120
+ *
121
+ * A path follows the JOB, not the position: a résumé the candidate has
122
+ * reordered renders `experience.2` in first place, and its fields keep saying
123
+ * `experience.2.*` so a stored edit follows the role rather than the slot. So
124
+ * the path index says where an entry STARTED, and reverse-chronological order
125
+ * is a claim about where it is NOW. Walking by index compared entries in an
126
+ * order nobody was looking at — and reported nothing on the very document a
127
+ * candidate had just dragged into the wrong order, which is exactly when they
128
+ * need telling.
129
+ *
130
+ * The caller passes the prefixes in drawn order, taken from the same
131
+ * `collectionOrder` the document lays itself out with, so the check and the
132
+ * page cannot disagree about which entry is above which.
133
+ *
134
+ * @param sections one array of entry path prefixes per section, each in the
135
+ * order the section is drawn — e.g. `[['experience.2', 'experience.0']]`.
136
+ * @param valueAt reads a field's current value, live from the editor.
137
+ */
138
+ export function dateIssuesInDrawnOrder(sections, valueAt) {
139
+ const byField = new Map();
140
+ for (const prefixes of sections) {
141
+ let previousStart = null;
142
+ for (const prefix of prefixes) {
143
+ const start = dateOrder(valueAt(`${prefix}.start`));
144
+ const end = dateOrder(valueAt(`${prefix}.end`));
145
+ if (start !== null && end !== null && end < start) {
146
+ if (!byField.has(`${prefix}.start`))
147
+ byField.set(`${prefix}.start`, 'ends-before-start');
148
+ if (!byField.has(`${prefix}.end`))
149
+ byField.set(`${prefix}.end`, 'ends-before-start');
150
+ }
151
+ if (start === null)
152
+ continue;
153
+ if (previousStart !== null && start > previousStart) {
154
+ if (!byField.has(`${prefix}.start`))
155
+ byField.set(`${prefix}.start`, 'out-of-order');
156
+ }
157
+ previousStart = start;
158
+ }
159
+ }
160
+ return byField;
161
+ }
162
+ /** What the editor says about each kind, in the candidate's terms. */
163
+ export const DATE_ISSUE_MESSAGE = {
164
+ 'ends-before-start': 'This ends before it starts — check the dates.',
165
+ 'out-of-order': 'Recruiters expect the most recent first — this one starts later than the entry above it.',
166
+ };
167
+ /**
168
+ * The issues keyed by the FIELD path each one marks.
169
+ *
170
+ * Keyed by path because that is the address a field already knows itself by, so
171
+ * a field can ask "is there anything about me?" without knowing the résumé's
172
+ * shape — and every template gets this without being edited.
173
+ */
174
+ export function dateIssuesByField(resume) {
175
+ const byField = new Map();
176
+ for (const issue of resumeDateIssues(resume)) {
177
+ for (const field of issue.fields) {
178
+ /* First wins. A range that is inverted AND out of order is more usefully
179
+ described by the thing wrong inside it than by its position. */
180
+ if (!byField.has(field))
181
+ byField.set(field, issue.kind);
182
+ }
183
+ }
184
+ return byField;
185
+ }