@busy-hour/blaze
Version:
<h1 align='center'>🔥 Blaze</h1> <div align='center'> An event driven framework for 🔥 Hono.js </div>
95 lines (93 loc) • 2.4 kB
JavaScript
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
}) : x)(function(x) {
if (typeof require !== "undefined")
return require.apply(this, arguments);
throw Error('Dynamic require of "' + x + '" is not supported');
});
// src/utils/common.ts
import fs from "node:fs";
import { createRequire } from "node:module";
import path from "node:path";
import { Logger } from "../internal/logger/index.js";
function hasOwnProperty(obj, property) {
return Object.hasOwn(obj, property);
}
function mapToObject(map, valueMapper) {
return Array.from(map.entries()).reduce(
(acc, [key, value]) => ({
...acc,
[key]: valueMapper ? valueMapper(value) : value
}),
{}
);
}
function toArray(value) {
return Array.isArray(value) ? value : [value];
}
function isNil(value) {
return value === null || value === void 0;
}
function removeTrailingSlash(path2) {
return path2.replace(/^\/+/, "");
}
async function resolvePromise(promise) {
try {
const res = await promise;
return [res, null];
} catch (err) {
return [null, err];
}
}
function isEmpty(value) {
if (Array.isArray(value)) {
return value.length === 0;
}
if (value && typeof value === "object") {
return Object.keys(value).length === 0;
}
return false;
}
function isOnCjs() {
return typeof module !== "undefined" && typeof exports !== "undefined";
}
function loadFile(id) {
if (isOnCjs()) {
return __require(id);
}
if (!fs.existsSync(id)) {
throw Logger.throw(`${id} doesn't exist`);
}
if (fs.statSync(id).isDirectory()) {
const infos = fs.readdirSync(id);
const index = infos.find(
(info) => info.match(/index\.[jt]s$|index\.[jt]x|index\.[cm][jt]s$/)
);
if (!index) {
throw Logger.throw(
`No index file found in directory ${id} (expected to find index.[jt]s or index.[jt]x or index.[cm][jt]s)`
);
}
return import(path.join(id, index));
}
return import(id);
}
function crossRequire(id) {
if (isOnCjs()) {
return __require(id);
}
const esmRequire = createRequire(import.meta.url);
return esmRequire(id);
}
export {
crossRequire,
hasOwnProperty,
isEmpty,
isNil,
isOnCjs,
loadFile,
mapToObject,
removeTrailingSlash,
resolvePromise,
toArray
};