Comparing version 4.0.5 to 4.0.6
/*! | ||
* pangu.js | ||
* -------- | ||
* @version: 4.0.5 | ||
* @version: 4.0.6 | ||
* @homepage: https://github.com/vinta/pangu.js | ||
@@ -111,3 +111,3 @@ * @license: MIT | ||
if (true) { | ||
!(__WEBPACK_AMD_DEFINE_ARRAY__ = [__webpack_require__(1)], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), | ||
!(__WEBPACK_AMD_DEFINE_ARRAY__ = [], __WEBPACK_AMD_DEFINE_FACTORY__ = (factory), | ||
__WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? | ||
@@ -117,3 +117,3 @@ (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), | ||
} else { var mod; } | ||
})(this, function (_core) { | ||
})(this, function () { | ||
"use strict"; | ||
@@ -139,2 +139,5 @@ | ||
var _require = __webpack_require__(1), | ||
Pangu = _require.Pangu; | ||
function once(func) { | ||
@@ -192,5 +195,2 @@ var _this = this, | ||
_this3 = _possibleConstructorReturn(this, _getPrototypeOf(BrowserPangu).call(this)); | ||
_this3.punctuation = "\u3001\u3002\uFF01\uFF1B\uFF0C\uFF1A\uFF1B\uFF1F"; | ||
_this3.punctuationRegex = new RegExp("[".concat(_this3.punctuation, "]")); | ||
_this3.stopCharRegex = new RegExp("[ \n\t\\(\\)\\[\\]\\\"\\'".concat(_this3.punctuation, "]")); | ||
_this3.blockTags = /^(div|p|h1|h2|h3|h4|h5|h6)$/i; | ||
@@ -482,3 +482,3 @@ _this3.ignoredTags = /^(script|code|pre|textarea)$/i; | ||
setTimeout(function () { | ||
self.spacingPage(); | ||
onceSpacingPage(); | ||
}, pageDelay); | ||
@@ -488,2 +488,10 @@ } else { | ||
var video = videos[i]; | ||
if (video.readyState === 4) { | ||
setTimeout(function () { | ||
onceSpacingPage(); | ||
}, 3000); | ||
break; | ||
} | ||
video.addEventListener('loadeddata', function () { | ||
@@ -546,3 +554,3 @@ setTimeout(function () { | ||
return BrowserPangu; | ||
}(_core.Pangu); | ||
}(Pangu); | ||
@@ -581,4 +589,4 @@ var pangu = new BrowserPangu(); | ||
var anyCjk = new RegExp("[".concat(cjk, "]")); | ||
var convertToFullwidthCjkSpaceSymbolsSpaceCjk = new RegExp("([".concat(cjk, "])[ ]*([~\\!;\\:,\\?]+|\\.)[ ]*([").concat(cjk, "])"), 'g'); | ||
var convertToFullwidthCjkSymbolsAn = new RegExp("([".concat(cjk, "])([~\\!;\\?]+)([A-Za-z0-9])"), 'g'); | ||
var convertToFullwidthCjkSpaceSymbolsSpaceCjk = new RegExp("([".concat(cjk, "])[ ]*([\\:]+|\\.)[ ]*([").concat(cjk, "])"), 'g'); | ||
var convertToFullwidthCjkSymbols = new RegExp("([".concat(cjk, "])[ ]*([~\\!;,\\?]+)[ ]*"), 'g'); | ||
var dotsCjk = new RegExp("([\\.]{2,}|\u2026)([".concat(cjk, "])"), 'g'); | ||
@@ -611,2 +619,4 @@ var fixCjkColonAns = new RegExp("([".concat(cjk, "])\\:([A-Z0-9\\(\\)])"), 'g'); | ||
_classCallCheck(this, Pangu); | ||
this.VERSION = '4.0.6'; | ||
} | ||
@@ -637,5 +647,5 @@ | ||
}); | ||
newText = newText.replace(convertToFullwidthCjkSymbolsAn, function (match, cjk, symbols, an) { | ||
newText = newText.replace(convertToFullwidthCjkSymbols, function (match, cjk, symbols) { | ||
var fullwidthSymbols = self.convertToFullwidth(symbols); | ||
return "".concat(cjk).concat(fullwidthSymbols).concat(an); | ||
return "".concat(cjk).concat(fullwidthSymbols); | ||
}); | ||
@@ -642,0 +652,0 @@ newText = newText.replace(dotsCjk, '$1 $2'); |
/*! | ||
* pangu.js | ||
* -------- | ||
* @version: 4.0.5 | ||
* @version: 4.0.6 | ||
* @homepage: https://github.com/vinta/pangu.js | ||
@@ -9,2 +9,2 @@ * @license: MIT | ||
*/ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("pangu",[],t):"object"==typeof exports?exports.pangu=t():e.pangu=t()}(window,function(){return function(e){var t={};function n(a){if(t[a])return t[a].exports;var o=t[a]={i:a,l:!1,exports:{}};return e[a].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,a){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:a})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var a=Object.create(null);if(n.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(a,o,function(t){return e[t]}.bind(null,o));return a},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){var a,o,i;o=[n(1)],void 0===(i="function"==typeof(a=function(t){"use strict";function n(e){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function a(e,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}function o(e,t){return!t||"object"!==n(t)&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function i(e){return(i=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function r(e,t){return(r=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var c=function(e){function t(){var e;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),(e=o(this,i(t).call(this))).punctuation="、。!;,:;?",e.punctuationRegex=new RegExp("[".concat(e.punctuation,"]")),e.stopCharRegex=new RegExp("[ \n\t\\(\\)\\[\\]\\\"\\'".concat(e.punctuation,"]")),e.blockTags=/^(div|p|h1|h2|h3|h4|h5|h6)$/i,e.ignoredTags=/^(script|code|pre|textarea)$/i,e.presentationalTags=/^(b|code|del|em|i|s|strong)$/i,e.spaceLikeTags=/^(br|hr|i|img|pangu)$/i,e.spaceSensitiveTags=/^(a|del|pre|s|strike|u)$/i,e.isAutoSpacingPageExecuted=!1,e}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&r(e,t)}(t,e),n=t,(c=[{key:"isContentEditable",value:function(e){return e.isContentEditable||e.getAttribute&&"true"===e.getAttribute("g_editable")}},{key:"isSpecificTag",value:function(e,t){return e&&e.nodeName&&e.nodeName.search(t)>=0}},{key:"isInsideSpecificTag",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],a=e;if(n&&this.isSpecificTag(a,t))return!0;for(;a.parentNode;)if(a=a.parentNode,this.isSpecificTag(a,t))return!0;return!1}},{key:"canIgnoreNode",value:function(e){var t=e;if(t&&(this.isSpecificTag(t,this.ignoredTags)||this.isContentEditable(t)))return!0;for(;t.parentNode;)if((t=t.parentNode)&&(this.isSpecificTag(t,this.ignoredTags)||this.isContentEditable(t)))return!0;return!1}},{key:"isFirstTextChild",value:function(e,t){for(var n=e.childNodes,a=0;a<n.length;a++){var o=n[a];if(o.nodeType!==Node.COMMENT_NODE&&o.textContent)return o===t}return!1}},{key:"isLastTextChild",value:function(e,t){for(var n=e.childNodes,a=n.length-1;a>-1;a--){var o=n[a];if(o.nodeType!==Node.COMMENT_NODE&&o.textContent)return o===t}return!1}},{key:"spacingNodeByXPath",value:function(e,t){for(var n,a,o=document.evaluate(e,t,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),i=o.snapshotLength-1;i>-1;--i){if(n=o.snapshotItem(i),this.isSpecificTag(n.parentNode,this.presentationalTags)&&!this.isInsideSpecificTag(n.parentNode,this.ignoredTags)){var r=n.parentNode;if(r.previousSibling){var c=r.previousSibling;if(c.nodeType===Node.TEXT_NODE){var s=c.data.substr(-1)+n.data.toString().charAt(0),u=this.spacing(s);s!==u&&(c.data="".concat(c.data," "))}}if(r.nextSibling){var p=r.nextSibling;if(p.nodeType===Node.TEXT_NODE){var l=n.data.substr(-1)+p.data.toString().charAt(0),g=this.spacing(l);l!==g&&(p.data=" ".concat(p.data))}}}if(this.canIgnoreNode(n))a=n;else{var f=this.spacing(n.data);if(n.data!==f&&(n.data=f),a){if(n.nextSibling&&n.nextSibling.nodeName.search(this.spaceLikeTags)>=0){a=n;continue}var d=n.data.toString().substr(-1)+a.data.toString().substr(0,1),h=this.spacing(d);if(h!==d){for(var y=a;y.parentNode&&-1===y.nodeName.search(this.spaceSensitiveTags)&&this.isFirstTextChild(y.parentNode,y);)y=y.parentNode;for(var v=n;v.parentNode&&-1===v.nodeName.search(this.spaceSensitiveTags)&&this.isLastTextChild(v.parentNode,v);)v=v.parentNode;if(v.nextSibling&&v.nextSibling.nodeName.search(this.spaceLikeTags)>=0){a=n;continue}if(-1===v.nodeName.search(this.blockTags))if(-1===y.nodeName.search(this.spaceSensitiveTags))-1===y.nodeName.search(this.ignoredTags)&&-1===y.nodeName.search(this.blockTags)&&(a.previousSibling?-1===a.previousSibling.nodeName.search(this.spaceLikeTags)&&(a.data=" ".concat(a.data)):this.canIgnoreNode(a)||(a.data=" ".concat(a.data)));else if(-1===v.nodeName.search(this.spaceSensitiveTags))n.data="".concat(n.data," ");else{var b=document.createElement("pangu");b.innerHTML=" ",y.previousSibling?-1===y.previousSibling.nodeName.search(this.spaceLikeTags)&&y.parentNode.insertBefore(b,y):y.parentNode.insertBefore(b,y),b.previousElementSibling||b.parentNode&&b.parentNode.removeChild(b)}}}a=n}}}},{key:"spacingNode",value:function(e){var t=".//*/text()[normalize-space(.)]";e.children&&0===e.children.length&&(t=".//text()[normalize-space(.)]"),this.spacingNodeByXPath(t,e)}},{key:"spacingElementById",value:function(e){var t='id("'.concat(e,'")//text()');this.spacingNodeByXPath(t,document)}},{key:"spacingElementByClassName",value:function(e){var t='//*[contains(concat(" ", normalize-space(@class), " "), "'.concat(e,'")]//text()');this.spacingNodeByXPath(t,document)}},{key:"spacingElementByTagName",value:function(e){var t="//".concat(e,"//text()");this.spacingNodeByXPath(t,document)}},{key:"spacingPageTitle",value:function(){this.spacingNodeByXPath("/html/head/title/text()",document)}},{key:"spacingPageBody",value:function(){var e="/html/body//*/text()[normalize-space(.)]";["script","style","textarea"].forEach(function(t){e="".concat(e,'[translate(name(..),"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")!="').concat(t,'"]')}),this.spacingNodeByXPath(e,document)}},{key:"spacingPage",value:function(){this.spacingPageTitle(),this.spacingPageBody()}},{key:"autoSpacingPage",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1e3,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:500,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:2e3;if(document.body instanceof Node&&!this.isAutoSpacingPageExecuted){this.isAutoSpacingPageExecuted=!0;var a=this,o=function(e){var t=this,n=arguments,a=!1;return function(){if(!a){var o=t;a=!0,e.apply(o,n)}}}(function(){a.spacingPage()}),i=document.getElementsByTagName("video");if(0===i.length)setTimeout(function(){a.spacingPage()},e);else for(var r=0;r<i.length;r++){var c=i[r];c.addEventListener("loadeddata",function(){setTimeout(function(){o()},4e3)})}var s=[],u=function(e,t,n){var a=this,o=arguments,i=null,r=null;return function(){var c=a,s=o,u=+new Date;clearTimeout(i),r||(r=u),u-r>=n?(e.apply(c,s),r=u):i=setTimeout(function(){e.apply(c,s)},t)}}(function(){for(;s.length;){var e=s.shift();e&&a.spacingNode(e)}},t,{maxWait:n}),p=new MutationObserver(function(e,t){e.forEach(function(e){switch(e.type){case"childList":e.addedNodes.forEach(function(e){e.nodeType===Node.ELEMENT_NODE?s.push(e):e.nodeType===Node.TEXT_NODE&&s.push(e.parentNode)});break;case"characterData":var t=e.target;t.nodeType===Node.TEXT_NODE&&s.push(t.parentNode)}}),u()});p.observe(document.body,{characterData:!0,childList:!0,subtree:!0})}}}])&&a(n.prototype,c),s&&a(n,s),t;var n,c,s}(t.Pangu),s=new c;e.exports=s,e.exports.default=s,e.exports.Pangu=c})?a.apply(t,o):a)||(e.exports=i)},function(e,t,n){var a,o,i;o=[],void 0===(i="function"==typeof(a=function(){"use strict";function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function n(e,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}var a="⺀-⼀--ゟ゠-ヺー-ヿ-ㄯ㈀-㋿㐀-䶿一-鿿豈-",o=new RegExp("[".concat(a,"]")),i=new RegExp("([".concat(a,"])[ ]*([~\\!;\\:,\\?]+|\\.)[ ]*([").concat(a,"])"),"g"),r=new RegExp("([".concat(a,"])([~\\!;\\?]+)([A-Za-z0-9])"),"g"),c=new RegExp("([\\.]{2,}|…)([".concat(a,"])"),"g"),s=new RegExp("([".concat(a,"])\\:([A-Z0-9\\(\\)])"),"g"),u=new RegExp("([".concat(a,'])([`"״])'),"g"),p=new RegExp('([`"״])(['.concat(a,"])"),"g"),l=/([`"\u05f4]+)(\s*)(.+?)(\s*)([`"\u05f4]+)/g,g=new RegExp("([".concat(a,"])('[^s])"),"g"),f=new RegExp("(')([".concat(a,"])"),"g"),d=new RegExp("([".concat(a,"A-Za-z0-9])( )('s)"),"g"),h=new RegExp("([".concat(a,"])(#)([").concat(a,"]+)(#)([").concat(a,"])"),"g"),y=new RegExp("([".concat(a,"])(#([^ ]))"),"g"),v=new RegExp("(([^ ])#)([".concat(a,"])"),"g"),b=new RegExp("([".concat(a,"])([\\+\\-\\*\\/=&\\|<>])([A-Za-z0-9])"),"g"),m=new RegExp("([A-Za-z0-9])([\\+\\-\\*\\/=&\\|<>])([".concat(a,"])"),"g"),x=new RegExp("([\\/])( )([a-z\\-_\\.\\/]+)","g"),T=new RegExp("([\\/\\.])([A-Za-z\\-_\\.\\/]+)( )([\\/])","g"),N=new RegExp("([".concat(a,"])([\\(\\[\\{<>“])"),"g"),E=new RegExp("([\\)\\]\\}<>”])([".concat(a,"])"),"g"),$=/([\(\[\{<\u201c]+)(\s*)(.+?)(\s*)([\)\]\}>\u201d]+)/,S=/([A-Za-z0-9])([\(\[\{])/g,w=/([\)\]\}])([A-Za-z0-9])/g,P=new RegExp("([".concat(a,"])([A-Za-z0-9\\$%\\^&\\*\\-=\\+\\\\|/@¡-ÿ⅐-✀—➿])"),"g"),k=new RegExp("([A-Za-z0-9~\\$%\\^&\\*\\-=\\+\\\\|/!;:,\\.\\?¡-ÿ⅐-✀—➿])([".concat(a,"])"),"g"),O=/([ ]*)([\u00b7\u2022\u2027])([ ]*)/g,R=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e)}return a=e,(R=[{key:"convertToFullwidth",value:function(e){return e.replace(/~/g,"~").replace(/!/g,"!").replace(/;/g,";").replace(/:/g,":").replace(/,/g,",").replace(/\./g,"。").replace(/\?/g,"?")}},{key:"spacing",value:function(e){if("string"!=typeof e)return console.warn("spacing(text) only accepts string but got ".concat(t(e))),e;if(e.length<=1||!o.test(e))return e;var n=this,a=e;return a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=a.replace(i,function(e,t,a,o){var i=n.convertToFullwidth(a);return"".concat(t).concat(i).concat(o)})).replace(r,function(e,t,a,o){var i=n.convertToFullwidth(a);return"".concat(t).concat(i).concat(o)})).replace(c,"$1 $2")).replace(s,"$1:$2")).replace(u,"$1 $2")).replace(p,"$1 $2")).replace(l,"$1$3$5")).replace(g,"$1 $2")).replace(f,"$1 $2")).replace(d,"$1's")).replace(h,"$1 $2$3$4 $5")).replace(y,"$1 $2")).replace(v,"$1 $3")).replace(b,"$1 $2 $3")).replace(m,"$1 $2 $3")).replace(x,"$1$3")).replace(T,"$1$2$4")).replace(N,"$1 $2")).replace(E,"$1 $2")).replace($,"$1$3$5")).replace(S,"$1 $2")).replace(w,"$1 $2")).replace(P,"$1 $2")).replace(k,"$1 $2")).replace(O,"・")}},{key:"spacingText",value:function(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:function(){};try{t=this.spacing(e)}catch(e){return void n(e)}n(null,t)}},{key:"spacingTextSync",value:function(e){return this.spacing(e)}}])&&n(a.prototype,R),_&&n(a,_),e;var a,R,_}(),_=new R;e.exports=_,e.exports.default=_,e.exports.Pangu=R})?a.apply(t,o):a)||(e.exports=i)}])}); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define("pangu",[],t):"object"==typeof exports?exports.pangu=t():e.pangu=t()}(window,function(){return function(e){var t={};function n(a){if(t[a])return t[a].exports;var i=t[a]={i:a,l:!1,exports:{}};return e[a].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,a){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:a})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var a=Object.create(null);if(n.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var i in e)n.d(a,i,function(t){return e[t]}.bind(null,i));return a},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){var a,i,o;i=[],void 0===(o="function"==typeof(a=function(){"use strict";function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function a(e,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}function i(e,n){return!n||"object"!==t(n)&&"function"!=typeof n?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):n}function o(e){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function r(e,t){return(r=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var c=function(e){function t(){var e;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),(e=i(this,o(t).call(this))).blockTags=/^(div|p|h1|h2|h3|h4|h5|h6)$/i,e.ignoredTags=/^(script|code|pre|textarea)$/i,e.presentationalTags=/^(b|code|del|em|i|s|strong)$/i,e.spaceLikeTags=/^(br|hr|i|img|pangu)$/i,e.spaceSensitiveTags=/^(a|del|pre|s|strike|u)$/i,e.isAutoSpacingPageExecuted=!1,e}return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&r(e,t)}(t,e),n=t,(c=[{key:"isContentEditable",value:function(e){return e.isContentEditable||e.getAttribute&&"true"===e.getAttribute("g_editable")}},{key:"isSpecificTag",value:function(e,t){return e&&e.nodeName&&e.nodeName.search(t)>=0}},{key:"isInsideSpecificTag",value:function(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],a=e;if(n&&this.isSpecificTag(a,t))return!0;for(;a.parentNode;)if(a=a.parentNode,this.isSpecificTag(a,t))return!0;return!1}},{key:"canIgnoreNode",value:function(e){var t=e;if(t&&(this.isSpecificTag(t,this.ignoredTags)||this.isContentEditable(t)))return!0;for(;t.parentNode;)if((t=t.parentNode)&&(this.isSpecificTag(t,this.ignoredTags)||this.isContentEditable(t)))return!0;return!1}},{key:"isFirstTextChild",value:function(e,t){for(var n=e.childNodes,a=0;a<n.length;a++){var i=n[a];if(i.nodeType!==Node.COMMENT_NODE&&i.textContent)return i===t}return!1}},{key:"isLastTextChild",value:function(e,t){for(var n=e.childNodes,a=n.length-1;a>-1;a--){var i=n[a];if(i.nodeType!==Node.COMMENT_NODE&&i.textContent)return i===t}return!1}},{key:"spacingNodeByXPath",value:function(e,t){for(var n,a,i=document.evaluate(e,t,null,XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),o=i.snapshotLength-1;o>-1;--o){if(n=i.snapshotItem(o),this.isSpecificTag(n.parentNode,this.presentationalTags)&&!this.isInsideSpecificTag(n.parentNode,this.ignoredTags)){var r=n.parentNode;if(r.previousSibling){var c=r.previousSibling;if(c.nodeType===Node.TEXT_NODE){var s=c.data.substr(-1)+n.data.toString().charAt(0),u=this.spacing(s);s!==u&&(c.data="".concat(c.data," "))}}if(r.nextSibling){var p=r.nextSibling;if(p.nodeType===Node.TEXT_NODE){var l=n.data.substr(-1)+p.data.toString().charAt(0),f=this.spacing(l);l!==f&&(p.data=" ".concat(p.data))}}}if(this.canIgnoreNode(n))a=n;else{var g=this.spacing(n.data);if(n.data!==g&&(n.data=g),a){if(n.nextSibling&&n.nextSibling.nodeName.search(this.spaceLikeTags)>=0){a=n;continue}var d=n.data.toString().substr(-1)+a.data.toString().substr(0,1),h=this.spacing(d);if(h!==d){for(var y=a;y.parentNode&&-1===y.nodeName.search(this.spaceSensitiveTags)&&this.isFirstTextChild(y.parentNode,y);)y=y.parentNode;for(var v=n;v.parentNode&&-1===v.nodeName.search(this.spaceSensitiveTags)&&this.isLastTextChild(v.parentNode,v);)v=v.parentNode;if(v.nextSibling&&v.nextSibling.nodeName.search(this.spaceLikeTags)>=0){a=n;continue}if(-1===v.nodeName.search(this.blockTags))if(-1===y.nodeName.search(this.spaceSensitiveTags))-1===y.nodeName.search(this.ignoredTags)&&-1===y.nodeName.search(this.blockTags)&&(a.previousSibling?-1===a.previousSibling.nodeName.search(this.spaceLikeTags)&&(a.data=" ".concat(a.data)):this.canIgnoreNode(a)||(a.data=" ".concat(a.data)));else if(-1===v.nodeName.search(this.spaceSensitiveTags))n.data="".concat(n.data," ");else{var b=document.createElement("pangu");b.innerHTML=" ",y.previousSibling?-1===y.previousSibling.nodeName.search(this.spaceLikeTags)&&y.parentNode.insertBefore(b,y):y.parentNode.insertBefore(b,y),b.previousElementSibling||b.parentNode&&b.parentNode.removeChild(b)}}}a=n}}}},{key:"spacingNode",value:function(e){var t=".//*/text()[normalize-space(.)]";e.children&&0===e.children.length&&(t=".//text()[normalize-space(.)]"),this.spacingNodeByXPath(t,e)}},{key:"spacingElementById",value:function(e){var t='id("'.concat(e,'")//text()');this.spacingNodeByXPath(t,document)}},{key:"spacingElementByClassName",value:function(e){var t='//*[contains(concat(" ", normalize-space(@class), " "), "'.concat(e,'")]//text()');this.spacingNodeByXPath(t,document)}},{key:"spacingElementByTagName",value:function(e){var t="//".concat(e,"//text()");this.spacingNodeByXPath(t,document)}},{key:"spacingPageTitle",value:function(){this.spacingNodeByXPath("/html/head/title/text()",document)}},{key:"spacingPageBody",value:function(){var e="/html/body//*/text()[normalize-space(.)]";["script","style","textarea"].forEach(function(t){e="".concat(e,'[translate(name(..),"ABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwxyz")!="').concat(t,'"]')}),this.spacingNodeByXPath(e,document)}},{key:"spacingPage",value:function(){this.spacingPageTitle(),this.spacingPageBody()}},{key:"autoSpacingPage",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1e3,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:500,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:2e3;if(document.body instanceof Node&&!this.isAutoSpacingPageExecuted){this.isAutoSpacingPageExecuted=!0;var a=this,i=function(e){var t=this,n=arguments,a=!1;return function(){if(!a){var i=t;a=!0,e.apply(i,n)}}}(function(){a.spacingPage()}),o=document.getElementsByTagName("video");if(0===o.length)setTimeout(function(){i()},e);else for(var r=0;r<o.length;r++){var c=o[r];if(4===c.readyState){setTimeout(function(){i()},3e3);break}c.addEventListener("loadeddata",function(){setTimeout(function(){i()},4e3)})}var s=[],u=function(e,t,n){var a=this,i=arguments,o=null,r=null;return function(){var c=a,s=i,u=+new Date;clearTimeout(o),r||(r=u),u-r>=n?(e.apply(c,s),r=u):o=setTimeout(function(){e.apply(c,s)},t)}}(function(){for(;s.length;){var e=s.shift();e&&a.spacingNode(e)}},t,{maxWait:n}),p=new MutationObserver(function(e,t){e.forEach(function(e){switch(e.type){case"childList":e.addedNodes.forEach(function(e){e.nodeType===Node.ELEMENT_NODE?s.push(e):e.nodeType===Node.TEXT_NODE&&s.push(e.parentNode)});break;case"characterData":var t=e.target;t.nodeType===Node.TEXT_NODE&&s.push(t.parentNode)}}),u()});p.observe(document.body,{characterData:!0,childList:!0,subtree:!0})}}}])&&a(n.prototype,c),s&&a(n,s),t;var n,c,s}(n(1).Pangu),s=new c;e.exports=s,e.exports.default=s,e.exports.Pangu=c})?a.apply(t,i):a)||(e.exports=o)},function(e,t,n){var a,i,o;i=[],void 0===(o="function"==typeof(a=function(){"use strict";function t(e){return(t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function n(e,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}var a="⺀-⼀--ゟ゠-ヺー-ヿ-ㄯ㈀-㋿㐀-䶿一-鿿豈-",i=new RegExp("[".concat(a,"]")),o=new RegExp("([".concat(a,"])[ ]*([\\:]+|\\.)[ ]*([").concat(a,"])"),"g"),r=new RegExp("([".concat(a,"])[ ]*([~\\!;,\\?]+)[ ]*"),"g"),c=new RegExp("([\\.]{2,}|…)([".concat(a,"])"),"g"),s=new RegExp("([".concat(a,"])\\:([A-Z0-9\\(\\)])"),"g"),u=new RegExp("([".concat(a,'])([`"״])'),"g"),p=new RegExp('([`"״])(['.concat(a,"])"),"g"),l=/([`"\u05f4]+)(\s*)(.+?)(\s*)([`"\u05f4]+)/g,f=new RegExp("([".concat(a,"])('[^s])"),"g"),g=new RegExp("(')([".concat(a,"])"),"g"),d=new RegExp("([".concat(a,"A-Za-z0-9])( )('s)"),"g"),h=new RegExp("([".concat(a,"])(#)([").concat(a,"]+)(#)([").concat(a,"])"),"g"),y=new RegExp("([".concat(a,"])(#([^ ]))"),"g"),v=new RegExp("(([^ ])#)([".concat(a,"])"),"g"),b=new RegExp("([".concat(a,"])([\\+\\-\\*\\/=&\\|<>])([A-Za-z0-9])"),"g"),m=new RegExp("([A-Za-z0-9])([\\+\\-\\*\\/=&\\|<>])([".concat(a,"])"),"g"),E=new RegExp("([\\/])( )([a-z\\-_\\.\\/]+)","g"),$=new RegExp("([\\/\\.])([A-Za-z\\-_\\.\\/]+)( )([\\/])","g"),S=new RegExp("([".concat(a,"])([\\(\\[\\{<>“])"),"g"),T=new RegExp("([\\)\\]\\}<>”])([".concat(a,"])"),"g"),N=/([\(\[\{<\u201c]+)(\s*)(.+?)(\s*)([\)\]\}>\u201d]+)/,w=/([A-Za-z0-9])([\(\[\{])/g,k=/([\)\]\}])([A-Za-z0-9])/g,O=new RegExp("([".concat(a,"])([A-Za-z0-9\\$%\\^&\\*\\-=\\+\\\\|/@¡-ÿ⅐-✀—➿])"),"g"),P=new RegExp("([A-Za-z0-9~\\$%\\^&\\*\\-=\\+\\\\|/!;:,\\.\\?¡-ÿ⅐-✀—➿])([".concat(a,"])"),"g"),R=/([ ]*)([\u00b7\u2022\u2027])([ ]*)/g,_=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.VERSION="4.0.6"}return a=e,(_=[{key:"convertToFullwidth",value:function(e){return e.replace(/~/g,"~").replace(/!/g,"!").replace(/;/g,";").replace(/:/g,":").replace(/,/g,",").replace(/\./g,"。").replace(/\?/g,"?")}},{key:"spacing",value:function(e){if("string"!=typeof e)return console.warn("spacing(text) only accepts string but got ".concat(t(e))),e;if(e.length<=1||!i.test(e))return e;var n=this,a=e;return a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=(a=a.replace(o,function(e,t,a,i){var o=n.convertToFullwidth(a);return"".concat(t).concat(o).concat(i)})).replace(r,function(e,t,a){var i=n.convertToFullwidth(a);return"".concat(t).concat(i)})).replace(c,"$1 $2")).replace(s,"$1:$2")).replace(u,"$1 $2")).replace(p,"$1 $2")).replace(l,"$1$3$5")).replace(f,"$1 $2")).replace(g,"$1 $2")).replace(d,"$1's")).replace(h,"$1 $2$3$4 $5")).replace(y,"$1 $2")).replace(v,"$1 $3")).replace(b,"$1 $2 $3")).replace(m,"$1 $2 $3")).replace(E,"$1$3")).replace($,"$1$2$4")).replace(S,"$1 $2")).replace(T,"$1 $2")).replace(N,"$1$3$5")).replace(w,"$1 $2")).replace(k,"$1 $2")).replace(O,"$1 $2")).replace(P,"$1 $2")).replace(R,"・")}},{key:"spacingText",value:function(e){var t,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:function(){};try{t=this.spacing(e)}catch(e){return void n(e)}n(null,t)}},{key:"spacingTextSync",value:function(e){return this.spacing(e)}}])&&n(a.prototype,_),x&&n(a,x),e;var a,_,x}(),x=new _;e.exports=x,e.exports.default=x,e.exports.Pangu=_})?a.apply(t,i):a)||(e.exports=o)}])}); |
@@ -30,11 +30,5 @@ "use strict"; | ||
function NodePangu() { | ||
var _this; | ||
var filePrefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'readable.'; | ||
_classCallCheck(this, NodePangu); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(NodePangu).call(this)); | ||
_this.filePrefix = filePrefix; | ||
return _this; | ||
return _possibleConstructorReturn(this, _getPrototypeOf(NodePangu).apply(this, arguments)); | ||
} | ||
@@ -45,3 +39,3 @@ | ||
value: function spacingFile(path) { | ||
var _this2 = this; | ||
var _this = this; | ||
@@ -56,3 +50,3 @@ var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {}; | ||
var spacingData = _this2.spacing(data); | ||
var spacingData = _this.spacing(data); | ||
@@ -67,7 +61,3 @@ resolve(spacingData); | ||
value: function spacingFileSync(path) { | ||
try { | ||
return this.spacing(fs.readFileSync(path, 'utf8')); | ||
} catch (err) { | ||
throw err; | ||
} | ||
return this.spacing(fs.readFileSync(path, 'utf8')); | ||
} | ||
@@ -74,0 +64,0 @@ }]); |
@@ -15,4 +15,4 @@ "use strict"; | ||
var anyCjk = new RegExp("[".concat(cjk, "]")); | ||
var convertToFullwidthCjkSpaceSymbolsSpaceCjk = new RegExp("([".concat(cjk, "])[ ]*([~\\!;\\:,\\?]+|\\.)[ ]*([").concat(cjk, "])"), 'g'); | ||
var convertToFullwidthCjkSymbolsAn = new RegExp("([".concat(cjk, "])([~\\!;\\?]+)([A-Za-z0-9])"), 'g'); | ||
var convertToFullwidthCjkSpaceSymbolsSpaceCjk = new RegExp("([".concat(cjk, "])[ ]*([\\:]+|\\.)[ ]*([").concat(cjk, "])"), 'g'); | ||
var convertToFullwidthCjkSymbols = new RegExp("([".concat(cjk, "])[ ]*([~\\!;,\\?]+)[ ]*"), 'g'); | ||
var dotsCjk = new RegExp("([\\.]{2,}|\u2026)([".concat(cjk, "])"), 'g'); | ||
@@ -45,2 +45,4 @@ var fixCjkColonAns = new RegExp("([".concat(cjk, "])\\:([A-Z0-9\\(\\)])"), 'g'); | ||
_classCallCheck(this, Pangu); | ||
this.VERSION = '4.0.6'; | ||
} | ||
@@ -71,5 +73,5 @@ | ||
}); | ||
newText = newText.replace(convertToFullwidthCjkSymbolsAn, function (match, cjk, symbols, an) { | ||
newText = newText.replace(convertToFullwidthCjkSymbols, function (match, cjk, symbols) { | ||
var fullwidthSymbols = self.convertToFullwidth(symbols); | ||
return "".concat(cjk).concat(fullwidthSymbols).concat(an); | ||
return "".concat(cjk).concat(fullwidthSymbols); | ||
}); | ||
@@ -76,0 +78,0 @@ newText = newText.replace(dotsCjk, '$1 $2'); |
# History | ||
v4.0.6 / 2019-02-04 | ||
------------------- | ||
- 修正 `,` 的問題 | ||
- 新增 `pangu` 指令,詳見 [cli.js](https://github.com/vinta/pangu.js/blob/master/src/node/cli.js) | ||
v4.0.5 / 2019-01-30 | ||
@@ -4,0 +10,0 @@ ------------------- |
@@ -18,3 +18,3 @@ { | ||
], | ||
"version": "4.0.5", | ||
"version": "4.0.6", | ||
"author": { | ||
@@ -35,6 +35,10 @@ "name": "Vinta Chen", | ||
"main": "./dist/node/index.js", | ||
"bin": { | ||
"pangu": "./dist/node/cli.js" | ||
}, | ||
"browser": "./dist/browser/pangu.js", | ||
"scripts": { | ||
"pack:chrome": "npm run build:browser && cp -rf ./dist/browser/pangu.min.js ./browser_extensions/chrome/vendors/pangu/pangu.min.js && cd ./browser_extensions/chrome/ && zip -q -r -0 ../paranoid-auto-spacing.zip . && zip -j ../paranoid-auto-spacing.zip ~/Dropbox/Projects/paranoid-auto-spacing/key.pem", | ||
"pack": "npm run pack:chrome", | ||
"pack:firefox": "node ./browser_extensions/firefox/pack.js", | ||
"pack": "npm run pack:chrome && npm run pack:firefox", | ||
"clear:shared": "rm -rf ./dist/shared/", | ||
@@ -78,2 +82,3 @@ "clear:browser": "rm -rf ./dist/browser/", | ||
"puppeteer": "1.11.0", | ||
"terser": "3.13.1", | ||
"terser-webpack-plugin": "1.2.1", | ||
@@ -80,0 +85,0 @@ "underscore": "1.9.1", |
@@ -21,3 +21,4 @@ # 為什麼你們就是不能加個空格呢? | ||
- [Google Chrome](https://chrome.google.com/webstore/detail/paphcfdffjnbcgkokihcdjliihicmbpd) (**2019-01-29 updated**) | ||
- [Google Chrome](https://chrome.google.com/webstore/detail/paphcfdffjnbcgkokihcdjliihicmbpd) (**2019-02-04 UPDATED**) | ||
- [Mozilla Firefox](https://github.com/vinta/pangu.js/blob/master/browser_extensions/firefox/paranoid-auto-spacing.user.js) (**2019-02-04 UPDATED**) | ||
@@ -53,18 +54,20 @@ ### For Developers | ||
Files are located in `./node_modules/pangu/dist/browser/`. | ||
```html | ||
<head> | ||
// files are located in ./node_modules/pangu/dist/browser/ | ||
<script src="pangu.min.js"></script> | ||
</head> | ||
<script> | ||
var text = pangu.spacing("當你凝視著bug,bug也凝視著你"); | ||
const text = pangu.spacing("當你凝視著bug,bug也凝視著你"); | ||
// text = '當你凝視著 bug,bug 也凝視著你' | ||
// listen to any DOM change and automatically perform spacing via MutationObserver() | ||
pangu.autoSpacingPage(); | ||
pangu.spacingPage(); | ||
pangu.spacingElementById('main'); | ||
pangu.spacingElementByClassName('comment'); | ||
pangu.spacingElementByTagName('p'); | ||
document.addEventListener('DOMContentLoaded', () => { | ||
// listen to any DOM change and automatically perform spacing via MutationObserver() | ||
pangu.autoSpacingPage(); | ||
}); | ||
</script> | ||
@@ -76,7 +79,7 @@ ``` | ||
```html | ||
<script src="https://cdn.jsdelivr.net/npm/pangu@4.0.5/dist/browser/pangu.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/pangu@4.0.5/dist/browser/pangu.min.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/pangu@4.0.6/dist/browser/pangu.js"></script> | ||
<script src="https://cdn.jsdelivr.net/npm/pangu@4.0.6/dist/browser/pangu.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/pangu/4.0.5/pangu.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/pangu/4.0.5/pangu.min.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/pangu/4.0.6/pangu.js"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/pangu/4.0.6/pangu.min.js"></script> | ||
``` | ||
@@ -89,5 +92,3 @@ | ||
```js | ||
var pangu = require('pangu'); | ||
// or | ||
import * as pangu from 'pangu'; | ||
const pangu = require('pangu'); | ||
@@ -97,11 +98,13 @@ const text = pangu.spacing('與PM戰鬥的人,應當小心自己不要成為PM'); | ||
// callback | ||
pangu.spacingFile('/path/to/text.txt', function(err, data) { | ||
pangu.spacingFile('/path/to/text.txt', (err, data) => { | ||
console.log(data); | ||
}); | ||
// promise | ||
pangu.spacingFile('/path/to/text.txt').then(function(data) { | ||
console.log(data); | ||
}); | ||
pangu.spacingFile('/path/to/text.txt') | ||
.then((data) => { | ||
console.log(data); | ||
}) | ||
.catch((err) => { | ||
console.error(err); | ||
}); | ||
@@ -111,2 +114,26 @@ const data = pangu.spacingFileSync('/path/to/text.txt'); | ||
You **SHOULD NOT** use `pangu.js` directly to spacing Markdown documents, this library is specially designed for HTML webpages and plain texts without any markup language. See [issue #127](https://github.com/vinta/pangu.js/issues/127). | ||
### CLI | ||
```console | ||
$ pangu "不能信任那些Terminal或Editor用白底的人" | ||
不能信任那些 Terminal 或 Editor 用白底的人 | ||
$ pangu --help | ||
usage: pangu [-h] [-v] [-t] [-f] text_or_path | ||
pangu.js -- Paranoid text spacing for good readability, to automatically insert whitespace | ||
between CJK and half-width characters (alphabetical letters, numerical digits and symbols). | ||
positional arguments: | ||
text_or_path the text or file path to perform spacing | ||
optional arguments: | ||
-h, --help show this help message and exit | ||
-v, --version show program's version number and exit | ||
-t, --text specify the input value is a text | ||
-f, --file specify the input value is a file path | ||
``` | ||
## Testing | ||
@@ -113,0 +140,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { Pangu } from '../shared/core'; | ||
const { Pangu } = require('../shared/core'); | ||
@@ -21,3 +21,3 @@ function once(func) { | ||
const args = arguments; | ||
const currentTime = + new Date(); | ||
const currentTime = +new Date(); | ||
@@ -47,6 +47,2 @@ clearTimeout(timer); | ||
this.punctuation = '\u3001\u3002\uff01\uff1b\uff0c\uff1a\uff1b\uff1f'; | ||
this.punctuationRegex = new RegExp(`[${this.punctuation}]`); | ||
this.stopCharRegex = new RegExp(`[ \n\t\\(\\)\\[\\]\\"\\'${this.punctuation}]`); | ||
this.blockTags = /^(div|p|h1|h2|h3|h4|h5|h6)$/i; | ||
@@ -355,3 +351,3 @@ this.ignoredTags = /^(script|code|pre|textarea)$/i; | ||
setTimeout(() => { | ||
self.spacingPage(); | ||
onceSpacingPage(); | ||
}, pageDelay); | ||
@@ -361,2 +357,8 @@ } else { | ||
const video = videos[i]; | ||
if (video.readyState === 4) { | ||
setTimeout(() => { | ||
onceSpacingPage(); | ||
}, 3000); | ||
break; | ||
} | ||
video.addEventListener('loadeddata', () => { | ||
@@ -363,0 +365,0 @@ setTimeout(() => { |
@@ -6,9 +6,2 @@ const fs = require('fs'); | ||
class NodePangu extends Pangu { | ||
constructor(filePrefix = 'readable.') { | ||
super(); | ||
this.filePrefix = filePrefix; | ||
} | ||
spacingFile(path, callback = () => {}) { | ||
@@ -23,3 +16,2 @@ return new Promise((resolve, reject) => { | ||
const spacingData = this.spacing(data); | ||
resolve(spacingData); | ||
@@ -32,9 +24,4 @@ return callback(null, spacingData); | ||
spacingFileSync(path) { | ||
try { | ||
return this.spacing(fs.readFileSync(path, 'utf8')); | ||
} catch (err) { | ||
throw err; | ||
} | ||
return this.spacing(fs.readFileSync(path, 'utf8')); | ||
} | ||
} | ||
@@ -41,0 +28,0 @@ |
@@ -34,4 +34,4 @@ // CJK is short for Chinese, Japanese, and Korean. | ||
// the symbol part only includes ~ ! ; : , . ? but . only matches one character | ||
const convertToFullwidthCjkSpaceSymbolsSpaceCjk = new RegExp(`([${cjk}])[ ]*([~\\!;\\:,\\?]+|\\.)[ ]*([${cjk}])`, 'g'); | ||
const convertToFullwidthCjkSymbolsAn = new RegExp(`([${cjk}])([~\\!;\\?]+)([A-Za-z0-9])`, 'g'); | ||
const convertToFullwidthCjkSpaceSymbolsSpaceCjk = new RegExp(`([${cjk}])[ ]*([\\:]+|\\.)[ ]*([${cjk}])`, 'g'); | ||
const convertToFullwidthCjkSymbols = new RegExp(`([${cjk}])[ ]*([~\\!;,\\?]+)[ ]*`, 'g'); | ||
const dotsCjk = new RegExp(`([\\.]{2,}|\u2026)([${cjk}])`, 'g'); | ||
@@ -74,2 +74,6 @@ const fixCjkColonAns = new RegExp(`([${cjk}])\\:([A-Z0-9\\(\\)])`, 'g'); | ||
class Pangu { | ||
constructor() { | ||
this.VERSION = '4.0.6'; | ||
} | ||
convertToFullwidth(symbols) { | ||
@@ -118,5 +122,6 @@ return symbols | ||
}); | ||
newText = newText.replace(convertToFullwidthCjkSymbolsAn, (match, cjk, symbols, an) => { | ||
newText = newText.replace(convertToFullwidthCjkSymbols, (match, cjk, symbols) => { | ||
const fullwidthSymbols = self.convertToFullwidth(symbols); | ||
return `${cjk}${fullwidthSymbols}${an}`; | ||
return `${cjk}${fullwidthSymbols}`; | ||
}); | ||
@@ -123,0 +128,0 @@ |
90448
1428
152
2
26
14