# gearworks-validation

> A TypeScript wrapper around the Joi package, providing typed object validation for Gearworks apps.

Latest version **1.2.0** (published 2017-07-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install gearworks-validation
pnpm add gearworks-validation
yarn add gearworks-validation
bun add gearworks-validation
```

Provides the command `gearworks-validation`.

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2017-07-08 |
| First published | 2017-05-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Joshua Harms |
| Maintainers | nozzlegear |
| Keywords | gearworks, shopify, joi, validation, typings |

## Links

- npm: https://www.npmjs.com/package/gearworks-validation
- Repository: https://github.com/nozzlegear/gearworks-validation
- Homepage: https://github.com/nozzlegear/gearworks-validation#readme
- Issues: https://github.com/nozzlegear/gearworks-validation/issues
- npm.io page: https://npm.io/package/gearworks-validation

## Dependencies (1)

- [joi](https://npm.io/package/joi.md) ^10.4.2

## Alternatives

- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@regle/core](https://npm.io/package/@regle/core.md) — 47.0K weekly downloads
- [typeof-arguments](https://npm.io/package/typeof-arguments.md) — 12.5K weekly downloads
- [@lokalise/projects-engine-contracts](https://npm.io/package/@lokalise/projects-engine-contracts.md) — 978 weekly downloads
- [@osjwnpm/nam-laboriosam-quibusdam](https://npm.io/package/@osjwnpm/nam-laboriosam-quibusdam.md) — 70 weekly downloads

## Recent versions

- 1.2.0 (latest) — 2017-07-08
- 1.1.1 — 2017-05-19
- 1.1.0 — 2017-05-19
- 1.0.0 — 2017-05-16

## README

# gearworks-validation
A TypeScript wrapper around the Joi package, providing typed object validation for Gearworks apps. [Gearworks](https://github.com/nozzlegear/gearworks) is the best way to get started with building Shopify applications!

## Installing

You can install this package from NPM with the NPM CLI or with Yarn (recommended):

```bash
# With NPM
npm install gearworks-validation --save

# With Yarn
yarn add gearworks-validation
```

## Importing

You can import the validators either one function at a time, or all at once, via require or TypeScript's import:

```typescript
// Import all functions
import * as gwv from "gearworks-validation";

// Import just one function
import { strings } from "gearworks-validation";

// Import all functions via Node's require:
const gwv = require("gearworks-validation");

// Import just one function via Node's require:
const strings = require("gearworks-validation").strings;
```

## Usage

Most of the functions are straightforward and self-explanatory. Where this package really shines is when using the functions that provide intellisense for TypeScript types: `object`, `numbers`, `onlyStrings`, `onlyStringsOrEmpty`, and `array`.

```typescript
import * as gwv from "gearworks-validation";

type MyString = "hello" | "world";

type MyNumber = 1 | 2 | 3;

interface MyType {
    foo: string;
    bar: number;
    baz: boolean;
    bat: MyString[];
    bang: MyNumber[];
}

const schema = gwv.object<MyType>({
    // We now have intellisense on MyType property names.
    foo: gwv.string().required(),
    bar: gwv.number(),
    baz: gwv.boolean(),
    bat: gwv.onlyStrings<MyString>("hello", "world" /* And we have intellisense on these strings. */),
    bang: gwv.numbers<MyNumber>(1, 2, 3 /* And these numbers! */)
})
```

## Why?

[Joi](https://npmjs.com/package/joi) is a great package, which I use liberally throughout Gearworks and my own custom Shopify apps, but it has one big pitfall that we can easily fall into when working with plain JS packages: there's no type intellisense for the objects that I'm validating!

I would have zero intellisense for validating an object with plain Joi; I'd have to open my interface definition in a side-by-side window to make sure I was validating all of the properties I needed to validate. *Worse*, though, was that I wouldn't have any warnings or compiler errors when I changed a property on my interfaces. I'd just have to cross my fingers and hope that I updated all occurrences.

That problem is now solved with `gearworks-validation`.

---
_Source: https://npm.io/package/gearworks-validation · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
