-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunicode.js
More file actions
37 lines (30 loc) · 1.08 KB
/
Copy pathunicode.js
File metadata and controls
37 lines (30 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env node
"use strict";
// Unicode symbol list — search arrows, math, currency, greek, box-drawing.
const { readInput, writeResponse, list, error, stripKeyword } = require("@yoki/plugin-sdk");
const data = require("./data/unicode.json");
const { filterByQuery } = require("./lib");
const LIST_LIMIT = 80;
async function main() {
const input = await readInput();
let query = stripKeyword(input.query || "", "u", "unicode", "sym", "symbol");
// Tolerate "u:arrow" and "u: arrow" shorthand (legacy prefix).
if (query.startsWith(":")) {
query = query.slice(1).trim();
}
const results = filterByQuery(data, query, LIST_LIMIT, e => e.char + " " + e.name + " " + e.keywords);
const items = results.map((e, i) => ({
id: `u-${i}`,
title: e.char,
subtitle: e.name,
value: e.char,
actions: [
{ title: "Copy symbol", shortcut: "enter", type: "copy", value: e.char },
],
}));
writeResponse(list(items));
}
main().catch(e => {
try { writeResponse(error("Unicode error", e && e.message ? e.message : String(e))); } catch (_) {}
process.exit(1);
});