This package has been deprecated

Author message:

This package has been moved to @w0s/closest-html-page

@saekitominaga/closest-html-page
TypeScript icon, indicating that this package has built-in type declarations

2.0.2 • Public • Published

Get the data of the HTML page of the nearest ancestor hierarchy

npm version test status

Demo

Examples

import ClosestHTMLPage from '@saekitominaga/closest-html-page';

const closestHTMLPage = new ClosestHTMLPage({
  maxFetchCount: 3,
  fetchOptions: {
    redirect: 'error',
  },
  mimeTypes: ['text/html'],
});

await closestHTMLPage.fetch('https://example.com/path/to/file');

const url = closestHTMLPage.getUrl();
const title = closestHTMLPage.getTitle();

Constructor

new ClosestHTMLPage(options?: Option)

Parameters

options [Optional]
Options for accessing web content.

Option

interface Option {
  maxFetchCount?: number;
  fetchOptions?: RequestInit;
  mimeTypes?: DOMParserSupportedType[];
}
maxFetchCount
If no HTML page matching the condition can be retrieved after this number of attempts to access the ancestor hierarchy, the process is rounded up (0 = ∞). The default value is 0.
fetchOptions
An object containing any custom settings that you want to apply to the reques. Same as the second argument of the `fetch()` method.
mimeTypes
MIME types of the HTML resource to retrieve. The values that can be specified are limited to DOMParserSupportedType types, namely 'text/html', 'text/xml', 'application/xml', 'application/xhtml+xml', and 'image/svg+xml'. The default value is ['text/html', 'application/xhtml+xml'].

Methods

async fetch(baseUrl: string = location.toString()): Promise<void>
Traverse the ancestor hierarchy in order from the base URL and retrieve the data of resources that match the specified condition (MIME types). This method must be called before executing the following getXXX().
getFetchedResponses(): Set<Response>
Get the Response data resulting from the execution of fetch().
getUrl(): string | null
Get the URL of the HTML page of the nearest ancestor hierarchy.
getTitle(): string | null
Get the title of the HTML page of the nearest ancestor hierarchy.

Readme

Keywords

none

Package Sidebar

Install

npm i @saekitominaga/closest-html-page

Weekly Downloads

1

Version

2.0.2

License

MIT

Unpacked Size

48.1 kB

Total Files

7

Last publish

Collaborators

  • saekitominaga