From 32640ab96d3e79cde8a0055dea3cf6bb2e318abd Mon Sep 17 00:00:00 2001 From: Fernando Colom Date: Wed, 19 Feb 2025 09:30:54 -0300 Subject: [PATCH] add file index --- CHANGELOG.md | 6 ++++++ lib/helpers/formatDate.js | 4 +--- lib/helpers/formatRangeDates.js | 4 +--- lib/helpers/formatSingleDate.js | 4 +--- lib/helpers/getValidRange.js | 4 +--- lib/helpers/index.js | 13 +++++++++++++ lib/helpers/isRangeDate.js | 4 +--- lib/helpers/isSameDay.js | 4 +--- lib/helpers/isSameYear.js | 3 +-- lib/helpers/isToday.js | 3 +-- lib/helpers/isTomorrow.js | 3 +-- lib/helpers/isValidDate.js | 3 +-- lib/helpers/logError.js | 5 ++--- lib/helpers/sameDayRangeDate.js | 5 ++--- lib/helpers/translate.js | 5 ++--- lib/index.js | 17 ++++++++++------- 16 files changed, 45 insertions(+), 42 deletions(-) create mode 100644 lib/helpers/index.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 899867c..3b0c204 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. [Unreleased] +## [1.3.0] - 2025-02-19 + +### Changed + +- Export and import for helpers + ## [1.2.0] - 2025-01-24 ### Removed diff --git a/lib/helpers/formatDate.js b/lib/helpers/formatDate.js index 94540a9..ab58930 100644 --- a/lib/helpers/formatDate.js +++ b/lib/helpers/formatDate.js @@ -14,9 +14,7 @@ import translate from './translate.js'; * behavior of the `formatDate` function based on their specific requirements. It can include options * such as locale settings, time zone information, */ -const formatDate = (date, format = 'dd MMM, HH:mm', options) => { +export default (date, format = 'dd MMM, HH:mm', options) => { const formattedDate = formatDateLib(date, format, options); return translate(formattedDate, options?.locale); }; - -export default formatDate; diff --git a/lib/helpers/formatRangeDates.js b/lib/helpers/formatRangeDates.js index 5e51127..43c24de 100644 --- a/lib/helpers/formatRangeDates.js +++ b/lib/helpers/formatRangeDates.js @@ -21,7 +21,7 @@ import isSameYear from './isSameYear.js'; * (' - ') to represent a date range. The formatting is determined by the `format` parameter if * provided */ -const formatRangeDates = (dates = [], options) => { +export default (dates = [], options) => { const [firstDate, secondDate] = dates; if (isSameDay(firstDate, secondDate)) return sameDayRangeDate(firstDate, secondDate, options); @@ -36,5 +36,3 @@ const formatRangeDates = (dates = [], options) => { .concat(' hours'); return translate(dateFormatted, options.locale); }; - -export default formatRangeDates; diff --git a/lib/helpers/formatSingleDate.js b/lib/helpers/formatSingleDate.js index 392b161..f95c6b9 100644 --- a/lib/helpers/formatSingleDate.js +++ b/lib/helpers/formatSingleDate.js @@ -15,7 +15,7 @@ import isTomorrow from './isTomorrow.js'; * @returns The `formatSingleDate` function is returning the result of calling the `formatDate` * function with the `date`, `formatToUse`, and `options` as arguments. */ -const formatSingleDate = (date, options) => { +export default (date, options) => { if (isToday(date)) return formatDate( date, @@ -32,5 +32,3 @@ const formatSingleDate = (date, options) => { return formatDate(date, `'Until' ${options?.locale?.customFormat?.singleDate} 'hours'`, options); }; - -export default formatSingleDate; diff --git a/lib/helpers/getValidRange.js b/lib/helpers/getValidRange.js index 381157f..b1f800b 100644 --- a/lib/helpers/getValidRange.js +++ b/lib/helpers/getValidRange.js @@ -5,6 +5,4 @@ import isValidDate from './isValidDate.js'; * @param {Dates[]} dates - An array of date values. * @return {Dates[] | []} */ -const getValidRange = (dates) => dates.filter(Boolean).filter(isValidDate); - -export default getValidRange; +export default (dates) => dates.filter(Boolean).filter(isValidDate); diff --git a/lib/helpers/index.js b/lib/helpers/index.js new file mode 100644 index 0000000..e3a2023 --- /dev/null +++ b/lib/helpers/index.js @@ -0,0 +1,13 @@ +export { default as formatDate } from './formatDate.js'; +export { default as formatRangeDates } from './formatRangeDates.js'; +export { default as formatSingleDate } from './formatSingleDate.js'; +export { default as getValidRange } from './getValidRange.js'; +export { default as isRangeDate } from './isRangeDate.js'; +export { default as isSameDay } from './isSameDay.js'; +export { default as isSameYear } from './isSameYear.js'; +export { default as isToday } from './isToday.js'; +export { default as isTomorrow } from './isTomorrow.js'; +export { default as isValidDate } from './isValidDate.js'; +export { default as logError } from './logError.js'; +export { default as sameDayRangeDate } from './sameDayRangeDate.js'; +export { default as translate } from './translate.js'; diff --git a/lib/helpers/isRangeDate.js b/lib/helpers/isRangeDate.js index 32d9d0f..34b5761 100644 --- a/lib/helpers/isRangeDate.js +++ b/lib/helpers/isRangeDate.js @@ -5,10 +5,8 @@ import isValidDate from './isValidDate.js'; * @returns {boolean} The function `isRangeDate` returns a boolean value indicating whether the input `dates` is * an array with a length greater than 1. */ -const isRangeDate = (dates) => { +export default (dates) => { if (!Array.isArray(dates)) return false; return dates.filter(Boolean).filter(isValidDate).length > 1; }; - -export default isRangeDate; diff --git a/lib/helpers/isSameDay.js b/lib/helpers/isSameDay.js index 2dee2d8..733edfa 100644 --- a/lib/helpers/isSameDay.js +++ b/lib/helpers/isSameDay.js @@ -7,6 +7,4 @@ import { isSameDay as sameDay } from 'date-fns'; * when comparing two dates. * @return {boolean} */ -const isSameDay = (earlierDate, laterDate) => sameDay(laterDate, earlierDate, { in: true }); - -export default isSameDay; +export default (earlierDate, laterDate) => sameDay(laterDate, earlierDate, { in: true }); diff --git a/lib/helpers/isSameYear.js b/lib/helpers/isSameYear.js index cce3cdb..71e2124 100644 --- a/lib/helpers/isSameYear.js +++ b/lib/helpers/isSameYear.js @@ -7,6 +7,5 @@ import { isSameYear as sameYear } from 'date-fns'; * when comparing two dates. * @return {boolean} */ -const isSameYear = (earlierDate, laterDate) => sameYear(laterDate, earlierDate, { in: true }); -export default isSameYear; +export default (earlierDate, laterDate) => sameYear(laterDate, earlierDate, { in: true }); diff --git a/lib/helpers/isToday.js b/lib/helpers/isToday.js index 892afb4..d8e3319 100644 --- a/lib/helpers/isToday.js +++ b/lib/helpers/isToday.js @@ -5,6 +5,5 @@ import { isToday as isTodayDate } from 'date-fns'; * @param {Date} date - The `date` parameter is a variable that represents a specific date. * @return {boolean} */ -const isToday = (date) => isTodayDate(date); -export default isToday; +export default (date) => isTodayDate(date); diff --git a/lib/helpers/isTomorrow.js b/lib/helpers/isTomorrow.js index a9df200..3559d4e 100644 --- a/lib/helpers/isTomorrow.js +++ b/lib/helpers/isTomorrow.js @@ -6,6 +6,5 @@ import { isTomorrow as isTomorrowDate } from 'date-fns'; * Date object format. * @return {boolean} */ -const isTomorrow = (date) => isTomorrowDate(date); -export default isTomorrow; +export default (date) => isTomorrowDate(date); diff --git a/lib/helpers/isValidDate.js b/lib/helpers/isValidDate.js index 33286db..5870a09 100644 --- a/lib/helpers/isValidDate.js +++ b/lib/helpers/isValidDate.js @@ -6,6 +6,5 @@ import { isValid } from 'date-fns'; * representing a date in a format that can be parsed by the `Date` constructor. * @return {boolean} */ -const isValidDate = (date) => isValid(new Date(date)); -export default isValidDate; +export default (date) => isValid(new Date(date)); diff --git a/lib/helpers/logError.js b/lib/helpers/logError.js index 3cf4a26..9c1b32e 100644 --- a/lib/helpers/logError.js +++ b/lib/helpers/logError.js @@ -10,8 +10,7 @@ const { * containing all the arguments passed to the `logError` function when it is called. * @returns console.log(...args) */ -const logError = (...args) => { + +export default (...args) => { if (NODE_ENV === 'development') return console.log(...args); }; - -export default logError; diff --git a/lib/helpers/sameDayRangeDate.js b/lib/helpers/sameDayRangeDate.js index 69d77f7..024ddb1 100644 --- a/lib/helpers/sameDayRangeDate.js +++ b/lib/helpers/sameDayRangeDate.js @@ -15,7 +15,8 @@ import translate from './translate.js'; * 'today', 'tomorrow', or a formatted date), the start time, and the end time. If the start and end * times are the same, it only includes the day and the start time. */ -const sameDayRangeDate = (startDate, endDate, options) => { + +export default (startDate, endDate, options) => { let day = ''; const { locale } = options; @@ -32,5 +33,3 @@ const sameDayRangeDate = (startDate, endDate, options) => { return translate(`${day}, ${startHours} - ${endHours} hours`, locale); }; - -export default sameDayRangeDate; diff --git a/lib/helpers/translate.js b/lib/helpers/translate.js index 6871cca..087d8c6 100644 --- a/lib/helpers/translate.js +++ b/lib/helpers/translate.js @@ -6,7 +6,8 @@ * word in the original language and the value is the translation of that word in the desired language. * @returns The `translate` function is being returned. */ -const translate = (string, locale) => { + +export default (string, locale) => { return string .replace(/\b[a-zA-Z]+\b/g, (word) => { const translation = locale?.words?.[word]; @@ -14,5 +15,3 @@ const translate = (string, locale) => { }) .trim(); }; - -export default translate; diff --git a/lib/index.js b/lib/index.js index c69b7cf..e4c65ef 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,12 +1,15 @@ import { setDefaultOptions } from 'date-fns'; import locales from './locales.js'; -import isRangeDate from './helpers/isRangeDate.js'; -import getValidRange from './helpers/getValidRange.js'; -import formatSingleDate from './helpers/formatSingleDate.js'; -import formatRangeDates from './helpers/formatRangeDates.js'; -import isValidDate from './helpers/isValidDate.js'; -import formatDate from './helpers/formatDate.js'; -import logError from './helpers/logError.js'; + +import { + isRangeDate, + getValidRange, + formatSingleDate, + formatRangeDates, + isValidDate, + formatDate, + logError +} from './helpers/index.js'; /** *