@mll-lab/js-utils 2.0.0 → 2.4.0
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/dist/array.d.ts +5 -0
- package/dist/date.d.ts +9 -8
- package/dist/index.common.js +68 -6
- package/dist/index.common.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +68 -6
- package/dist/index.js.map +1 -1
- package/dist/string.d.ts +2 -0
- package/dist/string.test.d.ts +1 -0
- package/package.json +1 -1
package/dist/array.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
export declare type NonEmptyArray<T> = Array<T> & {
|
|
2
|
+
0: T;
|
|
3
|
+
};
|
|
4
|
+
export declare function isNonEmptyArray<T>(value: Array<T>): value is NonEmptyArray<T>;
|
|
1
5
|
/**
|
|
2
6
|
* Return a new array that does not contain the item at the specified index.
|
|
3
7
|
*/
|
|
@@ -18,3 +22,4 @@ export declare const EMPTY_ARRAY: never[];
|
|
|
18
22
|
* @example const arr = ['x', ...insertIf(foo === 42, 'y', 'z')]
|
|
19
23
|
*/
|
|
20
24
|
export declare function insertIf<T>(condition: boolean, ...elements: Array<T>): Array<T>;
|
|
25
|
+
export declare function last<T, A extends Array<T>>(array: A): A extends NonEmptyArray<T> ? T : T | undefined;
|
package/dist/date.d.ts
CHANGED
|
@@ -1,24 +1,25 @@
|
|
|
1
|
-
export declare function isToday(date: Date | number): boolean;
|
|
1
|
+
export declare function isToday(date: Date | string | number): boolean;
|
|
2
|
+
export declare function isFuture(date: Date | string | number): boolean;
|
|
2
3
|
export declare function parseDate(value: string, formatString: string): Date | null;
|
|
3
4
|
export declare function parseGermanDateFlexible(value: string): Date | null;
|
|
4
5
|
export declare const GERMAN_DATE_FORMAT: string;
|
|
5
6
|
export declare function parseGermanDate(value: string): Date | null;
|
|
6
|
-
export declare function formatGerman(date: Date): string;
|
|
7
|
+
export declare function formatGerman(date: Date | string | number): string;
|
|
7
8
|
export declare const ISO_DATE_FORMAT: string;
|
|
8
9
|
export declare function parseIsoDate(value: string): Date | null;
|
|
9
|
-
export declare function formatIsoDate(date:
|
|
10
|
+
export declare function formatIsoDate(date: Date | string | number): string;
|
|
10
11
|
export declare const GERMAN_DOTLESS_DATE_FORMAT: string;
|
|
11
12
|
export declare function parseGermanDotlessDate(value: string): Date | null;
|
|
12
|
-
export declare function formatGermanDotlessDate(date: Date): string;
|
|
13
|
+
export declare function formatGermanDotlessDate(date: Date | string | number): string;
|
|
13
14
|
export declare const SECONDLESS_DATE_TIME_FORMAT: string;
|
|
14
15
|
export declare function parseSecondlessDateTime(value: string): Date | null;
|
|
15
|
-
export declare function formatSecondlessDateTime(
|
|
16
|
+
export declare function formatSecondlessDateTime(date: Date | string | number): string;
|
|
16
17
|
export declare const GERMAN_DATE_TIME_FORMAT: string;
|
|
17
18
|
export declare function parseGermanDateTime(value: string): Date | null;
|
|
18
|
-
export declare function formatGermanDateTime(date: Date): string;
|
|
19
|
+
export declare function formatGermanDateTime(date: Date | string | number): string;
|
|
19
20
|
export declare const ISO_DATE_TIME_FORMAT: string;
|
|
20
21
|
export declare function parseIsoDateTime(value: string): Date | null;
|
|
21
|
-
export declare function formatIsoDateTime(
|
|
22
|
+
export declare function formatIsoDateTime(date: Date | string | number): string;
|
|
22
23
|
export declare const DOTLESS_DATE_FORMAT: string;
|
|
23
24
|
export declare function parseDotlessDate(value: string): Date | null;
|
|
24
|
-
export declare function formatDotlessDate(
|
|
25
|
+
export declare function formatDotlessDate(date: Date | string | number): string;
|
package/dist/index.common.js
CHANGED
|
@@ -9432,6 +9432,9 @@ if(freeModule){// Export for Node.js.
|
|
|
9432
9432
|
freeExports._=_;}else {// Export to the global object.
|
|
9433
9433
|
root._=_;}}).call(commonjsGlobal);});
|
|
9434
9434
|
|
|
9435
|
+
function isNonEmptyArray(value) {
|
|
9436
|
+
return value.length > 0;
|
|
9437
|
+
}
|
|
9435
9438
|
/**
|
|
9436
9439
|
* Return a new array that does not contain the item at the specified index.
|
|
9437
9440
|
*/
|
|
@@ -9459,6 +9462,10 @@ Object.freeze(EMPTY_ARRAY);
|
|
|
9459
9462
|
function insertIf(condition, ...elements) {
|
|
9460
9463
|
return condition ? elements : [];
|
|
9461
9464
|
}
|
|
9465
|
+
function last(array) {
|
|
9466
|
+
// @ts-expect-error too magical
|
|
9467
|
+
return array[array.length - 1];
|
|
9468
|
+
}
|
|
9462
9469
|
|
|
9463
9470
|
function toInteger(dirtyNumber) {
|
|
9464
9471
|
if (dirtyNumber === null || dirtyNumber === true || dirtyNumber === false) {
|
|
@@ -12339,6 +12346,43 @@ function cleanEscapedString$1(input) {
|
|
|
12339
12346
|
return input.match(escapedStringRegExp$1)[1].replace(doubleQuoteRegExp$1, "'");
|
|
12340
12347
|
}
|
|
12341
12348
|
|
|
12349
|
+
/**
|
|
12350
|
+
* @name isAfter
|
|
12351
|
+
* @category Common Helpers
|
|
12352
|
+
* @summary Is the first date after the second one?
|
|
12353
|
+
*
|
|
12354
|
+
* @description
|
|
12355
|
+
* Is the first date after the second one?
|
|
12356
|
+
*
|
|
12357
|
+
*
|
|
12358
|
+
* ### v2.0.0 breaking changes:
|
|
12359
|
+
*
|
|
12360
|
+
* - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
|
|
12361
|
+
*
|
|
12362
|
+
* @param {Date|String|Number} date - the date that should be after the other one to return true
|
|
12363
|
+
* @param {Date|String|Number} dateToCompare - the date to compare with
|
|
12364
|
+
* @param {Options} [options] - the object with options. See [Options]{@link https://date-fns.org/docs/Options}
|
|
12365
|
+
* @param {0|1|2} [options.additionalDigits=2] - passed to `toDate`. See [toDate]{@link https://date-fns.org/docs/toDate}
|
|
12366
|
+
* @returns {Boolean} the first date is after the second date
|
|
12367
|
+
* @throws {TypeError} 2 arguments required
|
|
12368
|
+
* @throws {RangeError} `options.additionalDigits` must be 0, 1 or 2
|
|
12369
|
+
*
|
|
12370
|
+
* @example
|
|
12371
|
+
* // Is 10 July 1989 after 11 February 1987?
|
|
12372
|
+
* var result = isAfter(new Date(1989, 6, 10), new Date(1987, 1, 11))
|
|
12373
|
+
* //=> true
|
|
12374
|
+
*/
|
|
12375
|
+
|
|
12376
|
+
function isAfter(dirtyDate, dirtyDateToCompare, dirtyOptions) {
|
|
12377
|
+
if (arguments.length < 2) {
|
|
12378
|
+
throw new TypeError('2 arguments required, but only ' + arguments.length + ' present');
|
|
12379
|
+
}
|
|
12380
|
+
|
|
12381
|
+
var date = toDate(dirtyDate, dirtyOptions);
|
|
12382
|
+
var dateToCompare = toDate(dirtyDateToCompare, dirtyOptions);
|
|
12383
|
+
return date.getTime() > dateToCompare.getTime();
|
|
12384
|
+
}
|
|
12385
|
+
|
|
12342
12386
|
// See issue: https://github.com/date-fns/date-fns/issues/376
|
|
12343
12387
|
|
|
12344
12388
|
function setUTCDay(dirtyDate, dirtyDay, dirtyOptions) {
|
|
@@ -15007,6 +15051,9 @@ var de$1 = /*@__PURE__*/getDefaultExportFromCjs(de);
|
|
|
15007
15051
|
function isToday(date) {
|
|
15008
15052
|
return differenceInCalendarDays(new Date(), date) === 0;
|
|
15009
15053
|
}
|
|
15054
|
+
function isFuture(date) {
|
|
15055
|
+
return isAfter(date, new Date());
|
|
15056
|
+
}
|
|
15010
15057
|
function parseDate(value, formatString) {
|
|
15011
15058
|
const parsedDate = parse(value, formatString, new Date());
|
|
15012
15059
|
return isValid(parsedDate) ? parsedDate : null;
|
|
@@ -15039,8 +15086,8 @@ const SECONDLESS_DATE_TIME_FORMAT = 'y-MM-dd HH:mm';
|
|
|
15039
15086
|
function parseSecondlessDateTime(value) {
|
|
15040
15087
|
return parseDate(value, SECONDLESS_DATE_TIME_FORMAT);
|
|
15041
15088
|
}
|
|
15042
|
-
function formatSecondlessDateTime(
|
|
15043
|
-
return format(
|
|
15089
|
+
function formatSecondlessDateTime(date) {
|
|
15090
|
+
return format(date, SECONDLESS_DATE_TIME_FORMAT, { locale: de$1 });
|
|
15044
15091
|
}
|
|
15045
15092
|
const GERMAN_DATE_TIME_FORMAT = 'dd.MM.y HH:mm';
|
|
15046
15093
|
function parseGermanDateTime(value) {
|
|
@@ -15053,15 +15100,15 @@ const ISO_DATE_TIME_FORMAT = 'y-MM-dd HH:mm:ss';
|
|
|
15053
15100
|
function parseIsoDateTime(value) {
|
|
15054
15101
|
return parseDate(value, ISO_DATE_TIME_FORMAT);
|
|
15055
15102
|
}
|
|
15056
|
-
function formatIsoDateTime(
|
|
15057
|
-
return format(
|
|
15103
|
+
function formatIsoDateTime(date) {
|
|
15104
|
+
return format(date, ISO_DATE_TIME_FORMAT, { locale: de$1 });
|
|
15058
15105
|
}
|
|
15059
15106
|
const DOTLESS_DATE_FORMAT = 'yMMdd';
|
|
15060
15107
|
function parseDotlessDate(value) {
|
|
15061
15108
|
return parseDate(value, DOTLESS_DATE_FORMAT);
|
|
15062
15109
|
}
|
|
15063
|
-
function formatDotlessDate(
|
|
15064
|
-
return format(
|
|
15110
|
+
function formatDotlessDate(date) {
|
|
15111
|
+
return format(date, DOTLESS_DATE_FORMAT, { locale: de$1 });
|
|
15065
15112
|
}
|
|
15066
15113
|
|
|
15067
15114
|
function pluralize(amount, singular, plural) {
|
|
@@ -15114,6 +15161,16 @@ function round(number, decimalPlaces) {
|
|
|
15114
15161
|
return Math.round(number * factorOfTen) / factorOfTen;
|
|
15115
15162
|
}
|
|
15116
15163
|
|
|
15164
|
+
function includesIgnoreCase(needle, haystack) {
|
|
15165
|
+
if (haystack instanceof Array) {
|
|
15166
|
+
return haystack.some((hay) => includesIgnoreCase(needle, hay));
|
|
15167
|
+
}
|
|
15168
|
+
return haystack.toLowerCase().includes(needle.toLowerCase());
|
|
15169
|
+
}
|
|
15170
|
+
function firstLine(multilineText) {
|
|
15171
|
+
return multilineText.split('\n', 1)[0];
|
|
15172
|
+
}
|
|
15173
|
+
|
|
15117
15174
|
exports.DOTLESS_DATE_FORMAT = DOTLESS_DATE_FORMAT;
|
|
15118
15175
|
exports.EMAIL_REGEX = EMAIL_REGEX;
|
|
15119
15176
|
exports.EMPTY_ARRAY = EMPTY_ARRAY;
|
|
@@ -15124,6 +15181,7 @@ exports.ISO_DATE_FORMAT = ISO_DATE_FORMAT;
|
|
|
15124
15181
|
exports.ISO_DATE_TIME_FORMAT = ISO_DATE_TIME_FORMAT;
|
|
15125
15182
|
exports.SECONDLESS_DATE_TIME_FORMAT = SECONDLESS_DATE_TIME_FORMAT;
|
|
15126
15183
|
exports.containSameValues = containSameValues;
|
|
15184
|
+
exports.firstLine = firstLine;
|
|
15127
15185
|
exports.formatDotlessDate = formatDotlessDate;
|
|
15128
15186
|
exports.formatGerman = formatGerman;
|
|
15129
15187
|
exports.formatGermanDateTime = formatGermanDateTime;
|
|
@@ -15131,17 +15189,21 @@ exports.formatGermanDotlessDate = formatGermanDotlessDate;
|
|
|
15131
15189
|
exports.formatIsoDate = formatIsoDate;
|
|
15132
15190
|
exports.formatIsoDateTime = formatIsoDateTime;
|
|
15133
15191
|
exports.formatSecondlessDateTime = formatSecondlessDateTime;
|
|
15192
|
+
exports.includesIgnoreCase = includesIgnoreCase;
|
|
15134
15193
|
exports.insertIf = insertIf;
|
|
15135
15194
|
exports.isAlphanumeric = isAlphanumeric;
|
|
15136
15195
|
exports.isBSNR = isBSNR;
|
|
15137
15196
|
exports.isEmail = isEmail;
|
|
15197
|
+
exports.isFuture = isFuture;
|
|
15138
15198
|
exports.isLabId = isLabId;
|
|
15199
|
+
exports.isNonEmptyArray = isNonEmptyArray;
|
|
15139
15200
|
exports.isOnlyDigits = isOnlyDigits;
|
|
15140
15201
|
exports.isRackBarcode = isRackBarcode;
|
|
15141
15202
|
exports.isString = isString;
|
|
15142
15203
|
exports.isToday = isToday;
|
|
15143
15204
|
exports.isURL = isURL;
|
|
15144
15205
|
exports.isWord = isWord;
|
|
15206
|
+
exports.last = last;
|
|
15145
15207
|
exports.parseDate = parseDate;
|
|
15146
15208
|
exports.parseDotlessDate = parseDotlessDate;
|
|
15147
15209
|
exports.parseGermanDate = parseGermanDate;
|