{"id":11010,"library":"hast-util-is-javascript","title":"hast-util-is-javascript","description":"`hast-util-is-javascript` is a utility package within the unified/rehype ecosystem designed to determine if a given `hast` (HTML Abstract Syntax Tree) node represents a JavaScript script. It specifically checks `<script>` elements, evaluating their `type` and `language` attributes to ascertain if they contain or reference JavaScript, or if these attributes are absent, implying JavaScript by default. The current stable version is `3.0.1`. As part of the `rehypejs` project, it follows a coordinated release schedule, often releasing minor or patch updates across multiple packages, with major version increments for significant breaking changes, such as the recent `7.0.0` ecosystem release which introduced ESM-only modules and a Node.js 16+ requirement. Its primary differentiator is its seamless integration with other `hast` manipulation tools and its strict adherence to WHATWG HTML parsing standards.","status":"active","version":"3.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/rehypejs/rehype-minify#main","tags":["javascript","hast","hast-util","html","script","unist","util","utility","typescript"],"install":[{"cmd":"npm install hast-util-is-javascript","lang":"bash","label":"npm"},{"cmd":"yarn add hast-util-is-javascript","lang":"bash","label":"yarn"},{"cmd":"pnpm add hast-util-is-javascript","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package is ESM-only since v3; CommonJS `require` is not supported. Additionally, `isJavaScript` is a named export, not a default export.","wrong":"const isJavaScript = require('hast-util-is-javascript')","symbol":"isJavaScript","correct":"import { isJavaScript } from 'hast-util-is-javascript'"}],"quickstart":{"code":"import { h } from 'hastscript';\nimport { isJavaScript } from 'hast-util-is-javascript';\n\n// Create a script element without type/language, which defaults to JS\nconst jsScript = h('script');\nconsole.log(\"Is plain script JS?\", isJavaScript(jsScript));\n// Expected output: Is plain script JS? true\n\n// Create a script element with explicit JS type\nconst jsScriptWithType = h('script', { type: 'text/ecmascript' });\nconsole.log(\"Is script with text/ecmascript type JS?\", isJavaScript(jsScriptWithType));\n// Expected output: Is script with text/ecmascript type JS? true\n\n// Create a script element with explicit JS language\nconst jsScriptWithLanguage = h('script', { language: 'ecmascript' });\nconsole.log(\"Is script with ecmascript language JS?\", isJavaScript(jsScriptWithLanguage));\n// Expected output: Is script with ecmascript language JS? true\n\n// Create a script element with a non-JS type\nconst nonJsScript = h('script', { type: 'text/fooscript' });\nconsole.log(\"Is script with text/fooscript type JS?\", isJavaScript(nonJsScript));\n// Expected output: Is script with text/fooscript type JS? false\n\n// Create a div element (not a script)\nconst divElement = h('div');\nconsole.log(\"Is a div element JS?\", isJavaScript(divElement));\n// Expected output: Is a div element JS? false","lang":"javascript","description":"Demonstrates how to use `isJavaScript` to check various `hast` script nodes for JavaScript content based on their `type` or `language` attributes, or when these attributes are implicitly JavaScript."},"warnings":[{"fix":"Migrate your project to use ES module imports (`import ... from '...'`) instead of CommonJS `require()` statements.","message":"This package is now pure ES module (ESM) and no longer provides CommonJS (CJS) exports. Direct `require()` calls will fail.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Upgrade your Node.js environment to version 16 or newer. Check the unified collective's compatibility guidelines for specific version requirements.","message":"Node.js 16 or greater is now required for this package. Older Node.js versions are no longer supported.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Always sanitize your `hast` trees, especially when dealing with user-generated or untrusted content. Use `rehype-sanitize` to make the tree safe before rendering to HTML.","message":"Working with HTML ASTs like `hast` can expose applications to Cross-Site Scripting (XSS) vulnerabilities if not handled carefully, especially when injecting user-supplied content.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Change your import statement from `const isJavaScript = require('hast-util-is-javascript')` to `import { isJavaScript } from 'hast-util-is-javascript'`.","cause":"Attempting to import `hast-util-is-javascript` using CommonJS `require()` syntax in an environment that enforces ESM.","error":"ERR_REQUIRE_ESM"},{"fix":"Ensure you are using a named import: `import { isJavaScript } from 'hast-util-is-javascript'`.","cause":"Attempting to use `import isJavaScript from 'hast-util-is-javascript'` which assumes a default export, but `isJavaScript` is a named export.","error":"TypeError: Cannot read properties of undefined (reading 'isJavaScript') or TypeError: isJavaScript is not a function"}],"ecosystem":"npm"}