1.2.9 • Published 1 year ago
@bonsai-components/meta-key
Licence
(MIT OR Apache-2.0)
Version
1.2.9
Deps
1
Size
12 kB
Vulns
0
Weekly
0
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 browsermetaKeyInNodeProcess- handles detection in nodemetaKey- 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.
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:
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:
const metaKeyAsString: string = metaKey({ windows: 'ctrl +' });
Browser
import { metaKeyInBrowser } from '@bonsai-components/meta-key';
Node Process
import { metaKeyInNodeProcess } from '@bonsai-components/meta-key';
Universal
import { metaKey } from '@bonsai-components/meta-key';