Skip to content

Commit

Permalink
refactor(types): Make types easier to consume (#2915)
Browse files Browse the repository at this point in the history
TypeDoc will now resolve several symbols to external documentation
  • Loading branch information
fb55 committed Dec 23, 2022
1 parent 00b8777 commit fa00a9d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
16 changes: 8 additions & 8 deletions src/options.ts
@@ -1,20 +1,20 @@
import type { DomHandlerOptions } from 'domhandler';
import type { ParserOptions } from 'htmlparser2';
import type { ParserOptions as HTMLParser2ParserOptions } from 'htmlparser2';
import type { ParserOptions as Parse5ParserOptions } from 'parse5';
import type { Htmlparser2TreeAdapterMap } from 'parse5-htmlparser2-tree-adapter';
import type { Options as SelectOptions } from 'cheerio-select';

/**
* Options accepted by htmlparser2, the default parser for XML.
*
* @see https://github.com/fb55/htmlparser2/wiki/Parser-options
*/
export interface HTMLParser2Options extends DomHandlerOptions, ParserOptions {}
export interface HTMLParser2Options
extends DomHandlerOptions,
HTMLParser2ParserOptions {}

/** Options for parse5, the default parser for HTML. */
export interface Parse5Options {
/** Disable scripting in parse5, so noscript tags would be parsed. */
scriptingEnabled?: boolean;
/** Enable location support for parse5. */
sourceCodeLocationInfo?: boolean;
}
export type Parse5Options = Parse5ParserOptions<Htmlparser2TreeAdapterMap>;

/**
* Options accepted by Cheerio.
Expand Down
12 changes: 5 additions & 7 deletions src/static.ts
Expand Up @@ -244,10 +244,7 @@ export function extract<M extends ExtractMap>(
return this.root().extract(map);
}

interface WritableArrayLike<T> extends ArrayLike<T> {
length: number;
[n: number]: T;
}
type Writable<T> = { -readonly [P in keyof T]: T[P] };

/**
* $.merge().
Expand All @@ -259,7 +256,7 @@ interface WritableArrayLike<T> extends ArrayLike<T> {
* @see {@link https://api.jquery.com/jQuery.merge/}
*/
export function merge<T>(
arr1: WritableArrayLike<T>,
arr1: Writable<ArrayLike<T>>,
arr2: ArrayLike<T>
): ArrayLike<T> | undefined {
if (!isArrayLike(arr1) || !isArrayLike(arr2)) {
Expand All @@ -281,14 +278,15 @@ export function merge<T>(
* @param item - Item to check.
* @returns Indicates if the item is array-like.
*/
function isArrayLike(item: any): item is ArrayLike<unknown> {
function isArrayLike(item: unknown): item is ArrayLike<unknown> {
if (Array.isArray(item)) {
return true;
}

if (
typeof item !== 'object' ||
!Object.prototype.hasOwnProperty.call(item, 'length') ||
item === null ||
!('length' in item) ||
typeof item.length !== 'number' ||
item.length < 0
) {
Expand Down
23 changes: 23 additions & 0 deletions typedoc.json
@@ -0,0 +1,23 @@
{
"hideGenerator": true,
"externalSymbolLinkMappings": {
"typescript": {
"Promise": "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise",
"URL": "https://developer.mozilla.org/en-US/docs/Web/API/URL"
},
"domhandler": {
"Document": "https://domhandler.js.org/classes/Document.html",
"Element": "https://domhandler.js.org/classes/Element.html",
"Node": "https://domhandler.js.org/classes/Node.html",

"AnyNode": "https://domhandler.js.org/types/AnyNode.html",
"ChildNode": "https://domhandler.js.org/types/ChildNode.html",
"ParentNode": "https://domhandler.js.org/types/ParentNode.html",

"DomHandlerOptions": "https://domhandler.js.org/interfaces/DomHandlerOptions.html"
},
"parse5": {
"ParserOptions": "https://parse5.js.org/interfaces/parse5.ParserOptions.html"
}
}
}

0 comments on commit fa00a9d

Please sign in to comment.