-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add trusted types support "angular-extensions#elements"
- Loading branch information
1 parent
d84102e
commit f07ed3e
Showing
3 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
import 'jest-preset-angular/setup-jest.mjs'; | ||
|
||
declare const ngDevMode: boolean; | ||
|
||
// Globals mocks | ||
(window as any).trustedTypes = { | ||
createPolicy: (name: string) => ({ | ||
createScript: (script: string) => script, | ||
createScriptURL: (url: string) => url, | ||
}), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
export declare interface TrustedTypePolicy { | ||
createScriptURL(url: string): string; | ||
} | ||
|
||
export declare interface TrustedTypePolicyFactory { | ||
createPolicy( | ||
policyName: string, | ||
policyOptions: { | ||
createScriptURL?: (url: string) => string; | ||
} | ||
): TrustedTypePolicy; | ||
} | ||
|
||
let policy: TrustedTypePolicy | null | undefined; | ||
|
||
export function getPolicy(): TrustedTypePolicy | null { | ||
if (policy === undefined) { | ||
policy = null; | ||
if (typeof window !== 'undefined') { | ||
const ttWindow = window as unknown as { | ||
trustedTypes?: TrustedTypePolicyFactory; | ||
}; | ||
if (ttWindow.trustedTypes !== undefined) { | ||
policy = ttWindow.trustedTypes.createPolicy( | ||
'angular-extensions#elements', | ||
{ | ||
createScriptURL: (url: string) => url, | ||
} | ||
); | ||
} | ||
} | ||
} | ||
return policy; | ||
} |