Skip to content
Merged

Dev #29

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
## Changelog

### [v5.19.0](https://github.com/panates/valgen/compare/v5.18.3...v5.19.0) -
### [v5.19.1](https://github.com/panates/valgen/compare/v5.19.0...v5.19.1) -

#### 🚀 New Features

- feat: Added "trim" option to "toDateString" @Eray Hanoğlu

#### 🧪 Changes to Test Assests

- test: Set timezone for entire job in test workflow @Eray Hanoğlu
- test: Set timezone for entire job in test workflow @Eray Hanoğlu

### [v5.19.0](https://github.com/panates/valgen/compare/v5.18.3...v5.19.0) - 19 January 2026

#### 💬 General Changes

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "valgen",
"description": "Fast runtime type validator, converter and io (encoding/decoding) library",
"version": "5.19.0",
"version": "5.19.1",
"author": "Panates",
"license": "MIT",
"private": true,
Expand Down
18 changes: 16 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { Context, ExecutionOptions } from './core/index.js';
import { DatePrecision } from './rules/index.js';
import * as vg from './rules/index.js';

export * from './constants.js';
Expand Down Expand Up @@ -60,12 +62,24 @@ const toArray = vg.isArray(isAny, { coerce: true });
const toBigint = vg.isBigint({ coerce: true });
const toBoolean = vg.isBoolean({ coerce: true });
const toDate = vg.isDate({ coerce: true });
const toDateString = vg.isDateString({ coerce: true, precisionMin: 'day' });
const toDateStringValidators = new Map();
const toDateString = (
input: Date | string | number,
options?: ExecutionOptions & { trim?: DatePrecision },
ctx?: Context,
) => {
const trim = options?.trim ?? 'seconds';
let validator = toDateStringValidators.get(trim);
if (!validator) {
validator = vg.isDateString({ coerce: true, trim });
toDateStringValidators.set(trim, validator);
}
return validator(input, options, ctx);
};
const toInteger = vg.isInteger({ coerce: true });
const toNumber = vg.isNumber({ coerce: true });
const toString = vg.isString({ coerce: true });
const toTime = vg.isTime({ coerce: true });

export {
isAlpha,
isAlphanumeric,
Expand Down
14 changes: 7 additions & 7 deletions src/rules/type-rules/is-date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
validator,
} from '../../core/index.js';

type Precision =
export type DatePrecision =
| 'year'
| 'yr'
| 'month'
Expand All @@ -24,7 +24,7 @@ type Precision =
| 'tz';

export interface IsDateOptions extends ValidationOptions {
trim?: Precision;
trim?: DatePrecision;
}

/**
Expand Down Expand Up @@ -62,9 +62,9 @@ export function isDate(options?: IsDateOptions) {
}

export interface IsDateStringOptions extends ValidationOptions {
precisionMin?: Precision;
precisionMax?: Precision;
trim?: Precision;
precisionMin?: DatePrecision;
precisionMax?: DatePrecision;
trim?: DatePrecision;
timeZone?: boolean | number;
}

Expand Down Expand Up @@ -120,7 +120,7 @@ const DATE_PATTERN2 =

function coerceDateString(
input: any,
precision?: Precision,
precision?: DatePrecision,
): Nullish<{
value: string;
precision: number;
Expand Down Expand Up @@ -191,7 +191,7 @@ function coerceDateString(
};
}

const PRECISION_INDEX: Record<Precision, number> = {
const PRECISION_INDEX: Record<DatePrecision, number> = {
year: 1,
yr: 1,
month: 2,
Expand Down