args-json
Version:
Zero-dependency descriptively typed command-line argument parser
9 lines (7 loc) • 347 B
text/typescript
import { isKey } from "./isKey.ts";
import { toCamelCase } from "./toCamelCase.ts";
export function toKey(x: string | undefined): string | undefined {
if (x === undefined || !isKey(x)) return;
if (x.startsWith("-") && x.length === 2) return toCamelCase(x.slice(1));
if (x.startsWith("--") && x.length > 2) return toCamelCase(x.slice(2));
}