1 | "use strict";
|
---|
2 |
|
---|
3 | Object.defineProperty(exports, "__esModule", {
|
---|
4 | value: true
|
---|
5 | });
|
---|
6 | exports.merge = merge;
|
---|
7 | exports.normalizeReplacements = normalizeReplacements;
|
---|
8 | exports.validate = validate;
|
---|
9 | const _excluded = ["placeholderWhitelist", "placeholderPattern", "preserveComments", "syntacticPlaceholders"];
|
---|
10 | function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
---|
11 | function merge(a, b) {
|
---|
12 | const {
|
---|
13 | placeholderWhitelist = a.placeholderWhitelist,
|
---|
14 | placeholderPattern = a.placeholderPattern,
|
---|
15 | preserveComments = a.preserveComments,
|
---|
16 | syntacticPlaceholders = a.syntacticPlaceholders
|
---|
17 | } = b;
|
---|
18 | return {
|
---|
19 | parser: Object.assign({}, a.parser, b.parser),
|
---|
20 | placeholderWhitelist,
|
---|
21 | placeholderPattern,
|
---|
22 | preserveComments,
|
---|
23 | syntacticPlaceholders
|
---|
24 | };
|
---|
25 | }
|
---|
26 | function validate(opts) {
|
---|
27 | if (opts != null && typeof opts !== "object") {
|
---|
28 | throw new Error("Unknown template options.");
|
---|
29 | }
|
---|
30 | const _ref = opts || {},
|
---|
31 | {
|
---|
32 | placeholderWhitelist,
|
---|
33 | placeholderPattern,
|
---|
34 | preserveComments,
|
---|
35 | syntacticPlaceholders
|
---|
36 | } = _ref,
|
---|
37 | parser = _objectWithoutPropertiesLoose(_ref, _excluded);
|
---|
38 | if (placeholderWhitelist != null && !(placeholderWhitelist instanceof Set)) {
|
---|
39 | throw new Error("'.placeholderWhitelist' must be a Set, null, or undefined");
|
---|
40 | }
|
---|
41 | if (placeholderPattern != null && !(placeholderPattern instanceof RegExp) && placeholderPattern !== false) {
|
---|
42 | throw new Error("'.placeholderPattern' must be a RegExp, false, null, or undefined");
|
---|
43 | }
|
---|
44 | if (preserveComments != null && typeof preserveComments !== "boolean") {
|
---|
45 | throw new Error("'.preserveComments' must be a boolean, null, or undefined");
|
---|
46 | }
|
---|
47 | if (syntacticPlaceholders != null && typeof syntacticPlaceholders !== "boolean") {
|
---|
48 | throw new Error("'.syntacticPlaceholders' must be a boolean, null, or undefined");
|
---|
49 | }
|
---|
50 | if (syntacticPlaceholders === true && (placeholderWhitelist != null || placeholderPattern != null)) {
|
---|
51 | throw new Error("'.placeholderWhitelist' and '.placeholderPattern' aren't compatible" + " with '.syntacticPlaceholders: true'");
|
---|
52 | }
|
---|
53 | return {
|
---|
54 | parser,
|
---|
55 | placeholderWhitelist: placeholderWhitelist || undefined,
|
---|
56 | placeholderPattern: placeholderPattern == null ? undefined : placeholderPattern,
|
---|
57 | preserveComments: preserveComments == null ? undefined : preserveComments,
|
---|
58 | syntacticPlaceholders: syntacticPlaceholders == null ? undefined : syntacticPlaceholders
|
---|
59 | };
|
---|
60 | }
|
---|
61 | function normalizeReplacements(replacements) {
|
---|
62 | if (Array.isArray(replacements)) {
|
---|
63 | return replacements.reduce((acc, replacement, i) => {
|
---|
64 | acc["$" + i] = replacement;
|
---|
65 | return acc;
|
---|
66 | }, {});
|
---|
67 | } else if (typeof replacements === "object" || replacements == null) {
|
---|
68 | return replacements || undefined;
|
---|
69 | }
|
---|
70 | throw new Error("Template replacements must be an array, object, null, or undefined");
|
---|
71 | }
|
---|
72 |
|
---|
73 | //# sourceMappingURL=options.js.map
|
---|