smalos / nubuilder_dev

Prefer adding u flag in regular expressions JS-0117
Anti-pattern
Minor
30 occurrences in this check
Use the 'u' flag with regular expressions
1305}
1306
1307function nuAddSlashes (s) {
1308  return String(s).replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0')1309}
1310
1311function nuOpenTab (i) {
Use the 'u' flag with regular expressions
  72}
  73
  74String.prototype.fixNbsp = function () {
  75  return this.replace(/\xA0/g, ' ')  76}
  77
  78String.prototype.capitalise = function () {
Use the 'u' flag with regular expressions
  48  const ALL_LOWER_INVERTED = /^[^A-Z\xbf-\xdf]+$/
  49  const ONE_UPPER = /[a-z\xdf-\xff]/
  50  const ONE_LOWER = /[A-Z\xbf-\xdf]/
  51  const ALPHA_INVERTED = /[^A-Za-z\xbf-\xdf]/gi  52  const ALL_DIGIT = /^\d+$/
  53  const REFERENCE_YEAR = new Date().getFullYear()
  54  const REGEXEN = {
Use the 'u' flag with regular expressions
  47  const ALL_LOWER = /^[a-z\xdf-\xff]+$/
  48  const ALL_LOWER_INVERTED = /^[^A-Z\xbf-\xdf]+$/
  49  const ONE_UPPER = /[a-z\xdf-\xff]/
  50  const ONE_LOWER = /[A-Z\xbf-\xdf]/  51  const ALPHA_INVERTED = /[^A-Za-z\xbf-\xdf]/gi
  52  const ALL_DIGIT = /^\d+$/
  53  const REFERENCE_YEAR = new Date().getFullYear()
Use the 'u' flag with regular expressions
  46  const ALL_UPPER_INVERTED = /^[^a-z\xdf-\xff]+$/
  47  const ALL_LOWER = /^[a-z\xdf-\xff]+$/
  48  const ALL_LOWER_INVERTED = /^[^A-Z\xbf-\xdf]+$/
  49  const ONE_UPPER = /[a-z\xdf-\xff]/  50  const ONE_LOWER = /[A-Z\xbf-\xdf]/
  51  const ALPHA_INVERTED = /[^A-Za-z\xbf-\xdf]/gi
  52  const ALL_DIGIT = /^\d+$/
Use the 'u' flag with regular expressions
  45  const ALL_UPPER = /^[A-Z\xbf-\xdf]+$/
  46  const ALL_UPPER_INVERTED = /^[^a-z\xdf-\xff]+$/
  47  const ALL_LOWER = /^[a-z\xdf-\xff]+$/
  48  const ALL_LOWER_INVERTED = /^[^A-Z\xbf-\xdf]+$/  49  const ONE_UPPER = /[a-z\xdf-\xff]/
  50  const ONE_LOWER = /[A-Z\xbf-\xdf]/
  51  const ALPHA_INVERTED = /[^A-Za-z\xbf-\xdf]/gi
Use the 'u' flag with regular expressions
  44
  45  const ALL_UPPER = /^[A-Z\xbf-\xdf]+$/
  46  const ALL_UPPER_INVERTED = /^[^a-z\xdf-\xff]+$/
  47  const ALL_LOWER = /^[a-z\xdf-\xff]+$/  48  const ALL_LOWER_INVERTED = /^[^A-Z\xbf-\xdf]+$/
  49  const ONE_UPPER = /[a-z\xdf-\xff]/
  50  const ONE_LOWER = /[A-Z\xbf-\xdf]/
Use the 'u' flag with regular expressions
  43  const END_UPPER = /^[^A-Z\xbf-\xdf]+[A-Z\xbf-\xdf]$/ // \xdf-\xff is a range for almost all special lowercase letter like ä and so on
  44
  45  const ALL_UPPER = /^[A-Z\xbf-\xdf]+$/
  46  const ALL_UPPER_INVERTED = /^[^a-z\xdf-\xff]+$/  47  const ALL_LOWER = /^[a-z\xdf-\xff]+$/
  48  const ALL_LOWER_INVERTED = /^[^A-Z\xbf-\xdf]+$/
  49  const ONE_UPPER = /[a-z\xdf-\xff]/
Use the 'u' flag with regular expressions
  42  const START_UPPER = /^[A-Z\xbf-\xdf][^A-Z\xbf-\xdf]+$/
  43  const END_UPPER = /^[^A-Z\xbf-\xdf]+[A-Z\xbf-\xdf]$/ // \xdf-\xff is a range for almost all special lowercase letter like ä and so on
  44
  45  const ALL_UPPER = /^[A-Z\xbf-\xdf]+$/  46  const ALL_UPPER_INVERTED = /^[^a-z\xdf-\xff]+$/
  47  const ALL_LOWER = /^[a-z\xdf-\xff]+$/
  48  const ALL_LOWER_INVERTED = /^[^A-Z\xbf-\xdf]+$/
Use the 'u' flag with regular expressions
  40  const MIN_YEAR_SPACE = 20 // \xbf-\xdf is a range for almost all special uppercase letter like Ä and so on
  41
  42  const START_UPPER = /^[A-Z\xbf-\xdf][^A-Z\xbf-\xdf]+$/
  43  const END_UPPER = /^[^A-Z\xbf-\xdf]+[A-Z\xbf-\xdf]$/ // \xdf-\xff is a range for almost all special lowercase letter like ä and so on  44
  45  const ALL_UPPER = /^[A-Z\xbf-\xdf]+$/
  46  const ALL_UPPER_INVERTED = /^[^a-z\xdf-\xff]+$/
Use the 'u' flag with regular expressions
  39  const MIN_SUBMATCH_GUESSES_MULTI_CHAR = 50
  40  const MIN_YEAR_SPACE = 20 // \xbf-\xdf is a range for almost all special uppercase letter like Ä and so on
  41
  42  const START_UPPER = /^[A-Z\xbf-\xdf][^A-Z\xbf-\xdf]+$/  43  const END_UPPER = /^[^A-Z\xbf-\xdf]+[A-Z\xbf-\xdf]$/ // \xdf-\xff is a range for almost all special lowercase letter like ä and so on
  44
  45  const ALL_UPPER = /^[A-Z\xbf-\xdf]+$/
Use the 'u' flag with regular expressions
1113     * @memberof TraceKit.computeStackTrace
1114     */
1115    function computeStackTraceByWalkingCallerChain (ex, depth) {
1116      const functionName = /function\s+([_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*)?\s*\(/i1117      const stack = []
1118      const funcs = {}
1119      let recursion = false
Use the 'u' flag with regular expressions
1402        // https://gist.github.com/dperini/729294
1403        // see also https://mathiasbynens.be/demo/url-regex
1404        // modified to allow protocol-relative URLs
1405        return this.optional(element) || /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u00a1-\uffff][a-z0-9\u00a1-\uffff_-]{0,62})?[a-z0-9\u00a1-\uffff]\.)+(?:[a-z\u00a1-\uffff]{2,}\.?))(?::\d{2,5})?(?:[/?#]\S*)?$/i.test(value)1406      },
1407
1408      // https://jqueryvalidation.org/date-method/
Use the 'u' flag with regular expressions
 213  // JQuery trim is deprecated, provide a trim method based on String.prototype.trim
 214  const trim = function (str) {
 215    // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim#Polyfill
 216    return str.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '') 217  }
 218
 219  // Custom selectors
Use the 'u' flag with regular expressions
2696    })
2697
2698    ts.regex.currencyReplace = /[+\-,. ]/g
2699    ts.regex.currencyTest = /^\(?\d+[\u00a3$\u20ac\u00a4\u00a5\u00a2?.]|[\u00a3$\u20ac\u00a4\u00a5\u00a2?.]\d+\)?$/2700    ts.addParser({
2701      id: 'currency',
2702      is: function (str) {
Use the 'u' flag with regular expressions
137
138  // Support: Android <=4.0 only
139  // Make sure we trim BOM and NBSP
140  const rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g141
142  jQuery.fn.init = function (arg1) {
143    const args = Array.prototype.slice.call(arguments)
Use the 'u' flag with regular expressions
701    }
702  })
703
704  const rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([a-z][^\/\0>\x20\t\r\n\f]*)[^>]*)\/>/gi705  const origHtmlPrefilter = jQuery.htmlPrefilter
706  const makeMarkup = function (html) {
707    const doc = window.document.implementation.createHTMLDocument('')
Use the 'u' flag with regular expressions
  21      return value.replace(/<.[^<>]*?>/g, ' ').replace(/&nbsp;|&#160;/gi, ' ')
  22
  23      // Remove punctuation
  24        .replace(/[.(),;:!?%#$'\"_+=\/\-“”’]*/g, '')  25    }
  26
  27    $.validator.addMethod('maxWords', function (value, element, params) {
Use the 'u' flag with regular expressions
1426
1427  // Same as url, but TLD is optional
1428  $.validator.addMethod('url2', function (value, element) {
1429    return this.optional(element) || /^(https?|ftp):\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?(((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)*(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?)(:\d*)?)(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)?(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i.test(value)1430  }, $.validator.messages.url)
1431
1432  /**
Use the 'u' flag with regular expressions
183        state.stringStartCol = stream.column()
184        return state.tokenize(stream, state)
185      } else {
186        stream.match(/^[^\s\u00a0=<>\"\']*[^\s\u00a0=<>\"\'\/]/)187        return 'word'
188      }
189    }
 16    const jsonMode = parserConfig.json || jsonldMode
 17    const trackScope = parserConfig.trackScope !== false
 18    const isTS = parserConfig.typescript
 19    const wordRE = parserConfig.wordCharacters || /[\w$\xa1-\uffff]/ 20
 21    // Tokenizer
 22
Use the 'u' flag with regular expressions
 368      if (code <= 0xf7) { return lowTypes.charAt(code) } else if (code >= 0x590 && code <= 0x5f4) { return 'R' } else if (code >= 0x600 && code <= 0x6f9) { return arabicTypes.charAt(code - 0x600) } else if (code >= 0x6ee && code <= 0x8ac) { return 'r' } else if (code >= 0x2000 && code <= 0x200b) { return 'w' } else if (code == 0x200c) { return 'b' } else { return 'L' }
 369    }
 370
 371    const bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/ 372    const isNeutral = /[stwN]/; const isStrong = /[LRr]/; const countsAsLeft = /[Lb1n]/; const countsAsNum = /[1n]/
 373
 374    function BidiSpan (level, from, to) {
Use the 'u' flag with regular expressions
 280  // as editing and measuring is concerned. This is not fully correct,
 281  // since some scripts/fonts/browsers also treat other configurations
 282  // of code points as a group.
 283  const extendingChars = /[\u0300-\u036f\u0483-\u0489\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u065e\u0670\u06d6-\u06dc\u06de-\u06e4\u06e7\u06e8\u06ea-\u06ed\u0711\u0730-\u074a\u07a6-\u07b0\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0900-\u0902\u093c\u0941-\u0948\u094d\u0951-\u0955\u0962\u0963\u0981\u09bc\u09be\u09c1-\u09c4\u09cd\u09d7\u09e2\u09e3\u0a01\u0a02\u0a3c\u0a41\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a70\u0a71\u0a75\u0a81\u0a82\u0abc\u0ac1-\u0ac5\u0ac7\u0ac8\u0acd\u0ae2\u0ae3\u0b01\u0b3c\u0b3e\u0b3f\u0b41-\u0b44\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b82\u0bbe\u0bc0\u0bcd\u0bd7\u0c3e-\u0c40\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0cbc\u0cbf\u0cc2\u0cc6\u0ccc\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0d3e\u0d41-\u0d44\u0d4d\u0d57\u0d62\u0d63\u0dca\u0dcf\u0dd2-\u0dd4\u0dd6\u0ddf\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0f18\u0f19\u0f35\u0f37\u0f39\u0f71-\u0f7e\u0f80-\u0f84\u0f86\u0f87\u0f90-\u0f97\u0f99-\u0fbc\u0fc6\u102d-\u1030\u1032-\u1037\u1039\u103a\u103d\u103e\u1058\u1059\u105e-\u1060\u1071-\u1074\u1082\u1085\u1086\u108d\u109d\u135f\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b7-\u17bd\u17c6\u17c9-\u17d3\u17dd\u180b-\u180d\u18a9\u1920-\u1922\u1927\u1928\u1932\u1939-\u193b\u1a17\u1a18\u1a56\u1a58-\u1a5e\u1a60\u1a62\u1a65-\u1a6c\u1a73-\u1a7c\u1a7f\u1b00-\u1b03\u1b34\u1b36-\u1b3a\u1b3c\u1b42\u1b6b-\u1b73\u1b80\u1b81\u1ba2-\u1ba5\u1ba8\u1ba9\u1c2c-\u1c33\u1c36\u1c37\u1cd0-\u1cd2\u1cd4-\u1ce0\u1ce2-\u1ce8\u1ced\u1dc0-\u1de6\u1dfd-\u1dff\u200c\u200d\u20d0-\u20f0\u2cef-\u2cf1\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua66f-\ua672\ua67c\ua67d\ua6f0\ua6f1\ua802\ua806\ua80b\ua825\ua826\ua8c4\ua8e0-\ua8f1\ua926-\ua92d\ua947-\ua951\ua980-\ua982\ua9b3\ua9b6-\ua9b9\ua9bc\uaa29-\uaa2e\uaa31\uaa32\uaa35\uaa36\uaa43\uaa4c\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uabe5\uabe8\uabed\udc00-\udfff\ufb1e\ufe00-\ufe0f\ufe20-\ufe26\uff9e\uff9f]/ 284  function isExtendingChar (ch) { return ch.charCodeAt(0) >= 768 && extendingChars.test(ch) }
 285
 286  // Returns a number from the range [`0`; `str.length`] unless `pos` is outside that range.
Use the 'u' flag with regular expressions
 259    return inst
 260  }
 261
 262  const nonASCIISingleCaseWordChar = /[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/ 263  function isWordCharBasic (ch) {
 264    return /\w/.test(ch) || ch > '\x80' &&
 265      (ch.toUpperCase() != ch.toLowerCase() || nonASCIISingleCaseWordChar.test(ch))
Use the 'u' flag with regular expressions
1402    '\u2029': 'u2029'
1403  }
1404
1405  const escaper = /\\|'|\r|\n|\u2028|\u2029/g1406
1407  const escapeChar = function (match) {
1408    return '\\' + escapes[match]