asv-hlps 1.4.18 → 1.4.20
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/lib/cjs/utils.d.ts +4 -1
- package/lib/cjs/utils.js +32 -2
- package/lib/esm/utils.d.ts +4 -1
- package/lib/esm/utils.js +27 -0
- package/package.json +1 -1
package/lib/cjs/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ConfigType, OpUnitType, QUnitType } from "dayjs";
|
|
1
|
+
import dayjs, { ConfigType, OpUnitType, QUnitType } from "dayjs";
|
|
2
2
|
import "dayjs/locale/fr";
|
|
3
3
|
export declare const isEmpty: (str: string) => str is "";
|
|
4
4
|
export declare const formatDateFirstDayFr: (date: Date | any) => string;
|
|
@@ -46,6 +46,8 @@ export declare const toPlural: (word: string) => string;
|
|
|
46
46
|
export declare const replaceAllIn: (text: string, regex?: RegExp, toChar?: string) => string;
|
|
47
47
|
export declare const replaceSpacesWith: (text: string, toChar?: string) => string;
|
|
48
48
|
export declare const dateFormatter: (date: Date | string, format?: "y" | "ym" | "ymd" | "dmy" | "ago" | "md" | "dmy-hm" | "dmyfr" | "myfr" | "mfr-short" | "mfr-long", separator?: "/" | "" | "-") => string;
|
|
49
|
+
export declare const getNthWeek: (startDate: Date | string, endDate: Date | string, nthWeek: number) => dayjs.Dayjs;
|
|
50
|
+
export declare const dateNthWeek: (startDate: Date | string, endDate: Date | string, nthWeek: number) => number;
|
|
49
51
|
export declare const dateDiff: (date1: ConfigType, unit?: QUnitType | OpUnitType, date2?: Date) => number;
|
|
50
52
|
export declare const dateToString: (date: Date | any) => string;
|
|
51
53
|
export declare const firstDayOfDate: (date: Date | any) => string;
|
|
@@ -79,6 +81,7 @@ export declare const isBirthday: (birthDayDate: any) => boolean;
|
|
|
79
81
|
export declare const insertAtInArray: (array: any[], index: number, ...elements: any) => void;
|
|
80
82
|
export declare const randomInteger: (max: number) => number;
|
|
81
83
|
export declare const randomRgbColor: () => number[];
|
|
84
|
+
export declare const genRandomNumberArray: (nbSize: number) => number[];
|
|
82
85
|
export declare const randomHexColor: () => string;
|
|
83
86
|
export declare const randomHslColor: () => number[];
|
|
84
87
|
export declare const getArrayOfRandomColor: (length: number, type?: "hex" | "rgb" | "hsl") => string[];
|
package/lib/cjs/utils.js
CHANGED
|
@@ -3,13 +3,17 @@ 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.
|
|
7
|
-
exports.checkObjInArray = exports.arraySome = exports.winMaxHeight = exports.toggleProp = exports.roundLastNDigits = exports.removeParamKeyName = exports.countryIsoToFlag = exports.monthStringName = exports.returnBool = exports.formatAmountToString = exports.reduceTimes = 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 = exports.packAndUnit = void 0;
|
|
6
|
+
exports.arrayMultiChecked = exports.getPeriodDateColor = exports.getColorAccordingToDate = exports.genRandomColour = exports.formatNgbDate = exports.getNbOfDaysBetweenTwoDates = exports.displayDateRangeFr = exports.reformatDates = exports.firstDayOfDate = exports.dateToString = exports.dateDiff = exports.dateNthWeek = exports.getNthWeek = exports.dateFormatter = exports.replaceSpacesWith = exports.replaceAllIn = exports.toPlural = exports.sesStorageGet = exports.sesStorageSet = exports.genSequenceRef = exports.refGenerator = exports.removeBackSlashOccurences = exports.stringifyFormatter = 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.checkAuth = exports.wakeUp = exports.sleep = exports.limitTo = exports.titleCase = exports.toObjectDate = exports.duplicateObjects = exports.removeDuplicateObjects = exports.getRandomColor = exports.calPercent = exports.percentOf = exports.genDateMinutesStep = exports.formatDateFirstDayFr = exports.isEmpty = void 0;
|
|
7
|
+
exports.checkObjInArray = exports.arraySome = exports.winMaxHeight = exports.toggleProp = exports.roundLastNDigits = exports.removeParamKeyName = exports.countryIsoToFlag = exports.monthStringName = exports.returnBool = exports.formatAmountToString = exports.reduceTimes = exports.reduceSum = exports.sumAmount = exports.fillEndWithZero = exports.fillStartWithZero = exports.absFromSequence = exports.returnDates = exports.displayFrDatePeriode = exports.getArrayOfRandomColor = exports.randomHslColor = exports.randomHexColor = exports.genRandomNumberArray = exports.randomRgbColor = exports.randomInteger = exports.insertAtInArray = exports.isBirthday = exports.padEndWithZero = exports.padStartWithZero = exports.formatMonthYearToLocaleString = exports.calculPercent = exports.validEmail = exports.convertToCfa = exports.packAndUnit = exports.unCheckedAll = exports.inputChecked = void 0;
|
|
8
8
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
9
|
+
const isSameOrBefore_1 = __importDefault(require("dayjs/plugin/isSameOrBefore"));
|
|
9
10
|
const relativeTime_1 = __importDefault(require("dayjs/plugin/relativeTime"));
|
|
11
|
+
const weekOfYear_1 = __importDefault(require("dayjs/plugin/weekOfYear"));
|
|
10
12
|
const lodash_1 = __importDefault(require("lodash"));
|
|
11
13
|
require("dayjs/locale/fr");
|
|
12
14
|
dayjs_1.default.extend(relativeTime_1.default);
|
|
15
|
+
dayjs_1.default.extend(weekOfYear_1.default);
|
|
16
|
+
dayjs_1.default.extend(isSameOrBefore_1.default);
|
|
13
17
|
// require("dayjs/locale/fr");
|
|
14
18
|
/* start: dates -------------------------------------- */
|
|
15
19
|
/* end: dates ---------------------------------------- */
|
|
@@ -359,6 +363,21 @@ const dateFormatter = (date, format = "dmy", separator = "/") => {
|
|
|
359
363
|
}
|
|
360
364
|
};
|
|
361
365
|
exports.dateFormatter = dateFormatter;
|
|
366
|
+
const getNthWeek = (startDate, endDate, nthWeek) => {
|
|
367
|
+
let currentDate = (0, dayjs_1.default)(startDate);
|
|
368
|
+
let weeks = [];
|
|
369
|
+
while (currentDate.isSameOrBefore(endDate)) {
|
|
370
|
+
weeks.push(currentDate);
|
|
371
|
+
currentDate = currentDate.add(1, "week");
|
|
372
|
+
}
|
|
373
|
+
return weeks[nthWeek - 1];
|
|
374
|
+
};
|
|
375
|
+
exports.getNthWeek = getNthWeek;
|
|
376
|
+
const dateNthWeek = (startDate, endDate, nthWeek) => {
|
|
377
|
+
const week = (0, exports.getNthWeek)(startDate, endDate, nthWeek);
|
|
378
|
+
return (0, dayjs_1.default)(week.format("YYYY-MM-DD")).week();
|
|
379
|
+
};
|
|
380
|
+
exports.dateNthWeek = dateNthWeek;
|
|
362
381
|
const dateDiff = (date1, unit = "year", date2 = new Date()) => {
|
|
363
382
|
return (0, dayjs_1.default)(date2).diff(date1, unit);
|
|
364
383
|
};
|
|
@@ -598,6 +617,17 @@ const randomRgbColor = () => {
|
|
|
598
617
|
return [r, g, b];
|
|
599
618
|
};
|
|
600
619
|
exports.randomRgbColor = randomRgbColor;
|
|
620
|
+
const genRandomNumberArray = (nbSize) => {
|
|
621
|
+
const numbers = [];
|
|
622
|
+
while (numbers.length < nbSize) {
|
|
623
|
+
const random = Math.floor(Math.random() * nbSize) + 1;
|
|
624
|
+
if (numbers.indexOf(random) === -1) {
|
|
625
|
+
numbers.push(random);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
return numbers;
|
|
629
|
+
};
|
|
630
|
+
exports.genRandomNumberArray = genRandomNumberArray;
|
|
601
631
|
const randomHexColor = () => {
|
|
602
632
|
let [r, g, b] = (0, exports.randomRgbColor)();
|
|
603
633
|
let hr = r.toString(16).padStart(2, "0");
|
package/lib/esm/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ConfigType, OpUnitType, QUnitType } from "dayjs";
|
|
1
|
+
import dayjs, { ConfigType, OpUnitType, QUnitType } from "dayjs";
|
|
2
2
|
import "dayjs/locale/fr";
|
|
3
3
|
export declare const isEmpty: (str: string) => str is "";
|
|
4
4
|
export declare const formatDateFirstDayFr: (date: Date | any) => string;
|
|
@@ -46,6 +46,8 @@ export declare const toPlural: (word: string) => string;
|
|
|
46
46
|
export declare const replaceAllIn: (text: string, regex?: RegExp, toChar?: string) => string;
|
|
47
47
|
export declare const replaceSpacesWith: (text: string, toChar?: string) => string;
|
|
48
48
|
export declare const dateFormatter: (date: Date | string, format?: "y" | "ym" | "ymd" | "dmy" | "ago" | "md" | "dmy-hm" | "dmyfr" | "myfr" | "mfr-short" | "mfr-long", separator?: "/" | "" | "-") => string;
|
|
49
|
+
export declare const getNthWeek: (startDate: Date | string, endDate: Date | string, nthWeek: number) => dayjs.Dayjs;
|
|
50
|
+
export declare const dateNthWeek: (startDate: Date | string, endDate: Date | string, nthWeek: number) => number;
|
|
49
51
|
export declare const dateDiff: (date1: ConfigType, unit?: QUnitType | OpUnitType, date2?: Date) => number;
|
|
50
52
|
export declare const dateToString: (date: Date | any) => string;
|
|
51
53
|
export declare const firstDayOfDate: (date: Date | any) => string;
|
|
@@ -79,6 +81,7 @@ export declare const isBirthday: (birthDayDate: any) => boolean;
|
|
|
79
81
|
export declare const insertAtInArray: (array: any[], index: number, ...elements: any) => void;
|
|
80
82
|
export declare const randomInteger: (max: number) => number;
|
|
81
83
|
export declare const randomRgbColor: () => number[];
|
|
84
|
+
export declare const genRandomNumberArray: (nbSize: number) => number[];
|
|
82
85
|
export declare const randomHexColor: () => string;
|
|
83
86
|
export declare const randomHslColor: () => number[];
|
|
84
87
|
export declare const getArrayOfRandomColor: (length: number, type?: "hex" | "rgb" | "hsl") => string[];
|
package/lib/esm/utils.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import dayjs from "dayjs";
|
|
2
|
+
import isSameOrBefore from "dayjs/plugin/isSameOrBefore";
|
|
2
3
|
import relativeTime from "dayjs/plugin/relativeTime";
|
|
4
|
+
import weekOfYear from "dayjs/plugin/weekOfYear";
|
|
3
5
|
import lodash from "lodash";
|
|
4
6
|
import "dayjs/locale/fr";
|
|
5
7
|
dayjs.extend(relativeTime);
|
|
8
|
+
dayjs.extend(weekOfYear);
|
|
9
|
+
dayjs.extend(isSameOrBefore);
|
|
6
10
|
// require("dayjs/locale/fr");
|
|
7
11
|
/* start: dates -------------------------------------- */
|
|
8
12
|
/* end: dates ---------------------------------------- */
|
|
@@ -315,6 +319,19 @@ export const dateFormatter = (date, format = "dmy", separator = "/") => {
|
|
|
315
319
|
// return dayjs(date).format(`YYYY${separator}MM${separator}DD`);
|
|
316
320
|
}
|
|
317
321
|
};
|
|
322
|
+
export const getNthWeek = (startDate, endDate, nthWeek) => {
|
|
323
|
+
let currentDate = dayjs(startDate);
|
|
324
|
+
let weeks = [];
|
|
325
|
+
while (currentDate.isSameOrBefore(endDate)) {
|
|
326
|
+
weeks.push(currentDate);
|
|
327
|
+
currentDate = currentDate.add(1, "week");
|
|
328
|
+
}
|
|
329
|
+
return weeks[nthWeek - 1];
|
|
330
|
+
};
|
|
331
|
+
export const dateNthWeek = (startDate, endDate, nthWeek) => {
|
|
332
|
+
const week = getNthWeek(startDate, endDate, nthWeek);
|
|
333
|
+
return dayjs(week.format("YYYY-MM-DD")).week();
|
|
334
|
+
};
|
|
318
335
|
export const dateDiff = (date1, unit = "year", date2 = new Date()) => {
|
|
319
336
|
return dayjs(date2).diff(date1, unit);
|
|
320
337
|
};
|
|
@@ -530,6 +547,16 @@ export const randomRgbColor = () => {
|
|
|
530
547
|
let b = randomInteger(255);
|
|
531
548
|
return [r, g, b];
|
|
532
549
|
};
|
|
550
|
+
export const genRandomNumberArray = (nbSize) => {
|
|
551
|
+
const numbers = [];
|
|
552
|
+
while (numbers.length < nbSize) {
|
|
553
|
+
const random = Math.floor(Math.random() * nbSize) + 1;
|
|
554
|
+
if (numbers.indexOf(random) === -1) {
|
|
555
|
+
numbers.push(random);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
return numbers;
|
|
559
|
+
};
|
|
533
560
|
export const randomHexColor = () => {
|
|
534
561
|
let [r, g, b] = randomRgbColor();
|
|
535
562
|
let hr = r.toString(16).padStart(2, "0");
|