Skip to content

Commit 9a4be78

Browse files
committed
art: 🎨 dts 简化
1 parent 7f999a0 commit 9a4be78

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

libs/xpath-selector/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @xiaohuohumax/xpath-selector
22

3+
## 1.1.1
4+
5+
### Patch Changes
6+
7+
- dts 简化
8+
39
## 1.1.0
410

511
### Minor Changes

libs/xpath-selector/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@xiaohuohumax/xpath-selector",
33
"type": "module",
4-
"version": "1.1.0",
4+
"version": "1.1.1",
55
"description": "XPath Selector -- 一个 XPath 选择器库,快速获取节点数据",
66
"author": {
77
"name": "xiaohuohumax",

libs/xpath-selector/src/index.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,20 @@ function returnTypeTransition<T extends ReturnType>(returnType: T): ReturnTypeTr
5252
return returnTypeMap[returnType]
5353
}
5454

55+
type QuickFunc<T extends ReturnType> = <N extends fontoxpath.Node>(expression: string, node?: Node) => fontoxpath.IReturnTypes<N>[ReturnTypeTransition<T>]
56+
5557
export interface XPathSelector {
5658
<N extends fontoxpath.Node, T extends ReturnType>(options: Options<T>): fontoxpath.IReturnTypes<N>[ReturnTypeTransition<T>]
57-
selectString: <N extends fontoxpath.Node>(expression: string, node?: Node) => fontoxpath.IReturnTypes<N>[ReturnTypeTransition<'string'>]
58-
selectStrings: <N extends fontoxpath.Node>(expression: string, node?: Node) => fontoxpath.IReturnTypes<N>[ReturnTypeTransition<'strings'>]
59-
selectNumber: <N extends fontoxpath.Node>(expression: string, node?: Node) => fontoxpath.IReturnTypes<N>[ReturnTypeTransition<'number'>]
60-
selectNumbers: <N extends fontoxpath.Node>(expression: string, node?: Node) => fontoxpath.IReturnTypes<N>[ReturnTypeTransition<'numbers'>]
61-
selectBoolean: <N extends fontoxpath.Node>(expression: string, node?: Node) => fontoxpath.IReturnTypes<N>[ReturnTypeTransition<'boolean'>]
62-
selectNodes: <N extends fontoxpath.Node>(expression: string, node?: Node) => fontoxpath.IReturnTypes<N>[ReturnTypeTransition<'nodes'>]
63-
selectFirstNode: <N extends fontoxpath.Node>(expression: string, node?: Node) => fontoxpath.IReturnTypes<N>[ReturnTypeTransition<'first-node'>]
64-
selectMap: <N extends fontoxpath.Node>(expression: string, node?: Node) => fontoxpath.IReturnTypes<N>[ReturnTypeTransition<'map'>]
65-
selectArray: <N extends fontoxpath.Node>(expression: string, node?: Node) => fontoxpath.IReturnTypes<N>[ReturnTypeTransition<'array'>]
66-
selectAllResults: <N extends fontoxpath.Node>(expression: string, node?: Node) => fontoxpath.IReturnTypes<N>[ReturnTypeTransition<'all-results'>]
59+
selectString: QuickFunc<'string'>
60+
selectStrings: QuickFunc<'strings'>
61+
selectNumber: QuickFunc<'number'>
62+
selectNumbers: QuickFunc<'numbers'>
63+
selectBoolean: QuickFunc<'boolean'>
64+
selectNodes: QuickFunc<'nodes'>
65+
selectFirstNode: QuickFunc<'first-node'>
66+
selectMap: QuickFunc<'map'>
67+
selectArray: QuickFunc<'array'>
68+
selectAllResults: QuickFunc<'all-results'>
6769
}
6870

6971
function createXPathSelector(): XPathSelector {
@@ -77,15 +79,15 @@ function createXPathSelector(): XPathSelector {
7779
)
7880
}
7981

80-
xpathSelector.selectString = <N extends fontoxpath.Node>(expression: string, node?: Node) => xpathSelector<N, 'string'>({ expression, node, returnType: 'string' })
81-
xpathSelector.selectStrings = <N extends fontoxpath.Node>(expression: string, node?: Node) => xpathSelector<N, 'strings'>({ expression, node, returnType: 'strings' })
82-
xpathSelector.selectNumber = <N extends fontoxpath.Node>(expression: string, node?: Node) => xpathSelector<N, 'number'>({ expression, node, returnType: 'number' })
83-
xpathSelector.selectNumbers = <N extends fontoxpath.Node>(expression: string, node?: Node) => xpathSelector<N, 'numbers'>({ expression, node, returnType: 'numbers' })
84-
xpathSelector.selectBoolean = <N extends fontoxpath.Node>(expression: string, node?: Node) => xpathSelector<N, 'boolean'>({ expression, node, returnType: 'boolean' })
82+
xpathSelector.selectString = (expression: string, node?: Node) => xpathSelector({ expression, node, returnType: 'string' })
83+
xpathSelector.selectStrings = (expression: string, node?: Node) => xpathSelector({ expression, node, returnType: 'strings' })
84+
xpathSelector.selectNumber = (expression: string, node?: Node) => xpathSelector({ expression, node, returnType: 'number' })
85+
xpathSelector.selectNumbers = (expression: string, node?: Node) => xpathSelector({ expression, node, returnType: 'numbers' })
86+
xpathSelector.selectBoolean = (expression: string, node?: Node) => xpathSelector({ expression, node, returnType: 'boolean' })
8587
xpathSelector.selectNodes = <N extends fontoxpath.Node>(expression: string, node?: Node) => xpathSelector<N, 'nodes'>({ expression, node, returnType: 'nodes' })
8688
xpathSelector.selectFirstNode = <N extends fontoxpath.Node>(expression: string, node?: Node) => xpathSelector<N, 'first-node'>({ expression, node, returnType: 'first-node' })
87-
xpathSelector.selectMap = <N extends fontoxpath.Node>(expression: string, node?: Node) => xpathSelector<N, 'map'>({ expression, node, returnType: 'map' })
88-
xpathSelector.selectArray = <N extends fontoxpath.Node>(expression: string, node?: Node) => xpathSelector<N, 'array'>({ expression, node, returnType: 'array' })
89+
xpathSelector.selectMap = (expression: string, node?: Node) => xpathSelector({ expression, node, returnType: 'map' })
90+
xpathSelector.selectArray = (expression: string, node?: Node) => xpathSelector({ expression, node, returnType: 'array' })
8991
xpathSelector.selectAllResults = <N extends fontoxpath.Node>(expression: string, node?: Node) => xpathSelector<N, 'all-results'>({ expression, node, returnType: 'all-results' })
9092

9193
return xpathSelector

0 commit comments

Comments
 (0)