New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

valimock

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

valimock

Generate mock data for Valibot schemas using Faker

latest
Source
npmnpm
Version
1.4.0
Version published
Maintainers
1
Created
Source

🃏 Valimock

npm version CI status

Generate mock data for Valibot schemas using Faker

📦 Installation

npm install --save-dev valimock @faker-js/faker
yarn 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!

import { parse, array, union, string, pipe, url, number, maxValue } from "valibot";
import { Valimock } from "valimock";

describe(`example test`, () => {
  it(`should generate valid mock data`, () => {
    const schema = array(union([pipe(string(), url()), pipe(number(), maxValue(20))]));
    const result = new Valimock().mock(schema);
    expect(parse(schema, result)).toStrictEqual(result);
  });
});

[!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.

Keywords

valibot

FAQs

Package last updated on 29 Jun 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts