diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ee318ca..fb63387 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,5 +17,5 @@ jobs: strategy: matrix: node: - - lts/hydrogen + - lts/gallium - node diff --git a/.npmrc b/.npmrc index 9951b11..3757b30 100644 --- a/.npmrc +++ b/.npmrc @@ -1,2 +1,2 @@ -package-lock=false ignore-scripts=true +package-lock=false diff --git a/lib/index.js b/lib/index.js index e05db06..2caf1ab 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,13 +1,8 @@ -/** - * @typedef {import('hast').Element} Element - */ - import {convertElement} from 'hast-util-is-element' /** * Check if a node is a *embedded content*. * - * @type {import('hast-util-is-element').AssertPredicate} * @param value * Thing to check (typically `Node`). * @returns @@ -16,16 +11,23 @@ import {convertElement} from 'hast-util-is-element' * The elements `audio`, `canvas`, `embed`, `iframe`, `img`, `math`, * `object`, `picture`, `svg`, and `video` are embedded content. */ -// @ts-expect-error Sure, the assertion matches. -export const embedded = convertElement([ - 'audio', - 'canvas', - 'embed', - 'iframe', - 'img', - 'math', - 'object', - 'picture', - 'svg', - 'video' -]) +export const embedded = convertElement( + /** + * @param element + * @returns {element is {tagName: 'audio' | 'canvas' | 'embed' | 'iframe' | 'img' | 'math' | 'object' | 'picture' | 'svg' | 'video'}} + */ + function (element) { + return ( + element.tagName === 'audio' || + element.tagName === 'canvas' || + element.tagName === 'embed' || + element.tagName === 'iframe' || + element.tagName === 'img' || + element.tagName === 'math' || + element.tagName === 'object' || + element.tagName === 'picture' || + element.tagName === 'svg' || + element.tagName === 'video' + ) + } +) diff --git a/package.json b/package.json index 54a684c..f081896 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hast-util-embedded", - "version": "2.0.1", + "version": "3.0.0", "description": "hast utility to check if a node is an embedded element", "license": "MIT", "keywords": [ @@ -25,53 +25,54 @@ ], "sideEffects": false, "type": "module", - "main": "index.js", - "types": "index.d.ts", + "exports": "./index.js", "files": [ "lib/", "index.d.ts", "index.js" ], "dependencies": { - "hast-util-is-element": "^2.0.0" + "@types/hast": "^3.0.0", + "hast-util-is-element": "^3.0.0" }, "devDependencies": { - "@types/node": "^18.0.0", - "c8": "^7.0.0", - "prettier": "^2.0.0", + "@types/node": "^20.0.0", + "c8": "^8.0.0", + "prettier": "^3.0.0", "remark-cli": "^11.0.0", "remark-preset-wooorm": "^9.0.0", "type-coverage": "^2.0.0", - "typescript": "^4.0.0", - "xo": "^0.53.0" + "typescript": "^5.0.0", + "xo": "^0.55.0" }, "scripts": { "prepack": "npm run build && npm run format", "build": "tsc --build --clean && tsc --build && type-coverage", - "format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", + "format": "remark . -qfo && prettier . -w --log-level warn && xo --fix", "test-api": "node --conditions development test.js", - "test-coverage": "c8 --check-coverage --100 --reporter lcov npm run test-api", + "test-coverage": "c8 --100 --reporter lcov npm run test-api", "test": "npm run build && npm run format && npm run test-coverage" }, "prettier": { - "tabWidth": 2, - "useTabs": false, - "singleQuote": true, "bracketSpacing": false, "semi": false, - "trailingComma": "none" - }, - "xo": { - "prettier": true + "singleQuote": true, + "tabWidth": 2, + "trailingComma": "none", + "useTabs": false }, "remarkConfig": { "plugins": [ - "preset-wooorm" + "remark-preset-wooorm" ] }, "typeCoverage": { "atLeast": 100, "detail": true, + "ignoreCatch": true, "strict": true + }, + "xo": { + "prettier": true } } diff --git a/readme.md b/readme.md index 8a54164..0719aa8 100644 --- a/readme.md +++ b/readme.md @@ -38,7 +38,7 @@ looking for! ## Install This package is [ESM only][esm]. -In Node.js (version 14.14+ and 16.0+), install with [npm][]: +In Node.js (version 16+), install with [npm][]: ```sh npm install hast-util-embedded @@ -47,14 +47,14 @@ npm install hast-util-embedded In Deno with [`esm.sh`][esmsh]: ```js -import {embedded} from 'https://esm.sh/hast-util-embedded@2' +import {embedded} from 'https://esm.sh/hast-util-embedded@3' ``` In browsers with [`esm.sh`][esmsh]: ```html ``` @@ -82,7 +82,7 @@ embedded({ ## API -This package exports the identifier [`embedded`][embedded]. +This package exports the identifier [`embedded`][api-embedded]. There is no default export. ### `embedded(value)` @@ -108,10 +108,13 @@ It exports no additional types. ## Compatibility -Projects maintained by the unified collective are compatible with all maintained +Projects maintained by the unified collective are compatible with maintained versions of Node.js. -As of now, that is Node.js 14.14+ and 16.0+. -Our projects sometimes work with older versions, but this is not guaranteed. + +When we cut a new major release, we drop support for unmaintained versions of +Node. +This means we try to keep the current release line, `hast-util-embedded@^3`, +compatible with Node.js 16. ## Security @@ -179,9 +182,9 @@ abide by its terms. [downloads]: https://www.npmjs.com/package/hast-util-embedded -[size-badge]: https://img.shields.io/bundlephobia/minzip/hast-util-embedded.svg +[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=hast-util-embedded -[size]: https://bundlephobia.com/result?p=hast-util-embedded +[size]: https://bundlejs.com/?q=hast-util-embedded [sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg @@ -221,4 +224,4 @@ abide by its terms. [xss]: https://en.wikipedia.org/wiki/Cross-site_scripting -[embedded]: #embeddedvalue +[api-embedded]: #embeddedvalue diff --git a/test.js b/test.js index a3f751e..57de024 100644 --- a/test.js +++ b/test.js @@ -1,50 +1,61 @@ import assert from 'node:assert/strict' import test from 'node:test' -import {embedded} from './index.js' -import * as mod from './index.js' +import {embedded} from 'hast-util-embedded' -test('embedded', () => { - assert.deepEqual( - Object.keys(mod).sort(), - ['embedded'], - 'should expose the public api' - ) +test('embedded', async function (t) { + await t.test('should expose the public api', async function () { + assert.deepEqual(Object.keys(await import('hast-util-embedded')).sort(), [ + 'embedded' + ]) + }) - assert.equal(embedded(), false, 'should return `false` without node') + await t.test('should return `false` without node', async function () { + // @ts-expect-error: check how a missing node is handled. + assert.equal(embedded(), false) + }) - assert.equal(embedded(null), false, 'should return `false` with `null`') + await t.test('should return `false` with `null`', async function () { + assert.equal(embedded(null), false) + }) - assert.equal( - embedded({type: 'text'}), - false, - 'should return `false` when without `element`' + await t.test( + 'should return `false` when without `element`', + async function () { + assert.equal(embedded({type: 'text'}), false) + } ) - assert.equal( - embedded({type: 'element'}), - false, - 'should return `false` when with invalid `element`' + await t.test( + 'should return `false` when with invalid `element`', + async function () { + assert.equal(embedded({type: 'element'}), false) + } ) - assert.equal( - embedded({ - type: 'element', - tagName: 'a', - properties: {href: '#alpha', title: 'Bravo'}, - children: [{type: 'text', value: 'Charlie'}] - }), - false, - 'should return `false` when without not embedded' + await t.test( + 'should return `false` when without not embedded', + async function () { + assert.equal( + embedded({ + type: 'element', + tagName: 'a', + properties: {href: '#alpha', title: 'Bravo'}, + children: [{type: 'text', value: 'Charlie'}] + }), + false + ) + } ) - assert.equal( - embedded({ - type: 'element', - tagName: 'audio', - properties: {src: 'delta.ogg'}, - children: [] - }), - true, - 'should return `true` when with embedded' - ) + await t.test('should return `true` when with embedded', async function () { + assert.equal( + embedded({ + type: 'element', + tagName: 'audio', + properties: {src: 'delta.ogg'}, + children: [] + }), + true + ) + }) }) diff --git a/tsconfig.json b/tsconfig.json index 1bc9e99..82cc749 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,17 +1,15 @@ { - "include": ["**/**.js"], - "exclude": ["coverage/", "node_modules/"], "compilerOptions": { "checkJs": true, + "customConditions": ["development"], "declaration": true, "emitDeclarationOnly": true, "exactOptionalPropertyTypes": true, - "forceConsistentCasingInFileNames": true, - "lib": ["es2020"], + "lib": ["es2022"], "module": "node16", - "newLine": "lf", - "skipLibCheck": true, "strict": true, - "target": "es2020" - } + "target": "es2022" + }, + "exclude": ["coverage/", "node_modules/"], + "include": ["**/*.js"] } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy