npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

kuaio

v0.0.2

Published

A modern shortcut JavaScript library.

Downloads

3

Readme

Kuaio

A modern shortcut JavaScript library.

中文 | English

Note: This library is under development, please do not use it in a production environment.

Getting Started

Browser Support

TODO

Installation

npm install kuaio

or

yarn add kuaio

or

pnpm add kuaio

Quick Start

import Kuaio from 'kuaio'

// Chain call
Kuaio.create()
  .Ctrl()
  .A()
  .on((e) => {
    console.log('Ctrl + a', e)
  })

// Use string definition
Kuaio.on('Ctrl + a', (e) => {
  console.log('Ctrl + a', e)
})

Usage

Create Instance

There are two ways to create an instance:

1. [Recommend] Create via the create method.

// 1. Create a global instance.
const instance = Kuaio.create()
// 2. Create a instance on the specified element.
const target = document.querySelector('#input')
const instance = Kuaio.create(target)
// 3. Use configuration.
const config = {
  preventDefault: true,
  stopPropagation: true
}
const instance = Kuaio.create(config)
// const instance = Kuaio.create(target, config)

2. Create via the new operator.

const target = document
const config = {}
const instance = new Kuaio(target, config)

Create Listener

There are two ways to create an listener:

1. Chain Call

Kuaio.create()
  .Ctrl()
  .A()
  .on((e) => {
    console.log('Ctrl + a', e)
  })

2. String Definition

Created through the static method Kuaio.on.

Kuaio.on('Ctrl + a', (e) => {
  console.log('Ctrl + a', e)
})

NOTE: Kuaio.on('Ctrl + A') will not work, you may need to read TODO.

Trigger

Single Key

Kuaio provides built-in methods for efficient key selection from the standard US keyboard. When these methods are called, the specified key, excluding modifier keys, will serve as the trigger.

// General keys
Kuaio.create()
  .A()
  .on((e) => {})
// Function keys
Kuaio.create()
  .F1()
  .on((e) => {})
// Whitespace keys
Kuaio.create()
  .Enter()
  .on((e) => {})
// Navigation keys
Kuaio.create()
  .PageDown()
  .on((e) => {})
// Editing keys
Kuaio.create()
  .Backspace()
  .on((e) => {})
// UI keys
Kuaio.create()
  .Escape()
  .on((e) => {})

In addition, you can also use the key method to specify the trigger key, but it must be a valid value of KeyboardEvent.key.

You can easily get it with JavaScript Key Code Event Tool.

Kuaio.create()
  .key('a')
  .on((e) => {})

NOTE: You can use this method to set a modifier key as a trigger key, but this is not recommended.

Key Combination

Use a combination of modifier keys (Ctrl, Shift, etc.) with other trigger keys as triggers.

1. Chain Call

// 1. Use built-in modifier methods.
Kuaio.create()
  .Ctrl()
  .A()
  .on((e) => {
    console.log('Ctrl + a', e)
  })

Kuaio.create()
  .Ctrl()
  .Alt()
  .A()
  .on((e) => {
    console.log('Ctrl + Alt + a', e)
  })
// 2. Use the method `modifier` to specify modifiers.
Kuaio.create()
  .modifier('Shift')
  .A()
  .on((e) => {
    console.log('Shift + a', e)
  })

NOTE: You can use this method to set a trigger key as a modifier key, but this is not recommended.

2. String Definition

Kuaio.on('Ctrl + a', (e) => {
  console.log('Ctrl + a', e)
})
Kuaio.on('Ctrl + Alt + a', (e) => {
  console.log('Ctrl + Alt + a', e)
})

Sequence

You can define an sequence containing Single Key or Key Combination as a trigger, which will be triggered when the keyboard is pressed in a specified order. In fact this can also be called a key combination, but it is more powerful.

1. Chain Call

Kuaio.create()
  .Q()
  // Set timeout. Pressing the next key within this time will continue listening to the sequence, otherwise it will stop.
  .after(1000)
  .W()
  .after()
  .E()
  .after()
  .R()
  .on((e) => {
    console.log('q, w, e, r', e)
  })

Kuaio.create()
  .prventDefault()
  .Ctrl()
  .K()
  .after()
  .Ctrl()
  .C()
  .on((e) => {
    console.log('Ctrl + k, Ctrl + c', e)
  })

2. String Definition

Kuaio.on('q, w, e, r', (e) => {
  console.log('q, w, e, r', e)
})

Kuaio.on(
  'Ctrl + k, Ctrl + c',
  (e) => {
    console.log('Ctrl + k, Ctrl + c', e)
  },
  {
    preventDefault: true
  }
)

Keyboard Layout and Glyph Modifiers

TODO

US Layout