An open API service indexing awesome lists of open source software.

https://github.com/movableink/data-sources-parser

A library for normalizing the links and urls in a fetched html resource
https://github.com/movableink/data-sources-parser

Last synced: 2 months ago
JSON representation

A library for normalizing the links and urls in a fetched html resource

Awesome Lists containing this project

README

        

# Movable Ink: Data Sources Parser

This library contains a library for parsing Data Sources responses in a consistent way.

## HTMLNormalizer

This class takes an HTML string and the URL of the HTML in its constructor. For example:

```js
import { HTMLNormalizer } from 'data-sources-parser';

new HTMLNormalizer(`


Hello, world!




`, 'https://www.movableink.com');
```

### normalizer.document

This provides the created [document](https://developer.mozilla.org/en-US/docs/Web/API/Document) object.

```js
import { HTMLNormalizer } from 'data-sources-parser';
const { document } = new HTMLNormalizer('...', 'https://www.movableink.com');

const header = document.querySelector('h1');
```

### normalizer.baseURL

This provides the base URL of the page, taking into account any `` tag and the provided URL:

```js
import { HTMLNormalizer } from 'data-sources-parser';
const { baseURL } = new HTMLNormalizer('', 'https://www.movableink.com');

console.log(baseURL); // https://www.movableink.com/home/
```

### normalizers.absolutizePath

This takes a path (likely from an `href` or `src`) and converts it into its fully qualified URL, taking into account the URL and `` tags of the page.

```js
import { HTMLNormalizer } from 'data-sources-parser';
const normalizer = new HTMLNormalizer('', 'https://www.movableink.com');

const logoURL = normalizer.absolutizePath('images/logo.png');
console.log(logoURL); // https://www.movableink.com/home/images/logo.png
```

## Releases

To release a change, run the release command.

(This uses [release-it](https://github.com/webpro/release-it) for managing the releases).

```sh
yarn run release
```

By default, this will be a patch release. If you wish to release a different change:

```sh
yarn run release patch;
yarn run release minor;
yarn run release major;
yarn run release 2.8.3;
```