@static-pages/core 1.0.4 → 2.0.0

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/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  [![Build Status](https://app.travis-ci.com/staticpagesjs/core.svg?branch=master)](https://app.travis-ci.com/staticpagesjs/core)
4
4
  [![Coverage Status](https://coveralls.io/repos/github/staticpagesjs/core/badge.svg?branch=master)](https://coveralls.io/github/staticpagesjs/core?branch=master)
5
5
  ![npms.io (quality)](https://img.shields.io/npms-io/quality-score/@static-pages/core?label=quality)
6
- ![Maintenance](https://img.shields.io/maintenance/yes/2021)
6
+ ![Maintenance](https://img.shields.io/maintenance/yes/2022)
7
7
 
8
8
  This package contains only the core; this means it does not provide CLI support or readers and writers.
9
9
  You can import this library to your JS project then add your own controllers, readers and writers.
@@ -75,14 +75,18 @@ type Options = {
75
75
  from: Iterable<Data> | AsyncIterable<Data>;
76
76
  to: (data: Data) => void | Promise<void>;
77
77
  controller?: (data: Data) => undefined | Data | Data[] | Promise<undefined | Data | Data[]>;
78
+ variables: Record<string, unknown>;
78
79
  }[];
79
80
 
81
+ // Where `Data` is:
82
+ type Data = Record<string, unknown>;
83
+ // Or the same definition in a more known form:
80
84
  type Data = { [k: string]: unknown };
81
85
  ```
82
86
 
83
87
  ## Custom options for the controller
84
- You can define additional properties at the same level as the `from`, `to` and `controller` keys.
85
- These user defined properties are accessible through the `this` context variable of the controller.
88
+ You can pass additional configuration options to your controller under the `variables` property.
89
+ These variables are accessible through the `this` context variable of the controller.
86
90
 
87
91
  ```js
88
92
  require("@static-pages/core").default([{
@@ -91,7 +95,9 @@ require("@static-pages/core").default([{
91
95
  controller: function(data) {
92
96
  this.myProp; // <-- 123
93
97
  },
94
- myProp: 123,
98
+ variables: {
99
+ myProp: 123,
100
+ },
95
101
  }]);
96
102
  ```
97
103
 
package/cjs/index.d.ts CHANGED
@@ -4,7 +4,7 @@ export declare type Route = {
4
4
  from: Iterable<Data> | AsyncIterable<Data>;
5
5
  to: (data: Data) => void | Promise<void>;
6
6
  controller?: Controller;
7
- [key: string]: unknown;
7
+ variables?: Record<string, unknown>;
8
8
  };
9
9
  declare const _default: (routes: Route | Route[]) => Promise<void>;
10
10
  export default _default;
package/cjs/index.js CHANGED
@@ -9,7 +9,7 @@ exports.default = async (routes) => {
9
9
  for (const route of Array.isArray(routes) ? routes : [routes]) {
10
10
  if (typeof route !== 'object' || !route)
11
11
  throw new Error(`Route type mismatch, expected 'object', got '${getType(route)}'.`);
12
- const { from, to, controller, ...userOptions } = route;
12
+ const { from, to, controller, variables } = route;
13
13
  if (!isIterable(from) && !isAsyncIterable(from))
14
14
  throw new Error('Route \'from\' is not an \'iterable\' or an \'asyncIterable\'.');
15
15
  if (typeof to !== 'function')
@@ -18,7 +18,7 @@ exports.default = async (routes) => {
18
18
  throw new Error(`Route 'controller' type mismatch, expected 'function', got '${getType(controller)}'.`);
19
19
  const isController = typeof controller === 'function';
20
20
  for await (const data of from) {
21
- const results = isController ? await controller.call(userOptions, data) : data;
21
+ const results = isController ? await controller.call(variables, data) : data;
22
22
  if (typeof results === 'object' && results) {
23
23
  if (Array.isArray(results)) {
24
24
  for (const result of results) {
package/esm/index.d.ts CHANGED
@@ -4,7 +4,7 @@ export declare type Route = {
4
4
  from: Iterable<Data> | AsyncIterable<Data>;
5
5
  to: (data: Data) => void | Promise<void>;
6
6
  controller?: Controller;
7
- [key: string]: unknown;
7
+ variables?: Record<string, unknown>;
8
8
  };
9
9
  declare const _default: (routes: Route | Route[]) => Promise<void>;
10
10
  export default _default;
package/esm/index.js CHANGED
@@ -7,7 +7,7 @@ export default async (routes) => {
7
7
  for (const route of Array.isArray(routes) ? routes : [routes]) {
8
8
  if (typeof route !== 'object' || !route)
9
9
  throw new Error(`Route type mismatch, expected 'object', got '${getType(route)}'.`);
10
- const { from, to, controller, ...userOptions } = route;
10
+ const { from, to, controller, variables } = route;
11
11
  if (!isIterable(from) && !isAsyncIterable(from))
12
12
  throw new Error('Route \'from\' is not an \'iterable\' or an \'asyncIterable\'.');
13
13
  if (typeof to !== 'function')
@@ -16,7 +16,7 @@ export default async (routes) => {
16
16
  throw new Error(`Route 'controller' type mismatch, expected 'function', got '${getType(controller)}'.`);
17
17
  const isController = typeof controller === 'function';
18
18
  for await (const data of from) {
19
- const results = isController ? await controller.call(userOptions, data) : data;
19
+ const results = isController ? await controller.call(variables, data) : data;
20
20
  if (typeof results === 'object' && results) {
21
21
  if (Array.isArray(results)) {
22
22
  for (const result of results) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@static-pages/core",
3
- "version": "1.0.4",
3
+ "version": "2.0.0",
4
4
  "description": "General purpose static pages renderer.",
5
5
  "type": "module",
6
6
  "main": "./cjs/index.js",