tezx 1.0.71 → 1.0.73

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE CHANGED
@@ -5,17 +5,17 @@ Copyright (c) 2025 SRAKIB17
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the “Software”), to deal
7
7
  in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
10
  furnished to do so, subject to the following conditions:
11
11
 
12
12
  The above copyright notice and this permission notice shall be included in all
13
13
  copies or substantial portions of the Software.
14
14
 
15
- THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
15
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
@@ -207,8 +207,15 @@ class Context {
207
207
  headers,
208
208
  });
209
209
  }
210
- html(data, ...args) {
210
+ html(strings, ...args) {
211
211
  let status = this.#status;
212
+ let data = strings;
213
+ if (Array.isArray(strings)) {
214
+ data = strings.reduce((result, str, i) => {
215
+ const value = args?.[i] ?? "";
216
+ return result + str + value;
217
+ }, "");
218
+ }
212
219
  let headers = {
213
220
  "Content-Type": "text/html; charset=utf-8",
214
221
  };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Router = void 0;
3
+ exports.Router = exports.TrieRouter = void 0;
4
4
  const staticFile_js_1 = require("../utils/staticFile.js");
5
5
  const url_js_1 = require("../utils/url.js");
6
6
  const config_js_1 = require("./config.js");
@@ -16,6 +16,7 @@ class TrieRouter {
16
16
  this.pathname = pathname;
17
17
  }
18
18
  }
19
+ exports.TrieRouter = TrieRouter;
19
20
  class Router extends MiddlewareConfigure_js_1.default {
20
21
  routers = new Map();
21
22
  env = {};
@@ -217,7 +218,7 @@ class Router extends MiddlewareConfigure_js_1.default {
217
218
  callback: callback,
218
219
  middlewares: finalMiddleware,
219
220
  });
220
- node.pathname = path;
221
+ node.pathname = `/${p}`;
221
222
  }
222
223
  #addRouteMiddleware(path, middlewareFunctions) {
223
224
  this.addMiddleware(path, middlewareFunctions);
package/cjs/index.js CHANGED
@@ -7,4 +7,4 @@ var server_js_1 = require("./core/server.js");
7
7
  Object.defineProperty(exports, "TezX", { enumerable: true, get: function () { return server_js_1.TezX; } });
8
8
  var params_js_1 = require("./utils/params.js");
9
9
  Object.defineProperty(exports, "useParams", { enumerable: true, get: function () { return params_js_1.useParams; } });
10
- exports.version = "1.0.71";
10
+ exports.version = "1.0.73";
package/cjs/utils/url.js CHANGED
@@ -3,9 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.wildcardOrOptionalParamRegex = void 0;
4
4
  exports.sanitizePathSplit = sanitizePathSplit;
5
5
  exports.urlParse = urlParse;
6
+ function normalizePath(path) {
7
+ return ('/' +
8
+ path
9
+ .replace(/\\/g, '')
10
+ .replace(/\/+/g, '/')
11
+ .replace(/^\/+/, ''));
12
+ }
6
13
  function sanitizePathSplit(basePath, path) {
7
14
  const parts = `${basePath}/${path}`
8
- .replace(/\\/g, "")
15
+ .replace(/\\/g, '')
16
+ .replace(/\/+/g, '/')
9
17
  ?.split("/")
10
18
  .filter(Boolean);
11
19
  return parts;
package/cjs/ws/node.js CHANGED
@@ -20,6 +20,7 @@ class NodeTransport {
20
20
  };
21
21
  }
22
22
  setupHandlers(ws, event, options) {
23
+ event.open?.(ws);
23
24
  ws.on("open", () => event.open?.(ws));
24
25
  ws.on("message", (data) => event.message?.(ws, data));
25
26
  ws.on("close", (code, reason) => event.close?.(ws, { code, reason }));
package/core/config.d.ts CHANGED
@@ -3,7 +3,7 @@ import { Callback, ctx } from "./router.js";
3
3
  export declare let GlobalConfig: {
4
4
  new (): {};
5
5
  notFound: Callback;
6
- onError: <T extends Record<string, any> = {}>(err: string, ctx: ctx<T>) => any;
6
+ onError: <T extends Record<string, any> = {}>(err: string, ctx: ctx<T>) => Response;
7
7
  allowDuplicateMw?: boolean;
8
8
  overwriteMethod?: boolean;
9
9
  debugMode?: boolean;
package/core/context.d.ts CHANGED
@@ -114,19 +114,20 @@ export declare class Context<T extends Record<string, any> = {}> {
114
114
  * @param headers - (Optional) Additional response headers.
115
115
  * @returns Response object.
116
116
  */
117
- send(body: any, status?: number, headers?: ResponseHeaders): any;
118
- send(body: any, headers?: ResponseHeaders): any;
119
- send(body: any, status?: number): any;
117
+ send(body: any, status?: number, headers?: ResponseHeaders): Response;
118
+ send(body: any, headers?: ResponseHeaders): Response;
119
+ send(body: any, status?: number): Response;
120
120
  /**
121
121
  * Sends an HTML response.
122
- * @param data - The HTML content as a string.
122
+ * @param strings - The HTML content as a string. Supports `both template literals` and plain string input..
123
123
  * @param status - (Optional) HTTP status code (default: 200).
124
124
  * @param headers - (Optional) Additional response headers.
125
125
  * @returns Response object with HTML data.
126
126
  */
127
- html(data: string, status?: number, headers?: ResponseHeaders): any;
128
- html(data: string, headers?: ResponseHeaders): any;
129
- html(data: string, status?: number): any;
127
+ html(strings: readonly string[], ...values: any[]): Response;
128
+ html(strings: string, status?: number, headers?: ResponseHeaders): Response;
129
+ html(strings: string, headers?: ResponseHeaders): Response;
130
+ html(strings: string, status?: number): Response;
130
131
  /**
131
132
  * Sends a plain text response.
132
133
  * @param data - The text content.
@@ -134,9 +135,9 @@ export declare class Context<T extends Record<string, any> = {}> {
134
135
  * @param headers - (Optional) Additional response headers.
135
136
  * @returns Response object with plain text data.
136
137
  */
137
- text(data: string, status?: number, headers?: ResponseHeaders): any;
138
- text(data: string, headers?: ResponseHeaders): any;
139
- text(data: string, status?: number): any;
138
+ text(data: string, status?: number, headers?: ResponseHeaders): Response;
139
+ text(data: string, headers?: ResponseHeaders): Response;
140
+ text(data: string, status?: number): Response;
140
141
  /**
141
142
  * Sends an XML response.
142
143
  * @param data - The XML content.
@@ -144,9 +145,9 @@ export declare class Context<T extends Record<string, any> = {}> {
144
145
  * @param headers - (Optional) Additional response headers.
145
146
  * @returns Response object with XML data.
146
147
  */
147
- xml(data: string, status?: number, headers?: ResponseHeaders): any;
148
- xml(data: string, headers?: ResponseHeaders): any;
149
- xml(data: string, status?: number): any;
148
+ xml(data: string, status?: number, headers?: ResponseHeaders): Response;
149
+ xml(data: string, headers?: ResponseHeaders): Response;
150
+ xml(data: string, status?: number): Response;
150
151
  /**
151
152
  * HTTP status code..
152
153
  * @param status - number.
package/core/context.js CHANGED
@@ -204,8 +204,15 @@ export class Context {
204
204
  headers,
205
205
  });
206
206
  }
207
- html(data, ...args) {
207
+ html(strings, ...args) {
208
208
  let status = this.#status;
209
+ let data = strings;
210
+ if (Array.isArray(strings)) {
211
+ data = strings.reduce((result, str, i) => {
212
+ const value = args?.[i] ?? "";
213
+ return result + str + value;
214
+ }, "");
215
+ }
209
216
  let headers = {
210
217
  "Content-Type": "text/html; charset=utf-8",
211
218
  };
package/core/router.d.ts CHANGED
@@ -19,7 +19,7 @@ export type RouterConfig = {
19
19
  */
20
20
  basePath?: string;
21
21
  };
22
- declare class TrieRouter {
22
+ export declare class TrieRouter {
23
23
  children: Map<string, TrieRouter>;
24
24
  handlers: Map<HTTPMethod, {
25
25
  callback: Callback<any>;
@@ -34,12 +34,13 @@ export type StaticServeOption = {
34
34
  cacheControl?: string;
35
35
  headers?: ResponseHeaders;
36
36
  };
37
+ export type RouterHandler<T extends Record<string, any>> = {
38
+ callback: Callback<T>;
39
+ middlewares: UniqueMiddlewares | DuplicateMiddlewares;
40
+ };
37
41
  export declare class Router<T extends Record<string, any> = {}> extends MiddlewareConfigure<T> {
38
42
  #private;
39
- protected routers: Map<string, Map<HTTPMethod, {
40
- callback: Callback<T>;
41
- middlewares: UniqueMiddlewares | DuplicateMiddlewares;
42
- }>>;
43
+ protected routers: Map<string, Map<HTTPMethod, RouterHandler<T>>>;
43
44
  protected env: Record<string, string | number>;
44
45
  protected triRouter: TrieRouter;
45
46
  constructor({ basePath, env }?: RouterConfig);
@@ -189,4 +190,3 @@ export declare class Router<T extends Record<string, any> = {}> extends Middlewa
189
190
  use(middleware: Middleware<T>): this;
190
191
  use(callback: Callback<T> | Router<T | any>): this;
191
192
  }
192
- export {};
package/core/router.js CHANGED
@@ -2,7 +2,7 @@ import { getFiles } from "../utils/staticFile.js";
2
2
  import { sanitizePathSplit, wildcardOrOptionalParamRegex, } from "../utils/url.js";
3
3
  import { GlobalConfig } from "./config.js";
4
4
  import MiddlewareConfigure, { TriMiddleware, } from "./MiddlewareConfigure.js";
5
- class TrieRouter {
5
+ export class TrieRouter {
6
6
  children = new Map();
7
7
  handlers = new Map();
8
8
  pathname;
@@ -214,7 +214,7 @@ export class Router extends MiddlewareConfigure {
214
214
  callback: callback,
215
215
  middlewares: finalMiddleware,
216
216
  });
217
- node.pathname = path;
217
+ node.pathname = `/${p}`;
218
218
  }
219
219
  #addRouteMiddleware(path, middlewareFunctions) {
220
220
  this.addMiddleware(path, middlewareFunctions);
package/index.js CHANGED
@@ -1,4 +1,4 @@
1
1
  export { Router } from "./core/router.js";
2
2
  export { TezX } from "./core/server.js";
3
3
  export { useParams } from "./utils/params.js";
4
- export let version = "1.0.71";
4
+ export let version = "1.0.73";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tezx",
3
- "version": "1.0.71",
3
+ "version": "1.0.73",
4
4
  "description": "TezX is a high-performance, lightweight JavaScript framework designed for speed, scalability, and flexibility. It enables efficient routing, middleware management, and static file serving with minimal configuration. Fully compatible with Node.js, Deno, and Bun.",
5
5
  "main": "cjs/index.js",
6
6
  "module": "index.js",
package/utils/url.js CHANGED
@@ -1,6 +1,14 @@
1
+ function normalizePath(path) {
2
+ return ('/' +
3
+ path
4
+ .replace(/\\/g, '')
5
+ .replace(/\/+/g, '/')
6
+ .replace(/^\/+/, ''));
7
+ }
1
8
  export function sanitizePathSplit(basePath, path) {
2
9
  const parts = `${basePath}/${path}`
3
- .replace(/\\/g, "")
10
+ .replace(/\\/g, '')
11
+ .replace(/\/+/g, '/')
4
12
  ?.split("/")
5
13
  .filter(Boolean);
6
14
  return parts;
package/ws/node.js CHANGED
@@ -17,6 +17,7 @@ export class NodeTransport {
17
17
  };
18
18
  }
19
19
  setupHandlers(ws, event, options) {
20
+ event.open?.(ws);
20
21
  ws.on("open", () => event.open?.(ws));
21
22
  ws.on("message", (data) => event.message?.(ws, data));
22
23
  ws.on("close", (code, reason) => event.close?.(ws, { code, reason }));