topkat-utils 1.0.34 → 1.0.37
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/CHANGELOG.md +7 -0
- package/package.json +1 -1
- package/utils.d.ts +34 -91
- package/utils.js +20 -215
- package/utils.js.map +1 -1
- package/utils.ts +36 -258
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/utils.d.ts
CHANGED
|
@@ -5,6 +5,9 @@ declare const arrayUniqueValue: typeof noDuplicateFilter;
|
|
|
5
5
|
declare const JSONstringyParse: (o: any) => any;
|
|
6
6
|
declare const removeUndefinedKeys: typeof objFilterUndefinedRecursive;
|
|
7
7
|
declare type Color = [number, number, number];
|
|
8
|
+
declare type ObjectGeneric = {
|
|
9
|
+
[k: string]: any;
|
|
10
|
+
};
|
|
8
11
|
declare type BaseTypes = 'objectId' | 'dateInt6' | 'dateInt' | 'dateInt8' | 'dateInt12' | 'time' | 'humanReadableTimestamp' | 'date' | 'dateObject' | 'array' | 'object' | 'buffer' | 'string' | 'function' | 'boolean' | 'number' | 'bigint' | 'year' | 'email';
|
|
9
12
|
/** Round with custom number of decimals (default:0) */
|
|
10
13
|
declare function round(number: number, decimals?: number): number;
|
|
@@ -23,7 +26,7 @@ declare function moyenne(array: number[], nbOfDecimals?: number): number;
|
|
|
23
26
|
/** Clean output for outside world. All undefined / null / NaN / Infinity values are changed to '-' */
|
|
24
27
|
declare function cln(val: any, replacerInCaseItIsUndefinNaN?: string): any;
|
|
25
28
|
/** length default 2, shortcut for 1 to 01 */
|
|
26
|
-
declare function pad(numberOrStr:
|
|
29
|
+
declare function pad(numberOrStr: number | string, length?: number): string;
|
|
27
30
|
/** return the number or the closest number of the range
|
|
28
31
|
* * nb min max => returns
|
|
29
32
|
* * 7 5 10 => 7 // in the range
|
|
@@ -31,19 +34,20 @@ declare function pad(numberOrStr: any, length?: number): string;
|
|
|
31
34
|
* * 99 5 10 => 10// above the max value
|
|
32
35
|
*/
|
|
33
36
|
declare function minMax(nb: number, min: number, max: number): number;
|
|
34
|
-
declare function tryCatch(callback:
|
|
37
|
+
declare function tryCatch(callback: Function, onErr?: Function): Promise<any>;
|
|
35
38
|
/** minLength 8 if unique
|
|
36
39
|
* @param {Number} length default: 20
|
|
37
40
|
* @param {Boolean} unique default: true. Generate a real unique token base on the date. min length will be min 8 in this case
|
|
38
41
|
* @param {string} mode one of ['alphanumeric', 'hexadecimal']
|
|
39
42
|
* NOTE: to generate a mongoDB Random Id, use the params: 24, true, 'hexadecimal'
|
|
40
43
|
*/
|
|
41
|
-
declare function generateToken(length?: number, unique?: boolean, mode?:
|
|
44
|
+
declare function generateToken(length?: number, unique?: boolean, mode?: 'alphanumeric' | 'hexadecimal'): any;
|
|
45
|
+
declare function generateObjectId(): any;
|
|
42
46
|
/** Useful to join differents bits of url with normalizing slashes
|
|
43
47
|
* * urlPathJoin('https://', 'www.kikou.lol/', '/user', '//2//') => https://www.kikou.lol/user/2/
|
|
44
48
|
* * urlPathJoin('http:/', 'kikou.lol') => https://www.kikou.lol
|
|
45
49
|
*/
|
|
46
|
-
declare function urlPathJoin(...bits:
|
|
50
|
+
declare function urlPathJoin(...bits: string[]): string;
|
|
47
51
|
/** path shall always be sorted before using in express
|
|
48
52
|
* to avoid a generic route like /* to catch a specific one like /bonjour
|
|
49
53
|
*
|
|
@@ -52,15 +56,18 @@ declare function urlPathJoin(...bits: any[]): string;
|
|
|
52
56
|
* @return {Array} urls modified
|
|
53
57
|
*/
|
|
54
58
|
declare function sortUrlsByDeepnessInArrayOrObject(urlObjOrArr: any, propInObjectOrIndexInArray: any): any;
|
|
55
|
-
|
|
56
|
-
|
|
59
|
+
declare type MiniTemplaterOptions = {
|
|
60
|
+
valueWhenNotSet?: string;
|
|
61
|
+
regexp?: RegExp;
|
|
62
|
+
};
|
|
63
|
+
/** Replace variables in a string like: `Hello {{userName}}!`
|
|
57
64
|
* @param {String} content
|
|
58
65
|
* @param {Object} varz object with key => value === toReplace => replacer
|
|
59
66
|
* @param {Object} options
|
|
60
67
|
* * valueWhenNotSet => replacer for undefined values. Default: ''
|
|
61
68
|
* * regexp => must be 'g' and first capturing group matching the value to replace. Default: /{{\s*([^}]*)\s*}}/g
|
|
62
69
|
*/
|
|
63
|
-
declare function miniTemplater(content:
|
|
70
|
+
declare function miniTemplater(content: string, varz: ObjectGeneric, options?: MiniTemplaterOptions): string;
|
|
64
71
|
/**
|
|
65
72
|
*
|
|
66
73
|
* @param {Object} object main object
|
|
@@ -68,7 +75,7 @@ declare function miniTemplater(content: any, varz: any, options: any): any;
|
|
|
68
75
|
* @param {Boolean} isMask default: true; determine the behavior of the function. If is mask, selected fields will not appear in the resulting object. If it's a select, only selected fields will appear.
|
|
69
76
|
* @param {Boolean} deleteKeysInsteadOfReturningAnewObject default:false; modify the existing object instead of creating a new instance
|
|
70
77
|
*/
|
|
71
|
-
declare function simpleObjectMaskOrSelect(object:
|
|
78
|
+
declare function simpleObjectMaskOrSelect(object: ObjectGeneric, maskedOrSelectedFields: string[], isMask?: boolean, deleteKeysInsteadOfReturningAnewObject?: boolean): ObjectGeneric;
|
|
72
79
|
/** READ ONLY, output a parsed version of process.env
|
|
73
80
|
* use it like ENV().myVar
|
|
74
81
|
*/
|
|
@@ -128,23 +135,23 @@ declare function registerConfig(customConfig: any): void;
|
|
|
128
135
|
* @param {Object} obj object to test against
|
|
129
136
|
* @param {string} addr `a.b.c.0.1` will test if myObject has props a that has prop b. Work wit arrays as well (like `arr.0`)
|
|
130
137
|
*/
|
|
131
|
-
declare function has(obj:
|
|
138
|
+
declare function has(obj: ObjectGeneric, addr: string): boolean;
|
|
132
139
|
/** Find address in an object "a.b.c" IN { a : { b : {c : 'blah' }}} RETURNS 'blah'
|
|
133
140
|
* @param {object} obj
|
|
134
141
|
* @param {string} addr accept syntax like "obj.subItem.[0].sub2" OR "obj.subItem.0.sub2" OR "obj.subItem[0].sub2"
|
|
135
142
|
* @returns {any} the last item of the chain OR undefined if not found
|
|
136
143
|
*/
|
|
137
|
-
declare function findByAddress(obj:
|
|
144
|
+
declare function findByAddress(obj: ObjectGeneric, addr: string): any;
|
|
138
145
|
/** Enforce writing subItems. Eg: user.name.blah will ensure all are set until the writing of the last item
|
|
139
146
|
* NOTE: doesn't work with arrays
|
|
140
147
|
*/
|
|
141
|
-
declare function objForceWrite(obj:
|
|
148
|
+
declare function objForceWrite(obj: ObjectGeneric, addr: string, item: any): void;
|
|
142
149
|
/** Enforce writing subItems, only if obj.addr is empty.
|
|
143
150
|
* Eg: user.name.blah will ensure all are set until the writing of the last item
|
|
144
151
|
* if user.name.blah has a value it will not change it.
|
|
145
152
|
* NOTE: doesn't work with arrays
|
|
146
153
|
*/
|
|
147
|
-
declare function objForceWriteIfNotSet(obj:
|
|
154
|
+
declare function objForceWriteIfNotSet(obj: ObjectGeneric, addr: string, item: any): void;
|
|
148
155
|
/** Merge mixins into class. Use it in the constructor like: mergeMixins(this, {myMixin: true}) */
|
|
149
156
|
declare function mergeMixins(that: any, ...mixins: any[]): void;
|
|
150
157
|
/** If a string is provided, return it as array else return the value */
|
|
@@ -152,12 +159,11 @@ declare function strAsArray(arrOrStr: any): any;
|
|
|
152
159
|
/** If not an array provided, return the array with the value
|
|
153
160
|
* /!\ NOTE /!\ In case the value is null or undefined, it will return that value
|
|
154
161
|
*/
|
|
155
|
-
declare function asArray<T extends
|
|
156
|
-
declare function asArray<T extends string | number | boolean | any[] | object>(item: T): T[];
|
|
162
|
+
declare function asArray<T extends any[] | any>(item: T): T extends undefined ? undefined : T extends any[] ? T : T[];
|
|
157
163
|
/** Array comparison
|
|
158
164
|
* @return {object} { inCommon, notInB, notInA }
|
|
159
165
|
*/
|
|
160
|
-
declare function compareArrays(arrayA
|
|
166
|
+
declare function compareArrays(arrayA: any[], arrayB: any[], compare?: (a: any, b: any) => boolean): {
|
|
161
167
|
inCommon: any[];
|
|
162
168
|
notInB: any[];
|
|
163
169
|
notInA: any[];
|
|
@@ -447,12 +453,12 @@ declare function isValid(...paramsToValidate: any[]): boolean;
|
|
|
447
453
|
declare function isType(value: any, type: BaseTypes): boolean;
|
|
448
454
|
declare function validatorReturnErrArray(...paramsToValidate: ValidatorObject[]): [string?, number?, object?];
|
|
449
455
|
declare function isEmpty(objOrArr: object | any[] | string | null | undefined): boolean;
|
|
450
|
-
declare function getDateAsInt12(dateAllFormat?: Date | string | number, errIfNotValid?: any):
|
|
456
|
+
declare function getDateAsInt12(dateAllFormat?: Date | string | number, errIfNotValid?: any): string;
|
|
451
457
|
declare function humanReadableTimestamp(dateAllFormat: any): number;
|
|
452
458
|
/** format for 6/8/2018 => 20180806
|
|
453
459
|
* @param dateAllFormat multiple format allowed 2012, 20120101, 201201011200, new Date(), "2019-12-08T16:19:10.341Z" and all string that new Date() can parse
|
|
454
460
|
*/
|
|
455
|
-
declare function getDateAsInt(dateAllFormat?: Date | string | number, errIfNotValid$?: boolean, withHoursAndMinutes$?: boolean):
|
|
461
|
+
declare function getDateAsInt(dateAllFormat?: Date | string | number, errIfNotValid$?: boolean, withHoursAndMinutes$?: boolean): string;
|
|
456
462
|
declare function getMonthAsInt(dateAllFormat?: Date | string | number): number;
|
|
457
463
|
/**
|
|
458
464
|
* @param dateAllFormat multiple format allowed 2012, 20120101, 201201011200, new Date(), "2019-12-08T16:19:10.341Z" and all string that new Date() can parse
|
|
@@ -482,7 +488,7 @@ declare function getTimeAsInt(timeOrDateInt?: any): number | "dateInvalid";
|
|
|
482
488
|
* @param {timeInt|dateInt12} Eg: 2222 OR 201201012222. Default, actual dateInt12
|
|
483
489
|
* @param {String} separator default: ":"
|
|
484
490
|
*/
|
|
485
|
-
declare function getIntAsTime(intOrDateTimeInt?:
|
|
491
|
+
declare function getIntAsTime(intOrDateTimeInt?: string, separator?: string): string;
|
|
486
492
|
declare function isTimeStringValid(timeStr: any, outputAnError$?: boolean): boolean;
|
|
487
493
|
declare function getDuration(startDate: any, endDate: any, inMinutes?: boolean): number | number[];
|
|
488
494
|
/** compare two object with DATE INT, if they overlap return true
|
|
@@ -494,50 +500,28 @@ declare function getDuration(startDate: any, endDate: any, inMinutes?: boolean):
|
|
|
494
500
|
* @param {Boolean} strict$ if true,
|
|
495
501
|
*/
|
|
496
502
|
declare function doDateOverlap(event1: any, event2: any, fieldNameForStartDate$?: string, fieldNameForEndDate$?: string, allowNull$?: boolean, strict$?: boolean): boolean;
|
|
497
|
-
/** Get all dates at specified days between two dates
|
|
498
|
-
* @param daysArray [0,1,2,3,4,5,6]
|
|
499
|
-
* @param {*} startDate all format
|
|
500
|
-
* @param {*} endDate all format
|
|
501
|
-
* @param {'int'|'object'} outputFormat default: int
|
|
502
|
-
*/
|
|
503
|
-
declare function getDatesForDaysArrayBetweenTwoDates(daysArray: any, startDate: any, endDate: any, outputFormat?: string): (number | Date)[];
|
|
504
|
-
declare function getEndTimeFromDurationAndStartTime(startTime: any, duration: any): {
|
|
505
|
-
days: number;
|
|
506
|
-
time: string;
|
|
507
|
-
};
|
|
508
|
-
declare function getDate12FromDateAndTime(dateAllFormat: Date | string | number, timeAllFormat: any): any;
|
|
509
|
-
declare function eachDayOfInterval(startDateAllFormat: any, endDateAllFormat: any, outputFormat?: string): (number | Date)[];
|
|
510
|
-
declare function eachMonthOfInterval(startDateAllFormat: any, endDateAllFormat: any): any[];
|
|
511
|
-
declare function isSunday(dateAllFormat?: Date | string | number): boolean;
|
|
512
|
-
declare function isMonday(dateAllFormat?: Date | string | number): boolean;
|
|
513
|
-
declare function isTuesday(dateAllFormat?: Date | string | number): boolean;
|
|
514
|
-
declare function isWednesday(dateAllFormat?: Date | string | number): boolean;
|
|
515
|
-
declare function isThursday(dateAllFormat?: Date | string | number): boolean;
|
|
516
|
-
declare function isFriday(dateAllFormat?: Date | string | number): boolean;
|
|
517
|
-
declare function isSaturday(dateAllFormat?: Date | string | number): boolean;
|
|
518
|
-
declare function isWeekend(dateAllFormat?: Date | string | number): boolean;
|
|
519
503
|
declare function nextWeekDay(fromDate: any, weekDayInt?: 0 | 1 | 2 | 3 | 4 | 5 | 6, outputFormat?: 'dateInt8' | 'dateInt12' | 'humanReadableTimestamp', sameDayAllowed?: boolean): number;
|
|
520
504
|
declare function nextWeekDay(fromDate: any, weekDayInt?: 0 | 1 | 2 | 3 | 4 | 5 | 6, outputFormat?: 'date', sameDayAllowed?: boolean): Date;
|
|
521
505
|
/**
|
|
522
506
|
* @param {String} outputFormat dateInt, dateInt8, dateInt12, date, humanReadableTimestamp, int (dateInt8)
|
|
523
507
|
*/
|
|
524
|
-
declare function addDays(dateAllFormat?: Date | string | number, numberOfDays?: number, outputFormat?: string): number | Date;
|
|
508
|
+
declare function addDays(dateAllFormat?: Date | string | number, numberOfDays?: number, outputFormat?: string): string | number | Date;
|
|
525
509
|
/**
|
|
526
510
|
* @param {String} outputFormat dateInt, dateInt8, dateInt12, date, humanReadableTimestamp, int (dateInt8)
|
|
527
511
|
*/
|
|
528
|
-
declare function addMinutes(dateAllFormat?: Date | string | number, numberOfMinutes?: number, outputFormat?: string): number | Date;
|
|
512
|
+
declare function addMinutes(dateAllFormat?: Date | string | number, numberOfMinutes?: number, outputFormat?: string): string | number | Date;
|
|
529
513
|
/**
|
|
530
514
|
* @param {String} outputFormat dateInt, dateInt8, dateInt12, date, humanReadableTimestamp, int (dateInt8)
|
|
531
515
|
*/
|
|
532
|
-
declare function addHours(dateAllFormat?: Date | string | number, numberOfHours?: number, outputFormat?: string): number | Date;
|
|
516
|
+
declare function addHours(dateAllFormat?: Date | string | number, numberOfHours?: number, outputFormat?: string): string | number | Date;
|
|
533
517
|
/**
|
|
534
518
|
* @param {String} outputFormat dateInt, dateInt8, dateInt12, date, humanReadableTimestamp, int (dateInt8)
|
|
535
519
|
*/
|
|
536
|
-
declare function addMonths(dateAllFormat?: Date | string | number, numberOfMonths?: number, outputFormat?: string): number | Date;
|
|
520
|
+
declare function addMonths(dateAllFormat?: Date | string | number, numberOfMonths?: number, outputFormat?: string): string | number | Date;
|
|
537
521
|
/**
|
|
538
522
|
* @param {String} outputFormat dateInt, dateInt8, dateInt12, date, humanReadableTimestamp, int (dateInt8)
|
|
539
523
|
*/
|
|
540
|
-
declare function addYears(dateAllFormat?: Date | string | number, numberOfYears?: number, outputFormat?: string): number | Date;
|
|
524
|
+
declare function addYears(dateAllFormat?: Date | string | number, numberOfYears?: number, outputFormat?: string): string | number | Date;
|
|
541
525
|
declare function getDayOfMonth(dateAllFormat?: Date | string | number): any;
|
|
542
526
|
declare function getYear(dateAllFormat?: Date | string | number): any;
|
|
543
527
|
declare function getHours(dateAllFormat?: Date | string | number): any;
|
|
@@ -545,40 +529,17 @@ declare function getMinutes(dateAllFormat?: Date | string | number): any;
|
|
|
545
529
|
/**
|
|
546
530
|
* @param {String} outputFormat dateInt, dateInt8, dateInt12, date, humanReadableTimestamp, int (dateInt8)
|
|
547
531
|
*/
|
|
548
|
-
declare function lastDayOfMonth(dateAllFormat?: Date | string | number, outputFormat?: string): number | Date;
|
|
532
|
+
declare function lastDayOfMonth(dateAllFormat?: Date | string | number, outputFormat?: string): string | number | Date;
|
|
549
533
|
/**
|
|
550
534
|
* @param {String} outputFormat dateInt, dateInt8, dateInt12, date, humanReadableTimestamp, int (dateInt8)
|
|
551
535
|
*/
|
|
552
|
-
declare function firstDayOfMonth(dateAllFormat?: Date | string | number, outputFormat?: string): number | Date;
|
|
536
|
+
declare function firstDayOfMonth(dateAllFormat?: Date | string | number, outputFormat?: string): string | number | Date;
|
|
553
537
|
declare function differenceInMilliseconds(startDateAllFormat: any, endDateAllFormat: any): number;
|
|
554
538
|
declare function differenceInSeconds(startDateAllFormat: any, endDateAllFormat: any): number;
|
|
555
539
|
declare function differenceInMinutes(startDateAllFormat: any, endDateAllFormat: any): number;
|
|
556
540
|
declare function differenceInHours(startDateAllFormat: any, endDateAllFormat: any): number;
|
|
557
541
|
declare function differenceInDays(startDateAllFormat: any, endDateAllFormat: any): number;
|
|
558
542
|
declare function differenceInWeeks(startDateAllFormat: any, endDateAllFormat: any): number;
|
|
559
|
-
declare function differenceInMonths(startDateAllFormat: any, endDateAllFormat: any): number;
|
|
560
|
-
/** Will check if that date exists, and if not, this will
|
|
561
|
-
* Usefull for monthly subscription or reccuring month dates
|
|
562
|
-
* @param {any} dateAllFormat default: new Date()
|
|
563
|
-
* @returns {Date} Date object
|
|
564
|
-
*/
|
|
565
|
-
declare function getClosestExistingDateOfMonth(dateAllFormat?: Date | string | number): any;
|
|
566
|
-
/** Compute the best possible date for next month same day
|
|
567
|
-
* Usefull for monthly subscription or reccuring month dates
|
|
568
|
-
* @param {any} dateAllFormat default: new Date()
|
|
569
|
-
* @param {Boolean} onlyFuture if true return the future date relative to any date in the past, else, it return the next month date possible relative to the dateAllFormat
|
|
570
|
-
* @returns {Date} Date object
|
|
571
|
-
*/
|
|
572
|
-
declare function getNextMonthlyDate(dateAllFormat?: Date | string | number, onlyFuture?: boolean): any;
|
|
573
|
-
declare function getHolidayReferenceYear(dateAllFormat: Date | string | number): number;
|
|
574
|
-
/**
|
|
575
|
-
* @param {String} outputFormat dateInt, dateInt8, dateInt12, date, humanReadableTimestamp, int (dateInt8)
|
|
576
|
-
*/
|
|
577
|
-
declare function getFirstDayOfHolidayReferenceYear(dateAllFormat: Date | string | number, outputFormat?: string): number | Date;
|
|
578
|
-
/**
|
|
579
|
-
* @param {String} outputFormat dateInt, dateInt8, dateInt12, date, humanReadableTimestamp, int (dateInt8)
|
|
580
|
-
*/
|
|
581
|
-
declare function getLastDayOfHolidayReferenceYear(dateAllFormat: Date | string | number, outputFormat?: string): number | Date;
|
|
582
543
|
/**
|
|
583
544
|
// console colored output
|
|
584
545
|
// * console.log(C.green(C.dim('Hey bro !')))
|
|
@@ -715,6 +676,7 @@ declare const _: {
|
|
|
715
676
|
sortUrlsByDeepnessInArrayOrObject: typeof sortUrlsByDeepnessInArrayOrObject;
|
|
716
677
|
urlPathJoin: typeof urlPathJoin;
|
|
717
678
|
miniTemplater: typeof miniTemplater;
|
|
679
|
+
generateObjectId: typeof generateObjectId;
|
|
718
680
|
isBetween: typeof isBetween;
|
|
719
681
|
simpleObjectMaskOrSelect: typeof simpleObjectMaskOrSelect;
|
|
720
682
|
ENV: typeof ENV;
|
|
@@ -824,18 +786,7 @@ declare const _: {
|
|
|
824
786
|
isTimeStringValid: typeof isTimeStringValid;
|
|
825
787
|
getDuration: typeof getDuration;
|
|
826
788
|
doDateOverlap: typeof doDateOverlap;
|
|
827
|
-
getDatesForDaysArrayBetweenTwoDates: typeof getDatesForDaysArrayBetweenTwoDates;
|
|
828
|
-
getEndTimeFromDurationAndStartTime: typeof getEndTimeFromDurationAndStartTime;
|
|
829
|
-
getDate12FromDateAndTime: typeof getDate12FromDateAndTime;
|
|
830
789
|
getMonthAsInt: typeof getMonthAsInt;
|
|
831
|
-
isSunday: typeof isSunday;
|
|
832
|
-
isMonday: typeof isMonday;
|
|
833
|
-
isTuesday: typeof isTuesday;
|
|
834
|
-
isWednesday: typeof isWednesday;
|
|
835
|
-
isThursday: typeof isThursday;
|
|
836
|
-
isFriday: typeof isFriday;
|
|
837
|
-
isSaturday: typeof isSaturday;
|
|
838
|
-
isWeekend: typeof isWeekend;
|
|
839
790
|
nextWeekDay: typeof nextWeekDay;
|
|
840
791
|
addMinutes: typeof addMinutes;
|
|
841
792
|
addHours: typeof addHours;
|
|
@@ -848,20 +799,12 @@ declare const _: {
|
|
|
848
799
|
getMinutes: typeof getMinutes;
|
|
849
800
|
firstDayOfMonth: typeof firstDayOfMonth;
|
|
850
801
|
lastDayOfMonth: typeof lastDayOfMonth;
|
|
851
|
-
eachDayOfInterval: typeof eachDayOfInterval;
|
|
852
|
-
eachMonthOfInterval: typeof eachMonthOfInterval;
|
|
853
802
|
differenceInMilliseconds: typeof differenceInMilliseconds;
|
|
854
803
|
differenceInSeconds: typeof differenceInSeconds;
|
|
855
804
|
differenceInMinutes: typeof differenceInMinutes;
|
|
856
805
|
differenceInHours: typeof differenceInHours;
|
|
857
806
|
differenceInDays: typeof differenceInDays;
|
|
858
807
|
differenceInWeeks: typeof differenceInWeeks;
|
|
859
|
-
differenceInMonths: typeof differenceInMonths;
|
|
860
|
-
getClosestExistingDateOfMonth: typeof getClosestExistingDateOfMonth;
|
|
861
|
-
getNextMonthlyDate: typeof getNextMonthlyDate;
|
|
862
|
-
getHolidayReferenceYear: typeof getHolidayReferenceYear;
|
|
863
|
-
getFirstDayOfHolidayReferenceYear: typeof getFirstDayOfHolidayReferenceYear;
|
|
864
|
-
getLastDayOfHolidayReferenceYear: typeof getLastDayOfHolidayReferenceYear;
|
|
865
808
|
getDateAsArrayFormatted: typeof dateArray;
|
|
866
809
|
getDateAsArray: typeof dateStringToArray;
|
|
867
810
|
convertDateAsInt: typeof getDateAsInt;
|
|
@@ -927,6 +870,6 @@ declare const _: {
|
|
|
927
870
|
tryCatch: typeof tryCatch;
|
|
928
871
|
};
|
|
929
872
|
export default _;
|
|
930
|
-
export { round, random, cln, pad, int, minMax, generateToken, moyenne, average, sumArray, sortUrlsByDeepnessInArrayOrObject, urlPathJoin, miniTemplater, isBetween, simpleObjectMaskOrSelect, ENV, parseBool, registerConfig, configFn, findByAddress, objForceWrite, objForceWriteIfNotSet, strAsArray, asArray, compareArrays, getArrayInCommon, getArrayDiff, getNotInArrayA, noDuplicateFilter, arrayCount, arrayToObjectSorted, pushIfNotExist, isNotEmptyArray, randomItemInArray, arrayUniqueValue, deepClone, cloneObject, JSONstringyParse, has, isObject, mergeDeep, flattenObject, unflattenObject, recursiveGenericFunction, recursiveGenericFunctionSync, findByAddressAll, objFilterUndefined, readOnly, reassignForbidden, readOnlyForAll, mergeDeepOverrideArrays, mergeDeepConfigurable, objFilterUndefinedRecursive, removeUndefinedKeys, // alias
|
|
873
|
+
export { round, random, cln, pad, int, minMax, generateToken, moyenne, average, sumArray, sortUrlsByDeepnessInArrayOrObject, urlPathJoin, miniTemplater, generateObjectId, isBetween, simpleObjectMaskOrSelect, ENV, parseBool, registerConfig, configFn, findByAddress, objForceWrite, objForceWriteIfNotSet, strAsArray, asArray, compareArrays, getArrayInCommon, getArrayDiff, getNotInArrayA, noDuplicateFilter, arrayCount, arrayToObjectSorted, pushIfNotExist, isNotEmptyArray, randomItemInArray, arrayUniqueValue, deepClone, cloneObject, JSONstringyParse, has, isObject, mergeDeep, flattenObject, unflattenObject, recursiveGenericFunction, recursiveGenericFunctionSync, findByAddressAll, objFilterUndefined, readOnly, reassignForbidden, readOnlyForAll, mergeDeepOverrideArrays, mergeDeepConfigurable, objFilterUndefinedRecursive, removeUndefinedKeys, // alias
|
|
931
874
|
sortObjKeyAccordingToValue, ensureObjectProp, filterKeys, deleteByAddress, ensureIsArrayAndPush, removeCircularJSONstringify, isset, cleanStackTrace, shuffleArray, shuffleArray as randomizeArray, round2, camelCase, snakeCase, kebabCase, kebabCase as dashCase, snakeCase as underscoreCase, titleCase, pascalCase, lowerCase, upperCase, capitalize1st, camelCaseToWords, firstMatch, allMatches, getValuesBetweenSeparator, getValuesBetweenStrings, escapeRegexp, validator, validator as required, // alias for readability
|
|
932
|
-
validatorReturnErrArray, assert, restTestMini, isValid, isType, isDateObject, issetOr, isEmptyOrNotSet, errIfNotSet, err500IfNotSet, errIfEmptyOrNotSet, err500IfEmptyOrNotSet, errXXXIfNotSet, isEmpty, checkAllObjectValuesAreEmpty, checkCtxIntegrity, issetOr as orIsset, getDateAsInt12, humanReadableTimestamp, getDateAsInt, getDateAsObject, isDateIntOrStringValid, isDateIsoOrObjectValid, dateStringToArray, dateArray, dateArrayInt, dateFormatted as dateSlash, dateFormatted, dateOffset, getTimeAsInt, getIntAsTime, isTimeStringValid, getDuration, doDateOverlap,
|
|
875
|
+
validatorReturnErrArray, assert, restTestMini, isValid, isType, isDateObject, issetOr, isEmptyOrNotSet, errIfNotSet, err500IfNotSet, errIfEmptyOrNotSet, err500IfEmptyOrNotSet, errXXXIfNotSet, isEmpty, checkAllObjectValuesAreEmpty, checkCtxIntegrity, issetOr as orIsset, getDateAsInt12, humanReadableTimestamp, getDateAsInt, getDateAsObject, isDateIntOrStringValid, isDateIsoOrObjectValid, dateStringToArray, dateArray, dateArrayInt, dateFormatted as dateSlash, dateFormatted, dateOffset, getTimeAsInt, getIntAsTime, isTimeStringValid, getDuration, doDateOverlap, getMonthAsInt, nextWeekDay, addMinutes, addHours, addDays, addMonths, addYears, getYear, getDayOfMonth, getHours, getMinutes, firstDayOfMonth, lastDayOfMonth, differenceInMilliseconds, differenceInSeconds, differenceInMinutes, differenceInHours, differenceInDays, differenceInWeeks, getDateAsInt as convertDateAsInt, getDateAsObject as convertDateAsObject, C, cliProgressBar, cliLoadingSpinner, convertAccentedCharacters, executeInDelayedLoop, timeout, runAsync, waitUntilTrue, transaction, waitForTransaction, getId, mergeMixins, mongoFilterMerger, mongoPush, tryCatch, };
|
package/utils.js
CHANGED
|
@@ -61,12 +61,14 @@ function generateToken(length = 20, unique = true, mode = 'alphanumeric') {
|
|
|
61
61
|
while (token.length < length)
|
|
62
62
|
token += Math.random().toString(charConvNumeric).substr(2, 1); // char alphaNumeric aléatoire
|
|
63
63
|
} while (generatedTokens.includes(token));
|
|
64
|
-
if (lastTs < tokenTs)
|
|
64
|
+
if (lastTs < tokenTs)
|
|
65
65
|
generatedTokens = []; // reset generated token on new timestamp because cannot collide
|
|
66
|
-
}
|
|
67
66
|
generatedTokens.push(token);
|
|
68
67
|
return token;
|
|
69
68
|
}
|
|
69
|
+
function generateObjectId() {
|
|
70
|
+
return generateToken(24, true, 'hexadecimal');
|
|
71
|
+
}
|
|
70
72
|
/** Useful to join differents bits of url with normalizing slashes
|
|
71
73
|
* * urlPathJoin('https://', 'www.kikou.lol/', '/user', '//2//') => https://www.kikou.lol/user/2/
|
|
72
74
|
* * urlPathJoin('http:/', 'kikou.lol') => https://www.kikou.lol
|
|
@@ -103,15 +105,14 @@ function sortUrlsByDeepnessInArrayOrObject(urlObjOrArr, propInObjectOrIndexInArr
|
|
|
103
105
|
bUrl.length - aUrl.length; // help separating / vs /blah
|
|
104
106
|
});
|
|
105
107
|
}
|
|
106
|
-
/**
|
|
107
|
-
* Replace variables in a string like: `Hello {{userName}}!`
|
|
108
|
+
/** Replace variables in a string like: `Hello {{userName}}!`
|
|
108
109
|
* @param {String} content
|
|
109
110
|
* @param {Object} varz object with key => value === toReplace => replacer
|
|
110
111
|
* @param {Object} options
|
|
111
112
|
* * valueWhenNotSet => replacer for undefined values. Default: ''
|
|
112
113
|
* * regexp => must be 'g' and first capturing group matching the value to replace. Default: /{{\s*([^}]*)\s*}}/g
|
|
113
114
|
*/
|
|
114
|
-
function miniTemplater(content, varz, options) {
|
|
115
|
+
function miniTemplater(content, varz, options = {}) {
|
|
115
116
|
options = {
|
|
116
117
|
valueWhenNotSet: '',
|
|
117
118
|
regexp: /{{\s*([^}]*)\s*}}/g,
|
|
@@ -344,13 +345,16 @@ function mergeMixins(that, ...mixins) {
|
|
|
344
345
|
function strAsArray(arrOrStr) {
|
|
345
346
|
return typeof arrOrStr === 'string' ? [arrOrStr] : arrOrStr;
|
|
346
347
|
}
|
|
348
|
+
/** If not an array provided, return the array with the value
|
|
349
|
+
* /!\ NOTE /!\ In case the value is null or undefined, it will return that value
|
|
350
|
+
*/
|
|
347
351
|
function asArray(item) {
|
|
348
|
-
return typeof item === 'undefined' ? item : Array.isArray(item) ? item : [item];
|
|
352
|
+
return (typeof item === 'undefined' ? item : Array.isArray(item) ? item : [item]);
|
|
349
353
|
}
|
|
350
354
|
/** Array comparison
|
|
351
355
|
* @return {object} { inCommon, notInB, notInA }
|
|
352
356
|
*/
|
|
353
|
-
function compareArrays(arrayA
|
|
357
|
+
function compareArrays(arrayA, arrayB, compare = (a, b) => a === b) {
|
|
354
358
|
return {
|
|
355
359
|
inCommon: getArrayInCommon(arrayA, arrayB, compare),
|
|
356
360
|
notInB: getNotInArrayA(arrayB, arrayA, compare),
|
|
@@ -1003,9 +1007,6 @@ function validator(...paramsToValidate) {
|
|
|
1003
1007
|
}
|
|
1004
1008
|
const restTestMini = {
|
|
1005
1009
|
reset() {
|
|
1006
|
-
restTestMini.nbSuccess = 0;
|
|
1007
|
-
restTestMini.nbError = 0;
|
|
1008
|
-
restTestMini.lastErrors = [];
|
|
1009
1010
|
},
|
|
1010
1011
|
printStats() {
|
|
1011
1012
|
// TODO print last errz
|
|
@@ -1220,7 +1221,12 @@ function humanReadableTimestamp(dateAllFormat) {
|
|
|
1220
1221
|
*/
|
|
1221
1222
|
function getDateAsInt(dateAllFormat = new Date(), errIfNotValid$ = false, withHoursAndMinutes$ = false) {
|
|
1222
1223
|
let dateInt;
|
|
1223
|
-
if (
|
|
1224
|
+
if (typeof dateAllFormat === 'string' && dateAllFormat.includes('/')) {
|
|
1225
|
+
// 01/01/2020 format
|
|
1226
|
+
const [d, m, y] = dateAllFormat.split('/');
|
|
1227
|
+
return y + m.toString().padStart(2, '0') + d.toString().padStart(2, '0');
|
|
1228
|
+
}
|
|
1229
|
+
else if (isDateIntOrStringValid(dateAllFormat)) {
|
|
1224
1230
|
// we can pass an int or string format (20180106)
|
|
1225
1231
|
dateInt = (dateAllFormat + '00000000').substr(0, 12); // add default 000000 for "month days minutes:sec" if not set
|
|
1226
1232
|
}
|
|
@@ -1406,92 +1412,6 @@ function doDateOverlap(event1, event2, fieldNameForStartDate$ = 'startDate', fie
|
|
|
1406
1412
|
return (!event2[fieldNameForEndDate$] || event1[fieldNameForStartDate$] < event2[fieldNameForEndDate$]) && (!event1[fieldNameForEndDate$] || event1[fieldNameForEndDate$] > event2[fieldNameForStartDate$]);
|
|
1407
1413
|
return (!event2[fieldNameForEndDate$] || event1[fieldNameForStartDate$] <= event2[fieldNameForEndDate$]) && (!event1[fieldNameForEndDate$] || event1[fieldNameForEndDate$] >= event2[fieldNameForStartDate$]);
|
|
1408
1414
|
}
|
|
1409
|
-
/** Get all dates at specified days between two dates
|
|
1410
|
-
* @param daysArray [0,1,2,3,4,5,6]
|
|
1411
|
-
* @param {*} startDate all format
|
|
1412
|
-
* @param {*} endDate all format
|
|
1413
|
-
* @param {'int'|'object'} outputFormat default: int
|
|
1414
|
-
*/
|
|
1415
|
-
function getDatesForDaysArrayBetweenTwoDates(daysArray, startDate, endDate, outputFormat = 'int') {
|
|
1416
|
-
const dateArr = [];
|
|
1417
|
-
let actualDate = getDateAsObject(startDate);
|
|
1418
|
-
endDate = getDateAsObject(endDate);
|
|
1419
|
-
while (actualDate <= endDate) {
|
|
1420
|
-
if (daysArray.includes(actualDate.getUTCDay()))
|
|
1421
|
-
dateArr.push(getDateAsObject(actualDate)); // cloned
|
|
1422
|
-
actualDate.setUTCDate(actualDate.getUTCDate() + 1);
|
|
1423
|
-
}
|
|
1424
|
-
return dateArr.map(d => getDateAs(d, outputFormat));
|
|
1425
|
-
}
|
|
1426
|
-
function getEndTimeFromDurationAndStartTime(startTime, duration) {
|
|
1427
|
-
const timeArr = startTime.split(':').map(n => parseInt(n));
|
|
1428
|
-
let endTime = (timeArr[0] * 60 + timeArr[1]) + duration;
|
|
1429
|
-
return {
|
|
1430
|
-
days: Math.floor(endTime / 1440),
|
|
1431
|
-
time: pad(Math.floor((endTime % 1440) / 60)) + ':' + pad(endTime % 60)
|
|
1432
|
-
};
|
|
1433
|
-
}
|
|
1434
|
-
function getDate12FromDateAndTime(dateAllFormat, timeAllFormat) {
|
|
1435
|
-
if (typeof dateAllFormat !== 'number' || dateAllFormat > 99991231 || dateAllFormat < 0)
|
|
1436
|
-
dateAllFormat = getDateAsInt(dateAllFormat);
|
|
1437
|
-
if (typeof timeAllFormat !== 'number' || timeAllFormat > 2359 || timeAllFormat < 0)
|
|
1438
|
-
timeAllFormat = getTimeAsInt(timeAllFormat);
|
|
1439
|
-
return dateAllFormat * 10000 + timeAllFormat;
|
|
1440
|
-
}
|
|
1441
|
-
function eachDayOfInterval(startDateAllFormat, endDateAllFormat, outputFormat = 'int') {
|
|
1442
|
-
const start = getDateAsObject(startDateAllFormat);
|
|
1443
|
-
const end = getDateAsObject(endDateAllFormat);
|
|
1444
|
-
let days = [];
|
|
1445
|
-
let current = new Date();
|
|
1446
|
-
current.setTime(start.getTime());
|
|
1447
|
-
while (current <= end) {
|
|
1448
|
-
days.push(new Date(current.getTime()));
|
|
1449
|
-
current.setTime(current.getTime() + 1000 * 60 * 60 * 24);
|
|
1450
|
-
}
|
|
1451
|
-
return days.map(d => getDateAs(d, outputFormat));
|
|
1452
|
-
}
|
|
1453
|
-
function eachMonthOfInterval(startDateAllFormat, endDateAllFormat) {
|
|
1454
|
-
const months = [];
|
|
1455
|
-
const current = firstDayOfMonth(startDateAllFormat, 'Object');
|
|
1456
|
-
const end = firstDayOfMonth(endDateAllFormat, 'Object');
|
|
1457
|
-
while (current <= end) {
|
|
1458
|
-
months.push(getMonthAsInt(current));
|
|
1459
|
-
current.setUTCMonth(current.getUTCMonth() + 1);
|
|
1460
|
-
}
|
|
1461
|
-
return months;
|
|
1462
|
-
}
|
|
1463
|
-
function isSunday(dateAllFormat = getDateAsInt()) {
|
|
1464
|
-
let date = getDateAsObject(dateAllFormat);
|
|
1465
|
-
return date.getUTCDay() === 0;
|
|
1466
|
-
}
|
|
1467
|
-
function isMonday(dateAllFormat = getDateAsInt()) {
|
|
1468
|
-
let date = getDateAsObject(dateAllFormat);
|
|
1469
|
-
return date.getUTCDay() === 1;
|
|
1470
|
-
}
|
|
1471
|
-
function isTuesday(dateAllFormat = getDateAsInt()) {
|
|
1472
|
-
let date = getDateAsObject(dateAllFormat);
|
|
1473
|
-
return date.getUTCDay() === 2;
|
|
1474
|
-
}
|
|
1475
|
-
function isWednesday(dateAllFormat = getDateAsInt()) {
|
|
1476
|
-
let date = getDateAsObject(dateAllFormat);
|
|
1477
|
-
return date.getUTCDay() === 3;
|
|
1478
|
-
}
|
|
1479
|
-
function isThursday(dateAllFormat = getDateAsInt()) {
|
|
1480
|
-
let date = getDateAsObject(dateAllFormat);
|
|
1481
|
-
return date.getUTCDay() === 4;
|
|
1482
|
-
}
|
|
1483
|
-
function isFriday(dateAllFormat = getDateAsInt()) {
|
|
1484
|
-
let date = getDateAsObject(dateAllFormat);
|
|
1485
|
-
return date.getUTCDay() === 5;
|
|
1486
|
-
}
|
|
1487
|
-
function isSaturday(dateAllFormat = getDateAsInt()) {
|
|
1488
|
-
let date = getDateAsObject(dateAllFormat);
|
|
1489
|
-
return date.getUTCDay() === 6;
|
|
1490
|
-
}
|
|
1491
|
-
function isWeekend(dateAllFormat = getDateAsInt()) {
|
|
1492
|
-
let date = getDateAsObject(dateAllFormat);
|
|
1493
|
-
return date.getUTCDay() === 6 || date.getUTCDay() === 0;
|
|
1494
|
-
}
|
|
1495
1415
|
function nextWeekDay(fromDate, weekDayInt, outputFormat = 'date', sameDayAllowed = false) {
|
|
1496
1416
|
const date = getDateAsObject(fromDate);
|
|
1497
1417
|
if (!isset(weekDayInt))
|
|
@@ -1603,103 +1523,6 @@ function differenceInDays(startDateAllFormat, endDateAllFormat) {
|
|
|
1603
1523
|
function differenceInWeeks(startDateAllFormat, endDateAllFormat) {
|
|
1604
1524
|
return differenceInDays(startDateAllFormat, endDateAllFormat) / 7;
|
|
1605
1525
|
}
|
|
1606
|
-
function differenceInMonths(startDateAllFormat, endDateAllFormat) {
|
|
1607
|
-
const startDate = getDateAsInt(startDateAllFormat);
|
|
1608
|
-
const endDate = getDateAsInt(endDateAllFormat);
|
|
1609
|
-
const monthesForStart = parseInt(getYear(startDate)) * 12 + parseInt(getMonthForHuman(startDate));
|
|
1610
|
-
const monthesForEnd = parseInt(getYear(endDate)) * 12 + parseInt(getMonthForHuman(endDate));
|
|
1611
|
-
if (monthesForStart === monthesForEnd) {
|
|
1612
|
-
const firstDay = firstDayOfMonth(startDate);
|
|
1613
|
-
const lastDay = lastDayOfMonth(endDate);
|
|
1614
|
-
const differenceBetweenStartAndEnd = differenceInDays(startDate, endDate);
|
|
1615
|
-
const numberOfDaysInMonth = differenceInDays(firstDay, lastDay);
|
|
1616
|
-
return round(differenceBetweenStartAndEnd / numberOfDaysInMonth, 2);
|
|
1617
|
-
}
|
|
1618
|
-
const firstDayOfStartDateMonth = firstDayOfMonth(startDate);
|
|
1619
|
-
const lastDayOfStartDateMonth = lastDayOfMonth(startDate);
|
|
1620
|
-
const firstDayOfEndDateMonth = firstDayOfMonth(endDate);
|
|
1621
|
-
const lastDayOfEndDateMonth = lastDayOfMonth(endDate);
|
|
1622
|
-
const differenceBetweenStartDateAndEndOfStartMonth = differenceInDays(startDate, lastDayOfStartDateMonth);
|
|
1623
|
-
const differenceBetweenStartOfEndMonthAndEndDate = differenceInDays(firstDayOfEndDateMonth, endDate);
|
|
1624
|
-
const numberOfDaysInStartMonth = differenceInDays(firstDayOfStartDateMonth, lastDayOfStartDateMonth);
|
|
1625
|
-
const numberOfDaysInEndMonth = differenceInDays(firstDayOfEndDateMonth, lastDayOfEndDateMonth);
|
|
1626
|
-
return round(monthesForEnd - monthesForStart - 1 + differenceBetweenStartDateAndEndOfStartMonth / numberOfDaysInStartMonth + differenceBetweenStartOfEndMonthAndEndDate / numberOfDaysInEndMonth, 2);
|
|
1627
|
-
}
|
|
1628
|
-
/** Will check if that date exists, and if not, this will
|
|
1629
|
-
* Usefull for monthly subscription or reccuring month dates
|
|
1630
|
-
* @param {any} dateAllFormat default: new Date()
|
|
1631
|
-
* @returns {Date} Date object
|
|
1632
|
-
*/
|
|
1633
|
-
function getClosestExistingDateOfMonth(dateAllFormat = getDateAsInt()) {
|
|
1634
|
-
let [day, month, year] = dateArrayInt(dateAllFormat);
|
|
1635
|
-
const zeroBasedMonth = minMax(month - 1, 0, 11);
|
|
1636
|
-
if (!isBetween(month, 1, 12))
|
|
1637
|
-
console.error('Wrong month provided for getClosestExistingDateOfMonth: ' + month + ' Shall be between 1-12. Converted to ' + zeroBasedMonth);
|
|
1638
|
-
let dayNb = minMax(day, 1, 31);
|
|
1639
|
-
let date;
|
|
1640
|
-
let increment = dayNb < 1;
|
|
1641
|
-
let tooMuchRecursionCount = 0;
|
|
1642
|
-
do
|
|
1643
|
-
date = new Date(year, zeroBasedMonth, (increment ? dayNb++ : dayNb--), 12);
|
|
1644
|
-
while (date.getUTCMonth() !== zeroBasedMonth && tooMuchRecursionCount < 99);
|
|
1645
|
-
if (tooMuchRecursionCount)
|
|
1646
|
-
throw new dataValidationUtilErrorHandler(`tooMuchRecursionCount`, 500, { origin: 'getClosestExistingDateOfMonth', day, month, year });
|
|
1647
|
-
return date;
|
|
1648
|
-
}
|
|
1649
|
-
/** Compute the best possible date for next month same day
|
|
1650
|
-
* Usefull for monthly subscription or reccuring month dates
|
|
1651
|
-
* @param {any} dateAllFormat default: new Date()
|
|
1652
|
-
* @param {Boolean} onlyFuture if true return the future date relative to any date in the past, else, it return the next month date possible relative to the dateAllFormat
|
|
1653
|
-
* @returns {Date} Date object
|
|
1654
|
-
*/
|
|
1655
|
-
function getNextMonthlyDate(dateAllFormat = getDateAsInt(), onlyFuture = false) {
|
|
1656
|
-
let [day, month, year] = dateArrayInt(dateAllFormat);
|
|
1657
|
-
day = minMax(day, 1, 31);
|
|
1658
|
-
month = minMax(month, 1, 12);
|
|
1659
|
-
err422IfNotSet({ year, month, day });
|
|
1660
|
-
const isDatePast = getDateAsInt(dateAllFormat) <= getDateAsInt();
|
|
1661
|
-
if (onlyFuture && isDatePast) {
|
|
1662
|
-
let [, todayMonth, todayYear] = dateArrayInt();
|
|
1663
|
-
month = todayMonth;
|
|
1664
|
-
year = todayYear;
|
|
1665
|
-
}
|
|
1666
|
-
let nextMonth;
|
|
1667
|
-
if (month === 12) {
|
|
1668
|
-
nextMonth = 1;
|
|
1669
|
-
year++;
|
|
1670
|
-
}
|
|
1671
|
-
else
|
|
1672
|
-
nextMonth = month + 1;
|
|
1673
|
-
return getClosestExistingDateOfMonth(new Date(year, nextMonth - 1, day));
|
|
1674
|
-
}
|
|
1675
|
-
function getHolidayReferenceYear(dateAllFormat) {
|
|
1676
|
-
let date = getDateAsObject(dateAllFormat);
|
|
1677
|
-
if (date.getUTCMonth() > 4)
|
|
1678
|
-
return date.getUTCFullYear();
|
|
1679
|
-
return date.getUTCFullYear() - 1;
|
|
1680
|
-
}
|
|
1681
|
-
/**
|
|
1682
|
-
* @param {String} outputFormat dateInt, dateInt8, dateInt12, date, humanReadableTimestamp, int (dateInt8)
|
|
1683
|
-
*/
|
|
1684
|
-
function getFirstDayOfHolidayReferenceYear(dateAllFormat, outputFormat = 'int') {
|
|
1685
|
-
const date = getDateAsObject(dateAllFormat);
|
|
1686
|
-
let year = date.getUTCFullYear();
|
|
1687
|
-
if (date.getUTCMonth() < 4)
|
|
1688
|
-
year = date.getUTCFullYear() - 1;
|
|
1689
|
-
const firstDayAsInt = year + '0601';
|
|
1690
|
-
return getDateAs(firstDayAsInt, outputFormat);
|
|
1691
|
-
}
|
|
1692
|
-
/**
|
|
1693
|
-
* @param {String} outputFormat dateInt, dateInt8, dateInt12, date, humanReadableTimestamp, int (dateInt8)
|
|
1694
|
-
*/
|
|
1695
|
-
function getLastDayOfHolidayReferenceYear(dateAllFormat, outputFormat = 'int') {
|
|
1696
|
-
let date = getDateAsObject(dateAllFormat);
|
|
1697
|
-
let year = date.getUTCFullYear() + 1;
|
|
1698
|
-
if (date.getUTCMonth() < 4)
|
|
1699
|
-
year = date.getUTCFullYear();
|
|
1700
|
-
const firstDayAsInt = year + '0531';
|
|
1701
|
-
return getDateAs(firstDayAsInt, outputFormat);
|
|
1702
|
-
}
|
|
1703
1526
|
/**
|
|
1704
1527
|
* @param {String} outputDateFormat dateInt, dateInt8, dateInt12, date, humanReadableTimestamp, int (dateInt8)
|
|
1705
1528
|
*/
|
|
@@ -2243,6 +2066,7 @@ const _ = {
|
|
|
2243
2066
|
sortUrlsByDeepnessInArrayOrObject,
|
|
2244
2067
|
urlPathJoin,
|
|
2245
2068
|
miniTemplater,
|
|
2069
|
+
generateObjectId,
|
|
2246
2070
|
isBetween,
|
|
2247
2071
|
simpleObjectMaskOrSelect,
|
|
2248
2072
|
ENV,
|
|
@@ -2349,18 +2173,7 @@ const _ = {
|
|
|
2349
2173
|
isTimeStringValid,
|
|
2350
2174
|
getDuration,
|
|
2351
2175
|
doDateOverlap,
|
|
2352
|
-
getDatesForDaysArrayBetweenTwoDates,
|
|
2353
|
-
getEndTimeFromDurationAndStartTime,
|
|
2354
|
-
getDate12FromDateAndTime,
|
|
2355
2176
|
getMonthAsInt,
|
|
2356
|
-
isSunday,
|
|
2357
|
-
isMonday,
|
|
2358
|
-
isTuesday,
|
|
2359
|
-
isWednesday,
|
|
2360
|
-
isThursday,
|
|
2361
|
-
isFriday,
|
|
2362
|
-
isSaturday,
|
|
2363
|
-
isWeekend,
|
|
2364
2177
|
nextWeekDay,
|
|
2365
2178
|
addMinutes,
|
|
2366
2179
|
addHours,
|
|
@@ -2373,20 +2186,12 @@ const _ = {
|
|
|
2373
2186
|
getMinutes,
|
|
2374
2187
|
firstDayOfMonth,
|
|
2375
2188
|
lastDayOfMonth,
|
|
2376
|
-
eachDayOfInterval,
|
|
2377
|
-
eachMonthOfInterval,
|
|
2378
2189
|
differenceInMilliseconds,
|
|
2379
2190
|
differenceInSeconds,
|
|
2380
2191
|
differenceInMinutes,
|
|
2381
2192
|
differenceInHours,
|
|
2382
2193
|
differenceInDays,
|
|
2383
2194
|
differenceInWeeks,
|
|
2384
|
-
differenceInMonths,
|
|
2385
|
-
getClosestExistingDateOfMonth,
|
|
2386
|
-
getNextMonthlyDate,
|
|
2387
|
-
getHolidayReferenceYear,
|
|
2388
|
-
getFirstDayOfHolidayReferenceYear,
|
|
2389
|
-
getLastDayOfHolidayReferenceYear,
|
|
2390
2195
|
// ALIASES
|
|
2391
2196
|
getDateAsArrayFormatted: dateArray,
|
|
2392
2197
|
getDateAsArray: dateStringToArray,
|
|
@@ -2417,7 +2222,7 @@ const _ = {
|
|
|
2417
2222
|
export default _;
|
|
2418
2223
|
export { round, random, cln, pad,
|
|
2419
2224
|
// ALIASES
|
|
2420
|
-
int, minMax, generateToken, moyenne, average, sumArray, sortUrlsByDeepnessInArrayOrObject, urlPathJoin, miniTemplater, isBetween, simpleObjectMaskOrSelect, ENV, parseBool, registerConfig, configFn, findByAddress, objForceWrite, objForceWriteIfNotSet, strAsArray, asArray, compareArrays, getArrayInCommon, getArrayDiff, getNotInArrayA, noDuplicateFilter, arrayCount, arrayToObjectSorted, pushIfNotExist, isNotEmptyArray, randomItemInArray,
|
|
2225
|
+
int, minMax, generateToken, moyenne, average, sumArray, sortUrlsByDeepnessInArrayOrObject, urlPathJoin, miniTemplater, generateObjectId, isBetween, simpleObjectMaskOrSelect, ENV, parseBool, registerConfig, configFn, findByAddress, objForceWrite, objForceWriteIfNotSet, strAsArray, asArray, compareArrays, getArrayInCommon, getArrayDiff, getNotInArrayA, noDuplicateFilter, arrayCount, arrayToObjectSorted, pushIfNotExist, isNotEmptyArray, randomItemInArray,
|
|
2421
2226
|
//allias
|
|
2422
2227
|
arrayUniqueValue, deepClone, cloneObject, JSONstringyParse, has, isObject, mergeDeep, flattenObject, unflattenObject, recursiveGenericFunction, recursiveGenericFunctionSync, findByAddressAll, objFilterUndefined, readOnly, reassignForbidden, readOnlyForAll, mergeDeepOverrideArrays, mergeDeepConfigurable, objFilterUndefinedRecursive, removeUndefinedKeys, // alias
|
|
2423
2228
|
sortObjKeyAccordingToValue, ensureObjectProp, filterKeys, deleteByAddress, ensureIsArrayAndPush, removeCircularJSONstringify, isset, cleanStackTrace, shuffleArray, shuffleArray as randomizeArray, round2, camelCase, snakeCase, kebabCase, kebabCase as dashCase, snakeCase as underscoreCase, titleCase, pascalCase, lowerCase, upperCase, capitalize1st, camelCaseToWords, firstMatch, allMatches, getValuesBetweenSeparator, getValuesBetweenStrings, escapeRegexp, validator, validator as required, // alias for readability
|
|
@@ -2427,7 +2232,7 @@ issetOr as orIsset,
|
|
|
2427
2232
|
// DATE
|
|
2428
2233
|
getDateAsInt12, humanReadableTimestamp, getDateAsInt, getDateAsObject, isDateIntOrStringValid, isDateIsoOrObjectValid, dateStringToArray, dateArray, dateArrayInt, dateFormatted as dateSlash, dateFormatted, dateOffset, getTimeAsInt, getIntAsTime, isTimeStringValid,
|
|
2429
2234
|
// isDateObject <= see validator.js
|
|
2430
|
-
getDuration, doDateOverlap,
|
|
2235
|
+
getDuration, doDateOverlap, getMonthAsInt, nextWeekDay, addMinutes, addHours, addDays, addMonths, addYears, getYear, getDayOfMonth, getHours, getMinutes, firstDayOfMonth, lastDayOfMonth, differenceInMilliseconds, differenceInSeconds, differenceInMinutes, differenceInHours, differenceInDays, differenceInWeeks,
|
|
2431
2236
|
// ALIASES
|
|
2432
2237
|
getDateAsInt as convertDateAsInt, getDateAsObject as convertDateAsObject,
|
|
2433
2238
|
// LOGGER
|