forked from yaronn/xpath.js
-
Notifications
You must be signed in to change notification settings - Fork 73
Adjust types to match exported functions #116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,51 @@ | ||
| /// <reference lib="dom" /> | ||
|
|
||
| type SelectedValue = Node | Attr | string | number | boolean; | ||
| interface XPathSelect { | ||
| (expression: string, node?: Node): Array<SelectedValue>; | ||
| (expression: string, node: Node, single: true): SelectedValue | undefined; | ||
| export type SelectedValue = Node | string | number | boolean | null; | ||
|
|
||
| export type SelectReturnType = Array<Node> | SelectedValue; | ||
| export type SelectSingleReturnType = SelectedValue; | ||
|
|
||
| export interface XPathSelect { | ||
| (expression: string, node: Node): SelectReturnType; | ||
| (expression: string, node: Node, single: false): SelectReturnType; | ||
| (expression: string, node: Node, single: true): SelectSingleReturnType; | ||
| } | ||
| export var select: XPathSelect; | ||
| export function select1(expression: string, node?: Node): SelectedValue | undefined; | ||
| export function evaluate(expression: string, contextNode: Node, resolver: XPathNSResolver | null, type: number, result: XPathResult | null): XPathResult; | ||
| export function useNamespaces(namespaceMap: { [name: string]: string }): XPathSelect; | ||
|
|
||
| /** | ||
| * Evaluate an XPath expression against a DOM node. | ||
| */ | ||
| export function select(expression: string, node: Node): SelectReturnType; | ||
| export function select(expression: string, node: Node, single: false): SelectReturnType; | ||
| export function select(expression: string, node: Node, single: true): SelectSingleReturnType; | ||
|
|
||
| /** | ||
| * Evaluate an xpath expression against a DOM node, returning the first result only. | ||
| */ | ||
| export function select1(expression: string, node: Node): SelectSingleReturnType; | ||
|
|
||
| /** | ||
| * Evaluate an XPath expression against a DOM node using a given namespace resolver. | ||
| */ | ||
| export function selectWithResolver(expression: string, node: Node, resolver?: XPathNSResolver | null): SelectReturnType; | ||
| export function selectWithResolver(expression: string, node: Node, resolver: XPathNSResolver | null, single: false): SelectReturnType; | ||
| export function selectWithResolver(expression: string, node: Node, resolver: XPathNSResolver | null, single: true): SelectSingleReturnType; | ||
|
|
||
| /** | ||
| * Creates a `select` function that uses the given namespace prefix to URI mappings when evaluating queries. | ||
| * @param namespaceMap an object mapping namespace prefixes to namespace URIs. Each key is a prefix; each value is a URI. | ||
| * @return a function with the same signature as `xpath.select` | ||
| */ | ||
| export function useNamespaces(namespaceMap: Record<string, string>): XPathSelect; | ||
|
|
||
| // Type guards to narrow down the type of the selected type of a returned Node object | ||
| export function isNodeLike(value: SelectedValue): value is Node; | ||
| export function isArrayOfNodes(value: SelectedValue): value is Node[]; | ||
| export function isElement(value: SelectedValue): value is Element; | ||
| export function isAttribute(value: SelectedValue): value is Attr; | ||
| export function isTextNode(value: SelectedValue): value is Text; | ||
| export function isCDATASection(value: SelectedValue): value is CDATASection; | ||
| export function isProcessingInstruction(value: SelectedValue): value is ProcessingInstruction; | ||
| export function isComment(value: SelectedValue): value is Comment; | ||
| export function isDocumentNode(value: SelectedValue): value is Document; | ||
| export function isDocumentTypeNode(value: SelectedValue): value is DocumentType; | ||
| export function isDocumentFragment(value: SelectedValue): value is DocumentFragment; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.