MCPcopy Create free account
hub / github.com/angular/components / getPolicy

Function getPolicy

src/cdk/private/trusted-types.ts:42–63  ·  view source on GitHub ↗

* Returns the Trusted Types policy, or null if Trusted Types are not * enabled/supported. The first call to this function will create the policy.

()

Source from the content-addressed store, hash-verified

40 * enabled/supported. The first call to this function will create the policy.
41 */
42function getPolicy(): TrustedTypePolicy | null {
43 if (policy === undefined) {
44 policy = null;
45 if (typeof window !== 'undefined') {
46 const ttWindow = window as unknown as {trustedTypes?: TrustedTypePolicyFactory};
47 if (ttWindow.trustedTypes !== undefined) {
48 try {
49 policy = ttWindow.trustedTypes.createPolicy('angular#components', {
50 createHTML: (s: string) => s,
51 });
52 } catch (error) {
53 // createPolicy can throw if the name is already registered, or if
54 // window.trustedTypes was DOM-clobbered with an HTML element before
55 // Angular bootstrapped. trustedHTMLFromString falls back to plain
56 // strings — sanitization in _setInnerHtml still runs.
57 console.error(error);
58 }
59 }
60 }
61 }
62 return policy;
63}
64
65/**
66 * Unsafely promote a string to a TrustedHTML, falling back to strings when

Callers 1

trustedHTMLFromStringFunction · 0.85

Calls 2

createPolicyMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected