# ts-ast-to-literal

> Transform a TypeScript AST node into a real JS object.

Latest version **5.0.0** (published 2026-01-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install ts-ast-to-literal
pnpm add ts-ast-to-literal
yarn add ts-ast-to-literal
bun add ts-ast-to-literal
```

## Health

**Score 70/100 (B)** — status: stable.

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 5.0.0 |
| Published | 2026-01-02 |
| First published | 2021-08-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=22 |
| Dependencies | 0 |
| Unpacked size | 7.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 11 |
| Author | Sebastian Landwehr |
| Maintainers | dword-design |
| Keywords | abstract-syntax-tree, ast, node, typescript |

## Links

- npm: https://www.npmjs.com/package/ts-ast-to-literal
- Repository: https://github.com/dword-design/ts-ast-to-literal
- Homepage: https://github.com/dword-design/ts-ast-to-literal#readme
- Issues: https://github.com/dword-design/ts-ast-to-literal/issues
- Funding: https://github.com/sponsors/dword-design
- npm.io page: https://npm.io/package/ts-ast-to-literal

## Alternatives

- [update-check](https://npm.io/package/update-check.md) — 4.0M weekly downloads
- [react-native-onesignal](https://npm.io/package/react-native-onesignal.md) — 134.5K weekly downloads
- [react-redux-toastr](https://npm.io/package/react-redux-toastr.md) — 33.7K weekly downloads
- [@nocobase/plugin-notification-manager](https://npm.io/package/@nocobase/plugin-notification-manager.md) — 2.0K weekly downloads
- [react-simple-toasts](https://npm.io/package/react-simple-toasts.md) — 1.9K weekly downloads

## Recent versions

- 5.0.0 (latest) — 2026-01-02
- 4.0.4 — 2025-07-14
- 4.0.3 — 2025-07-12
- 4.0.2 — 2025-07-12
- 4.0.1 — 2025-07-12
- 4.0.0 — 2024-03-04
- 3.0.13 — 2023-05-16
- 3.0.12 — 2023-04-09
- 3.0.11 — 2023-04-09
- 3.0.10 — 2023-04-09
- 3.0.9 — 2023-03-19
- 3.0.8 — 2023-03-19
- 3.0.7 — 2023-03-19
- 3.0.6 — 2023-03-19
- 3.0.5 — 2023-03-18
- … 13 more at https://npm.io/package/ts-ast-to-literal/versions

## README

<!-- TITLE/ -->
# ts-ast-to-literal
<!-- /TITLE -->

<!-- BADGES/ -->
<p>
  <a href="https://npmjs.org/package/ts-ast-to-literal">
    <img
      src="https://img.shields.io/npm/v/ts-ast-to-literal.svg"
      alt="npm version"
    >
  </a><img src="https://img.shields.io/badge/os-linux%20%7C%C2%A0macos%20%7C%C2%A0windows-blue" alt="Linux macOS Windows compatible"><a href="https://github.com/dword-design/ts-ast-to-literal/actions">
    <img
      src="https://github.com/dword-design/ts-ast-to-literal/workflows/build/badge.svg"
      alt="Build status"
    >
  </a><a href="https://codecov.io/gh/dword-design/ts-ast-to-literal">
    <img
      src="https://codecov.io/gh/dword-design/ts-ast-to-literal/branch/master/graph/badge.svg"
      alt="Coverage status"
    >
  </a><a href="https://david-dm.org/dword-design/ts-ast-to-literal">
    <img src="https://img.shields.io/david/dword-design/ts-ast-to-literal" alt="Dependency status">
  </a><img src="https://img.shields.io/badge/renovate-enabled-brightgreen" alt="Renovate enabled"><br/><a href="https://gitpod.io/#https://github.com/dword-design/ts-ast-to-literal">
    <img
      src="https://gitpod.io/button/open-in-gitpod.svg"
      alt="Open in Gitpod"
      width="114"
    >
  </a><a href="https://www.buymeacoffee.com/dword">
    <img
      src="https://www.buymeacoffee.com/assets/img/guidelines/download-assets-sm-2.svg"
      alt="Buy Me a Coffee"
      width="114"
    >
  </a><a href="https://paypal.me/SebastianLandwehr">
    <img
      src="https://sebastianlandwehr.com/images/paypal.svg"
      alt="PayPal"
      width="163"
    >
  </a><a href="https://www.patreon.com/dworddesign">
    <img
      src="https://sebastianlandwehr.com/images/patreon.svg"
      alt="Patreon"
      width="163"
    >
  </a>
</p>
<!-- /BADGES -->

<!-- DESCRIPTION/ -->
Transform a TypeScript AST node into a real JS object.
<!-- /DESCRIPTION -->

Special thanks to [ast-to-literal](https://github.com/hypervillain/ast-to-literal) for the initial idea 👏.

<!-- INSTALL/ -->
## Install

```bash
# npm
$ npm install ts-ast-to-literal

# Yarn
$ yarn add ts-ast-to-literal
```
<!-- /INSTALL -->

## Usage

```js
import ts from 'typescript';
import astToLiteral from 'ts-ast-to-literal';

const ast = ts.createSourceFile(
  'x.ts',
  `export default { foo: 'bar', num: 8 }`,
  ts.ScriptTarget.Latest
)

console.log(astToLiteral(ast.statements[0].expression))
// { foo: 'bar', num: 8 }
```

<!-- LICENSE/ -->
## Contribute

Are you missing something or want to contribute? Feel free to file an [issue](https://github.com/dword-design/ts-ast-to-literal/issues) or a [pull request](https://github.com/dword-design/ts-ast-to-literal/pulls)! ⚙️

## Support

Hey, I am Sebastian Landwehr, a freelance web developer, and I love developing web apps and open source packages. If you want to support me so that I can keep packages up to date and build more helpful tools, you can donate here:

<p>
  <a href="https://www.buymeacoffee.com/dword">
    <img
      src="https://www.buymeacoffee.com/assets/img/guidelines/download-assets-sm-2.svg"
      alt="Buy Me a Coffee"
      width="114"
    >
  </a>&nbsp;If you want to send me a one time donation. The coffee is pretty good 😊.<br/>
  <a href="https://paypal.me/SebastianLandwehr">
    <img
      src="https://sebastianlandwehr.com/images/paypal.svg"
      alt="PayPal"
      width="163"
    >
  </a>&nbsp;Also for one time donations if you like PayPal.<br/>
  <a href="https://www.patreon.com/dworddesign">
    <img
      src="https://sebastianlandwehr.com/images/patreon.svg"
      alt="Patreon"
      width="163"
    >
  </a>&nbsp;Here you can support me regularly, which is great so I can steadily work on projects.
</p>

Thanks a lot for your support! ❤️

## License

[MIT License](https://opensource.org/license/mit/) © [Sebastian Landwehr](https://sebastianlandwehr.com)
<!-- /LICENSE -->

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