Releases: ValkyrieStudios/validator
Releases · ValkyrieStudios/validator
9.29.0
Improved
- dx: Branded Types now internally work with a cleaner type allowing for easier usage in eg IDEs such as VS Code
- dx: SSN rule now has a branded type behind it
- dx: ULID rule now has a branded type behind it
- dx: date_string rule now has a branded type behind it
- dx: date_iso and date_day rules now have the same branded type as date_string
- dx: All uuid rules now have a branded type behind them
Fixed
- Fix an issue where ulid regex was including non-base32 characters
9.28.0
Added
- feat:
ssn
rule - Validates U.S. Social Security Numbers (SSN), ensuring the format XXX-XX-XXXX where each "X" is a digit
const v = new Validator({a: 'ssn'});
v.check({a: '987-65-4321'}); /* true */
v.check({a: '123-45-678'}); /* false */
- feat:
ulid
rule - Validates ULIDs (Universally Unique Lexicographically Sortable Identifiers), ensuring a 26-character uppercase alphanumeric format.
const v = new Validator({ a: 'ulid' });
v.check({ a: '01ARZ3NDEKTSV4RRFFQ69G5FAV' }); // true
v.check({ a: '01ARZ3NDEKTSV4RRFFQ69G5FA' }); // false (too short)
- feat:
uuid
rule - Validates general UUIDs, supporting versions 1 through 5
const v = new Validator({ a: 'uuid' });
v.check({ a: '550e8400-e29b-11d4-a716-446655440000' }); // true
v.check({ a: 'bla' }); // false
v.check({ a: '550e8400-e29b-61d4-a716-446655440000' }); // false, version 6 does not exist
- feat:
uuid_v1
rule to verify that a provided value is a correctly formatted UUID V1 - feat:
uuid_v2
rule to verify that a provided value is a correctly formatted UUID V2 - feat:
uuid_v3
rule to verify that a provided value is a correctly formatted UUID V3 - feat:
uuid_v4
rule to verify that a provided value is a correctly formatted UUID V4 - feat:
uuid_v5
rule to verify that a provided value is a correctly formatted UUID V5
const v = new Validator({a: 'uuid'});
v.check({a: '550e8400-e29b-11d4-a716-446655440000'}); /* true */
v.check({a: 'bla'}); /* false */
v.check({a: '550e8400-e29b-61d4-a716-446655440000'}); /* false, v6 does not exist */
- feat:
isbn
rule - Validates International Standard Book Numbers (ISBNs), supporting both ISBN-10 and ISBN-13 formats.
const v = new Validator({ a: 'isbn' });
v.check({ a: '123456789X' }); // true (ISBN-10)
v.check({ a: '9781234567897' }); // true (ISBN-13)
v.check({ a: '1234567890' }); // true (ISBN-10)
v.check({ a: '1234567890123' }); // false (invalid ISBN)
- feat:
isbn_10
rule to verify that a provided value is a correctly formatted 10 character ISBN - feat:
isbn_13
rule to verify that a provided value is a correctly formatted 13 character ISBN - feat:
ean
rule - Validates European Article Numbers (EANs), supporting both 8-character (EAN-8) and 13-character (EAN-13) formats.
const v = new Validator({ a: 'ean' });
v.check({ a: '12345670' }); // true (EAN-8)
v.check({ a: '1234567890128' }); // true (EAN-13)
v.check({ a: '1234567' }); // false (too short for EAN-8)
- feat:
ean_8
rule to verify that a provided value is a correctly formatted 8 character EAN - feat:
ean_13
rule to verify that a provided value is a correctly formatted 13 character EAN
Improved
- dx:
color_hex
rule now works with a branded ColorHex type as typeguard instead of string - dx:
email
rule now works with a branded Email type as typeguard instead of string - dx:
guid
rule now works with a branded Guid type as typeguard instead of string - dx:
phone
rule now works with a branded Phone type as typeguard instead of string - dx:
sys_ipv4
rule now works with a branded IP_V4 type as typeguard instead of string - dx:
sys_ipv6
rule now works with a branded IP_V6 type as typeguard instead of string - dx:
sys_ipv4_or_v6
rule now works with a branded IP type as typeguard instead of string - dx:
sys_mac
rule now works with a branded MAC type as typeguard instead of string - deps: Upgrade @valkyriestudios/utils to 12.27.1
- deps: Upgrade @types/node to 22.8.7
- deps: Upgrade eslint to 9.14.0
- deps: Upgrade typescript to 5.6.3
- deps: Upgrade typescript-eslint to 8.12.2
9.27.0
9.26.0
Improved
- feat:
date_iso
rule now sees ISO formatted date strings without milliseconds as valid too
const v = new Validator({a: 'date_iso'});
v.check({a: '2024-02-07T19:35:00Z'}); // true
v.check({a: '2024-02-07T19:35:00.010Z'}); // true
v.check({a: '2024-02-07T19:35:00.Z'}); // false
- deps: Upgrade @valkyriestudios/utils to 12.25.0
- deps: Upgrade eslint to 9.12.0
- deps: Upgrade typescript-eslint to 8.8.0
9.25.0
Added
- feat:
null
as a rule to validate that a value is null, take note this can be used in tandem with conditional groups, for example:
const v = new Validator({a: '(string_ne)(null)'});
v.check({a: null}); /* true */
v.check({a: false}); /* false */
v.check({a: "Hello world"}); /* true */
- feat:
blob
as a rule to validate that a value is an instance of Blob - feat:
file
as a rule to validate that a value is an instance of File - deps: typescript-eslint (dev dep)
Improved
- feat:
less_than
andlt
now support Blob and File to verify their size is below a certain number of bytes - feat:
less_than_or_equal
andlte
now support Blob and File to verify their size is below or equal to a certain number of bytes - feat:
greater_than
andlt
now support Blob and File to verify their size is above a certain number of bytes - feat:
greater_than_or_equal
andlte
now support Blob and File to verify their size is above or equal to a certain number of bytes - feat:
between
now support Blob and File to verify their size is between a minimum and maximum number of bytes - feat:
between_inc
now support Blob and File to verify their size is between or inclusive to a minimum and maximum number of bytes - deps: Upgrade @valkyriestudios/utils to 12.24.0
- deps: Upgrade eslint to 9.11.1
- deps: Upgrade nyc to 17.1.0
- deps: Upgrade typescript to 5.6.2
- deps: Upgrade @types/node to 20.16.10
Removed
- deps: @typescript-eslint/eslint-plugin
- deps: @typescript-eslint/parser
9.24.0
Added
- feat: Validator@checkForm - Instance function which checks if a FormData instance is valid and returns it as an object if it is. Perfect for middleware situations in backend endpoints
type User = {
age: number;
name: string;
};
const v = new Validator<User>({
name: 'string_ne|min:2',
age: 'integer|between:1,150',
});
const form = new FormData();
form.append('name', 'Peter');
form.append('age', '34');
const result = v.checkForm(form);
if (!result) return;
... // result is converted to an object and typed as User here and will be {name: "Peter", age: 34}
- feat: Validator@check now supports FormData validation
const v = new Validator({
name: 'string_ne|min:2',
age: 'integer|between:1,150',
});
const form = new FormData();
form.append('name', 'Peter');
v.check(form); // false
form.append('age', '40');
v.check(form); // true
- feat: Validator@validate now supports FormData validation
const v = new Validator({
name: 'string_ne|min:2',
age: 'integer|between:1,150',
});
const form = new FormData();
form.append('name', 'Peter');
console.log(v.validate(form).is_valid); // false
form.append('age', '40');
console.log(v.validate(form).is_valid); // true
Improved
- deps: Upgrade @valkyriestudios/utils to 12.22.0
- deps: Upgrade @types/node to 20.16.5
9.23.0
Added
- feat: Rule 'date_iso' - Validates that a provided value is a date string in the iso format of
YYYY-MM-DDTHH:mm:ss.SSSZ
const v = new Validator({created: 'date_iso'});
v.check({a: '2024-04-31T09:20:00.000Z'}); // false there is no 31st day in April
v.check({a: '2024-04-16T09:20:00.000Z'}); // true
- feat: Rule 'date_day' - Validates that a provided value is a date string in the format of
YYYY-MM-DD
const v = new Validator({created: 'date_day'});
v.check({a: '2023-02-29'}); // false 2023 was not a leap year
v.check({a: '2024-02-29'}); // true
Improved
- perf: ~2-5% improvement in
url_med
validation thanks to precompiled regexes - perf: ~2-5% improvement in
url_vid
validation thanks to precompiled regexes - perf: ~2-5% improvement in
url_aud
validation thanks to precompiled regexes - perf: ~2-5% improvement in
url_img
validation thanks to precompiled regexes - perf: ~2-5% improvement in
sys_ipv4_or_v6
validation thanks to removal of redundant typeof check and simplification of ops - perf: ~5% improvement in
lt
,less_than
,lte
,less_than_or_equal
,gt
,greater_than
,gte
,greater_than_or_equal
,between
,between_inc
when using numerical checks thanks to removal of typeof check and simplification of operations - sys: Automated test runs are now run against node 18.x, 20.x and 22.x instead of only 20.x
- deps: Upgrade @valkyriestudios/utils to 12.20.0
- deps: Upgrade @types/node to 20.16.0
9.22.0
9.21.0
Improved
- deps: Upgrade @valkyriestudios/utils to 12.18.0
- deps: Upgrade @types/node to 20.14.14
- deps: Upgrade @typescript-eslint/eslint-plugin to 7.18.0
- deps: Upgrade @typescript-eslint/parser to 7.18.0
- deps: Upgrade esbuild-register to 3.6.0
- deps: Upgrade typescript to 5.5.4