nsp-server-pages 0.1.0 → 0.1.1

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/cjs/src/bundle.js CHANGED
@@ -6,13 +6,16 @@ const join = (a, b) => (a == null ? b : (b == null ? a : a + b));
6
6
  const bundle = (array, start, end) => {
7
7
  start = +start || 0;
8
8
  end = +end || array?.length || 0;
9
+ // empty
9
10
  if (end <= start) {
10
11
  return () => null;
11
12
  }
13
+ // single item
12
14
  if (end - 1 === start) {
13
15
  const node = array[start];
14
16
  return (typeof node === "function") ? node : () => node;
15
17
  }
18
+ // multiple items
16
19
  return context => {
17
20
  let result;
18
21
  let promise;
package/index.d.ts CHANGED
@@ -7,19 +7,21 @@
7
7
  export const createNSP: (options?: NSP.Options) => NSP.App;
8
8
 
9
9
  declare namespace NSP {
10
- type NodeFn<T> = (context?: T) => string | Promise<string>;
10
+ type NodeFn<T> = (context: T) => string | Promise<string>;
11
11
 
12
12
  type Node<T> = string | NodeFn<T>;
13
13
 
14
- type AttrFn<A, T = any> = (context?: T) => A;
14
+ type AttrFn<A, T = any> = (context: T) => A;
15
15
 
16
- type TagFn<A, T = any> = (tag: TagDef<A, T>) => NodeFn<T>;
16
+ type VoidFn<T> = (context: T) => void | Promise<void>;
17
17
 
18
- type LoaderFn = (path: string) => Promise<NodeFn<any>>;
18
+ type TagFn<A, T = any> = (tag: TagDef<A, T>) => (NodeFn<T> | VoidFn<T>);
19
19
 
20
- type TextFlex = string | Promise<string> | (string | Promise<string>)[];
20
+ type LoaderFn = (path: string) => Promise<NodeFn<any> | undefined>;
21
21
 
22
- type Build<T> = (nsp: App) => (context?: T) => string | Promise<string>;
22
+ type Strings = string | Promise<string> | Strings[];
23
+
24
+ type Build<T> = (nsp: App) => (context: T) => string | Promise<string>;
23
25
 
24
26
  interface TagDef<A, T = any> {
25
27
  app: App;
@@ -103,18 +105,18 @@ declare namespace NSP {
103
105
  /**
104
106
  * concat strings even if they are Promise<string>
105
107
  */
106
- concat(...text: TextFlex[]): string | Promise<string>;
108
+ concat(...text: Strings[]): string | Promise<string>;
107
109
 
108
110
  /**
109
111
  * retrieve a result from hook function
110
112
  */
111
- process<T>(type: "error", e: Error, context?: T): string;
113
+ process<T>(type: "error", e: Error, context: T): string;
112
114
 
113
- process<T>(type: "directive", src: string, context?: T): string;
115
+ process<T>(type: "directive", src: string, context: T): string;
114
116
 
115
- process<T>(type: "declaration", src: string, context?: T): string;
117
+ process<T>(type: "declaration", src: string, context: T): string;
116
118
 
117
- process<T>(type: "scriptlet", src: string, context?: T): string;
119
+ process<T>(type: "scriptlet", src: string, context: T): string;
118
120
 
119
121
  /**
120
122
  * pickup the taglib function
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nsp-server-pages",
3
3
  "description": "NSP JavaScript Server Pages for Node.js",
4
- "version": "0.1.0",
4
+ "version": "0.1.1",
5
5
  "author": "@kawanet",
6
6
  "bugs": {
7
7
  "url": "https://github.com/kawanet/nsp-server-pages/issues"
@@ -13,7 +13,7 @@
13
13
  "devDependencies": {
14
14
  "@rollup/plugin-node-resolve": "^15.2.1",
15
15
  "@types/mocha": "^10.0.1",
16
- "@types/node": "^20.5.3",
16
+ "@types/node": "^20.5.4",
17
17
  "mocha": "^10.2.0",
18
18
  "typescript": "^5.1.6"
19
19
  },
package/src/bundle.js CHANGED
@@ -3,13 +3,16 @@ const join = (a, b) => (a == null ? b : (b == null ? a : a + b));
3
3
  export const bundle = (array, start, end) => {
4
4
  start = +start || 0;
5
5
  end = +end || array?.length || 0;
6
+ // empty
6
7
  if (end <= start) {
7
8
  return () => null;
8
9
  }
10
+ // single item
9
11
  if (end - 1 === start) {
10
12
  const node = array[start];
11
13
  return (typeof node === "function") ? node : () => node;
12
14
  }
15
+ // multiple items
13
16
  return context => {
14
17
  let result;
15
18
  let promise;