Skip to content

Commit

Permalink
Merge pull request #17 from hmu332233/feature/readme
Browse files Browse the repository at this point in the history
Update README
  • Loading branch information
hmu332233 authored Jan 28, 2023
2 parents 0e9b897 + df079f5 commit cf5e203
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 145 deletions.
146 changes: 5 additions & 141 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,149 +6,13 @@ A lightweight (~850 B) library for easy mac/window shortcut notation.
This is useful when you want to display a shortcut text that fits user's OS.
It is also useful for converting mac's shortcut keys to symbols.

## Installation
**[Demo »](https://kbd-txt.minung.dev)**
**[Getting Started »](https://kbd-txt.minung.dev/docs/getting-started/introduction)**

Using npm/yarn:
## Packages

```bash
# npm
npm install --save kbd-txt

# yarn
yarn add kbd-txt
```

Using unpkg CDN:

```html
<script src="https://unpkg.com/kbd-txt/dist/kbd-txt.umd.js"></script>
```

## Quick Usage

```js
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
```

### Use CDN

```html
<script src="https://unpkg.com/kbd-txt/dist/kbd-txt.umd.js">
kbdTxt.convert('Alt+S');
kbdTxt.convert('$mod+s');
kbdTxt.convert('$mod+s', { normalizeOptions: { useSymbol: true } });
</script>
```

## 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).

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

**Options**

```ts
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.
os?: 'window' | 'mac' // If set, Display a shortcut text that fits OS.
}
```

### 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.

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

**Options**

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

### normalizeToken

Merge Token[] to text according to the option.

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

**Options**

```ts
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.
os?: 'window' | 'mac' // If set, Display a shortcut text that fits OS.
```

## 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
- [x] CDN version
- [x] Option to view OS version as fixed (View only in Mac version, view only in Window version)
[pacakages/kbd-txt](https://github.com/hmu332233/kbd-txt/tree/feature/readme/packages/kbd-txt): Main Library
[pacakages/docs](https://github.com/hmu332233/kbd-txt/tree/main/packages/kbd-txt): Docs using Docusaurus 2

## Contributing

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"scripts": {
"dev": "turbo dev",
"build": "turbo build",
"test": "turbo test"
"test": "turbo test",
"prepare": "husky install"
}
}
5 changes: 4 additions & 1 deletion packages/kbd-txt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ A lightweight (~850 B) library for easy mac/window shortcut notation.
This is useful when you want to display a shortcut text that fits user's OS.
It is also useful for converting mac's shortcut keys to symbols.

**[Demo »](https://kbd-txt.minung.dev)**
**[Getting Started »](https://kbd-txt.minung.dev/docs/getting-started/introduction)**

## Installation

Using npm/yarn:
Expand Down Expand Up @@ -146,7 +149,7 @@ normalize: Merge Token[] to text according to the option

## Roadmaps

- [ ] Demo Site
- [x] Demo Site
- [x] CDN version
- [x] Option to view OS version as fixed (View only in Mac version, view only in Window version)

Expand Down
3 changes: 1 addition & 2 deletions packages/kbd-txt/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "kbd-txt",
"description": "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).",
"version": "0.1.6",
"version": "1.0.0",
"author": "Minung Han <[email protected]>",
"type": "module",
"source": "src/index.ts",
Expand Down Expand Up @@ -35,7 +35,6 @@
"pretest": "yarn build:ts",
"test": "jest",
"test:coverage": "jest --coverage",
"prepare": "husky install",
"format": "prettier src/**/* --write --ignore-unknown",
"clean": "rm -rf ./dist ./dist-test",
"prepack": "yarn build"
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6834,6 +6834,11 @@ jsonfile@^6.0.1:
array-includes "^3.1.5"
object.assign "^4.1.3"

kbd-txt@^0.1.6:
version "0.1.6"
resolved "https://registry.yarnpkg.com/kbd-txt/-/kbd-txt-0.1.6.tgz#395c2aaacc6cd7e4134df0694411f48190f1f596"
integrity sha512-i8YaRLynaQELtLJwOblKE5rHo5xDzDtRG2F6/TfO2MlHA68cAqOVg4N10eC76PP/A7yyzsc3SH8DOEi21k9Nzw==

keyv@^3.0.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/keyv/-/keyv-3.1.0.tgz#ecc228486f69991e49e9476485a5be1e8fc5c4d9"
Expand Down

1 comment on commit cf5e203

@vercel
Copy link

@vercel vercel bot commented on cf5e203 Jan 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.