Greasy Fork is available in English.

stringify-entities-umd

UMD of stringify-entities

ეს სკრიპტი არ უნდა იყოს პირდაპირ დაინსტალირებული. ეს ბიბლიოთეკაა, სხვა სკრიპტებისთვის უნდა ჩართეთ მეტა-დირექტივაში // @require https://update.greatest.deepsurf.us/scripts/500264/1408969/stringify-entities-umd.js.

  1. // ==UserScript==
  2. // @name stringify-entities-umd
  3. // @namespace flomk.userscripts
  4. // @version 1.0
  5. // @description UMD of stringify-entities
  6. // @author flomk
  7. // ==/UserScript==
  8. (function (global, factory) {
  9. typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
  10. typeof define === 'function' && define.amd ? define(['exports'], factory) :
  11. (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.StringifyEntities = {}));
  12. })(this, (function (exports) { 'use strict';
  13. var defaultSubsetRegex = /["&'<>`]/g;
  14. var surrogatePairsRegex = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
  15. var controlCharactersRegex = (
  16. /[\x01-\t\v\f\x0E-\x1F\x7F\x81\x8D\x8F\x90\x9D\xA0-\uFFFF]/g
  17. );
  18. var regexEscapeRegex = /[|\\{}()[\]^$+*?.]/g;
  19. var subsetToRegexCache = new WeakMap();
  20. function core(value, options) {
  21. value = value.replace(
  22. options.subset ? charactersToExpressionCached(options.subset) : defaultSubsetRegex,
  23. basic
  24. );
  25. if (options.subset || options.escapeOnly) {
  26. return value;
  27. }
  28. return value.replace(surrogatePairsRegex, surrogate).replace(controlCharactersRegex, basic);
  29. function surrogate(pair, index, all) {
  30. return options.format(
  31. (pair.charCodeAt(0) - 55296) * 1024 + pair.charCodeAt(1) - 56320 + 65536,
  32. all.charCodeAt(index + 2),
  33. options
  34. );
  35. }
  36. function basic(character, index, all) {
  37. return options.format(
  38. character.charCodeAt(0),
  39. all.charCodeAt(index + 1),
  40. options
  41. );
  42. }
  43. }
  44. function charactersToExpressionCached(subset) {
  45. let cached = subsetToRegexCache.get(subset);
  46. if (!cached) {
  47. cached = charactersToExpression(subset);
  48. subsetToRegexCache.set(subset, cached);
  49. }
  50. return cached;
  51. }
  52. function charactersToExpression(subset) {
  53. const groups = [];
  54. let index = -1;
  55. while (++index < subset.length) {
  56. groups.push(subset[index].replace(regexEscapeRegex, "\\$&"));
  57. }
  58. return new RegExp("(?:" + groups.join("|") + ")", "g");
  59. }
  60.  
  61. var hexadecimalRegex = /[\dA-Fa-f]/;
  62. function toHexadecimal(code, next, omit) {
  63. const value = "&#x" + code.toString(16).toUpperCase();
  64. return omit && next && !hexadecimalRegex.test(String.fromCharCode(next)) ? value : value + ";";
  65. }
  66.  
  67. var decimalRegex = /\d/;
  68. function toDecimal(code, next, omit) {
  69. const value = "&#" + String(code);
  70. return omit && next && !decimalRegex.test(String.fromCharCode(next)) ? value : value + ";";
  71. }
  72.  
  73. var characterEntitiesLegacy = [
  74. "AElig",
  75. "AMP",
  76. "Aacute",
  77. "Acirc",
  78. "Agrave",
  79. "Aring",
  80. "Atilde",
  81. "Auml",
  82. "COPY",
  83. "Ccedil",
  84. "ETH",
  85. "Eacute",
  86. "Ecirc",
  87. "Egrave",
  88. "Euml",
  89. "GT",
  90. "Iacute",
  91. "Icirc",
  92. "Igrave",
  93. "Iuml",
  94. "LT",
  95. "Ntilde",
  96. "Oacute",
  97. "Ocirc",
  98. "Ograve",
  99. "Oslash",
  100. "Otilde",
  101. "Ouml",
  102. "QUOT",
  103. "REG",
  104. "THORN",
  105. "Uacute",
  106. "Ucirc",
  107. "Ugrave",
  108. "Uuml",
  109. "Yacute",
  110. "aacute",
  111. "acirc",
  112. "acute",
  113. "aelig",
  114. "agrave",
  115. "amp",
  116. "aring",
  117. "atilde",
  118. "auml",
  119. "brvbar",
  120. "ccedil",
  121. "cedil",
  122. "cent",
  123. "copy",
  124. "curren",
  125. "deg",
  126. "divide",
  127. "eacute",
  128. "ecirc",
  129. "egrave",
  130. "eth",
  131. "euml",
  132. "frac12",
  133. "frac14",
  134. "frac34",
  135. "gt",
  136. "iacute",
  137. "icirc",
  138. "iexcl",
  139. "igrave",
  140. "iquest",
  141. "iuml",
  142. "laquo",
  143. "lt",
  144. "macr",
  145. "micro",
  146. "middot",
  147. "nbsp",
  148. "not",
  149. "ntilde",
  150. "oacute",
  151. "ocirc",
  152. "ograve",
  153. "ordf",
  154. "ordm",
  155. "oslash",
  156. "otilde",
  157. "ouml",
  158. "para",
  159. "plusmn",
  160. "pound",
  161. "quot",
  162. "raquo",
  163. "reg",
  164. "sect",
  165. "shy",
  166. "sup1",
  167. "sup2",
  168. "sup3",
  169. "szlig",
  170. "thorn",
  171. "times",
  172. "uacute",
  173. "ucirc",
  174. "ugrave",
  175. "uml",
  176. "uuml",
  177. "yacute",
  178. "yen",
  179. "yuml"
  180. ];
  181.  
  182. var characterEntitiesHtml4 = {
  183. nbsp: "\xA0",
  184. iexcl: "\xA1",
  185. cent: "\xA2",
  186. pound: "\xA3",
  187. curren: "\xA4",
  188. yen: "\xA5",
  189. brvbar: "\xA6",
  190. sect: "\xA7",
  191. uml: "\xA8",
  192. copy: "\xA9",
  193. ordf: "\xAA",
  194. laquo: "\xAB",
  195. not: "\xAC",
  196. shy: "\xAD",
  197. reg: "\xAE",
  198. macr: "\xAF",
  199. deg: "\xB0",
  200. plusmn: "\xB1",
  201. sup2: "\xB2",
  202. sup3: "\xB3",
  203. acute: "\xB4",
  204. micro: "\xB5",
  205. para: "\xB6",
  206. middot: "\xB7",
  207. cedil: "\xB8",
  208. sup1: "\xB9",
  209. ordm: "\xBA",
  210. raquo: "\xBB",
  211. frac14: "\xBC",
  212. frac12: "\xBD",
  213. frac34: "\xBE",
  214. iquest: "\xBF",
  215. Agrave: "\xC0",
  216. Aacute: "\xC1",
  217. Acirc: "\xC2",
  218. Atilde: "\xC3",
  219. Auml: "\xC4",
  220. Aring: "\xC5",
  221. AElig: "\xC6",
  222. Ccedil: "\xC7",
  223. Egrave: "\xC8",
  224. Eacute: "\xC9",
  225. Ecirc: "\xCA",
  226. Euml: "\xCB",
  227. Igrave: "\xCC",
  228. Iacute: "\xCD",
  229. Icirc: "\xCE",
  230. Iuml: "\xCF",
  231. ETH: "\xD0",
  232. Ntilde: "\xD1",
  233. Ograve: "\xD2",
  234. Oacute: "\xD3",
  235. Ocirc: "\xD4",
  236. Otilde: "\xD5",
  237. Ouml: "\xD6",
  238. times: "\xD7",
  239. Oslash: "\xD8",
  240. Ugrave: "\xD9",
  241. Uacute: "\xDA",
  242. Ucirc: "\xDB",
  243. Uuml: "\xDC",
  244. Yacute: "\xDD",
  245. THORN: "\xDE",
  246. szlig: "\xDF",
  247. agrave: "\xE0",
  248. aacute: "\xE1",
  249. acirc: "\xE2",
  250. atilde: "\xE3",
  251. auml: "\xE4",
  252. aring: "\xE5",
  253. aelig: "\xE6",
  254. ccedil: "\xE7",
  255. egrave: "\xE8",
  256. eacute: "\xE9",
  257. ecirc: "\xEA",
  258. euml: "\xEB",
  259. igrave: "\xEC",
  260. iacute: "\xED",
  261. icirc: "\xEE",
  262. iuml: "\xEF",
  263. eth: "\xF0",
  264. ntilde: "\xF1",
  265. ograve: "\xF2",
  266. oacute: "\xF3",
  267. ocirc: "\xF4",
  268. otilde: "\xF5",
  269. ouml: "\xF6",
  270. divide: "\xF7",
  271. oslash: "\xF8",
  272. ugrave: "\xF9",
  273. uacute: "\xFA",
  274. ucirc: "\xFB",
  275. uuml: "\xFC",
  276. yacute: "\xFD",
  277. thorn: "\xFE",
  278. yuml: "\xFF",
  279. fnof: "\u0192",
  280. Alpha: "\u0391",
  281. Beta: "\u0392",
  282. Gamma: "\u0393",
  283. Delta: "\u0394",
  284. Epsilon: "\u0395",
  285. Zeta: "\u0396",
  286. Eta: "\u0397",
  287. Theta: "\u0398",
  288. Iota: "\u0399",
  289. Kappa: "\u039A",
  290. Lambda: "\u039B",
  291. Mu: "\u039C",
  292. Nu: "\u039D",
  293. Xi: "\u039E",
  294. Omicron: "\u039F",
  295. Pi: "\u03A0",
  296. Rho: "\u03A1",
  297. Sigma: "\u03A3",
  298. Tau: "\u03A4",
  299. Upsilon: "\u03A5",
  300. Phi: "\u03A6",
  301. Chi: "\u03A7",
  302. Psi: "\u03A8",
  303. Omega: "\u03A9",
  304. alpha: "\u03B1",
  305. beta: "\u03B2",
  306. gamma: "\u03B3",
  307. delta: "\u03B4",
  308. epsilon: "\u03B5",
  309. zeta: "\u03B6",
  310. eta: "\u03B7",
  311. theta: "\u03B8",
  312. iota: "\u03B9",
  313. kappa: "\u03BA",
  314. lambda: "\u03BB",
  315. mu: "\u03BC",
  316. nu: "\u03BD",
  317. xi: "\u03BE",
  318. omicron: "\u03BF",
  319. pi: "\u03C0",
  320. rho: "\u03C1",
  321. sigmaf: "\u03C2",
  322. sigma: "\u03C3",
  323. tau: "\u03C4",
  324. upsilon: "\u03C5",
  325. phi: "\u03C6",
  326. chi: "\u03C7",
  327. psi: "\u03C8",
  328. omega: "\u03C9",
  329. thetasym: "\u03D1",
  330. upsih: "\u03D2",
  331. piv: "\u03D6",
  332. bull: "\u2022",
  333. hellip: "\u2026",
  334. prime: "\u2032",
  335. Prime: "\u2033",
  336. oline: "\u203E",
  337. frasl: "\u2044",
  338. weierp: "\u2118",
  339. image: "\u2111",
  340. real: "\u211C",
  341. trade: "\u2122",
  342. alefsym: "\u2135",
  343. larr: "\u2190",
  344. uarr: "\u2191",
  345. rarr: "\u2192",
  346. darr: "\u2193",
  347. harr: "\u2194",
  348. crarr: "\u21B5",
  349. lArr: "\u21D0",
  350. uArr: "\u21D1",
  351. rArr: "\u21D2",
  352. dArr: "\u21D3",
  353. hArr: "\u21D4",
  354. forall: "\u2200",
  355. part: "\u2202",
  356. exist: "\u2203",
  357. empty: "\u2205",
  358. nabla: "\u2207",
  359. isin: "\u2208",
  360. notin: "\u2209",
  361. ni: "\u220B",
  362. prod: "\u220F",
  363. sum: "\u2211",
  364. minus: "\u2212",
  365. lowast: "\u2217",
  366. radic: "\u221A",
  367. prop: "\u221D",
  368. infin: "\u221E",
  369. ang: "\u2220",
  370. and: "\u2227",
  371. or: "\u2228",
  372. cap: "\u2229",
  373. cup: "\u222A",
  374. int: "\u222B",
  375. there4: "\u2234",
  376. sim: "\u223C",
  377. cong: "\u2245",
  378. asymp: "\u2248",
  379. ne: "\u2260",
  380. equiv: "\u2261",
  381. le: "\u2264",
  382. ge: "\u2265",
  383. sub: "\u2282",
  384. sup: "\u2283",
  385. nsub: "\u2284",
  386. sube: "\u2286",
  387. supe: "\u2287",
  388. oplus: "\u2295",
  389. otimes: "\u2297",
  390. perp: "\u22A5",
  391. sdot: "\u22C5",
  392. lceil: "\u2308",
  393. rceil: "\u2309",
  394. lfloor: "\u230A",
  395. rfloor: "\u230B",
  396. lang: "\u2329",
  397. rang: "\u232A",
  398. loz: "\u25CA",
  399. spades: "\u2660",
  400. clubs: "\u2663",
  401. hearts: "\u2665",
  402. diams: "\u2666",
  403. quot: '"',
  404. amp: "&",
  405. lt: "<",
  406. gt: ">",
  407. OElig: "\u0152",
  408. oelig: "\u0153",
  409. Scaron: "\u0160",
  410. scaron: "\u0161",
  411. Yuml: "\u0178",
  412. circ: "\u02C6",
  413. tilde: "\u02DC",
  414. ensp: "\u2002",
  415. emsp: "\u2003",
  416. thinsp: "\u2009",
  417. zwnj: "\u200C",
  418. zwj: "\u200D",
  419. lrm: "\u200E",
  420. rlm: "\u200F",
  421. ndash: "\u2013",
  422. mdash: "\u2014",
  423. lsquo: "\u2018",
  424. rsquo: "\u2019",
  425. sbquo: "\u201A",
  426. ldquo: "\u201C",
  427. rdquo: "\u201D",
  428. bdquo: "\u201E",
  429. dagger: "\u2020",
  430. Dagger: "\u2021",
  431. permil: "\u2030",
  432. lsaquo: "\u2039",
  433. rsaquo: "\u203A",
  434. euro: "\u20AC"
  435. };
  436.  
  437. var dangerous = [
  438. "cent",
  439. "copy",
  440. "divide",
  441. "gt",
  442. "lt",
  443. "not",
  444. "para",
  445. "times"
  446. ];
  447.  
  448. var own = {}.hasOwnProperty;
  449. var characters = {};
  450. var key;
  451. for (key in characterEntitiesHtml4) {
  452. if (own.call(characterEntitiesHtml4, key)) {
  453. characters[characterEntitiesHtml4[key]] = key;
  454. }
  455. }
  456. var notAlphanumericRegex = /[^\dA-Za-z]/;
  457. function toNamed(code, next, omit, attribute) {
  458. const character = String.fromCharCode(code);
  459. if (own.call(characters, character)) {
  460. const name = characters[character];
  461. const value = "&" + name;
  462. if (omit && characterEntitiesLegacy.includes(name) && !dangerous.includes(name) && (!attribute || next && next !== 61 && notAlphanumericRegex.test(String.fromCharCode(next)))) {
  463. return value;
  464. }
  465. return value + ";";
  466. }
  467. return "";
  468. }
  469.  
  470. function formatSmart(code, next, options) {
  471. let numeric = toHexadecimal(code, next, options.omitOptionalSemicolons);
  472. let named;
  473. if (options.useNamedReferences || options.useShortestReferences) {
  474. named = toNamed(
  475. code,
  476. next,
  477. options.omitOptionalSemicolons,
  478. options.attribute
  479. );
  480. }
  481. if ((options.useShortestReferences || !named) && options.useShortestReferences) {
  482. const decimal = toDecimal(code, next, options.omitOptionalSemicolons);
  483. if (decimal.length < numeric.length) {
  484. numeric = decimal;
  485. }
  486. }
  487. return named && (!options.useShortestReferences || named.length < numeric.length) ? named : numeric;
  488. }
  489.  
  490. function formatBasic(code) {
  491. return "&#x" + code.toString(16).toUpperCase() + ";";
  492. }
  493.  
  494. function stringifyEntities(value, options) {
  495. return core(value, Object.assign({ format: formatSmart }, options));
  496. }
  497. function stringifyEntitiesLight(value, options) {
  498. return core(value, Object.assign({ format: formatBasic }, options));
  499. }
  500.  
  501. exports.stringifyEntities = stringifyEntities;
  502. exports.stringifyEntitiesLight = stringifyEntitiesLight;
  503.  
  504. }));