-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from vbudovski/feature/more-string-validators
Feature/more string validators
- Loading branch information
Showing
13 changed files
with
1,029 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { z } from 'zod'; | ||
import * as p from '../../src/index.ts'; | ||
|
||
const { bench } = Deno; | ||
|
||
const paseriSchema = p.string().cidr(); | ||
const zodSchema = z.string().cidr(); | ||
|
||
const dataValid = '10.0.0.0/22'; | ||
const dataInvalid = '127.0.0.1'; | ||
|
||
bench('Paseri', { group: 'CIDR valid' }, () => { | ||
paseriSchema.safeParse(dataValid); | ||
}); | ||
|
||
bench('Zod', { group: 'CIDR valid' }, () => { | ||
zodSchema.safeParse(dataValid); | ||
}); | ||
|
||
bench('Paseri', { group: 'CIDR invalid' }, () => { | ||
paseriSchema.safeParse(dataInvalid); | ||
}); | ||
|
||
bench('Zod', { group: 'CIDR invalid' }, () => { | ||
zodSchema.safeParse(dataInvalid); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { z } from 'zod'; | ||
import * as p from '../../src/index.ts'; | ||
|
||
const { bench } = Deno; | ||
|
||
const paseriSchema = p.string().date(); | ||
const zodSchema = z.string().date(); | ||
|
||
const dataValid = '2020-01-01'; | ||
const dataInvalid = '2024-01-32'; | ||
|
||
bench('Paseri', { group: 'Date valid' }, () => { | ||
paseriSchema.safeParse(dataValid); | ||
}); | ||
|
||
bench('Zod', { group: 'Date valid' }, () => { | ||
zodSchema.safeParse(dataValid); | ||
}); | ||
|
||
bench('Paseri', { group: 'Date invalid' }, () => { | ||
paseriSchema.safeParse(dataInvalid); | ||
}); | ||
|
||
bench('Zod', { group: 'Date invalid' }, () => { | ||
zodSchema.safeParse(dataInvalid); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { z } from 'zod'; | ||
import * as p from '../../src/index.ts'; | ||
|
||
const { bench } = Deno; | ||
|
||
const paseriSchema = p.string().datetime(); | ||
const zodSchema = z.string().datetime(); | ||
|
||
const dataValid = '2020-01-01T01:02:03.45678Z'; | ||
const dataInvalid = '2024-01-32T00:00:00'; | ||
|
||
bench('Paseri', { group: 'Datetime valid' }, () => { | ||
paseriSchema.safeParse(dataValid); | ||
}); | ||
|
||
bench('Zod', { group: 'Datetime valid' }, () => { | ||
zodSchema.safeParse(dataValid); | ||
}); | ||
|
||
bench('Paseri', { group: 'Datetime invalid' }, () => { | ||
paseriSchema.safeParse(dataInvalid); | ||
}); | ||
|
||
bench('Zod', { group: 'Datetime invalid' }, () => { | ||
zodSchema.safeParse(dataInvalid); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import * as v from '@badrap/valita'; | ||
import { z } from 'zod'; | ||
import * as p from '../../src/index.ts'; | ||
|
||
const { bench } = Deno; | ||
|
||
const paseriSchema = p.string().endsWith('foo'); | ||
const zodSchema = z.string().endsWith('foo'); | ||
const valitaSchema = v.string().assert((value) => value.endsWith('foo')); | ||
|
||
const dataValid = 'Hello, world!foo'; | ||
const dataInvalid = 'Hello, world!'; | ||
|
||
bench('Paseri', { group: 'Ends with valid' }, () => { | ||
paseriSchema.safeParse(dataValid); | ||
}); | ||
|
||
bench('Zod', { group: 'Ends with valid' }, () => { | ||
zodSchema.safeParse(dataValid); | ||
}); | ||
|
||
bench('Valita', { group: 'Ends with valid' }, () => { | ||
valitaSchema.try(dataValid); | ||
}); | ||
|
||
bench('Paseri', { group: 'Ends with invalid' }, () => { | ||
paseriSchema.safeParse(dataInvalid); | ||
}); | ||
|
||
bench('Zod', { group: 'Ends with invalid' }, () => { | ||
zodSchema.safeParse(dataInvalid); | ||
}); | ||
|
||
bench('Valita', { group: 'Ends with invalid' }, () => { | ||
valitaSchema.try(dataInvalid); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import * as v from '@badrap/valita'; | ||
import { z } from 'zod'; | ||
import * as p from '../../src/index.ts'; | ||
|
||
const { bench } = Deno; | ||
|
||
const paseriSchema = p.string().includes('foo'); | ||
const zodSchema = z.string().includes('foo'); | ||
const valitaSchema = v.string().assert((value) => value.includes('foo')); | ||
|
||
const dataValid = 'Hello,fooworld!'; | ||
const dataInvalid = 'Hello, world!'; | ||
|
||
bench('Paseri', { group: 'Includes valid' }, () => { | ||
paseriSchema.safeParse(dataValid); | ||
}); | ||
|
||
bench('Zod', { group: 'Includes valid' }, () => { | ||
zodSchema.safeParse(dataValid); | ||
}); | ||
|
||
bench('Valita', { group: 'Includes valid' }, () => { | ||
valitaSchema.try(dataValid); | ||
}); | ||
|
||
bench('Paseri', { group: 'Includes invalid' }, () => { | ||
paseriSchema.safeParse(dataInvalid); | ||
}); | ||
|
||
bench('Zod', { group: 'Includes invalid' }, () => { | ||
zodSchema.safeParse(dataInvalid); | ||
}); | ||
|
||
bench('Valita', { group: 'Includes invalid' }, () => { | ||
valitaSchema.try(dataInvalid); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { z } from 'zod'; | ||
import * as p from '../../src/index.ts'; | ||
|
||
const { bench } = Deno; | ||
|
||
const paseriSchema = p.string().ip(); | ||
const zodSchema = z.string().ip(); | ||
|
||
const dataValid = '192.168.1.254'; | ||
const dataInvalid = '999'; | ||
|
||
bench('Paseri', { group: 'IP valid' }, () => { | ||
paseriSchema.safeParse(dataValid); | ||
}); | ||
|
||
bench('Zod', { group: 'IP valid' }, () => { | ||
zodSchema.safeParse(dataValid); | ||
}); | ||
|
||
bench('Paseri', { group: 'IP invalid' }, () => { | ||
paseriSchema.safeParse(dataInvalid); | ||
}); | ||
|
||
bench('Zod', { group: 'IP invalid' }, () => { | ||
zodSchema.safeParse(dataInvalid); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import * as v from '@badrap/valita'; | ||
import { z } from 'zod'; | ||
import * as p from '../../src/index.ts'; | ||
|
||
const { bench } = Deno; | ||
|
||
const paseriSchema = p.string().startsWith('foo'); | ||
const zodSchema = z.string().startsWith('foo'); | ||
const valitaSchema = v.string().assert((value) => value.startsWith('foo')); | ||
|
||
const dataValid = 'fooHello, world!'; | ||
const dataInvalid = 'Hello, world!'; | ||
|
||
bench('Paseri', { group: 'Starts with valid' }, () => { | ||
paseriSchema.safeParse(dataValid); | ||
}); | ||
|
||
bench('Zod', { group: 'Starts with valid' }, () => { | ||
zodSchema.safeParse(dataValid); | ||
}); | ||
|
||
bench('Valita', { group: 'Starts with valid' }, () => { | ||
valitaSchema.try(dataValid); | ||
}); | ||
|
||
bench('Paseri', { group: 'Starts with invalid' }, () => { | ||
paseriSchema.safeParse(dataInvalid); | ||
}); | ||
|
||
bench('Zod', { group: 'Starts with invalid' }, () => { | ||
zodSchema.safeParse(dataInvalid); | ||
}); | ||
|
||
bench('Valita', { group: 'Starts with invalid' }, () => { | ||
valitaSchema.try(dataInvalid); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { z } from 'zod'; | ||
import * as p from '../../src/index.ts'; | ||
|
||
const { bench } = Deno; | ||
|
||
const paseriSchema = p.string().time(); | ||
const zodSchema = z.string().time(); | ||
|
||
const dataValid = '00:00:00'; | ||
const dataInvalid = '99:99:99'; | ||
|
||
bench('Paseri', { group: 'Time valid' }, () => { | ||
paseriSchema.safeParse(dataValid); | ||
}); | ||
|
||
bench('Zod', { group: 'Time valid' }, () => { | ||
zodSchema.safeParse(dataValid); | ||
}); | ||
|
||
bench('Paseri', { group: 'Time invalid' }, () => { | ||
paseriSchema.safeParse(dataInvalid); | ||
}); | ||
|
||
bench('Zod', { group: 'Time invalid' }, () => { | ||
zodSchema.safeParse(dataInvalid); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.