open-index/open-npm huggingface dataset:
npm package: @hotoo/unistring
Description: Unicode String for JavaScript
Author: 闲耘
Latest version: 0.0.3

# UniString

Fast Unicode String.

![benchmark image](https://user-images.githubusercontent.com/143572/135718223-c8f70cd8-7092-4476-8d7e-b8c202f7d930.png)


## USAGE

```js
import unistring from '@hotoo/unistring';

// length:   1  2  2  4  8  11
// unilength:1  1  1  1  1  1
const str = '张 𤰉 😀 👦🏿 👨‍👩‍👧 👨‍👩‍👧‍👦';
const unistr = unistring(str);

str.length; // 33
unistr.length; // 9

str.substr(2, 1); // '�'
unistr.substr(2, 1); // '𤰉'

str.substr(5, 1); // '�'
str.substr(5, 2); // '😀'
unistr.substr(5, 1); // ' '
unistr.substr(5, 2); // ' 👦🏿'

str.split('');
// [ '张', ' ',
//   '�', '�', ' ',
//   '�', '�', ' ',
//   '�', '�', '�', '�', ' ',
//   '�', '�',  '‍',  '�', '�', '‍',  '�', '�', ' ',
//   '�', '�', '‍',  '�', '�', '‍', '�',  '�', '‍',  '�', '�'
// ]

unistr.split('');
// [ '张', ' ',
//   '𤰉', ' ',
//   '😀', ' ',
//   '👦🏿', ' ',
//   '👨‍👩‍👧', ' ',
//   '👨‍👩‍👧‍👦'
// ]
```

## References

- [String.prototype.split() - JavaScript](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String/split)
- [javascript - How to get character array from a string? - Stack Overflow](https://stackoverflow.com/questions/4547609/how-to-get-character-array-from-a-string/34717402#34717402)
npm package: @hotora/core
Description: A small engine for handling step combos and sequences with scoped actions.
Author: egorkk1211@gmail.com
Latest version: 2.0.3

# Core

Small engine for handling **step stages and sequences**.

Supports:

- step stage (`A + B`)
- stage sequences (`A+B → C`)
- scoped actions (same stages in different contexts)
- sequence timeouts

---

## Install

```bash
npm install @hotora/core
```

---

## Basic usage

```ts
const controller = new SequenceController<string>();

controller.register(["Ctrl", "S"], {
  handler: () => console.log("Save"),
});

controller.addStep("Ctrl");
controller.addStep("S");
const fired = controller.process();
for (const [event, handler] of fired) {
  handler(event);
}
```

---

## Keyboard example

```ts
const controller = new SequenceController<string>();
controller.register(["Ctrl", "S"], {
  handler: () => console.log("Save"),
});

window.addEventListener("keydown", (e) => {
  controller.addStep(e.code);
  const fired = controller.process();

  for (const [event, handler] of fired) {
    handler(event);
  }
});

window.addEventListener("keyup", (e) => {
  controller.removeStep(e.code);
});
```

---

## Stages

```ts
controller.register(["Ctrl", "S"], {
  handler: () => console.log("Save"),
});
```

---

## Sequences

```ts
controller.register(
  [
    ["Ctrl", "K"],
    ["Ctrl", "C"],
  ],
  {
    handler: () => console.log("Comment"),
  },
);
```

Execution order:

    Ctrl+K → Ctrl+C

---

## Scope

Scopes isolate actions so the same combos can exist in different
contexts.

```ts
controller.register(["Enter"], { handler: submitForm }, "modal");
controller.addStep("Enter");
const fired = controller.process("modal");

for (const [event, handler] of fired) {
  handler(event);
}
```

Default scope:

    $global

---

## Sequence timeout

Default: **3 seconds**

```ts
controller.register([["A"], ["B"]], {
  clearDuration: 5,
  handler: () => console.log("Triggered"),
});
```

---

## API

### register(sequence, setup, scope?)

Registers an action.

```ts
register(
  Combo | Sequence,
  {
    handler: (event) => void
    clearDuration?: number
  },
  scope?: string
): ActionId
```

---

### addStep(step)

Add step to active steps.

Used for events like `keydown`.

---

### process(scope?)

Processes a step.

Returns actions to execute.

```ts
const fired = controller.process();

for (const [event, handler] of fired) {
  handler(event);
}
```

---

### removeStep(step)

Removes step from active steps.

Used for events like `keyup`.

---

### unregister(id)

Removes registered action.

---

## Event

Handler receives:

```ts
{
  sequence: Sequence;
  activeSteps: Set;
  timestamp: number;
}
```

---

## License

MIT