asv-hlps 1.2.92 → 1.2.94

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.
@@ -22,7 +22,8 @@ export declare const removeDuplicates: (tab: any[]) => any[];
22
22
  * @param key
23
23
  * @returns
24
24
  */
25
- export declare const removeDuplicatesByKey: (tobs: any[], key: string) => any[];
25
+ export declare const removeDuplicatesByKey: (tobs: any[], property: string) => any[];
26
+ export declare const removeDuplicateObjects: (array: any[], property: string) => any[];
26
27
  export declare const toObjectDate: (fromDate: any, toDate: string) => {
27
28
  fromDate: any;
28
29
  toDate: string;
@@ -57,6 +58,7 @@ export declare const formatNgbDate: (date: any) => {
57
58
  };
58
59
  export declare const genRandomColour: () => string;
59
60
  export declare const getColorAccordingToDate: (inputDate: Date, period1?: number, period2?: number, period3?: number, ifClass?: boolean) => "red" | "DarkOrange" | "turquoise" | "blue" | "green" | "#f46a6a" | "#f1b44c" | "#cce5ff" | "#34c38f" | "#339900";
61
+ export declare const getPeriodDateColor: (inputDate: string, period?: number) => "danger" | "warning" | "purple" | "success" | "info";
60
62
  export declare const arrayMultiChecked: (objet: any[], event: boolean, item: any) => any[];
61
63
  export declare const inputChecked: (event: any, item: any, checks: any[], isChecked?: boolean) => any[];
62
64
  export declare const unCheckedAll: (checks?: any[]) => void;
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.validEmail = exports.convertToCfa = exports.packAndUnit = exports.unCheckedAll = exports.inputChecked = exports.arrayMultiChecked = exports.getColorAccordingToDate = exports.genRandomColour = exports.formatNgbDate = exports.dateToString = exports.replaceSpacesWith = exports.replaceAllIn = exports.sesStorageGet = exports.sesStorageSet = exports.genSequenceRef = exports.removeBackSlashOccurences = exports.removeString = exports.deepClone = exports.findFirstSequenceMissing = exports.fillNumWithZero = exports.findSequencesMissing = exports.sequencesToNumbers = exports.notInSequence = exports.reformatDates = exports.formatToStringCfa = exports.formatToString = exports.wakeUp = exports.sleep = exports.limitTo = exports.titleCase = exports.toObjectDate = exports.removeDuplicatesByKey = exports.removeDuplicates = exports.getRandomColor = exports.getNbOfDaysBetweenTwoDates = exports.displayDateRangeFr = exports.calPercent = exports.percentOf = exports.genDateMinutesStep = exports.convertFrDateToEnDate = exports.convertEnDateToFr = exports.formatDateMd = exports.formatDateYm = exports.formatDateYmFirstDay = exports.formatDateYmd = exports.formatFromAndToDate = exports.formatDateYmHypen = exports.formatDateFirstDayFr = exports.formatDateYmdHypenFr = exports.formatDateYmdHypen = void 0;
7
- 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 = exports.padEndWithZero = exports.padStartWithZero = exports.formatMonthYearToLocaleString = exports.calculPercent = void 0;
6
+ 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.deepClone = exports.findFirstSequenceMissing = exports.fillNumWithZero = exports.findSequencesMissing = exports.sequencesToNumbers = exports.notInSequence = exports.reformatDates = exports.formatToStringCfa = exports.formatToString = exports.wakeUp = exports.sleep = exports.limitTo = exports.titleCase = exports.toObjectDate = exports.removeDuplicateObjects = exports.removeDuplicatesByKey = exports.removeDuplicates = exports.getRandomColor = exports.getNbOfDaysBetweenTwoDates = exports.displayDateRangeFr = exports.calPercent = exports.percentOf = exports.genDateMinutesStep = exports.convertFrDateToEnDate = exports.convertEnDateToFr = exports.formatDateMd = exports.formatDateYm = exports.formatDateYmFirstDay = exports.formatDateYmd = exports.formatFromAndToDate = exports.formatDateYmHypen = exports.formatDateFirstDayFr = exports.formatDateYmdHypenFr = exports.formatDateYmdHypen = void 0;
7
+ 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 = exports.padEndWithZero = exports.padStartWithZero = exports.formatMonthYearToLocaleString = exports.calculPercent = exports.validEmail = exports.convertToCfa = void 0;
8
8
  const dayjs_1 = __importDefault(require("dayjs"));
9
9
  require("dayjs/locale/fr");
10
10
  const formatDateYmdHypen = (date) => {
@@ -126,10 +126,23 @@ exports.removeDuplicates = removeDuplicates;
126
126
  * @param key
127
127
  * @returns
128
128
  */
129
- const removeDuplicatesByKey = (tobs, key) => {
130
- return [...new Map(tobs.map((item) => [item[key], item])).values()];
129
+ const removeDuplicatesByKey = (tobs, property) => {
130
+ return [...new Map(tobs.map((item) => [item[property], item])).values()];
131
131
  };
132
132
  exports.removeDuplicatesByKey = removeDuplicatesByKey;
133
+ const removeDuplicateObjects = (array, property) => {
134
+ const uniqueIds = [];
135
+ const unique = array.filter((element) => {
136
+ const isDuplicate = uniqueIds.includes(element[property]);
137
+ if (!isDuplicate) {
138
+ uniqueIds.push(element[property]);
139
+ return true;
140
+ }
141
+ return false;
142
+ });
143
+ return unique;
144
+ };
145
+ exports.removeDuplicateObjects = removeDuplicateObjects;
133
146
  const toObjectDate = (fromDate, toDate) => {
134
147
  toDate = toDate !== "null" ? toDate : fromDate;
135
148
  return { fromDate: fromDate, toDate: toDate };
@@ -323,6 +336,36 @@ const getColorAccordingToDate = (inputDate, period1 = 3, period2 = 6, period3 =
323
336
  return "#339900";
324
337
  };
325
338
  exports.getColorAccordingToDate = getColorAccordingToDate;
339
+ const getPeriodDateColor = (inputDate, period = 30) => {
340
+ const month0 = 0;
341
+ const month3 = period * 3;
342
+ const month6 = period * 6;
343
+ const month9 = period * 9;
344
+ const month12 = period * 12;
345
+ const today = (0, dayjs_1.default)(new Date());
346
+ const expDate = new Date(inputDate);
347
+ const diff = (0, dayjs_1.default)(expDate).diff(today, "day");
348
+ if (diff <= month0) {
349
+ // return "dark";
350
+ return "danger";
351
+ }
352
+ if (diff <= month3) {
353
+ return "danger";
354
+ }
355
+ if (diff <= month6) {
356
+ return "warning";
357
+ }
358
+ if (diff <= month9) {
359
+ return "purple";
360
+ }
361
+ if (diff <= month12) {
362
+ return "success";
363
+ }
364
+ if (diff > month12) {
365
+ return "info";
366
+ }
367
+ };
368
+ exports.getPeriodDateColor = getPeriodDateColor;
326
369
  const arrayMultiChecked = (objet, event, item) => {
327
370
  const findItem = objet.find((x) => x.id === item.id);
328
371
  event && !findItem ? objet.push(item) : objet.splice(objet.indexOf(findItem), 1);
@@ -22,7 +22,8 @@ export declare const removeDuplicates: (tab: any[]) => any[];
22
22
  * @param key
23
23
  * @returns
24
24
  */
25
- export declare const removeDuplicatesByKey: (tobs: any[], key: string) => any[];
25
+ export declare const removeDuplicatesByKey: (tobs: any[], property: string) => any[];
26
+ export declare const removeDuplicateObjects: (array: any[], property: string) => any[];
26
27
  export declare const toObjectDate: (fromDate: any, toDate: string) => {
27
28
  fromDate: any;
28
29
  toDate: string;
@@ -57,6 +58,7 @@ export declare const formatNgbDate: (date: any) => {
57
58
  };
58
59
  export declare const genRandomColour: () => string;
59
60
  export declare const getColorAccordingToDate: (inputDate: Date, period1?: number, period2?: number, period3?: number, ifClass?: boolean) => "red" | "DarkOrange" | "turquoise" | "blue" | "green" | "#f46a6a" | "#f1b44c" | "#cce5ff" | "#34c38f" | "#339900";
61
+ export declare const getPeriodDateColor: (inputDate: string, period?: number) => "danger" | "warning" | "purple" | "success" | "info";
60
62
  export declare const arrayMultiChecked: (objet: any[], event: boolean, item: any) => any[];
61
63
  export declare const inputChecked: (event: any, item: any, checks: any[], isChecked?: boolean) => any[];
62
64
  export declare const unCheckedAll: (checks?: any[]) => void;
package/lib/esm/utils.js CHANGED
@@ -101,8 +101,20 @@ export const removeDuplicates = (tab) => {
101
101
  * @param key
102
102
  * @returns
103
103
  */
104
- export const removeDuplicatesByKey = (tobs, key) => {
105
- return [...new Map(tobs.map((item) => [item[key], item])).values()];
104
+ export const removeDuplicatesByKey = (tobs, property) => {
105
+ return [...new Map(tobs.map((item) => [item[property], item])).values()];
106
+ };
107
+ export const removeDuplicateObjects = (array, property) => {
108
+ const uniqueIds = [];
109
+ const unique = array.filter((element) => {
110
+ const isDuplicate = uniqueIds.includes(element[property]);
111
+ if (!isDuplicate) {
112
+ uniqueIds.push(element[property]);
113
+ return true;
114
+ }
115
+ return false;
116
+ });
117
+ return unique;
106
118
  };
107
119
  export const toObjectDate = (fromDate, toDate) => {
108
120
  toDate = toDate !== "null" ? toDate : fromDate;
@@ -272,6 +284,35 @@ export const getColorAccordingToDate = (inputDate, period1 = 3, period2 = 6, per
272
284
  }
273
285
  return "#339900";
274
286
  };
287
+ export const getPeriodDateColor = (inputDate, period = 30) => {
288
+ const month0 = 0;
289
+ const month3 = period * 3;
290
+ const month6 = period * 6;
291
+ const month9 = period * 9;
292
+ const month12 = period * 12;
293
+ const today = dayjs(new Date());
294
+ const expDate = new Date(inputDate);
295
+ const diff = dayjs(expDate).diff(today, "day");
296
+ if (diff <= month0) {
297
+ // return "dark";
298
+ return "danger";
299
+ }
300
+ if (diff <= month3) {
301
+ return "danger";
302
+ }
303
+ if (diff <= month6) {
304
+ return "warning";
305
+ }
306
+ if (diff <= month9) {
307
+ return "purple";
308
+ }
309
+ if (diff <= month12) {
310
+ return "success";
311
+ }
312
+ if (diff > month12) {
313
+ return "info";
314
+ }
315
+ };
275
316
  export const arrayMultiChecked = (objet, event, item) => {
276
317
  const findItem = objet.find((x) => x.id === item.id);
277
318
  event && !findItem ? objet.push(item) : objet.splice(objet.indexOf(findItem), 1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "asv-hlps",
3
- "version": "1.2.92",
3
+ "version": "1.2.94",
4
4
  "description": "helpers",
5
5
  "main": "./lib/cjs/index.js",
6
6
  "module": "./lib/esm/index.js",