Skip to content
Snippets Groups Projects
Commit ab105550 authored by Reiter, Christoph's avatar Reiter, Christoph :snake:
Browse files

Re-format all code

parent 44c83e8d
Branches
No related tags found
1 merge request!124Add prettier
Pipeline #86099 passed
Showing
with 895 additions and 700 deletions
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
*/ */
export const parseLinkHeader = (header) => { export const parseLinkHeader = (header) => {
if (header.length === 0) { if (header.length === 0) {
throw new Error("input must not be of zero length"); throw new Error('input must not be of zero length');
} }
// Split parts by comma // Split parts by comma
...@@ -49,7 +49,9 @@ export const parseBaseUrl = (url) => { ...@@ -49,7 +49,9 @@ export const parseBaseUrl = (url) => {
*/ */
export const stringListToSelect2DataArray = (list) => { export const stringListToSelect2DataArray = (list) => {
let data = []; let data = [];
list.forEach((item) => {data.push({id: item, text: item});}); list.forEach((item) => {
data.push({id: item, text: item});
});
return data; return data;
}; };
...@@ -99,11 +101,18 @@ export const defineCustomElement = (name, constructor, options) => { ...@@ -99,11 +101,18 @@ export const defineCustomElement = (name, constructor, options) => {
return true; return true;
} }
// Checks taken from https://github.com/webcomponents/webcomponentsjs/blob/master/webcomponents-loader.js // Checks taken from https://github.com/webcomponents/webcomponentsjs/blob/master/webcomponents-loader.js
if (!('attachShadow' in Element.prototype && 'getRootNode' in Element.prototype && window.customElements)) { if (
!(
'attachShadow' in Element.prototype &&
'getRootNode' in Element.prototype &&
window.customElements
)
) {
var elements = document.getElementsByTagName(name); var elements = document.getElementsByTagName(name);
for (var i = 0; i < elements.length; i++) { for (var i = 0; i < elements.length; i++) {
elements[i].innerHTML = "<span style='border: 1px solid red; font-size: 0.8em; " elements[i].innerHTML =
+ "opacity: 0.5; padding: 0.2em;'>☹ Your browser is not supported ☹</span>"; "<span style='border: 1px solid red; font-size: 0.8em; " +
"opacity: 0.5; padding: 0.2em;'>☹ Your browser is not supported ☹</span>";
} }
return false; return false;
} }
...@@ -136,7 +145,9 @@ export const makeId = (length) => { ...@@ -136,7 +145,9 @@ export const makeId = (length) => {
* @param n * @param n
* @returns {string} * @returns {string}
*/ */
export const pad10 = (n) => { return n < 10 ? '0' + n : n; }; export const pad10 = (n) => {
return n < 10 ? '0' + n : n;
};
/** /**
* Converts a date object or string to a local iso datetime with stripped seconds and timezone for the datetime-local input * Converts a date object or string to a local iso datetime with stripped seconds and timezone for the datetime-local input
...@@ -149,7 +160,9 @@ export const dateToStrippedIsoDT = (date) => { ...@@ -149,7 +160,9 @@ export const dateToStrippedIsoDT = (date) => {
date = new Date(date); date = new Date(date);
} }
return `${date.getFullYear()}-${pad10(date.getMonth()+1)}-${pad10(date.getDate())}T${pad10(date.getHours())}:${pad10(date.getMinutes())}`; return `${date.getFullYear()}-${pad10(date.getMonth() + 1)}-${pad10(date.getDate())}T${pad10(
date.getHours()
)}:${pad10(date.getMinutes())}`;
}; };
/** /**
...@@ -198,7 +211,6 @@ export const getAssetURL = (pkg, path) => { ...@@ -198,7 +211,6 @@ export const getAssetURL = (pkg, path) => {
return new URL(fullPath, new URL('..', import.meta.url).href).href; return new URL(fullPath, new URL('..', import.meta.url).href).href;
}; };
/** /**
* Poll <fn> every <interval> ms until <timeout> ms * Poll <fn> every <interval> ms until <timeout> ms
* *
...@@ -207,12 +219,12 @@ export const getAssetURL = (pkg, path) => { ...@@ -207,12 +219,12 @@ export const getAssetURL = (pkg, path) => {
* @param interval * @param interval
*/ */
export const pollFunc = (fn, timeout, interval) => { export const pollFunc = (fn, timeout, interval) => {
var startTime = (new Date()).getTime(); var startTime = new Date().getTime();
interval = interval || 1000; interval = interval || 1000;
(function p() { (function p() {
// don't retry if we took longer than timeout ms // don't retry if we took longer than timeout ms
if (((new Date).getTime() - startTime ) > timeout) { if (new Date().getTime() - startTime > timeout) {
return; return;
} }
...@@ -327,8 +339,8 @@ export async function getMimeTypeOfFile(file) { ...@@ -327,8 +339,8 @@ export async function getMimeTypeOfFile(file) {
export const getBaseName = (str) => { export const getBaseName = (str) => {
let base = String(str).substring(str.lastIndexOf('/') + 1); let base = String(str).substring(str.lastIndexOf('/') + 1);
if (base.lastIndexOf(".") !== -1) { if (base.lastIndexOf('.') !== -1) {
base = base.substring(0, base.lastIndexOf(".")); base = base.substring(0, base.lastIndexOf('.'));
} }
return base; return base;
...@@ -356,9 +368,11 @@ export const querySlotted = (root, selector) => { ...@@ -356,9 +368,11 @@ export const querySlotted = (root, selector) => {
let matched = []; let matched = [];
slots.forEach((slot) => { slots.forEach((slot) => {
matched = matched.concat(slot.assignedElements().filter((el) => { matched = matched.concat(
slot.assignedElements().filter((el) => {
return el.matches(selector); return el.matches(selector);
})); })
);
}); });
return matched; return matched;
......
{ {
"sEmptyTable": "No data available in table", "sEmptyTable": "No data available in table",
"sInfo": "Showing _START_ to _END_ of _TOTAL_ entries", "sInfo": "Showing _START_ to _END_ of _TOTAL_ entries",
......
{ {
"sEmptyTable": "Keine Daten in der Tabelle vorhanden", "sEmptyTable": "Keine Daten in der Tabelle vorhanden",
"sInfo": "_START_ bis _END_ von _TOTAL_ Einträgen", "sInfo": "_START_ bis _END_ von _TOTAL_ Einträgen",
......
module.exports = { module.exports = {
input: [ input: ['src/*.js'],
'src/*.js',
],
output: './', output: './',
options: { options: {
debug: false, debug: false,
...@@ -10,7 +8,7 @@ module.exports = { ...@@ -10,7 +8,7 @@ module.exports = {
lngs: ['en', 'de'], lngs: ['en', 'de'],
resource: { resource: {
loadPath: 'src/i18n/{{lng}}/{{ns}}.json', loadPath: 'src/i18n/{{lng}}/{{ns}}.json',
savePath: 'src/i18n/{{lng}}/{{ns}}.json' savePath: 'src/i18n/{{lng}}/{{ns}}.json',
}, },
}, },
} };
...@@ -2,33 +2,36 @@ import glob from 'glob'; ...@@ -2,33 +2,36 @@ import glob from 'glob';
import resolve from '@rollup/plugin-node-resolve'; import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs'; import commonjs from '@rollup/plugin-commonjs';
import copy from 'rollup-plugin-copy'; import copy from 'rollup-plugin-copy';
import {terser} from "rollup-plugin-terser"; import {terser} from 'rollup-plugin-terser';
import json from '@rollup/plugin-json'; import json from '@rollup/plugin-json';
import serve from 'rollup-plugin-serve'; import serve from 'rollup-plugin-serve';
import urlPlugin from "@rollup/plugin-url"; import urlPlugin from '@rollup/plugin-url';
import del from 'rollup-plugin-delete'; import del from 'rollup-plugin-delete';
import {getPackagePath, getDistPath} from '../../rollup.utils.js'; import {getPackagePath, getDistPath} from '../../rollup.utils.js';
const pkg = require('./package.json'); const pkg = require('./package.json');
const build = (typeof process.env.BUILD !== 'undefined') ? process.env.BUILD : 'local'; const build = typeof process.env.BUILD !== 'undefined' ? process.env.BUILD : 'local';
console.log("build: " + build); console.log('build: ' + build);
export default (async () => { export default (async () => {
return { return {
input: (build != 'test') ? ['src/dbp-data-table-view.js', 'src/dbp-data-table-view-demo.js'] : glob.sync('test/**/*.js'), input:
build != 'test'
? ['src/dbp-data-table-view.js', 'src/dbp-data-table-view-demo.js']
: glob.sync('test/**/*.js'),
output: { output: {
dir: 'dist', dir: 'dist',
entryFileNames: '[name].js', entryFileNames: '[name].js',
chunkFileNames: 'shared/[name].[hash].[format].js', chunkFileNames: 'shared/[name].[hash].[format].js',
format: 'esm', format: 'esm',
sourcemap: true sourcemap: true,
}, },
watch: { watch: {
chokidar: true, chokidar: true,
}, },
plugins: [ plugins: [
del({ del({
targets: 'dist/*' targets: 'dist/*',
}), }),
resolve(), resolve(),
commonjs(), commonjs(),
...@@ -36,24 +39,41 @@ export default (async () => { ...@@ -36,24 +39,41 @@ export default (async () => {
urlPlugin({ urlPlugin({
limit: 0, limit: 0,
emitFiles: true, emitFiles: true,
fileName: 'shared/[name].[hash][extname]' fileName: 'shared/[name].[hash][extname]',
}), }),
(build !== 'local' && build !== 'test') ? terser() : false, build !== 'local' && build !== 'test' ? terser() : false,
copy({ copy({
targets: [ targets: [
{src: 'assets/index.html', dest: 'dist'}, {src: 'assets/index.html', dest: 'dist'},
{src: 'assets/*.css', dest: 'dist/' + await getDistPath(pkg.name)}, {src: 'assets/*.css', dest: 'dist/' + (await getDistPath(pkg.name))},
{src: 'assets/*.ico', dest: 'dist/' + await getDistPath(pkg.name)}, {src: 'assets/*.ico', dest: 'dist/' + (await getDistPath(pkg.name))},
{src: 'assets/nomodule.js', dest: 'dist/' + await getDistPath(pkg.name)}, {src: 'assets/nomodule.js', dest: 'dist/' + (await getDistPath(pkg.name))},
{src: await getPackagePath('@dbp-toolkit/common', 'assets/icons/*.svg'), dest: 'dist/' + await getDistPath('@dbp-toolkit/common', 'icons')}, {
{src: await getPackagePath('datatables.net-dt', 'css'), dest: 'dist/' + await getDistPath(pkg.name)}, src: await getPackagePath('@dbp-toolkit/common', 'assets/icons/*.svg'),
{src: await getPackagePath('datatables.net-dt', 'images'), dest: 'dist/' + await getDistPath(pkg.name)}, dest: 'dist/' + (await getDistPath('@dbp-toolkit/common', 'icons')),
{src: await getPackagePath('datatables.net-responsive-dt', 'css'), dest: 'dist/' + await getDistPath(pkg.name)}, },
{src: await getPackagePath('datatables.net-buttons-dt', 'css'), dest: 'dist/' + await getDistPath(pkg.name)}, {
src: await getPackagePath('datatables.net-dt', 'css'),
dest: 'dist/' + (await getDistPath(pkg.name)),
},
{
src: await getPackagePath('datatables.net-dt', 'images'),
dest: 'dist/' + (await getDistPath(pkg.name)),
},
{
src: await getPackagePath('datatables.net-responsive-dt', 'css'),
dest: 'dist/' + (await getDistPath(pkg.name)),
},
{
src: await getPackagePath('datatables.net-buttons-dt', 'css'),
dest: 'dist/' + (await getDistPath(pkg.name)),
},
], ],
}), }),
(process.env.ROLLUP_WATCH === 'true') ? serve({contentBase: 'dist', host: '127.0.0.1', port: 8003}) : false process.env.ROLLUP_WATCH === 'true'
] ? serve({contentBase: 'dist', host: '127.0.0.1', port: 8003})
: false,
],
}; };
})(); })();
This diff is collapsed.
This diff is collapsed.
module.exports = { module.exports = {
input: [ input: ['src/*.js'],
'src/*.js',
],
output: './', output: './',
options: { options: {
debug: false, debug: false,
...@@ -10,7 +8,7 @@ module.exports = { ...@@ -10,7 +8,7 @@ module.exports = {
lngs: ['en', 'de'], lngs: ['en', 'de'],
resource: { resource: {
loadPath: 'src/i18n/{{lng}}/{{ns}}.json', loadPath: 'src/i18n/{{lng}}/{{ns}}.json',
savePath: 'src/i18n/{{lng}}/{{ns}}.json' savePath: 'src/i18n/{{lng}}/{{ns}}.json',
}, },
}, },
} };
This diff is collapsed.
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment