Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@actus/core

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@actus/core

This is the machine and inner core of the Actus command bar.

  • 2.3.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
decreased by-68.75%
Maintainers
1
Weekly downloads
 
Created
Source

@actus/core

This is the machine and inner core of the Actus command bar.

It consists of a Finite State Machine, an input parser, and a result ranking algorithm (self learning).

Usage

npm install @actus/core

See the Svelte example in packages/ for more detailed info.

import { interpret, filterAndSort, selectionMachine } from "@actus/core";

const selectionService = interpret(selectionMachine);
const commands = [
    {
        id: "1",
        title: "My command",
        description: "My description",
        exec: () => {
            console.log("Executed!");
        },
    },
];
selectionService.send("NEW_COMMANDS", commands);

// Bind it to the UI of choice and send events
// when the user inputs something or clicks on a result
selectionService.send("INPUT", "m");
selectionService.send("EXEC", "1");

The Finite State Machine

Have a look at src/selection-machine.ts to see the machine and its services / actions / guards implementations.

Here's a visaulization of the machine: vis

Commands

Type definition of a command:

type Command = {
    id: string;
    title: CommandTitle;
    description: CommandDescription;
    exec: ExecutionFn;
    getMatchString?: GenerateMatchStringFn;
    requiredArgs?: string[];
};
type CommandTitle = string | CommandTitleFn;
type CommandTitleFn = (input: ParserResult) => string;
type CommandDescription = string | CommandDescriptionFn;
type CommandDescriptionFn = (input: ParserResult) => string;
type ExecutionFn = (command: Command, input: ParserResult) => void;
type GenerateMatchStringFn = (input: ParserResult) => string;
type ParserResult = [string] | [string, ParserParams] | null;
type ParserParams = {
    [key: string]: string;
};

The parser

The parser is built using Nearley.

Check out src/grammar/parse-input.ne for the grammar.

Here's what the parse outputs:

type ParserResult = [string] | [string, ParserParams] | null;
type ParserParams = {
    [key: string]: string;
};

Examples:

hello                    -> ["hello"]
hello -p                 -> ["hello", {p: null}]
hello -p 1               -> ["hello", {p: "1"}]
hello -p 1 -r "hello x"  -> ["hello", {p: "1", r: "hello x"}]
hello -p "               -> null (broken string)

Self learning

It's self learning in the sense that it ranks items higher the more you pick them for a certain input. To follow trends and have new commands have achance to get to the top fairly quick, it doesn't keep the execution history forever but normalizes it from time to time. See src/exec-graph.ts for the implementation of this.

FAQs

Package last updated on 10 Jan 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc