hast-util-parse-selector
Advanced tools
Comparing version 3.1.1 to 4.0.0
@@ -1,1 +0,1 @@ | ||
export {parseSelector} from './lib/index.js' | ||
export { parseSelector } from "./lib/index.js"; |
@@ -7,7 +7,7 @@ /** | ||
* @template {string} [DefaultTagName='div'] | ||
* Type of default tag name. | ||
* Type of default tag name (default: `'div'`). | ||
* @param {Selector | null | undefined} [selector] | ||
* Simple CSS selector. | ||
* Simple CSS selector (optional). | ||
* | ||
* Can contain a tag-name (`foo`), classes (`.bar`), and an ID (`#baz`). | ||
* Can contain a tag name (`foo`), classes (`.bar`), and an ID (`#baz`). | ||
* Multiple classes are allowed. | ||
@@ -17,15 +17,13 @@ * Uses the last ID if multiple IDs are found. | ||
* Tag name to use if `selector` does not specify one (default: `'div'`). | ||
* @returns {Element & {tagName: import('./extract.js').ExtractTagName<Selector, DefaultTagName>}} | ||
* @returns {Element & {tagName: ExtractTagName<Selector, DefaultTagName>}} | ||
* Built element. | ||
*/ | ||
export function parseSelector< | ||
Selector extends string, | ||
DefaultTagName extends string = 'div' | ||
>( | ||
selector?: Selector | null | undefined, | ||
defaultTagName?: DefaultTagName | null | undefined | ||
): import('hast').Element & { | ||
tagName: import('./extract.js').ExtractTagName<Selector, DefaultTagName> | ||
} | ||
export type Properties = import('hast').Properties | ||
export type Element = import('hast').Element | ||
export function parseSelector<Selector extends string, DefaultTagName extends string = "div">(selector?: Selector | null | undefined, defaultTagName?: DefaultTagName | null | undefined): import("hast").Element & { | ||
tagName: ExtractTagName<Selector, DefaultTagName>; | ||
}; | ||
export type Element = import('hast').Element; | ||
export type Properties = import('hast').Properties; | ||
/** | ||
* Extract tag name from a simple selector. | ||
*/ | ||
export type ExtractTagName<SimpleSelector extends string, DefaultTagName extends string> = SimpleSelector extends "" ? DefaultTagName : SimpleSelector extends `${infer TagName}.${infer Rest}` ? ExtractTagName<TagName, DefaultTagName> : SimpleSelector extends `${infer TagName_1}#${infer Rest_1}` ? ExtractTagName<TagName_1, DefaultTagName> : SimpleSelector extends string ? SimpleSelector : DefaultTagName; |
/** | ||
* @typedef {import('hast').Element} Element | ||
* @typedef {import('hast').Properties} Properties | ||
* @typedef {import('hast').Element} Element | ||
*/ | ||
/** | ||
* @template {string} SimpleSelector | ||
* Selector type. | ||
* @template {string} DefaultTagName | ||
* Default tag name. | ||
* @typedef {( | ||
* SimpleSelector extends '' | ||
* ? DefaultTagName | ||
* : SimpleSelector extends `${infer TagName}.${infer Rest}` | ||
* ? ExtractTagName<TagName, DefaultTagName> | ||
* : SimpleSelector extends `${infer TagName}#${infer Rest}` | ||
* ? ExtractTagName<TagName, DefaultTagName> | ||
* : SimpleSelector extends string | ||
* ? SimpleSelector | ||
* : DefaultTagName | ||
* )} ExtractTagName | ||
* Extract tag name from a simple selector. | ||
*/ | ||
const search = /[#.]/g | ||
@@ -14,5 +33,5 @@ | ||
* @template {string} [DefaultTagName='div'] | ||
* Type of default tag name. | ||
* Type of default tag name (default: `'div'`). | ||
* @param {Selector | null | undefined} [selector] | ||
* Simple CSS selector. | ||
* Simple CSS selector (optional). | ||
* | ||
@@ -24,3 +43,3 @@ * Can contain a tag name (`foo`), classes (`.bar`), and an ID (`#baz`). | ||
* Tag name to use if `selector` does not specify one (default: `'div'`). | ||
* @returns {Element & {tagName: import('./extract.js').ExtractTagName<Selector, DefaultTagName>}} | ||
* @returns {Element & {tagName: ExtractTagName<Selector, DefaultTagName>}} | ||
* Built element. | ||
@@ -65,3 +84,3 @@ */ | ||
type: 'element', | ||
// @ts-expect-error: fine. | ||
// @ts-expect-error: tag name is parsed. | ||
tagName: tagName || defaultTagName || 'div', | ||
@@ -68,0 +87,0 @@ properties: props, |
{ | ||
"name": "hast-util-parse-selector", | ||
"version": "3.1.1", | ||
"version": "4.0.0", | ||
"description": "hast utility to create an element from a simple CSS selector", | ||
@@ -29,11 +29,3 @@ "license": "MIT", | ||
"type": "module", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"typesVersions": { | ||
"<=4.1": { | ||
"lib/extract.d.ts": [ | ||
"lib/extract-legacy.d.ts" | ||
] | ||
} | ||
}, | ||
"exports": "./index.js", | ||
"files": [ | ||
@@ -45,37 +37,34 @@ "lib/", | ||
"dependencies": { | ||
"@types/hast": "^2.0.0" | ||
"@types/hast": "^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", | ||
"tsd": "^0.25.0", | ||
"tsd": "^0.28.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", | ||
"build": "tsc --build --clean && tsc --build && type-coverage && tsd", | ||
"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" | ||
"singleQuote": true, | ||
"tabWidth": 2, | ||
"trailingComma": "none", | ||
"useTabs": false | ||
}, | ||
"xo": { | ||
"prettier": true | ||
}, | ||
"remarkConfig": { | ||
"plugins": [ | ||
"preset-wooorm" | ||
"remark-preset-wooorm" | ||
] | ||
@@ -86,4 +75,8 @@ }, | ||
"detail": true, | ||
"ignoreCatch": true, | ||
"strict": true | ||
}, | ||
"xo": { | ||
"prettier": true | ||
} | ||
} |
@@ -41,3 +41,3 @@ # hast-util-parse-selector | ||
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][]: | ||
@@ -51,3 +51,3 @@ ```sh | ||
```js | ||
import {parseSelector} from 'https://esm.sh/hast-util-parse-selector@3' | ||
import {parseSelector} from 'https://esm.sh/hast-util-parse-selector@4' | ||
``` | ||
@@ -59,3 +59,3 @@ | ||
<script type="module"> | ||
import {parseSelector} from 'https://esm.sh/hast-util-parse-selector@3?bundle' | ||
import {parseSelector} from 'https://esm.sh/hast-util-parse-selector@4?bundle' | ||
</script> | ||
@@ -83,3 +83,3 @@ ``` | ||
This package exports the identifier [`parseSelector`][parseselector]. | ||
This package exports the identifier [`parseSelector`][api-parse-selector]. | ||
There is no default export. | ||
@@ -109,12 +109,12 @@ | ||
In TypeScript 4.2+, the type system can infer the tag name of literal | ||
`selector`s and knows that the return element has that name. | ||
## 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-parse-selector@^4`, compatible with Node.js 16. | ||
## Security | ||
@@ -162,5 +162,5 @@ | ||
[size-badge]: https://img.shields.io/bundlephobia/minzip/hast-util-parse-selector.svg | ||
[size-badge]: https://img.shields.io/badge/dynamic/json?label=minzipped%20size&query=$.size.compressedSize&url=https://deno.bundlejs.com/?q=hast-util-parse-selector | ||
[size]: https://bundlephobia.com/result?p=hast-util-parse-selector | ||
[size]: https://bundlejs.com/?q=hast-util-parse-selector | ||
@@ -209,2 +209,2 @@ [sponsors-badge]: https://opencollective.com/unified/sponsors/badge.svg | ||
[parseselector]: #parseselectorselector-defaulttagname | ||
[api-parse-selector]: #parseselectorselector-defaulttagname |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
12652
7
109
+ Added@types/hast@3.0.4(transitive)
+ Added@types/unist@3.0.3(transitive)
- Removed@types/hast@2.3.10(transitive)
- Removed@types/unist@2.0.11(transitive)
Updated@types/hast@^3.0.0