From 18af3f8a109da3ff6fc443132951ab19a299be3f Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Wed, 9 Jan 2019 14:16:50 +0100 Subject: [PATCH] Add trusted-types --- types/trusted-types/index.d.ts | 31 ++++++++++++++++++++++ types/trusted-types/trusted-types-tests.ts | 17 ++++++++++++ types/trusted-types/tsconfig.json | 23 ++++++++++++++++ types/trusted-types/tslint.json | 1 + 4 files changed, 72 insertions(+) create mode 100644 types/trusted-types/index.d.ts create mode 100644 types/trusted-types/trusted-types-tests.ts create mode 100644 types/trusted-types/tsconfig.json create mode 100644 types/trusted-types/tslint.json diff --git a/types/trusted-types/index.d.ts b/types/trusted-types/index.d.ts new file mode 100644 index 0000000000..64ed96b713 --- /dev/null +++ b/types/trusted-types/index.d.ts @@ -0,0 +1,31 @@ +// Type definitions for trusted-types 1.0 +// Project: https://github.com/WICG/trusted-types +// Definitions by: Jakub 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; diff --git a/types/trusted-types/trusted-types-tests.ts b/types/trusted-types/trusted-types-tests.ts new file mode 100644 index 0000000000..79f79db4b7 --- /dev/null +++ b/types/trusted-types/trusted-types-tests.ts @@ -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; diff --git a/types/trusted-types/tsconfig.json b/types/trusted-types/tsconfig.json new file mode 100644 index 0000000000..8bfe83a032 --- /dev/null +++ b/types/trusted-types/tsconfig.json @@ -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" + ] +} diff --git a/types/trusted-types/tslint.json b/types/trusted-types/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/trusted-types/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }