From 4f62dcd63cdc19167261cb980cdeba9b8ae2d2ca Mon Sep 17 00:00:00 2001 From: Mario Heiderich Date: Sat, 13 Aug 2022 16:18:52 +0200 Subject: [PATCH] chore: Added new npm script "types" to create type definitions chore: Made sure that type definitions are created in ./dist chore: Added type definition files to git via commit-amend-build.sh --- dist/purify.cjs.d.ts | 144 ++++++++++++++++++++++++++++++++++ dist/purify.es.d.ts | 144 ++++++++++++++++++++++++++++++++++ package.json | 4 +- scripts/commit-amend-build.sh | 4 +- 4 files changed, 293 insertions(+), 3 deletions(-) create mode 100644 dist/purify.cjs.d.ts create mode 100644 dist/purify.es.d.ts diff --git a/dist/purify.cjs.d.ts b/dist/purify.cjs.d.ts new file mode 100644 index 00000000..f067d8dd --- /dev/null +++ b/dist/purify.cjs.d.ts @@ -0,0 +1,144 @@ +export = purify; +declare function purify(root: any): { + (root: any): any; + /** + * Version label, exposed for easier checks + * if DOMPurify is up to date or not + */ + version: string; + /** + * Array of elements that DOMPurify removed during sanitation. + * Empty if nothing was removed. + */ + removed: any[]; + isSupported: boolean; + /** + * Sanitize + * Public method providing core sanitation functionality + * + * @param {String|Node} dirty string or DOM node + * @param {Object} configuration object + */ + sanitize(dirty: string | Node, cfg: any): any; + /** + * Public method to set the configuration once + * setConfig + * + * @param {Object} cfg configuration object + */ + setConfig(cfg: any): void; + /** + * Public method to remove the configuration + * clearConfig + * + */ + clearConfig(): void; + /** + * Public method to check if an attribute value is valid. + * Uses last set config, if any. Otherwise, uses config defaults. + * isValidAttribute + * + * @param {string} tag Tag name of containing element. + * @param {string} attr Attribute name. + * @param {string} value Attribute value. + * @return {Boolean} Returns true if `value` is valid. Otherwise, returns false. + */ + isValidAttribute(tag: string, attr: string, value: string): boolean; + /** + * AddHook + * Public method to add DOMPurify hooks + * + * @param {String} entryPoint entry point for the hook to add + * @param {Function} hookFunction function to execute + */ + addHook(entryPoint: string, hookFunction: Function): void; + /** + * RemoveHook + * Public method to remove a DOMPurify hook at a given entryPoint + * (pops it from the stack of hooks if more are present) + * + * @param {String} entryPoint entry point for the hook to remove + * @return {Function} removed(popped) hook + */ + removeHook(entryPoint: string): Function; + /** + * RemoveHooks + * Public method to remove all DOMPurify hooks at a given entryPoint + * + * @param {String} entryPoint entry point for the hooks to remove + */ + removeHooks(entryPoint: string): void; + /** + * RemoveAllHooks + * Public method to remove all DOMPurify hooks + * + */ + removeAllHooks(): void; +}; +declare namespace purify { + const version: string; + const removed: any[]; + const isSupported: boolean; + /** + * Sanitize + * Public method providing core sanitation functionality + * + * @param {String|Node} dirty string or DOM node + * @param {Object} configuration object + */ + function sanitize(dirty: string | Node, cfg: any): any; + /** + * Public method to set the configuration once + * setConfig + * + * @param {Object} cfg configuration object + */ + function setConfig(cfg: any): void; + /** + * Public method to remove the configuration + * clearConfig + * + */ + function clearConfig(): void; + /** + * Public method to check if an attribute value is valid. + * Uses last set config, if any. Otherwise, uses config defaults. + * isValidAttribute + * + * @param {string} tag Tag name of containing element. + * @param {string} attr Attribute name. + * @param {string} value Attribute value. + * @return {Boolean} Returns true if `value` is valid. Otherwise, returns false. + */ + function isValidAttribute(tag: string, attr: string, value: string): boolean; + /** + * AddHook + * Public method to add DOMPurify hooks + * + * @param {String} entryPoint entry point for the hook to add + * @param {Function} hookFunction function to execute + */ + function addHook(entryPoint: string, hookFunction: Function): void; + /** + * RemoveHook + * Public method to remove a DOMPurify hook at a given entryPoint + * (pops it from the stack of hooks if more are present) + * + * @param {String} entryPoint entry point for the hook to remove + * @return {Function} removed(popped) hook + */ + function removeHook(entryPoint: string): Function; + /** + * RemoveHooks + * Public method to remove all DOMPurify hooks at a given entryPoint + * + * @param {String} entryPoint entry point for the hooks to remove + */ + function removeHooks(entryPoint: string): void; + /** + * RemoveAllHooks + * Public method to remove all DOMPurify hooks + * + */ + function removeAllHooks(): void; +} diff --git a/dist/purify.es.d.ts b/dist/purify.es.d.ts new file mode 100644 index 00000000..23f1b198 --- /dev/null +++ b/dist/purify.es.d.ts @@ -0,0 +1,144 @@ +export { purify as default }; +declare function purify(root: any): { + (root: any): any; + /** + * Version label, exposed for easier checks + * if DOMPurify is up to date or not + */ + version: string; + /** + * Array of elements that DOMPurify removed during sanitation. + * Empty if nothing was removed. + */ + removed: any[]; + isSupported: boolean; + /** + * Sanitize + * Public method providing core sanitation functionality + * + * @param {String|Node} dirty string or DOM node + * @param {Object} configuration object + */ + sanitize(dirty: string | Node, cfg: any): any; + /** + * Public method to set the configuration once + * setConfig + * + * @param {Object} cfg configuration object + */ + setConfig(cfg: any): void; + /** + * Public method to remove the configuration + * clearConfig + * + */ + clearConfig(): void; + /** + * Public method to check if an attribute value is valid. + * Uses last set config, if any. Otherwise, uses config defaults. + * isValidAttribute + * + * @param {string} tag Tag name of containing element. + * @param {string} attr Attribute name. + * @param {string} value Attribute value. + * @return {Boolean} Returns true if `value` is valid. Otherwise, returns false. + */ + isValidAttribute(tag: string, attr: string, value: string): boolean; + /** + * AddHook + * Public method to add DOMPurify hooks + * + * @param {String} entryPoint entry point for the hook to add + * @param {Function} hookFunction function to execute + */ + addHook(entryPoint: string, hookFunction: Function): void; + /** + * RemoveHook + * Public method to remove a DOMPurify hook at a given entryPoint + * (pops it from the stack of hooks if more are present) + * + * @param {String} entryPoint entry point for the hook to remove + * @return {Function} removed(popped) hook + */ + removeHook(entryPoint: string): Function; + /** + * RemoveHooks + * Public method to remove all DOMPurify hooks at a given entryPoint + * + * @param {String} entryPoint entry point for the hooks to remove + */ + removeHooks(entryPoint: string): void; + /** + * RemoveAllHooks + * Public method to remove all DOMPurify hooks + * + */ + removeAllHooks(): void; +}; +declare namespace purify { + const version: string; + const removed: any[]; + const isSupported: boolean; + /** + * Sanitize + * Public method providing core sanitation functionality + * + * @param {String|Node} dirty string or DOM node + * @param {Object} configuration object + */ + function sanitize(dirty: string | Node, cfg: any): any; + /** + * Public method to set the configuration once + * setConfig + * + * @param {Object} cfg configuration object + */ + function setConfig(cfg: any): void; + /** + * Public method to remove the configuration + * clearConfig + * + */ + function clearConfig(): void; + /** + * Public method to check if an attribute value is valid. + * Uses last set config, if any. Otherwise, uses config defaults. + * isValidAttribute + * + * @param {string} tag Tag name of containing element. + * @param {string} attr Attribute name. + * @param {string} value Attribute value. + * @return {Boolean} Returns true if `value` is valid. Otherwise, returns false. + */ + function isValidAttribute(tag: string, attr: string, value: string): boolean; + /** + * AddHook + * Public method to add DOMPurify hooks + * + * @param {String} entryPoint entry point for the hook to add + * @param {Function} hookFunction function to execute + */ + function addHook(entryPoint: string, hookFunction: Function): void; + /** + * RemoveHook + * Public method to remove a DOMPurify hook at a given entryPoint + * (pops it from the stack of hooks if more are present) + * + * @param {String} entryPoint entry point for the hook to remove + * @return {Function} removed(popped) hook + */ + function removeHook(entryPoint: string): Function; + /** + * RemoveHooks + * Public method to remove all DOMPurify hooks at a given entryPoint + * + * @param {String} entryPoint entry point for the hooks to remove + */ + function removeHooks(entryPoint: string): void; + /** + * RemoveAllHooks + * Public method to remove all DOMPurify hooks + * + */ + function removeAllHooks(): void; +} diff --git a/package.json b/package.json index b9e19440..ff75de82 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,8 @@ "test:jsdom": "cross-env NODE_ENV=test BABEL_ENV=rollup node test/jsdom-node-runner --dot", "test:karma": "cross-env NODE_ENV=test BABEL_ENV=rollup karma start test/karma.conf.js --log-level warn ", "test:ci": "cross-env NODE_ENV=test BABEL_ENV=rollup npm run test:jsdom && npm run test:karma -- --log-level error --reporters dots --single-run --shouldTestOnBrowserStack=\"${TEST_BROWSERSTACK}\" --shouldProbeOnly=\"${TEST_PROBE_ONLY}\"", - "test": "cross-env NODE_ENV=test BABEL_ENV=rollup npm run lint && npm run test:jsdom && npm run test:karma -- --browsers Chrome" + "test": "cross-env NODE_ENV=test BABEL_ENV=rollup npm run lint && npm run test:jsdom && npm run test:karma -- --browsers Chrome", + "types": "npx -p typescript tsc dist/purify.cjs.js dist/purify.es.js --declaration --allowJs --emitDeclarationOnly --outDir dist" }, "main": "dist/purify.cjs.js", "module": "dist/purify.es.js", @@ -26,6 +27,7 @@ "pre-commit": [ "lint", "build", + "types", "commit-amend-build" ], "xo": { diff --git a/scripts/commit-amend-build.sh b/scripts/commit-amend-build.sh index 37f17537..391a0538 100755 --- a/scripts/commit-amend-build.sh +++ b/scripts/commit-amend-build.sh @@ -1,3 +1,3 @@ -echo "# Amending minified assets to HEAD" +echo "# Amending minified assets & types to HEAD" -git add ./dist/purify.js ./dist/purify.js.map ./dist/purify.min.js ./dist/purify.min.js.map ./dist/purify.cjs.js ./dist/purify.cjs.js.map ./dist/purify.es.js ./dist/purify.es.js.map +git add ./dist/purify.js ./dist/purify.js.map ./dist/purify.min.js ./dist/purify.min.js.map ./dist/purify.cjs.js ./dist/purify.cjs.js.map ./dist/purify.cjs.d.ts ./dist/purify.es.js ./dist/purify.es.js.map ./dist/purify.es.d.ts