# untyped

Latest version **2.0.0** (published 2025-02-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install untyped
pnpm add untyped
yarn add untyped
bun add untyped
```

Provides the command `untyped`.

## Health

**Score 55/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2025-02-26 |
| First published | 2015-05-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 5 |
| Unpacked size | 318.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 527 |
| Maintainers | pi0, danielroe |

## Links

- npm: https://www.npmjs.com/package/untyped
- Repository: https://github.com/unjs/untyped
- Homepage: https://github.com/unjs/untyped#readme
- Issues: https://github.com/unjs/untyped/issues
- npm.io page: https://npm.io/package/untyped

## Dependencies (5)

- [defu](https://npm.io/package/defu.md) ^6.1.4
- [jiti](https://npm.io/package/jiti.md) ^2.4.2
- [citty](https://npm.io/package/citty.md) ^0.1.6
- [scule](https://npm.io/package/scule.md) ^1.3.0
- [knitwork](https://npm.io/package/knitwork.md) ^1.2.0

## Recent versions

- 2.0.0 (latest) — 2025-02-26
- 1.5.2 — 2024-12-16
- 1.5.1 — 2024-10-05
- 1.5.0 — 2024-09-26
- 1.4.2 — 2024-01-20
- 1.4.1 — 2024-01-19
- 1.4.0 — 2023-07-28
- 1.3.2 — 2023-03-28
- 1.3.1 — 2023-03-27
- 1.3.0 — 2023-03-27
- 1.2.2 — 2023-01-13
- 1.2.1 — 2023-01-03
- 1.2.0 — 2022-12-14
- 1.1.0 — 2022-12-13
- 1.0.0 — 2022-11-15
- … 25 more at https://npm.io/package/untyped/versions

## README

# untyped

<!-- automd:badges bundlejs -->

[![npm version](https://img.shields.io/npm/v/untyped)](https://npmjs.com/package/untyped)
[![npm downloads](https://img.shields.io/npm/dm/untyped)](https://npm.chart.dev/untyped)
[![bundle size](https://img.shields.io/bundlejs/size/untyped)](https://bundlejs.com/?q=untyped)

<!-- /automd -->

**▶️ Check [online playground](https://untyped.unjs.io)**

## Install

<!-- automd:pm-i -->

```sh
# ✨ Auto-detect
npx nypm install untyped

# npm
npm install untyped

# yarn
yarn add untyped

# pnpm
pnpm install untyped

# bun
bun install untyped

# deno
deno install untyped
```

<!-- /automd -->

## Usage

First we have to define a reference object that describes types, defaults, and a `$resolve` method (normalizer).

```js
const defaultPlanet = {
  name: "earth",
  specs: {
    gravity: {
      $resolve: (val) => Number.parseFloat(val),
      $default: "9.8",
    },
    moons: {
      $resolve: (val = ["moon"]) => [val].flat(),
      $schema: {
        title: "planet moons",
      },
    },
  },
};
```

## API

### `resolveSchema`

```js
import { resolveSchema } from "untyped";

const schema = await resolveSchema(defaultPlanet);
```

Output:

```json
{
  "properties": {
    "name": {
      "type": "string",
      "default": "earth"
    },
    "specs": {
      "properties": {
        "gravity": {
          "default": 9.8,
          "type": "number"
        },
        "moons": {
          "title": "planet moons",
          "default": ["moon"],
          "type": "array",
          "items": [
            {
              "type": "string"
            }
          ]
        }
      },
      "type": "object"
    }
  },
  "type": "object"
}
```

### `generateTypes`

```js
import { resolveSchema, generateTypes } from "untyped";

const types = generateTypes(await resolveSchema(defaultPlanet));
```

Output:

```ts
interface Untyped {
  /** @default "earth" */
  name: string;

  specs: {
    /** @default 9.8 */
    gravity: number;

    /**
     * planet moons
     * @default ["moon"]
     */
    moons: string[];
  };
}
```

### `generateMarkdown`

```js
import { resolveSchema, generateMarkdown } from "untyped";

const markdown = generateMarkdown(await resolveSchema(defaultPlanet));
```

Output:

```markdown
# `name`

- **Type**: `string`
- **Default**: `"earth"`

# `specs`

## `gravity`

- **Type**: `number`
- **Default**: `9.8`

## `moons`

- **Type**: `array`
- **Default**: `["moon"]`
```

## 💻 Development

- Clone this repository
- Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable` (use `npm i -g corepack` for Node.js < 16.10)
- Install dependencies using `pnpm install`
- Run interactive tests using `pnpm dev`
- Use `pnpm web` to start playground website
- Use `pnpm test` before push to ensure all tests and lint checks passing

## License

[MIT](./LICENSE)

Thanks to [@dominikschreiber](https://github.com/dominikschreiber) for donating package name.

<!-- Badges -->

[npm-version-src]: https://img.shields.io/npm/v/untyped?style=flat-square
[npm-version-href]: https://npmjs.com/package/untyped
[npm-downloads-src]: https://img.shields.io/npm/dm/untyped?style=flat-square
[npm-downloads-href]: https://npmjs.com/package/untyped
[github-actions-src]: https://img.shields.io/github/actions/workflow/status/unjs/untyped/ci.yml?branch-main&style=flat-square
[github-actions-href]: https://github.com/unjs/untyped/actions?query=workflow%3Aci
[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/untyped/main?style=flat-square
[codecov-href]: https://codecov.io/gh/unjs/untyped
[bundle-src]: https://img.shields.io/bundlephobia/minzip/untyped?style=flat-square
[bundle-href]: https://bundlephobia.com/result?p=untyped

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