estilo
Version:
Create color schemes for Vim, NeoVim, Airline and Lightline
67 lines (66 loc) • 1.92 kB
JavaScript
import * as dntShim from "../_dnt.shims.js";
import { resolve } from "../deps/jsr.io/@std/path/1.0.8/mod.js";
export function crash(message, data) {
console.log("%cError: " + message, "color: red");
if (data) {
console.log("%c" +
Object.keys(data)
.map((key) => `- ${key}: ${data[key]}`)
.join("\n"), "color: red");
}
dntShim.Deno.exit(1);
}
export function isHexColor(color) {
return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(color);
}
export function assertIsObject(input, filepath) {
if (typeof input !== "object" || input === null) {
crash("Content of file is not a list of strings", { filepath });
}
}
export function assertIsList(input, filepath) {
assertIsObject(input, filepath);
const content = input;
for (const key of Object.keys(input)) {
const value = content[key];
if (typeof value !== "string") {
crash("Content of file is not a list of strings", { filepath });
}
}
}
export function existsSync(path) {
try {
dntShim.Deno.statSync(path);
}
catch (e) {
return !e;
}
return true;
}
export async function ensureDir(dir) {
try {
const stat = await dntShim.Deno.stat(dir);
if (!stat.isDirectory) {
throw new Error(`Path exists but is not a directory: ${dir}`);
}
}
catch (error) {
if (error instanceof dntShim.Deno.errors.NotFound) {
const parent = resolve(dir, "..");
if (parent !== dir) {
await ensureDir(parent);
}
try {
await dntShim.Deno.mkdir(dir);
}
catch (err) {
if (!(err instanceof dntShim.Deno.errors.AlreadyExists)) {
throw err;
}
}
}
else {
throw error;
}
}
}