@jsonresume/core 0.1.0 → 0.2.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,16 @@
1
+ /**
2
+ * Resume Count Calculation Helpers
3
+ *
4
+ * Re-exported from @jsonresume/utils (framework-free).
5
+ *
6
+ * @module @jsonresume/core/helpers/counts
7
+ */
8
+ export {
9
+ countCompanies,
10
+ countProjects,
11
+ countPublications,
12
+ countAwards,
13
+ countTotalSkills,
14
+ countSkillCategories,
15
+ countLanguages,
16
+ } from '@jsonresume/utils/metrics';
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Resume Education Calculation Helpers
3
+ *
4
+ * Re-exported from @jsonresume/utils (framework-free). Note: calculateEducationYears
5
+ * now uses the corrected ms-per-year formula (Wave 1 bugfix).
6
+ *
7
+ * @module @jsonresume/core/helpers/education
8
+ */
9
+ export {
10
+ calculateEducationYears,
11
+ getHighestDegree,
12
+ } from '@jsonresume/utils/metrics';
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Resume Experience Calculation Helpers
3
+ *
4
+ * Re-exported from @jsonresume/utils (framework-free). The implementations
5
+ * moved there in Wave 1; this shim keeps @jsonresume/core's public surface
6
+ * byte-for-byte stable.
7
+ *
8
+ * @module @jsonresume/core/helpers/experience
9
+ */
10
+ export {
11
+ calculateTotalExperience,
12
+ calculateCurrentRoleExperience,
13
+ countCareerPositions,
14
+ getCareerProgressionRate,
15
+ countTotalHighlights,
16
+ } from '@jsonresume/utils/metrics';
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @jsonresume/core/helpers
3
+ *
4
+ * Discoverability re-export of the framework-free @jsonresume/utils surface
5
+ * (date, metrics, and URL helpers). Prefer importing from @jsonresume/utils
6
+ * directly in new code; this subpath exists so the helpers are easy to find
7
+ * from @jsonresume/core.
8
+ *
9
+ * @module @jsonresume/core/helpers
10
+ */
11
+ export * from '@jsonresume/utils';
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Resume Key Metrics Aggregation Helper
3
+ *
4
+ * Re-exported from @jsonresume/utils (framework-free).
5
+ *
6
+ * @module @jsonresume/core/helpers/keyMetrics
7
+ */
8
+ export { calculateKeyMetrics } from '@jsonresume/utils/metrics';
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Resume Work History Insight Helpers
3
+ *
4
+ * Re-exported from @jsonresume/utils (framework-free).
5
+ *
6
+ * @module @jsonresume/core/helpers/workHistory
7
+ */
8
+ export {
9
+ calculateVolunteerYears,
10
+ getUniqueIndustries,
11
+ getCurrentEmployer,
12
+ isCurrentlyEmployed,
13
+ } from '@jsonresume/utils/metrics';
package/src/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  /**
2
- * @resume/core
2
+ * @jsonresume/core
3
3
  * React component library for building ATS-friendly resume themes
4
4
  * Design tokens, primitives, and utilities with JSX
5
+ *
6
+ * The pure (framework-free) calculation, date, and URL helpers re-exported
7
+ * below now live in @jsonresume/utils; they are re-exported here so existing
8
+ * `import { ... } from '@jsonresume/core'` consumers keep working unchanged.
5
9
  */
6
10
 
7
11
  // Export theme provider
@@ -249,5 +253,6 @@ export { ToolTagRibbon } from './tags/index.jsx';
249
253
  // Export badge components
250
254
  export { BadgeRowOutline } from './badges/index.jsx';
251
255
 
252
- // Package metadata
253
- export const version = '0.2.0';
256
+ // Package metadata. Kept in sync with package.json's "version" (the canonical,
257
+ // changeset-managed source of truth).
258
+ export const version = '0.1.0';
@@ -1,115 +1,13 @@
1
1
  import React from 'react';
2
2
  import styled from 'styled-components';
3
+ import { formatDateRange } from '@jsonresume/utils/dates';
3
4
 
4
5
  /**
5
- * Date formatting utility with Intl.DateTimeFormat
6
- * Formats date ranges for work/education experience with full locale support
7
- *
8
- * @param {Object} options - DateRange options
9
- * @param {string|Date} options.startDate - Start date (ISO string or Date object)
10
- * @param {string|Date} [options.endDate] - End date (ISO string, Date object, or null for "Present")
11
- * @param {string} [options.format='short'] - Format style: 'short' (default), 'long', 'numeric'
12
- * @param {string} [options.locale='en-US'] - BCP 47 locale (e.g., 'en-US', 'fr-FR', 'ar-SA')
13
- * @param {string} [options.numberingSystem] - Numbering system (e.g., 'arab', 'latn', 'hanidec')
14
- * @param {string} [options.presentLabel] - Custom label for present/ongoing (defaults to localized)
15
- * @returns {string} Formatted date range
16
- *
17
- * @example
18
- * formatDateRange({ startDate: '2020-01-15', endDate: null })
19
- * // 'Jan 2020 - Present'
20
- *
21
- * @example
22
- * formatDateRange({
23
- * startDate: '2020-01-15',
24
- * locale: 'fr-FR',
25
- * format: 'long'
26
- * })
27
- * // 'janvier 2020 - Présent'
28
- *
29
- * @example
30
- * formatDateRange({
31
- * startDate: '2020-01-15',
32
- * locale: 'ar-SA',
33
- * numberingSystem: 'arab'
34
- * })
35
- * // With Arabic numerals
6
+ * The pure date-formatting function now lives in @jsonresume/utils (no React /
7
+ * styled-components). It is re-exported here so existing imports
8
+ * (`import { formatDateRange } from '@jsonresume/core'`) keep working.
36
9
  */
37
- export function formatDateRange({
38
- startDate,
39
- endDate,
40
- format = 'short',
41
- locale = 'en-US',
42
- numberingSystem,
43
- presentLabel,
44
- }) {
45
- if (!startDate) return '';
46
-
47
- // Determine "Present" label based on locale
48
- const getPresentLabel = () => {
49
- if (presentLabel) return presentLabel;
50
-
51
- const labels = {
52
- en: 'Present',
53
- 'en-US': 'Present',
54
- 'en-GB': 'Present',
55
- fr: 'Présent',
56
- 'fr-FR': 'Présent',
57
- es: 'Presente',
58
- 'es-ES': 'Presente',
59
- de: 'Heute',
60
- 'de-DE': 'Heute',
61
- it: 'Presente',
62
- 'it-IT': 'Presente',
63
- pt: 'Presente',
64
- 'pt-BR': 'Presente',
65
- ja: '現在',
66
- 'ja-JP': '現在',
67
- zh: '至今',
68
- 'zh-CN': '至今',
69
- 'zh-TW': '至今',
70
- ko: '현재',
71
- 'ko-KR': '현재',
72
- ar: 'حاضر',
73
- 'ar-SA': 'حاضر',
74
- };
75
-
76
- return labels[locale] || labels[locale.split('-')[0]] || 'Present';
77
- };
78
-
79
- const formatDate = (dateStr) => {
80
- if (!dateStr) return getPresentLabel();
81
-
82
- const date = typeof dateStr === 'string' ? new Date(dateStr) : dateStr;
83
-
84
- if (isNaN(date.getTime())) return dateStr; // Invalid date, return as-is
85
-
86
- // Configure Intl.DateTimeFormat based on format style
87
- const monthFormats = {
88
- short: { month: 'short' },
89
- long: { month: 'long' },
90
- numeric: { month: '2-digit' },
91
- };
92
-
93
- const options = {
94
- ...monthFormats[format],
95
- year: 'numeric',
96
- };
97
-
98
- // Add numbering system if provided
99
- if (numberingSystem) {
100
- options.numberingSystem = numberingSystem;
101
- }
102
-
103
- // Use Intl.DateTimeFormat for proper locale support
104
- const formatter = new Intl.DateTimeFormat(locale, options);
105
- return formatter.format(date);
106
- };
107
-
108
- const start = formatDate(startDate);
109
- const end = formatDate(endDate);
110
-
111
- return `${start} - ${end}`;
112
- }
10
+ export { formatDateRange };
113
11
 
114
12
  /**
115
13
  * DateRange Component
@@ -0,0 +1,46 @@
1
+ import 'styled-components';
2
+
3
+ declare module 'styled-components' {
4
+ export interface DefaultTheme {
5
+ colors?: {
6
+ primary?: string;
7
+ secondary?: string;
8
+ tertiary?: string;
9
+ text?: string;
10
+ link?: string;
11
+ linkVisited?: string;
12
+ accent?: string;
13
+ accentLight?: string;
14
+ accentMuted?: string;
15
+ accentBorder?: string;
16
+ muted?: string;
17
+ border?: string;
18
+ borderLight?: string;
19
+ };
20
+ spacing?: {
21
+ section?: string;
22
+ item?: string;
23
+ small?: string;
24
+ tight?: string;
25
+ };
26
+ typography?: {
27
+ heading?: string;
28
+ body?: string;
29
+ small?: string;
30
+ lineHeight?: string;
31
+ weightMedium?: string;
32
+ sizes?: {
33
+ small?: string;
34
+ };
35
+ weights?: {
36
+ medium?: string;
37
+ semibold?: string;
38
+ };
39
+ };
40
+ radius?: {
41
+ sm?: string;
42
+ md?: string;
43
+ full?: string;
44
+ };
45
+ }
46
+ }
@@ -1,155 +1,14 @@
1
1
  /**
2
- * Security utilities for @resume/core
3
- * Prevents XSS attacks and ensures safe URL handling
4
- */
5
-
6
- /**
7
- * Sanitizes URLs to prevent XSS attacks
8
- * - Blocks javascript:, data:, vbscript: schemes
9
- * - Allows http:, https:, mailto:, tel: schemes
10
- * - Returns null for invalid/dangerous URLs
11
- *
12
- * @param {string} url - The URL to sanitize
13
- * @returns {string|null} - Safe URL or null if dangerous
14
- *
15
- * @example
16
- * safeUrl('https://example.com') // 'https://example.com'
17
- * safeUrl('javascript:alert(1)') // null
18
- * safeUrl('mailto:user@example.com') // 'mailto:user@example.com'
19
- */
20
- export function safeUrl(url) {
21
- if (!url || typeof url !== 'string') {
22
- return null;
23
- }
24
-
25
- // Trim whitespace
26
- const trimmed = url.trim();
27
-
28
- // Check for dangerous protocols
29
- const dangerousProtocols = /^(javascript|data|vbscript|file|about):/i;
30
- if (dangerousProtocols.test(trimmed)) {
31
- console.warn(`[Security] Blocked dangerous URL: ${trimmed.slice(0, 50)}`);
32
- return null;
33
- }
34
-
35
- // Allow safe protocols
36
- const safeProtocols = /^(https?|mailto|tel|sms|ftp):/i;
37
- if (safeProtocols.test(trimmed)) {
38
- return trimmed;
39
- }
40
-
41
- // Allow relative URLs (starting with / or .)
42
- if (trimmed.startsWith('/') || trimmed.startsWith('.')) {
43
- return trimmed;
44
- }
45
-
46
- // Allow URLs without protocol (assume https)
47
- if (/^www\./i.test(trimmed)) {
48
- return `https://${trimmed}`;
49
- }
50
-
51
- // For other cases, check if it looks like a valid domain
52
- // Allow alphanumeric, hyphens, dots, and common TLDs
53
- if (/^[a-z0-9][a-z0-9.-]+\.[a-z]{2,}$/i.test(trimmed)) {
54
- return `https://${trimmed}`;
55
- }
56
-
57
- // If we can't determine safety, return the original
58
- // (Let the browser handle it, but log a warning)
59
- console.warn(`[Security] Uncertain URL safety: ${trimmed.slice(0, 50)}`);
60
- return trimmed;
61
- }
62
-
63
- /**
64
- * Returns proper rel attribute for external links
65
- * Adds security attributes for links opening in new windows
66
- *
67
- * @param {string} url - The URL to check
68
- * @param {boolean} openInNewTab - Whether link opens in new tab
69
- * @returns {string} - rel attribute value
70
- *
71
- * @example
72
- * getLinkRel('https://example.com', true) // 'noopener noreferrer'
73
- * getLinkRel('mailto:user@example.com', false) // ''
74
- */
75
- export function getLinkRel(url, openInNewTab = false) {
76
- if (!url || typeof url !== 'string') {
77
- return '';
78
- }
79
-
80
- // Only add security attributes for http(s) links opening in new tabs
81
- if (openInNewTab && /^https?:/i.test(url)) {
82
- return 'noopener noreferrer';
83
- }
84
-
85
- return '';
86
- }
87
-
88
- /**
89
- * Sanitizes HTML to prevent XSS
90
- * Simple implementation that escapes dangerous characters
91
- * For more complex needs, use DOMPurify
92
- *
93
- * @param {string} html - HTML string to sanitize
94
- * @returns {string} - Sanitized HTML
95
- *
96
- * @example
97
- * sanitizeHtml('<script>alert(1)</script>') // '&lt;script&gt;alert(1)&lt;/script&gt;'
98
- */
99
- export function sanitizeHtml(html) {
100
- if (!html || typeof html !== 'string') {
101
- return '';
102
- }
103
-
104
- return html
105
- .replace(/&/g, '&amp;')
106
- .replace(/</g, '&lt;')
107
- .replace(/>/g, '&gt;')
108
- .replace(/"/g, '&quot;')
109
- .replace(/'/g, '&#039;');
110
- }
111
-
112
- /**
113
- * Checks if a URL is external (different origin)
114
- *
115
- * @param {string} url - URL to check
116
- * @param {string} currentOrigin - Current site origin (default: window.location.origin if available)
117
- * @returns {boolean} - True if URL is external
118
- *
119
- * @example
120
- * isExternalUrl('https://example.com') // true (if on different domain)
121
- * isExternalUrl('/about') // false
122
- */
123
- export function isExternalUrl(url, currentOrigin = null) {
124
- if (!url || typeof url !== 'string') {
125
- return false;
126
- }
127
-
128
- // Relative URLs are not external
129
- if (url.startsWith('/') || url.startsWith('.') || url.startsWith('#')) {
130
- return false;
131
- }
132
-
133
- // mailto:, tel:, etc. are not external in the HTTP sense
134
- if (/^(mailto|tel|sms):/i.test(url)) {
135
- return false;
136
- }
137
-
138
- // If no origin provided and we're in a browser, use window.location
139
- if (!currentOrigin && typeof window !== 'undefined') {
140
- currentOrigin = window.location.origin;
141
- }
142
-
143
- // If still no origin, we can't determine (assume external for safety)
144
- if (!currentOrigin) {
145
- return true;
146
- }
147
-
148
- try {
149
- const urlObj = new URL(url, currentOrigin);
150
- return urlObj.origin !== currentOrigin;
151
- } catch (e) {
152
- // Invalid URL, treat as external for safety
153
- return true;
154
- }
155
- }
2
+ * Security utilities for @jsonresume/core
3
+ *
4
+ * The implementations now live in @jsonresume/utils (framework-free). This
5
+ * module re-exports them so existing imports
6
+ * (`import { safeUrl } from '@jsonresume/core'` and the internal
7
+ * `../utils/security.js` imports in Link/ContactInfo) keep working unchanged.
8
+ */
9
+ export {
10
+ safeUrl,
11
+ getLinkRel,
12
+ sanitizeHtml,
13
+ isExternalUrl,
14
+ } from '@jsonresume/utils/url';