{"_id":"@woocommerce/sanitize","_rev":"4-a6d1e788c8363448c0c74a3b4fd90252","name":"@woocommerce/sanitize","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@woocommerce/sanitize","version":"1.0.0","keywords":["woocommerce","sanitize","dompurify","html","security"],"author":{"name":"Automattic"},"license":"GPL-2.0-or-later","_id":"@woocommerce/sanitize@1.0.0","maintainers":[{"name":"mikejolley","email":"mikejolley86@gmail.com"},{"name":"albertjuhe","email":"contact@albertjuhe.com"},{"name":"nerrad","email":"darren@roughsmootheng.in"},{"name":"obliviousharmony","email":"obliviousharmony@gmail.com"},{"name":"louwie17","email":"lourensschep@gmail.com"},{"name":"joshuatf","email":"joshuatf@gmail.com"},{"name":"chihsuan","email":"chihsuan.tw@gmail.com"},{"name":"~woocommerce","email":"atlas@matticspace.com"},{"name":"zhongruige","email":"greg.bell@automattic.com"},{"name":"opr","email":"thomas@thomasroberts.dev"}],"homepage":"https://github.com/woocommerce/woocommerce/tree/trunk/packages/js/sanitize#readme","bugs":{"url":"https://github.com/woocommerce/woocommerce/issues"},"dist":{"shasum":"cc8898826983fa3cb92673c39e266e213f6c5f18","tarball":"https://registry.npmjs.org/@woocommerce/sanitize/-/sanitize-1.0.0.tgz","fileCount":18,"integrity":"sha512-NSTCpOzRp+kqsHTR0+Dbv6eYzm9rslUSNzOVqb3FuKeH2NU5amWDkGPx9L99+m5tOzHPUrZDWwPgGmHvOdIUNQ==","signatures":[{"sig":"MEUCIFBwXmWcuTMH6g8W1r+QvV71DAzKAV6rwLnJcXIJnRI4AiEA9XZPKISYVVNTJFMAJkgUJHeTdqtc5FEyJdVI+gQ8oI4=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":20469},"main":"build/index.js","_from":"file:woocommerce-sanitize-1.0.0.tgz","types":"build-types/index.d.ts","config":{"ci":{"lint":{"changes":"src/**/*.{js,jsx,ts,tsx}","command":"lint"},"tests":[{"name":"JavaScript","events":["pull_request","push"],"changes":["jest.config.json","tsconfig.json","src/**/*.{js,jsx,ts,tsx}"],"command":"test:js"}]}},"module":"build-module/index.js","wireit":{"build:project:cjs":{"clean":"if-file-deleted","files":["tsconfig-cjs.json","src/**/*.{js,jsx,ts,tsx}","typings/**/*.ts"],"output":["build"],"command":"tsc --project tsconfig-cjs.json --noCheck","dependencies":["dependencyOutputs"]},"build:project:esm":{"clean":"if-file-deleted","files":["tsconfig.json","src/**/*.{js,jsx,ts,tsx}","typings/**/*.ts"],"output":["build-module","build-types"],"command":"tsc --project tsconfig.json","dependencies":["dependencyOutputs"]},"dependencyOutputs":{"files":["package.json","node_modules/@woocommerce/eslint-plugin/configs","node_modules/@woocommerce/eslint-plugin/rules","node_modules/@woocommerce/eslint-plugin/index.js","node_modules/@woocommerce/internal-js-tests/build","node_modules/@woocommerce/internal-js-tests/build-module","node_modules/@woocommerce/internal-js-tests/jest-preset.js"],"allowUsuallyExcludedPaths":true},"watch:build:project:cjs":{"command":"tsc --project tsconfig-cjs.json --watch --noCheck","service":true},"watch:build:project:esm":{"command":"tsc --project tsconfig.json --watch","service":true}},"scripts":{"lint":"pnpm --if-present '/^lint:lang:.*$/'","build":"pnpm --if-present --workspace-concurrency=Infinity --stream --filter=\"$npm_package_name...\" '/^build:project:.*$/'","test:js":"jest --config ./jest.config.json --passWithNoTests","lint:fix":"pnpm --if-present '/^lint:fix:lang:.*$/'","changelog":"XDEBUG_MODE=off composer install --quiet && composer exec -- changelogger","update:php":"XDEBUG_MODE=off composer update --quiet","watch:build":"pnpm --if-present --workspace-concurrency=Infinity --filter=\"$npm_package_name...\" --parallel '/^watch:build:project:.*$/'","lint:lang:js":"eslint src","build:project":"pnpm --if-present '/^build:project:.*$/'","lint:fix:lang:js":"eslint src --fix","build:project:cjs":"wireit","build:project:esm":"wireit","watch:build:project":"pnpm --if-present run '/^watch:build:project:.*$/'","watch:build:project:cjs":"wireit","watch:build:project:esm":"wireit"},"_npmUser":{"name":"~woocommerce","email":"atlas@matticspace.com"},"_resolved":"/tmp/1d79c013273ee56ac8c5e2938728adec/woocommerce-sanitize-1.0.0.tgz","_integrity":"sha512-NSTCpOzRp+kqsHTR0+Dbv6eYzm9rslUSNzOVqb3FuKeH2NU5amWDkGPx9L99+m5tOzHPUrZDWwPgGmHvOdIUNQ==","repository":{"url":"git+https://github.com/woocommerce/woocommerce.git","type":"git","directory":"packages/js/sanitize"},"_npmVersion":"10.8.2","description":"WooCommerce HTML sanitization utilities.","directories":{},"lint-staged":{"*.(t|j)s?(x)":["pnpm lint:fix","pnpm test:js"]},"_nodeVersion":"20.19.5","dependencies":{"dompurify":"^3.2.6"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"jest":"29.5.x","eslint":"^8.55.0","rimraf":"5.0.5","wireit":"0.14.12","ts-jest":"29.1.x","jest-cli":"29.5.x","typescript":"5.7.x","@babel/core":"7.25.7","@types/jest":"29.5.x","@types/dompurify":"^2.0.4","@wordpress/scripts":"^27.0.0","@types/trusted-types":"^2.0.7","jest-environment-jsdom":"29.5.x","@woocommerce/eslint-plugin":"2.3.0","@woocommerce/internal-js-tests":"1.1.0"},"peerDependencies":{"react":"18.3.x","react-dom":"18.3.x","@types/react":"18.3.x","@types/react-dom":"18.3.x"},"_npmOperationalInternal":{"tmp":"tmp/sanitize_1.0.0_1762813862342_0.7943254340987913","host":"s3://npm-registry-packages-npm-production"}}},"time":{"created":"2025-11-10T22:31:02.183Z","modified":"2026-06-17T14:31:49.800Z","1.0.0":"2025-11-10T22:31:02.523Z"},"bugs":{"url":"https://github.com/woocommerce/woocommerce/issues"},"author":{"name":"Automattic"},"license":"GPL-2.0-or-later","homepage":"https://github.com/woocommerce/woocommerce/tree/trunk/packages/js/sanitize#readme","keywords":["woocommerce","sanitize","dompurify","html","security"],"repository":{"url":"git+https://github.com/woocommerce/woocommerce.git","type":"git","directory":"packages/js/sanitize"},"description":"WooCommerce HTML sanitization utilities.","maintainers":[{"email":"mikejolley86@gmail.com","name":"mikejolley"},{"email":"contact@albertjuhe.com","name":"albertjuhe"},{"email":"darren@roughsmootheng.in","name":"nerrad"},{"email":"lourensschep@gmail.com","name":"louwie17"},{"email":"chihsuan.tw@gmail.com","name":"chihsuan"},{"email":"heart-of-gold@matticspace.com","name":"~woocommerce"},{"email":"greg.bell@automattic.com","name":"zhongruige"},{"email":"thomas@thomasroberts.dev","name":"opr"},{"email":"public@brandonkraft.com","name":"kraftbj"}],"readme":"# @woocommerce/sanitize\n\nWooCommerce HTML sanitization utilities using DOMPurify with trusted types support.\n\n## Features\n\n- **Secure HTML Sanitization**: Uses DOMPurify to sanitize HTML content\n- **Trusted Types Support**: Automatically configures trusted types policy to avoid conflicts\n- **Configurable**: Supports custom allowed tags and attributes\n- **TypeScript Support**: Full TypeScript definitions included\n\n## Usage\n\n### Basic HTML Sanitization\n\n```typescript\nimport { sanitizeHTML } from '@woocommerce/sanitize';\n\nconst cleanHTML = sanitizeHTML('<p>Hello <script>alert(\"xss\")</script> World!</p>');\n// Returns: '<p>Hello World!</p>'\n```\n\n### React Integration\n\n```javascript\nimport { sanitizeHTML } from '@woocommerce/sanitize';\n\nfunction MyComponent( { content } ) {\n  const sanitizedContent = {\n    __html: sanitizeHTML( content )\n  };\n  \n  return (\n    <div dangerouslySetInnerHTML={ sanitizedContent } />\n  );\n}\n```\n\n### Custom Configuration\n\n```javascript\nimport { sanitizeHTML } from '@woocommerce/sanitize';\n\nconst customSanitized = sanitizeHTML(\n    html,\n    {\n        tags: ['p', 'br', 'strong'],\n        attr: ['class', 'id']\n    }\n);\n```\n\n### Selecting the return type\n\nBy default, `sanitizeHTML` returns a string. You can opt into other DOMPurify return modes with the `returnType` option:\n\n```ts\nimport { sanitizeHTML } from '@woocommerce/sanitize';\n\n// Return an HTMLBodyElement\nconst bodyEl = sanitizeHTML('<p>Hi</p>', { returnType: 'HTMLBodyElement' });\n\n// Return a DocumentFragment\nconst fragment = sanitizeHTML('<p>Hi</p>', { returnType: 'DocumentFragment' });\n```\n\n## Trusted Types\n\nThis package automatically configures a trusted types policy named `woocommerce-sanitize` to avoid conflicts with DOMPurify's default policy. The policy is initialized when the module is loaded.\n\n```ts\nimport { getTrustedTypesPolicy } from '@woocommerce/sanitize';\n\nconst policy = getTrustedTypesPolicy();\nif (policy) {\n  const trustedHTML = policy.createHTML('<p>Content</p>');\n  element.innerHTML = trustedHTML; // Safe in Trusted Types environments\n}\n```\n\nThe policy automatically sanitizes HTML using the same rules as `sanitizeHTML()`.\n","readmeFilename":"README.md"}