Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

normalize-uri.js 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. 'use strict'
  2. var asciiAlphanumeric = require('../character/ascii-alphanumeric.js')
  3. var fromCharCode = require('../constant/from-char-code.js')
  4. // encoded sequences.
  5. function normalizeUri(value) {
  6. var index = -1
  7. var result = []
  8. var start = 0
  9. var skip = 0
  10. var code
  11. var next
  12. var replace
  13. while (++index < value.length) {
  14. code = value.charCodeAt(index) // A correct percent encoded value.
  15. if (
  16. code === 37 &&
  17. asciiAlphanumeric(value.charCodeAt(index + 1)) &&
  18. asciiAlphanumeric(value.charCodeAt(index + 2))
  19. ) {
  20. skip = 2
  21. } // ASCII.
  22. else if (code < 128) {
  23. if (!/[!#$&-;=?-Z_a-z~]/.test(fromCharCode(code))) {
  24. replace = fromCharCode(code)
  25. }
  26. } // Astral.
  27. else if (code > 55295 && code < 57344) {
  28. next = value.charCodeAt(index + 1) // A correct surrogate pair.
  29. if (code < 56320 && next > 56319 && next < 57344) {
  30. replace = fromCharCode(code, next)
  31. skip = 1
  32. } // Lone surrogate.
  33. else {
  34. replace = '\uFFFD'
  35. }
  36. } // Unicode.
  37. else {
  38. replace = fromCharCode(code)
  39. }
  40. if (replace) {
  41. result.push(value.slice(start, index), encodeURIComponent(replace))
  42. start = index + skip + 1
  43. replace = undefined
  44. }
  45. if (skip) {
  46. index += skip
  47. skip = 0
  48. }
  49. }
  50. return result.join('') + value.slice(start)
  51. }
  52. module.exports = normalizeUri