Skip to content

Commit ea015ee

Browse files
committed
📦 Update unknownutil to v4
1 parent d724f46 commit ea015ee

File tree

7 files changed

+55
-36
lines changed

7 files changed

+55
-36
lines changed

buffer/buffer.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Denops } from "@denops/core";
2-
import { maybe } from "@core/unknownutil";
2+
import { maybe } from "@core/unknownutil/maybe";
33
import { ulid } from "@std/ulid";
44
import * as autocmd from "../autocmd/mod.ts";
55
import * as batch from "../batch/mod.ts";

buffer/fileformat.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { assert, ensure, is, maybe, type Predicate } from "@core/unknownutil";
1+
import type { Predicate } from "@core/unknownutil/type";
2+
import { isLiteralOneOf } from "@core/unknownutil/is/literal-one-of";
23

34
export type FileFormat = "unix" | "dos" | "mac";
45

56
/**
67
* Predicate that the value is FileFormat.
78
*/
8-
export const isFileFormat: Predicate<FileFormat> = is.LiteralOneOf(
9+
export const isFileFormat: Predicate<FileFormat> = isLiteralOneOf(
910
["unix", "dos", "mac"] as const,
1011
);
1112

deno.jsonc

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
]
4242
},
4343
"imports": {
44-
"@core/unknownutil": "jsr:@core/unknownutil@^3.18.0",
44+
"@core/unknownutil": "jsr:@core/unknownutil@^4.0.0",
4545
"@denops/core": "jsr:@denops/core@^7.0.0",
4646
"@denops/test": "jsr:@denops/test@^3.0.1",
4747
"@lambdalisue/errorutil": "jsr:@lambdalisue/errorutil@^1.0.0",

function/types.ts

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { assert, is } from "@core/unknownutil";
1+
import { assert } from "@core/unknownutil/assert";
2+
import { isNumber } from "@core/unknownutil/is/number";
3+
import { isObjectOf } from "@core/unknownutil/is/object-of";
4+
import { isTupleOf } from "@core/unknownutil/is/tuple-of";
5+
import { isUnionOf } from "@core/unknownutil/is/union-of";
26

37
/**
48
* Type of `screenpos()` result.
@@ -15,12 +19,12 @@ export type ScreenPos = {
1519
*/
1620
export function isScreenPos(x: unknown): x is ScreenPos {
1721
const predObj = {
18-
row: is.Number,
19-
col: is.Number,
20-
endcol: is.Number,
21-
curscol: is.Number,
22+
row: isNumber,
23+
col: isNumber,
24+
endcol: isNumber,
25+
curscol: isNumber,
2226
};
23-
return is.ObjectOf(predObj)(x);
27+
return isObjectOf(predObj)(x);
2428
}
2529

2630
/**
@@ -45,9 +49,9 @@ export type Position = [
4549
* Return true if the value is Position.
4650
*/
4751
export function isPosition(x: unknown): x is Position {
48-
const pred = is.OneOf([
49-
is.TupleOf([is.Number, is.Number, is.Number, is.Number]),
50-
is.TupleOf([is.Number, is.Number, is.Number, is.Number, is.Number]),
52+
const pred = isUnionOf([
53+
isTupleOf([isNumber, isNumber, isNumber, isNumber]),
54+
isTupleOf([isNumber, isNumber, isNumber, isNumber, isNumber]),
5155
]);
5256
return pred(x);
5357
}

helper/expr_string.ts

+27-16
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,18 @@
2525
* @module
2626
*/
2727
import type { Context, Denops, Dispatcher, Meta } from "@denops/core";
28-
import { is } from "@core/unknownutil";
28+
import { isArray } from "@core/unknownutil/is/array";
29+
import { isBoolean } from "@core/unknownutil/is/boolean";
30+
import { isFunction } from "@core/unknownutil/is/function";
31+
import { isInstanceOf } from "@core/unknownutil/is/instance-of";
32+
import { isLiteralOf } from "@core/unknownutil/is/literal-of";
33+
import { isNullish } from "@core/unknownutil/is/nullish";
34+
import { isNumber } from "@core/unknownutil/is/number";
35+
import { isObjectOf } from "@core/unknownutil/is/object-of";
36+
import { isRecord } from "@core/unknownutil/is/record";
37+
import { isString } from "@core/unknownutil/is/string";
38+
import { isSymbol } from "@core/unknownutil/is/symbol";
39+
import { isUndefined } from "@core/unknownutil/is/undefined";
2940
import { ulid } from "@std/ulid";
3041
import { execute } from "./execute.ts";
3142

@@ -55,7 +66,7 @@ type TemplateSubstitutions = any[];
5566
const cacheKey = "denops_std/helper/expr_string@1";
5667

5768
async function ensurePrerequisites(denops: Denops): Promise<string> {
58-
if (is.String(denops.context[cacheKey])) {
69+
if (isString(denops.context[cacheKey])) {
5970
return denops.context[cacheKey];
6071
}
6172
const suffix = ulid();
@@ -95,9 +106,9 @@ export function exprQuote(
95106
});
96107
}
97108

98-
const isInstanceOfBoolean = is.InstanceOf(Boolean);
99-
const isInstanceOfNumber = is.InstanceOf(Number);
100-
const isInstanceOfString = is.InstanceOf(String);
109+
const isInstanceOfBoolean = isInstanceOf(Boolean);
110+
const isInstanceOfNumber = isInstanceOf(Number);
111+
const isInstanceOfString = isInstanceOf(String);
101112

102113
/**
103114
* Returns `true` if the value is a string marked as Vim's string constant format.
@@ -110,17 +121,17 @@ const isInstanceOfString = is.InstanceOf(String);
110121
* ```
111122
*/
112123
export function isExprString(x: unknown): x is ExprString {
113-
return is.ObjectOf({
114-
[EXPR_STRING_MARK]: is.LiteralOf(1),
124+
return isObjectOf({
125+
[EXPR_STRING_MARK]: isLiteralOf(1),
115126
})(x);
116127
}
117128

118129
function isJsonable(x: unknown): x is Jsonable {
119-
return x != null && is.Function((x as Jsonable).toJSON);
130+
return x != null && isFunction((x as Jsonable).toJSON);
120131
}
121132

122133
function isIgnoreRecordValue(x: unknown): boolean {
123-
return is.Undefined(x) || is.Function(x) || is.Symbol(x);
134+
return isUndefined(x) || isFunction(x) || isSymbol(x);
124135
}
125136

126137
/**
@@ -134,26 +145,26 @@ export function vimStringify(value: unknown, key?: string | number): string {
134145
// Return Vim's expr-string
135146
return `"${value.replaceAll('"', '\\"')}"`;
136147
}
137-
if ((is.Nullish(value) || is.Function(value) || is.Symbol(value))) {
148+
if ((isNullish(value) || isFunction(value) || isSymbol(value))) {
138149
return "v:null";
139150
}
140-
if (is.Boolean(value) || isInstanceOfBoolean(value)) {
151+
if (isBoolean(value) || isInstanceOfBoolean(value)) {
141152
// Return v:true or v:false
142153
return `v:${value}`;
143154
}
144-
if (is.Number(value) || isInstanceOfNumber(value)) {
155+
if (isNumber(value) || isInstanceOfNumber(value)) {
145156
// Replace `5e-10` to `5.0e-10`
146157
return `${value}`.replace(/^(\d+)e/, "$1.0e");
147158
}
148-
if (is.String(value) || isInstanceOfString(value)) {
159+
if (isString(value) || isInstanceOfString(value)) {
149160
// Returns Vim's literal-string
150161
return `'${value.replaceAll("'", "''")}'`;
151162
}
152-
if (is.Array(value)) {
163+
if (isArray(value)) {
153164
// Returns Vim's list
154165
return `[${value.map(vimStringify).join(",")}]`;
155166
}
156-
if (is.Record(value)) {
167+
if (isRecord(value)) {
157168
// Returns Vim's dict
158169
return `{${
159170
Object.entries(value)
@@ -169,7 +180,7 @@ export function vimStringify(value: unknown, key?: string | number): string {
169180
}
170181

171182
function trimEndOfArgs(args: unknown[]): unknown[] {
172-
const last = args.findIndex(is.Undefined);
183+
const last = args.findIndex(isUndefined);
173184
return last < 0 ? args : args.slice(0, last);
174185
}
175186

helper/input.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import type { Denops } from "@denops/core";
2-
import { assert, is } from "@core/unknownutil";
2+
import { assert } from "@core/unknownutil/assert";
3+
import { isNumber } from "@core/unknownutil/is/number";
4+
import { isString } from "@core/unknownutil/is/string";
35
import { ulid } from "@std/ulid";
46
import * as fn from "../function/mod.ts";
57
import * as lambda from "../lambda/mod.ts";
@@ -218,9 +220,9 @@ export async function input(
218220
const completion = options.completion ?? null;
219221
if (completion && typeof completion !== "string") {
220222
const id = lambda.register(denops, async (arglead, cmdline, cursorpos) => {
221-
assert(arglead, is.String);
222-
assert(cmdline, is.String);
223-
assert(cursorpos, is.Number);
223+
assert(arglead, isString);
224+
assert(cmdline, isString);
225+
assert(cursorpos, isNumber);
224226
return await completion(arglead, cmdline, cursorpos);
225227
});
226228
try {

helper/keymap.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Denops } from "@denops/core";
2-
import { is } from "@core/unknownutil";
2+
import { isArray } from "@core/unknownutil/is/array";
3+
import { isString } from "@core/unknownutil/is/string";
34
import {
45
exprQuote as q,
56
type ExprString,
@@ -18,11 +19,11 @@ export type Keys = {
1819
export type KeysSpecifier = Keys | Keys["keys"];
1920

2021
function toArray<T>(x: T | T[]): T[] {
21-
return is.Array(x) ? x : [x];
22+
return isArray(x) ? x : [x];
2223
}
2324

2425
function toKeys(keys: KeysSpecifier): Keys {
25-
if (is.String(keys) || isExprString(keys)) {
26+
if (isString(keys) || isExprString(keys)) {
2627
return { keys, remap: false };
2728
}
2829
return keys;

0 commit comments

Comments
 (0)