@amimpact/willy-utils 4.12.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.
Files changed (3) hide show
  1. package/package.json +1 -1
  2. package/src/date.ts +11 -9
  3. package/src/misc.ts +18 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amimpact/willy-utils",
3
- "version": "4.12.0",
3
+ "version": "4.13.0",
4
4
  "description": "Javascript utils",
5
5
  "scripts": {
6
6
  "publish:prerelease": "npm version prerelease --preid beta && npm publish --tag beta",
package/src/date.ts CHANGED
@@ -14,7 +14,7 @@ import { parse as parseISO } from './includes/tinyduration';
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 = (dateObject: CraftDate, options: FormatCraftDateOptions) => {
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
- // Check of dateRaw een valide datum is, zo ja, dan geven we de geformatteerde datum terug, anders de originele dateToFormat
205
- return isNaN(dateRaw.getTime()) ? dateToFormat : dateFormatted;
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
  /**
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
  *