UNPKG

2.25 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var gulp_util_1 = require("gulp-util");
4var common_1 = require("./common");
5/**
6 * A normalized configuration object based on arguments passed to
7 * the plugin.
8 *
9 * @internal
10 */
11var Config = (function () {
12 function Config(callback, encoding, thisArg) {
13 this.callback = callback;
14 this.encoding = encoding;
15 this.thisArg = thisArg;
16 }
17 Config.fromPluginArguments = function (arg0, arg1) {
18 var _a = this.resolveArgs(arg0, arg1), callback = _a[0], optionsOrEncoding = _a[1];
19 var options = this.resolveOptions(optionsOrEncoding);
20 var encoding = this.getEncoding(options);
21 var thisArg = this.getThisArg(options);
22 return new this(callback, encoding, thisArg);
23 };
24 Config.resolveArgs = function (arg0, arg1) {
25 if (common_1.isFunction(arg0))
26 return [arg0, arg1];
27 if (common_1.isFunction(arg1))
28 return [arg1, arg0];
29 throw new gulp_util_1.PluginError(common_1.PLUGIN_NAME, "callback is required");
30 };
31 Config.resolveOptions = function (optionsOrEncoding) {
32 if (common_1.isObjectLike(optionsOrEncoding))
33 return optionsOrEncoding;
34 if (common_1.isString(optionsOrEncoding))
35 return { encoding: optionsOrEncoding };
36 if (common_1.isNil(optionsOrEncoding))
37 return { encoding: null };
38 throw new gulp_util_1.PluginError(common_1.PLUGIN_NAME, "options must be an object, a string, null, or undefined");
39 };
40 Config.getEncoding = function (options) {
41 var encoding = options.encoding;
42 if (common_1.isNil(encoding) || encoding === "")
43 return null;
44 if (!common_1.isString(encoding))
45 throw new gulp_util_1.PluginError(common_1.PLUGIN_NAME, "encoding must be a string, null, or undefined");
46 if (!Buffer.isEncoding(encoding))
47 throw new gulp_util_1.PluginError(common_1.PLUGIN_NAME, "encoding is not supported: " + encoding);
48 return encoding;
49 };
50 Config.getThisArg = function (options) {
51 return options.thisArg;
52 };
53 return Config;
54}());
55exports.Config = Config;
56//# sourceMappingURL=Config.js.map
\No newline at end of file