Skip to content

Commit

Permalink
add file index
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando Colom committed Feb 19, 2025
1 parent 747eee7 commit 32640ab
Show file tree
Hide file tree
Showing 16 changed files with 45 additions and 42 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions lib/helpers/formatDate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
4 changes: 1 addition & 3 deletions lib/helpers/formatRangeDates.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -36,5 +36,3 @@ const formatRangeDates = (dates = [], options) => {
.concat(' hours');
return translate(dateFormatted, options.locale);
};

export default formatRangeDates;
4 changes: 1 addition & 3 deletions lib/helpers/formatSingleDate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -32,5 +32,3 @@ const formatSingleDate = (date, options) => {

return formatDate(date, `'Until' ${options?.locale?.customFormat?.singleDate} 'hours'`, options);
};

export default formatSingleDate;
4 changes: 1 addition & 3 deletions lib/helpers/getValidRange.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
13 changes: 13 additions & 0 deletions lib/helpers/index.js
Original file line number Diff line number Diff line change
@@ -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';
4 changes: 1 addition & 3 deletions lib/helpers/isRangeDate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
4 changes: 1 addition & 3 deletions lib/helpers/isSameDay.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
3 changes: 1 addition & 2 deletions lib/helpers/isSameYear.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
3 changes: 1 addition & 2 deletions lib/helpers/isToday.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
3 changes: 1 addition & 2 deletions lib/helpers/isTomorrow.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
3 changes: 1 addition & 2 deletions lib/helpers/isValidDate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
5 changes: 2 additions & 3 deletions lib/helpers/logError.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
5 changes: 2 additions & 3 deletions lib/helpers/sameDayRangeDate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -32,5 +33,3 @@ const sameDayRangeDate = (startDate, endDate, options) => {

return translate(`${day}, ${startHours} - ${endHours} hours`, locale);
};

export default sameDayRangeDate;
5 changes: 2 additions & 3 deletions lib/helpers/translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
* 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];
return translation !== undefined ? translation : word;
})
.trim();
};

export default translate;
17 changes: 10 additions & 7 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -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';

/**
*
Expand Down

0 comments on commit 32640ab

Please sign in to comment.