# omikuji

> Get a random value from an array.

Latest version **1.1.0** (published 2026-05-04) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 65/100 (B)** — status: active.

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2026-05-04 |
| First published | 2018-09-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18 |
| Dependencies | 0 |
| Unpacked size | 6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 0 |
| Maintainers | diwao |
| Keywords | omikuji, random, fortune |

## Links

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

## Recent versions

- 1.1.0 (latest) — 2026-05-04
- 1.0.1 — 2018-09-19
- 1.0.0 — 2018-09-17
- 0.0.1 — 2018-09-17

## README

# Omikuji

[![Tests](https://github.com/diwao/omikuji/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/diwao/omikuji/actions/workflows/test.yml)

## Description

Get a random value from an array.

Omikuji works with both CommonJS and ES Modules, and includes default fortune items so it can be used without initialization.

## Installation

```sh
npm install omikuji
```

## Usage

### CommonJS

```js
const Omikuji = require('omikuji');

const items = ['大吉', '中吉', '末吉', '吉', '凶'];
const omikuji = new Omikuji(items);

console.log(omikuji.get());
```

### ES Modules

```js
import Omikuji from 'omikuji';

const omikuji = new Omikuji(['大吉', '中吉', '末吉', '吉', '凶']);

console.log(omikuji.get());
```

### Without Initialization

```js
import Omikuji from 'omikuji';

const omikuji = new Omikuji();

console.log(omikuji.get());
```

The default items are:

```js
['大吉', '中吉', '末吉', '吉', '凶'];
```

### TypeScript

```ts
import Omikuji from 'omikuji';

const omikuji = new Omikuji<string>(['大吉', '中吉', '末吉', '吉', '凶']);

const result: string = omikuji.get();
```

## Methods

### get()

Returns a random item.

### setItems(items)

Replaces the current items.

### add(item)

Adds one item.

### remove(item)

Removes the first matching item and returns `true`. Returns `false` if the item is not found.

### reset()

Restores the items that were set when the instance was created.

### getItems()

Returns a copy of the current items.

## Errors

Passing a non-array value as `items` to the constructor or `setItems()` throws a `TypeError`.

Omikuji needs at least one item. Passing an empty array to the constructor or `setItems()` throws a `RangeError`.

Removing the last remaining item also throws a `RangeError`.

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