Saeris

Saeris /valimock

πŸƒ Generate mock data for Valibot schemas using Faker

33
0

Repository Statistics

Key metrics and engagement data

33
Stars
0
Forks
0
Open Issues
0
Releases
1.00
Engagement Rate
Default branch: main

Timeline

Repository has been active for 1 year, 9 months

Repository Created

Last Commit
Recently active

README.md

πŸƒ Valimock

npm version CI status

Generate mock data for Valibot schemas using Faker


πŸ“¦ Installation

bash
1npm install --save-dev valimock @faker-js/faker
bash
1yarn add -D valimock @faker-js/faker

πŸ”§ Usage

Import and optionally configure a new instance of the Valimock class, then pass along your valibot schema to mock(), that's it!

ts
1import { parse, array, union, string, pipe, url, number, maxValue } from "valibot";
2import { Valimock } from "valimock";
3
4describe(`example test`, () => {
5 it(`should generate valid mock data`, () => {
6 const schema = array(union([pipe(string(), url()), pipe(number(), maxValue(20))]));
7 const result = new Valimock().mock(schema);
8 expect(parse(schema, result)).toStrictEqual(result);
9 });
10});

[!NOTE]

For async schemas, you will need to use parseAsync(). Be aware that async schemas generate a Promise and may need to be await'ed depending on usage.

Please see the __tests__ folder for more usage examples of different schema types.

API Coverage

[!WARNING]

At present, not all of valibot's API is fully covered by valimock, however, any unimplemented schema type can be handled by a user-supplied map via the customMocks configuration option. The schema's type proerty is used as the property key for this map.

ImplementedIncompleteNot ImplementedUnsupported
Symbolβœ”βš βŒβž–

Schemas

AnyArrayBigintBlobBooleanDateEnum
βŒβœ”βœ”βž–βœ”βš βœ”
InstanceIntersectLiteralMapNaNNeverNonNullable
βž–βœ”βœ”βœ”βœ”βŒβœ”
NonNullishNonOptionalNullNullableNullishNumberObject
βœ”βœ”βœ”βœ”βœ”βš βœ”
OptionalPicklistRecordRecursiveSetSpecialString
βœ”βœ”βœ”βœ”βœ”βž–βš 
SymbolTupleUndefinedUnionUnknownVariantVoid
βž–βœ”βœ”βœ”βŒβŒβŒ

Validations

Below is an incomplete list of supported validations for the given schemas.

Array

checkcheckItemsemptyeveryItemexcludes
βŒβŒβœ”βŒβŒ
includeslengthmaxLengthminLengthnonEmpty
βŒβœ”βœ”βœ”βœ”
notLengthpartialCheckrawChecksomeItem
❌❌❌❌

BigInt

checkgtValueltValuemaxValueminValue
βŒβŒβŒβœ”βœ”
multipleOfnotValuenotValuesrawCheckvalue
βŒβŒβŒβŒβœ”
values
❌

Date

checkgtValueltValuemaxValueminValue
βŒβŒβŒβœ”βœ”
notValuenotValuesrawCheckvaluevalues
βŒβŒβŒβœ”βŒ

Number

checkfinitegtValueintegerltValue
βŒβŒβŒβœ”βŒ
maxValueminValuemultipleOfnotValuenotValues
βœ”βœ”βŒβŒβŒ
rawChecksafeIntegervaluevalues
βŒβŒβœ”βŒ

String

base64bicbytescreditCardcuid2
βœ”βœ”βŒβœ”βœ”
checkdecimaldigitsemailemoji
βŒβœ”βœ”βœ”βœ”
emptyendsWithexcludesgraphemesgtValue
βœ”βŒβŒβŒβŒ
hashhexadecimalhexColorimeiincludes
βŒβœ”βœ”βœ”βŒ
ipipv4ipv6isoDateisoDateTime
βœ”βœ”βœ”βœ”βœ”
isoTimeisoTimeSecondisoTimestampisoWeeklength
βœ”βœ”βœ”βŒβœ”
ltValuemacmac48mac64maxBytes
βŒβœ”βŒβŒβŒ
maxGraphemesmaxLengthmaxValuemaxWordsminBytes
βŒβœ”βŒβŒβŒ
minGraphemesminLengthminValueminWordsnanoid
βŒβœ”βŒβŒβœ”
nonEmptynotBytesnotEntriesnotGraphemesnotLength
βœ”βŒβŒβŒβŒ
notValuenotValuesnotWordsoctalrawCheck
βŒβŒβŒβœ”βŒ
regexrfcEmailslugstartsWithulid
βœ”βŒβŒβŒβœ”
urluuidvaluevalueswords
βœ”βœ”βŒβŒβŒ

πŸ“£ Acknowledgements

Valimock's implementation is based on @anatine/zod-mock

πŸ₯‚ License

Released under the MIT license Β© Drake Costa.