@naturalcycles/js-lib 14.211.0 → 14.213.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/array.util.d.ts +5 -0
- package/dist/array/array.util.js +11 -1
- package/dist/datetime/localDate.d.ts +2 -1
- package/dist/datetime/localDate.js +3 -0
- package/dist-esm/array/array.util.js +9 -0
- package/dist-esm/datetime/localDate.js +3 -0
- package/package.json +2 -2
- package/src/array/array.util.ts +9 -0
- package/src/datetime/localDate.ts +5 -1
|
@@ -176,6 +176,11 @@ export declare function _last<T>(array: T[]): T;
|
|
|
176
176
|
* Returns last item of the array (or undefined if array is empty).
|
|
177
177
|
*/
|
|
178
178
|
export declare function _lastOrUndefined<T>(array: T[]): T | undefined;
|
|
179
|
+
/**
|
|
180
|
+
* Returns the first item of non-empty array.
|
|
181
|
+
* Throws if array is empty.
|
|
182
|
+
*/
|
|
183
|
+
export declare function _first<T>(array: T[]): T;
|
|
179
184
|
export declare function _minOrUndefined<T>(array: T[]): NonNullable<T> | undefined;
|
|
180
185
|
/**
|
|
181
186
|
* Filters out nullish values (undefined and null).
|
package/dist/array/array.util.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports._zip = exports._minByOrUndefined = exports._maxByOrUndefined = exports._minBy = exports._maxBy = exports._max = exports._maxOrUndefined = exports._min = exports._minOrUndefined = exports._lastOrUndefined = exports._last = exports._shuffle = exports._mapToObject = exports._sumBy = exports._sum = exports._difference = exports._intersectsWith = exports._intersection = exports._countBy = exports._count = exports._dropRightWhile = exports._dropWhile = exports._takeRightWhile = exports._takeWhile = exports._findLast = exports._sortDescBy = exports._sortBy = exports._groupBy = exports._mapBy = exports._by = exports._uniqBy = exports._pushUniqBy = exports._pushUniq = exports._uniq = exports._chunk = void 0;
|
|
3
|
+
exports._zip = exports._minByOrUndefined = exports._maxByOrUndefined = exports._minBy = exports._maxBy = exports._max = exports._maxOrUndefined = exports._min = exports._minOrUndefined = exports._first = exports._lastOrUndefined = exports._last = exports._shuffle = exports._mapToObject = exports._sumBy = exports._sum = exports._difference = exports._intersectsWith = exports._intersection = exports._countBy = exports._count = exports._dropRightWhile = exports._dropWhile = exports._takeRightWhile = exports._takeWhile = exports._findLast = exports._sortDescBy = exports._sortBy = exports._groupBy = exports._mapBy = exports._by = exports._uniqBy = exports._pushUniqBy = exports._pushUniq = exports._uniq = exports._chunk = void 0;
|
|
4
4
|
const is_util_1 = require("../is.util");
|
|
5
5
|
const types_1 = require("../types");
|
|
6
6
|
/**
|
|
@@ -333,6 +333,16 @@ function _lastOrUndefined(array) {
|
|
|
333
333
|
return array[array.length - 1];
|
|
334
334
|
}
|
|
335
335
|
exports._lastOrUndefined = _lastOrUndefined;
|
|
336
|
+
/**
|
|
337
|
+
* Returns the first item of non-empty array.
|
|
338
|
+
* Throws if array is empty.
|
|
339
|
+
*/
|
|
340
|
+
function _first(array) {
|
|
341
|
+
if (!array.length)
|
|
342
|
+
throw new Error('_first called on empty array');
|
|
343
|
+
return array[0];
|
|
344
|
+
}
|
|
345
|
+
exports._first = _first;
|
|
336
346
|
function _minOrUndefined(array) {
|
|
337
347
|
const a = array.filter(is_util_1._isNotNullish);
|
|
338
348
|
if (!a.length)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Iterable2 } from '../iter/iterable2';
|
|
2
2
|
import type { Inclusiveness, IsoDateString, IsoDateTimeString, MonthId, SortDirection, UnixTimestampMillisNumber, UnixTimestampNumber } from '../types';
|
|
3
|
-
import { LocalTime } from './localTime';
|
|
3
|
+
import { ISODayOfWeek, LocalTime } from './localTime';
|
|
4
4
|
export type LocalDateUnit = LocalDateUnitStrict | 'week';
|
|
5
5
|
export type LocalDateUnitStrict = 'year' | 'month' | 'day';
|
|
6
6
|
export type LocalDateInput = LocalDate | Date | IsoDateString;
|
|
@@ -42,6 +42,7 @@ export declare class LocalDate {
|
|
|
42
42
|
month(v: number): LocalDate;
|
|
43
43
|
day(): number;
|
|
44
44
|
day(v: number): LocalDate;
|
|
45
|
+
dayOfWeek(): ISODayOfWeek;
|
|
45
46
|
isSame(d: LocalDateInput): boolean;
|
|
46
47
|
isBefore(d: LocalDateInput, inclusive?: boolean): boolean;
|
|
47
48
|
isSameOrBefore(d: LocalDateInput): boolean;
|
|
@@ -129,6 +129,9 @@ class LocalDate {
|
|
|
129
129
|
day(v) {
|
|
130
130
|
return v === undefined ? this.$day : this.set('day', v);
|
|
131
131
|
}
|
|
132
|
+
dayOfWeek() {
|
|
133
|
+
return (this.toDate().getDay() || 7);
|
|
134
|
+
}
|
|
132
135
|
isSame(d) {
|
|
133
136
|
d = LocalDate.of(d);
|
|
134
137
|
return this.$day === d.$day && this.$month === d.$month && this.$year === d.$year;
|
|
@@ -304,6 +304,15 @@ export function _last(array) {
|
|
|
304
304
|
export function _lastOrUndefined(array) {
|
|
305
305
|
return array[array.length - 1];
|
|
306
306
|
}
|
|
307
|
+
/**
|
|
308
|
+
* Returns the first item of non-empty array.
|
|
309
|
+
* Throws if array is empty.
|
|
310
|
+
*/
|
|
311
|
+
export function _first(array) {
|
|
312
|
+
if (!array.length)
|
|
313
|
+
throw new Error('_first called on empty array');
|
|
314
|
+
return array[0];
|
|
315
|
+
}
|
|
307
316
|
export function _minOrUndefined(array) {
|
|
308
317
|
const a = array.filter(_isNotNullish);
|
|
309
318
|
if (!a.length)
|
|
@@ -126,6 +126,9 @@ export class LocalDate {
|
|
|
126
126
|
day(v) {
|
|
127
127
|
return v === undefined ? this.$day : this.set('day', v);
|
|
128
128
|
}
|
|
129
|
+
dayOfWeek() {
|
|
130
|
+
return (this.toDate().getDay() || 7);
|
|
131
|
+
}
|
|
129
132
|
isSame(d) {
|
|
130
133
|
d = LocalDate.of(d);
|
|
131
134
|
return this.$day === d.$day && this.$month === d.$month && this.$year === d.$year;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@naturalcycles/js-lib",
|
|
3
|
-
"version": "14.
|
|
3
|
+
"version": "14.213.0",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"prepare": "husky",
|
|
6
6
|
"build-prod": "build-prod-esm-cjs",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"crypto-js": "^4.1.1",
|
|
23
23
|
"jest": "^29.0.0",
|
|
24
24
|
"prettier": "^3.0.0",
|
|
25
|
-
"vitepress": "^1.0.0
|
|
25
|
+
"vitepress": "^1.0.0",
|
|
26
26
|
"vue": "^3.2.45"
|
|
27
27
|
},
|
|
28
28
|
"resolutions": {
|
package/src/array/array.util.ts
CHANGED
|
@@ -365,6 +365,15 @@ export function _lastOrUndefined<T>(array: T[]): T | undefined {
|
|
|
365
365
|
return array[array.length - 1]
|
|
366
366
|
}
|
|
367
367
|
|
|
368
|
+
/**
|
|
369
|
+
* Returns the first item of non-empty array.
|
|
370
|
+
* Throws if array is empty.
|
|
371
|
+
*/
|
|
372
|
+
export function _first<T>(array: T[]): T {
|
|
373
|
+
if (!array.length) throw new Error('_first called on empty array')
|
|
374
|
+
return array[0]!
|
|
375
|
+
}
|
|
376
|
+
|
|
368
377
|
export function _minOrUndefined<T>(array: T[]): NonNullable<T> | undefined {
|
|
369
378
|
const a = array.filter(_isNotNullish)
|
|
370
379
|
if (!a.length) return
|
|
@@ -9,7 +9,7 @@ import type {
|
|
|
9
9
|
UnixTimestampMillisNumber,
|
|
10
10
|
UnixTimestampNumber,
|
|
11
11
|
} from '../types'
|
|
12
|
-
import { LocalTime } from './localTime'
|
|
12
|
+
import { ISODayOfWeek, LocalTime } from './localTime'
|
|
13
13
|
|
|
14
14
|
export type LocalDateUnit = LocalDateUnitStrict | 'week'
|
|
15
15
|
export type LocalDateUnitStrict = 'year' | 'month' | 'day'
|
|
@@ -177,6 +177,10 @@ export class LocalDate {
|
|
|
177
177
|
return v === undefined ? this.$day : this.set('day', v)
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
+
dayOfWeek(): ISODayOfWeek {
|
|
181
|
+
return (this.toDate().getDay() || 7) as ISODayOfWeek
|
|
182
|
+
}
|
|
183
|
+
|
|
180
184
|
isSame(d: LocalDateInput): boolean {
|
|
181
185
|
d = LocalDate.of(d)
|
|
182
186
|
return this.$day === d.$day && this.$month === d.$month && this.$year === d.$year
|