@naturalcycles/js-lib 15.6.1 → 15.7.1

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.
@@ -2,9 +2,14 @@ import { AsyncIterable2 } from '../iter/asyncIterable2.js';
2
2
  import { Iterable2 } from '../iter/iterable2.js';
3
3
  export function _range(fromIncl, toExcl, step = 1) {
4
4
  if (toExcl === undefined) {
5
- return Array.from(new Array(fromIncl), (_, i) => i);
5
+ toExcl = fromIncl;
6
+ fromIncl = 0;
7
+ }
8
+ const a = [];
9
+ for (let i = fromIncl; i < toExcl; i += step) {
10
+ a.push(i);
6
11
  }
7
- return Array.from({ length: Math.ceil((toExcl - fromIncl) / step) }, (_, i) => i * step + fromIncl);
12
+ return a;
8
13
  }
9
14
  export function _rangeIterable(fromIncl, toExcl, step = 1) {
10
15
  if (toExcl === undefined) {
@@ -1,4 +1,5 @@
1
1
  import { z } from 'zod/v4';
2
+ import type { IsoDate } from '../types.js';
2
3
  export declare const TS_2500 = 16725225600;
3
4
  export declare const TS_2000 = 946684800;
4
5
  export declare const zUnixTimestamp: () => z.ZodNumber;
@@ -6,7 +7,7 @@ export declare const zUnixTimestamp2000: () => z.ZodNumber;
6
7
  export declare const zUnixTimestampMillis: () => z.ZodNumber;
7
8
  export declare const zUnixTimestampMillis2000: () => z.ZodNumber;
8
9
  export declare const zSemVer: () => z.ZodString;
9
- export declare const zIsoDate: () => z.ZodString;
10
+ export declare const zIsoDate: () => z.ZodCustom<IsoDate>;
10
11
  export declare const zEmail: () => z.ZodEmail;
11
12
  export declare const BASE62_REGEX: RegExp;
12
13
  export declare const BASE64_REGEX: RegExp;
@@ -27,7 +28,7 @@ export declare const customZodSchemas: {
27
28
  base64Url: () => z.ZodString;
28
29
  email: () => z.ZodEmail;
29
30
  ianaTimezone: () => z.ZodEnum;
30
- isoDate: () => z.ZodString;
31
+ isoDate: () => z.ZodCustom<IsoDate>;
31
32
  jwt: () => z.ZodString;
32
33
  slug: () => z.ZodString;
33
34
  semver: () => z.ZodString;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@naturalcycles/js-lib",
3
3
  "type": "module",
4
- "version": "15.6.1",
4
+ "version": "15.7.1",
5
5
  "dependencies": {
6
6
  "tslib": "^2",
7
7
  "zod": "^3"
@@ -1,8 +1,6 @@
1
1
  import { AsyncIterable2 } from '../iter/asyncIterable2.js'
2
2
  import { Iterable2 } from '../iter/iterable2.js'
3
3
 
4
- /* eslint-disable unicorn/no-new-array */
5
-
6
4
  /**
7
5
  * Returns an array with ranges from `from` up to (but not including) `to`.
8
6
  *
@@ -17,13 +15,15 @@ export function _range(toExcl: number): number[]
17
15
  export function _range(fromIncl: number, toExcl: number, step?: number): number[]
18
16
  export function _range(fromIncl: number, toExcl?: number, step = 1): number[] {
19
17
  if (toExcl === undefined) {
20
- return Array.from(new Array(fromIncl), (_, i) => i)
18
+ toExcl = fromIncl
19
+ fromIncl = 0
21
20
  }
22
21
 
23
- return Array.from(
24
- { length: Math.ceil((toExcl - fromIncl) / step) },
25
- (_, i) => i * step + fromIncl,
26
- )
22
+ const a: number[] = []
23
+ for (let i = fromIncl; i < toExcl; i += step) {
24
+ a.push(i)
25
+ }
26
+ return a
27
27
  }
28
28
 
29
29
  /**
@@ -1,4 +1,5 @@
1
1
  import { z } from 'zod/v4'
2
+ import type { IsoDate } from '../types.js'
2
3
 
3
4
  export const TS_2500 = 16725225600 // 2500-01-01
4
5
  export const TS_2000 = 946684800 // 2000-01-01
@@ -45,13 +46,13 @@ export const zSemVer = (): z.ZodString =>
45
46
  .regex(/^[0-9]+\.[0-9]+\.[0-9]+$/, 'Must be a SemVer string')
46
47
  .describe('SemVer')
47
48
 
48
- export const zIsoDate = (): z.ZodString =>
49
+ export const zIsoDate = (): z.ZodCustom<IsoDate> =>
49
50
  z
50
51
  .string()
51
52
  .refine(v => {
52
53
  return /^\d{4}-\d{2}-\d{2}$/.test(v)
53
54
  }, 'Must be an IsoDateString')
54
- .describe('IsoDateString')
55
+ .describe('IsoDateString') as unknown as z.ZodCustom<IsoDate>
55
56
 
56
57
  export const zEmail = (): z.ZodEmail => z.email().describe('Email')
57
58