@alveole/core 1.9.0 → 2.0.0-alpha
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/dist/date/dateFormat.d.ts.map +1 -1
- package/dist/date/dateFormat.js +5 -1
- package/dist/date/displayDate.d.ts +11 -9
- package/dist/date/displayDate.d.ts.map +1 -1
- package/dist/date/displayDate.js +27 -20
- package/dist/date/formatMinutes.d.ts.map +1 -1
- package/dist/date/formatMinutes.js +9 -6
- package/dist/date/getDurationBetweenTimes.d.ts.map +1 -1
- package/dist/date/getDurationBetweenTimes.js +2 -1
- package/dist/date/isAfterDate.d.ts.map +1 -1
- package/dist/date/isAfterDate.js +2 -1
- package/dist/date/isBeforeDate.d.ts.map +1 -1
- package/dist/date/isBeforeDate.js +2 -1
- package/dist/date/isValidDate.d.ts.map +1 -1
- package/dist/date/isValidDate.js +2 -1
- package/package.json +9 -12
- package/dist/date/formatDateRangeLabel.d.ts +0 -8
- package/dist/date/formatDateRangeLabel.d.ts.map +0 -1
- package/dist/date/formatDateRangeLabel.js +0 -21
- package/dist/date/formatSec.d.ts +0 -2
- package/dist/date/formatSec.d.ts.map +0 -1
- package/dist/date/formatSec.js +0 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dateFormat.d.ts","sourceRoot":"","sources":["../../src/date/dateFormat.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;CAkBd,CAAC;AAEX,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,OAAO,WAAW,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"dateFormat.d.ts","sourceRoot":"","sources":["../../src/date/dateFormat.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;CAkBd,CAAC;AAEX,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,OAAO,WAAW,CAAC,CAAC;AAOxE,eAAO,MAAM,YAAY,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,UAAsD,CAAC"}
|
package/dist/date/dateFormat.js
CHANGED
|
@@ -17,4 +17,8 @@ export const DateFormats = {
|
|
|
17
17
|
DateTimeFR: 'd MMMM yyyy à HH:mm',
|
|
18
18
|
DateTimeEN: 'd MMMM yyyy at HH:mm',
|
|
19
19
|
};
|
|
20
|
-
|
|
20
|
+
// `includes` refuse un `unknown` parce qu'il attend un element du tableau : c'est le tableau
|
|
21
|
+
// qu'on elargit, pas la valeur qu'on ment. `as any` eteignait la verification des deux cotes,
|
|
22
|
+
// et aurait laisse passer un appel sur un tout autre catalogue.
|
|
23
|
+
const FORMATS = Object.values(DateFormats);
|
|
24
|
+
export const isDateFormat = (value) => value != null && FORMATS.includes(value);
|
|
@@ -1,23 +1,25 @@
|
|
|
1
|
-
import { Locale } from 'date-fns';
|
|
1
|
+
import type { Locale } from 'date-fns';
|
|
2
2
|
import { type DateFormat } from './dateFormat';
|
|
3
|
+
type DisplayDateOptions = {
|
|
4
|
+
fallback?: string;
|
|
5
|
+
format?: DateFormat;
|
|
6
|
+
capitalize?: boolean;
|
|
7
|
+
locale?: Locale;
|
|
8
|
+
};
|
|
3
9
|
/**
|
|
4
10
|
* Retourne la locale date-fns à partir du code langue (ex: 'en', 'fr').
|
|
5
11
|
* Défaut: enGB.
|
|
6
12
|
*/
|
|
7
13
|
export declare function getDateFnsLocale(localeCode?: string): Locale;
|
|
8
14
|
/**
|
|
9
|
-
* Affiche une date au format
|
|
15
|
+
* Affiche une date au format demandé (ex: 22 juillet 2025).
|
|
10
16
|
*/
|
|
11
|
-
export declare function displayDate(date: string | Date | undefined, options?:
|
|
12
|
-
fallback?: string;
|
|
13
|
-
format?: DateFormat;
|
|
14
|
-
capitalize?: boolean;
|
|
15
|
-
locale?: Locale;
|
|
16
|
-
}): string;
|
|
17
|
+
export declare function displayDate(date: string | Date | undefined, options?: DisplayDateOptions): string;
|
|
17
18
|
/**
|
|
18
|
-
* Affiche une date
|
|
19
|
+
* Affiche une date avec son heure (ex: 22 juillet 2025 à 15:30).
|
|
19
20
|
*/
|
|
20
21
|
export declare function displayDatetime(date: string | Date, options?: {
|
|
21
22
|
fallback?: string;
|
|
22
23
|
}): string;
|
|
24
|
+
export {};
|
|
23
25
|
//# sourceMappingURL=displayDate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"displayDate.d.ts","sourceRoot":"","sources":["../../src/date/displayDate.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"displayDate.d.ts","sourceRoot":"","sources":["../../src/date/displayDate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAMvC,OAAO,EAAe,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAE5D,KAAK,kBAAkB,GAAG;IACxB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CAG5D;AAeD;;GAEG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAAE,OAAO,GAAE,kBAAuB,GAAG,MAAM,CASrG;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAE5F"}
|
package/dist/date/displayDate.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { format
|
|
2
|
-
import {
|
|
1
|
+
import { format } from 'date-fns/format';
|
|
2
|
+
import { isValid } from 'date-fns/isValid';
|
|
3
|
+
import { enGB } from 'date-fns/locale/en-GB';
|
|
4
|
+
import { fr } from 'date-fns/locale/fr';
|
|
5
|
+
import { parseISO } from 'date-fns/parseISO';
|
|
3
6
|
import { DateFormats } from './dateFormat';
|
|
4
7
|
/**
|
|
5
8
|
* Retourne la locale date-fns à partir du code langue (ex: 'en', 'fr').
|
|
@@ -11,27 +14,31 @@ export function getDateFnsLocale(localeCode) {
|
|
|
11
14
|
return enGB;
|
|
12
15
|
}
|
|
13
16
|
/**
|
|
14
|
-
*
|
|
17
|
+
* Normalise l'entrée en une date exploitable, ou `undefined` si elle est absente ou invalide.
|
|
15
18
|
*/
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
function toValidDate(date) {
|
|
20
|
+
const parsed = typeof date === 'string' ? parseISO(date) : date;
|
|
21
|
+
if (!parsed || !isValid(parsed))
|
|
22
|
+
return undefined;
|
|
23
|
+
return parsed;
|
|
24
|
+
}
|
|
25
|
+
function capitaliser(texte) {
|
|
26
|
+
return texte.charAt(0).toUpperCase() + texte.slice(1);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Affiche une date au format demandé (ex: 22 juillet 2025).
|
|
30
|
+
*/
|
|
31
|
+
export function displayDate(date, options = {}) {
|
|
32
|
+
const { fallback = '', format: dateFormat = DateFormats.Date, capitalize = false, locale = enGB } = options;
|
|
33
|
+
const parsed = toValidDate(date);
|
|
34
|
+
if (!parsed)
|
|
35
|
+
return fallback;
|
|
36
|
+
const formatted = format(parsed, dateFormat, { locale });
|
|
37
|
+
return capitalize ? capitaliser(formatted) : formatted;
|
|
27
38
|
}
|
|
28
39
|
/**
|
|
29
|
-
* Affiche une date
|
|
40
|
+
* Affiche une date avec son heure (ex: 22 juillet 2025 à 15:30).
|
|
30
41
|
*/
|
|
31
42
|
export function displayDatetime(date, options) {
|
|
32
|
-
|
|
33
|
-
const d = typeof date === 'string' ? parseISO(date) : date;
|
|
34
|
-
if (!isValid(d))
|
|
35
|
-
return options?.fallback ?? '';
|
|
36
|
-
return format(d, defaultFormat, { locale: enGB });
|
|
43
|
+
return displayDate(date, { fallback: options?.fallback, format: DateFormats.Datetime });
|
|
37
44
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatMinutes.d.ts","sourceRoot":"","sources":["../../src/date/formatMinutes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"formatMinutes.d.ts","sourceRoot":"","sources":["../../src/date/formatMinutes.ts"],"names":[],"mappings":"AAEA,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,UAW3D"}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
const pluralise = (nombre, unite) => `${nombre} ${unite}${nombre > 1 ? 's' : ''}`;
|
|
1
2
|
export function formatMinutes(min, fallback) {
|
|
2
3
|
const heures = Math.floor(min / 60);
|
|
3
4
|
const minutes = min % 60;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
const segments = [];
|
|
6
|
+
if (heures > 0)
|
|
7
|
+
segments.push(pluralise(heures, 'heure'));
|
|
8
|
+
if (minutes > 0)
|
|
9
|
+
segments.push(pluralise(minutes, 'minute'));
|
|
10
|
+
if (segments.length === 0)
|
|
11
|
+
return fallback ?? 'Vide';
|
|
12
|
+
return segments.join(' et ');
|
|
10
13
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDurationBetweenTimes.d.ts","sourceRoot":"","sources":["../../src/date/getDurationBetweenTimes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getDurationBetweenTimes.d.ts","sourceRoot":"","sources":["../../src/date/getDurationBetweenTimes.ts"],"names":[],"mappings":"AAKA;;;;;GAKG;AACH,eAAO,MAAM,uBAAuB,GAClC,QAAQ,MAAM,GAAG,IAAI,EACrB,MAAM,MAAM,GAAG,IAAI,EACnB,UAAU;IAAE,YAAY,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,OAAO,CAAA;CAAE,KACvD,MAAM,GAAG,SAcX,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { differenceInMinutes
|
|
1
|
+
import { differenceInMinutes } from 'date-fns/differenceInMinutes';
|
|
2
|
+
import { parse } from 'date-fns/parse';
|
|
2
3
|
const parseTime = (time) => parse(time, 'HH:mm', new Date(0));
|
|
3
4
|
/**
|
|
4
5
|
* Déduit la durée d'une période en heures au format time
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isAfterDate.d.ts","sourceRoot":"","sources":["../../src/date/isAfterDate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"isAfterDate.d.ts","sourceRoot":"","sources":["../../src/date/isAfterDate.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAE1E"}
|
package/dist/date/isAfterDate.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isBeforeDate.d.ts","sourceRoot":"","sources":["../../src/date/isBeforeDate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"isBeforeDate.d.ts","sourceRoot":"","sources":["../../src/date/isBeforeDate.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,GAAG,OAAO,CAE3E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isValidDate.d.ts","sourceRoot":"","sources":["../../src/date/isValidDate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"isValidDate.d.ts","sourceRoot":"","sources":["../../src/date/isValidDate.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,GAAG,IAAI,CAoClE"}
|
package/dist/date/isValidDate.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alveole/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-alpha",
|
|
4
4
|
"description": "Core for Alveole.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -13,25 +13,22 @@
|
|
|
13
13
|
},
|
|
14
14
|
"files": [
|
|
15
15
|
"dist",
|
|
16
|
+
"!dist/.tsbuildinfo",
|
|
16
17
|
"README.md"
|
|
17
18
|
],
|
|
18
19
|
"sideEffects": false,
|
|
19
|
-
"scripts": {
|
|
20
|
-
"build": "tsc -p tsconfig.build.json",
|
|
21
|
-
"lint": "eslint .",
|
|
22
|
-
"typecheck": "tsc -p tsconfig.typecheck.json --noEmit",
|
|
23
|
-
"test:unit": "NODE_OPTIONS=--max-old-space-size=4096 npx jest --maxWorkers=2 --ci"
|
|
24
|
-
},
|
|
25
20
|
"devDependencies": {
|
|
26
21
|
"@alveole/eslint-config": "file:../eslint-config",
|
|
27
22
|
"date-fns": "4.4.0",
|
|
28
|
-
"eslint": "
|
|
23
|
+
"eslint": "10.10.0"
|
|
29
24
|
},
|
|
30
25
|
"peerDependencies": {
|
|
31
26
|
"date-fns": "*"
|
|
32
27
|
},
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
28
|
+
"scripts": {
|
|
29
|
+
"build": "tsc -p tsconfig.build.json",
|
|
30
|
+
"lint": "eslint . --cache --cache-strategy content",
|
|
31
|
+
"typecheck": "tsc -p tsconfig.typecheck.json --noEmit",
|
|
32
|
+
"test:unit": "npx jest --coverage --runInBand --ci"
|
|
36
33
|
}
|
|
37
|
-
}
|
|
34
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formatDateRangeLabel.d.ts","sourceRoot":"","sources":["../../src/date/formatDateRangeLabel.ts"],"names":[],"mappings":"AAGA,wBAAgB,oBAAoB,CAAC,MAAM,EAAE;IAC3C,SAAS,EAAE,IAAI,CAAC;IAChB,OAAO,EAAE,IAAI,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB,GAAG,MAAM,CAgCT"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { format, isValid } from 'date-fns';
|
|
2
|
-
import { getDateFnsLocale } from './displayDate';
|
|
3
|
-
export function formatDateRangeLabel(params) {
|
|
4
|
-
const { startDate, endDate, localeCode, fromLabel, toLabel } = params;
|
|
5
|
-
if (!isValid(startDate) || !isValid(endDate))
|
|
6
|
-
return '';
|
|
7
|
-
const sameMonthYear = startDate.getMonth() === endDate.getMonth() && startDate.getFullYear() === endDate.getFullYear();
|
|
8
|
-
const sameYear = startDate.getFullYear() === endDate.getFullYear();
|
|
9
|
-
const dateFnsLocale = getDateFnsLocale(localeCode);
|
|
10
|
-
if (sameMonthYear) {
|
|
11
|
-
return `${fromLabel} ${format(startDate, 'dd', { locale: dateFnsLocale })} ${toLabel} ${format(endDate, 'dd', {
|
|
12
|
-
locale: dateFnsLocale,
|
|
13
|
-
})} ${format(startDate, 'MMMM', { locale: dateFnsLocale })} ${format(startDate, 'yyyy', {
|
|
14
|
-
locale: dateFnsLocale,
|
|
15
|
-
})}`;
|
|
16
|
-
}
|
|
17
|
-
if (sameYear) {
|
|
18
|
-
return `${fromLabel} ${format(startDate, 'dd MMM', { locale: dateFnsLocale })} ${toLabel} ${format(endDate, 'dd MMM', { locale: dateFnsLocale })} ${format(startDate, 'yyyy', { locale: dateFnsLocale })}`;
|
|
19
|
-
}
|
|
20
|
-
return `${fromLabel} ${format(startDate, 'dd MMM yyyy', { locale: dateFnsLocale })} ${toLabel} ${format(endDate, 'dd MMM yyyy', { locale: dateFnsLocale })}`;
|
|
21
|
-
}
|
package/dist/date/formatSec.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"formatSec.d.ts","sourceRoot":"","sources":["../../src/date/formatSec.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,UAKpC"}
|