Comparing version 2.1.0 to 2.1.1
@@ -60,4 +60,4 @@ 'use strict'; | ||
browserPage.getElements = browserPage.$$; | ||
browserPage.evalHandle = this.evalHandle.bind(this, browserPage); | ||
browserPage.tableToJson = this.tableToJson.bind(this, browserPage); | ||
// browserPage.evalHandle = (...args) => this.evalHandle(browserPage, ...args); | ||
// browserPage.tableToJson = (...args) => this.tableToJson(browserPage, ...args); | ||
browserPage.id = Date.now(); | ||
@@ -75,32 +75,34 @@ | ||
// TODO this is busted rn | ||
// Intended to evaluate an ElementHandle | ||
async evalHandle(page, elHandle, props) { | ||
// async evalHandle(page, elHandle, props) { | ||
// | ||
// return await page.evaluate(async (el) => { | ||
// | ||
// return [].concat(props).map((prop) => { | ||
// | ||
// const isFunc = prop.slice(-2) === '()'; | ||
// | ||
// return isFunc ? el[prop.slice(0, -2)]() : el[prop]; | ||
// }); | ||
// }); | ||
// } | ||
return await page.evaluate((el) => { | ||
return [].concat(props).map((prop) => { | ||
const isFunc = prop.slice(-2) === '()'; | ||
return isFunc ? el[prop.slice(0, -2)]() : el[prop]; | ||
}); | ||
}, elHandle); | ||
} | ||
async tableToJson(page, selector) { | ||
// Serializes the table into a string with rows separated by '\n', | ||
// cols separated by '\t' | ||
const tableInnerText = await this.evalHandle(page, page.$(selector), 'innerText'); | ||
// Will take the first 2 columns in a table, | ||
// turning it into an object | ||
return tableInnerText.split('\n').slice(1).reduce((collector, pair) => { | ||
const [key, val] = pair.split('\t'); | ||
collector[key] = val; | ||
return collector; | ||
}, {}); | ||
} | ||
// TODO this is busted til we fix evalHandle | ||
// async tableToJson(page, selector) { | ||
// | ||
// // Serializes the table into a string with rows separated by '\n', | ||
// // cols separated by '\t' | ||
// const tableInnerText = await this.evalHandle(page, page.$(selector), 'innerText'); | ||
// | ||
// // Will take the first 2 columns in a table, | ||
// // turning it into an object | ||
// return tableInnerText.split('\n').slice(1).reduce((collector, pair) => { | ||
// | ||
// const [key, val] = pair.split('\t'); | ||
// collector[key] = val; | ||
// | ||
// return collector; | ||
// }, {}); | ||
// } | ||
}; |
{ | ||
"name": "clickity", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "author": "wsw", |
5198
117