Comparing version 1.2.1 to 1.3.0
@@ -0,0 +0,0 @@ # Changelog |
@@ -12,3 +12,3 @@ /// <reference types="cheerio" /> | ||
}; | ||
export declare const ifResolve: <T extends import("../selectors/attr").Attr<any> | import("../selectors/exists").Exists<any> | import("../selectors/html").Html<any> | import("../selectors/text").Text<any> | import("../selectors/count").Count<any> | import("../selectors/link").Link<any> | Query | import("./list").List<any> | import("../selectors/select").Select<any> | If<any, any, any, any>, F extends import("../selectors/attr").Attr<any> | import("../selectors/exists").Exists<any> | import("../selectors/html").Html<any> | import("../selectors/text").Text<any> | import("../selectors/count").Count<any> | import("../selectors/link").Link<any> | Query | import("./list").List<any> | import("../selectors/select").Select<any> | If<any, any, any, any>>($: CheerioStatic, context: Cheerio, queryType: If<T, F, TypeOf<T>, TypeOf<F>>, scrapQuery: ScrapQuery, ScrapSelector: ScrapSelector) => any; | ||
export declare const ifResolve: <T extends Query | import("../selectors/attr").Attr<any> | import("../selectors/exists").Exists<any> | import("../selectors/html").Html<any> | import("./list").List<any> | import("../selectors/select").Select<any> | If<any, any, any, any> | import("../selectors/text").Text<any> | import("../selectors/count").Count<any> | import("../selectors/link").Link<any>, F extends Query | import("../selectors/attr").Attr<any> | import("../selectors/exists").Exists<any> | import("../selectors/html").Html<any> | import("./list").List<any> | import("../selectors/select").Select<any> | If<any, any, any, any> | import("../selectors/text").Text<any> | import("../selectors/count").Count<any> | import("../selectors/link").Link<any>>($: CheerioStatic, context: Cheerio, queryType: If<T, F, TypeOf<T>, TypeOf<F>>, scrapQuery: ScrapQuery, ScrapSelector: ScrapSelector) => any; | ||
/** | ||
@@ -19,2 +19,2 @@ * Get list of items | ||
*/ | ||
export declare const ifCreator: <T extends import("../selectors/attr").Attr<any> | import("../selectors/exists").Exists<any> | import("../selectors/html").Html<any> | import("../selectors/text").Text<any> | import("../selectors/count").Count<any> | import("../selectors/link").Link<any> | Query | import("./list").List<any> | import("../selectors/select").Select<any> | If<any, any, any, any>, F extends import("../selectors/attr").Attr<any> | import("../selectors/exists").Exists<any> | import("../selectors/html").Html<any> | import("../selectors/text").Text<any> | import("../selectors/count").Count<any> | import("../selectors/link").Link<any> | Query | import("./list").List<any> | import("../selectors/select").Select<any> | If<any, any, any, any>>(selector: string, condition: (el: Cheerio) => boolean, truthy: T, falsey: F) => If<T, F, TypeOf<T>, TypeOf<F>>; | ||
export declare const ifCreator: <T extends Query | import("../selectors/attr").Attr<any> | import("../selectors/exists").Exists<any> | import("../selectors/html").Html<any> | import("./list").List<any> | import("../selectors/select").Select<any> | If<any, any, any, any> | import("../selectors/text").Text<any> | import("../selectors/count").Count<any> | import("../selectors/link").Link<any>, F extends Query | import("../selectors/attr").Attr<any> | import("../selectors/exists").Exists<any> | import("../selectors/html").Html<any> | import("./list").List<any> | import("../selectors/select").Select<any> | If<any, any, any, any> | import("../selectors/text").Text<any> | import("../selectors/count").Count<any> | import("../selectors/link").Link<any>>(selector: string, condition: (el: Cheerio) => boolean, truthy: T, falsey: F) => If<T, F, TypeOf<T>, TypeOf<F>>; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -18,2 +18,2 @@ /// <reference types="cheerio" /> | ||
*/ | ||
export declare const listCreator: <Q extends import("../selectors/attr").Attr<any> | import("../selectors/exists").Exists<any> | import("../selectors/html").Html<any> | import("../selectors/text").Text<any> | import("../selectors/count").Count<any> | import("../selectors/link").Link<any> | Query | List<any> | import("../selectors/select").Select<any> | import("./if").If<any, any, any, any>>(selector: string, data: Q, predicate?: ((el: Cheerio, index: number) => boolean) | undefined) => List<Q extends Query ? TypeOfQuery<Q> : Q extends Selector ? TypeOfSelector<Q> : never>; | ||
export declare const listCreator: <Q extends Query | import("../selectors/attr").Attr<any> | import("../selectors/exists").Exists<any> | import("../selectors/html").Html<any> | List<any> | import("../selectors/select").Select<any> | import("./if").If<any, any, any, any> | import("../selectors/text").Text<any> | import("../selectors/count").Count<any> | import("../selectors/link").Link<any>>(selector: string, data: Q, predicate?: ((el: Cheerio, index: number) => boolean) | undefined) => List<Q extends Query ? TypeOfQuery<Q> : Q extends Selector ? TypeOfSelector<Q> : never>; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -20,8 +20,8 @@ /// <reference types="cheerio" /> | ||
import { linkCreator as link } from "./selectors/link"; | ||
export declare const Q: { | ||
If: <T extends import("./selectors/attr").Attr<any> | import("./selectors/exists").Exists<any> | import("./selectors/html").Html<any> | import("./selectors/text").Text<any> | import("./selectors/count").Count<any> | import("./selectors/link").Link<any> | Query | import("./controls/list").List<any> | import("./selectors/select").Select<any> | import("./controls/if").If<any, any, any, any>, F extends import("./selectors/attr").Attr<any> | import("./selectors/exists").Exists<any> | import("./selectors/html").Html<any> | import("./selectors/text").Text<any> | import("./selectors/count").Count<any> | import("./selectors/link").Link<any> | Query | import("./controls/list").List<any> | import("./selectors/select").Select<any> | import("./controls/if").If<any, any, any, any>>(selector: string, condition: (el: Cheerio) => boolean, truthy: T, falsey: F) => import("./controls/if").If<T, F, import("./types").TypeOf<T>, import("./types").TypeOf<F>>; | ||
export declare const $: { | ||
if: <T extends Query | import("./selectors/attr").Attr<any> | import("./selectors/exists").Exists<any> | import("./selectors/html").Html<any> | import("./controls/list").List<any> | import("./selectors/select").Select<any> | import("./controls/if").If<any, any, any, any> | import("./selectors/text").Text<any> | import("./selectors/count").Count<any> | import("./selectors/link").Link<any>, F extends Query | import("./selectors/attr").Attr<any> | import("./selectors/exists").Exists<any> | import("./selectors/html").Html<any> | import("./controls/list").List<any> | import("./selectors/select").Select<any> | import("./controls/if").If<any, any, any, any> | import("./selectors/text").Text<any> | import("./selectors/count").Count<any> | import("./selectors/link").Link<any>>(selector: string, condition: (el: Cheerio) => boolean, truthy: T, falsey: F) => import("./controls/if").If<T, F, import("./types").TypeOf<T>, import("./types").TypeOf<F>>; | ||
list: <Q extends Query | import("./selectors/attr").Attr<any> | import("./selectors/exists").Exists<any> | import("./selectors/html").Html<any> | import("./controls/list").List<any> | import("./selectors/select").Select<any> | import("./controls/if").If<any, any, any, any> | import("./selectors/text").Text<any> | import("./selectors/count").Count<any> | import("./selectors/link").Link<any>>(selector: string, data: Q, predicate?: ((el: Cheerio, index: number) => boolean) | undefined) => import("./controls/list").List<Q extends Query ? TypeOfQuery<Q> : Q extends Selector ? TypeOfSelector<Q> : never>; | ||
attr: typeof attr; | ||
exists: typeof exists; | ||
html: typeof html; | ||
List: <Q extends import("./selectors/attr").Attr<any> | import("./selectors/exists").Exists<any> | import("./selectors/html").Html<any> | import("./selectors/text").Text<any> | import("./selectors/count").Count<any> | import("./selectors/link").Link<any> | Query | import("./controls/list").List<any> | import("./selectors/select").Select<any> | import("./controls/if").If<any, any, any, any>>(selector: string, data: Q, predicate?: ((el: Cheerio, index: number) => boolean) | undefined) => import("./controls/list").List<Q extends Query ? TypeOfQuery<Q> : Q extends Selector ? TypeOfSelector<Q> : never>; | ||
text: typeof text; | ||
@@ -28,0 +28,0 @@ select: typeof select; |
@@ -34,8 +34,8 @@ "use strict"; | ||
var if_2 = require("./controls/if"); | ||
exports.Q = { | ||
If: if_2.ifCreator, | ||
exports.$ = { | ||
if: if_2.ifCreator, | ||
list: list_2.listCreator, | ||
attr: attr_2.attrCreator, | ||
exists: exists_2.existsCreator, | ||
html: html_2.htmlCreator, | ||
List: list_2.listCreator, | ||
text: text_2.textCreator, | ||
@@ -42,0 +42,0 @@ select: select_2.selectCreator, |
@@ -0,0 +0,0 @@ /// <reference types="cheerio" /> |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ /// <reference types="cheerio" /> |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ /// <reference types="cheerio" /> |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ /// <reference types="cheerio" /> |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ /// <reference types="cheerio" /> |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ /// <reference types="cheerio" /> |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ /// <reference types="cheerio" /> |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ /// <reference types="cheerio" /> |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { Attr } from './selectors/attr'; |
@@ -0,0 +0,0 @@ "use strict"; |
@@ -0,0 +0,0 @@ import { Query, Selector, TypeOf, isSelector } from "../types"; |
export { listCreator as List } from "./list"; | ||
export { ifCreator as If } from "./if"; |
@@ -0,0 +0,0 @@ import { |
@@ -28,8 +28,8 @@ export { Query, Selector, TypeOfSelector, TypeOfQuery } from './types'; | ||
export const Q = { | ||
If, | ||
export const $ = { | ||
if: If, | ||
list: List, | ||
attr, | ||
exists, | ||
html, | ||
List, | ||
text, | ||
@@ -40,2 +40,1 @@ select, | ||
}; | ||
@@ -0,0 +0,0 @@ import { load } from "cheerio"; |
@@ -0,0 +0,0 @@ export type Attr<F extends (attribute: string) => any> = { |
@@ -0,0 +0,0 @@ export type Count<F extends (count: number) => any> = { |
@@ -0,0 +0,0 @@ export type Exists<F extends (exists: boolean) => any> = { |
@@ -0,0 +0,0 @@ export type Html<F extends (html: string) => any> = { |
@@ -0,0 +0,0 @@ export { attrCreator as attr } from "./attr"; |
@@ -0,0 +0,0 @@ export type Link<F extends (link: string) => any> = { |
@@ -0,0 +0,0 @@ export type Select<F extends (el: Cheerio) => any> = { |
@@ -0,0 +0,0 @@ export type Text<F extends (text: string) => any> = { |
@@ -0,0 +0,0 @@ import { Attr } from './selectors/attr'; |
{ | ||
"name": "scrapq", | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"description": "Lightweight Typescript library for scrapping html", | ||
@@ -11,3 +11,5 @@ "main": "./dist/index.js", | ||
"test:exhaustive": "jasmine-ts ./test/**/*.ts", | ||
"dist": "npm run test; npm run build; npm run build:web", | ||
"build": "tsc", | ||
"build:web": "webpack --mode=production", | ||
"prettify": "npm run prettify:src; npm run prettify:test", | ||
@@ -34,3 +36,6 @@ "prettify:src": "prettier --write ./lib/**/*.ts", | ||
"prettier": "^1.13.7", | ||
"typescript": "^3.0.3" | ||
"ts-loader": "^5.3.3", | ||
"typescript": "^3.0.3", | ||
"webpack": "^4.29.0", | ||
"webpack-cli": "^3.2.1" | ||
}, | ||
@@ -37,0 +42,0 @@ "dependencies": { |
@@ -24,3 +24,3 @@ # ScrapQ | ||
```typescript | ||
import { scrap, Q } from 'scrapq'; | ||
import { scrap, $ } from 'scrapq'; | ||
@@ -31,6 +31,6 @@ // `fetch` is not included in library, use your own implementation | ||
const data = scrap(html, { | ||
articles: Q.List('.athing', { | ||
title: Q.text('.title > a'), | ||
website: Q.text('.title > span.sitebit'), | ||
link: Q.attr('.title > a', 'href') | ||
articles: $.list('.athing', { // for every '.athing' selected element in document | ||
title: $.text('.title > a'), // get text from '.title > a' | ||
link: $.link('.title > a'), // get link (href attr) from '.title > a' | ||
website: $.text('.title > span.sitebit'), // get text | ||
}); | ||
@@ -56,3 +56,3 @@ }); | ||
```typescript | ||
import { scrap, Q } from 'scrapq'; | ||
import { scrap, $ } from 'scrapq'; | ||
@@ -70,7 +70,7 @@ const STR_TO_SCRAP = ` | ||
const result = scrap(STR_TO_SCRAP, { | ||
title: Q.text('h1.title'), | ||
items: Q.List('ul>li', { | ||
text: Q.text('span') | ||
title: $.text('h1.title'), | ||
items: $.list('ul>li', { | ||
text: $.text('span') | ||
}), | ||
link: Q.link('a.link') | ||
link: $.link('a.link') | ||
}); | ||
@@ -77,0 +77,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { scrap, Q } from '../lib'; | ||
import { scrap, $ } from '../lib'; | ||
@@ -17,3 +17,3 @@ const STR_TO_SCRAP = ` | ||
const result = scrap(STR_TO_SCRAP, { | ||
title: Q.text('h1.title') | ||
title: $.text('h1.title') | ||
}); | ||
@@ -25,3 +25,3 @@ expect(result).toEqual({ title: 'Hello'}); | ||
const result = scrap(STR_TO_SCRAP, { | ||
title: Q.attr('h1.title', 'class') | ||
title: $.attr('h1.title', 'class') | ||
}); | ||
@@ -33,4 +33,4 @@ expect(result).toEqual({ title: 'title'}); | ||
const result = scrap(STR_TO_SCRAP, { | ||
items: Q.List('li', { | ||
text: Q.text('span') | ||
items: $.list('li', { | ||
text: $.text('span') | ||
}) | ||
@@ -44,3 +44,3 @@ }); | ||
const result = scrap(STR_TO_SCRAP, { | ||
hasTitle: Q.exists('h1.title') | ||
hasTitle: $.exists('h1.title') | ||
}); | ||
@@ -52,3 +52,3 @@ expect(result.hasTitle).toBe(true); | ||
const result = scrap(STR_TO_SCRAP, { | ||
hasCastle: Q.exists('.castle') | ||
hasCastle: $.exists('.castle') | ||
}); | ||
@@ -60,4 +60,4 @@ expect(result.hasCastle).toBe(false); | ||
const result = scrap(STR_TO_SCRAP, { | ||
items: Q.List('li', { | ||
hasMsg: Q.exists('span.msg') | ||
items: $.list('li', { | ||
hasMsg: $.exists('span.msg') | ||
}) | ||
@@ -73,4 +73,4 @@ }); | ||
const result = scrap(STR_TO_SCRAP, { | ||
items: Q.List('li', { | ||
text: Q.text('span') | ||
items: $.list('li', { | ||
text: $.text('span') | ||
}) | ||
@@ -84,4 +84,4 @@ }); | ||
const result = scrap(STR_TO_SCRAP, { | ||
items: Q.List('span', { | ||
text: Q.text('') | ||
items: $.list('span', { | ||
text: $.text('') | ||
}) | ||
@@ -95,3 +95,3 @@ }); | ||
const result = scrap(STR_TO_SCRAP, { | ||
title: Q.select('h1', (el) => el.text()) | ||
title: $.select('h1', (el) => el.text()) | ||
}); | ||
@@ -103,3 +103,3 @@ expect(result.title).toBe('Hello'); | ||
const result = scrap(STR_TO_SCRAP, { | ||
texts: Q.List('li', Q.text('span')) | ||
texts: $.list('li', $.text('span')) | ||
}); | ||
@@ -115,5 +115,5 @@ expect(result.texts).toEqual([ | ||
const result = scrap(STR_TO_SCRAP, { | ||
title: Q.text('.title'), | ||
title: $.text('.title'), | ||
data: { | ||
msg: Q.text('.msg') | ||
msg: $.text('.msg') | ||
} | ||
@@ -127,3 +127,3 @@ }); | ||
const result = scrap(STR_TO_SCRAP, { | ||
spanCount: Q.count('span') | ||
spanCount: $.count('span') | ||
}); | ||
@@ -135,3 +135,3 @@ expect(result.spanCount).toBe(3); | ||
const result = scrap(STR_TO_SCRAP, { | ||
spanCount: Q.count('table') | ||
spanCount: $.count('table') | ||
}); | ||
@@ -143,3 +143,3 @@ expect(result.spanCount).toBe(0); | ||
const result = scrap(STR_TO_SCRAP, { | ||
link: Q.link('a') | ||
link: $.link('a') | ||
}); | ||
@@ -151,3 +151,3 @@ expect(result.link).toBe('/read-more'); | ||
const result = scrap(STR_TO_SCRAP, { | ||
link: Q.link('tr') | ||
link: $.link('tr') | ||
}); | ||
@@ -159,4 +159,4 @@ expect(result.link).toBeUndefined(); | ||
const result = scrap(STR_TO_SCRAP, { | ||
items: Q.List('span', { | ||
msg: Q.text('') | ||
items: $.list('span', { | ||
msg: $.text('') | ||
}, (el) => el.hasClass('msg')) | ||
@@ -168,3 +168,3 @@ }); | ||
it('should use only selector to scrap title', () => { | ||
const title = scrap(STR_TO_SCRAP, Q.text('.title')); | ||
const title = scrap(STR_TO_SCRAP, $.text('.title')); | ||
expect(title).toBe('Hello'); | ||
@@ -174,3 +174,3 @@ }); | ||
it('should use only selector to scrap <span/>', () => { | ||
const spans = scrap(STR_TO_SCRAP, Q.List('span', Q.text(''))); | ||
const spans = scrap(STR_TO_SCRAP, $.list('span', $.text(''))); | ||
expect(spans.length).toBe(3); | ||
@@ -181,3 +181,3 @@ expect(spans[0]).toBe('Guten Tag'); | ||
it('should use truthy condition', () => { | ||
const result = scrap(STR_TO_SCRAP, Q.If('.title', (el) => !!el, Q.text('.title'), Q.text('.msg'))); | ||
const result = scrap(STR_TO_SCRAP, $.if('.title', (el) => !!el, $.text('.title'), $.text('.msg'))); | ||
expect(result).toBe('Hello'); | ||
@@ -187,3 +187,3 @@ }); | ||
it('should use falsey condition', () => { | ||
const result = scrap(STR_TO_SCRAP, Q.If('.notexisting', (el) => !el, Q.text('.title'), { msg: Q.text('.msg') })); | ||
const result = scrap(STR_TO_SCRAP, $.if('.notexisting', (el) => !el, $.text('.title'), { msg: $.text('.msg') })); | ||
expect(result).toEqual({ msg: 'Ciao' }); | ||
@@ -190,0 +190,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
import { scrap, Q } from "../../lib"; | ||
import { scrap, $ } from "../../lib"; | ||
import { html } from "../data"; | ||
@@ -8,3 +8,3 @@ | ||
html, | ||
Q.If(".title", el => !!el, Q.text(".title"), Q.text(".msg")) | ||
$.if(".title", el => !!el, $.text(".title"), $.text(".msg")) | ||
); | ||
@@ -17,3 +17,3 @@ expect(result).toBe("Hello"); | ||
html, | ||
Q.If(".notexisting", el => !el, Q.text(".title"), { msg: Q.text(".msg") }) | ||
$.if(".notexisting", el => !el, $.text(".title"), { msg: $.text(".msg") }) | ||
); | ||
@@ -26,7 +26,7 @@ expect(result).toEqual({ msg: "Ciao" }); | ||
html, | ||
Q.If( | ||
$.if( | ||
".title", | ||
el => !!el, | ||
Q.text(".title", text => text.length), | ||
Q.text(".msg") | ||
$.text(".title", text => text.length), | ||
$.text(".msg") | ||
) | ||
@@ -33,0 +33,0 @@ ); |
@@ -1,2 +0,2 @@ | ||
import { scrap, Q } from "../../lib"; | ||
import { scrap, $ } from "../../lib"; | ||
import { html } from "../data"; | ||
@@ -6,3 +6,3 @@ | ||
it("should scrap items from <span/>", () => { | ||
const spans = scrap(html, Q.List("span", Q.text(""))); | ||
const spans = scrap(html, $.list("span", $.text(""))); | ||
expect(spans.length).toBe(3); | ||
@@ -14,4 +14,4 @@ expect(spans[0]).toBe("Guten Tag"); | ||
const result = scrap(html, { | ||
items: Q.List("li", { | ||
text: Q.text("span") | ||
items: $.list("li", { | ||
text: $.text("span") | ||
}) | ||
@@ -26,3 +26,3 @@ }); | ||
html, | ||
Q.List("span", Q.text(""), el => el.hasClass("msg")) | ||
$.list("span", $.text(""), el => el.hasClass("msg")) | ||
); | ||
@@ -29,0 +29,0 @@ expect(result.length).toBe(1); |
@@ -0,0 +0,0 @@ export const html = ` |
import { readFileSync } from "fs"; | ||
import { scrap, List, text, link, html } from "../../lib"; | ||
import { scrap, $ } from "../../lib"; | ||
@@ -9,12 +9,12 @@ const shtml = readFileSync("./test/exhaustive/agescx.html").toString(); | ||
const result = scrap(shtml, { | ||
navs: List("ul.navbar-nav>li:not(.disabled)", { | ||
text: text("li > a"), | ||
link: link("li > a"), | ||
submenu: List("ul.dropdown-menu>li", { | ||
text: text("li > a"), | ||
link: link("li > a") | ||
navs: $.list("ul.navbar-nav>li:not(.disabled)", { | ||
text: $.text("li > a"), | ||
link: $.link("li > a"), | ||
submenu: $.list("ul.dropdown-menu>li", { | ||
text: $.text("li > a"), | ||
link: $.link("li > a") | ||
}) | ||
}), | ||
title: text("h1"), | ||
content: html('div[role="main"]') | ||
title: $.text("h1"), | ||
content: $.html('div[role="main"]') | ||
}); | ||
@@ -21,0 +21,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { scrap, Q } from "../../lib"; | ||
import { scrap, $ } from "../../lib"; | ||
import { html } from "../data"; | ||
@@ -6,3 +6,3 @@ | ||
it("should scrap href attr from an <a/>", () => { | ||
const result = scrap(html, Q.attr("a", "href")); | ||
const result = scrap(html, $.attr("a", "href")); | ||
expect(result).toBe("/read-more"); | ||
@@ -12,3 +12,3 @@ }); | ||
it("should scrap href attr from an <a/> and split it by -", () => { | ||
const result = scrap(html, Q.attr("a", "href", attr => attr.split("-"))); | ||
const result = scrap(html, $.attr("a", "href", attr => attr.split("-"))); | ||
expect(result).toEqual(["/read", "more"]); | ||
@@ -18,3 +18,3 @@ }); | ||
it("should scrap data-extra from <div/>", () => { | ||
const result = scrap(html, Q.attr(".footer", "data-extra")); | ||
const result = scrap(html, $.attr(".footer", "data-extra")); | ||
expect(result).toBe("footer"); | ||
@@ -25,3 +25,3 @@ }); | ||
const result = scrap(html, { | ||
footer: Q.attr(".footer", "data-extra") | ||
footer: $.attr(".footer", "data-extra") | ||
}); | ||
@@ -28,0 +28,0 @@ expect(result.footer).toBe("footer"); |
@@ -1,2 +0,2 @@ | ||
import { scrap, Q } from "../../lib"; | ||
import { scrap, $ } from "../../lib"; | ||
import { html } from "../data"; | ||
@@ -6,3 +6,3 @@ | ||
it("should count <li/> elements", () => { | ||
const result = scrap(html, Q.count("li")); | ||
const result = scrap(html, $.count("li")); | ||
expect(result).toBe(3); | ||
@@ -12,3 +12,3 @@ }); | ||
it("should count <li/> elements and convert it to string", () => { | ||
const result = scrap(html, Q.count("li", count => count.toString())); | ||
const result = scrap(html, $.count("li", count => count.toString())); | ||
expect(result).toBe("3"); | ||
@@ -18,3 +18,3 @@ }); | ||
it("should count <h1/>", () => { | ||
const result = scrap(html, Q.count("h1")); | ||
const result = scrap(html, $.count("h1")); | ||
expect(result).toBe(1); | ||
@@ -24,3 +24,3 @@ }); | ||
it("should count non-existing element", () => { | ||
const result = scrap(html, Q.count("h3")); | ||
const result = scrap(html, $.count("h3")); | ||
expect(result).toBe(0); | ||
@@ -31,3 +31,3 @@ }); | ||
const result = scrap(html, { | ||
liCounts: Q.count("li") | ||
liCounts: $.count("li") | ||
}); | ||
@@ -34,0 +34,0 @@ expect(result.liCounts).toBe(3); |
@@ -1,2 +0,2 @@ | ||
import { scrap, Q } from "../../lib"; | ||
import { scrap, $ } from "../../lib"; | ||
import { html } from "../data"; | ||
@@ -6,3 +6,3 @@ | ||
it("should exists title", () => { | ||
const result = scrap(html, Q.exists("h1")); | ||
const result = scrap(html, $.exists("h1")); | ||
expect(result).toBe(true); | ||
@@ -12,3 +12,3 @@ }); | ||
it("should exists title and convert it to string", () => { | ||
const result = scrap(html, Q.exists("h1", exists => "" + exists)); | ||
const result = scrap(html, $.exists("h1", exists => "" + exists)); | ||
expect(result).toBe("true"); | ||
@@ -18,3 +18,3 @@ }); | ||
it("should not exists h3", () => { | ||
const result = scrap(html, Q.exists("h3")); | ||
const result = scrap(html, $.exists("h3")); | ||
expect(result).toBe(false); | ||
@@ -25,3 +25,3 @@ }); | ||
const result = scrap(html, { | ||
hasFooter: Q.exists(".footer") | ||
hasFooter: $.exists(".footer") | ||
}); | ||
@@ -28,0 +28,0 @@ expect(result.hasFooter).toBe(true); |
@@ -1,2 +0,2 @@ | ||
import { scrap, Q } from "../../lib"; | ||
import { scrap, $ } from "../../lib"; | ||
import { html } from "../data"; | ||
@@ -6,3 +6,3 @@ | ||
it("should get html from <ul/>", () => { | ||
const result = scrap(html, Q.html("ul>li:first-child")); | ||
const result = scrap(html, $.html("ul>li:first-child")); | ||
expect(result).toBe(`<span>Guten Tag</span>`); | ||
@@ -14,3 +14,3 @@ }); | ||
html, | ||
Q.html("ul>li:first-child", html => html.length) | ||
$.html("ul>li:first-child", html => html.length) | ||
); | ||
@@ -21,3 +21,3 @@ expect(result).toBe(22); | ||
// it("should not get html from non exists element", () => { | ||
// const result = scrap(html, Q.html('h3')); | ||
// const result = scrap(html, $.html('h3')); | ||
// expect(result).toBe(null); | ||
@@ -28,3 +28,3 @@ // }); | ||
const result = scrap(html, { | ||
footer: Q.html("ul>li:last-child") | ||
footer: $.html("ul>li:last-child") | ||
}); | ||
@@ -31,0 +31,0 @@ expect(result.footer).toBe(`<span>Bonjour</span>`); |
@@ -1,2 +0,2 @@ | ||
import { scrap, Q } from "../../lib"; | ||
import { scrap, $ } from "../../lib"; | ||
import { html } from "../data"; | ||
@@ -6,3 +6,3 @@ | ||
it("should get link from <a/>", () => { | ||
const result = scrap(html, Q.link("a")); | ||
const result = scrap(html, $.link("a")); | ||
expect(result).toBe("/read-more"); | ||
@@ -12,3 +12,3 @@ }); | ||
it("should get length of the link from <a/>", () => { | ||
const result = scrap(html, Q.link("a", link => link.length)); | ||
const result = scrap(html, $.link("a", link => link.length)); | ||
expect(result).toBe(10); | ||
@@ -18,3 +18,3 @@ }); | ||
// it("should not get link from title", () => { | ||
// const result = scrap(html, Q.link('h1')); | ||
// const result = scrap(html, $.link('h1')); | ||
// expect(result).toBe(""); | ||
@@ -24,3 +24,3 @@ // }); | ||
// it("should not get link non existing element", () => { | ||
// const result = scrap(html, Q.link('h3')); | ||
// const result = scrap(html, $.link('h3')); | ||
// expect(result).toBe(""); | ||
@@ -31,3 +31,3 @@ // }); | ||
const result = scrap(html, { | ||
href: Q.link("a") | ||
href: $.link("a") | ||
}); | ||
@@ -34,0 +34,0 @@ expect(result.href).toBe("/read-more"); |
@@ -1,2 +0,2 @@ | ||
import { scrap, Q } from "../../lib"; | ||
import { scrap, $ } from "../../lib"; | ||
import { html } from "../data"; | ||
@@ -7,3 +7,3 @@ | ||
const result = scrap(html, { | ||
title: Q.select("h1", el => el.text()) | ||
title: $.select("h1", el => el.text()) | ||
}); | ||
@@ -10,0 +10,0 @@ expect(result.title).toBe("Hello"); |
@@ -1,2 +0,2 @@ | ||
import { scrap, Q } from "../../lib"; | ||
import { scrap, $ } from "../../lib"; | ||
import { html } from "../data"; | ||
@@ -6,3 +6,3 @@ | ||
it("should get text from .msg", () => { | ||
const result = scrap(html, Q.text(".msg")); | ||
const result = scrap(html, $.text(".msg")); | ||
expect(result).toBe("Ciao"); | ||
@@ -12,3 +12,3 @@ }); | ||
it("should get text from .msg and get length", () => { | ||
const result = scrap(html, Q.text(".msg", text => text.length)); | ||
const result = scrap(html, $.text(".msg", text => text.length)); | ||
expect(result).toBe(4); | ||
@@ -23,3 +23,3 @@ }); | ||
it("should not get text from non existing element", () => { | ||
const result = scrap(html, Q.text("h3")); | ||
const result = scrap(html, $.text("h3")); | ||
expect(result).toBe(""); | ||
@@ -30,3 +30,3 @@ }); | ||
const result = scrap(html, { | ||
link: Q.text("a") | ||
link: $.text("a") | ||
}); | ||
@@ -33,0 +33,0 @@ expect(result.link).toBe("read more ..."); |
@@ -0,0 +0,0 @@ # TODO |
@@ -0,0 +0,0 @@ { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
2272357
75
3365
9