BVB Source Codes

reactide Show generate-identifier-regex.js Source code

Return Download reactide: download generate-identifier-regex.js Source code - Download reactide Source code - Type:.js
  1. 'use strict';
  2.  
  3. // Which Unicode version should be used?
  4. var version = '9.0.0';
  5.  
  6. var start = require('unicode-' + version + '/Binary_Property/ID_Start/code-points.js')
  7.     .filter(function(ch) { return ch > 0x7f; });
  8. var last = -1;
  9. var cont = [0x200c, 0x200d].concat(require('unicode-' + version + '/Binary_Property/ID_Continue/code-points.js')
  10.     .filter(function(ch) { return ch > 0x7f && search(start, ch, last + 1) == -1; }));
  11.  
  12. function search(arr, ch, starting) {
  13.   for (var i = starting; arr[i] <= ch && i < arr.length; last = i++)
  14.     if (arr[i] === ch)
  15.       return i;
  16.   return -1;
  17. }
  18.  
  19. function pad(str, width) {
  20.   while (str.length < width) str = "0" + str;
  21.   return str;
  22. }
  23.  
  24. function esc(code) {
  25.   var hex = code.toString(16);
  26.   if (hex.length <= 2) return "\\x" + pad(hex, 2);
  27.   else return "\\u" + pad(hex, 4);
  28. }
  29.  
  30. function generate(chars) {
  31.   var astral = [], re = "";
  32.   for (var i = 0, at = 0x10000; i < chars.length; i++) {
  33.     var from = chars[i], to = from;
  34.     while (i < chars.length - 1 && chars[i + 1] == to + 1) {
  35.       i++;
  36.       to++;
  37.     }
  38.     if (to <= 0xffff) {
  39.       if (from == to) re += esc(from);
  40.       else if (from + 1 == to) re += esc(from) + esc(to);
  41.       else re += esc(from) + "-" + esc(to);
  42.     } else {
  43.       astral.push(from - at, to - from);
  44.       at = to;
  45.     }
  46.   }
  47.   return {nonASCII: re, astral: astral};
  48. }
  49.  
  50. var startData = generate(start), contData = generate(cont);
  51.  
  52. console.log("let nonASCIIidentifierStartChars = \"" + startData.nonASCII + "\"");
  53. console.log("let nonASCIIidentifierChars = \"" + contData.nonASCII + "\"");
  54. console.log("const astralIdentifierStartCodes = " + JSON.stringify(startData.astral));
  55. console.log("const astralIdentifierCodes = " + JSON.stringify(contData.astral));
  56.  
downloadgenerate-identifier-regex.js Source code - Download reactide Source code
Related Source Codes/Software:
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
postal - 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top