Compare commits
6 Commits
v1.0.2
...
developmen
| Author | SHA1 | Date | |
|---|---|---|---|
| 35d2ef8580 | |||
| 5b69cecf9f | |||
| ef8b4e04ce | |||
| 082cb761c0 | |||
| 0968085084 | |||
| a629482a20 |
9
.github/workflows/ci.yml
vendored
9
.github/workflows/ci.yml
vendored
@@ -1,10 +1,15 @@
|
||||
name: CI
|
||||
run-name: ${{ github.actor}} runs CI
|
||||
name: JavaScriptUtilsVitest
|
||||
run-name: ${{ github.actor}} runs vitest checks
|
||||
|
||||
# on:
|
||||
# push:
|
||||
# branches:
|
||||
# - main
|
||||
# pull_request:
|
||||
# branches:
|
||||
# - main
|
||||
# - staging
|
||||
# - development
|
||||
|
||||
on: [push]
|
||||
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
node_modules/
|
||||
coverage/*
|
||||
package-lock.json
|
||||
|
||||
@@ -100,19 +100,19 @@ Build with the following commands, the output will be stored in "build/js/output
|
||||
For full not minified version
|
||||
|
||||
```sh
|
||||
npm build utils-build
|
||||
npm run utils-build
|
||||
```
|
||||
|
||||
For minified build (but keeps the function names as is)
|
||||
|
||||
```sh
|
||||
npm build utils-min-build
|
||||
npm run utils-min-build
|
||||
```
|
||||
|
||||
Or build both at the same time
|
||||
|
||||
```sh
|
||||
npm build utils-build-all
|
||||
npm run utils-build-all
|
||||
```
|
||||
|
||||
## Develop
|
||||
|
||||
3149
package-lock.json
generated
3149
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -22,6 +22,7 @@
|
||||
"esbuild": "^0.25.0",
|
||||
"eslint": "^9.20.1",
|
||||
"globals": "^15.15.0",
|
||||
"jsdom": "^26.0.0",
|
||||
"vitest": "^3.0.8"
|
||||
}
|
||||
}
|
||||
|
||||
127
src/utils.mjs
127
src/utils.mjs
@@ -10,6 +10,8 @@ import {
|
||||
isFunction as _isFunction,
|
||||
executeFunctionByName as _executeFunctionByName,
|
||||
isObject as _isObject,
|
||||
isArray as _isArray,
|
||||
isIterable as _isIterable,
|
||||
getObjectCount as _getObjectCount,
|
||||
keyInObject as _keyInObject,
|
||||
getKeyByValue as _getKeyByValue,
|
||||
@@ -61,7 +63,11 @@ import {
|
||||
} from './utils/FormatBytes.mjs';
|
||||
import {
|
||||
parseQueryString as _parseQueryString,
|
||||
getQueryStringParam as _getQueryStringParam
|
||||
getQueryStringParam as _getQueryStringParam,
|
||||
hasUrlParameter as _hasUrlParameter,
|
||||
getUrlParameter as _getUrlParameter,
|
||||
updateUrlParameter as _updateUrlParameter,
|
||||
removeUrlParameter as _removeUrlParameter,
|
||||
} from './utils/UrlParser.mjs';
|
||||
import {
|
||||
loginLogout as _loginLogout,
|
||||
@@ -81,6 +87,11 @@ import { l10nTranslation } from './utils/l10nTranslation.mjs';
|
||||
import { HtmlElementCreator } from './utils/HtmlElementCreator.mjs';
|
||||
import { ActionBox } from './utils/ActionBox.mjs';
|
||||
import { LoginNavMenu } from './utils/LoginNavMenu.mjs';
|
||||
import {
|
||||
isWebkit as _isWebkit,
|
||||
isMobileWebKit as _isMobileWebKit,
|
||||
isDesktopWebKit as _isDesktopWebKit
|
||||
} from './utils/BrowserDetect.mjs';
|
||||
|
||||
let aiob = new ActionIndicatorOverlayBox();
|
||||
let hec = new HtmlElementCreator();
|
||||
@@ -433,8 +444,8 @@ function executeFunctionByName(functionName, context) // eslint-disable-line no-
|
||||
|
||||
/**
|
||||
* checks if a variable is an object
|
||||
* @param {any} val possible object
|
||||
* @return {Boolean} true/false if it is an object or not
|
||||
* @param {any} val possible object
|
||||
* @return {Boolean} true/false if it is an object or not
|
||||
*/
|
||||
// @ts-ignore
|
||||
function isObject(val) // eslint-disable-line no-unused-vars
|
||||
@@ -442,6 +453,28 @@ function isObject(val) // eslint-disable-line no-unused-vars
|
||||
return _isObject(val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if variable is array
|
||||
* @param {any} val possible array
|
||||
* @returns {Boolean} true/false if it an array
|
||||
*/
|
||||
// @ts-ignore
|
||||
function isArray(val) // eslint-disable-line no-unused-vars
|
||||
{
|
||||
return _isArray(val);
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if a variable is an iterable
|
||||
* @param {any} val possible iterable
|
||||
* @return {Boolean} true/false if it is an object or not
|
||||
*/
|
||||
// @ts-ignore
|
||||
function isIterable(val) // eslint-disable-line no-unused-vars
|
||||
{
|
||||
return _isIterable(val);
|
||||
}
|
||||
|
||||
/**
|
||||
* get the length of an object (entries)
|
||||
* @param {Object} object object to check
|
||||
@@ -937,16 +970,14 @@ function html_options_refill(name, data, sort = '') // eslint-disable-line no-un
|
||||
* ALTERNATIVE CODE
|
||||
* var url = new URL(window.location.href);
|
||||
* param_uid = url.searchParams.get('uid');
|
||||
* @param {String} [query=''] the query string to parse
|
||||
* if not set will auto fill
|
||||
* @param {String} [return_key=''] if set only returns this key entry
|
||||
* or empty for none
|
||||
* @return {Object|String} parameter entry list
|
||||
* @param {String} [query=''] the query string to parse, if not set will auto fill
|
||||
* @param {String} [return_key=''] if set only returns this key entry or empty for none
|
||||
* @param {Boolean} [single=false] if set to true then only the first found will be returned
|
||||
*/
|
||||
// @ts-ignore
|
||||
function parseQueryString(query = '', return_key = '') // eslint-disable-line no-unused-vars
|
||||
function parseQueryString(query = '', return_key = '', single = false) // eslint-disable-line no-unused-vars
|
||||
{
|
||||
return _parseQueryString(query, return_key);
|
||||
return _parseQueryString(query, return_key, single);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -955,15 +986,12 @@ function parseQueryString(query = '', return_key = '') // eslint-disable-line no
|
||||
* if a parameter is set several times it will be returned as an array
|
||||
* if search parameter set and nothing found and empty string is returned
|
||||
* if no parametes exist and no serach is set and empty object is returned
|
||||
* @param {String} [search=''] if set searches for this entry, if empty
|
||||
* all parameters are returned
|
||||
* @param {String} [query=''] different query string to parse, if not
|
||||
* set (default) the current window href is used
|
||||
* @param {Boolean} [single=false] if set to true then only the first found
|
||||
* will be returned
|
||||
* @return {Object|Array|String} if search is empty, object, if search is set
|
||||
* and only one entry, then string, else array
|
||||
* unless single is true
|
||||
* @param {String} [search=''] if set searches for this entry, if empty all parameters are returned
|
||||
* @param {String} [query=''] different query string to parse, if not set (default) the current window href is used
|
||||
* @param {Boolean} [single=false] if set to true then only the first found will be returned
|
||||
* @return {Object|Array|String} if search is empty, object, if search is set
|
||||
* and only one entry, then string, else array
|
||||
* unless single is true
|
||||
*/
|
||||
// @ts-ignore
|
||||
function getQueryStringParam(search = '', query = '', single = false) // eslint-disable-line no-unused-vars
|
||||
@@ -971,6 +999,51 @@ function getQueryStringParam(search = '', query = '', single = false) // eslint-
|
||||
return _getQueryStringParam(search, query, single);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or update a query parameter in the current URL and update the browser's address bar
|
||||
* @param {string} key - The parameter name to add or update
|
||||
* @param {string} value - The value to set for the parameter
|
||||
* @param {boolean} [reload=false] - Whether to reload the page after updating the URL
|
||||
*/
|
||||
// @ts-ignore
|
||||
function updateUrlParameter(key, value, reload = false) // eslint-disable-line no-unused-vars
|
||||
{
|
||||
return _updateUrlParameter(key, value, reload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a parameter from the current URL and update the browser's address bar
|
||||
* @param {string} key - The parameter name to remove
|
||||
* @param {boolean} [reload=false] - Whether to reload the page after updating the URL
|
||||
*/
|
||||
// @ts-ignore
|
||||
function removeUrlParameter(key, reload = false) // eslint-disable-line no-unused-vars
|
||||
{
|
||||
return _removeUrlParameter(key, reload);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if key exists as URL parameter
|
||||
* @param {String} key URL parameter to search
|
||||
* @returns {Boolean} True if key exists
|
||||
*/
|
||||
// @ts-ignore
|
||||
function hasUrlParameter(key) // eslint-disable-line no-unused-vars
|
||||
{
|
||||
return _hasUrlParameter(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return one value for a URL paramter or null if not found
|
||||
* @param {String} key Which URL parameter to get
|
||||
* @returns {String|Null} URL parameter content
|
||||
*/
|
||||
// @ts-ignore
|
||||
function getUrlParameter(key) // eslint-disable-line no-unused-vars
|
||||
{
|
||||
return _getUrlParameter(key);
|
||||
}
|
||||
|
||||
// MARK: ACL LOGIN
|
||||
// *** MASTER logout call
|
||||
/**
|
||||
@@ -1156,4 +1229,20 @@ function adjustActionBoxHeight(target_id = 'actionBox', override = 0, content_ov
|
||||
ab.adjustActionBoxHeight(target_id, override, content_override);
|
||||
}
|
||||
|
||||
// MARK: BROWSER DETECTION
|
||||
function isWebkit() // eslint-disable-line no-unused-vars
|
||||
{
|
||||
return _isWebkit();
|
||||
}
|
||||
|
||||
function isMobileWebKit() // eslint-disable-line no-unused-vars
|
||||
{
|
||||
return _isMobileWebKit();
|
||||
}
|
||||
|
||||
function isDesktopWebKit() // eslint-disable-line no-unused-vars
|
||||
{
|
||||
return _isDesktopWebKit();
|
||||
}
|
||||
|
||||
/* END */
|
||||
|
||||
@@ -5,7 +5,7 @@ Creator: Clemens Schwaighofer
|
||||
*/
|
||||
|
||||
export { ActionBox };
|
||||
import { keyInObject, getObjectCount } from './JavaScriptHelpers.mjs';
|
||||
import { objectKeyExists, getObjectCount } from './JavaScriptHelpers.mjs';
|
||||
import { exists } from './DomHelpers.mjs';
|
||||
import { setCenter, getWindowSize } from './ResizingAndMove.mjs';
|
||||
|
||||
@@ -155,7 +155,7 @@ class ActionBox {
|
||||
}
|
||||
// adjust zIndex so its above all other and set action box zindex +1
|
||||
$('#overlayBox').show();
|
||||
if (!keyInObject(target_id, this.zIndex.boxes)) {
|
||||
if (!objectKeyExists(this.zIndex.boxes, target_id)) {
|
||||
this.zIndex.boxes[target_id] = this.zIndex.max;
|
||||
// increase by ten
|
||||
this.zIndex.max += 10;
|
||||
@@ -197,7 +197,7 @@ class ActionBox {
|
||||
}
|
||||
// clear storage object
|
||||
if (
|
||||
keyInObject(target_id, this.action_box_storage) && clean === true
|
||||
objectKeyExists(this.action_box_storage, target_id) && clean === true
|
||||
) {
|
||||
this.action_box_storage[target_id] = {};
|
||||
}
|
||||
@@ -249,18 +249,18 @@ class ActionBox {
|
||||
settings = {},
|
||||
show_close = true
|
||||
) {
|
||||
if (!keyInObject(target_id, this.action_box_storage)) {
|
||||
if (!objectKeyExists(this.action_box_storage, target_id)) {
|
||||
this.action_box_storage[target_id] = {};
|
||||
}
|
||||
// settings can have the following
|
||||
// : header_css:[]
|
||||
// : action_box_css:[]
|
||||
let header_css = [];
|
||||
if (keyInObject('header_css', settings)) {
|
||||
if (objectKeyExists(settings, 'header_css')) {
|
||||
header_css = settings.header_css;
|
||||
}
|
||||
let action_box_css = [];
|
||||
if (keyInObject('action_box_css', settings)) {
|
||||
if (objectKeyExists(settings, 'action_box_css')) {
|
||||
action_box_css = settings.action_box_css;
|
||||
}
|
||||
let elements = [];
|
||||
@@ -288,7 +288,7 @@ class ActionBox {
|
||||
// if we have header content, add that here
|
||||
if (getObjectCount(headers) > 0) {
|
||||
// if the element has an entry called "raw_string" then this does not need to be converted
|
||||
if (keyInObject('raw_string', headers)) {
|
||||
if (objectKeyExists(headers, 'raw_string')) {
|
||||
elements.push(headers.raw_string);
|
||||
} else {
|
||||
elements.push(this.hec.phfo(headers));
|
||||
@@ -297,7 +297,7 @@ class ActionBox {
|
||||
// main content part (this should NOT be empty), if empty, add empty _content block
|
||||
if (getObjectCount(contents) > 0) {
|
||||
// if the element has an entry called "raw_string" then this does not need to be converted
|
||||
if (keyInObject('raw_string', contents)) {
|
||||
if (objectKeyExists(contents, 'raw_string')) {
|
||||
elements.push(contents.raw_string);
|
||||
} else {
|
||||
elements.push(this.hec.phfo(contents));
|
||||
|
||||
31
src/utils/BrowserDetect.mjs
Normal file
31
src/utils/BrowserDetect.mjs
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
Description: Browser detect
|
||||
Date: 2025/11.25
|
||||
Creator: Clemens Schwaighofer
|
||||
*/
|
||||
|
||||
export { isWebkit, isMobileWebKit, isDesktopWebKit };
|
||||
|
||||
// Desktop Safari, all mobile WebKit browsers on iOS and webview iOS
|
||||
function isWebkit()
|
||||
{
|
||||
return "GestureEvent" in window;
|
||||
}
|
||||
|
||||
// all mobile webkit browsers and webview iOS
|
||||
function isMobileWebKit()
|
||||
{
|
||||
return "ongesturechange" in window;
|
||||
}
|
||||
|
||||
// Desktop Safari
|
||||
function isDesktopWebKit()
|
||||
{
|
||||
return (
|
||||
typeof window !== 'undefined' &&
|
||||
'safari' in window &&
|
||||
'pushNotification' in window.safari
|
||||
);
|
||||
}
|
||||
|
||||
// __END__
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Description: Date Time functions
|
||||
Date: 2025//3/6
|
||||
Date: 2025/3/6
|
||||
Creator: Clemens Schwaighofer
|
||||
*/
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Description: DOM Helpers
|
||||
Date: 2025//3/6
|
||||
Date: 2025/3/6
|
||||
Creator: Clemens Schwaighofer
|
||||
*/
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Description: Byte string formatting
|
||||
Date: 2025//3/6
|
||||
Date: 2025/3/6
|
||||
Creator: Clemens Schwaighofer
|
||||
*/
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Description: DOM Management and HTML builder
|
||||
Date: 2025//3/6
|
||||
Date: 2025/3/6
|
||||
Creator: Clemens Schwaighofer
|
||||
*/
|
||||
|
||||
@@ -9,7 +9,7 @@ export {
|
||||
// deprecated name
|
||||
HtmlElementCreator as DomManagement
|
||||
};
|
||||
import { deepCopyFunction, isObject } from './JavaScriptHelpers.mjs';
|
||||
import { deepCopyFunction, isObject, isArray } from './JavaScriptHelpers.mjs';
|
||||
|
||||
class HtmlElementCreator {
|
||||
/**
|
||||
@@ -50,7 +50,7 @@ class HtmlElementCreator {
|
||||
base.sub.push(deepCopyFunction(attach));
|
||||
} else {
|
||||
// sub check
|
||||
if (isObject(base.sub) && base.sub.length > 0) {
|
||||
if (isArray(base.sub) && base.sub.length > 0) {
|
||||
for (var i = 0; i < base.sub.length; i ++) {
|
||||
// recursive call to sub element
|
||||
this.ael(base.sub[i], attach, id);
|
||||
@@ -209,7 +209,7 @@ class HtmlElementCreator {
|
||||
}
|
||||
}
|
||||
// second CSS
|
||||
if (isObject(tree.css) && tree.css.length > 0) {
|
||||
if (isArray(tree.css) && tree.css.length > 0) {
|
||||
line += ' class="';
|
||||
for (i = 0; i < tree.css.length; i ++) {
|
||||
line += tree.css[i] + ' ';
|
||||
@@ -234,7 +234,7 @@ class HtmlElementCreator {
|
||||
// dive into sub tree to attach sub nodes
|
||||
// NOTES: we can have content (text) AND sub nodes at the same level
|
||||
// CONTENT (TEXT) takes preference over SUB NODE in order
|
||||
if (isObject(tree.sub) && tree.sub.length > 0) {
|
||||
if (isArray(tree.sub) && tree.sub.length > 0) {
|
||||
if (tree.content) {
|
||||
content.push(tree.content);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Description: HTML Helpers
|
||||
Date: 2025//3/6
|
||||
Date: 2025/3/6
|
||||
Creator: Clemens Schwaighofer
|
||||
*/
|
||||
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
/*
|
||||
Description: JavaScript Helpers
|
||||
Date: 2025//3/6
|
||||
Date: 2025/3/6
|
||||
Creator: Clemens Schwaighofer
|
||||
*/
|
||||
|
||||
export {
|
||||
errorCatch, isFunction, executeFunctionByName,
|
||||
isObject, getObjectCount,
|
||||
errorCatch, isFunction,
|
||||
executeFunctionByName, runFunction, runFunctionArgsArray,
|
||||
isObject, isIterable, isArray, getObjectCount,
|
||||
keyInObject, objectKeyExists,
|
||||
getKeyByValue, valueInObject, objectValueExists,
|
||||
deepCopyFunction
|
||||
@@ -77,6 +78,35 @@ function executeFunctionByName(functionName, context /*, args */)
|
||||
return context[func].apply(context, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* call a function by string
|
||||
* call runFunctionArgArray
|
||||
* @param {string} name Function name to call
|
||||
* @param {Array} arguments all next function arguments are passed on as argument to the function
|
||||
* @returns void
|
||||
*/
|
||||
function runFunction(name)
|
||||
{
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
runFunctionArgsArray(name, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* call a function with a string, argumens as array
|
||||
* @param {string} name Function name to call
|
||||
* @param {array} args function arguments as arry
|
||||
* @returns void
|
||||
*/
|
||||
function runFunctionArgsArray(name, args)
|
||||
{
|
||||
var fn = window[name];
|
||||
if(typeof fn !== 'function') {
|
||||
return;
|
||||
}
|
||||
|
||||
fn.apply(window, args);
|
||||
}
|
||||
|
||||
/**
|
||||
* checks if a variable is an object
|
||||
* @param {any} val possible object
|
||||
@@ -84,10 +114,33 @@ function executeFunctionByName(functionName, context /*, args */)
|
||||
*/
|
||||
function isObject(val)
|
||||
{
|
||||
if (val === null) {
|
||||
return false;
|
||||
}
|
||||
return ((typeof val === 'function') || (typeof val === 'object'));
|
||||
return val !== null && typeof val === 'object' && !Array.isArray(val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if variable is array
|
||||
* @param {any} val possible array
|
||||
* @returns {Boolean} true/false if it an array
|
||||
*/
|
||||
function isArray(val)
|
||||
{
|
||||
return val !== null && Array.isArray(val);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if any iterable type
|
||||
* @param {any} val possible iteratable object/array
|
||||
* @returns {Boolean} true/false if it is iterable
|
||||
*/
|
||||
function isIterable(val)
|
||||
{
|
||||
if (val == null) return false;
|
||||
|
||||
// Check if it's iterable, but excldue strings
|
||||
if (typeof val[Symbol.iterator] === 'function' && typeof val !== 'string') return true;
|
||||
|
||||
// Check if it's a plain object
|
||||
return typeof val === 'object' && val.constructor === Object;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Description: Login access and menu
|
||||
Date: 2025//3/6
|
||||
Date: 2025/3/6
|
||||
Creator: Clemens Schwaighofer
|
||||
*/
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Description: Login access and menu
|
||||
Date: 2025//3/6
|
||||
Date: 2025/3/6
|
||||
Creator: Clemens Schwaighofer
|
||||
*/
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Description: Resize and Move Javascript
|
||||
Date: 2025//3/6
|
||||
Date: 2025/3/6
|
||||
Creator: Clemens Schwaighofer
|
||||
*/
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Description: String Helpers
|
||||
Date: 2025//3/6
|
||||
Date: 2025/3/6
|
||||
Creator: Clemens Schwaighofer
|
||||
*/
|
||||
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
/*
|
||||
Description: HTML Helpers
|
||||
Date: 2025//3/6
|
||||
Date: 2025/3/6
|
||||
Creator: Clemens Schwaighofer
|
||||
*/
|
||||
|
||||
export { parseQueryString, getQueryStringParam };
|
||||
export { parseQueryString, getQueryStringParam, hasUrlParameter, getUrlParameter, updateUrlParameter, removeUrlParameter };
|
||||
|
||||
/**
|
||||
* NOTE: this original code was wrong, now using URL and parsing through
|
||||
@@ -13,13 +13,10 @@ export { parseQueryString, getQueryStringParam };
|
||||
* ALTERNATIVE CODE
|
||||
* var url = new URL(window.location.href);
|
||||
* param_uid = url.searchParams.get('uid');
|
||||
* @param {String} [query=''] the query string to parse
|
||||
* if not set will auto fill
|
||||
* @param {String} [return_key=''] if set only returns this key entry
|
||||
* or empty for none
|
||||
* @param {Boolean} [single=false] if set to true then only the first found
|
||||
* will be returned
|
||||
* @return {Object|String} parameter entry list
|
||||
* @param {String} [query=''] the query string to parse, if not set will auto fill
|
||||
* @param {String} [return_key=''] if set only returns this key entry or empty for none
|
||||
* @param {Boolean} [single=false] if set to true then only the first found will be returned
|
||||
* @return {Object|String} parameter entry list
|
||||
*/
|
||||
function parseQueryString(query = '', return_key = '', single = false)
|
||||
{
|
||||
@@ -32,15 +29,12 @@ function parseQueryString(query = '', return_key = '', single = false)
|
||||
* if a parameter is set several times it will be returned as an array
|
||||
* if search parameter set and nothing found and empty string is returned
|
||||
* if no parametes exist and no serach is set and empty object is returned
|
||||
* @param {String} [search=''] if set searches for this entry, if empty
|
||||
* all parameters are returned
|
||||
* @param {String} [query=''] different query string to parse, if not
|
||||
* set (default) the current window href is used
|
||||
* @param {Boolean} [single=false] if set to true then only the first found
|
||||
* will be returned
|
||||
* @return {Object|Array|String} if search is empty, object, if search is set
|
||||
* and only one entry, then string, else array
|
||||
* unless single is true
|
||||
* @param {String} [search=''] if set searches for this entry, if empty all parameters are returned
|
||||
* @param {String} [query=''] different query string to parse, if not set (default) the current window href is used
|
||||
* @param {Boolean} [single=false] if set to true then only the first found will be returned
|
||||
* @return {Object|Array|String} if search is empty, object, if search is set
|
||||
* and only one entry, then string, else array
|
||||
* unless single is true
|
||||
*/
|
||||
function getQueryStringParam(search = '', query = '', single = false)
|
||||
{
|
||||
@@ -75,4 +69,74 @@ function getQueryStringParam(search = '', query = '', single = false)
|
||||
return param;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if key exists as URL parameter
|
||||
* @param {String} key URL parameter to search
|
||||
* @returns {Boolean} True if key exists
|
||||
*/
|
||||
function hasUrlParameter(key)
|
||||
{
|
||||
var urlParams = new URLSearchParams(window.location.search);
|
||||
return urlParams.has(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return one value for a URL paramter or null if not found
|
||||
* @param {String} key Which URL parameter to get
|
||||
* @returns {String|Null} URL parameter content
|
||||
*/
|
||||
function getUrlParameter(key)
|
||||
{
|
||||
var urlParams = new URLSearchParams(window.location.search);
|
||||
return urlParams.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or update a query parameter in the current URL and update the browser's address bar
|
||||
* @param {string} key - The parameter name to add or update
|
||||
* @param {string} value - The value to set for the parameter
|
||||
* @param {boolean} [reload=false] - Whether to reload the page after updating the URL
|
||||
*/
|
||||
function updateUrlParameter(key, value, reload = false)
|
||||
{
|
||||
// Create a URL object from the current URL
|
||||
const url = new URL(window.location.href);
|
||||
|
||||
// Set or update the parameter
|
||||
url.searchParams.set(key, value);
|
||||
|
||||
const newUrl = url.toString();
|
||||
|
||||
// Update the browser's address bar without reloading the page
|
||||
window.history.pushState({ path: newUrl }, '', newUrl);
|
||||
|
||||
// Optionally reload the page
|
||||
if (reload) {
|
||||
// window.location.href = newUrl;
|
||||
window.location.reload();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a parameter from the current URL and update the browser's address bar
|
||||
* @param {string} key - The parameter name to remove
|
||||
* @param {boolean} [reload=false] - Whether to reload the page after updating the URL
|
||||
*/
|
||||
function removeUrlParameter(key, reload = false)
|
||||
{
|
||||
// Create a URL object from the current URL
|
||||
const url = new URL(window.location.href);
|
||||
|
||||
// Remove the parameter if it exists
|
||||
url.searchParams.delete(key);
|
||||
|
||||
// Update the browser's address bar without reloading the page
|
||||
window.history.pushState({}, '', url.toString());
|
||||
|
||||
// Optionally reload the page
|
||||
if (reload) {
|
||||
window.location.reload();
|
||||
}
|
||||
}
|
||||
|
||||
// __EMD__
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
Description: Translation call
|
||||
Date: 2025//3/6
|
||||
Date: 2025/3/6
|
||||
Creator: Clemens Schwaighofer
|
||||
*/
|
||||
|
||||
|
||||
@@ -5,6 +5,8 @@ import {
|
||||
// isFunction,
|
||||
// executeFunctionByName,
|
||||
isObject,
|
||||
isArray,
|
||||
isIterable,
|
||||
getObjectCount,
|
||||
keyInObject,
|
||||
objectKeyExists,
|
||||
@@ -30,15 +32,57 @@ describe("isObject", () => {
|
||||
let is_object = {
|
||||
"a": 1
|
||||
};
|
||||
let empty_array = [];
|
||||
let is_array = [1, 2, 3];
|
||||
let is_string = "";
|
||||
let is_number = 1;
|
||||
expect(isObject(empty_object)).toEqual(true);
|
||||
expect(isObject(is_object)).toEqual(true);
|
||||
expect(isObject(empty_array)).toEqual(false);
|
||||
expect(isObject(is_array)).toEqual(false);
|
||||
expect(isObject(is_string)).toEqual(false);
|
||||
expect(isObject(is_number)).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("isArray", () => {
|
||||
it('should return bool if array', () => {
|
||||
let empty_object = {};
|
||||
let is_object = {
|
||||
"a": 1
|
||||
};
|
||||
let empty_array = [];
|
||||
let is_array = [1, 2, 3];
|
||||
let is_string = "";
|
||||
let is_number = 1;
|
||||
expect(isArray(empty_object)).toEqual(false);
|
||||
expect(isArray(is_object)).toEqual(false);
|
||||
expect(isArray(empty_array)).toEqual(true);
|
||||
expect(isArray(is_array)).toEqual(true);
|
||||
expect(isArray(is_string)).toEqual(false);
|
||||
expect(isArray(is_number)).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("isIterable", () => {
|
||||
it('should return bool if iterable', () => {
|
||||
let empty_object = {};
|
||||
let is_object = {
|
||||
"a": 1
|
||||
};
|
||||
let empty_array = [];
|
||||
let is_array = [1, 2, 3];
|
||||
let is_string = "";
|
||||
let is_number = 1;
|
||||
expect(isIterable(empty_object)).toEqual(true);
|
||||
expect(isIterable(is_object)).toEqual(true);
|
||||
expect(isIterable(empty_array)).toEqual(true);
|
||||
expect(isIterable(is_array)).toEqual(true);
|
||||
expect(isIterable(is_string)).toEqual(false);
|
||||
expect(isIterable(is_number)).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getObjectCount", () => {
|
||||
it('should return count of objects', () => {
|
||||
let zero = {};
|
||||
|
||||
@@ -3,6 +3,7 @@ import { defineConfig } from 'vitest/config';
|
||||
|
||||
export default defineConfig({
|
||||
test: {
|
||||
environment: 'jsdom',
|
||||
include: [
|
||||
'tests/**/*.{test,spec}.?(c|m)[jt]s?(x)'
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user