# @bonsai-components/meta-key

> Make meta key less annoying

Latest version **1.2.9** (published 2025-03-04) · (MIT OR Apache-2.0) license · 0 weekly downloads

## Install

```sh
npm install @bonsai-components/meta-key
pnpm add @bonsai-components/meta-key
yarn add @bonsai-components/meta-key
bun add @bonsai-components/meta-key
```

## Health

**Score 25/100 (F)** — status: maintenance-mode.

Positive: no vulnerabilities.

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

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.9 |
| Published | 2025-03-04 |
| First published | 2021-12-21 |
| Weekly downloads | 0 |
| License | (MIT OR Apache-2.0) |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 12.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Kyle Scully |
| Maintainers | zieka, sjungling |
| Keywords | meta, key, meta-key, cross-browser, cross-platform |

## Links

- npm: https://www.npmjs.com/package/@bonsai-components/meta-key
- npm.io page: https://npm.io/package/@bonsai-components/meta-key

## Dependencies (1)

- [@bonsai-components/detect-os](https://npm.io/package/@bonsai-components/detect-os.md) ^0.1.8

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.2.9 (latest) — 2025-03-04
- 1.2.8 — 2025-03-04
- 1.2.1 — 2023-03-14
- 1.2.0 — 2023-03-14
- 1.0.3 — 2021-12-22
- 1.0.2 — 2021-12-22
- 1.0.1 — 2021-12-22
- 1.0.0 — 2021-12-22
- 0.2.1 — 2021-12-21
- 0.2.0 — 2021-12-21
- 0.1.2 — 2021-12-21
- 0.1.1 — 2021-12-21
- 0.1.0 — 2021-12-21

## README

<p align="center"><img src="https://raw.githubusercontent.com/zieka/bonsai-components/main/svg/bonsai-logo.svg" height="250px" alt="Bonsai Logo"></p>

# Meta Key

## Intro

Meta keys vary based on the platform the user is on. This package aims to
make detection and actions (like printing the meta key as a string) easy.

## How to install

```
npm i @bonsai-components/meta-key
```

## How to use

There are 3 different variants:

- `metaKeyInBrowser` - handles detection in the browser
- `metaKeyInNodeProcess` - handles detection in node
- `metaKey` - universal detection (the most code delivered but handles universal usage)

All variants work the same way, `(metaKeyMap?: MetaKeyMap<T>) => T`. The keys of
`MetaKeyMap` are `mac`, `windows`, and `other`. The values of these fields can
be anything; one of the values will be returned depending on the platform
detection.

```ts
type VoidFunction = () => void;

const alertMetaKeyMap: MetaKeyMap<VoidFunction> = {
  mac: () => console.log('mac'),
  windows: () => console.log('windows'),
  other: () => console.log('other'),
};

const alertConsole: VoidFunction = metaKey<VoidFunction>(alertMetaKeyMap);
alertConsole();
```

If no `MetaKeyMap` is provided, the default maps to a string representing meta key symbol:

```ts
const metaKeyMapDefault: MetaKeyMap<string> = {
  mac: '⌘',
  windows: '⊞',
  other: '◆',
};

const metaKeyAsString: string = metaKey();
```

Additionally, if you pass a partial of the `MetaKeyMap` the missing keys will be
filled in with the default. This is handy when wanting to override one string:

```ts
const metaKeyAsString: string = metaKey({ windows: 'ctrl +' });
```

### Browser

```ts
import { metaKeyInBrowser } from '@bonsai-components/meta-key';
```

### Node Process

```ts
import { metaKeyInNodeProcess } from '@bonsai-components/meta-key';
```

### Universal

```ts
import { metaKey } from '@bonsai-components/meta-key';
```

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