# yup-jwt

> An extension to the yup library to validate that a string is a JSON Web Token.

Latest version **2.0.1** (published 2018-12-16) · ISC license · 0 weekly downloads

## Install

```sh
npm install yup-jwt
pnpm add yup-jwt
yarn add yup-jwt
bun add yup-jwt
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2018-12-16 |
| First published | 2018-12-03 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=8.0.0 |
| Dependencies | 2 |
| Unpacked size | 8.5 KB |
| Known vulnerabilities | 0 (+3 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Robert Bullen |
| Maintainers | robertbullen |
| Keywords | yup, jwt, jsonwebtoken, validate |

## Links

- npm: https://www.npmjs.com/package/yup-jwt
- Repository: https://github.com/robertbullen/yup-jwt
- Homepage: https://github.com/robertbullen/yup-jwt#readme
- Issues: https://github.com/robertbullen/yup-jwt/issues
- npm.io page: https://npm.io/package/yup-jwt

## Dependencies (2)

- [@types/yup](https://npm.io/package/@types/yup.md) ^0.26.2
- [jsonwebtoken](https://npm.io/package/jsonwebtoken.md) ^8.4.0

## Alternatives

- [@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
- [@oridune/validator](https://npm.io/package/@oridune/validator.md) — 16 weekly downloads

## Recent versions

- 2.0.1 (latest) — 2018-12-16
- 2.0.0 — 2018-12-16
- 1.0.1 — 2018-12-03
- 1.0.0 — 2018-12-03

## README

# yup-jwt

Adds an extension to the [yup](https://www.npmjs.com/package/yup) library to validate that a string is a decode-able JSON Web Token. [jsonwebtoken](https://www.npmjs.com/package/jsonwebtoken) is used to perform the validation under the hood.

## Usage

### Installing

```bash
npm install yup-jwt
```

### Invoking

This project adds a single method to yum: `StringSchema.jwt()`. It's TypeScript definition is:

```typescript
// TypeScript module augmentation.

declare module 'yup' {
    export interface StringSchema {
        jwt(message?: string): StringSchema;
    }
}
```

Building a schema is accomplished identically to the other specialized `StringSchema` methods, like `StringSchema.email()` or `StringSchema.url()`:

```javascript
// A simple example in JavaScript.

const yup = require('yup');
require('yup-jwt');

const schema = yup.string().jwt();

const token = '...';

schema.validateSync(token);
```

## Toolchain

The main tools used for authoring this project are:

- TypeScript
- Prettier
- TSLint
- Jest/ts-jest

These two tutorials for publishing TypeScript-based projects were useful:

- [Step by step: Building and publishing an NPM Typescript package](https://itnext.io/step-by-step-building-and-publishing-an-npm-typescript-package-44fe7164964c)
- [How to Create and Publish an NPM module in TypeScript](https://codeburst.io/https-chidume-nnamdi-com-npm-module-in-typescript-12b3b22f0724)

### Prettier Configuration

Prettier's configuration is placed in `.prettierrc`, which specifies only options that deviate from Prettier's defaults. JSON and markdown files are ignored.

### TSLint Configuration

TSLint's configuration is found in `tslint.json` and starts with `"tslint:latest"`. It adjusts for the aforementioned code formatting preferences of Prettier by also extending `"tslint-config-prettier"`, and then adds just a couple of customized rules beyond that.

### TypeScript Configuration

There are two TypeScript configuration files, one for standard builds and a second one for running the unit tests. The standard build configuration file, `tsconfig.json` started with the output from `tsc init` (of TypeScript 3.2) and made a couple tweaks for ultimate compiler scrictness.

The unit test configuration file, `tsconfig.test.json`, extends the standard build subtly: The only difference between the two is their runtime `"target"` and `"include"` entry point. Standard builds keep the browser in mind and therefore target ES5. Unit tests execute within Node.js (v8 at the time of this writing) and therefore can target ES2017, which is closer to the style of source code, although because unit tests are executed with `ts-jest`, unit test code is never emitted.

## Testing

Unit tests are written for and executed by `jest`/`ts-jest`. They can be invoked as follows:

```bash
npm test
```

## Building

Building consists of performing a clean, compiling with TypeScript, and finally linting with TSLint.

```bash
npm run build

# The above command is equivalent to:
npm run clean
npm run compile
npm run lint
```

JavaScript is emitted to the `./dist` subdirectory.

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