Created
March 27, 2022 09:37
-
-
Save farishan/7aec62f7ed50c152cac3bcea252275d1 to your computer and use it in GitHub Desktop.
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
define(() => { | |
function objectToTable(object = {}, header = {}, orientation = 'landscape') { | |
const $table = document.createElement('table') | |
let $thead | |
if (orientation === 'landscape') { | |
$thead = document.createElement('thead') | |
$table.appendChild($thead) | |
} | |
const $tbody = document.createElement('tbody') | |
$table.appendChild($tbody) | |
if (orientation === 'landscape') { | |
const $thRow = document.createElement('tr') | |
const $tdRow = document.createElement('tr') | |
for (let [k, v] of Object.entries(header)) { | |
const $th = document.createElement('th') | |
$th.innerHTML = v | |
$thRow.appendChild($th) | |
const $td = document.createElement('td') | |
$td.innerHTML = object[k] | |
$tdRow.appendChild($td) | |
} | |
$thead.appendChild($thRow) | |
$tbody.appendChild($tdRow) | |
} else if (orientation === 'potrait') { | |
for (let [k, v] of Object.entries(header)) { | |
const $tdRow = document.createElement('tr') | |
const $th = document.createElement('th') | |
$th.innerHTML = v | |
$tdRow.appendChild($th) | |
const $td = document.createElement('td') | |
$td.innerHTML = object[k] | |
$tdRow.appendChild($td) | |
$tbody.appendChild($tdRow) | |
} | |
} | |
return $table | |
} | |
return objectToTable | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment