typograf 6.12.1 → 6.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md CHANGED
@@ -1,7 +1,7 @@
1
1
  ## Лицензия
2
2
  The MIT License (MIT)
3
3
 
4
- © 2014–2021 Денис Селезнёв, <hcodes@yandex.ru>
4
+ © 2014–2022 Денис Селезнёв, <hcodes@yandex.ru>
5
5
 
6
6
  Данная лицензия разрешает лицам, получившим копию данного программного обеспечения и сопутствующей документации (в дальнейшем именуемыми «Программное Обеспечение»), безвозмездно использовать Программное Обеспечение без ограничений, включая неограниченное право на использование, копирование, изменение, добавление, публикацию, распространение, сублицензирование и/или продажу копий Программного Обеспечения, также как и лицам, которым предоставляется данное Программное Обеспечение, при соблюдении следующих условий:
7
7
 
package/README.md CHANGED
@@ -5,8 +5,8 @@
5
5
  [![NPM version](https://img.shields.io/npm/v/typograf.svg?style=flat)](https://www.npmjs.com/package/typograf)
6
6
  [![NPM downloads](https://img.shields.io/npm/dm/typograf.svg?style=flat)](https://www.npmjs.com/package/typograf)
7
7
  [![Coverage Status](https://img.shields.io/coveralls/typograf/typograf.svg?style=flat)](https://coveralls.io/r/typograf/typograf)
8
- [![Dependency Status](https://img.shields.io/david/typograf/typograf.svg?style=flat)](https://david-dm.org/typograf/typograf)
9
8
  [![bundlephobia](https://badgen.net/bundlephobia/minzip/typograf)](https://bundlephobia.com/result?p=typograf)
9
+ [![install size](https://packagephobia.com/badge?p=typograf)](https://packagephobia.com/result?p=typograf)
10
10
 
11
11
  Помогает автоматически расставить неразрывные пробелы, исправить мелкие опечатки, привести кавычки к правильному виду, заменить дефисы на тире в нужных местах и многое другое.
12
12
 
@@ -18,7 +18,7 @@
18
18
  + кроссплатформенность;
19
19
  + кроссбраузерность;
20
20
  + поддержка Node.js;
21
- + поддержка HTML;
21
+ + поддержка HTML и XML;
22
22
  + [типографирование на лету](https://github.com/typograf/jquery-typograf);
23
23
  + TDD.
24
24
 
@@ -1,4 +1,4 @@
1
- /*! typograf | © 2021 Denis Seleznev | MIT License | https://github.com/typograf/typograf */
1
+ /*! typograf | © 2022 Denis Seleznev | MIT License | https://github.com/typograf/typograf */
2
2
  (function (global, factory) {
3
3
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
4
4
  typeof define === 'function' && define.amd ? define(factory) :
@@ -8,17 +8,11 @@
8
8
  function _typeof(obj) {
9
9
  "@babel/helpers - typeof";
10
10
 
11
- if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
12
- _typeof = function (obj) {
13
- return typeof obj;
14
- };
15
- } else {
16
- _typeof = function (obj) {
17
- return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
18
- };
19
- }
20
-
21
- return _typeof(obj);
11
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
12
+ return typeof obj;
13
+ } : function (obj) {
14
+ return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
15
+ }, _typeof(obj);
22
16
  }
23
17
 
24
18
  function _classCallCheck(instance, Constructor) {
@@ -40,6 +34,9 @@
40
34
  function _createClass(Constructor, protoProps, staticProps) {
41
35
  if (protoProps) _defineProperties(Constructor.prototype, protoProps);
42
36
  if (staticProps) _defineProperties(Constructor, staticProps);
37
+ Object.defineProperty(Constructor, "prototype", {
38
+ writable: false
39
+ });
43
40
  return Constructor;
44
41
  }
45
42
 
@@ -52,7 +49,7 @@
52
49
  }
53
50
 
54
51
  function _iterableToArrayLimit(arr, i) {
55
- var _i = arr && (typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]);
52
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
56
53
 
57
54
  if (_i == null) return;
58
55
  var _arr = [];
@@ -380,6 +377,10 @@
380
377
 
381
378
  var regExpUrl = new RegExp('(https?|file|ftp)://([a-zA-Z0-9/+-=%&:_.~?]+[a-zA-Z0-9#+]*)', 'g');
382
379
  var regExpNumber = '\\d+([.,]\\d+)?';
380
+ var regExpDigit = /\d/;
381
+ function isDigit(symbol) {
382
+ return symbol.search(regExpDigit) > -1;
383
+ }
383
384
 
384
385
  var privateLabel = "\uF000";
385
386
  var privateSeparateLabel = "\uF001";
@@ -1211,7 +1212,7 @@
1211
1212
 
1212
1213
  return Typograf;
1213
1214
  }();
1214
- Typograf.version = '6.12.1';
1215
+ Typograf.version = '6.14.1';
1215
1216
  Typograf.addLocale = addLocale;
1216
1217
  Typograf.getLocales = getLocales;
1217
1218
  Typograf.hasLocale = hasLocale;
@@ -1823,12 +1824,12 @@
1823
1824
  }
1824
1825
  };
1825
1826
 
1827
+ var MAX_LEVEL_WITH_ERRORS = 2;
1826
1828
  var Quote = {
1827
1829
  bufferQuotes: {
1828
1830
  left: "\uF005\uF006\uF007",
1829
1831
  right: "\uF008\uF009\uF0A0"
1830
1832
  },
1831
- maxLevel: 3,
1832
1833
  beforeLeft: " \n\t\xA0[(",
1833
1834
  afterRight: " \n\t\xA0!?.:;#*,\u2026)\\]",
1834
1835
  process: function process(params) {
@@ -1935,8 +1936,8 @@
1935
1936
  var lquote = params.settings.left[0];
1936
1937
  var lquote2 = params.settings.left[1] || lquote;
1937
1938
  var rquote = params.settings.right[0];
1938
- var reL = new RegExp('(^|[' + this.beforeLeft + '])([' + quotes + ']{1,' + this.maxLevel + '})(?=[^\\s' + privateLabel + '])', 'gim');
1939
- var reR = new RegExp('([^\\s' + privateLabel + '])([' + quotes + ']{1,' + this.maxLevel + '})(?=[' + this.afterRight + ']|$)', 'gim');
1939
+ var reL = new RegExp('(^|[' + this.beforeLeft + '])([' + quotes + ']+)(?=[^\\s' + privateLabel + '])', 'gim');
1940
+ var reR = new RegExp('([^\\s' + privateLabel + '])([' + quotes + ']+)(?=[' + this.afterRight + ']|$)', 'gim');
1940
1941
  text = text.replace(reL, function ($0, $1, $2) {
1941
1942
  return $1 + repeat(lquote, $2.length);
1942
1943
  }).replace(reR, function ($0, $1, $2) {
@@ -2037,18 +2038,10 @@
2037
2038
  return null;
2038
2039
  },
2039
2040
  setInner: function setInner(text, settings) {
2040
- var leftQuotes = [];
2041
- var rightQuotes = [];
2042
-
2043
- for (var k = 0; k < settings.left.length; k++) {
2044
- leftQuotes.push(settings.left[k]);
2045
- rightQuotes.push(settings.right[k]);
2046
- }
2047
-
2048
2041
  var lquote = settings.left[0];
2049
2042
  var rquote = settings.right[0];
2050
- var minLevel = -1;
2051
- var maxLevel = leftQuotes.length - 1;
2043
+ var minLevel = 0;
2044
+ var maxLevel = this.getMaxLevel(text, lquote, rquote, settings.left.length);
2052
2045
  var level = minLevel;
2053
2046
  var result = '';
2054
2047
 
@@ -2056,25 +2049,20 @@
2056
2049
  var letter = text[i];
2057
2050
 
2058
2051
  if (letter === lquote) {
2052
+ result += settings.left[level > maxLevel - 1 ? maxLevel - 1 : level];
2059
2053
  level++;
2060
2054
 
2061
2055
  if (level > maxLevel) {
2062
2056
  level = maxLevel;
2063
2057
  }
2064
-
2065
- result += leftQuotes[level];
2066
2058
  } else if (letter === rquote) {
2067
- if (level <= minLevel) {
2068
- level = 0;
2069
- result += rightQuotes[level];
2070
- } else {
2071
- result += rightQuotes[level];
2072
- level--;
2073
-
2074
- if (level < minLevel) {
2075
- level = minLevel;
2076
- }
2059
+ level--;
2060
+
2061
+ if (level < minLevel) {
2062
+ level = minLevel;
2077
2063
  }
2064
+
2065
+ result += settings.right[level];
2078
2066
  } else {
2079
2067
  if (letter === '"') {
2080
2068
  level = minLevel;
@@ -2084,8 +2072,11 @@
2084
2072
  }
2085
2073
  }
2086
2074
 
2087
- var count = this.count(result, settings);
2088
- return count[lquote] !== count[rquote] ? text : result;
2075
+ return result;
2076
+ },
2077
+ getMaxLevel: function getMaxLevel(text, leftQuote, rightQuote, length) {
2078
+ var count = this.count(text);
2079
+ return count[leftQuote] === count[rightQuote] ? length : Math.min(length, MAX_LEVEL_WITH_ERRORS);
2089
2080
  }
2090
2081
  };
2091
2082
  var quote = {
@@ -2137,15 +2128,6 @@
2137
2128
 
2138
2129
  Typograf.addRules([apostrophe, delDoublePunctuation, hellip, quote, quoteLink]);
2139
2130
 
2140
- var afterPunctuation = {
2141
- name: 'common/space/afterPunctuation',
2142
- handler: function handler(text) {
2143
- var reExcl = new RegExp('(!|;|\\?)([^).…!;?\\s[\\])' + privateLabel + getData('common/quote') + '])', 'g');
2144
- var reComma = new RegExp('(\\D)(,|:)([^)",:.?\\s\\/\\\\' + privateLabel + '])', 'g');
2145
- return text.replace(reExcl, '$1 $2').replace(reComma, '$1$2 $3');
2146
- }
2147
- };
2148
-
2149
2131
  var beforeBracket = {
2150
2132
  name: 'common/space/beforeBracket',
2151
2133
  handler: function handler(text, settings, context) {
@@ -2277,7 +2259,49 @@
2277
2259
  }
2278
2260
  };
2279
2261
 
2280
- Typograf.addRules([afterPunctuation, beforeBracket, bracket, delBeforeDot, delBeforePercent, delBeforePunctuation, delBetweenExclamationMarks, delLeadingBlanks, delRepeatN, delRepeatSpace, delTrailingBlanks, insertFinalNewline, replaceTab, squareBracket, trimLeft, trimRight]);
2262
+ var reColon = new RegExp('(\\D):([^)",:.?\\s\\/\\\\' + privateLabel + '])', 'g');
2263
+ var afterColon = {
2264
+ name: 'common/space/afterColon',
2265
+ handler: function handler(text) {
2266
+ return text.replace(reColon, '$1: $2');
2267
+ }
2268
+ };
2269
+
2270
+ var reComma = new RegExp('(.),([^)",:.?\\s\\/\\\\' + privateLabel + '])', 'g');
2271
+ var afterComma = {
2272
+ name: 'common/space/afterComma',
2273
+ handler: function handler(text) {
2274
+ return text.replace(reComma, function ($0, $1, $2) {
2275
+ return isDigit($1) && isDigit($2) ? $0 : $1 + ', ' + $2;
2276
+ });
2277
+ }
2278
+ };
2279
+
2280
+ var reQuestionMark = new RegExp('\\?([^).…!;?\\s[\\])' + privateLabel + getData('common/quote') + '])', 'g');
2281
+ var afterQuestionMark = {
2282
+ name: 'common/space/afterQuestionMark',
2283
+ handler: function handler(text) {
2284
+ return text.replace(reQuestionMark, '? $1');
2285
+ }
2286
+ };
2287
+
2288
+ var reExclamationMark = new RegExp('!([^).…!;?\\s[\\])' + privateLabel + getData('common/quote') + '])', 'g');
2289
+ var afterExclamationMark = {
2290
+ name: 'common/space/afterExclamationMark',
2291
+ handler: function handler(text) {
2292
+ return text.replace(reExclamationMark, '! $1');
2293
+ }
2294
+ };
2295
+
2296
+ var reSemicolon = new RegExp(';([^).…!;?\\s[\\])' + privateLabel + getData('common/quote') + '])', 'g');
2297
+ var afterSemicolon = {
2298
+ name: 'common/space/afterSemicolon',
2299
+ handler: function handler(text) {
2300
+ return text.replace(reSemicolon, '; $1');
2301
+ }
2302
+ };
2303
+
2304
+ Typograf.addRules([afterColon, afterComma, afterQuestionMark, afterExclamationMark, afterSemicolon, beforeBracket, bracket, delBeforeDot, delBeforePercent, delBeforePunctuation, delBetweenExclamationMarks, delLeadingBlanks, delRepeatN, delRepeatSpace, delTrailingBlanks, insertFinalNewline, replaceTab, squareBracket, trimLeft, trimRight]);
2281
2305
 
2282
2306
  var arrow = {
2283
2307
  name: 'common/symbols/arrow',
@@ -2649,7 +2673,7 @@
2649
2673
  var spaces = "\xA0\u202F "; // nbsp, thinsp
2650
2674
 
2651
2675
  var quote = getData('ru/quote');
2652
- var re = new RegExp('(^|[' + spaces + quote.left + privateLabel + '"])([А-ЯЁ])\\.[' + spaces + ']?([А-ЯЁ])\\.[' + spaces + ']?([А-ЯЁ][а-яё]+)(?=[\\s.,;:?!"' + quote.right + privateLabel + ']|$)', 'gm');
2676
+ var re = new RegExp('(^|[' + spaces + quote.left + privateLabel + '"])([А-ЯЁ])\\.[' + spaces + ']?([А-ЯЁ])\\.[' + spaces + ']?([А-ЯЁ][а-яё]+)', 'gm');
2653
2677
  return text.replace(re, "$1$2.\xA0$3.\xA0$4");
2654
2678
  }
2655
2679
  };
@@ -3009,11 +3033,9 @@
3009
3033
  var ano = {
3010
3034
  name: 'ru/punctuation/ano',
3011
3035
  handler: function handler(text) {
3012
- var re = new RegExp("([^\xAB\u201E[(!?,:;\\-\u2012\u2013\u2014\\s])(\\s+)(\u0430|\u043D\u043E)(?= |\xA0|\\n)", 'g');
3036
+ var re = new RegExp('([^«„[(!?,:;\\-‒–—\\s' + privateLabel + "])(\\s+)(\u0430|\u043D\u043E)(?= |\xA0|\\n)", 'g');
3013
3037
  return text.replace(re, '$1,$2$3');
3014
- },
3015
- // Запятая может идти после ссылки.
3016
- queue: 'hide-safe-tags-html'
3038
+ }
3017
3039
  };
3018
3040
 
3019
3041
  var exclamation = {
@@ -3217,9 +3239,25 @@
3217
3239
  "en-US": "Removal quotes outside a link",
3218
3240
  "ru": "Вынос кавычек за пределы ссылки"
3219
3241
  },
3220
- "common/space/afterPunctuation": {
3221
- "en-US": "space after punctuation",
3222
- "ru": "Пробел после знаков пунктуации"
3242
+ "common/space/afterColon": {
3243
+ "en-US": "space after colon",
3244
+ "ru": "Пробел после двоеточия"
3245
+ },
3246
+ "common/space/afterComma": {
3247
+ "en-US": "space after comma",
3248
+ "ru": "Пробел после запятой"
3249
+ },
3250
+ "common/space/afterExclamationMark": {
3251
+ "en-US": "space after exclamation mark",
3252
+ "ru": "Пробел после знака восклицания"
3253
+ },
3254
+ "common/space/afterQuestionMark": {
3255
+ "en-US": "space after question mark",
3256
+ "ru": "Пробел после знака вопроса"
3257
+ },
3258
+ "common/space/afterSemicolon": {
3259
+ "en-US": "space after semicolon",
3260
+ "ru": "Пробел после точки с запятой"
3223
3261
  },
3224
3262
  "common/space/beforeBracket": {
3225
3263
  "en-US": "Space before opening bracket",