diff --git a/package.json b/package.json index 63f729f..d617516 100644 --- a/package.json +++ b/package.json @@ -5,13 +5,12 @@ "build-prod": "build-prod-esm-cjs" }, "dependencies": { - "@naturalcycles/js-lib": "^14.6.1", + "@naturalcycles/js-lib": "^14.192.0", "dayjs": "^1.8.26" }, "devDependencies": { "@naturalcycles/bench-lib": "^1.0.4", "@naturalcycles/dev-lib": "^13.25.5", - "@naturalcycles/js-lib": "^14.6.1", "@naturalcycles/nodejs-lib": "^12.11.3", "@types/node": "^18.15.12", "jest": "^29.5.0", diff --git a/scripts/tsconfig.json b/scripts/tsconfig.json index 7c0412a..3011934 100644 --- a/scripts/tsconfig.json +++ b/scripts/tsconfig.json @@ -4,6 +4,7 @@ { "extends": "@naturalcycles/dev-lib/scripts/tsconfig.json", "compilerOptions": { + "skipLibCheck": true, "baseUrl": "./", "outDir": "../dist" }, diff --git a/src/dayjsRange.test.ts b/src/dayjsRange.test.ts deleted file mode 100644 index db53eb9..0000000 --- a/src/dayjsRange.test.ts +++ /dev/null @@ -1,76 +0,0 @@ -import { _shuffle } from '@naturalcycles/js-lib' -import { - dayjsEarliest, - dayjsLatest, - dayjsRange, - dayjsRangeIncl, - dayjsRangeInclISODate, - dayjsRangeISODate, - dayjsRangeSeq, -} from './dayjsRange' - -test('dayjsRange', () => { - expect(dayjsRangeISODate('2021-12-24', '2021-12-26')).toMatchInlineSnapshot(` - [ - "2021-12-24", - "2021-12-25", - ] - `) - - expect(dayjsRangeInclISODate('2021-12-24', '2021-12-26')).toMatchInlineSnapshot(` - [ - "2021-12-24", - "2021-12-25", - "2021-12-26", - ] - `) - - expect(dayjsRangeISODate('2021-12-24', '2021-12-30', 2)).toMatchInlineSnapshot(` - [ - "2021-12-24", - "2021-12-26", - "2021-12-28", - ] - `) - - expect(dayjsRangeInclISODate('2021-12-24', '2021-12-30', 2)).toMatchInlineSnapshot(` - [ - "2021-12-24", - "2021-12-26", - "2021-12-28", - "2021-12-30", - ] - `) - - expect(dayjsRange('2021-12-24', '2021-12-26', 4, 'hour').map(d => d.toPretty(false))) - .toMatchInlineSnapshot(` - [ - "2021-12-24 00:00", - "2021-12-24 04:00", - "2021-12-24 08:00", - "2021-12-24 12:00", - "2021-12-24 16:00", - "2021-12-24 20:00", - "2021-12-25 00:00", - "2021-12-25 04:00", - "2021-12-25 08:00", - "2021-12-25 12:00", - "2021-12-25 16:00", - "2021-12-25 20:00", - ] - `) -}) - -test('dayjsEarliest, dayjsLatest', () => { - const dates = _shuffle(dayjsRangeIncl('2021-01-01', '2021-01-05', 2, 'd')) - expect(dayjsEarliest(...dates).toISODate()).toBe('2021-01-01') - expect(dayjsLatest(...dates).toISODate()).toBe('2021-01-05') - - expect(() => dayjsEarliest()).toThrow() - expect(() => dayjsLatest()).toThrow() -}) - -test('dayjsRangeSeq', () => { - const d = dayjsRangeSeq('2021-01-01', '2022-01-01').find(d => d.month() === 1) - expect(d?.toISODate()).toBe('2021-02-01') -}) diff --git a/src/dayjsRange.ts b/src/dayjsRange.ts deleted file mode 100644 index a7cb1d9..0000000 --- a/src/dayjsRange.ts +++ /dev/null @@ -1,101 +0,0 @@ -import { END, IsoDateString, Sequence } from '@naturalcycles/js-lib' -import { ConfigType, dayjs, IDayjs, OpUnitType } from './index' - -/** - * Like _range, but for IDayjs. - * Left side is inclusive. - * Right side of the range is exclusive. (same as _range) - */ -export function dayjsRange( - minIncl: ConfigType, - maxExcl: ConfigType, - step = 1, - stepUnit: OpUnitType = 'd', -): IDayjs[] { - const days: IDayjs[] = [] - let current = dayjs(minIncl).startOf(stepUnit) - const max = dayjs(maxExcl).startOf(stepUnit) - - do { - days.push(current) - current = current.add(step, stepUnit) - } while (current.isBefore(max)) - - return days -} - -export function dayjsRangeSeq( - minIncl: ConfigType, - maxExcl: ConfigType, - step = 1, - stepUnit: OpUnitType = 'd', -): Sequence { - const min = dayjs(minIncl).startOf(stepUnit) - const max = dayjs(maxExcl).startOf(stepUnit) - return Sequence.create(min, d => { - const next = d.add(step, stepUnit) - return next.isAfter(max) ? END : next - }) -} - -// todo: this would require Seq.map() implementation -// export function dayjsRangeISODateSeq( -// minIncl: ConfigType, -// maxExcl: ConfigType, -// step = 1, -// stepUnit: OpUnitType = 'd', -// ): Seq { -// const min = dayjs(minIncl).startOf(stepUnit) -// const max = dayjs(maxExcl).startOf(stepUnit) -// return Seq.create(min, d => { -// const next = d.add(step, stepUnit) -// return next.isAfter(max) ? END : next -// }) -// } - -export function dayjsRangeISODate( - minIncl: ConfigType, - maxExcl: ConfigType, - step = 1, - stepUnit: OpUnitType = 'd', -): IsoDateString[] { - return dayjsRange(minIncl, maxExcl, step, stepUnit).map(d => d.toISODate()) -} - -/** - * Like _range, but for IDayjs. - * Both sides inclusive. - */ -export function dayjsRangeIncl( - minIncl: ConfigType, - maxIncl: ConfigType, - step = 1, - stepUnit: OpUnitType = 'd', -): IDayjs[] { - return dayjsRange(minIncl, dayjs(maxIncl).add(1, stepUnit), step, stepUnit) -} - -export function dayjsRangeInclISODate( - minIncl: ConfigType, - maxIncl: ConfigType, - step = 1, - stepUnit: OpUnitType = 'd', -): IsoDateString[] { - return dayjsRangeIncl(minIncl, maxIncl, step, stepUnit).map(d => d.toISODate()) -} - -/** - * Input must contain at least 1 item. - */ -export function dayjsEarliest(...days: IDayjs[]): IDayjs { - // eslint-disable-next-line unicorn/no-array-reduce - return days.reduce((earliest, d) => (d.isBefore(earliest) ? d : earliest)) -} - -/** - * Input must contain at least 1 item. - */ -export function dayjsLatest(...days: IDayjs[]): IDayjs { - // eslint-disable-next-line unicorn/no-array-reduce - return days.reduce((latest, d) => (d.isAfter(latest) ? d : latest)) -} diff --git a/src/index.ts b/src/index.ts index c6a8511..f01e00a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -15,7 +15,6 @@ import { OpUnitType, GlobalLocaleDataReturn, } from './types' -export * from './dayjsRange' export type { IDayjsFactory, IDayjs, IDayjsLocale, ConfigType, OpUnitType, GlobalLocaleDataReturn } diff --git a/tsconfig.json b/tsconfig.json index f1cd1a6..d53918f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,7 @@ { "extends": "@naturalcycles/dev-lib/cfg/tsconfig.json", "compilerOptions": { + "skipLibCheck": true, "sourceMap": true, "module": "commonjs", "moduleResolution": "node", diff --git a/yarn.lock b/yarn.lock index f790d90..d22b0e4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -871,10 +871,10 @@ typescript "^5.0.2" yargs "^17.0.0" -"@naturalcycles/js-lib@^14.0.0", "@naturalcycles/js-lib@^14.6.1": - version "14.149.1" - resolved "https://registry.yarnpkg.com/@naturalcycles/js-lib/-/js-lib-14.149.1.tgz#300194a32a53ec0d2ff6600e9042d24d4305e27d" - integrity sha512-bR4P8jn3UHVsreFRcwplY9RtwIipGeeB2Qy1XUkXrsboSPHU4Dq4JzKXCKKsF2SV8b4UJEbinw7/4d0bItuXDQ== +"@naturalcycles/js-lib@^14.0.0", "@naturalcycles/js-lib@^14.192.0": + version "14.192.0" + resolved "https://registry.yarnpkg.com/@naturalcycles/js-lib/-/js-lib-14.192.0.tgz#ce3c47fc2e43e069ccc0a4a8c509177685151f9b" + integrity sha512-JJU9Ky8yYrUZVafp1//NKxwOrOh8DYOEuWEaE2WZzgIapITopHdovFso8+E5hMHtyWtxJ9U1LeIL1J3Cter7sg== dependencies: tslib "^2.0.0" zod "^3.20.2"