import { parse } from "https://deno.land/x/denops_std@v5.0.1/bufname/mod.ts";
Parse Vim's buffer name and return a Bufname
instance.
It throws errors when a given bufname
is not valid Vim's buffer name.
For example, if it contains unusable characters ("<>|?*).
import { assertEquals } from "https://deno.land/std@0.192.0/testing/asserts.ts";
import { parse } from "../bufname/mod.ts";
assertEquals(
parse("denops:///Users/John Titor/test.git"),
{
scheme: "denops",
expr: "/Users/John Titor/test.git",
},
);
assertEquals(
parse("denops:///Users/John Titor/test.git;foo=foo&bar=bar1&bar=bar2"),
{
scheme: "denops",
expr: "/Users/John Titor/test.git",
params: {
foo: "foo",
bar: ["bar1", "bar2"],
},
},
);
assertEquals(
parse("denops:///Users/John Titor/test.git#README.md"),
{
scheme: "denops",
expr: "/Users/John Titor/test.git",
fragment: "README.md",
},
);
assertEquals(
parse(
"denops:///Users/John Titor/test.git;foo=foo&bar=bar1&bar=bar2#README.md",
),
{
scheme: "denops",
expr: "/Users/John Titor/test.git",
params: {
foo: "foo",
bar: ["bar1", "bar2"],
},
fragment: "README.md",
},
);
This function does not handle path separator differences among platforms. That's
why it's recommended to restore the expr
with
fromFileUrl
after if a buffer name
was constructed from a real path. For example
import { assertEquals } from "https://deno.land/std@0.192.0/testing/asserts.ts";
import * as path from "https://deno.land/std/path/mod.ts";
import { parse } from "../bufname/mod.ts";
const bufname = parse("denops:///C:/Users/John%2520Titor/test.git");
assertEquals(bufname, {
scheme: "denops",
expr: "/C:/Users/John%20Titor/test.git",
});
// NOTE:
// Works only on Windows (Use path.win32.fromFileUrl instead on other platforms)
assertEquals(
path.fromFileUrl(`file://${bufname.expr}`),
"C:\\Users\\John Titor\\test.git",
);