util.js 629 B

1234567891011121314151617181920212223242526272829
  1. 'use strict'
  2. /**
  3. * Checks if the given value is a valid LastEventId.
  4. * @param {string} value
  5. * @returns {boolean}
  6. */
  7. function isValidLastEventId (value) {
  8. // LastEventId should not contain U+0000 NULL
  9. return value.indexOf('\u0000') === -1
  10. }
  11. /**
  12. * Checks if the given value is a base 10 digit.
  13. * @param {string} value
  14. * @returns {boolean}
  15. */
  16. function isASCIINumber (value) {
  17. if (value.length === 0) return false
  18. for (let i = 0; i < value.length; i++) {
  19. if (value.charCodeAt(i) < 0x30 || value.charCodeAt(i) > 0x39) return false
  20. }
  21. return true
  22. }
  23. module.exports = {
  24. isValidLastEventId,
  25. isASCIINumber
  26. }