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
- Host: GitHub
- URL: https://github.com/movableink/data-sources-parser
- Owner: movableink
- Created: 2018-01-26T20:32:28.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2025-03-06T23:15:48.000Z (3 months ago)
- Last Synced: 2025-03-07T00:24:05.845Z (3 months ago)
- Language: JavaScript
- Size: 136 KB
- Stars: 0
- Watchers: 37
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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;
```