From 6342787aefe79efd0873f53d7ef6b43b985293b0 Mon Sep 17 00:00:00 2001 From: "Robin C. Ladiges" Date: Fri, 5 Feb 2021 00:14:06 +0100 Subject: [PATCH] whitespace --- src/js/datasource.js | 112 +++++++++++++++++++++---------------------- 1 file changed, 56 insertions(+), 56 deletions(-) diff --git a/src/js/datasource.js b/src/js/datasource.js index c987338..a2e5e00 100644 --- a/src/js/datasource.js +++ b/src/js/datasource.js @@ -22,67 +22,67 @@ const fetch = { const transform = { spreadsheet: ({ data: { feed: { entry: entries } } }) => { - const keys = {} - const objs = {} - let moreKeys = true - const isKey = (cell) => moreKeys && /^[A-Z]+1$/.test(cell) - const n = entries.length - for (let i = 0 ; i < n; i++) { - if (!(i in entries)) { continue } - const e = entries[i] - const cell = e.title.$t - const cont = escapeHtml(e.content.$t) - if (isKey(cell)) { - keys[cell] = cont - } - else { - moreKeys = false - const val = text2number(cont) - objs[cell] = val - const row = cell.replace(/[A-Z]/g, '') - const col = cell.replace(/[0-9]/g, '') - if (! (row in objs)) { objs[row] = {} } - objs[row][keys[ col + '1' ]] = val - } + const keys = {} + const objs = {} + let moreKeys = true + const isKey = (cell) => moreKeys && /^[A-Z]+1$/.test(cell) + const n = entries.length + for (let i = 0 ; i < n; i++) { + if (!(i in entries)) { continue } + const e = entries[i] + const cell = e.title.$t + const cont = escapeHtml(e.content.$t) + if (isKey(cell)) { + keys[cell] = cont } - return Object.values(objs) - }, - wiki: async (document) => { - const table = document.tables(0).data - const out = [] - for (const i in table) { - const row = table[i] - const obj = {} - for (const key in row) { - const sentence = row[key] - const text = sentence.data.text.trim() - if (! text) { continue } - const val = text2number(text) + else { + moreKeys = false + const val = text2number(cont) + objs[cell] = val + const row = cell.replace(/[A-Z]/g, '') + const col = cell.replace(/[0-9]/g, '') + if (! (row in objs)) { objs[row] = {} } + objs[row][keys[ col + '1' ]] = val + } + } + return Object.values(objs) + }, + wiki: async (document) => { + const table = document.tables(0).data + const out = [] + for (const i in table) { + const row = table[i] + const obj = {} + for (const key in row) { + const sentence = row[key] + const text = sentence.data.text.trim() + if (! text) { continue } + const val = text2number(text) - obj[key] = ( - key === 'type' || key === 'item' - ? val.replace(/[\_\- ]/g, '').toLowerCase() - : val - ) - if (sentence.data.links || sentence.data.fmt) { - obj[key + '_html'] = sentence.html({formatting: true}).replace(/ href="\.\//g, ` target="_blank" href="${__WIKI__}`) - } - else if (key === 'type' || key === 'item') { - obj[key + '_html'] = val - } + obj[key] = ( + key === 'type' || key === 'item' + ? val.replace(/[\_\- ]/g, '').toLowerCase() + : val + ) + if (sentence.data.links || sentence.data.fmt) { + obj[key + '_html'] = sentence.html({formatting: true}).replace(/ href="\.\//g, ` target="_blank" href="${__WIKI__}`) + } + else if (key === 'type' || key === 'item') { + obj[key + '_html'] = val + } - // round coords - if (['x', 'y', 'z'].includes(key)) { - obj[key] = Math.round(obj[key] * 100) / 100 - } + // round coords + if (['x', 'y', 'z'].includes(key)) { + obj[key] = Math.round(obj[key] * 100) / 100 } - const [ type, item ] = mapOldBoth(obj.type, obj.item) - obj.type = type - obj.item = item - out.push(obj) } - return out - }, + const [ type, item ] = mapOldBoth(obj.type, obj.item) + obj.type = type + obj.item = item + out.push(obj) + } + return out + }, } module.exports = {