-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from marcomontalbano/update-dependencies
Update npm dependencies
- Loading branch information
Showing
8 changed files
with
1,183 additions
and
1,709 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -6,6 +6,7 @@ node_js: | |
- "11" | ||
- "12" | ||
- "13" | ||
- "14" | ||
|
||
script: | ||
- npm test | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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,4 +1,3 @@ | ||
|
||
const path = require('path'); | ||
const fs = require('fs'); | ||
const htmlMiner = require('../lib'); | ||
|
This file contains 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,4 +1,3 @@ | ||
|
||
const url = require('url'); | ||
const https = require('https'); | ||
const htmlMiner = require('../lib'); | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
const chai = require('chai'); | ||
|
||
const { assert } = chai; | ||
|
||
const htmlMiner = require('../lib'); | ||
|
||
describe('htmlMiner • EXAMPLE.md', () => { | ||
it('Get text and href from a list of <a>', () => { | ||
const html = ` | ||
<div> | ||
<a class="link-class" href="https://example.com/1">Link 1</a> | ||
<a class="link-class" href="https://example.com/2">Link 2</a> | ||
</div> | ||
`; | ||
|
||
const actual = htmlMiner(html, { | ||
_each_: '.link-class', | ||
text: (arg) => arg.$scope.text(), | ||
href: (arg) => arg.$scope.attr('href'), | ||
}); | ||
|
||
assert.deepEqual(actual, [ | ||
{ | ||
text: 'Link 1', | ||
href: 'https://example.com/1', | ||
}, | ||
{ | ||
text: 'Link 2', | ||
href: 'https://example.com/2', | ||
}, | ||
]); | ||
}); | ||
|
||
describe('Get src and alt from <img>', () => { | ||
const html = ` | ||
<img src="/image-1.jpg" alt="Image 1" /> | ||
<img src="/image-2.jpg" alt="Image 2" /> | ||
`; | ||
|
||
const doAssert = (actual) => { | ||
assert.deepEqual(actual, [ | ||
{ | ||
src: '/image-1.jpg', | ||
alt: 'Image 1', | ||
}, | ||
{ | ||
src: '/image-2.jpg', | ||
alt: 'Image 2', | ||
}, | ||
]); | ||
}; | ||
|
||
it('Selector as function', () => { | ||
const actual = htmlMiner(html, (arg) => { | ||
const $images = Array.from(arg.$('img')); | ||
return $images.map((img) => { | ||
const $currentImage = arg.$(img); | ||
return { | ||
src: $currentImage.attr('src'), | ||
alt: $currentImage.attr('alt'), | ||
}; | ||
}); | ||
}); | ||
|
||
doAssert(actual); | ||
}); | ||
|
||
it('Simpler way', () => { | ||
const actual = htmlMiner(html, { | ||
_each_: 'img', | ||
src: (arg) => arg.$scope.attr('src'), | ||
alt: (arg) => arg.$scope.attr('alt'), | ||
}); | ||
|
||
doAssert(actual); | ||
}); | ||
}); | ||
}); |
This file contains 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