ref: add base ext & convert camel case

This commit is contained in:
Nan72 2025-02-14 12:25:24 +07:00
parent d948f42c49
commit bc4e00f685
No known key found for this signature in database
2 changed files with 31 additions and 12 deletions

25
src/base.ts Normal file
View File

@ -0,0 +1,25 @@
import {clipboard, HeadlessCommand, toast} from "@kksh/api/headless";
export class BaseExt extends HeadlessCommand {
_func: Function;
constructor(func: (text: string) => string) {
super();
this._func = func;
}
async load() {
if (!await clipboard.hasText()) {
await toast.error("Clipboard is empty");
return;
}
const clipboardText = await clipboard.readText();
const convertedText = this._func(clipboardText);
await clipboard.writeText(convertedText);
await toast.success(`Copied "${convertedText}"`);
return;
}
}

View File

@ -1,16 +1,10 @@
import { clipboard, expose, HeadlessCommand, toast } from "@kksh/api/headless"
import camelCase from "lodash/camelcase"
import {expose} from "@kksh/api/headless";
import camelCase from "lodash/camelcase";
import {BaseExt} from "./base";
class CamelCaseExt extends HeadlessCommand {
async load() {
if (!await clipboard.hasText()) return;
const clipboardText = await clipboard.readText();
const convertedText = camelCase(clipboardText);
await clipboard.writeText(convertedText);
await toast.success(`Copied: "${convertedText}"`);
return
class CamelCaseExt extends BaseExt {
constructor() {
super(camelCase);
}
}