Giter Site home page Giter Site logo

saeris / valimock Goto Github PK

View Code? Open in Web Editor NEW
17.0 2.0 0.0 2.27 MB

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

Home Page: https://www.npmjs.com/package/valimock

TypeScript 99.21% JavaScript 0.79%
faker mocking-library testing valibot

valimock's Introduction

๐Ÿƒ 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, url, number, maxValue } from "valibot";
import { Valimock } from "valimock";

describe(`example test`, () => {
  it(`should generate valid mock data`, () => {
    const schema = array(union([string([url()]), 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.

Implemented Incomplete Not Implemented Unsupported
Symbol โœ” โš  โŒ โž–

Schemas

Any Array Bigint Blob Boolean Date Enum
โŒ โœ” โœ” โž– โœ” โš  โœ”
Instance Intersect Literal Map NaN Never NonNullable
โž– โœ” โœ” โœ” โœ” โŒ โœ”
NonNullish NonOptional Null Nullable Nullish Number Object
โœ” โœ” โœ” โœ” โœ” โš  โœ”
Optional Picklist Record Recursive Set Special String
โœ” โœ” โœ” โœ” โœ” โž– โš 
Symbol Tuple Undefined Union Unknown Variant Void
โž– โœ” โœ” โœ” โŒ โŒ โŒ

Validations

String Number Bigint Boolean Date Array Tuple Union Map Set Object Blob
bytes โŒ โž– โž– โž– โž– โž– โž– โž– โž– โž– โž– โž–
cuid2 โœ” โž– โž– โž– โž– โž– โž– โž– โž– โž– โž– โž–
custom โŒ โŒ โŒ โŒ โŒ โŒ โŒ โŒ โŒ โŒ โŒ โŒ
customAsync โŒ โŒ โŒ โŒ โŒ โŒ โŒ โŒ โŒ โŒ โŒ โŒ
email โœ” โž– โž– โž– โž– โž– โž– โž– โž– โž– โž– โž–
emoji โœ” โž– โž– โž– โž– โž– โž– โž– โž– โž– โž– โž–
endsWith โŒ โž– โž– โž– โž– โž– โž– โž– โž– โž– โž– โž–
excludes โŒ โž– โž– โž– โž– โŒ โž– โž– โž– โž– โž– โž–
finite โž– โŒ โŒ โž– โž– โž– โž– โž– โž– โž– โž– โž–
imei โœ” โž– โž– โž– โž– โž– โž– โž– โž– โž– โž– โž–
includes โŒ โž– โž– โž– โž– โŒ โž– โž– โž– โž– โž– โž–
integer โž– โœ” โž– โž– โž– โž– โž– โž– โž– โž– โž– โž–
ip โœ” โž– โž– โž– โž– โž– โž– โž– โž– โž– โž– โž–
ipv4 โœ” โž– โž– โž– โž– โž– โž– โž– โž– โž– โž– โž–
ipv6 โœ” โž– โž– โž– โž– โž– โž– โž– โž– โž– โž– โž–
isoDate โœ” โž– โž– โž– โž– โž– โž– โž– โž– โž– โž– โž–
isoDateTime โœ” โž– โž– โž– โž– โž– โž– โž– โž– โž– โž– โž–
isoTime โœ” โž– โž– โž– โž– โž– โž– โž– โž– โž– โž– โž–
isoTimeSecond โœ” โž– โž– โž– โž– โž– โž– โž– โž– โž– โž– โž–
isoTimestamp โœ” โž– โž– โž– โž– โž– โž– โž– โž– โž– โž– โž–
isoWeek โœ” โž– โž– โž– โž– โž– โž– โž– โž– โž– โž– โž–
length โœ” โž– โž– โž– โž– โœ” โŒ โž– โž– โž– โž– โž–
mexBytes โŒ โž– โž– โž– โž– โž– โž– โž– โž– โž– โž– โž–
maxLength โœ” โž– โž– โž– โž– โœ” โŒ โž– โž– โž– โž– โž–
maxSize โž– โž– โž– โž– โž– โž– โž– โž– โŒ โŒ โž– โž–
maxValue โŒ โœ” โœ” โž– โœ” โž– โž– โž– โž– โž– โž– โž–
mimeType โž– โž– โž– โž– โž– โž– โž– โž– โž– โž– โž– โŒ
minBytes โŒ โž– โž– โž– โž– โž– โž– โž– โž– โž– โž– โž–
minLength โœ” โž– โž– โž– โž– โœ” โŒ โž– โž– โž– โž– โž–
minSize โž– โž– โž– โž– โž– โž– โž– โž– โŒ โŒ โž– โž–
minValue โŒ โœ” โœ” โž– โœ” โž– โž– โž– โž– โž– โž– โž–
multipleOf โž– โŒ โŒ โž– โž– โž– โž– โž– โž– โž– โž– โž–
notBytes โŒ โž– โž– โž– โž– โž– โž– โž– โž– โž– โž– โž–
notLength โŒ โž– โž– โž– โž– โŒ โŒ โž– โž– โž– โž– โž–
notSize โž– โž– โž– โž– โž– โž– โž– โž– โŒ โŒ โŒ โŒ
notValue โŒ โŒ โŒ โŒ โŒ โŒ โŒ โŒ โŒ โŒ โŒ โŒ
regex โš  โž– โž– โž– โž– โž– โž– โž– โž– โž– โž– โž–
safeInteger โž– โŒ โž– โž– โž– โž– โž– โž– โž– โž– โž– โž–
size โž– โž– โž– โž– โž– โž– โž– โž– โŒ โŒ โž– โž–
startsWith โŒ โž– โž– โž– โž– โž– โž– โž– โž– โž– โž– โž–
ulid โœ” โž– โž– โž– โž– โž– โž– โž– โž– โž– โž– โž–
url โœ” โž– โž– โž– โž– โž– โž– โž– โž– โž– โž– โž–
uuid โœ” โž– โž– โž– โž– โž– โž– โž– โž– โž– โž– โž–
value โŒ โœ” โœ” โŒ โŒ โŒ โŒ โŒ โŒ โŒ โŒ โŒ

๐Ÿ“ฃ Acknowledgements

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

๐Ÿฅ‚ License

Released under the MIT license.

valimock's People

Contributors

dependabot[bot] avatar github-actions[bot] avatar saeris avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

valimock's Issues

๐Ÿšจ Alpha Notice

This package is currently published as an alpha release and requires fabian-hiller/valibot#211 to be merged and published before it can be used.

Until then, you can test valimock by pulling down the above PR branch and use npm link to run it locally to satisfy the peer dependency.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.