Ver código fonte

Restored OptionsNormalizer

sanex3339 9 anos atrás
pai
commit
db95e8c473
3 arquivos alterados com 151 adições e 122 exclusões
  1. 69 45
      dist/index.js
  2. 3 77
      src/Options.ts
  3. 79 0
      src/OptionsNormalizer.ts

+ 69 - 45
dist/index.js

@@ -871,13 +871,14 @@ module.exports =
 
 	function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
 
+	var OptionsNormalizer_1 = __webpack_require__(38);
 	var DefaultPreset_1 = __webpack_require__(37);
 
 	var Options = function () {
 	    function Options(options) {
 	        _classCallCheck(this, Options);
 
-	        this.options = Object.freeze(Options.normalizeOptionsPreset(Object.assign({}, DefaultPreset_1.DEFAULT_PRESET, options)));
+	        this.options = Object.freeze(OptionsNormalizer_1.OptionsNormalizer.normalizeOptionsPreset(Object.assign({}, DefaultPreset_1.DEFAULT_PRESET, options)));
 	    }
 
 	    _createClass(Options, [{
@@ -885,55 +886,11 @@ module.exports =
 	        value: function get(optionName) {
 	            return this.options[optionName];
 	        }
-	    }], [{
-	        key: "normalizeOptionsPreset",
-	        value: function normalizeOptionsPreset(options) {
-	            var normalizedOptions = Object.assign({}, options);
-	            normalizedOptions = Options.unicodeArrayRule(normalizedOptions);
-	            normalizedOptions = Options.unicodeArrayThresholdRule(normalizedOptions);
-	            normalizedOptions = Options.selfDefendingRule(normalizedOptions);
-	            return normalizedOptions;
-	        }
-	    }, {
-	        key: "selfDefendingRule",
-	        value: function selfDefendingRule(options) {
-	            if (options['selfDefending']) {
-	                Object.assign(options, Options.SELF_DEFENDING_OPTIONS);
-	            }
-	            return options;
-	        }
-	    }, {
-	        key: "unicodeArrayRule",
-	        value: function unicodeArrayRule(options) {
-	            if (!options['unicodeArray']) {
-	                Object.assign(options, Options.DISABLED_UNICODE_ARRAY_OPTIONS);
-	            }
-	            return options;
-	        }
-	    }, {
-	        key: "unicodeArrayThresholdRule",
-	        value: function unicodeArrayThresholdRule(options) {
-	            var minValue = 0,
-	                maxValue = 1;
-	            options['unicodeArrayThreshold'] = Math.min(Math.max(options['unicodeArrayThreshold'], minValue), maxValue);
-	            return options;
-	        }
 	    }]);
 
 	    return Options;
 	}();
 
-	Options.DISABLED_UNICODE_ARRAY_OPTIONS = {
-	    encodeUnicodeLiterals: false,
-	    rotateUnicodeArray: false,
-	    unicodeArray: false,
-	    unicodeArrayThreshold: 0,
-	    wrapUnicodeArrayCalls: false
-	};
-	Options.SELF_DEFENDING_OPTIONS = {
-	    compact: true,
-	    selfDefending: true
-	};
 	exports.Options = Options;
 
 /***/ },
@@ -2391,5 +2348,72 @@ module.exports =
 	    wrapUnicodeArrayCalls: true
 	});
 
+/***/ },
+/* 38 */
+/***/ function(module, exports) {
+
+	"use strict";
+	"use strict";
+
+	var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
+
+	function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
+
+	var OptionsNormalizer = function () {
+	    function OptionsNormalizer() {
+	        _classCallCheck(this, OptionsNormalizer);
+	    }
+
+	    _createClass(OptionsNormalizer, null, [{
+	        key: 'normalizeOptionsPreset',
+	        value: function normalizeOptionsPreset(options) {
+	            var normalizedOptions = Object.assign({}, options);
+	            normalizedOptions = OptionsNormalizer.unicodeArrayRule(normalizedOptions);
+	            normalizedOptions = OptionsNormalizer.unicodeArrayThresholdRule(normalizedOptions);
+	            normalizedOptions = OptionsNormalizer.selfDefendingRule(normalizedOptions);
+	            return normalizedOptions;
+	        }
+	    }, {
+	        key: 'selfDefendingRule',
+	        value: function selfDefendingRule(options) {
+	            if (options['selfDefending']) {
+	                Object.assign(options, OptionsNormalizer.SELF_DEFENDING_OPTIONS);
+	            }
+	            return options;
+	        }
+	    }, {
+	        key: 'unicodeArrayRule',
+	        value: function unicodeArrayRule(options) {
+	            if (!options['unicodeArray']) {
+	                Object.assign(options, OptionsNormalizer.DISABLED_UNICODE_ARRAY_OPTIONS);
+	            }
+	            return options;
+	        }
+	    }, {
+	        key: 'unicodeArrayThresholdRule',
+	        value: function unicodeArrayThresholdRule(options) {
+	            var minValue = 0,
+	                maxValue = 1;
+	            options['unicodeArrayThreshold'] = Math.min(Math.max(options['unicodeArrayThreshold'], minValue), maxValue);
+	            return options;
+	        }
+	    }]);
+
+	    return OptionsNormalizer;
+	}();
+
+	OptionsNormalizer.DISABLED_UNICODE_ARRAY_OPTIONS = {
+	    encodeUnicodeLiterals: false,
+	    rotateUnicodeArray: false,
+	    unicodeArray: false,
+	    unicodeArrayThreshold: 0,
+	    wrapUnicodeArrayCalls: false
+	};
+	OptionsNormalizer.SELF_DEFENDING_OPTIONS = {
+	    compact: true,
+	    selfDefending: true
+	};
+	exports.OptionsNormalizer = OptionsNormalizer;
+
 /***/ }
 /******/ ]);

+ 3 - 77
src/Options.ts

@@ -1,39 +1,22 @@
 import { IOptions } from "./interfaces/IOptions";
 import { IOptionsPreset } from "./interfaces/IOptionsPreset";
 
+import { OptionsNormalizer } from "./OptionsNormalizer";
+
 import { DEFAULT_PRESET } from "./preset-options/DefaultPreset";
 
 export class Options implements IOptions {
-    /**
-     * @type {IOptionsPreset}
-     */
-    private static DISABLED_UNICODE_ARRAY_OPTIONS: IOptionsPreset = {
-        encodeUnicodeLiterals: false,
-        rotateUnicodeArray: false,
-        unicodeArray: false,
-        unicodeArrayThreshold: 0,
-        wrapUnicodeArrayCalls: false
-    };
-
     /**
      * @type {IOptionsPreset}
      */
     private options: IOptionsPreset;
 
-    /**
-     * @type {IOptionsPreset}
-     */
-    public static SELF_DEFENDING_OPTIONS: IOptionsPreset = {
-        compact: true,
-        selfDefending: true
-    };
-
     /**
      * @param options
      */
     constructor (options: IOptionsPreset) {
         this.options = Object.freeze(
-            Options.normalizeOptionsPreset(
+            OptionsNormalizer.normalizeOptionsPreset(
                 Object.assign({}, DEFAULT_PRESET, options)
             )
         );
@@ -46,61 +29,4 @@ export class Options implements IOptions {
     public get <T> (optionName: string): T {
         return <T> this.options[optionName];
     }
-
-    /**
-     * @param options
-     * @returns {IOptionsPreset}
-     */
-    public static normalizeOptionsPreset (options: IOptionsPreset): IOptionsPreset {
-        let normalizedOptions: IOptionsPreset = Object.assign({}, options);
-
-        normalizedOptions = Options.unicodeArrayRule(normalizedOptions);
-        normalizedOptions = Options.unicodeArrayThresholdRule(normalizedOptions);
-        normalizedOptions = Options.selfDefendingRule(normalizedOptions);
-
-        return normalizedOptions;
-    }
-
-    /**
-     * @param options
-     * @returns {IOptionsPreset}
-     */
-    private static selfDefendingRule (options: IOptionsPreset): IOptionsPreset {
-        if (options['selfDefending']) {
-            Object.assign(options, Options.SELF_DEFENDING_OPTIONS);
-        }
-
-        return options;
-    }
-
-    /**
-     * @param options
-     * @returns {IOptionsPreset}
-     */
-    private static unicodeArrayRule (options: IOptionsPreset): IOptionsPreset {
-        if (!options['unicodeArray']) {
-            Object.assign(options, Options.DISABLED_UNICODE_ARRAY_OPTIONS);
-        }
-
-        return options;
-    }
-
-    /**
-     * @param options
-     * @returns {IOptionsPreset}
-     */
-    private static unicodeArrayThresholdRule (options: IOptionsPreset): IOptionsPreset {
-        const minValue: number = 0,
-            maxValue: number = 1;
-
-        options['unicodeArrayThreshold'] = Math.min(
-            Math.max(
-                options['unicodeArrayThreshold'],
-                minValue
-            ),
-            maxValue
-        );
-
-        return options;
-    }
 }

+ 79 - 0
src/OptionsNormalizer.ts

@@ -0,0 +1,79 @@
+import { IOptionsPreset } from "./interfaces/IOptionsPreset";
+
+export class OptionsNormalizer {
+    /**
+     * @type {IOptionsPreset}
+     */
+    private static DISABLED_UNICODE_ARRAY_OPTIONS: IOptionsPreset = {
+        encodeUnicodeLiterals: false,
+        rotateUnicodeArray: false,
+        unicodeArray: false,
+        unicodeArrayThreshold: 0,
+        wrapUnicodeArrayCalls: false
+    };
+
+    /**
+     * @type {IOptionsPreset}
+     */
+    public static SELF_DEFENDING_OPTIONS: IOptionsPreset = {
+        compact: true,
+        selfDefending: true
+    };
+
+    /**
+     * @param options
+     * @returns {IOptionsPreset}
+     */
+    public static normalizeOptionsPreset (options: IOptionsPreset): IOptionsPreset {
+        let normalizedOptions: IOptionsPreset = Object.assign({}, options);
+
+        normalizedOptions = OptionsNormalizer.unicodeArrayRule(normalizedOptions);
+        normalizedOptions = OptionsNormalizer.unicodeArrayThresholdRule(normalizedOptions);
+        normalizedOptions = OptionsNormalizer.selfDefendingRule(normalizedOptions);
+
+        return normalizedOptions;
+    }
+
+    /**
+     * @param options
+     * @returns {IOptionsPreset}
+     */
+    private static selfDefendingRule (options: IOptionsPreset): IOptionsPreset {
+        if (options['selfDefending']) {
+            Object.assign(options, OptionsNormalizer.SELF_DEFENDING_OPTIONS);
+        }
+
+        return options;
+    }
+
+    /**
+     * @param options
+     * @returns {IOptionsPreset}
+     */
+    private static unicodeArrayRule (options: IOptionsPreset): IOptionsPreset {
+        if (!options['unicodeArray']) {
+            Object.assign(options, OptionsNormalizer.DISABLED_UNICODE_ARRAY_OPTIONS);
+        }
+
+        return options;
+    }
+
+    /**
+     * @param options
+     * @returns {IOptionsPreset}
+     */
+    private static unicodeArrayThresholdRule (options: IOptionsPreset): IOptionsPreset {
+        const minValue: number = 0,
+            maxValue: number = 1;
+
+        options['unicodeArrayThreshold'] = Math.min(
+            Math.max(
+                options['unicodeArrayThreshold'],
+                minValue
+            ),
+            maxValue
+        );
+
+        return options;
+    }
+}