index.d.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /**
  2. * Make a value safe for injection as a URL.
  3. *
  4. * This encodes unsafe characters with percent-encoding and skips already
  5. * encoded sequences (see `normalizeUri`).
  6. * Further unsafe characters are encoded as character references (see
  7. * `micromark-util-encode`).
  8. *
  9. * A regex of allowed protocols can be given, in which case the URL is
  10. * sanitized.
  11. * For example, `/^(https?|ircs?|mailto|xmpp)$/i` can be used for `a[href]`, or
  12. * `/^https?$/i` for `img[src]` (this is what `github.com` allows).
  13. * If the URL includes an unknown protocol (one not matched by `protocol`, such
  14. * as a dangerous example, `javascript:`), the value is ignored.
  15. *
  16. * @param {string | null | undefined} url
  17. * URI to sanitize.
  18. * @param {RegExp | null | undefined} [protocol]
  19. * Allowed protocols.
  20. * @returns {string}
  21. * Sanitized URI.
  22. */
  23. export function sanitizeUri(url: string | null | undefined, protocol?: RegExp | null | undefined): string;
  24. /**
  25. * Normalize a URL.
  26. *
  27. * Encode unsafe characters with percent-encoding, skipping already encoded
  28. * sequences.
  29. *
  30. * @param {string} value
  31. * URI to normalize.
  32. * @returns {string}
  33. * Normalized URI.
  34. */
  35. export function normalizeUri(value: string): string;
  36. //# sourceMappingURL=index.d.ts.map