asv-hlps 1.0.4 → 1.0.7
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.
|
@@ -54,3 +54,6 @@ export declare const checked: (event: any, item: any, checks: string[], isChecke
|
|
|
54
54
|
export declare const unCheckedAll: (checks?: any[]) => void;
|
|
55
55
|
export declare const arrayMultiChecked: (objet: any[], event: boolean, item: any) => any[];
|
|
56
56
|
export declare const packAndUnit: (qtity: number, qtityPerPackaging?: number) => string;
|
|
57
|
+
export declare const convertToCfa: (price: number, currency?: string, dollarRate?: number) => number;
|
|
58
|
+
export declare const validEmail: (email: string) => boolean;
|
|
59
|
+
export declare const calculPercent: (nbr: number, percentage: number) => number;
|
package/lib/cjs/utils/shared.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.packAndUnit = exports.arrayMultiChecked = exports.unCheckedAll = exports.checked = 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.absFromSequence = exports.reformatDates = exports.formatToStringCfa = exports.formatToString = exports.wakeUp = exports.sleep = exports.limitTo = exports.titleCase = exports.toObjectDate = 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;
|
|
3
|
+
exports.calculPercent = exports.validEmail = exports.convertToCfa = exports.packAndUnit = exports.arrayMultiChecked = exports.unCheckedAll = exports.checked = 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.absFromSequence = exports.reformatDates = exports.formatToStringCfa = exports.formatToString = exports.wakeUp = exports.sleep = exports.limitTo = exports.titleCase = exports.toObjectDate = 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;
|
|
4
4
|
const formatDateYmdHypen = (date) => {
|
|
5
5
|
return (0, exports.formatDateYmd)(date, '-');
|
|
6
6
|
};
|
|
@@ -353,6 +353,7 @@ const convertToCfa = (price, currency = 'fcfa', dollarRate = 600) => {
|
|
|
353
353
|
return price;
|
|
354
354
|
}
|
|
355
355
|
};
|
|
356
|
+
exports.convertToCfa = convertToCfa;
|
|
356
357
|
const validEmail = (email) => {
|
|
357
358
|
// const regexEmail = '/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/'
|
|
358
359
|
if (email !== '' && email.toLowerCase().match(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/)) {
|
|
@@ -361,3 +362,8 @@ const validEmail = (email) => {
|
|
|
361
362
|
return false;
|
|
362
363
|
// return email.toLowerCase().match(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/)
|
|
363
364
|
};
|
|
365
|
+
exports.validEmail = validEmail;
|
|
366
|
+
const calculPercent = (nbr, percentage) => {
|
|
367
|
+
return nbr * percentage / 100;
|
|
368
|
+
};
|
|
369
|
+
exports.calculPercent = calculPercent;
|
|
@@ -54,3 +54,6 @@ export declare const checked: (event: any, item: any, checks: string[], isChecke
|
|
|
54
54
|
export declare const unCheckedAll: (checks?: any[]) => void;
|
|
55
55
|
export declare const arrayMultiChecked: (objet: any[], event: boolean, item: any) => any[];
|
|
56
56
|
export declare const packAndUnit: (qtity: number, qtityPerPackaging?: number) => string;
|
|
57
|
+
export declare const convertToCfa: (price: number, currency?: string, dollarRate?: number) => number;
|
|
58
|
+
export declare const validEmail: (email: string) => boolean;
|
|
59
|
+
export declare const calculPercent: (nbr: number, percentage: number) => number;
|
package/lib/esm/utils/shared.js
CHANGED
|
@@ -291,7 +291,7 @@ export const packAndUnit = (qtity, qtityPerPackaging = 0) => {
|
|
|
291
291
|
const unit = qtity % qtityPerPackaging;
|
|
292
292
|
return pack + ' c et ' + unit + ' u';
|
|
293
293
|
};
|
|
294
|
-
const convertToCfa = (price, currency = 'fcfa', dollarRate = 600) => {
|
|
294
|
+
export const convertToCfa = (price, currency = 'fcfa', dollarRate = 600) => {
|
|
295
295
|
switch (currency.toLowerCase()) {
|
|
296
296
|
case 'eur':
|
|
297
297
|
return price * 655.95;
|
|
@@ -303,7 +303,7 @@ const convertToCfa = (price, currency = 'fcfa', dollarRate = 600) => {
|
|
|
303
303
|
return price;
|
|
304
304
|
}
|
|
305
305
|
};
|
|
306
|
-
const validEmail = (email) => {
|
|
306
|
+
export const validEmail = (email) => {
|
|
307
307
|
// const regexEmail = '/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/'
|
|
308
308
|
if (email !== '' && email.toLowerCase().match(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/)) {
|
|
309
309
|
return true;
|
|
@@ -311,3 +311,6 @@ const validEmail = (email) => {
|
|
|
311
311
|
return false;
|
|
312
312
|
// return email.toLowerCase().match(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/)
|
|
313
313
|
};
|
|
314
|
+
export const calculPercent = (nbr, percentage) => {
|
|
315
|
+
return nbr * percentage / 100;
|
|
316
|
+
};
|
package/package.json
CHANGED
package/lib/esm/utils/util.d.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
export declare const formatDateYmdHypen: (date: Date | any) => string;
|
|
2
|
-
export declare const formatDateYmdHypenFr: (date: Date | any) => string;
|
|
3
|
-
export declare const formatDateFirstDayFr: (date: Date | any) => string;
|
|
4
|
-
export declare const formatDateYmHypen: (date: Date | any) => string;
|
|
5
|
-
export declare const formatFromAndToDate: (fromDate: Date, toDate: Date) => string;
|
|
6
|
-
export declare const formatDateYmd: (date: Date | any, separator?: string) => string;
|
|
7
|
-
export declare const formatDateYmFirstDay: (date: Date | any, separator?: string) => string;
|
|
8
|
-
export declare const formatDateYm: (date: Date | any, separator?: string) => string;
|
|
9
|
-
export declare const formatDateMd: (date: Date | any, separator?: string) => string;
|
|
10
|
-
export declare const convertEnDateToFr: (date: string, separator?: string) => string;
|
|
11
|
-
export declare const convertFrDateToEnDate: (date: string, separator?: string) => string;
|
|
12
|
-
export declare const genDateMinutesStep: (step: number, lang?: string) => string[];
|
|
13
|
-
export declare const percentOf: (nbr: number, percentage: number) => number;
|
|
14
|
-
export declare const calPercent: (nbr: number, percentage: number) => number;
|
|
15
|
-
export declare const displayDateRangeFr: (getFromDate?: any, getToDate?: any) => string;
|
|
16
|
-
export declare const getNbOfDaysBetweenTwoDates: (date1: Date, date2: Date) => number;
|
|
17
|
-
export declare const getRandomColor: (brightness: number) => string;
|
|
18
|
-
export declare const removeDuplicates: (tab: any[]) => any[];
|
|
19
|
-
export declare const toObjectDate: (fromDate: any, toDate: string) => {
|
|
20
|
-
fromDate: any;
|
|
21
|
-
toDate: string;
|
|
22
|
-
};
|
|
23
|
-
export declare const titleCase: (str: string) => string;
|
|
24
|
-
export declare const limitTo: (value: string, limit?: number, trail?: string) => string;
|
|
25
|
-
export declare const sleep: (ms: number) => Promise<unknown>;
|
|
26
|
-
export declare const wakeUp: (sleep: any) => void;
|
|
27
|
-
export declare const formatToString: (val: number, separator?: string, currency?: string) => string;
|
|
28
|
-
export declare const formatToStringCfa: (val: number) => string;
|
|
29
|
-
export declare const reformatDates: (fromDate: any, toDate: any) => {
|
|
30
|
-
fromDate: any;
|
|
31
|
-
toDate: any;
|
|
32
|
-
};
|
|
33
|
-
export declare const absFromSequence: (arr: number[]) => number[];
|
|
34
|
-
export declare const sequencesToNumbers: (arr: any[]) => number[];
|
|
35
|
-
export declare const findSequencesMissing: (arr: any[]) => number[];
|
|
36
|
-
export declare const fillNumWithZero: (num: number, targetLength: number) => string;
|
|
37
|
-
export declare const findFirstSequenceMissing: (arr: any[]) => number;
|
|
38
|
-
export declare const deepClone: (obj: any) => any;
|
|
39
|
-
export declare const removeString: (text: string, word: string) => string;
|
|
40
|
-
export declare const removeBackSlashOccurences: (text: string, toChar: string) => string;
|
|
41
|
-
export declare const genSequenceRef: (refs: any[], startChars: string, zeroFillWidth: number, dateFormat?: string) => string;
|
|
42
|
-
export declare const sesStorageSet: (key: string, val: any) => void;
|
|
43
|
-
export declare const sesStorageGet: (key: string) => any;
|
|
44
|
-
export declare const replaceAllIn: (text: string, regex?: RegExp, toChar?: string) => string;
|
|
45
|
-
export declare const replaceSpacesWith: (text: string, toChar?: string) => string;
|
|
46
|
-
export declare const dateToString: (date: Date | any) => string;
|
|
47
|
-
export declare const formatNgbDate: (date: any) => {
|
|
48
|
-
fromDate: string;
|
|
49
|
-
toDate: string;
|
|
50
|
-
};
|
|
51
|
-
export declare const genRandomColour: () => string;
|
|
52
|
-
export declare const getColorAccordingToDate: (inputDate: Date, period1?: number, period2?: number, period3?: number, ifClass?: boolean) => "red" | "DarkOrange" | "turquoise" | "blue" | "green" | "#f46a6a" | "#f1b44c" | "#cce5ff" | "#34c38f" | "#339900";
|
|
53
|
-
export declare const checked: (event: any, item: any, checks: string[], isChecked?: boolean) => string[];
|
|
54
|
-
export declare const unCheckedAll: (checks?: any[]) => void;
|
|
55
|
-
export declare const arrayMultiChecked: (objet: any[], event: boolean, item: any) => any[];
|
|
56
|
-
export declare const packAndUnit: (qtity: number, qtityPerPackaging?: number) => string;
|
package/lib/esm/utils/util.js
DELETED
|
@@ -1,313 +0,0 @@
|
|
|
1
|
-
export const formatDateYmdHypen = (date) => {
|
|
2
|
-
return formatDateYmd(date, '-');
|
|
3
|
-
};
|
|
4
|
-
export const formatDateYmdHypenFr = (date) => {
|
|
5
|
-
return convertEnDateToFr(formatDateYmd(date, '-'));
|
|
6
|
-
};
|
|
7
|
-
export const formatDateFirstDayFr = (date) => {
|
|
8
|
-
return (('0' + 1).slice(-2) +
|
|
9
|
-
'-' +
|
|
10
|
-
('0' + (date.getMonth() + 1)).slice(-2) +
|
|
11
|
-
'-' +
|
|
12
|
-
date.getUTCFullYear());
|
|
13
|
-
};
|
|
14
|
-
export const formatDateYmHypen = (date) => {
|
|
15
|
-
return formatDateYm(date, '-');
|
|
16
|
-
};
|
|
17
|
-
export const formatFromAndToDate = (fromDate, toDate) => {
|
|
18
|
-
const getFromDate = !fromDate ? new Date() : fromDate;
|
|
19
|
-
const getToDate = !toDate ? fromDate : toDate;
|
|
20
|
-
return formatDateYmdHypenFr(new Date(getFromDate)) + ' au ' + formatDateYmdHypenFr(new Date(getToDate));
|
|
21
|
-
};
|
|
22
|
-
export const formatDateYmd = (date, separator = '') => {
|
|
23
|
-
return formatDateYm(date, separator) + separator + ('0' + date.getUTCDate()).slice(-2);
|
|
24
|
-
};
|
|
25
|
-
export const formatDateYmFirstDay = (date, separator = '') => {
|
|
26
|
-
return formatDateYm(date, separator) + separator + ('0' + 1).slice(-2);
|
|
27
|
-
};
|
|
28
|
-
export const formatDateYm = (date, separator = '') => {
|
|
29
|
-
return date.getUTCFullYear() + separator + ('0' + (date.getMonth() + 1)).slice(-2);
|
|
30
|
-
};
|
|
31
|
-
export const formatDateMd = (date, separator = '') => {
|
|
32
|
-
// return ('0' + (date.getMonth() + 1)).slice(-2) + separator + ('0' + date.getUTCDate()).slice(-2);
|
|
33
|
-
return (date.getMonth() + 1) + separator + date.getUTCDate();
|
|
34
|
-
};
|
|
35
|
-
export const convertEnDateToFr = (date, separator = '-') => {
|
|
36
|
-
if (!date) {
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
date = date.trim();
|
|
40
|
-
const year = date.substring(0, 4);
|
|
41
|
-
const month = date.substring(5, 7);
|
|
42
|
-
const day = date.substring(8, 10);
|
|
43
|
-
return day + separator + month + separator + year;
|
|
44
|
-
};
|
|
45
|
-
export const convertFrDateToEnDate = (date, separator = '-') => {
|
|
46
|
-
if (!date) {
|
|
47
|
-
return null;
|
|
48
|
-
}
|
|
49
|
-
date = date.trim();
|
|
50
|
-
const day = date.substring(0, 2);
|
|
51
|
-
const month = date.substring(3, 5);
|
|
52
|
-
const year = date.substring(6, 10);
|
|
53
|
-
// return day + separator + month + separator + year
|
|
54
|
-
return year + separator + month + separator + day;
|
|
55
|
-
};
|
|
56
|
-
export const genDateMinutesStep = (step, lang = 'fr-FR') => {
|
|
57
|
-
const date = new Date(2021, 0, 1);
|
|
58
|
-
const series = [];
|
|
59
|
-
while (date.getDate() === 1) {
|
|
60
|
-
series.push(date.toLocaleTimeString(lang).replace(/(.*)\D\d+/, '$1')); // without seconds
|
|
61
|
-
date.setMinutes(date.getMinutes() + step);
|
|
62
|
-
}
|
|
63
|
-
return series;
|
|
64
|
-
};
|
|
65
|
-
export const percentOf = (nbr, percentage) => {
|
|
66
|
-
return nbr * percentage / 100;
|
|
67
|
-
};
|
|
68
|
-
export const calPercent = (nbr, percentage) => {
|
|
69
|
-
if (!nbr) {
|
|
70
|
-
return null;
|
|
71
|
-
}
|
|
72
|
-
if (!percentage) {
|
|
73
|
-
return nbr;
|
|
74
|
-
}
|
|
75
|
-
return nbr + (nbr * percentage / 100);
|
|
76
|
-
};
|
|
77
|
-
export const displayDateRangeFr = (getFromDate, getToDate) => {
|
|
78
|
-
const fromDate = !getFromDate ? new Date() : getFromDate;
|
|
79
|
-
const toDate = !getToDate ? fromDate : getToDate;
|
|
80
|
-
return formatDateYmdHypenFr(new Date(fromDate)) + ' au ' + formatDateYmdHypenFr(new Date(toDate));
|
|
81
|
-
};
|
|
82
|
-
export const getNbOfDaysBetweenTwoDates = (date1, date2) => {
|
|
83
|
-
const day = 1000 * 60 * 60 * 24;
|
|
84
|
-
const diff = Math.abs(date2.getTime() - date1.getTime());
|
|
85
|
-
return Math.ceil(diff / day);
|
|
86
|
-
};
|
|
87
|
-
export const getRandomColor = (brightness) => {
|
|
88
|
-
// Six levels of brightness from 0 to 5, 0 being the darkest
|
|
89
|
-
const rgb = [Math.random() * 256, Math.random() * 256, Math.random() * 256];
|
|
90
|
-
const mix = [brightness * 51, brightness * 51, brightness * 51]; // 51 => 255/5
|
|
91
|
-
const mixedrgb = [rgb[0] + mix[0], rgb[1] + mix[1], rgb[2] + mix[2]].map(function (x) { return Math.round(x / 2.0); });
|
|
92
|
-
return 'rgb(' + mixedrgb.join(',') + ')';
|
|
93
|
-
};
|
|
94
|
-
export const removeDuplicates = (tab) => {
|
|
95
|
-
return tab.filter((v, i, a) => a.findIndex(t => (t.id === v.id && t.name === v.name)) === i);
|
|
96
|
-
};
|
|
97
|
-
export const toObjectDate = (fromDate, toDate) => {
|
|
98
|
-
toDate = (toDate !== 'null') ? toDate : fromDate;
|
|
99
|
-
return { fromDate: fromDate, toDate: toDate };
|
|
100
|
-
};
|
|
101
|
-
export const titleCase = (str) => {
|
|
102
|
-
return str.trim()
|
|
103
|
-
.toLowerCase()
|
|
104
|
-
.split(' ')
|
|
105
|
-
// .map(function(word: string | string[]) => {
|
|
106
|
-
.map(function (word) {
|
|
107
|
-
return word.replace(word[0], word[0].toUpperCase());
|
|
108
|
-
})
|
|
109
|
-
.join(' ');
|
|
110
|
-
};
|
|
111
|
-
export const limitTo = (value, limit = 15, trail = '') => {
|
|
112
|
-
// const limit = args ? parseInt(args, 10) : 10;
|
|
113
|
-
// const trail = '...';
|
|
114
|
-
return value.length > limit ? value.substring(0, limit) + trail : value;
|
|
115
|
-
};
|
|
116
|
-
export const sleep = (ms) => {
|
|
117
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
118
|
-
};
|
|
119
|
-
export const wakeUp = (sleep) => {
|
|
120
|
-
clearInterval(sleep);
|
|
121
|
-
};
|
|
122
|
-
export const formatToString = (val, separator = ' ', currency = '') => {
|
|
123
|
-
// return String(val).replace(/(.)(?=(\d{3})+$)/g, '$1,');
|
|
124
|
-
return String(val).replace(/(.)(?=(\d{3})+$)/g, '$1' + separator + '') + currency;
|
|
125
|
-
};
|
|
126
|
-
export const formatToStringCfa = (val) => {
|
|
127
|
-
// return String(val).replace(/(.)(?=(\d{3})+$)/g, '$1 ') + ' CFA';
|
|
128
|
-
return formatToString(val, ' ', ' CFA');
|
|
129
|
-
};
|
|
130
|
-
// const = reformatDates(fromDate: string, toDate: string) => {
|
|
131
|
-
export const reformatDates = (fromDate, toDate) => {
|
|
132
|
-
if (fromDate === undefined || fromDate === null) {
|
|
133
|
-
return null;
|
|
134
|
-
}
|
|
135
|
-
toDate = (!toDate) ? fromDate : toDate;
|
|
136
|
-
return { fromDate, toDate };
|
|
137
|
-
};
|
|
138
|
-
export const absFromSequence = (arr) => {
|
|
139
|
-
const [min, max] = [Math.min(...arr), Math.max(...arr)];
|
|
140
|
-
// let out = Array.from(Array(max - min), (v, i) => i + min).filter((i) => !arr.includes(i));
|
|
141
|
-
return Array.from(Array(max - min), (v, i) => i + min).filter((i) => !arr.includes(i));
|
|
142
|
-
};
|
|
143
|
-
export const sequencesToNumbers = (arr) => {
|
|
144
|
-
const seqs = [];
|
|
145
|
-
for (const item of arr) {
|
|
146
|
-
seqs.push(+(Object.values(item)));
|
|
147
|
-
}
|
|
148
|
-
return seqs;
|
|
149
|
-
};
|
|
150
|
-
export const findSequencesMissing = (arr) => {
|
|
151
|
-
const seqs = [];
|
|
152
|
-
for (const item of arr) {
|
|
153
|
-
seqs.push(+(Object.values(item)));
|
|
154
|
-
}
|
|
155
|
-
return absFromSequence(seqs);
|
|
156
|
-
};
|
|
157
|
-
export const fillNumWithZero = (num, targetLength) => {
|
|
158
|
-
return num.toString().padStart(targetLength, '0');
|
|
159
|
-
};
|
|
160
|
-
export const findFirstSequenceMissing = (arr) => {
|
|
161
|
-
/* const seqs: number[] = [];
|
|
162
|
-
for (const item of arr) => {
|
|
163
|
-
seqs.push(+ (Object.values(item)))
|
|
164
|
-
} */
|
|
165
|
-
return findSequencesMissing(arr)[0];
|
|
166
|
-
};
|
|
167
|
-
export const deepClone = (obj) => {
|
|
168
|
-
return JSON.parse(JSON.stringify(obj));
|
|
169
|
-
};
|
|
170
|
-
export const removeString = (text, word) => {
|
|
171
|
-
return text.toLowerCase().replace(word.toLowerCase(), '') || text;
|
|
172
|
-
};
|
|
173
|
-
export const removeBackSlashOccurences = (text, toChar) => {
|
|
174
|
-
const regex = /\/+/gi;
|
|
175
|
-
return String(text).toLowerCase().replace(regex, toChar) || text;
|
|
176
|
-
};
|
|
177
|
-
export const genSequenceRef = (refs, startChars, zeroFillWidth, dateFormat = '') => {
|
|
178
|
-
if (!refs.length) {
|
|
179
|
-
return startChars + dateFormat + fillNumWithZero(1, zeroFillWidth);
|
|
180
|
-
}
|
|
181
|
-
else {
|
|
182
|
-
const seqs = sequencesToNumbers(refs);
|
|
183
|
-
const missingSequences = absFromSequence(seqs);
|
|
184
|
-
if (!missingSequences.length) {
|
|
185
|
-
/* if(seqs.length === 1) => {
|
|
186
|
-
return startChars + fillNumWithZero((+seqs[0] + 1 ), zeroFillWidth); // get the last item of the array and incremente
|
|
187
|
-
} else { */
|
|
188
|
-
if (seqs[0] !== 1) {
|
|
189
|
-
return startChars + dateFormat + fillNumWithZero(1, zeroFillWidth);
|
|
190
|
-
}
|
|
191
|
-
else {
|
|
192
|
-
return startChars + dateFormat + fillNumWithZero((seqs[seqs.length - 1] + 1), zeroFillWidth); // get the last item of the array
|
|
193
|
-
}
|
|
194
|
-
// }
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
197
|
-
return startChars + dateFormat + fillNumWithZero(missingSequences[0], zeroFillWidth);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
};
|
|
201
|
-
export const sesStorageSet = (key, val) => {
|
|
202
|
-
sessionStorage.setItem(key, JSON.stringify(val));
|
|
203
|
-
};
|
|
204
|
-
export const sesStorageGet = (key) => {
|
|
205
|
-
return JSON.parse(sessionStorage.getItem(key));
|
|
206
|
-
};
|
|
207
|
-
export const replaceAllIn = (text, regex = / /g, toChar = '_') => {
|
|
208
|
-
return text.replace(regex, toChar) || text;
|
|
209
|
-
};
|
|
210
|
-
export const replaceSpacesWith = (text, toChar = '_') => {
|
|
211
|
-
return text.replace(/\s/g, toChar) || text;
|
|
212
|
-
};
|
|
213
|
-
export const dateToString = (date) => {
|
|
214
|
-
return date.year + '-' + ('0' + date.month).slice(-2) + '-' + ('0' + date.day).slice(-2);
|
|
215
|
-
};
|
|
216
|
-
// export const formatNgbDate = (date: DateSelected) => {
|
|
217
|
-
export const formatNgbDate = (date) => {
|
|
218
|
-
const fromDate = (date.fromDate) ? dateToString(date.fromDate) : null;
|
|
219
|
-
const toDate = (date.toDate) ? dateToString(date.toDate) : null;
|
|
220
|
-
return { fromDate: fromDate, toDate: toDate };
|
|
221
|
-
};
|
|
222
|
-
export const genRandomColour = () => {
|
|
223
|
-
return "#" + Math.floor(Math.random() * 16777215).toString(16);
|
|
224
|
-
};
|
|
225
|
-
export const getColorAccordingToDate = (inputDate, period1 = 3, period2 = 6, period3 = 9, ifClass) => {
|
|
226
|
-
const date = new Date();
|
|
227
|
-
const date2 = new Date(inputDate);
|
|
228
|
-
const diffNumber = Math.ceil(getNbOfDaysBetweenTwoDates(date2, date));
|
|
229
|
-
period1 = period1 * 30;
|
|
230
|
-
period2 = period2 * 30;
|
|
231
|
-
period3 = period3 * 30;
|
|
232
|
-
if (ifClass) {
|
|
233
|
-
if (diffNumber <= period1) {
|
|
234
|
-
return 'red';
|
|
235
|
-
}
|
|
236
|
-
else if (diffNumber > period1 && diffNumber <= period2) {
|
|
237
|
-
return 'DarkOrange';
|
|
238
|
-
}
|
|
239
|
-
else if (diffNumber > period2 && diffNumber <= period3) {
|
|
240
|
-
return 'turquoise';
|
|
241
|
-
}
|
|
242
|
-
else if (diffNumber > period3) {
|
|
243
|
-
return 'blue';
|
|
244
|
-
}
|
|
245
|
-
return 'green';
|
|
246
|
-
}
|
|
247
|
-
if (diffNumber <= period1) {
|
|
248
|
-
// return '#cc3300';
|
|
249
|
-
return '#f46a6a';
|
|
250
|
-
}
|
|
251
|
-
else if (diffNumber > period1 && diffNumber <= period2) {
|
|
252
|
-
// return '#fff3cd';
|
|
253
|
-
return '#f1b44c';
|
|
254
|
-
}
|
|
255
|
-
else if (diffNumber > period2 && diffNumber <= period3) {
|
|
256
|
-
return '#cce5ff';
|
|
257
|
-
}
|
|
258
|
-
else if (diffNumber > period3) {
|
|
259
|
-
// return '#339900';
|
|
260
|
-
return '#34c38f';
|
|
261
|
-
}
|
|
262
|
-
return '#339900';
|
|
263
|
-
};
|
|
264
|
-
export const checked = (event, item, checks, isChecked = true) => {
|
|
265
|
-
// let isChecked = true;
|
|
266
|
-
const evt = event.target.checked;
|
|
267
|
-
checks = arrayMultiChecked(checks, evt, item);
|
|
268
|
-
// (checks.length) ? isChecked = true : isChecked = false;
|
|
269
|
-
isChecked = (checks.length) ? true : false;
|
|
270
|
-
return checks;
|
|
271
|
-
};
|
|
272
|
-
export const unCheckedAll = (checks) => {
|
|
273
|
-
const checkeds = document.querySelectorAll("input");
|
|
274
|
-
checkeds.forEach((el) => {
|
|
275
|
-
if (el.checked) {
|
|
276
|
-
el.checked = false;
|
|
277
|
-
}
|
|
278
|
-
});
|
|
279
|
-
checks = [];
|
|
280
|
-
};
|
|
281
|
-
export const arrayMultiChecked = (objet, event, item) => {
|
|
282
|
-
const findItem = objet.find(x => x.id === item.id);
|
|
283
|
-
event && !findItem ? objet.push(item) : objet.splice(objet.indexOf(findItem), 1);
|
|
284
|
-
return objet;
|
|
285
|
-
};
|
|
286
|
-
export const packAndUnit = (qtity, qtityPerPackaging = 0) => {
|
|
287
|
-
if (qtityPerPackaging === 0) {
|
|
288
|
-
return qtity + ' u';
|
|
289
|
-
}
|
|
290
|
-
const pack = Math.floor(qtity / qtityPerPackaging);
|
|
291
|
-
const unit = qtity % qtityPerPackaging;
|
|
292
|
-
return pack + ' c et ' + unit + ' u';
|
|
293
|
-
};
|
|
294
|
-
const convertToCfa = (price, currency = 'fcfa', dollarRate = 600) => {
|
|
295
|
-
switch (currency.toLowerCase()) {
|
|
296
|
-
case 'eur':
|
|
297
|
-
return price * 655.95;
|
|
298
|
-
case 'usd':
|
|
299
|
-
return price * dollarRate; //579.50
|
|
300
|
-
case 'fcfa':
|
|
301
|
-
return price;
|
|
302
|
-
default:
|
|
303
|
-
return price;
|
|
304
|
-
}
|
|
305
|
-
};
|
|
306
|
-
const validEmail = (email) => {
|
|
307
|
-
// const regexEmail = '/^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/'
|
|
308
|
-
if (email !== '' && email.toLowerCase().match(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/)) {
|
|
309
|
-
return true;
|
|
310
|
-
}
|
|
311
|
-
return false;
|
|
312
|
-
// return email.toLowerCase().match(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/)
|
|
313
|
-
};
|