-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
44 lines (40 loc) · 1.22 KB
/
Copy pathindex.js
File metadata and controls
44 lines (40 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* @typedef PMEUserConfig
*
* @property {import("puppeteer").LaunchOptions} [launchOptions]
* Options passed to Puppeteer when it launches a browser instance.
*
* {@link https://pptr.dev/api/puppeteer.launchoptions}
*
* @property {import("liquidjs").LiquidOptions} [liquidOptions]
* Options passed to the Liquid constructor.
*
* {@link https://liquidjs.com/api/interfaces/LiquidOptions.html}
*
* @property {import("puppeteer").PDFOptions} [pdfOptions]
* Options passed to Puppeteer when it generates a PDF.
*
* {@link https://pptr.dev/api/puppeteer.pdfoptions}
*/
const validKeys = ["launchOptions", "liquidOptions", "pdfOptions"];
/**
* A helper for defining config objects.
*
* @param {PMEUserConfig} config
*
* @throws {TypeError}
* If provided an argument that is not an object or if the object argument
* contains invalid keys.
*
* @returns {PMEUserConfig}
*/
export function defineConfig(config) {
if (Object.prototype.toString.call(config) !== "[object Object]") {
throw new TypeError("invalid config provided");
}
const keys = Object.keys(config);
if (new Set([...validKeys, ...keys]).size > validKeys.length) {
throw new TypeError("invalid config keys provided");
}
return config;
}