Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

依存関係のアップデート #18

Merged
merged 2 commits into from
Aug 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions denops/kensaku/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Denops } from "jsr:@denops/std@^7.0.0";
import { assert, is } from "jsr:@core/unknownutil@^3.18.1";
import { as, assert, is } from "jsr:@core/unknownutil@^4.0.0";
import { assertQueryOption, query, setRomanTable } from "./migemo.ts";

export function main(denops: Denops): void {
Expand All @@ -23,4 +23,4 @@ export function main(denops: Denops): void {

const isRomanTable = is.ArrayOf<
[roman: string, hiragana: string, remain?: number]
>(is.ParametersOf([is.String, is.String, is.OptionalOf(is.Number)] as const));
>(is.ParametersOf([is.String, is.String, as.Optional(is.Number)] as const));
15 changes: 5 additions & 10 deletions denops/kensaku/migemo.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import type { Denops } from "jsr:@denops/std@^7.0.0";
import {
assert,
isRecord,
isString,
isUndefined,
} from "jsr:@core/unknownutil@^3.18.1";
import { assert, is } from "jsr:@core/unknownutil@^4.0.0";
import * as path from "jsr:@std/path@^1.0.2";
import * as fs from "jsr:@std/fs@^1.0.0";
import * as batch from "jsr:@denops/std@^7.0.0/batch";
import * as vars from "jsr:@denops/std@^7.0.0/variable";
import * as jsmigemo from "https://cdn.jsdelivr.net/npm/jsmigemo@0.4.8/dist/jsmigemo.min.mjs";
import * as jsmigemo from "npm:jsmigemo@^0.4.8";
import { decompose, isKensakuRxop, KensakuRxop } from "./rxop.ts";

let migemo: jsmigemo.Migemo | undefined;
Expand All @@ -32,8 +27,8 @@ async function init(denops: Denops): Promise<jsmigemo.Migemo> {
vars.g.get(denops, "kensaku_dictionary_cache"),
],
);
assert(dictionaryUrl, isString);
assert(dictionaryCache, isString);
assert(dictionaryUrl, is.String);
assert(dictionaryCache, is.String);

const data = await readOrFetch(dictionaryUrl, dictionaryCache);
const dict = new jsmigemo.CompactDictionary(data.buffer);
Expand Down Expand Up @@ -70,7 +65,7 @@ export type QueryOption = {
};

export function assertQueryOption(x: unknown): asserts x is QueryOption {
if (!isRecord(x) || (!isUndefined(x.rxop) && !isKensakuRxop(x.rxop))) {
if (!is.Record(x) || (!is.Undefined(x.rxop) && !isKensakuRxop(x.rxop))) {
throw new Error("Not a QueryOption");
}
}
Expand Down
30 changes: 12 additions & 18 deletions denops/kensaku/rxop.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
isArray,
isArrayOf,
isRecord,
isString,
isUndefined,
} from "jsr:@core/unknownutil@^3.18.1";
import { is } from "jsr:@core/unknownutil@^4.0.0";

// https://github.com/oguna/jsmigemo/blob/d33052525dcb4bacdddc1e0b1f39a3675831ec92/src/TernaryRegexGenerator.ts#L127
const defaultEscape = "\\.[]{}()*+-?^$|";
Expand Down Expand Up @@ -49,25 +43,25 @@ export type KensakuRxop =
};

export function isKensakuRxop(x: unknown): x is KensakuRxop {
if (isArrayOf(isString)(x)) {
if (is.ArrayOf(is.String)(x)) {
return x.length === 6 || x.length === 7;
} else if (isRecord(x)) {
} else if (is.Record(x)) {
return (
(isUndefined(x.prefix) || isString(x.prefix)) &&
isString(x.or) &&
isString(x.startGroup) &&
isString(x.endGroup) &&
isString(x.startClass) &&
isString(x.endClass) &&
isString(x.newline) &&
isString(x.escape)
(is.Undefined(x.prefix) || is.String(x.prefix)) &&
is.String(x.or) &&
is.String(x.startGroup) &&
is.String(x.endGroup) &&
is.String(x.startClass) &&
is.String(x.endClass) &&
is.String(x.newline) &&
is.String(x.escape)
);
}
return false;
}

export function decompose(rxop: KensakuRxop): [string, Rxop] {
if (isArray(rxop)) {
if (is.Array(rxop)) {
if (rxop.length === 6) {
return ["", [...rxop, defaultEscape]];
} else {
Expand Down