Giter Club home page Giter Club logo

typeguard's Introduction

TypeGuard

Have you ever encountered a situation where Luau types just didn't cut it? I have, especially when validating RemoteEvent data that has been sent by a client. But this could also be useful to make 100% sure that the data you are about to write to your datastore matches a predefined schema.

Download

If you want to try it out for yourself, you can download the module here

Showcase

local tg = require(script.Parent.TypeGuard)

print(tg.PositiveInteger(1234)) -- Expected output: true
print(tg.PositiveInteger(-1234)) -- Expected output: false

local nullableNonEmptyString = tg.Optional(tg.NonEmptyString)

print(nullableNonEmptyString('Hello!')) -- Expected output: true
print(nullableNonEmptyString(nil)) -- Expected output: true
print(nullableNonEmptyString('')) -- Expected output: false

local itemSchema = tg.Dictionary({
    id = tg.NonEmptyString,
    name = tg.NonEmptyString,
    value = tg.Number,
})

local validationSchema = tg.Dictionary({
    level = tg.PositiveInteger,
    cash = tg.Number,
    inventory = tg.Array(itemSchema),
})

print(validationSchema({
    level = 16,
    cash = 12.15,
    inventory = {
        {
            id = 'gold-sword-a65a4fb4c',
            name = 'Gold Sword',
            value = 50.86,
        },
        {
            id = 'iron-sword-b75ce5f3a',
            name = 'Iron Sword',
            value = 5.39,
        },
    },
})) -- Expected output: true

Usage

An example of how to use the module can be found in the Tests script provided in the model. Feel free to add your own types or suggest them here.

GitHub

If you just wanna take a look at the code, feel free to do so. You can find the GitHub repository here

typeguard's People

Contributors

auxority avatar

Watchers

 avatar

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.