numericshaping.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. define([],
  4. function(bidi) {
  5. "use strict";
  6. var regex = /([0-9])|([\u0660-\u0669])|([\u0608\u060B\u060D\u061B-\u064A\u066D-\u066F\u0671-\u06D5\u06E5-\u06E6\u06EE-\u06EF\u06FA-\u06FF\u0750-\u077F\u08A0-\u08E3\u200F\u202B\u202E\u2067\uFB50-\uFD3D\uFD40-\uFDCF\uFDF0-\uFDFC\uFDFE-\uFDFF\uFE70-\uFEFE]+)|([^0-9\u0660-\u0669\u0608\u060B\u060D\u061B-\u064A\u066D-\u066F\u0671-\u06D5\u06E5-\u06E6\u06EE-\u06EF\u06FA-\u06FF\u0750-\u077F\u08A0-\u08E3\u200F\u202B\u202E\u2067\uFB50-\uFD3D\uFD40-\uFDCF\uFDF0-\uFDFC\uFDFE-\uFDFF\uFE70-\uFEFE\u0600-\u0607\u0609-\u060A\u060C\u060E-\u061A\u064B-\u066C\u0670\u06D6-\u06E4\u06E7-\u06ED\u06F0-\u06F9\u08E4-\u08FF\uFD3E-\uFD3F\uFDD0-\uFDEF\uFDFD\uFEFF\u0000-\u0040\u005B-\u0060\u007B-\u007F\u0080-\u00A9\u00AB-\u00B4\u00B6-\u00B9\u00BB-\u00BF\u00D7\u00F7\u02B9-\u02BA\u02C2-\u02CF\u02D2-\u02DF\u02E5-\u02ED\u02EF-\u02FF\u2070\u2074-\u207E\u2080-\u208E\u2100-\u2101\u2103-\u2106\u2108-\u2109\u2114\u2116-\u2118\u211E-\u2123\u2125\u2127\u2129\u212E\u213A-\u213B\u2140-\u2144\u214A-\u214D\u2150-\u215F\u2189\uA720-\uA721\uA788\uFF01-\uFF20\uFF3B-\uFF40\uFF5B-\uFF65\uFFE0-\uFFE6\uFFE8-\uFFEE]+)/g;
  7. var shape = function(text, shaperType) {
  8. text = text.toString();
  9. if (!text) {
  10. return text;
  11. }
  12. switch (shaperType) {
  13. case "defaultNumeral":
  14. return _shapeEuropean(text);
  15. case "national":
  16. return _shapeArabic(text);
  17. default:
  18. return text;
  19. }
  20. };
  21. var _shapeEuropean = function(text) {
  22. return text.replace(/[\u0660-\u0669]/g, function(c) {
  23. return c.charCodeAt(0) - 1632;
  24. });
  25. };
  26. var _shapeArabic = function(text) {
  27. return text.replace(/[0-9]/g, function(c) {
  28. return String.fromCharCode(parseInt(c) + 1632);
  29. });
  30. };
  31. var numericshaping = {
  32. shapeNumerals : shape
  33. };
  34. return numericshaping;
  35. });