asv-hlps 1.3.31 → 1.3.33

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.
@@ -1,9 +1,8 @@
1
+ import { ConfigType, OpUnitType, QUnitType } from "dayjs";
1
2
  import "dayjs/locale/fr";
2
3
  export declare const genDateMinutesStep: (step: number, lang?: string) => string[];
3
4
  export declare const percentOf: (nbr: number, percentage: number) => number;
4
5
  export declare const calPercent: (nbr: number, percentage: number) => number;
5
- export declare const displayDateRangeFr: (getFromDate?: any, getToDate?: any) => string;
6
- export declare const getNbOfDaysBetweenTwoDates: (date1: Date, date2: Date) => number;
7
6
  export declare const getRandomColor: (brightness: number) => string;
8
7
  /**
9
8
  * remove duplicates from array by crietere (key)
@@ -25,10 +24,6 @@ export declare const formatToString: (val: number, separator?: string, currency?
25
24
  export declare const currencyFormatter: (val: number, separator?: string, currency?: string) => string;
26
25
  export declare const formatToStringCfa: (val: number) => string;
27
26
  export declare const currencyFormatterCfa: (val: number) => string;
28
- export declare const reformatDates: (fromDate: any, toDate: any) => {
29
- fromDate: any;
30
- toDate: any;
31
- };
32
27
  export declare const notInSequence: (arr: number[]) => number[];
33
28
  export declare const sequencesToNumbers: (arr: any[]) => number[];
34
29
  export declare const findSequencesMissing: (arr: any[]) => number[];
@@ -44,7 +39,15 @@ export declare const sesStorageSet: (key: string, val: any) => void;
44
39
  export declare const sesStorageGet: (key: string) => any;
45
40
  export declare const replaceAllIn: (text: string, regex?: RegExp, toChar?: string) => string;
46
41
  export declare const replaceSpacesWith: (text: string, toChar?: string) => string;
42
+ export declare const dateFormatter: (date: Date | string, format?: "y" | "ym" | "ymd" | "dmy" | "ago" | "md" | "dmy-hm" | "dmyfr" | "myfr" | "mfr-short" | "mfr-long", separator?: "/" | "" | "-") => string;
43
+ export declare const dateDiff: (date1: ConfigType, unit?: QUnitType | OpUnitType, date2?: Date) => number;
47
44
  export declare const dateToString: (date: Date | any) => string;
45
+ export declare const reformatDates: (fromDate: any, toDate: any) => {
46
+ fromDate: any;
47
+ toDate: any;
48
+ };
49
+ export declare const displayDateRangeFr: (getFromDate?: any, getToDate?: any) => string;
50
+ export declare const getNbOfDaysBetweenTwoDates: (date1: Date, date2: Date) => number;
48
51
  export declare const formatNgbDate: (date: any) => {
49
52
  fromDate: string;
50
53
  toDate: string;
@@ -90,7 +93,6 @@ export declare const returnBool: (tob?: boolean) => boolean;
90
93
  export declare const monthStringName: (date: string | Date, format?: "MMM" | "MMMM", options?: {
91
94
  en?: true;
92
95
  }) => string;
93
- export declare const dateFormatter: (date: Date | string, format?: "y" | "ym" | "ymd" | "dmy" | "ago" | "md" | "dmy-hm" | "dmyfr" | "myfr" | "mfr-short" | "mfr-long", separator?: "/" | "" | "-") => string;
94
96
  export declare const countryIsoToFlag: (code: string) => string;
95
97
  export declare const removeParamKeyName: (params: any, name?: string) => any;
96
98
  export declare const roundLastNDigits: (num: number, digits?: number) => number | false;
package/lib/cjs/utils.js CHANGED
@@ -3,8 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.insertAtInArray = exports.isBirthday = exports.padEndWithZero = exports.padStartWithZero = exports.formatMonthYearToLocaleString = exports.calculPercent = exports.validEmail = exports.convertToCfa = exports.packAndUnit = exports.unCheckedAll = exports.inputChecked = exports.arrayMultiChecked = exports.getPeriodDateColor = exports.getColorAccordingToDate = exports.genRandomColour = exports.formatNgbDate = exports.dateToString = exports.replaceSpacesWith = exports.replaceAllIn = exports.sesStorageGet = exports.sesStorageSet = exports.genSequenceRef = exports.removeBackSlashOccurences = exports.removeString = exports.diffArraysByProp = exports.diffArraysByFunc = exports.deepClone = exports.findFirstSequenceMissing = exports.fillNumWithZero = exports.findSequencesMissing = exports.sequencesToNumbers = exports.notInSequence = exports.reformatDates = exports.currencyFormatterCfa = exports.formatToStringCfa = exports.currencyFormatter = exports.formatToString = exports.wakeUp = exports.sleep = exports.limitTo = exports.titleCase = exports.toObjectDate = exports.duplicateObjects = exports.removeDuplicateObjects = exports.getRandomColor = exports.getNbOfDaysBetweenTwoDates = exports.displayDateRangeFr = exports.calPercent = exports.percentOf = exports.genDateMinutesStep = void 0;
7
- exports.toggleProp = exports.roundLastNDigits = exports.removeParamKeyName = exports.countryIsoToFlag = exports.dateFormatter = exports.monthStringName = exports.returnBool = exports.formatAmountToString = exports.reduceSum = exports.sumAmount = exports.fillEndWithZero = exports.fillStartWithZero = exports.absFromSequence = exports.returnDates = exports.displayFrDatePeriode = exports.getArrayOfRandomColor = exports.randomHslColor = exports.randomHexColor = exports.randomRgbColor = exports.randomInteger = void 0;
6
+ exports.padEndWithZero = exports.padStartWithZero = exports.formatMonthYearToLocaleString = exports.calculPercent = exports.validEmail = exports.convertToCfa = exports.packAndUnit = exports.unCheckedAll = exports.inputChecked = exports.arrayMultiChecked = exports.getPeriodDateColor = exports.getColorAccordingToDate = exports.genRandomColour = exports.formatNgbDate = exports.getNbOfDaysBetweenTwoDates = exports.displayDateRangeFr = exports.reformatDates = exports.dateToString = exports.dateDiff = exports.dateFormatter = exports.replaceSpacesWith = exports.replaceAllIn = exports.sesStorageGet = exports.sesStorageSet = exports.genSequenceRef = exports.removeBackSlashOccurences = exports.removeString = exports.diffArraysByProp = exports.diffArraysByFunc = exports.deepClone = exports.findFirstSequenceMissing = exports.fillNumWithZero = exports.findSequencesMissing = exports.sequencesToNumbers = exports.notInSequence = exports.currencyFormatterCfa = exports.formatToStringCfa = exports.currencyFormatter = exports.formatToString = exports.wakeUp = exports.sleep = exports.limitTo = exports.titleCase = exports.toObjectDate = exports.duplicateObjects = exports.removeDuplicateObjects = exports.getRandomColor = exports.calPercent = exports.percentOf = exports.genDateMinutesStep = void 0;
7
+ exports.toggleProp = exports.roundLastNDigits = exports.removeParamKeyName = exports.countryIsoToFlag = exports.monthStringName = exports.returnBool = exports.formatAmountToString = exports.reduceSum = exports.sumAmount = exports.fillEndWithZero = exports.fillStartWithZero = exports.absFromSequence = exports.returnDates = exports.displayFrDatePeriode = exports.getArrayOfRandomColor = exports.randomHslColor = exports.randomHexColor = exports.randomRgbColor = exports.randomInteger = exports.insertAtInArray = exports.isBirthday = void 0;
8
8
  const dayjs_1 = __importDefault(require("dayjs"));
9
9
  const relativeTime_1 = __importDefault(require("dayjs/plugin/relativeTime"));
10
10
  const lodash_1 = __importDefault(require("lodash"));
@@ -86,18 +86,6 @@ const calPercent = (nbr, percentage) => {
86
86
  return nbr + (nbr * percentage) / 100;
87
87
  };
88
88
  exports.calPercent = calPercent;
89
- const displayDateRangeFr = (getFromDate, getToDate) => {
90
- const fromDate = !getFromDate ? new Date() : getFromDate;
91
- const toDate = !getToDate ? fromDate : getToDate;
92
- return (0, exports.dateFormatter)(new Date(fromDate), "dmy", "/") + " au " + (0, exports.dateFormatter)(new Date(toDate), "dmy", "/");
93
- };
94
- exports.displayDateRangeFr = displayDateRangeFr;
95
- const getNbOfDaysBetweenTwoDates = (date1, date2) => {
96
- const day = 1000 * 60 * 60 * 24;
97
- const diff = Math.abs(date2.getTime() - date1.getTime());
98
- return Math.ceil(diff / day);
99
- };
100
- exports.getNbOfDaysBetweenTwoDates = getNbOfDaysBetweenTwoDates;
101
89
  const getRandomColor = (brightness) => {
102
90
  // Six levels of brightness from 0 to 5, 0 being the darkest
103
91
  const rgb = [Math.random() * 256, Math.random() * 256, Math.random() * 256];
@@ -196,14 +184,6 @@ const currencyFormatterCfa = (val) => {
196
184
  };
197
185
  exports.currencyFormatterCfa = currencyFormatterCfa;
198
186
  // const = reformatDates(fromDate: string, toDate: string) => {
199
- const reformatDates = (fromDate, toDate) => {
200
- if (fromDate === undefined || fromDate === null) {
201
- return null;
202
- }
203
- toDate = !toDate ? fromDate : toDate;
204
- return { fromDate, toDate };
205
- };
206
- exports.reformatDates = reformatDates;
207
187
  const notInSequence = (arr) => {
208
188
  const [min, max] = [Math.min(...arr), Math.max(...arr)];
209
189
  // let out = Array.from(Array(max - min), (v, i) => i + min).filter((i) => !arr.includes(i));
@@ -248,7 +228,8 @@ const diffArraysByFunc = (arr1, arr2, func) => {
248
228
  };
249
229
  exports.diffArraysByFunc = diffArraysByFunc;
250
230
  const diffArraysByProp = (arr1, arr2, propArr1 = "id", propArr2 = "id") => {
251
- return lodash_1.default.differenceWith(arr1, arr2, (a, b) => lodash_1.default.isEqual(a[propArr1], b[propArr2]));
231
+ // return lodash.differenceWith(arr1, arr2, (a, b) => lodash.isEqual(a[propArr1], b[propArr2]));
232
+ return lodash_1.default.differenceWith(arr1, arr2, (a, b) => lodash_1.default.isEqual(lodash_1.default.get(a, propArr1), lodash_1.default.get(b, propArr2)));
252
233
  };
253
234
  exports.diffArraysByProp = diffArraysByProp;
254
235
  const removeString = (text, word) => {
@@ -301,10 +282,66 @@ const replaceSpacesWith = (text, toChar = "_") => {
301
282
  return text.replace(/\s/g, toChar) || text;
302
283
  };
303
284
  exports.replaceSpacesWith = replaceSpacesWith;
285
+ /* start: dates -------------------------------------- */
286
+ const dateFormatter = (date, format = "dmy", separator = "/") => {
287
+ switch (format) {
288
+ case "y":
289
+ return (0, dayjs_1.default)(date).format("YYYY");
290
+ case "ym":
291
+ return (0, dayjs_1.default)(date).format(`YYYY${separator}MM`);
292
+ case "ymd":
293
+ return (0, dayjs_1.default)(date).format(`YYYY${separator}MM${separator}DD`);
294
+ case "md":
295
+ return (0, dayjs_1.default)(date).format(`MM${separator}DD`);
296
+ case "dmy":
297
+ return (0, dayjs_1.default)(date).format(`DD${separator}MM${separator}YYYY`);
298
+ case "dmy-hm":
299
+ return (0, dayjs_1.default)(date).format(`DD${separator}MM${separator}YYYY HH:mm`);
300
+ case "dmyfr":
301
+ return (0, dayjs_1.default)(date).locale("fr").format("dddd DD MMMM YYYY");
302
+ case "myfr":
303
+ return (0, dayjs_1.default)(date).locale("fr").format("MMMM YYYY");
304
+ case "mfr-short":
305
+ return (0, dayjs_1.default)(date).locale("fr").format("MMM");
306
+ case "mfr-long":
307
+ return (0, dayjs_1.default)(date).locale("fr").format("MMMM");
308
+ case "ago":
309
+ return (0, dayjs_1.default)(date).locale("fr").fromNow(true);
310
+ default:
311
+ return (0, dayjs_1.default)(date).format(`DD/MM/YYYY`);
312
+ // return dayjs(date).format(`YYYY${separator}MM${separator}DD`);
313
+ }
314
+ };
315
+ exports.dateFormatter = dateFormatter;
316
+ const dateDiff = (date1, unit = "year", date2 = new Date()) => {
317
+ return (0, dayjs_1.default)(date2).diff(date1, unit);
318
+ };
319
+ exports.dateDiff = dateDiff;
304
320
  const dateToString = (date) => {
305
321
  return date.year + "-" + ("0" + date.month).slice(-2) + "-" + ("0" + date.day).slice(-2);
306
322
  };
307
323
  exports.dateToString = dateToString;
324
+ const reformatDates = (fromDate, toDate) => {
325
+ if (fromDate === undefined || fromDate === null) {
326
+ return null;
327
+ }
328
+ toDate = !toDate ? fromDate : toDate;
329
+ return { fromDate, toDate };
330
+ };
331
+ exports.reformatDates = reformatDates;
332
+ const displayDateRangeFr = (getFromDate, getToDate) => {
333
+ const fromDate = !getFromDate ? new Date() : getFromDate;
334
+ const toDate = !getToDate ? fromDate : getToDate;
335
+ return (0, exports.dateFormatter)(new Date(fromDate), "dmy", "/") + " au " + (0, exports.dateFormatter)(new Date(toDate), "dmy", "/");
336
+ };
337
+ exports.displayDateRangeFr = displayDateRangeFr;
338
+ const getNbOfDaysBetweenTwoDates = (date1, date2) => {
339
+ const day = 1000 * 60 * 60 * 24;
340
+ const diff = Math.abs(date2.getTime() - date1.getTime());
341
+ return Math.ceil(diff / day);
342
+ };
343
+ exports.getNbOfDaysBetweenTwoDates = getNbOfDaysBetweenTwoDates;
344
+ /* end: dates ---------------------------------------- */
308
345
  // export const formatNgbDate = (date: DateSelected) => {
309
346
  const formatNgbDate = (date) => {
310
347
  const fromDate = date.fromDate ? (0, exports.dateToString)(date.fromDate) : null;
@@ -623,36 +660,6 @@ const monthStringName = (date, format = "MMM", options) => {
623
660
  return (0, dayjs_1.default)(date).locale("fr").format(format);
624
661
  };
625
662
  exports.monthStringName = monthStringName;
626
- const dateFormatter = (date, format = "dmy", separator = "/") => {
627
- switch (format) {
628
- case "y":
629
- return (0, dayjs_1.default)(date).format("YYYY");
630
- case "ym":
631
- return (0, dayjs_1.default)(date).format(`YYYY${separator}MM`);
632
- case "ymd":
633
- return (0, dayjs_1.default)(date).format(`YYYY${separator}MM${separator}DD`);
634
- case "md":
635
- return (0, dayjs_1.default)(date).format(`MM${separator}DD`);
636
- case "dmy":
637
- return (0, dayjs_1.default)(date).format(`DD${separator}MM${separator}YYYY`);
638
- case "dmy-hm":
639
- return (0, dayjs_1.default)(date).format(`DD${separator}MM${separator}YYYY HH:mm`);
640
- case "dmyfr":
641
- return (0, dayjs_1.default)(date).locale("fr").format("dddd DD MMMM YYYY");
642
- case "myfr":
643
- return (0, dayjs_1.default)(date).locale("fr").format("MMMM YYYY");
644
- case "mfr-short":
645
- return (0, dayjs_1.default)(date).locale("fr").format("MMM");
646
- case "mfr-long":
647
- return (0, dayjs_1.default)(date).locale("fr").format("MMMM");
648
- case "ago":
649
- return (0, dayjs_1.default)(date).locale("fr").fromNow(true);
650
- default:
651
- return (0, dayjs_1.default)(date).format(`DD/MM/YYYY`);
652
- // return dayjs(date).format(`YYYY${separator}MM${separator}DD`);
653
- }
654
- };
655
- exports.dateFormatter = dateFormatter;
656
663
  const countryIsoToFlag = (code) => {
657
664
  return code
658
665
  .split("")
@@ -1,9 +1,8 @@
1
+ import { ConfigType, OpUnitType, QUnitType } from "dayjs";
1
2
  import "dayjs/locale/fr";
2
3
  export declare const genDateMinutesStep: (step: number, lang?: string) => string[];
3
4
  export declare const percentOf: (nbr: number, percentage: number) => number;
4
5
  export declare const calPercent: (nbr: number, percentage: number) => number;
5
- export declare const displayDateRangeFr: (getFromDate?: any, getToDate?: any) => string;
6
- export declare const getNbOfDaysBetweenTwoDates: (date1: Date, date2: Date) => number;
7
6
  export declare const getRandomColor: (brightness: number) => string;
8
7
  /**
9
8
  * remove duplicates from array by crietere (key)
@@ -25,10 +24,6 @@ export declare const formatToString: (val: number, separator?: string, currency?
25
24
  export declare const currencyFormatter: (val: number, separator?: string, currency?: string) => string;
26
25
  export declare const formatToStringCfa: (val: number) => string;
27
26
  export declare const currencyFormatterCfa: (val: number) => string;
28
- export declare const reformatDates: (fromDate: any, toDate: any) => {
29
- fromDate: any;
30
- toDate: any;
31
- };
32
27
  export declare const notInSequence: (arr: number[]) => number[];
33
28
  export declare const sequencesToNumbers: (arr: any[]) => number[];
34
29
  export declare const findSequencesMissing: (arr: any[]) => number[];
@@ -44,7 +39,15 @@ export declare const sesStorageSet: (key: string, val: any) => void;
44
39
  export declare const sesStorageGet: (key: string) => any;
45
40
  export declare const replaceAllIn: (text: string, regex?: RegExp, toChar?: string) => string;
46
41
  export declare const replaceSpacesWith: (text: string, toChar?: string) => string;
42
+ export declare const dateFormatter: (date: Date | string, format?: "y" | "ym" | "ymd" | "dmy" | "ago" | "md" | "dmy-hm" | "dmyfr" | "myfr" | "mfr-short" | "mfr-long", separator?: "/" | "" | "-") => string;
43
+ export declare const dateDiff: (date1: ConfigType, unit?: QUnitType | OpUnitType, date2?: Date) => number;
47
44
  export declare const dateToString: (date: Date | any) => string;
45
+ export declare const reformatDates: (fromDate: any, toDate: any) => {
46
+ fromDate: any;
47
+ toDate: any;
48
+ };
49
+ export declare const displayDateRangeFr: (getFromDate?: any, getToDate?: any) => string;
50
+ export declare const getNbOfDaysBetweenTwoDates: (date1: Date, date2: Date) => number;
48
51
  export declare const formatNgbDate: (date: any) => {
49
52
  fromDate: string;
50
53
  toDate: string;
@@ -90,7 +93,6 @@ export declare const returnBool: (tob?: boolean) => boolean;
90
93
  export declare const monthStringName: (date: string | Date, format?: "MMM" | "MMMM", options?: {
91
94
  en?: true;
92
95
  }) => string;
93
- export declare const dateFormatter: (date: Date | string, format?: "y" | "ym" | "ymd" | "dmy" | "ago" | "md" | "dmy-hm" | "dmyfr" | "myfr" | "mfr-short" | "mfr-long", separator?: "/" | "" | "-") => string;
94
96
  export declare const countryIsoToFlag: (code: string) => string;
95
97
  export declare const removeParamKeyName: (params: any, name?: string) => any;
96
98
  export declare const roundLastNDigits: (num: number, digits?: number) => number | false;
package/lib/esm/utils.js CHANGED
@@ -76,16 +76,6 @@ export const calPercent = (nbr, percentage) => {
76
76
  }
77
77
  return nbr + (nbr * percentage) / 100;
78
78
  };
79
- export const displayDateRangeFr = (getFromDate, getToDate) => {
80
- const fromDate = !getFromDate ? new Date() : getFromDate;
81
- const toDate = !getToDate ? fromDate : getToDate;
82
- return dateFormatter(new Date(fromDate), "dmy", "/") + " au " + dateFormatter(new Date(toDate), "dmy", "/");
83
- };
84
- export const getNbOfDaysBetweenTwoDates = (date1, date2) => {
85
- const day = 1000 * 60 * 60 * 24;
86
- const diff = Math.abs(date2.getTime() - date1.getTime());
87
- return Math.ceil(diff / day);
88
- };
89
79
  export const getRandomColor = (brightness) => {
90
80
  // Six levels of brightness from 0 to 5, 0 being the darkest
91
81
  const rgb = [Math.random() * 256, Math.random() * 256, Math.random() * 256];
@@ -172,13 +162,6 @@ export const currencyFormatterCfa = (val) => {
172
162
  return currencyFormatter(val, " ", " FCFA");
173
163
  };
174
164
  // const = reformatDates(fromDate: string, toDate: string) => {
175
- export const reformatDates = (fromDate, toDate) => {
176
- if (fromDate === undefined || fromDate === null) {
177
- return null;
178
- }
179
- toDate = !toDate ? fromDate : toDate;
180
- return { fromDate, toDate };
181
- };
182
165
  export const notInSequence = (arr) => {
183
166
  const [min, max] = [Math.min(...arr), Math.max(...arr)];
184
167
  // let out = Array.from(Array(max - min), (v, i) => i + min).filter((i) => !arr.includes(i));
@@ -216,7 +199,8 @@ export const diffArraysByFunc = (arr1, arr2, func) => {
216
199
  return lodash.differenceBy(arr1, arr2, func);
217
200
  };
218
201
  export const diffArraysByProp = (arr1, arr2, propArr1 = "id", propArr2 = "id") => {
219
- return lodash.differenceWith(arr1, arr2, (a, b) => lodash.isEqual(a[propArr1], b[propArr2]));
202
+ // return lodash.differenceWith(arr1, arr2, (a, b) => lodash.isEqual(a[propArr1], b[propArr2]));
203
+ return lodash.differenceWith(arr1, arr2, (a, b) => lodash.isEqual(lodash.get(a, propArr1), lodash.get(b, propArr2)));
220
204
  };
221
205
  export const removeString = (text, word) => {
222
206
  return text.toLowerCase().replace(word.toLowerCase(), "") || text;
@@ -261,9 +245,60 @@ export const replaceAllIn = (text, regex = / /g, toChar = "_") => {
261
245
  export const replaceSpacesWith = (text, toChar = "_") => {
262
246
  return text.replace(/\s/g, toChar) || text;
263
247
  };
248
+ /* start: dates -------------------------------------- */
249
+ export const dateFormatter = (date, format = "dmy", separator = "/") => {
250
+ switch (format) {
251
+ case "y":
252
+ return dayjs(date).format("YYYY");
253
+ case "ym":
254
+ return dayjs(date).format(`YYYY${separator}MM`);
255
+ case "ymd":
256
+ return dayjs(date).format(`YYYY${separator}MM${separator}DD`);
257
+ case "md":
258
+ return dayjs(date).format(`MM${separator}DD`);
259
+ case "dmy":
260
+ return dayjs(date).format(`DD${separator}MM${separator}YYYY`);
261
+ case "dmy-hm":
262
+ return dayjs(date).format(`DD${separator}MM${separator}YYYY HH:mm`);
263
+ case "dmyfr":
264
+ return dayjs(date).locale("fr").format("dddd DD MMMM YYYY");
265
+ case "myfr":
266
+ return dayjs(date).locale("fr").format("MMMM YYYY");
267
+ case "mfr-short":
268
+ return dayjs(date).locale("fr").format("MMM");
269
+ case "mfr-long":
270
+ return dayjs(date).locale("fr").format("MMMM");
271
+ case "ago":
272
+ return dayjs(date).locale("fr").fromNow(true);
273
+ default:
274
+ return dayjs(date).format(`DD/MM/YYYY`);
275
+ // return dayjs(date).format(`YYYY${separator}MM${separator}DD`);
276
+ }
277
+ };
278
+ export const dateDiff = (date1, unit = "year", date2 = new Date()) => {
279
+ return dayjs(date2).diff(date1, unit);
280
+ };
264
281
  export const dateToString = (date) => {
265
282
  return date.year + "-" + ("0" + date.month).slice(-2) + "-" + ("0" + date.day).slice(-2);
266
283
  };
284
+ export const reformatDates = (fromDate, toDate) => {
285
+ if (fromDate === undefined || fromDate === null) {
286
+ return null;
287
+ }
288
+ toDate = !toDate ? fromDate : toDate;
289
+ return { fromDate, toDate };
290
+ };
291
+ export const displayDateRangeFr = (getFromDate, getToDate) => {
292
+ const fromDate = !getFromDate ? new Date() : getFromDate;
293
+ const toDate = !getToDate ? fromDate : getToDate;
294
+ return dateFormatter(new Date(fromDate), "dmy", "/") + " au " + dateFormatter(new Date(toDate), "dmy", "/");
295
+ };
296
+ export const getNbOfDaysBetweenTwoDates = (date1, date2) => {
297
+ const day = 1000 * 60 * 60 * 24;
298
+ const diff = Math.abs(date2.getTime() - date1.getTime());
299
+ return Math.ceil(diff / day);
300
+ };
301
+ /* end: dates ---------------------------------------- */
267
302
  // export const formatNgbDate = (date: DateSelected) => {
268
303
  export const formatNgbDate = (date) => {
269
304
  const fromDate = date.fromDate ? dateToString(date.fromDate) : null;
@@ -551,35 +586,6 @@ export const monthStringName = (date, format = "MMM", options) => {
551
586
  }
552
587
  return dayjs(date).locale("fr").format(format);
553
588
  };
554
- export const dateFormatter = (date, format = "dmy", separator = "/") => {
555
- switch (format) {
556
- case "y":
557
- return dayjs(date).format("YYYY");
558
- case "ym":
559
- return dayjs(date).format(`YYYY${separator}MM`);
560
- case "ymd":
561
- return dayjs(date).format(`YYYY${separator}MM${separator}DD`);
562
- case "md":
563
- return dayjs(date).format(`MM${separator}DD`);
564
- case "dmy":
565
- return dayjs(date).format(`DD${separator}MM${separator}YYYY`);
566
- case "dmy-hm":
567
- return dayjs(date).format(`DD${separator}MM${separator}YYYY HH:mm`);
568
- case "dmyfr":
569
- return dayjs(date).locale("fr").format("dddd DD MMMM YYYY");
570
- case "myfr":
571
- return dayjs(date).locale("fr").format("MMMM YYYY");
572
- case "mfr-short":
573
- return dayjs(date).locale("fr").format("MMM");
574
- case "mfr-long":
575
- return dayjs(date).locale("fr").format("MMMM");
576
- case "ago":
577
- return dayjs(date).locale("fr").fromNow(true);
578
- default:
579
- return dayjs(date).format(`DD/MM/YYYY`);
580
- // return dayjs(date).format(`YYYY${separator}MM${separator}DD`);
581
- }
582
- };
583
589
  export const countryIsoToFlag = (code) => {
584
590
  return code
585
591
  .split("")
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "asv-hlps",
3
- "version": "1.3.31",
3
+ "version": "1.3.33",
4
4
  "description": "helpers",
5
5
  "main": "./lib/cjs/index.js",
6
6
  "module": "./lib/esm/index.js",