script_impl.d.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. /**
  2. * @license
  3. * SPDX-License-Identifier: Apache-2.0
  4. */
  5. /// <reference types="trusted-types" />
  6. import '../environment/dev';
  7. /**
  8. * JavaScript code that is safe to evaluate and use as the content of an HTML
  9. * script element.
  10. */
  11. export declare type SafeScript = TrustedScript;
  12. /**
  13. * Also exports the constructor so that instanceof checks work.
  14. */
  15. export declare const SafeScript: typeof TrustedScript;
  16. /**
  17. * Builds a new `SafeScript` from the given string, without enforcing
  18. * safety guarantees. It may cause side effects by creating a Trusted Types
  19. * policy. This shouldn't be exposed to application developers, and must only be
  20. * used as a step towards safe builders or safe constants.
  21. */
  22. export declare function createScript(script: string): SafeScript;
  23. /**
  24. * An empty `SafeScript` constant.
  25. * Unlike the functions above, using this will not create a policy.
  26. */
  27. export declare const EMPTY_SCRIPT: SafeScript;
  28. /**
  29. * Checks if the given value is a `SafeScript` instance.
  30. */
  31. export declare function isScript(value: unknown): value is SafeScript;
  32. /**
  33. * Returns the value of the passed `SafeScript` object while ensuring it
  34. * has the correct type.
  35. *
  36. * Returns a native `TrustedScript` or a string if Trusted Types are disabled.
  37. */
  38. export declare function unwrapScript(value: SafeScript): TrustedScript | string;