Comparing version 2.1.3 to 2.2.0
@@ -60,3 +60,3 @@ 'use strict'; | ||
browserPage.getElements = browserPage.$$; | ||
// browserPage.evalHandle = (...args) => this.evalHandle(browserPage, ...args); | ||
browserPage.evalHandle = (...args) => this.evalHandle(browserPage, ...args); | ||
// browserPage.tableToJson = (...args) => this.tableToJson(browserPage, ...args); | ||
@@ -80,34 +80,42 @@ browserPage.id = Uuid.v4(); | ||
// TODO this is busted rn | ||
// Intended to evaluate an ElementHandle | ||
// 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]; | ||
// }); | ||
// }); | ||
// } | ||
// Evaluate an element handle, (return value of page.$() or an item from page.$$()) | ||
async evalHandle(page, elHandle, passedProps) { | ||
// 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; | ||
// }, {}); | ||
// } | ||
if (!elHandle) { | ||
throw new Error('elHandle no good (might be null)'); | ||
} | ||
return await page.evaluate((el, props) => { | ||
const res = [].concat(props).map((prop) => { | ||
const isFunc = prop.slice(-2) === '()'; | ||
return isFunc ? el[prop.slice(0, -2)]() : el[prop]; | ||
}); | ||
if (res.length === 1) { | ||
return res[0]; | ||
} | ||
return res; | ||
}, elHandle, passedProps); | ||
} | ||
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.3", | ||
"version": "2.2.0", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "author": "wsw", |
5405
118