# awesome-types

> An awesome library for type checking on the fly.

Latest version **1.0.1** (published 2016-12-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install awesome-types
pnpm add awesome-types
yarn add awesome-types
bun add awesome-types
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2016-12-22 |
| First published | 2016-12-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Hackzzila |
| Maintainers | hackzzila |
| Keywords | types, checking, type, awesome |

## Links

- npm: https://www.npmjs.com/package/awesome-types
- Repository: https://github.com/hackzzila/awesome-types
- Homepage: https://github.com/hackzzila/awesome-types#readme
- Issues: https://github.com/hackzzila/awesome-types/issues
- npm.io page: https://npm.io/package/awesome-types

## Dependencies (1)

- [type-detect](https://npm.io/package/type-detect.md) ^4.0.0

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2016-12-22
- 1.0.0-3 — 2016-12-22

## README

# awesome-types
An awesome library for type checking on the fly.

A `type` is a string supported by [type-detect](https://www.npmjs.com/package/type-detect).
A `type` can also be `false` for no type checking.

awesome-types allows values of all types to also be `null` or `undefined`.

There are three main functions provided.

## watchObj({ obj }, { types })
This function watches an object, and when it changes it checks types.

`types` is an object where the key is the property name, and the value is a type.
It returns a copy of the object. Note: it *only* watches the returned value, if you edit the object you passed into
the function, nothing will happen.

Examples:

```js
// Watches an empty object.
const obj = types.watchObj({}, { name: 'string', age: 'number' });
obj.name = 'foo';  // all good
obj.age = 'bar';   // throws error
obj.height = '12'; // ignored
```

```js
// Watches a non-empty object.
const obj = types.watchObj({
  name: 'foo',  // all good
  age: 'bar',   // throws error
  height: '12', // ignored
}, { name: 'string', age: 'number' });
```

## watchArr([ arr ], [ types ])
This function watches an array, and when it changes it checks types.

`types` is an array of types, where the type's index corresponds to the index of the value in the array.
It returns a copy of the array. Note: it *only* watches the returned value, if you edit the array you passed into
the function, nothing will happen.

Examples:

```js
// Watches an empty array.
const arr = types.watchArr([], ['string', 'number']);
arr.push('foo'); // all good
arr.push('bar'); // throws error
arr.push('12');  // ignored
```

```js
// Watches a non-empty array.
const arr = types.watchArr([
  'foo', // all good
  'bar', // throws error
  '12',  // ignored
], ['string', 'number']);
```

## watchFunc(() => { func }, [ types ])
This function watches an function, and when it gets called it checks argument types.

`types` is an array of types, where the type's index corresponds to the index of the argument.
It returns a copy of the function. Note: it *only* watches the returned value, if you call the function you passed into
the watchFunc, nothing will happen.

Examples:

```js
// Watches a function.
const func = types.watchFunc((name, age, height) => {
  console.log(name, age, height);
}, ['string', 'number']);
func(
  'foo', // all good
  'bar', // throws error
  '12'   // ignored
);
```

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