Add trusted-types

This commit is contained in:
Jakub Vrana
2019-01-09 14:16:50 +01:00
parent a66df381a0
commit 18af3f8a10
4 changed files with 72 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
// Type definitions for trusted-types 1.0
// Project: https://github.com/WICG/trusted-types
// Definitions by: Jakub Vrana <https://github.com/vrana>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare class TrustedHTML {}
declare class TrustedScript {}
declare class TrustedScriptURL {}
declare class TrustedURL {}
declare class TrustedTypePolicy {
createHTML(s: string): TrustedHTML;
createScript(s: string): TrustedScript;
createScriptURL(s: string): TrustedScriptURL;
createURL(s: string): TrustedURL;
}
interface TrustedTypeInnerPolicy {
createHTML(s: string): string;
createScript(s: string): string;
createScriptURL(s: string): string;
createURL(s: string): string;
}
declare class TrustedTypePolicyFactory {
createPolicy(name: string, policy: TrustedTypeInnerPolicy, expose?: boolean): TrustedTypePolicy;
getExposedPolicy(name: string): TrustedTypePolicy;
getPolicyNames(): string[];
}
declare const TrustedTypes: TrustedTypePolicyFactory;
@@ -0,0 +1,17 @@
const policy = {
createHTML: (s: string) => s,
createScript: (s: string) => s,
createScriptURL: (s: string) => s,
createURL: (s: string) => s,
};
TrustedTypes.getPolicyNames();
TrustedTypes.createPolicy('default', policy, true);
TrustedTypes.getExposedPolicy('default');
const trustedTypes = TrustedTypes.createPolicy('test', policy);
trustedTypes.createHTML('') instanceof TrustedHTML;
trustedTypes.createScript('') instanceof TrustedScript;
trustedTypes.createScriptURL('') instanceof TrustedScriptURL;
trustedTypes.createURL('') instanceof TrustedURL;
+23
View File
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"trusted-types-tests.ts"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }