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

Move utils.js to named exports

So that rollup can do tree shaking and report import errors.
parent 2f811873
No related branches found
No related tags found
No related merge requests found
import utils from '../utils';
import * as utils from '../utils';
describe('utils', () => {
it('base64EncodeUnicode', () => {
......
import env from './env.js';
export default {
/**
* Parses a link header
*
......@@ -8,7 +7,7 @@ export default {
*
* @param header
*/
parseLinkHeader: (header) => {
export const parseLinkHeader = (header) => {
if (header.length === 0) {
throw new Error("input must not be of zero length");
}
......@@ -29,7 +28,7 @@ export default {
}
return links;
},
}
/**
* Reads a setting
......@@ -37,13 +36,13 @@ export default {
* @param key
* @returns {*}
*/
setting: (key) => {
export const setting = (key) => {
return env[key];
},
}
getAPiUrl: (path = "", withPrefix = true) => {
export const getAPiUrl = (path = "", withPrefix = true) => {
return env.apiBaseUrl + (withPrefix ? env.apiUrlPrefix : "") + path;
},
}
/**
* Parses the base url from an url
......@@ -51,12 +50,12 @@ export default {
* @param url
* @returns {string}
*/
parseBaseUrl: (url) => {
export const parseBaseUrl = (url) => {
const pathArray = url.split('/');
const protocol = pathArray[0];
const host = pathArray[2];
return protocol + '//' + host;
},
}
/**
* Converts a string list to a data array for Select2
......@@ -64,11 +63,11 @@ export default {
* @param list
* @returns {Array}
*/
stringListToSelect2DataArray: (list) => {
export const stringListToSelect2DataArray = (list) => {
let data = [];
list.forEach((item) => {data.push({id: item, text: item})});
return data;
},
}
/**
* Does generic Base64 Encoding with support for 16-bit encoded strings
......@@ -77,7 +76,7 @@ export default {
* @param str
* @returns {string}
*/
base64EncodeUnicode: (str) => {
export const base64EncodeUnicode = (str) => {
// First we escape the string using encodeURIComponent to get the UTF-8 encoding of the characters,
// then we convert the percent encodings into raw bytes, and finally feed it to btoa() function.
const utf8Bytes = encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function(match, p1) {
......@@ -85,7 +84,7 @@ export default {
});
return btoa(utf8Bytes);
},
}
/**
* Like customElements.define() but tries to display an error in case the browser doesn't
......@@ -95,7 +94,7 @@ export default {
*
* @returns {boolean}
*/
defineCustomElement: (name, constructor, options) => {
export const defineCustomElement = (name, constructor, options) => {
// Checks taken from https://github.com/webcomponents/webcomponentsjs/blob/master/webcomponents-loader.js
if (!('attachShadow' in Element.prototype && 'getRootNode' in Element.prototype && window.customElements)) {
var elements = document.getElementsByTagName(name);
......@@ -107,7 +106,7 @@ export default {
}
customElements.define(name, constructor, options);
return true;
},
}
/**
* Creates a random id
......@@ -117,7 +116,7 @@ export default {
* @param length
* @returns {string}
*/
makeId: (length) => {
export const makeId = (length) => {
var result = '';
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var charactersLength = characters.length;
......@@ -127,4 +126,3 @@ export default {
return result;
}
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment