@naturalcycles/js-lib
Advanced tools
Comparing version 14.239.0 to 14.240.0
import { _assert } from '../error/assert'; | ||
import { _isTruthy } from '../is.util'; | ||
import { Iterable2 } from '../iter/iterable2'; | ||
@@ -536,4 +537,7 @@ import { localTime } from './localTime'; | ||
min(items) { | ||
_assert(items.length, 'localDate.min called on empty array'); | ||
return items.map(i => this.of(i)).reduce((min, item) => (min.isSameOrBefore(item) ? min : item)); | ||
const items2 = items.filter(_isTruthy); | ||
_assert(items2.length, 'localDate.min called on empty array'); | ||
return items2 | ||
.map(i => this.of(i)) | ||
.reduce((min, item) => (min.isSameOrBefore(item) ? min : item)); | ||
} | ||
@@ -551,4 +555,5 @@ /** | ||
max(items) { | ||
_assert(items.length, 'localDate.max called on empty array'); | ||
return items.map(i => this.of(i)).reduce((max, item) => (max.isSameOrAfter(item) ? max : item)); | ||
const items2 = items.filter(_isTruthy); | ||
_assert(items2.length, 'localDate.max called on empty array'); | ||
return items2.map(i => this.of(i)).reduce((max, item) => (max.isSameOrAfter(item) ? max : item)); | ||
} | ||
@@ -555,0 +560,0 @@ /** |
import { _assert } from '../error/assert'; | ||
import { _isTruthy } from '../is.util'; | ||
import { _ms } from '../time/time.util'; | ||
@@ -704,4 +705,5 @@ import { localDate } from './localDate'; | ||
min(items) { | ||
_assert(items.length, 'localTime.min called on empty array'); | ||
return items | ||
const items2 = items.filter(_isTruthy); | ||
_assert(items2.length, 'localTime.min called on empty array'); | ||
return items2 | ||
.map(i => this.of(i)) | ||
@@ -714,4 +716,5 @@ .reduce((min, item) => (min.$date.valueOf() <= item.$date.valueOf() ? min : item)); | ||
max(items) { | ||
_assert(items.length, 'localTime.max called on empty array'); | ||
return items | ||
const items2 = items.filter(_isTruthy); | ||
_assert(items2.length, 'localTime.max called on empty array'); | ||
return items2 | ||
.map(i => this.of(i)) | ||
@@ -718,0 +721,0 @@ .reduce((max, item) => (max.$date.valueOf() >= item.$date.valueOf() ? max : item)); |
import { _range } from './array/range'; | ||
import { _assert } from './error/assert'; | ||
import { _isTruthy } from './is.util'; | ||
/** | ||
@@ -85,4 +86,5 @@ * Simple Semver implementation. | ||
max(items) { | ||
_assert(items.length, 'semver.max called on empty array'); | ||
return items.map(i => this.of(i)).reduce((max, item) => (max.isSameOrAfter(item) ? max : item)); | ||
const items2 = items.filter(_isTruthy); | ||
_assert(items2.length, 'semver.max called on empty array'); | ||
return items2.map(i => this.of(i)).reduce((max, item) => (max.isSameOrAfter(item) ? max : item)); | ||
} | ||
@@ -100,5 +102,15 @@ /** | ||
min(items) { | ||
_assert(items.length, 'semver.min called on empty array'); | ||
return items.map(i => this.of(i)).reduce((min, item) => (min.isSameOrBefore(item) ? min : item)); | ||
const items2 = items.filter(_isTruthy); | ||
_assert(items2.length, 'semver.min called on empty array'); | ||
return items2 | ||
.map(i => this.of(i)) | ||
.reduce((min, item) => (min.isSameOrBefore(item) ? min : item)); | ||
} | ||
/** | ||
* Sorts an array of Semvers in `dir` order (ascending by default). | ||
*/ | ||
sort(items, dir = 'asc', mutate = false) { | ||
const mod = dir === 'desc' ? -1 : 1; | ||
return (mutate ? items : [...items]).sort((a, b) => a.cmp(b) * mod); | ||
} | ||
} | ||
@@ -105,0 +117,0 @@ const semverFactory = new SemverFactory(); |
@@ -7,2 +7,3 @@ import { Iterable2 } from '../iter/iterable2'; | ||
export type LocalDateInput = LocalDate | Date | IsoDateString; | ||
export type LocalDateInputNullable = LocalDateInput | null | undefined; | ||
export type LocalDateFormatter = (ld: LocalDate) => string; | ||
@@ -170,3 +171,3 @@ /** | ||
*/ | ||
parseOrNull(d: LocalDateInput | undefined | null): LocalDate | null; | ||
parseOrNull(d: LocalDateInputNullable): LocalDate | null; | ||
/** | ||
@@ -209,3 +210,3 @@ * Parses "compact iso8601 format", e.g `19840621` into LocalDate. | ||
*/ | ||
minOrUndefined(items: LocalDateInput[]): LocalDate | undefined; | ||
minOrUndefined(items: LocalDateInputNullable[]): LocalDate | undefined; | ||
/** | ||
@@ -215,7 +216,7 @@ * Returns the earliest LocalDate from the array. | ||
*/ | ||
min(items: LocalDateInput[]): LocalDate; | ||
min(items: LocalDateInputNullable[]): LocalDate; | ||
/** | ||
* Returns the latest (max) LocalDate from the array, or undefined if the array is empty. | ||
*/ | ||
maxOrUndefined(items: LocalDateInput[]): LocalDate | undefined; | ||
maxOrUndefined(items: LocalDateInputNullable[]): LocalDate | undefined; | ||
/** | ||
@@ -225,3 +226,3 @@ * Returns the latest LocalDate from the array. | ||
*/ | ||
max(items: LocalDateInput[]): LocalDate; | ||
max(items: LocalDateInputNullable[]): LocalDate; | ||
/** | ||
@@ -242,7 +243,7 @@ * Returns the range (array) of LocalDates between min and max. | ||
*/ | ||
orUndefined(d: LocalDateInput | null | undefined): LocalDate | undefined; | ||
orUndefined(d: LocalDateInputNullable): LocalDate | undefined; | ||
/** | ||
* Creates a LocalDate from the input, unless it's falsy - then returns localDate.today. | ||
*/ | ||
orToday(d: LocalDateInput | null | undefined): LocalDate; | ||
orToday(d: LocalDateInputNullable): LocalDate; | ||
} | ||
@@ -249,0 +250,0 @@ interface LocalDateFn extends LocalDateFactory { |
@@ -5,2 +5,3 @@ "use strict"; | ||
const assert_1 = require("../error/assert"); | ||
const is_util_1 = require("../is.util"); | ||
const iterable2_1 = require("../iter/iterable2"); | ||
@@ -541,4 +542,7 @@ const localTime_1 = require("./localTime"); | ||
min(items) { | ||
(0, assert_1._assert)(items.length, 'localDate.min called on empty array'); | ||
return items.map(i => this.of(i)).reduce((min, item) => (min.isSameOrBefore(item) ? min : item)); | ||
const items2 = items.filter(is_util_1._isTruthy); | ||
(0, assert_1._assert)(items2.length, 'localDate.min called on empty array'); | ||
return items2 | ||
.map(i => this.of(i)) | ||
.reduce((min, item) => (min.isSameOrBefore(item) ? min : item)); | ||
} | ||
@@ -556,4 +560,5 @@ /** | ||
max(items) { | ||
(0, assert_1._assert)(items.length, 'localDate.max called on empty array'); | ||
return items.map(i => this.of(i)).reduce((max, item) => (max.isSameOrAfter(item) ? max : item)); | ||
const items2 = items.filter(is_util_1._isTruthy); | ||
(0, assert_1._assert)(items2.length, 'localDate.max called on empty array'); | ||
return items2.map(i => this.of(i)).reduce((max, item) => (max.isSameOrAfter(item) ? max : item)); | ||
} | ||
@@ -560,0 +565,0 @@ /** |
@@ -15,2 +15,3 @@ import type { Inclusiveness, IsoDateString, IsoDateTimeString, MonthId, NumberOfHours, NumberOfMinutes, SortDirection, UnixTimestampMillisNumber, UnixTimestampNumber } from '../types'; | ||
export type LocalTimeInput = LocalTime | Date | IsoDateTimeString | UnixTimestampNumber; | ||
export type LocalTimeInputNullable = LocalTimeInput | null | undefined; | ||
export type LocalTimeFormatter = (ld: LocalTime) => string; | ||
@@ -230,6 +231,6 @@ export type DateTimeObject = DateObject & TimeObject; | ||
*/ | ||
parseOrNull(d: LocalTimeInput | undefined | null): LocalTime | null; | ||
parseOrNull(d: LocalTimeInputNullable): LocalTime | null; | ||
parseToDate(d: LocalTimeInput): Date; | ||
parseToUnixTimestamp(d: LocalTimeInput): UnixTimestampNumber; | ||
isValid(d: LocalTimeInput | undefined | null): boolean; | ||
isValid(d: LocalTimeInputNullable): boolean; | ||
/** | ||
@@ -254,7 +255,7 @@ * Returns the IANA timezone e.g `Europe/Stockholm`. | ||
*/ | ||
orUndefined(d: LocalTimeInput | null | undefined): LocalTime | undefined; | ||
orUndefined(d: LocalTimeInputNullable): LocalTime | undefined; | ||
/** | ||
* Creates a LocalTime from the input, unless it's falsy - then returns LocalTime.now | ||
*/ | ||
orNow(d: LocalTimeInput | null | undefined): LocalTime; | ||
orNow(d: LocalTimeInputNullable): LocalTime; | ||
fromComponents(c: { | ||
@@ -265,6 +266,6 @@ year: number; | ||
sort(items: LocalTime[], dir?: SortDirection, mutate?: boolean): LocalTime[]; | ||
minOrUndefined(items: LocalTimeInput[]): LocalTime | undefined; | ||
min(items: LocalTimeInput[]): LocalTime; | ||
maxOrUndefined(items: LocalTimeInput[]): LocalTime | undefined; | ||
max(items: LocalTimeInput[]): LocalTime; | ||
minOrUndefined(items: LocalTimeInputNullable[]): LocalTime | undefined; | ||
min(items: LocalTimeInputNullable[]): LocalTime; | ||
maxOrUndefined(items: LocalTimeInputNullable[]): LocalTime | undefined; | ||
max(items: LocalTimeInputNullable[]): LocalTime; | ||
} | ||
@@ -271,0 +272,0 @@ interface LocalTimeFn extends LocalTimeFactory { |
@@ -5,2 +5,3 @@ "use strict"; | ||
const assert_1 = require("../error/assert"); | ||
const is_util_1 = require("../is.util"); | ||
const time_util_1 = require("../time/time.util"); | ||
@@ -709,4 +710,5 @@ const localDate_1 = require("./localDate"); | ||
min(items) { | ||
(0, assert_1._assert)(items.length, 'localTime.min called on empty array'); | ||
return items | ||
const items2 = items.filter(is_util_1._isTruthy); | ||
(0, assert_1._assert)(items2.length, 'localTime.min called on empty array'); | ||
return items2 | ||
.map(i => this.of(i)) | ||
@@ -719,4 +721,5 @@ .reduce((min, item) => (min.$date.valueOf() <= item.$date.valueOf() ? min : item)); | ||
max(items) { | ||
(0, assert_1._assert)(items.length, 'localTime.max called on empty array'); | ||
return items | ||
const items2 = items.filter(is_util_1._isTruthy); | ||
(0, assert_1._assert)(items2.length, 'localTime.max called on empty array'); | ||
return items2 | ||
.map(i => this.of(i)) | ||
@@ -723,0 +726,0 @@ .reduce((max, item) => (max.$date.valueOf() >= item.$date.valueOf() ? max : item)); |
@@ -0,2 +1,4 @@ | ||
import { SortDirection } from './types'; | ||
export type SemverInput = string | Semver; | ||
export type SemverInputNullable = SemverInput | null | undefined; | ||
export type SemverTokens = [major: number, minor: number, patch: number]; | ||
@@ -41,7 +43,7 @@ /** | ||
of(input: SemverInput): Semver; | ||
parseOrNull(input: SemverInput | undefined | null): Semver | null; | ||
parseOrNull(input: SemverInputNullable): Semver | null; | ||
/** | ||
* Returns the highest (max) Semver from the array, or undefined if the array is empty. | ||
*/ | ||
maxOrUndefined(items: SemverInput[]): Semver | undefined; | ||
maxOrUndefined(items: SemverInputNullable[]): Semver | undefined; | ||
/** | ||
@@ -51,7 +53,7 @@ * Returns the highest Semver from the array. | ||
*/ | ||
max(items: SemverInput[]): Semver; | ||
max(items: SemverInputNullable[]): Semver; | ||
/** | ||
* Returns the lowest (min) Semver from the array, or undefined if the array is empty. | ||
*/ | ||
minOrUndefined(items: SemverInput[]): Semver | undefined; | ||
minOrUndefined(items: SemverInputNullable[]): Semver | undefined; | ||
/** | ||
@@ -61,3 +63,7 @@ * Returns the lowest Semver from the array. | ||
*/ | ||
min(items: SemverInput[]): Semver; | ||
min(items: SemverInputNullable[]): Semver; | ||
/** | ||
* Sorts an array of Semvers in `dir` order (ascending by default). | ||
*/ | ||
sort(items: Semver[], dir?: SortDirection, mutate?: boolean): Semver[]; | ||
} | ||
@@ -64,0 +70,0 @@ interface SemverFn extends SemverFactory { |
@@ -6,2 +6,3 @@ "use strict"; | ||
const assert_1 = require("./error/assert"); | ||
const is_util_1 = require("./is.util"); | ||
/** | ||
@@ -90,4 +91,5 @@ * Simple Semver implementation. | ||
max(items) { | ||
(0, assert_1._assert)(items.length, 'semver.max called on empty array'); | ||
return items.map(i => this.of(i)).reduce((max, item) => (max.isSameOrAfter(item) ? max : item)); | ||
const items2 = items.filter(is_util_1._isTruthy); | ||
(0, assert_1._assert)(items2.length, 'semver.max called on empty array'); | ||
return items2.map(i => this.of(i)).reduce((max, item) => (max.isSameOrAfter(item) ? max : item)); | ||
} | ||
@@ -105,5 +107,15 @@ /** | ||
min(items) { | ||
(0, assert_1._assert)(items.length, 'semver.min called on empty array'); | ||
return items.map(i => this.of(i)).reduce((min, item) => (min.isSameOrBefore(item) ? min : item)); | ||
const items2 = items.filter(is_util_1._isTruthy); | ||
(0, assert_1._assert)(items2.length, 'semver.min called on empty array'); | ||
return items2 | ||
.map(i => this.of(i)) | ||
.reduce((min, item) => (min.isSameOrBefore(item) ? min : item)); | ||
} | ||
/** | ||
* Sorts an array of Semvers in `dir` order (ascending by default). | ||
*/ | ||
sort(items, dir = 'asc', mutate = false) { | ||
const mod = dir === 'desc' ? -1 : 1; | ||
return (mutate ? items : [...items]).sort((a, b) => a.cmp(b) * mod); | ||
} | ||
} | ||
@@ -110,0 +122,0 @@ const semverFactory = new SemverFactory(); |
{ | ||
"name": "@naturalcycles/js-lib", | ||
"version": "14.239.0", | ||
"version": "14.240.0", | ||
"scripts": { | ||
@@ -5,0 +5,0 @@ "prepare": "husky", |
import { _assert } from '../error/assert' | ||
import { _isTruthy } from '../is.util' | ||
import { Iterable2 } from '../iter/iterable2' | ||
@@ -21,2 +22,3 @@ import type { | ||
export type LocalDateInput = LocalDate | Date | IsoDateString | ||
export type LocalDateInputNullable = LocalDateInput | null | undefined | ||
export type LocalDateFormatter = (ld: LocalDate) => string | ||
@@ -521,3 +523,3 @@ | ||
*/ | ||
parseOrNull(d: LocalDateInput | undefined | null): LocalDate | null { | ||
parseOrNull(d: LocalDateInputNullable): LocalDate | null { | ||
if (!d) return null | ||
@@ -624,3 +626,3 @@ if (d instanceof LocalDate) return d | ||
*/ | ||
minOrUndefined(items: LocalDateInput[]): LocalDate | undefined { | ||
minOrUndefined(items: LocalDateInputNullable[]): LocalDate | undefined { | ||
return items.length ? this.min(items) : undefined | ||
@@ -633,6 +635,9 @@ } | ||
*/ | ||
min(items: LocalDateInput[]): LocalDate { | ||
_assert(items.length, 'localDate.min called on empty array') | ||
min(items: LocalDateInputNullable[]): LocalDate { | ||
const items2 = items.filter(_isTruthy) | ||
_assert(items2.length, 'localDate.min called on empty array') | ||
return items.map(i => this.of(i)).reduce((min, item) => (min.isSameOrBefore(item) ? min : item)) | ||
return items2 | ||
.map(i => this.of(i)) | ||
.reduce((min, item) => (min.isSameOrBefore(item) ? min : item)) | ||
} | ||
@@ -643,3 +648,3 @@ | ||
*/ | ||
maxOrUndefined(items: LocalDateInput[]): LocalDate | undefined { | ||
maxOrUndefined(items: LocalDateInputNullable[]): LocalDate | undefined { | ||
return items.length ? this.max(items) : undefined | ||
@@ -652,6 +657,7 @@ } | ||
*/ | ||
max(items: LocalDateInput[]): LocalDate { | ||
_assert(items.length, 'localDate.max called on empty array') | ||
max(items: LocalDateInputNullable[]): LocalDate { | ||
const items2 = items.filter(_isTruthy) | ||
_assert(items2.length, 'localDate.max called on empty array') | ||
return items.map(i => this.of(i)).reduce((max, item) => (max.isSameOrAfter(item) ? max : item)) | ||
return items2.map(i => this.of(i)).reduce((max, item) => (max.isSameOrAfter(item) ? max : item)) | ||
} | ||
@@ -720,3 +726,3 @@ | ||
*/ | ||
orUndefined(d: LocalDateInput | null | undefined): LocalDate | undefined { | ||
orUndefined(d: LocalDateInputNullable): LocalDate | undefined { | ||
return d ? this.of(d) : undefined | ||
@@ -728,3 +734,3 @@ } | ||
*/ | ||
orToday(d: LocalDateInput | null | undefined): LocalDate { | ||
orToday(d: LocalDateInputNullable): LocalDate { | ||
return d ? this.of(d) : this.today() | ||
@@ -731,0 +737,0 @@ } |
import { _assert } from '../error/assert' | ||
import { _isTruthy } from '../is.util' | ||
import { _ms } from '../time/time.util' | ||
@@ -30,2 +31,3 @@ import type { | ||
export type LocalTimeInput = LocalTime | Date | IsoDateTimeString | UnixTimestampNumber | ||
export type LocalTimeInputNullable = LocalTimeInput | null | undefined | ||
export type LocalTimeFormatter = (ld: LocalTime) => string | ||
@@ -715,3 +717,3 @@ | ||
*/ | ||
parseOrNull(d: LocalTimeInput | undefined | null): LocalTime | null { | ||
parseOrNull(d: LocalTimeInputNullable): LocalTime | null { | ||
if (!d) return null | ||
@@ -773,3 +775,3 @@ if (d instanceof LocalTime) return d | ||
isValid(d: LocalTimeInput | undefined | null): boolean { | ||
isValid(d: LocalTimeInputNullable): boolean { | ||
return this.parseOrNull(d) !== null | ||
@@ -806,3 +808,3 @@ } | ||
*/ | ||
orUndefined(d: LocalTimeInput | null | undefined): LocalTime | undefined { | ||
orUndefined(d: LocalTimeInputNullable): LocalTime | undefined { | ||
return d ? this.of(d) : undefined | ||
@@ -814,3 +816,3 @@ } | ||
*/ | ||
orNow(d: LocalTimeInput | null | undefined): LocalTime { | ||
orNow(d: LocalTimeInputNullable): LocalTime { | ||
return d ? this.of(d) : this.now() | ||
@@ -835,10 +837,11 @@ } | ||
minOrUndefined(items: LocalTimeInput[]): LocalTime | undefined { | ||
minOrUndefined(items: LocalTimeInputNullable[]): LocalTime | undefined { | ||
return items.length ? this.min(items) : undefined | ||
} | ||
min(items: LocalTimeInput[]): LocalTime { | ||
_assert(items.length, 'localTime.min called on empty array') | ||
min(items: LocalTimeInputNullable[]): LocalTime { | ||
const items2 = items.filter(_isTruthy) | ||
_assert(items2.length, 'localTime.min called on empty array') | ||
return items | ||
return items2 | ||
.map(i => this.of(i)) | ||
@@ -848,10 +851,11 @@ .reduce((min, item) => (min.$date.valueOf() <= item.$date.valueOf() ? min : item)) | ||
maxOrUndefined(items: LocalTimeInput[]): LocalTime | undefined { | ||
maxOrUndefined(items: LocalTimeInputNullable[]): LocalTime | undefined { | ||
return items.length ? this.max(items) : undefined | ||
} | ||
max(items: LocalTimeInput[]): LocalTime { | ||
_assert(items.length, 'localTime.max called on empty array') | ||
max(items: LocalTimeInputNullable[]): LocalTime { | ||
const items2 = items.filter(_isTruthy) | ||
_assert(items2.length, 'localTime.max called on empty array') | ||
return items | ||
return items2 | ||
.map(i => this.of(i)) | ||
@@ -858,0 +862,0 @@ .reduce((max, item) => (max.$date.valueOf() >= item.$date.valueOf() ? max : item)) |
import { _range } from './array/range' | ||
import { _assert } from './error/assert' | ||
import { _isTruthy } from './is.util' | ||
import { SortDirection } from './types' | ||
export type SemverInput = string | Semver | ||
export type SemverInputNullable = SemverInput | null | undefined | ||
export type SemverTokens = [major: number, minor: number, patch: number] | ||
@@ -75,3 +78,3 @@ | ||
parseOrNull(input: SemverInput | undefined | null): Semver | null { | ||
parseOrNull(input: SemverInputNullable): Semver | null { | ||
if (!input) return null | ||
@@ -87,3 +90,3 @@ if (input instanceof Semver) return input | ||
*/ | ||
maxOrUndefined(items: SemverInput[]): Semver | undefined { | ||
maxOrUndefined(items: SemverInputNullable[]): Semver | undefined { | ||
return items.length ? this.max(items) : undefined | ||
@@ -96,5 +99,6 @@ } | ||
*/ | ||
max(items: SemverInput[]): Semver { | ||
_assert(items.length, 'semver.max called on empty array') | ||
return items.map(i => this.of(i)).reduce((max, item) => (max.isSameOrAfter(item) ? max : item)) | ||
max(items: SemverInputNullable[]): Semver { | ||
const items2 = items.filter(_isTruthy) | ||
_assert(items2.length, 'semver.max called on empty array') | ||
return items2.map(i => this.of(i)).reduce((max, item) => (max.isSameOrAfter(item) ? max : item)) | ||
} | ||
@@ -105,3 +109,3 @@ | ||
*/ | ||
minOrUndefined(items: SemverInput[]): Semver | undefined { | ||
minOrUndefined(items: SemverInputNullable[]): Semver | undefined { | ||
return items.length ? this.min(items) : undefined | ||
@@ -114,6 +118,17 @@ } | ||
*/ | ||
min(items: SemverInput[]): Semver { | ||
_assert(items.length, 'semver.min called on empty array') | ||
return items.map(i => this.of(i)).reduce((min, item) => (min.isSameOrBefore(item) ? min : item)) | ||
min(items: SemverInputNullable[]): Semver { | ||
const items2 = items.filter(_isTruthy) | ||
_assert(items2.length, 'semver.min called on empty array') | ||
return items2 | ||
.map(i => this.of(i)) | ||
.reduce((min, item) => (min.isSameOrBefore(item) ? min : item)) | ||
} | ||
/** | ||
* Sorts an array of Semvers in `dir` order (ascending by default). | ||
*/ | ||
sort(items: Semver[], dir: SortDirection = 'asc', mutate = false): Semver[] { | ||
const mod = dir === 'desc' ? -1 : 1 | ||
return (mutate ? items : [...items]).sort((a, b) => a.cmp(b) * mod) | ||
} | ||
} | ||
@@ -120,0 +135,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1051442
31617