mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-24 01:18:10 -07:00
25 lines
868 B
JavaScript
25 lines
868 B
JavaScript
import { normalize } from "../text.js";
|
|
|
|
const CHART_REQUEST = /\b(?:chart|graph|plot)\b/;
|
|
const ADD_REQUEST = /\b(?:add|include|overlay)\b/;
|
|
const REMOVE_REQUEST = /\b(?:remove|drop)\b/;
|
|
|
|
/**
|
|
* @param {string} request
|
|
* @param {boolean} hasActiveChart
|
|
*/
|
|
export function directChartCommand(request, hasActiveChart) {
|
|
const text = normalize(request);
|
|
|
|
if (hasActiveChart && ADD_REQUEST.test(text)) {
|
|
return { kind: /** @type {const} */ ("edit"), operation: /** @type {const} */ ("add") };
|
|
}
|
|
if (hasActiveChart && REMOVE_REQUEST.test(text)) {
|
|
return { kind: /** @type {const} */ ("edit"), operation: /** @type {const} */ ("remove") };
|
|
}
|
|
if (CHART_REQUEST.test(text) && !ADD_REQUEST.test(text) && !REMOVE_REQUEST.test(text)) {
|
|
return { kind: /** @type {const} */ ("build"), operation: /** @type {const} */ ("add") };
|
|
}
|
|
return undefined;
|
|
}
|