patterns.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /*
  2. * Copyright (c) 2015-present, Vitaly Tomilov
  3. *
  4. * See the LICENSE file at the top-level directory of this distribution
  5. * for licensing information.
  6. *
  7. * Removal or modification of this copyright notice is prohibited.
  8. */
  9. /*
  10. The most important regular expressions and data as used by the library,
  11. isolated here to help with possible edge cases during integration.
  12. */
  13. module.exports = {
  14. // Searches for all Named Parameters, supporting any of the following syntax:
  15. // ${propName}, $(propName), $[propName], $/propName/, $<propName>
  16. // Nested property names are also supported: ${propName.abc}
  17. namedParameters: /\$(?:({)|(\()|(<)|(\[)|(\/))\s*[a-zA-Z0-9$_.]+(\^|~|#|:raw|:alias|:name|:json|:csv|:list|:value)?\s*(?:(?=\2)(?=\3)(?=\4)(?=\5)}|(?=\1)(?=\3)(?=\4)(?=\5)\)|(?=\1)(?=\2)(?=\4)(?=\5)>|(?=\1)(?=\2)(?=\3)(?=\5)]|(?=\1)(?=\2)(?=\3)(?=\4)\/)/g,
  18. // Searches for all variables $1, $2, ...$100000, and while it will find greater than $100000
  19. // variables, the formatting engine is expected to throw an error for those.
  20. multipleValues: /\$([1-9][0-9]{0,16}(?![0-9])(\^|~|#|:raw|:alias|:name|:json|:csv|:list|:value)?)/g,
  21. // Searches for all occurrences of variable $1
  22. singleValue: /\$1(?![0-9])(\^|~|#|:raw|:alias|:name|:json|:csv|:list|:value)?/g,
  23. // Matches a valid column name for the Column type parser, according to the following rules:
  24. // - can contain: any combination of a-z, A-Z, 0-9, $ or _
  25. // - can contain ? at the start
  26. // - can contain one of the supported filters/modifiers
  27. validColumn: /\??[a-zA-Z0-9$_]+(\^|~|#|:raw|:alias|:name|:json|:csv|:list|:value)?/,
  28. // Matches a valid open-name JavaScript variable, according to the following rules:
  29. // - can contain: any combination of a-z, A-Z, 0-9, $ or _
  30. validVariable: /[a-zA-Z0-9$_]+/,
  31. // Matches a valid modifier in a column/property:
  32. hasValidModifier: /\^|~|#|:raw|:alias|:name|:json|:csv|:list|:value/,
  33. // List of all supported formatting modifiers:
  34. validModifiers: ['^', '~', '#', ':raw', ':alias', ':name', ':json', ':csv', ':list', ':value']
  35. };