Files
Curse/packages/frontend/src/aiscript/common.ts
かっこかり 42706970f2 fix(frontend): PlayのAiScriptバージョン判定が正しく動作しない問題を修正 (#16843)
* fix: aiscript 1.0.0 以外が全部レガシー扱いになる問題を修正 (MisskeyIO#1129)

* Update Changelog

---------

Co-authored-by: あわわわとーにゅ <17376330+u1-liquid@users.noreply.github.com>
2025-11-24 20:53:39 +09:00

24 lines
920 B
TypeScript

/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { errors, utils } from '@syuilo/aiscript';
import type { values } from '@syuilo/aiscript';
const extractVersionIdentifier = /^\/\/\/\s*@\s*(\d+)\.(\d+)\.\d+$/m;
export function getAiScriptVersion(script: string): { major: number; minor: number } | undefined {
const match = extractVersionIdentifier.exec(script);
return match ? { major: Number(match[1]), minor: Number(match[2]) } : undefined;
}
export function assertStringAndIsIn<A extends readonly string[]>(value: values.Value | undefined, expects: A): asserts value is values.VStr & { value: A[number] } {
utils.assertString(value);
const str = value.value;
if (!expects.includes(str)) {
const expected = expects.map((expect) => `"${expect}"`).join(', ');
throw new errors.AiScriptRuntimeError(`"${value.value}" is not in ${expected}`);
}
}