htmv 0.0.26 → 0.0.27

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/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  import type { Paths } from "./types";
2
+ export type { RouteParams } from "./types";
2
3
  export { view } from "./views";
3
4
  export declare function setup(paths: Paths): Promise<void>;
package/dist/views.js CHANGED
@@ -13,8 +13,13 @@ export async function view(view, props) {
13
13
  .replace(/{(.+)}/g, (_, propName) => {
14
14
  return props[propName];
15
15
  })
16
- .replace(/<Isset\s+(\w+)>([\s\S]*?)<\/Isset>/g, (_, propName, innerContent) => {
17
- if (props[propName] !== undefined && props[propName] !== null)
16
+ .replace(/<Isset\s+(\w+)>([\s\S]*?)<\/Isset>/g, (_, propNameWithPrefix, innerContent) => {
17
+ const isNegated = propNameWithPrefix.startsWith("!");
18
+ const propName = isNegated
19
+ ? propNameWithPrefix.slice(1)
20
+ : propNameWithPrefix;
21
+ const exists = props[propName] !== undefined && props[propName] !== null;
22
+ if (isNegated ? !exists : exists)
18
23
  return innerContent;
19
24
  return "";
20
25
  });
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "htmv",
3
3
  "main": "dist/index.js",
4
4
  "type": "module",
5
- "version": "0.0.26",
5
+ "version": "0.0.27",
6
6
  "devDependencies": {
7
7
  "@biomejs/biome": "2.3.3",
8
8
  "@types/bun": "latest"
package/src/index.ts CHANGED
@@ -3,6 +3,7 @@ import { registerRoutes } from "./routing";
3
3
  import type { Paths } from "./types";
4
4
  import { setViewsPath } from "./views";
5
5
 
6
+ export type { RouteParams } from "./types";
6
7
  export { view } from "./views";
7
8
 
8
9
  export async function setup(paths: Paths) {
package/src/views.ts CHANGED
@@ -20,9 +20,15 @@ export async function view(view: string, props: Record<string, unknown>) {
20
20
  })
21
21
  .replace(
22
22
  /<Isset\s+(\w+)>([\s\S]*?)<\/Isset>/g,
23
- (_, propName, innerContent) => {
24
- if (props[propName] !== undefined && props[propName] !== null)
25
- return innerContent;
23
+ (_, propNameWithPrefix: string, innerContent: string) => {
24
+ const isNegated = propNameWithPrefix.startsWith("!");
25
+ const propName = isNegated
26
+ ? propNameWithPrefix.slice(1)
27
+ : propNameWithPrefix;
28
+ const exists =
29
+ props[propName] !== undefined && props[propName] !== null;
30
+
31
+ if (isNegated ? !exists : exists) return innerContent;
26
32
  return "";
27
33
  },
28
34
  );