Skip to content

Commit

Permalink
Merge branch 'rollup'
Browse files Browse the repository at this point in the history
# Conflicts:
#	package-lock.json
#	package.json
  • Loading branch information
GuillaumeNury committed Jan 25, 2022
2 parents f950a05 + e29fbf5 commit 405ba8b
Show file tree
Hide file tree
Showing 45 changed files with 12,361 additions and 6,188 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
@@ -0,0 +1,12 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
indent_style = tab
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = false
1 change: 1 addition & 0 deletions .gitignore
@@ -1,4 +1,5 @@
dist
browser
node_modules
yarn.lock
coverage
Expand Down
9 changes: 0 additions & 9 deletions .npmignore

This file was deleted.

12 changes: 7 additions & 5 deletions .travis.yml
@@ -1,21 +1,23 @@
language: node_js
node_js:
- "8"
- "14"

install:
- yarn global add codecov
- npm install --global codecov

before_script:
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
- chmod +x ./cc-test-reporter
- ./cc-test-reporter before-build

script:
- yarn
- yarn test
- npm ci
- npm test

after_script:
- codecov
- ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT

cache: yarn
cache:
directories:
- node_modules
81 changes: 57 additions & 24 deletions README.md
Expand Up @@ -20,7 +20,7 @@ EbriScrap is a tool that parse a HTML string, and return a JS object with all in

## Examples

Go to [Examples](./examples) to see EbriScrap in action.
Go to [Examples](./tests/cases) to see EbriScrap in action.

## Documentation

Expand Down Expand Up @@ -128,7 +128,7 @@ It should be a valid [Cheerio](https://github.com/cheeriojs/cheerio) / CSS selec

/* WARNING: as https://one-fake-domain.com contains colons, quotes (single or double) are mandatory ! */
const config =
"a | extract:prop:href | format:url:'https://one-fake-domain.com'";
"a | extract:prop:href | format:url:'https://one-fake-domain.com'";

parse(html, config); // Output: "https://one-fake-domain.com/unicorn-world"
```
Expand All @@ -146,14 +146,14 @@ Example:

```javascript
const html = `
<section>
<h1>What a wonderful world</h1>
<p>Lorem Ipsum...</p>
</section>`;
<section>
<h1>What a wonderful world</h1>
<p>Lorem Ipsum...</p>
</section>`;

const config = {
title: 'h1',
content: 'p',
title: 'h1',
content: 'p',
};

parse(html, config); // Output: { title: 'What a wonderful world': content: 'Lorem Ipsum...' }
Expand All @@ -166,34 +166,67 @@ Array configuration are a bit more complicated. It is an array, with a single it
- `containerSelector`: the selector of the container (It should be a valid [Cheerio](https://github.com/cheeriojs/cheerio) / CSS selector.)
- `itemSelector`: the selector on which you want to iterate (It should be a valid [Cheerio](https://github.com/cheeriojs/cheerio) / CSS selector.)
- `data`: a Field/Group/Array configuration
- `includeSiblings`: _optional_ include siblings of selected item (see example below)

Example:

```javascript
const html = `
<ul>
<li>
<p>Content 1</p>
</li>
<li>
<p>Content 2</p>
</li>
<li>
<p>Content 3</p>
</li>
</ul>`;
<ul>
<li>
<p>Content 1</p>
</li>
<li>
<p>Content 2</p>
</li>
<li>
<p>Content 3</p>
</li>
</ul>`;

const config = [
{
containerSelector: 'ul',
itemSelector: 'li',
data: 'p',
},
{
containerSelector: 'ul',
itemSelector: 'li',
data: 'p',
},
];

parse(html, config); // Output: ['Content 1', 'Content 2', 'Content 3']
```

```javascript
const html = `<body>
<h1>Title 1</h1>
<p>Text 1.1</p>
<p>Text 1.2</p>
<p>Text 1.3</p>
<h1>Title 2</h1>
<p>Text 2.1</p>
<p>Text 2.2</p>
<p>Text 2.3</p>
</body>`;

const config = [
{
containerSelector: 'section',
itemSelector: 'h1',
includeSiblings: true,
data: {
title: 'h1',
text: 'p'
},
},
];

parse(html, config);
/* Output: [
{ title: 'Title 1', text: 'Text 1.1Text 1.2Text 1.3' },
{ title: 'Title 2', text: 'Text 2.1Text 2.2Text 2.3' },
] */
```

### Walkthrough example

Say we have the following HTML:
Expand Down
47 changes: 0 additions & 47 deletions examples/github.ts

This file was deleted.

76 changes: 0 additions & 76 deletions examples/wikipedia.ts

This file was deleted.

4 changes: 0 additions & 4 deletions index.ts

This file was deleted.

8 changes: 8 additions & 0 deletions jest.config.js
@@ -0,0 +1,8 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testPathIgnorePatterns: ['examples', 'dist'],
collectCoverage: true,
coverageDirectory: './coverage/',
collectCoverageFrom: ['src/**/*.ts', '!src/**/index.ts'],
};

0 comments on commit 405ba8b

Please sign in to comment.