Update dist

This commit is contained in:
Benjamin Toby 2026-03-18 17:38:48 +01:00
parent eec0df83cd
commit 9b8e80728e
31 changed files with 1 additions and 761 deletions

View File

@ -1,52 +0,0 @@
import { readdirSync, statSync, unlinkSync } from "fs";
import grabAllPages from "../../utils/grab-all-pages";
import grabDirNames from "../../utils/grab-dir-names";
import grabPageName from "../../utils/grab-page-name";
import writeWebPageHydrationScript from "../server/web-pages/write-web-page-hydration-script";
import path from "path";
import bundle from "../../utils/bundle";
const { BUNX_HYDRATION_SRC_DIR, HYDRATION_DST_DIR } = grabDirNames();
export default async function allPagesBundler() {
console.time("build");
const pages = grabAllPages({ exclude_api: true });
for (let i = 0; i < pages.length; i++) {
const page = pages[i];
const pageName = grabPageName({ path: page.local_path });
writeWebPageHydrationScript({
pageName,
page_file: page.local_path,
});
}
const hydration_files = readdirSync(BUNX_HYDRATION_SRC_DIR);
for (let i = 0; i < hydration_files.length; i++) {
const hydration_file = hydration_files[i];
const valid_file = pages.find((p) => {
const pageName = grabPageName({ path: p.local_path });
const file_tsx_name = `${pageName}.tsx`;
if (file_tsx_name == hydration_file) {
return true;
}
return false;
});
if (!valid_file) {
unlinkSync(path.join(BUNX_HYDRATION_SRC_DIR, hydration_file));
}
}
const entrypoints = readdirSync(BUNX_HYDRATION_SRC_DIR)
.filter((f) => f.endsWith(".tsx"))
.map((f) => path.join(BUNX_HYDRATION_SRC_DIR, f))
.filter((f) => statSync(f).isFile());
// await Bun.build({
// entrypoints,
// outdir: HYDRATION_DST_DIR,
// minify: true,
// target: "browser",
// format: "esm",
// });
bundle({
src: entrypoints.join(" "),
out_dir: HYDRATION_DST_DIR,
exec_options: { stdio: "ignore" },
});
console.timeEnd("build");
}

View File

@ -1,19 +0,0 @@
import { existsSync } from "fs";
import grabDirNames from "../utils/grab-dir-names";
import exitWithError from "../utils/exit-with-error";
export default async function grabConfig() {
try {
const { CONFIG_FILE } = grabDirNames();
if (!existsSync(CONFIG_FILE)) {
exitWithError(`Config file \`${CONFIG_FILE}\` doesn't exist!`);
}
const config = (await import(CONFIG_FILE)).default;
if (!config) {
exitWithError(`Config file \`${CONFIG_FILE}\` is invalid! Please provide a valid default export in your config file.`);
}
return config;
}
catch (error) {
return undefined;
}
}

View File

@ -1,20 +0,0 @@
import { existsSync, mkdirSync, statSync, writeFileSync } from "fs";
import grabDirNames from "../utils/grab-dir-names";
export default async function () {
const dirNames = grabDirNames();
const keys = Object.keys(dirNames);
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
const dir = dirNames[key];
if (!existsSync(dir) && !dir.match(/\.\w+$/)) {
mkdirSync(dir, { recursive: true });
continue;
}
if (key == "CONFIG_FILE" && !existsSync(dir)) {
let basicConfig = ``;
basicConfig += `const config = {};\n`;
basicConfig += `export default config;\n`;
writeFileSync(dir, basicConfig);
}
}
}

View File

@ -1,26 +0,0 @@
import grabDirNames from "../../utils/grab-dir-names";
import grabAssetsPrefix from "../../utils/grab-assets-prefix";
import grabOrigin from "../../utils/grab-origin";
import grabRouter from "../../utils/grab-router";
export default async function getRoute({ route, }) {
const {} = grabDirNames();
if (route.match(/\(/)) {
return null;
}
const router = grabRouter();
const match = router.match(route);
if (!match?.filePath) {
console.error(`Route ${route} not found`);
return null;
}
const module = await import(match.filePath);
return {
match,
module,
component: module.default,
serverProps: module.serverProps,
staticProps: module.staticProps,
staticPaths: module.staticPaths,
staticParams: module.staticParams,
};
}

View File

@ -1,36 +0,0 @@
import grabRouteParams from "../../utils/grab-route-params";
import grabConstants from "../../utils/grab-constants";
import grabRouter from "../../utils/grab-router";
export default async function ({ req, server, }) {
const url = new URL(req.url);
const { MBInBytes, ServerDefaultRequestBodyLimitBytes } = await grabConstants();
const router = grabRouter();
const match = router.match(url.pathname);
if (!match?.filePath) {
const errMsg = `Route ${url.pathname} not found`;
console.error(errMsg);
return {
success: false,
status: 401,
msg: errMsg,
};
}
const routeParams = await grabRouteParams({ req });
const module = await import(match.filePath);
const config = module.config;
const contentLength = req.headers.get("content-length");
if (contentLength) {
const size = parseInt(contentLength, 10);
if ((config?.maxRequestBodyMB &&
size > config.maxRequestBodyMB * MBInBytes) ||
size > ServerDefaultRequestBodyLimitBytes) {
return {
success: false,
status: 413,
msg: "Request Body Too Large!",
};
}
}
const res = await module["default"](routeParams);
return res;
}

View File

@ -1,62 +0,0 @@
import path from "path";
import grabAppPort from "../../utils/grab-app-port";
import grabDirNames from "../../utils/grab-dir-names";
import handleWebPages from "./web-pages/handle-web-pages";
import handleRoutes from "./handle-routes";
import isDevelopment from "../../utils/is-development";
export default async function (params) {
const port = grabAppPort();
const { PUBLIC_DIR } = grabDirNames();
return {
async fetch(req, server) {
try {
const url = new URL(req.url);
if (url.pathname === "/__hmr" && isDevelopment()) {
let controller;
const stream = new ReadableStream({
start(c) {
controller = c;
global.HMR_CONTROLLERS.add(c);
},
cancel() {
global.HMR_CONTROLLERS.delete(controller);
},
});
return new Response(stream, {
headers: {
"Content-Type": "text/event-stream",
"Cache-Control": "no-cache",
Connection: "keep-alive",
},
});
}
else if (url.pathname.startsWith("/api/")) {
const res = await handleRoutes({ req, server });
return new Response(JSON.stringify(res), {
status: res?.status,
headers: {
"Content-Type": "application/json",
},
});
}
else if (url.pathname.startsWith("/public/")) {
const file = Bun.file(path.join(PUBLIC_DIR, url.pathname.replace(/^\/public/, "")));
return new Response(file);
}
else if (url.pathname.startsWith("/favicon.")) {
const file = Bun.file(path.join(PUBLIC_DIR, url.pathname));
return new Response(file);
}
else {
return await handleWebPages({ req });
}
}
catch (error) {
return new Response(`Server Error: ${error.message}`, {
status: 500,
});
}
},
port,
};
}

View File

@ -1,14 +0,0 @@
import AppNames from "../../utils/grab-app-names";
import serverParamsGen from "./server-params-gen";
import watcher from "./watcher";
export default async function startServer(params) {
const { name } = AppNames;
const serverParams = await serverParamsGen();
const server = Bun.serve(serverParams);
global.SERVER = server;
console.log(`${name} Server Running on http://localhost:${server.port} ...`);
if (params?.dev) {
watcher();
}
return server;
}

View File

@ -1,78 +0,0 @@
import { watch } from "fs";
import grabDirNames from "../../utils/grab-dir-names";
import grabPageName from "../../utils/grab-page-name";
import path from "path";
import serverParamsGen from "./server-params-gen";
import bundle from "../../utils/bundle";
import grabRouter from "../../utils/grab-router";
import allPagesBundler from "../bundler/all-pages-bundler";
const { ROOT_DIR, BUNX_HYDRATION_SRC_DIR, HYDRATION_DST_DIR, PAGES_DIR } = grabDirNames();
export default function watcher() {
watch(ROOT_DIR, { recursive: true, persistent: true }, async (event, filename) => {
if (global.RECOMPILING)
return;
if (!filename)
return;
if (filename.match(/ /))
return;
if (filename.match(/^node_modules\//))
return;
if (filename.match(/\.bunext|\/?public\//))
return;
if (!filename.match(/\.(tsx|ts|css|js|jsx)$/))
return;
if (filename.match(/\/pages\//)) {
try {
clearTimeout(global.WATCHER_TIMEOUT);
global.RECOMPILING = true;
await allPagesBundler();
global.LAST_BUILD_TIME = Date.now();
for (const controller of global.HMR_CONTROLLERS) {
controller.enqueue(`event: update\ndata: reload\n\n`);
}
global.RECOMPILING = false;
}
catch (error) {
console.error(`Bundler ERROR => ${error.message.substring(0, 120)} ...`);
}
// if (event == "change") {
// } else if (event == "rename") {
// await reloadServer();
// }
}
else if (filename.match(/\.(js|ts|tsx|jsx)$/)) {
clearTimeout(global.WATCHER_TIMEOUT);
await reloadServer();
}
});
// watch(BUNX_HYDRATION_SRC_DIR, async (event, filename) => {
// if (!filename) return;
// const targetFile = path.join(BUNX_HYDRATION_SRC_DIR, filename);
// await Bun.build({
// entrypoints: [targetFile],
// outdir: HYDRATION_DST_DIR,
// minify: true,
// target: "browser",
// format: "esm",
// });
// global.SERVER?.publish("__bun_hmr", "update");
// setTimeout(() => {
// global.RECOMPILING = false;
// }, 200);
// });
// watch(HYDRATION_DST_DIR, async (event, filename) => {
// const encoder = new TextEncoder();
// global.HMR_CONTROLLER?.enqueue(encoder.encode(`event: update\ndata: reload\n\n`));
// global.RECOMPILING = false;
// });
// let cmd = `bun build`;
// cmd += ` ${BUNX_HYDRATION_SRC_DIR}/*.tsx --outdir ${HYDRATION_DST_DIR}`;
// cmd += ` --watch --minify`;
// execSync(cmd, { stdio: "inherit" });
}
async function reloadServer() {
const serverParams = await serverParamsGen();
console.log(`Reloading Server ...`);
global.SERVER?.stop();
global.SERVER = Bun.serve(serverParams);
}

View File

@ -1,32 +0,0 @@
import path from "path";
import { renderToString } from "react-dom/server";
import grabContants from "../../../utils/grab-constants";
import EJSON from "../../../utils/ejson";
import isDevelopment from "../../../utils/is-development";
export default async function genWebHTML({ component, pageProps, pageName, module, }) {
const { ClientRootElementIDName, ClientWindowPagePropsName } = await grabContants();
const componentHTML = renderToString(component);
const SCRIPT_SRC = path.join("/public/pages", pageName + ".js");
let html = `<!DOCTYPE html>\n`;
html += `<html>\n`;
html += ` <head>\n`;
html += ` <meta charset="utf-8" />\n`;
if (isDevelopment()) {
html += `<script>
const hmr = new EventSource("/__hmr");
hmr.addEventListener("update", (event) => {
if (event.data === "reload") {
window.location.reload();
}
});
</script>\n`;
}
html += ` </head>\n`;
html += ` <body>\n`;
html += ` <div id="${ClientRootElementIDName}">${componentHTML}</div>\n`;
html += ` <script>window.${ClientWindowPagePropsName} = ${EJSON.stringify(pageProps || {}) || "{}"}</script>\n`;
html += ` <script src="${SCRIPT_SRC}" type="module"></script>\n`;
html += ` </body>\n`;
html += `</html>\n`;
return html;
}

View File

@ -1,62 +0,0 @@
import { jsx as _jsx } from "react/jsx-runtime";
import grabDirNames from "../../../utils/grab-dir-names";
import grabPageName from "../../../utils/grab-page-name";
import grabRouteParams from "../../../utils/grab-route-params";
import grabRouter from "../../../utils/grab-router";
import bundle from "../../../utils/bundle";
export default async function grabPageComponent({ req, file_path: passed_file_path, }) {
const url = req?.url ? new URL(req.url) : undefined;
const router = grabRouter();
const { BUNX_ROOT_500_PRESET_COMPONENT, HYDRATION_DST_DIR, BUNX_ROOT_500_FILE_NAME, } = grabDirNames();
const routeParams = req ? await grabRouteParams({ req }) : undefined;
try {
const match = url ? router.match(url.pathname) : undefined;
if (!match?.filePath && url?.pathname) {
const errMsg = `Page ${url.pathname} not found`;
console.error(errMsg);
throw new Error(errMsg);
}
const file_path = match?.filePath || passed_file_path;
if (!file_path) {
const errMsg = `No File Path (\`file_path\`) or Request Object (\`req\`) provided not found`;
console.error(errMsg);
throw new Error(errMsg);
}
const pageName = grabPageName({ path: file_path });
const module = await import(`${file_path}?t=${global.LAST_BUILD_TIME ?? 0}`);
const serverRes = await (async () => {
try {
if (routeParams) {
return await module["server"]?.(routeParams);
}
return {};
}
catch (error) {
return {};
}
})();
const Component = module.default;
const component = _jsx(Component, { ...serverRes });
return { component, serverRes, routeParams, pageName, module };
}
catch (error) {
const match = router.match("/500");
const filePath = match?.filePath || BUNX_ROOT_500_PRESET_COMPONENT;
// if (!match?.filePath) {
// bundle({
// out_dir: HYDRATION_DST_DIR,
// src: `${BUNX_ROOT_500_PRESET_COMPONENT}`,
// debug: true,
// });
// }
const module = await import(`${filePath}?t=${global.LAST_BUILD_TIME ?? 0}`);
const Component = module.default;
const component = _jsx(Component, {});
return {
component,
pageName: BUNX_ROOT_500_FILE_NAME,
routeParams,
module,
};
}
}

View File

@ -1,30 +0,0 @@
import genWebHTML from "./generate-web-html";
import grabPageComponent from "./grab-page-component";
import writeWebPageHydrationScript from "./write-web-page-hydration-script";
export default async function ({ req }) {
try {
const { component, pageName, module, serverRes } = await grabPageComponent({ req });
const html = await genWebHTML({
component,
pageProps: serverRes,
pageName,
module,
});
// writeWebPageHydrationScript({
// component,
// pageName,
// module,
// pageProps: serverRes,
// });
return new Response(html, {
headers: {
"Content-Type": "text/html",
},
});
}
catch (error) {
return new Response(error.message || `Page Not Found`, {
status: 404,
});
}
}

View File

@ -1,23 +0,0 @@
import { writeFileSync } from "fs";
import path from "path";
import grabDirNames from "../../../utils/grab-dir-names";
import grabContants from "../../../utils/grab-constants";
const { BUNX_HYDRATION_SRC_DIR } = grabDirNames();
export default async function (params) {
const { pageName, page_file } = params;
const { ClientRootElementIDName, ClientWindowPagePropsName } = await grabContants();
const pageSrcTsFileName = `${pageName}.tsx`;
let script = "";
script += `import React from "react";\n`;
script += `import { hydrateRoot } from "react-dom/client";\n`;
script += `import App from "${page_file}";\n`;
script += `declare global {\n`;
script += ` interface Window {\n`;
script += ` ${ClientWindowPagePropsName}: any;\n`;
script += ` }\n`;
script += `}\n`;
script += `const container = document.getElementById("${ClientRootElementIDName}");\n`;
script += `hydrateRoot(container, <App {...window.${ClientWindowPagePropsName}} />);\n`;
const SRC_WRITE_FILE = path.join(BUNX_HYDRATION_SRC_DIR, pageSrcTsFileName);
writeFileSync(SRC_WRITE_FILE, script, "utf-8");
}

View File

@ -1,11 +0,0 @@
import { jsx as _jsx } from "react/jsx-runtime";
export default function DefaultServerErrorPage() {
return (_jsx("div", { style: {
width: "100vw",
height: "100vh",
overflow: "hidden",
display: "flex",
alignItems: "center",
justifyContent: "center",
}, children: _jsx("span", { children: "500 Internal Server Error" }) }));
}

View File

@ -1 +0,0 @@
export {};

View File

@ -1,15 +0,0 @@
import { execSync } from "child_process";
export default function bundle({ out_dir, src, minify = true, exec_options, debug, }) {
let cmd = `bun build`;
cmd += ` ${src} --outdir ${out_dir}`;
if (minify) {
cmd += ` --minify`;
}
if (debug) {
console.log("cmd =>", cmd);
}
execSync(cmd, {
stdio: "inherit",
...exec_options,
});
}

View File

@ -1,18 +0,0 @@
import EJSON from "./ejson";
/**
* # Convert Serialized Query back to object
*/
export default function deserializeQuery(query) {
let queryObject = typeof query == "object" ? query : Object(EJSON.parse(query));
const keys = Object.keys(queryObject);
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
const value = queryObject[key];
if (typeof value == "string") {
if (value.match(/^\{|^\[/)) {
queryObject[key] = EJSON.parse(value);
}
}
}
return queryObject;
}

View File

@ -1,33 +0,0 @@
/**
* # EJSON parse string
*/
function parse(string, reviver) {
if (!string)
return undefined;
if (typeof string == "object")
return string;
if (typeof string !== "string")
return undefined;
try {
return JSON.parse(string, reviver);
}
catch (error) {
return undefined;
}
}
/**
* # EJSON stringify object
*/
function stringify(value, replacer, space) {
try {
return JSON.stringify(value, replacer || undefined, space);
}
catch (error) {
return undefined;
}
}
const EJSON = {
parse,
stringify,
};
export default EJSON;

View File

@ -1,4 +0,0 @@
export default function exitWithError(msg, code) {
console.error(msg);
process.exit(code || 1);
}

View File

@ -1,57 +0,0 @@
import { existsSync, readdirSync, statSync } from "fs";
import grabDirNames from "./grab-dir-names";
import path from "path";
export default function grabAllPages(params) {
const { PAGES_DIR } = grabDirNames();
const pages = grabPageDirRecursively({ page_dir: PAGES_DIR });
if (params?.exclude_api) {
return pages.filter((p) => !Boolean(p.url_path.startsWith("/api/")));
}
return pages;
}
function grabPageDirRecursively({ page_dir }) {
const pages = readdirSync(page_dir);
const pages_files = [];
const root_pages_file = grabPageFileObject({ file_path: `` });
if (root_pages_file) {
pages_files.push(root_pages_file);
}
for (let i = 0; i < pages.length; i++) {
const page = pages[i];
const full_page_path = path.join(page_dir, page);
if (!existsSync(full_page_path)) {
continue;
}
const page_stat = statSync(full_page_path);
if (page_stat.isDirectory()) {
if (page.match(/\(|\)/))
continue;
const new_page_files = grabPageDirRecursively({
page_dir: full_page_path,
});
pages_files.push(...new_page_files);
}
else if (page.match(/\.(ts|js)x?$/)) {
const pages_file = grabPageFileObject({
file_path: full_page_path,
});
if (pages_file) {
pages_files.push(pages_file);
}
}
}
return pages_files;
}
function grabPageFileObject({ file_path, }) {
let url_path = file_path
.replace(/.*\/pages\//, "/")
?.replace(/\.(ts|js)x?$/, "");
let file_name = url_path.split("/").pop();
if (!file_name)
return;
return {
local_path: file_path,
url_path,
file_name,
};
}

View File

@ -1,7 +0,0 @@
const AppNames = {
defaultPort: 7000,
defaultAssetPrefix: "_bunext/static",
name: "Bunext",
defaultDistDir: ".bunext",
};
export default AppNames;

View File

@ -1,17 +0,0 @@
import AppNames from "./grab-app-names";
import numberfy from "./numberfy";
export default function grabAppPort() {
const { defaultPort } = AppNames;
try {
if (process.env.PORT) {
return numberfy(process.env.PORT);
}
if (global.CONFIG.port) {
return global.CONFIG.port;
}
return numberfy(defaultPort);
}
catch (error) {
return numberfy(defaultPort);
}
}

View File

@ -1,8 +0,0 @@
import AppNames from "./grab-app-names";
export default function grabAssetsPrefix() {
if (global.CONFIG.assetsPrefix) {
return global.CONFIG.assetsPrefix;
}
const { defaultAssetPrefix } = AppNames;
return defaultAssetPrefix;
}

View File

@ -1,15 +0,0 @@
import path from "path";
import grabConfig from "../functions/grab-config";
export default async function grabConstants() {
const config = await grabConfig();
const MB_IN_BYTES = 1024 * 1024;
const ClientWindowPagePropsName = "__PAGE_PROPS__";
const ClientRootElementIDName = "__bunext";
const ServerDefaultRequestBodyLimitBytes = MB_IN_BYTES * 10;
return {
ClientRootElementIDName,
ClientWindowPagePropsName,
MBInBytes: MB_IN_BYTES,
ServerDefaultRequestBodyLimitBytes,
};
}

View File

@ -1,34 +0,0 @@
import path from "path";
export default function grabDirNames() {
const ROOT_DIR = process.cwd();
const SRC_DIR = path.join(ROOT_DIR, "src");
const PAGES_DIR = path.join(SRC_DIR, "pages");
const API_DIR = path.join(PAGES_DIR, "api");
const PUBLIC_DIR = path.join(ROOT_DIR, "public");
const HYDRATION_DST_DIR = path.join(PUBLIC_DIR, "pages");
const CONFIG_FILE = path.join(ROOT_DIR, "bunext.config.ts");
const BUNX_CWD_DIR = path.resolve(ROOT_DIR, ".bunext");
const BUNX_TMP_DIR = path.resolve(BUNX_CWD_DIR, ".tmp");
const BUNX_HYDRATION_SRC_DIR = path.resolve(BUNX_CWD_DIR, "client", "hydration-src");
const BUNX_ROOT_DIR = path.resolve(__dirname, "../../");
const BUNX_ROOT_SRC_DIR = path.join(BUNX_ROOT_DIR, "src");
const BUNX_ROOT_PRESETS_DIR = path.join(BUNX_ROOT_SRC_DIR, "presets");
const BUNX_ROOT_500_FILE_NAME = `server-error`;
const BUNX_ROOT_500_PRESET_COMPONENT = path.join(BUNX_ROOT_PRESETS_DIR, `${BUNX_ROOT_500_FILE_NAME}.tsx`);
return {
ROOT_DIR,
SRC_DIR,
PAGES_DIR,
API_DIR,
PUBLIC_DIR,
HYDRATION_DST_DIR,
BUNX_ROOT_DIR,
CONFIG_FILE,
BUNX_TMP_DIR,
BUNX_HYDRATION_SRC_DIR,
BUNX_ROOT_SRC_DIR,
BUNX_ROOT_PRESETS_DIR,
BUNX_ROOT_500_PRESET_COMPONENT,
BUNX_ROOT_500_FILE_NAME,
};
}

View File

@ -1,8 +0,0 @@
import grabAppPort from "./grab-app-port";
export default function grabOrigin() {
if (global.CONFIG.origin) {
return global.CONFIG.origin;
}
const port = grabAppPort();
return `http://localhost:${port}`;
}

View File

@ -1,10 +0,0 @@
export default function grabPageName(params) {
const pathArr = params.path.split("/");
const routesIndex = pathArr.findIndex((p) => p == "pages");
const newPathArr = [...pathArr].slice(routesIndex + 1);
const filename = newPathArr
.filter((p) => Boolean(p.match(/./)))
.map((p) => p.replace(/\.\w+$/, "").replace(/[^a-z]/g, ""))
.join("-");
return filename;
}

View File

@ -1,20 +0,0 @@
import deserializeQuery from "./deserialize-query";
export default async function grabRouteParams({ req, }) {
const url = new URL(req.url);
const query = deserializeQuery(Object.fromEntries(url.searchParams));
const body = await (async () => {
try {
return req.method == "GET" ? undefined : await req.json();
}
catch (error) {
return {};
}
})();
const routeParams = {
req,
url,
query,
body,
};
return routeParams;
}

View File

@ -1,11 +0,0 @@
import grabDirNames from "./grab-dir-names";
export default function grabRouter() {
const { PAGES_DIR } = grabDirNames();
if (process.env.NODE_ENV == "production") {
return global.ROUTER;
}
return new Bun.FileSystemRouter({
style: "nextjs",
dir: PAGES_DIR,
});
}

View File

@ -1,6 +0,0 @@
export default function isDevelopment() {
const config = global.CONFIG;
if (config.development)
return true;
return false;
}

View File

@ -1,31 +0,0 @@
export default function numberfy(num, decimals) {
try {
const numberString = String(num)
.replace(/[^0-9\.]/g, "")
.replace(/\.$/, "");
if (!numberString.match(/./))
return 0;
const existingDecimals = numberString.match(/\./)
? numberString.split(".").pop()?.length
: undefined;
const numberfiedNum = Number(numberString);
if (typeof numberfiedNum !== "number")
return 0;
if (isNaN(numberfiedNum))
return 0;
if (decimals == 0) {
return Math.round(Number(numberfiedNum));
}
else if (decimals) {
return Number(numberfiedNum.toFixed(decimals));
}
if (existingDecimals)
return Number(numberfiedNum.toFixed(existingDecimals));
return Math.round(numberfiedNum);
}
catch (error) {
console.log(`Numberfy ERROR: ${error.message}`);
return 0;
}
}
export const _n = numberfy;

View File

@ -17,6 +17,6 @@
"noPropertyAccessFromIndexSignature": false,
"outDir": "dist"
},
"include": ["src", "commands", "src/index.ts"],
"include": ["src"],
"exclude": ["node_modules", "dist"]
}