@amimpact/willy-utils 4.11.0 → 4.13.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.
- package/package.json +1 -1
- package/src/date.ts +14 -12
- package/src/misc.ts +18 -0
package/package.json
CHANGED
package/src/date.ts
CHANGED
|
@@ -7,14 +7,14 @@ import {
|
|
|
7
7
|
subDays,
|
|
8
8
|
} from 'date-fns';
|
|
9
9
|
import { nl } from 'date-fns/locale';
|
|
10
|
-
import {
|
|
10
|
+
import { TZDate } from '@date-fns/tz';
|
|
11
11
|
import { parse as parseISO } from './includes/tinyduration';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Momenteel beschikbare locales
|
|
15
15
|
* Engels is default (leeg)
|
|
16
16
|
*/
|
|
17
|
-
const availableLocales = {
|
|
17
|
+
const availableLocales: { [key: string]: any } = {
|
|
18
18
|
en: '',
|
|
19
19
|
nl: nl,
|
|
20
20
|
};
|
|
@@ -160,7 +160,10 @@ export interface parseISODurationOptions {
|
|
|
160
160
|
* @param {CraftDate} dateObject
|
|
161
161
|
* @param {FormatCraftDateOptions} options
|
|
162
162
|
*/
|
|
163
|
-
export const formatCraftDate = (
|
|
163
|
+
export const formatCraftDate = (
|
|
164
|
+
dateObject: CraftDate,
|
|
165
|
+
options: Partial<FormatCraftDateOptions>,
|
|
166
|
+
) => {
|
|
164
167
|
let dateFormat = options && options.systemFormat ? 'yyyy-MM-dd' : 'dd-MM-yyyy';
|
|
165
168
|
let localeString = 'nl';
|
|
166
169
|
|
|
@@ -195,14 +198,13 @@ export const formatCraftDate = (dateObject: CraftDate, options: FormatCraftDateO
|
|
|
195
198
|
: dateObject.date.replace(/-/g, '/').split('.')[0];
|
|
196
199
|
|
|
197
200
|
const dateRaw = new Date(dateToFormat);
|
|
198
|
-
const dateFormatted = format(
|
|
199
|
-
new Date(dateToFormat),
|
|
200
|
-
dateFormat,
|
|
201
|
-
getLocaleOptions(localeString),
|
|
202
|
-
);
|
|
203
201
|
|
|
204
|
-
|
|
205
|
-
|
|
202
|
+
if (isNaN(dateRaw.getTime())) {
|
|
203
|
+
console.warn('Ongeldige datum:', dateToFormat);
|
|
204
|
+
return dateToFormat;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return format(new Date(dateToFormat), dateFormat, getLocaleOptions(localeString));
|
|
206
208
|
};
|
|
207
209
|
|
|
208
210
|
/**
|
|
@@ -236,7 +238,7 @@ export const formatDateFromNow = (dateObject: CraftDate, options: FormatDateFrom
|
|
|
236
238
|
|
|
237
239
|
const parsed = isString
|
|
238
240
|
? new Date(dateObject).toString()
|
|
239
|
-
:
|
|
241
|
+
: new TZDate(dateObject.date, dateObject.timezone);
|
|
240
242
|
|
|
241
243
|
/**
|
|
242
244
|
* Datum tonen voor ouder dan x tijd
|
|
@@ -286,7 +288,7 @@ export const formatNewDate = (dateObject: CraftDate) => {
|
|
|
286
288
|
|
|
287
289
|
const parsed = isString
|
|
288
290
|
? new Date(dateObject).toString()
|
|
289
|
-
:
|
|
291
|
+
: new TZDate(dateObject.date, dateObject.timezone);
|
|
290
292
|
|
|
291
293
|
return new Date(parsed);
|
|
292
294
|
};
|
package/src/misc.ts
CHANGED
|
@@ -271,6 +271,24 @@ export const observeResize = (element: HTMLElement, callback: Function) => {
|
|
|
271
271
|
}
|
|
272
272
|
};
|
|
273
273
|
|
|
274
|
+
/**
|
|
275
|
+
* Kapt een string af tot de gespecificeerde lengte en voegt een ellipsis toe.
|
|
276
|
+
*
|
|
277
|
+
* @param {string} text - De inkomende string
|
|
278
|
+
* @param {number} [maxLength=30] - De maximale lengte voordat ... wordt toegevoegd.
|
|
279
|
+
* @returns {string} - De trunctated string.
|
|
280
|
+
*/
|
|
281
|
+
export const truncateString = (text: string, maxLength: number = 30) => {
|
|
282
|
+
if (!text || text.length <= maxLength) {
|
|
283
|
+
return text;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// We nemen de string tot (maxLength - 3) om ruimte te maken voor de "..."
|
|
287
|
+
const truncatedText = text.substring(0, maxLength - 3);
|
|
288
|
+
|
|
289
|
+
return `${truncatedText}...`;
|
|
290
|
+
};
|
|
291
|
+
|
|
274
292
|
/**
|
|
275
293
|
* Wrap een element in een nieuw element
|
|
276
294
|
*
|