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

@box-ik/ng-codes

v1.0.2

Published

Codes for Angular - create events for keystroke sequences

Downloads

5

Readme

BoxIK

@box-ik/ng-codes

Codes for Angular - create events for keystroke sequences.

Installation

npm install @box-ik/ng-codes

Quick Start

  1. Import BoxIkNgCodesModule
  2. Add codes with ngCodesService.use([...])
  3. Subscribe to code events with ngCodesService.code.subscribe(_ => {})
import { BoxIkNgCodesModule, BoxIkNgCodesService, BoxIkCode } from '@box-ik/ng-codes';

@NgModule({
  imports: [
    ...
    BoxIkNgCodesModule
  ]
  ...
})
export class AppModule {
  constructor(private ngCodesService: BoxIkNgCodesService) {
    
    // setup
    this.ngCodesService.use([
      new BoxIkCode('↑↑↓↓←→←→ba', 'The Konami Code')
    ]);
    
    // listen
    this.ngCodesService.code
      .subscribe((code: BoxIkCode) => {
        console.info(`'${code.description}' was activated`);
      });
  }
}

What is Code?

Code is a sequence of lowercase characters, special characters, arrows, numbers, spaces and enters.
Use next symbols to specify arrows: (U+2190), (U+2191), (U+2192), (U+2193) and (U+21B5) for Enter.
Several well known codes:

  • ↑↑↓↓←→←→ba - The Konami Code;
  • iddqd - DOOM: God Mode;
  • abacabb - Mortal Kombat: Blood Code.

Keystroke listening

Service listen keystrokes all the time except:

  • it was manually paused;
  • input or textarea elements are in focus.

There are ignored keys and they can not be used in code sequence:

  • unused keys: Escape, Backspace, CapsLock, Tab, Shift;
  • keys with modifiers: ctrl, alt, meta.

NOTE: Shift as modifier could be used for special characters input ~!@#$%^&*()_+.

Сode matching

Added codes are sorted by its length and codes with equal length sorted lexicographically.
User input is compared with each code in reverse order - the longest match wins.

If time interval between keys more then resetInterval or match found then user input will be reseted.

API

BoxIkCode

value: string

Сode sequence.

description: string | null

User friendly description

BoxIkNgCodesService

use(codes: BoxIkCode[]): CodeError[] | null

Add codes to checking loop. Multiple calls will merge provided codes. See Errors

list(): BoxIkCode[]

List of currently available codes.

removeAll(): void

Remove all codes.

code: Observable<BoxIkCode>

Observable for activated codes.

paused: boolean

Pause code checking loop.

resetInterval: number

Number of milliseconds without keystroke to start new input sequence.

Errors

Each code is validating by use() function and if invalid will be ignored.

Possible errors:

  • EmptyCode (Empty code found) - code can not be an empty string;
  • InvalidSymbolsInCode (Code '<code>' has invalid symbols <symbols>) - check that code sequence has no uppercase symbols;
  • UnreachableCode (Code '<subcode0><subcode1>' is unreachable because of '<subcode0>') - substring codes are reachable only if they are suffixes;
  • DuplicateCode (Code '<code>' has duplicates) - trying to add multiple codes with the same value.

License

MIT