A lightweight (~850 B) library for easy mac/window shortcut notation. kbd-txt convert shortcut text depending on the type of OS (window/linux/mac).

Overview

kbd-txt

A lightweight (~850 B) library for easy mac/window shortcut notation.
kbd-txt convert shortcut text depending on the type of OS (window/linux/mac).

Installation

# npm
npm install --save kbd-txt

# yarn
yarn add kbd-txt

Quick Usage

import { convert } from 'kbd-txt';

// Basic Usage
convert('Alt+S');
// Results
//   mac: Option+S
//   window: Alt+S

// Basic Usage 2 - $mod
convert('$mod+s');
// Results
//   mac: Command+S
//   window: Ctrl+S

// Symbol Usage
const options = { normalizeOptions: { useSymbol: true } };
convert('$mod+s', options);
// Results
//   mac: ⌘+S
//   window: Ctrl+S

Supported Keys

kbd-txt understands the following modifiers:

Meta: ['command', 'cmd', '⌘'],
Alt: ['alt', 'option', '⌥'],
Control: ['control', 'ctrl', '^'],
Shift: ['shift'],

API REFERENCE

convert

Convert shortcut text depending on the type of OS (window/linux/mac).

const options = { normalizeOptions: { useSymbol: true } };
convert('$mod+s', options);
// Results
//   mac: ⌘+S
//   window: Ctrl+S

Options

parseOptions: {
  separator?: string; // A string that identifies characters to use in separating the string.
}
normalizeOptions: {
  separator?: string; // A string used to separate one element of the array from the next in the resulting string.
  useSymbol?: boolean; // If true, Display as a symbol.
}

parseToToken

Parse the shortcut text and convert to Token(KeyboardEvent.key) format.
It's the same form as the Keyboard Event.key.
$mod is converted to Meta/Control depending on the type of OS.

parseToToken('$mod+S');
// Results
//   mac: ['Meta', 's']
//   window: ['Control', 's']

Options

separator?: string; // A string that identifies characters to use in separating the string.

normalizeToken

Merge Token[] to text according to the option.

normalizeToken(['Alt', 's']);
// Results
//   mac: Option+S
//   window: Alt+S

Options

separator?: string; // A string used to separate one element of the array from the next in the resulting string.
useSymbol?: boolean; // If true, Display as a symbol.

How it works

Shortcut Text --(parse)--> Token(KeyboardEvent.key) --(normalize)--> Shortcuts Text for OS

parse: Parse the shortcut text and convert to Token(KeyboardEvent.key) format
normalize: Merge Token[] to text according to the option

Roadmaps

  • Demo Site
  • CDN version
  • Option to view OS version as fixed (View only in Mac version, view only in Window version)

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

Distributed under the MIT License. See LICENSE for more information.

You might also like...

Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

Jan 3, 2023

A simple calculator for how many units of insulin to take with a meal depending on current and target blood sugar levels.

Insulin-Calculator One of my first programs, made to try building javascript-read HTML forms. A simple calculator for how many units of insulin to tak

Dec 26, 2021

A string of four operations of the library, can solve the js digital calculation accuracy of scientific notation and formatting problems, support for thousands of decimal point formatting output operations

A string of four operations of the library, can solve the js digital calculation accuracy of scientific notation and formatting problems, support for thousands of decimal point formatting output operations

Apr 6, 2022

Collection of SEO utilities like sitemap, robots.txt, etc. for a Remix Application

Remix SEO Collection of SEO utilities like sitemap, robots.txt, etc. for a Remix Features Generate Sitemap Generate Robots.txt Installation To use it,

Dec 21, 2022

Script to fetch all NFT owners using moralis API. This script output is a data.txt file containing all owner addresses of a given NFT and their balances.

Script to fetch all NFT owners using moralis API. This script output is a data.txt file containing all owner addresses of a given NFT and their balances.

🔎 Moralis NFT Snapshot Moralis NFT API will only return 500 itens at a time when its is called. For that reason, a simple logic is needed to fetch al

Jun 23, 2022

An online .txt file compressor, de-compressor tool which uses Huffman Coding for Lossless data compression.

An online .txt file compressor, de-compressor tool which uses Huffman Coding for Lossless data compression.

Text File Compressor De-compressor Web App This webapp uses Huffman Coding for Text Compression and De-compression. Made with JavaScript, HTML5 and CS

Dec 25, 2022

Decompose algorithms in commutator notation.

Commutator Decompose algorithms in commutator notation. Let be any group. If , then the commutator of and is the element . The expression denotes the

Dec 15, 2022

Obsidian plugin: Type text shortcuts that expand into javascript generated text.

Obsidian plugin: Type text shortcuts that expand into javascript generated text.

Obsidian Plugin - Text Expander JS (open beta) This Obsidian plugin allows the user to type text shortcuts that are replaced by (or "expanded into") j

Dec 27, 2022

Keyboard shortcut handler. KISS, light and library free.

Shortcut.js Shortcut.js is a JavaScript ES6 component that offers a global keyboard event handler. This way one can declare and react to any combinati

Sep 28, 2022
Comments
  • Shift symbol(⇧) not recognized

    Shift symbol(⇧) not recognized

    Shift symbol(⇧) not recognized in window/linux

    Issue

    console.log(convert('⌘+s')); // Ctrl+S
    console.log(convert('⇧+s')); // ⇧+S
    

    Expect

    console.log(convert('⌘+s')); // Ctrl+S
    console.log(convert('⇧+s')); // Shift+S
    
    bug good first issue 
    opened by hmu332233 0
Releases(v0.1.6)
  • v0.1.6(Sep 28, 2022)

    What's Changed

    • feat: Add CDN example by @hmu332233 in https://github.com/hmu332233/kbd-txt/pull/8
    • feat: Add option to view OS type as fixed by @hmu332233 in https://github.com/hmu332233/kbd-txt/pull/9

    Full Changelog: https://github.com/hmu332233/kbd-txt/compare/v0.1.4...v0.1.6

    Source code(tar.gz)
    Source code(zip)
  • v0.1.4(Sep 15, 2022)

    What's Changed

    • chore: Add function description annotation by @hmu332233 in https://github.com/hmu332233/kbd-txt/pull/5
    • fix: Fix Shift symbol(⇧) not recognized by @hmu332233 in https://github.com/hmu332233/kbd-txt/pull/7

    Full Changelog: https://github.com/hmu332233/kbd-txt/compare/v0.1.3...v0.1.4

    Source code(tar.gz)
    Source code(zip)
  • v0.1.3(Sep 12, 2022)

    What's Changed

    • fix: Fixed a bug that caused a type error when load a module by @hmu332233 in https://github.com/hmu332233/kbd-txt/pull/3

    Full Changelog: https://github.com/hmu332233/kbd-txt/compare/v0.1.2...v0.1.3

    Source code(tar.gz)
    Source code(zip)
  • v0.1.2(Sep 12, 2022)

    What's Changed

    • fix: Fixed a bug that didn't detect mac by @hmu332233 in https://github.com/hmu332233/kbd-txt/pull/2

    Full Changelog: https://github.com/hmu332233/kbd-txt/compare/v0.1.0...v0.1.2

    Source code(tar.gz)
    Source code(zip)
  • v0.1.0(Sep 12, 2022)

    What's Changed

    • feat: Add Bundler by @hmu332233 in https://github.com/hmu332233/kbd-txt/pull/1

    New Contributors

    • @hmu332233 made their first contribution in https://github.com/hmu332233/kbd-txt/pull/1

    Full Changelog: https://github.com/hmu332233/kbd-txt/compare/v0.0.1...v0.1.0

    Source code(tar.gz)
    Source code(zip)
  • v0.0.1(Sep 12, 2022)

Owner
Minung Han
Web Product Engineer / I love javascript!
Minung Han
Type Safe Object Notation & Validation

tson Type Safe Object Notation & Validation ?? Work in Progress, not ready for production... Features ?? Functional ?? Immutable ✅ Well tested Why? Af

null 9 Aug 10, 2022
Inter Process Communication Module for node supporting Unix sockets, TCP, TLS, and UDP. Giving lightning speed on Linux, Mac, and Windows. Neural Networking in Node.JS

Inter Process Communication Module for node supporting Unix sockets, TCP, TLS, and UDP. Giving lightning speed on Linux, Mac, and Windows. Neural Networking in Node.JS

Node IPC 43 Dec 9, 2022
MagicCap is a image/GIF capture suite for Mac and Linux

MagicCap is a image/GIF capture suite for Mac and Linux. You can get a precompiled copy from the releases page of this GitHub page.

null 5 Sep 15, 2022
An open-source, blazing fast code editor for Windows, Mac, and Linux.

Thermite An open-source, blazing fast code editor for Windows, Mac, and Linux. About Thermite is a Blazing Fast, Open-Source, Cross-Platform Code Edit

Keston 4 Oct 25, 2022
Requestly Desktop App (Mac, Linux, Windows)

Requestly Desktop App Requestly Desktop App. Debug your network request across all apps (Safari, Chrome, Firefox, Brave...) using a single app. Direct

Requestly 14 Jan 2, 2023
🆙 Upscayl - Free and Open Source AI Image Upscaler for Linux, MacOS and Windows built with Linux-First philosophy.

v1.3 will come around 12 September Upscayl ?? Free and Open Source AI Image Upscaler simplescreenrecorder-2022-08-23_20.17.02.mp4 Upscayl is a cross-p

Upscayl 8.7k Jan 9, 2023
An Anime Game launcher for Linux with automatic patching fixing detection of Linux/Wine and telemetry disabling

An Anime Game launcher for Linux with automatic patching fixing detection of Linux/Wine and telemetry disabling

An Anime Team 367 Jan 4, 2023
🆙 Upscayl - Free and Open Source AI Image Upscaler for Linux, MacOS and Windows built with Linux-First philosophy.

Upscayl ?? Free and Open Source AI Image Upscaler Upsacyl.Demo.mp4 Upscayl is a cross-platform application built with the Linux-first philosophy. This

Upscayl 5.1k Sep 21, 2022
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022