"use strict";

Object.defineProperty(exports, "__esModule", {
    value: true
});

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function(obj) {
        return typeof obj;
    } : function(obj) {
        if (obj && typeof Symbol === "function" && obj.constructor === Symbol) {
            return "symbol";
        } else {
            return typeof obj;
        }
    };

var ucs2decode = exports.ucs2decode = function ucs2decode(string) {
        var output = [];
        var counter = 0;
        while (counter < string.length) {
            var value = string.charCodeAt(counter++);
            if (value >= 55296 && value <= 56319 && counter < string.length) {
                var extra = string.charCodeAt(counter++);
                if ((extra & 64512) === 56320) {
                    output.push(((value & 1023) << 10) + (extra & 1023) + 65536);
                } else {
                    output.push(value);
                    counter--;
                }
            } else {
                output.push(value);
            }
        }
        return output;
    };

var fixChineseSpace = exports.fixChineseSpace = function fixChineseSpace(str) {
        return str.replace(/([^\u4e00-\u9fa5\W])([\u4e00-\u9fa5])/g, "$1 $2");
    };

var escapeRegExp = exports.escapeRegExp = function escapeRegExp(str) {
        if (str === null || str === undefined) {
            str = "";
        }
        return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
    };

var mergeOptions = exports.mergeOptions = function mergeOptions(defaultOptions, options) {
        var newOptions = {};
        if (!options || (typeof options === "undefined" ? "undefined" : _typeof(options)) !== "object") {
            options = {};
        }
        for (var key in defaultOptions) {
            newOptions[key] = options[key] === undefined ? defaultOptions[key] : options[key];
            if (newOptions[key] instanceof Array) {
                newOptions[key] = newOptions[key].slice(0);
            }
        }
        return newOptions;
    };

var parseCmdEqualOption = exports.parseCmdEqualOption = function parseCmdEqualOption(option) {
        var replaceToken = "__REPLACE_TOKEN__";
        var tmpToken = replaceToken;
        var result = void 0;
        while (option.indexOf(tmpToken) > -1) {
            tmpToken += tmpToken;
        }
        if (option.match(/[^\\]\\\\=/)) {
            option = option.replace(/([^\\])\\\\=/g, "$1\\=");
        } else {
            if (option.match(/[^\\]\\=/)) {
                option = option.replace(/([^\\])\\=/g, "$1" + tmpToken);
            }
        }
        result = option.split("=").map(function(value) {
            return value.replace(new RegExp(tmpToken, "g"), "=");
        });
        if (result.length !== 2) {
            result = false;
        }
        return result;
    };