# wiki-infoboxes

> Extract wikipedia article infoboxes in a structured JSON format.

Latest version **2.0.0** (published 2026-04-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install wiki-infoboxes
pnpm add wiki-infoboxes
yarn add wiki-infoboxes
bun add wiki-infoboxes
```

## Health

**Score 60/100 (C)** — status: active.

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2026-04-08 |
| First published | 2019-09-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 27.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Juan Convers |
| Maintainers | webdacjs |
| Keywords | wikipedia, infobox, json, extract |

## Links

- npm: https://www.npmjs.com/package/wiki-infoboxes
- Repository: https://github.com/webdacjs/wiki-infoboxes
- Homepage: https://github.com/webdacjs/wiki-infoboxes#readme
- Issues: https://github.com/webdacjs/wiki-infoboxes/issues
- npm.io page: https://npm.io/package/wiki-infoboxes

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 2.0.0 (latest) — 2026-04-08
- 1.0.0 — 2019-09-03

## README

# wiki-infoboxes

> Extract Wikipedia article infoboxes as structured JSON — zero runtime dependencies.

As defined by Wikipedia: *An infobox is a fixed-format table usually added to the top right-hand corner of articles to consistently present a summary of some unifying aspect that the articles share.*

## Install

```sh
pnpm install wiki-infoboxes
```

## Usage

```ts
import { fetchInfoBoxes, fetchSearchInfoBoxes } from 'wiki-infoboxes'

// Exact article title
const data = await fetchInfoBoxes('Anglo-Irish_Treaty')
console.log(data)
// {
//   name:      { text: 'Anglo-Irish Treaty' },
//   long_name: { text: 'Articles of Agreement for a Treaty Between Great Britain and Ireland' },
//   date_signed: { text: '6 December 1921' },
//   …
// }

// Free-text search (uses the top result)
const data2 = await fetchSearchInfoBoxes('republic of ireland')
console.log(data2.common_name.text)  // → 'Ireland'
```

CommonJS works too:

```js
const { fetchInfoBoxes, fetchSearchInfoBoxes } = require('wiki-infoboxes')
```

## API

### `fetchInfoBoxes(title, ttl?): Promise<Infobox>`

Fetches the infobox for the exact Wikipedia page `title`.  
`ttl` controls the in-memory cache lifetime in milliseconds (default: `3_600_000` — 1 hour).

### `fetchSearchInfoBoxes(query, ttl?): Promise<Infobox>`

Runs a Wikipedia search for `query` and returns the infobox of the top result.

### `clearCache(): void`

Invalidates all cached responses (useful in tests).

### Types

```ts
interface InfoboxValue { text: string }
type Infobox = Record<string, InfoboxValue>
```

## Architecture

The package ships **zero runtime dependencies**.  Functionality previously
provided by third-party libraries is reimplemented locally:

| Old dependency       | Replaced by                          |
|----------------------|--------------------------------------|
| `wtf_wikipedia`      | `src/wikitext.ts` — infobox parser<br>`src/wikipedia.ts` — MediaWiki API client |
| `simple-fetch-cache` | `src/cache.ts` — in-memory TTL cache |

The build uses [tsup](https://tsup.egoist.dev/) and emits both **ESM** (`dist/index.js`) and **CJS** (`dist/index.cjs`) bundles with TypeScript declarations.

## Development

```sh
npm install
npm run build    # compile with tsup
npm test         # run Jest (offline unit tests + integration tests)
```

## License

MIT © [Juan Convers](https://juanconvers.com/)

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