6 Commits

Author SHA1 Message Date
c818e56f3e Test fixes for UrlParser, HtmlElementCreator
All checks were successful
CI / ci-tests (push) Successful in 15s
Also fix old parseQueryString and alias it to getQueryStringParam
2025-03-10 19:33:44 +09:00
41e794b35d Node vesion 23 for github actions
All checks were successful
CI / ci-tests (push) Successful in 23s
2025-03-10 18:56:43 +09:00
1a3faad442 Github actions
All checks were successful
CI / ci-tests (push) Successful in 1m13s
2025-03-10 18:54:51 +09:00
f9d771f079 Add coverage report and basic vitest settings
Set tests folder and coverage settings, update run commands for tests
2025-03-10 17:29:07 +09:00
df94f864cf Readme update with covered tests 2025-03-10 17:07:27 +09:00
2f9333da54 Add testing for HtmlElementCreator and fix ...args calls
All args passthrough class where missing the leading "..."

Added Testing to HtmlElementCreator
2025-03-10 17:02:17 +09:00
15 changed files with 1601 additions and 54 deletions

23
.github/workflows/ci.yml vendored Normal file
View File

@@ -0,0 +1,23 @@
name: CI
run-name: ${{ github.actor}} runs CI
# on:
# pull_request:
# branches:
# - main
on: [push]
jobs:
ci-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 23
- name: Run `npm install`
run: |
npm install
- name: Run vitest and report issues
run: npm run test:run

1
.gitignore vendored
View File

@@ -1 +1,2 @@
node_modules/
coverage/*

View File

@@ -141,6 +141,18 @@ vitest is used for all usage tests
npx vitest
```
for one stop tests
```sh
npm run test:run
```
To show the full coverate (of all files)
```sh
npm run test:coverage
```
Currently covered:
- FormatBytes
@@ -149,6 +161,7 @@ Currently covered:
- UniqIdGenerators (Part)
- UrlParser
- JavaScriptHelpers
- HtmlElementCreator
TODO:

View File

@@ -4,12 +4,17 @@
<script type="text/javascript" src="js/general/jquery.min.js"></script>
<!-- <script type="text/javascript" src="js/general/translateTest-ja_JP.UTF-8.js"></script> -->
<script type="text/javascript" src="js/output/utils.min.js"></script>
<!-- <script type="text/javascript" src="js/output/utils.js"></script> -->
</head>
<body>
<div>
<h1>JavaScript Utils Test</h1>
<div id="test-div">
</div>
<div><hr></div>
<div id="build-test">
</div>
<div><hr></div>
</div>
</body>
<script languagae="JavaScript">
@@ -17,6 +22,7 @@
document.addEventListener('DOMContentLoaded', function() {
console.log('JavaScript Utils Test');
let el = document.getElementById('test-div');
let build_test = document.getElementById('build-test');
if (el === null) {
throw new Error("element test-div not found");
}
@@ -30,6 +36,27 @@ document.addEventListener('DOMContentLoaded', function() {
el.innerHTML += '<div>formatBytes: ' + formatBytes(bytes) + '</div>';
el.innerHTML += '<div>formatBytesLong: ' + formatBytesLong(bytes) + '</div>';
let cel_test = cel('div', 'sample-id', 'Some text', ['css-sample']);
el.innerHTML += '<div>cel: ' + JSON.stringify(cel_test) + '</div>';
let cel_out = phfo(cel_test);
console.log('CEL OUT: %o', cel_out);
build_test.innerHTML = cel_out;
//
let aelx_test = aelx(
cel('div', 'container-id', '', ['container-css']),
cel('div', 'entry-a-id', 'Entry block: A'),
cel('div', 'entry-b-id', 'Entry block: B')
);
el.innerHTML += '<div>aelx: ' + JSON.stringify(aelx_test) + '</div>';
let aelx_out = phfo(aelx_test);
console.log('AELX OUT: %o', aelx_out);
build_test.innerHTML += aelx_out;
// console.log("TEST URL: %o", parseQueryString("http://foor.org/?key=value"));
console.log("TEST URL: %o", getQueryStringParam('', "http://foor.org/?param=foo&param=other", true));
console.log("TEST URL: %o", parseQueryString("http://foor.org/?param=foo&param=other", ''));
// console.log("TEST URL: %o", getQueryStringParam('', "http://foor.org/?key=value&key=other&key=value&bar="));
// console.log('TR: %s', l10n.__('Original'));
// console.log('TR: %s', l10n.__('Not exists'));
});

706
package-lock.json generated
View File

@@ -10,12 +10,87 @@
"devDependencies": {
"@eslint/js": "^9.20.0",
"@types/jquery": "^3.5.32",
"@vitest/coverage-v8": "^3.0.8",
"esbuild": "^0.25.0",
"eslint": "^9.20.1",
"globals": "^15.15.0",
"vitest": "^3.0.8"
}
},
"node_modules/@ampproject/remapping": {
"version": "2.3.0",
"resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.3.0.tgz",
"integrity": "sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw==",
"dev": true,
"license": "Apache-2.0",
"dependencies": {
"@jridgewell/gen-mapping": "^0.3.5",
"@jridgewell/trace-mapping": "^0.3.24"
},
"engines": {
"node": ">=6.0.0"
}
},
"node_modules/@babel/helper-string-parser": {
"version": "7.25.9",
"resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.25.9.tgz",
"integrity": "sha512-4A/SCr/2KLd5jrtOMFzaKjVtAei3+2r/NChoBNoZ3EyP/+GlhoaEGoWOZUmFmoITP7zOJyHIMm+DYRd8o3PvHA==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/helper-validator-identifier": {
"version": "7.25.9",
"resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.25.9.tgz",
"integrity": "sha512-Ed61U6XJc3CVRfkERJWDz4dJwKe7iLmmJsbOGu9wSloNSFttHV0I8g6UAgb7qnK5ly5bGLPd4oXZlxCdANBOWQ==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@babel/parser": {
"version": "7.26.9",
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.26.9.tgz",
"integrity": "sha512-81NWa1njQblgZbQHxWHpxxCzNsa3ZwvFqpUg7P+NNUU6f3UU2jBEg4OlF/J6rl8+PQGh1q6/zWScd001YwcA5A==",
"dev": true,
"license": "MIT",
"dependencies": {
"@babel/types": "^7.26.9"
},
"bin": {
"parser": "bin/babel-parser.js"
},
"engines": {
"node": ">=6.0.0"
}
},
"node_modules/@babel/types": {
"version": "7.26.9",
"resolved": "https://registry.npmjs.org/@babel/types/-/types-7.26.9.tgz",
"integrity": "sha512-Y3IR1cRnOxOCDvMmNiym7XpXQ93iGDDPHx+Zj+NM+rg0fBaShfQLkg+hKPaZCEvg5N/LeCo4+Rj/i3FuJsIQaw==",
"dev": true,
"license": "MIT",
"dependencies": {
"@babel/helper-string-parser": "^7.25.9",
"@babel/helper-validator-identifier": "^7.25.9"
},
"engines": {
"node": ">=6.9.0"
}
},
"node_modules/@bcoe/v8-coverage": {
"version": "1.0.2",
"resolved": "https://registry.npmjs.org/@bcoe/v8-coverage/-/v8-coverage-1.0.2.tgz",
"integrity": "sha512-6zABk/ECA/QYSCQ1NGiVwwbQerUCZ+TQbp64Q3AgmfNvurHH0j8TtXa1qbShXA6qqkpAj4V5W8pP6mLe1mcMqA==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=18"
}
},
"node_modules/@esbuild/aix-ppc64": {
"version": "0.25.0",
"resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.25.0.tgz",
@@ -648,6 +723,69 @@
"url": "https://github.com/sponsors/nzakas"
}
},
"node_modules/@isaacs/cliui": {
"version": "8.0.2",
"resolved": "https://registry.npmjs.org/@isaacs/cliui/-/cliui-8.0.2.tgz",
"integrity": "sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==",
"dev": true,
"license": "ISC",
"dependencies": {
"string-width": "^5.1.2",
"string-width-cjs": "npm:string-width@^4.2.0",
"strip-ansi": "^7.0.1",
"strip-ansi-cjs": "npm:strip-ansi@^6.0.1",
"wrap-ansi": "^8.1.0",
"wrap-ansi-cjs": "npm:wrap-ansi@^7.0.0"
},
"engines": {
"node": ">=12"
}
},
"node_modules/@istanbuljs/schema": {
"version": "0.1.3",
"resolved": "https://registry.npmjs.org/@istanbuljs/schema/-/schema-0.1.3.tgz",
"integrity": "sha512-ZXRY4jNvVgSVQ8DL3LTcakaAtXwTVUxE81hslsyD2AtoXW/wVob10HkOJ1X/pAlcI7D+2YoZKg5do8G/w6RYgA==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=8"
}
},
"node_modules/@jridgewell/gen-mapping": {
"version": "0.3.8",
"resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.8.tgz",
"integrity": "sha512-imAbBGkb+ebQyxKgzv5Hu2nmROxoDOXHh80evxdoXNOrvAnVx7zimzc1Oo5h9RlfV4vPXaE2iM5pOFbvOCClWA==",
"dev": true,
"license": "MIT",
"dependencies": {
"@jridgewell/set-array": "^1.2.1",
"@jridgewell/sourcemap-codec": "^1.4.10",
"@jridgewell/trace-mapping": "^0.3.24"
},
"engines": {
"node": ">=6.0.0"
}
},
"node_modules/@jridgewell/resolve-uri": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz",
"integrity": "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=6.0.0"
}
},
"node_modules/@jridgewell/set-array": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/@jridgewell/set-array/-/set-array-1.2.1.tgz",
"integrity": "sha512-R8gLRTZeyp03ymzP/6Lil/28tGeGEzhx1q2k703KGWRAI1VdvPIXdG70VJc2pAMw3NA6JKL5hhFu1sJX0Mnn/A==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=6.0.0"
}
},
"node_modules/@jridgewell/sourcemap-codec": {
"version": "1.5.0",
"resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.0.tgz",
@@ -655,6 +793,28 @@
"dev": true,
"license": "MIT"
},
"node_modules/@jridgewell/trace-mapping": {
"version": "0.3.25",
"resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.25.tgz",
"integrity": "sha512-vNk6aEwybGtawWmy/PzwnGDOjCkLWSD2wqvjGGAgOAwCGWySYXfYoxt00IJkTF+8Lb57DwOb3Aa0o9CApepiYQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"@jridgewell/resolve-uri": "^3.1.0",
"@jridgewell/sourcemap-codec": "^1.4.14"
}
},
"node_modules/@pkgjs/parseargs": {
"version": "0.11.0",
"resolved": "https://registry.npmjs.org/@pkgjs/parseargs/-/parseargs-0.11.0.tgz",
"integrity": "sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==",
"dev": true,
"license": "MIT",
"optional": true,
"engines": {
"node": ">=14"
}
},
"node_modules/@rollup/rollup-android-arm-eabi": {
"version": "4.34.9",
"resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.34.9.tgz",
@@ -952,6 +1112,39 @@
"dev": true,
"license": "MIT"
},
"node_modules/@vitest/coverage-v8": {
"version": "3.0.8",
"resolved": "https://registry.npmjs.org/@vitest/coverage-v8/-/coverage-v8-3.0.8.tgz",
"integrity": "sha512-y7SAKsQirsEJ2F8bulBck4DoluhI2EEgTimHd6EEUgJBGKy9tC25cpywh1MH4FvDGoG2Unt7+asVd1kj4qOSAw==",
"dev": true,
"license": "MIT",
"dependencies": {
"@ampproject/remapping": "^2.3.0",
"@bcoe/v8-coverage": "^1.0.2",
"debug": "^4.4.0",
"istanbul-lib-coverage": "^3.2.2",
"istanbul-lib-report": "^3.0.1",
"istanbul-lib-source-maps": "^5.0.6",
"istanbul-reports": "^3.1.7",
"magic-string": "^0.30.17",
"magicast": "^0.3.5",
"std-env": "^3.8.0",
"test-exclude": "^7.0.1",
"tinyrainbow": "^2.0.0"
},
"funding": {
"url": "https://opencollective.com/vitest"
},
"peerDependencies": {
"@vitest/browser": "3.0.8",
"vitest": "3.0.8"
},
"peerDependenciesMeta": {
"@vitest/browser": {
"optional": true
}
}
},
"node_modules/@vitest/expect": {
"version": "3.0.8",
"resolved": "https://registry.npmjs.org/@vitest/expect/-/expect-3.0.8.tgz",
@@ -1105,6 +1298,19 @@
"url": "https://github.com/sponsors/epoberezkin"
}
},
"node_modules/ansi-regex": {
"version": "6.1.0",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.1.0.tgz",
"integrity": "sha512-7HSX4QQb4CspciLpVFwyRe79O3xsIZDDLER21kERQ71oaPodF8jL725AgJMFAYbooIqolJoRLuM81SpeUkpkvA==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://github.com/chalk/ansi-regex?sponsor=1"
}
},
"node_modules/ansi-styles": {
"version": "4.3.0",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
@@ -1297,6 +1503,20 @@
"dev": true,
"license": "MIT"
},
"node_modules/eastasianwidth": {
"version": "0.2.0",
"resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz",
"integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==",
"dev": true,
"license": "MIT"
},
"node_modules/emoji-regex": {
"version": "9.2.2",
"resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-9.2.2.tgz",
"integrity": "sha512-L18DaJsXSUk2+42pv8mLs5jJT2hqFkFE4j21wOmgbUqsZ2hL72NsUU785g9RXgo3s0ZNgVl42TiHp3ZtOv/Vyg==",
"dev": true,
"license": "MIT"
},
"node_modules/es-module-lexer": {
"version": "1.6.0",
"resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-1.6.0.tgz",
@@ -1604,6 +1824,23 @@
"dev": true,
"license": "ISC"
},
"node_modules/foreground-child": {
"version": "3.3.1",
"resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-3.3.1.tgz",
"integrity": "sha512-gIXjKqtFuWEgzFRJA9WCQeSJLZDjgJUOMCMzxtvFq/37KojM1BFGufqsCy0r4qSQmYLsZYMeyRqzIWOMup03sw==",
"dev": true,
"license": "ISC",
"dependencies": {
"cross-spawn": "^7.0.6",
"signal-exit": "^4.0.1"
},
"engines": {
"node": ">=14"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/fsevents": {
"version": "2.3.3",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz",
@@ -1619,6 +1856,27 @@
"node": "^8.16.0 || ^10.6.0 || >=11.0.0"
}
},
"node_modules/glob": {
"version": "10.4.5",
"resolved": "https://registry.npmjs.org/glob/-/glob-10.4.5.tgz",
"integrity": "sha512-7Bv8RF0k6xjo7d4A/PxYLbUCfb6c+Vpd2/mB2yRDlew7Jb5hEXiCD9ibfO7wpk8i4sevK6DFny9h7EYbM3/sHg==",
"dev": true,
"license": "ISC",
"dependencies": {
"foreground-child": "^3.1.0",
"jackspeak": "^3.1.2",
"minimatch": "^9.0.4",
"minipass": "^7.1.2",
"package-json-from-dist": "^1.0.0",
"path-scurry": "^1.11.1"
},
"bin": {
"glob": "dist/esm/bin.mjs"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/glob-parent": {
"version": "6.0.2",
"resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-6.0.2.tgz",
@@ -1632,6 +1890,32 @@
"node": ">=10.13.0"
}
},
"node_modules/glob/node_modules/brace-expansion": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz",
"integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==",
"dev": true,
"license": "MIT",
"dependencies": {
"balanced-match": "^1.0.0"
}
},
"node_modules/glob/node_modules/minimatch": {
"version": "9.0.5",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz",
"integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==",
"dev": true,
"license": "ISC",
"dependencies": {
"brace-expansion": "^2.0.1"
},
"engines": {
"node": ">=16 || 14 >=14.17"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/globals": {
"version": "15.15.0",
"resolved": "https://registry.npmjs.org/globals/-/globals-15.15.0.tgz",
@@ -1655,6 +1939,13 @@
"node": ">=8"
}
},
"node_modules/html-escaper": {
"version": "2.0.2",
"resolved": "https://registry.npmjs.org/html-escaper/-/html-escaper-2.0.2.tgz",
"integrity": "sha512-H2iMtd0I4Mt5eYiapRdIDjp+XzelXQ0tFE4JS7YFwFevXXMmOp9myNrUvCg0D6ws8iqkRPBfKHgbwig1SmlLfg==",
"dev": true,
"license": "MIT"
},
"node_modules/ignore": {
"version": "5.3.2",
"resolved": "https://registry.npmjs.org/ignore/-/ignore-5.3.2.tgz",
@@ -1702,6 +1993,16 @@
"node": ">=0.10.0"
}
},
"node_modules/is-fullwidth-code-point": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz",
"integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=8"
}
},
"node_modules/is-glob": {
"version": "4.0.3",
"resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz",
@@ -1722,6 +2023,76 @@
"dev": true,
"license": "ISC"
},
"node_modules/istanbul-lib-coverage": {
"version": "3.2.2",
"resolved": "https://registry.npmjs.org/istanbul-lib-coverage/-/istanbul-lib-coverage-3.2.2.tgz",
"integrity": "sha512-O8dpsF+r0WV/8MNRKfnmrtCWhuKjxrq2w+jpzBL5UZKTi2LeVWnWOmWRxFlesJONmc+wLAGvKQZEOanko0LFTg==",
"dev": true,
"license": "BSD-3-Clause",
"engines": {
"node": ">=8"
}
},
"node_modules/istanbul-lib-report": {
"version": "3.0.1",
"resolved": "https://registry.npmjs.org/istanbul-lib-report/-/istanbul-lib-report-3.0.1.tgz",
"integrity": "sha512-GCfE1mtsHGOELCU8e/Z7YWzpmybrx/+dSTfLrvY8qRmaY6zXTKWn6WQIjaAFw069icm6GVMNkgu0NzI4iPZUNw==",
"dev": true,
"license": "BSD-3-Clause",
"dependencies": {
"istanbul-lib-coverage": "^3.0.0",
"make-dir": "^4.0.0",
"supports-color": "^7.1.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/istanbul-lib-source-maps": {
"version": "5.0.6",
"resolved": "https://registry.npmjs.org/istanbul-lib-source-maps/-/istanbul-lib-source-maps-5.0.6.tgz",
"integrity": "sha512-yg2d+Em4KizZC5niWhQaIomgf5WlL4vOOjZ5xGCmF8SnPE/mDWWXgvRExdcpCgh9lLRRa1/fSYp2ymmbJ1pI+A==",
"dev": true,
"license": "BSD-3-Clause",
"dependencies": {
"@jridgewell/trace-mapping": "^0.3.23",
"debug": "^4.1.1",
"istanbul-lib-coverage": "^3.0.0"
},
"engines": {
"node": ">=10"
}
},
"node_modules/istanbul-reports": {
"version": "3.1.7",
"resolved": "https://registry.npmjs.org/istanbul-reports/-/istanbul-reports-3.1.7.tgz",
"integrity": "sha512-BewmUXImeuRk2YY0PVbxgKAysvhRPUQE0h5QRM++nVWyubKGV0l8qQ5op8+B2DOmwSe63Jivj0BjkPQVf8fP5g==",
"dev": true,
"license": "BSD-3-Clause",
"dependencies": {
"html-escaper": "^2.0.0",
"istanbul-lib-report": "^3.0.0"
},
"engines": {
"node": ">=8"
}
},
"node_modules/jackspeak": {
"version": "3.4.3",
"resolved": "https://registry.npmjs.org/jackspeak/-/jackspeak-3.4.3.tgz",
"integrity": "sha512-OGlZQpz2yfahA/Rd1Y8Cd9SIEsqvXkLVoSw/cgwhnhFMDbsQFeZYoJJ7bIZBS9BcamUW96asq/npPWugM+RQBw==",
"dev": true,
"license": "BlueOak-1.0.0",
"dependencies": {
"@isaacs/cliui": "^8.0.2"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
},
"optionalDependencies": {
"@pkgjs/parseargs": "^0.11.0"
}
},
"node_modules/js-yaml": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz",
@@ -1810,6 +2181,13 @@
"dev": true,
"license": "MIT"
},
"node_modules/lru-cache": {
"version": "10.4.3",
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-10.4.3.tgz",
"integrity": "sha512-JNAzZcXrCt42VGLuYz0zfAzDfAvJWW6AfYlDBQyDV5DClI2m5sAmK+OIO7s59XfsRsWHp02jAJrRadPRGTt6SQ==",
"dev": true,
"license": "ISC"
},
"node_modules/magic-string": {
"version": "0.30.17",
"resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.17.tgz",
@@ -1820,6 +2198,34 @@
"@jridgewell/sourcemap-codec": "^1.5.0"
}
},
"node_modules/magicast": {
"version": "0.3.5",
"resolved": "https://registry.npmjs.org/magicast/-/magicast-0.3.5.tgz",
"integrity": "sha512-L0WhttDl+2BOsybvEOLK7fW3UA0OQ0IQ2d6Zl2x/a6vVRs3bAY0ECOSHHeL5jD+SbOpOCUEi0y1DgHEn9Qn1AQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"@babel/parser": "^7.25.4",
"@babel/types": "^7.25.4",
"source-map-js": "^1.2.0"
}
},
"node_modules/make-dir": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/make-dir/-/make-dir-4.0.0.tgz",
"integrity": "sha512-hXdUTZYIVOt1Ex//jAQi+wTZZpUpwBj/0QsOzqegb3rGMMeJiSEu5xLHnYfBrRV4RH2+OCSOO95Is/7x1WJ4bw==",
"dev": true,
"license": "MIT",
"dependencies": {
"semver": "^7.5.3"
},
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/minimatch": {
"version": "3.1.2",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz",
@@ -1833,6 +2239,16 @@
"node": "*"
}
},
"node_modules/minipass": {
"version": "7.1.2",
"resolved": "https://registry.npmjs.org/minipass/-/minipass-7.1.2.tgz",
"integrity": "sha512-qOOzS1cBTWYF4BH8fVePDBOO9iptMnGUEZwNc/cMWnTV2nVLZ7VoNWEPHkYczZA0pdoA7dl6e7FL659nX9S2aw==",
"dev": true,
"license": "ISC",
"engines": {
"node": ">=16 || 14 >=14.17"
}
},
"node_modules/ms": {
"version": "2.1.3",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
@@ -1916,6 +2332,13 @@
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/package-json-from-dist": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/package-json-from-dist/-/package-json-from-dist-1.0.1.tgz",
"integrity": "sha512-UEZIS3/by4OC8vL3P2dTXRETpebLI2NiI5vIrjaD/5UtrkFX/tNbwjTSRAGC/+7CAo2pIcBaRgWmcBBHcsaCIw==",
"dev": true,
"license": "BlueOak-1.0.0"
},
"node_modules/parent-module": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz",
@@ -1949,6 +2372,23 @@
"node": ">=8"
}
},
"node_modules/path-scurry": {
"version": "1.11.1",
"resolved": "https://registry.npmjs.org/path-scurry/-/path-scurry-1.11.1.tgz",
"integrity": "sha512-Xa4Nw17FS9ApQFJ9umLiJS4orGjm7ZzwUrwamcGQuHSzDyth9boKDaycYdDcZDuqYATXw4HFXgaqWTctW/v1HA==",
"dev": true,
"license": "BlueOak-1.0.0",
"dependencies": {
"lru-cache": "^10.2.0",
"minipass": "^5.0.0 || ^6.0.2 || ^7.0.0"
},
"engines": {
"node": ">=16 || 14 >=14.18"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/pathe": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/pathe/-/pathe-2.0.3.tgz",
@@ -2071,6 +2511,19 @@
"fsevents": "~2.3.2"
}
},
"node_modules/semver": {
"version": "7.7.1",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.7.1.tgz",
"integrity": "sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA==",
"dev": true,
"license": "ISC",
"bin": {
"semver": "bin/semver.js"
},
"engines": {
"node": ">=10"
}
},
"node_modules/shebang-command": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz",
@@ -2101,6 +2554,19 @@
"dev": true,
"license": "ISC"
},
"node_modules/signal-exit": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-4.1.0.tgz",
"integrity": "sha512-bzyZ1e88w9O1iNJbKnOlvYTrWPDl46O1bG0D3XInv+9tkPrxrN8jUUTiFlDkkmKWgn1M6CfIA13SuGqOa9Korw==",
"dev": true,
"license": "ISC",
"engines": {
"node": ">=14"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/source-map-js": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.1.tgz",
@@ -2125,6 +2591,110 @@
"dev": true,
"license": "MIT"
},
"node_modules/string-width": {
"version": "5.1.2",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-5.1.2.tgz",
"integrity": "sha512-HnLOCR3vjcY8beoNLtcjZ5/nxn2afmME6lhrDrebokqMap+XbeW8n9TXpPDOqdGK5qcI3oT0GKTW6wC7EMiVqA==",
"dev": true,
"license": "MIT",
"dependencies": {
"eastasianwidth": "^0.2.0",
"emoji-regex": "^9.2.2",
"strip-ansi": "^7.0.1"
},
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
},
"node_modules/string-width-cjs": {
"name": "string-width",
"version": "4.2.3",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
"integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",
"dev": true,
"license": "MIT",
"dependencies": {
"emoji-regex": "^8.0.0",
"is-fullwidth-code-point": "^3.0.0",
"strip-ansi": "^6.0.1"
},
"engines": {
"node": ">=8"
}
},
"node_modules/string-width-cjs/node_modules/ansi-regex": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=8"
}
},
"node_modules/string-width-cjs/node_modules/emoji-regex": {
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz",
"integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==",
"dev": true,
"license": "MIT"
},
"node_modules/string-width-cjs/node_modules/strip-ansi": {
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
"integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==",
"dev": true,
"license": "MIT",
"dependencies": {
"ansi-regex": "^5.0.1"
},
"engines": {
"node": ">=8"
}
},
"node_modules/strip-ansi": {
"version": "7.1.0",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz",
"integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"ansi-regex": "^6.0.1"
},
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://github.com/chalk/strip-ansi?sponsor=1"
}
},
"node_modules/strip-ansi-cjs": {
"name": "strip-ansi",
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
"integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==",
"dev": true,
"license": "MIT",
"dependencies": {
"ansi-regex": "^5.0.1"
},
"engines": {
"node": ">=8"
}
},
"node_modules/strip-ansi-cjs/node_modules/ansi-regex": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=8"
}
},
"node_modules/strip-json-comments": {
"version": "3.1.1",
"resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz",
@@ -2151,6 +2721,47 @@
"node": ">=8"
}
},
"node_modules/test-exclude": {
"version": "7.0.1",
"resolved": "https://registry.npmjs.org/test-exclude/-/test-exclude-7.0.1.tgz",
"integrity": "sha512-pFYqmTw68LXVjeWJMST4+borgQP2AyMNbg1BpZh9LbyhUeNkeaPF9gzfPGUAnSMV3qPYdWUwDIjjCLiSDOl7vg==",
"dev": true,
"license": "ISC",
"dependencies": {
"@istanbuljs/schema": "^0.1.2",
"glob": "^10.4.1",
"minimatch": "^9.0.4"
},
"engines": {
"node": ">=18"
}
},
"node_modules/test-exclude/node_modules/brace-expansion": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz",
"integrity": "sha512-XnAIvQ8eM+kC6aULx6wuQiwVsnzsi9d3WxzV3FpWTGA19F621kwdbsAcFKXgKUHZWsy+mY6iL1sHTxWEFCytDA==",
"dev": true,
"license": "MIT",
"dependencies": {
"balanced-match": "^1.0.0"
}
},
"node_modules/test-exclude/node_modules/minimatch": {
"version": "9.0.5",
"resolved": "https://registry.npmjs.org/minimatch/-/minimatch-9.0.5.tgz",
"integrity": "sha512-G6T0ZX48xgozx7587koeX9Ys2NYy6Gmv//P89sEte9V9whIapMNF4idKxnW2QtCcLiTWlb/wfCabAtAFWhhBow==",
"dev": true,
"license": "ISC",
"dependencies": {
"brace-expansion": "^2.0.1"
},
"engines": {
"node": ">=16 || 14 >=14.17"
},
"funding": {
"url": "https://github.com/sponsors/isaacs"
}
},
"node_modules/tinybench": {
"version": "2.9.0",
"resolved": "https://registry.npmjs.org/tinybench/-/tinybench-2.9.0.tgz",
@@ -2426,6 +3037,101 @@
"node": ">=0.10.0"
}
},
"node_modules/wrap-ansi": {
"version": "8.1.0",
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-8.1.0.tgz",
"integrity": "sha512-si7QWI6zUMq56bESFvagtmzMdGOtoxfR+Sez11Mobfc7tm+VkUckk9bW2UeffTGVUbOksxmSw0AA2gs8g71NCQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"ansi-styles": "^6.1.0",
"string-width": "^5.0.1",
"strip-ansi": "^7.0.1"
},
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://github.com/chalk/wrap-ansi?sponsor=1"
}
},
"node_modules/wrap-ansi-cjs": {
"name": "wrap-ansi",
"version": "7.0.0",
"resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-7.0.0.tgz",
"integrity": "sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==",
"dev": true,
"license": "MIT",
"dependencies": {
"ansi-styles": "^4.0.0",
"string-width": "^4.1.0",
"strip-ansi": "^6.0.0"
},
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/chalk/wrap-ansi?sponsor=1"
}
},
"node_modules/wrap-ansi-cjs/node_modules/ansi-regex": {
"version": "5.0.1",
"resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz",
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=8"
}
},
"node_modules/wrap-ansi-cjs/node_modules/emoji-regex": {
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz",
"integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==",
"dev": true,
"license": "MIT"
},
"node_modules/wrap-ansi-cjs/node_modules/string-width": {
"version": "4.2.3",
"resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz",
"integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==",
"dev": true,
"license": "MIT",
"dependencies": {
"emoji-regex": "^8.0.0",
"is-fullwidth-code-point": "^3.0.0",
"strip-ansi": "^6.0.1"
},
"engines": {
"node": ">=8"
}
},
"node_modules/wrap-ansi-cjs/node_modules/strip-ansi": {
"version": "6.0.1",
"resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz",
"integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==",
"dev": true,
"license": "MIT",
"dependencies": {
"ansi-regex": "^5.0.1"
},
"engines": {
"node": ">=8"
}
},
"node_modules/wrap-ansi/node_modules/ansi-styles": {
"version": "6.2.1",
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-6.2.1.tgz",
"integrity": "sha512-bN798gFfQX+viw3R7yrGWRqnrN2oRkEkUjjl4JNn4E8GxxbjtG3FbrEIIY3l8/hrwUwIeCZvi4QuOTP4MErVug==",
"dev": true,
"license": "MIT",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
}
},
"node_modules/yocto-queue": {
"version": "0.1.0",
"resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz",

View File

@@ -4,11 +4,13 @@
"main": "",
"scripts": {
"test": "vitest",
"coverage": "vitest run --coverage",
"test:run": "vitest run",
"test:coverage": "vitest run --coverage",
"utils-min-build": "node_modules/esbuild/bin/esbuild utils.min=src/utils.mjs --outdir=build/js/output/ --format=esm --bundle --charset=utf8 --tree-shaking=false --minify-whitespace --minify-syntax --sourcemap",
"utils-build": "node_modules/esbuild/bin/esbuild utils=src/utils.mjs --outdir=build/js/output/ --format=esm --bundle --charset=utf8 --tree-shaking=false",
"utils-build-all": "npm run utils-min-build && npm run utils-build",
"utils-develop": "node_modules/esbuild/bin/esbuild utils=src/utils.mjs --outdir=build/js/output/ --format=esm --bundle --charset=utf8 --tree-shaking=false --watch"
"utils-develop": "node_modules/esbuild/bin/esbuild utils=src/utils.mjs --outdir=build/js/output/ --format=esm --bundle --charset=utf8 --tree-shaking=false --watch",
"utils-min-develop": "node_modules/esbuild/bin/esbuild utils.min=src/utils.mjs --outdir=build/js/output/ --format=esm --bundle --charset=utf8 --tree-shaking=false --minify-whitespace --minify-syntax --sourcemap --watch"
},
"author": "Clemens Schwaighofer",
"license": "",
@@ -16,6 +18,7 @@
"devDependencies": {
"@eslint/js": "^9.20.0",
"@types/jquery": "^3.5.32",
"@vitest/coverage-v8": "^3.0.8",
"esbuild": "^0.25.0",
"eslint": "^9.20.1",
"globals": "^15.15.0",

View File

@@ -197,7 +197,7 @@ function roundPrecision(number, prec) // eslint-disable-line no-unused-vars
// @ts-ignore
function formatString(string, ...args) // eslint-disable-line no-unused-vars
{
return _formatString(string, args);
return _formatString(string, ...args);
}
/**
@@ -775,7 +775,7 @@ function ael(base, attach, id = '') // eslint-disable-line no-unused-vars
// @ts-ignore
function aelx(base, ...attach) // eslint-disable-line no-unused-vars
{
return hec.aelx(base, attach);
return hec.aelx(base, ...attach);
}
/**

View File

@@ -19,6 +19,9 @@ function formatBytes(bytes)
if (typeof bytes === "bigint") {
bytes = Number(bytes);
}
if (isNaN(bytes)) {
return bytes.toString();
}
do {
bytes = bytes / 1024;
i++;

View File

@@ -26,7 +26,8 @@ class HtmlElementCreator {
return {
tag: tag,
id: id,
name: options.name, // override name if set [name gets ignored in tree build anyway]
// override name if set, else id is used. Only for input/button
name: options.name,
content: content,
css: css,
options: options,
@@ -46,7 +47,6 @@ class HtmlElementCreator {
if (id) {
// base id match already
if (base.id == id) {
// base.sub.push(Object.assign({}, attach));
base.sub.push(deepCopyFunction(attach));
} else {
// sub check
@@ -58,7 +58,6 @@ class HtmlElementCreator {
}
}
} else {
// base.sub.push(Object.assign({}, attach));
base.sub.push(deepCopyFunction(attach));
}
return base;
@@ -74,7 +73,6 @@ class HtmlElementCreator {
aelx(base, ...attach)
{
for (var i = 0; i < attach.length; i ++) {
// base.sub.push(Object.assign({}, attach[i]));
base.sub.push(deepCopyFunction(attach[i]));
}
return base;
@@ -90,7 +88,6 @@ class HtmlElementCreator {
aelxar(base, attach)
{
for (var i = 0; i < attach.length; i ++) {
// base.sub.push(Object.assign({}, attach[i]));
base.sub.push(deepCopyFunction(attach[i]));
}
return base;
@@ -149,6 +146,7 @@ class HtmlElementCreator {
{
this.rcssel(_element, rcss);
this.acssel(_element, acss);
return _element;
}
/**

View File

@@ -5,9 +5,10 @@ Creator: Clemens Schwaighofer
*/
export { parseQueryString, getQueryStringParam };
import { keyInObject } from './JavaScriptHelpers.mjs';
/**
* NOTE: this original code was wrong, now using URL and parsing through
* getQueryStringParam
* parses a query string from window.location.search.substring(1)
* ALTERNATIVE CODE
* var url = new URL(window.location.href);
@@ -16,44 +17,13 @@ import { keyInObject } from './JavaScriptHelpers.mjs';
* 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 = '')
function parseQueryString(query = '', return_key = '', single = false)
{
if (!query) {
query = window.location.search.substring(1);
}
var vars = query.split('&');
var query_string = {};
for (var i = 0; i < vars.length; i++) {
var pair = vars[i].split('=');
var key = decodeURIComponent(pair[0]);
var value = decodeURIComponent(pair[1]);
// skip over run if there is nothing
if (!key || value === 'undefined') {
continue;
}
// If first entry with this name
if (typeof query_string[key] === 'undefined') {
query_string[key] = decodeURIComponent(value);
// If second entry with this name
} else if (typeof query_string[key] === 'string') {
var arr = [query_string[key], decodeURIComponent(value)];
query_string[key] = arr;
// If third or later entry with this name
} else {
query_string[key].push(decodeURIComponent(value));
}
}
if (return_key) {
if (keyInObject(return_key, query_string)) {
return query_string[return_key];
} else {
return '';
}
} else {
return query_string;
}
return getQueryStringParam(return_key, query, single);
}
/**

View File

@@ -7,6 +7,11 @@ import {
} from '../src/utils/FormatBytes.mjs';
let bytes_map = [
{
"in": "120MB",
"out": "120MB",
"out_l": "120MB",
},
{
"in": -123123123,
"out": "-120237.42kB",
@@ -57,6 +62,7 @@ describe("formatBytes", () => {
it('convert bytes to human readable, round up to next set', () => {
// expect(formatBytes(1021152)).toBe('0.97MB');
for (const bytes of bytes_map) {
// @ts-ignore
expect(formatBytes(bytes.in)).toBe(bytes.out);
}
});
@@ -66,6 +72,7 @@ describe("formatBytesLong", () => {
it('convert bytes to human readable, keep on current set', () => {
expect(formatBytesLong(1021152)).toBe('997.22 KB');
for (const bytes of bytes_map) {
// @ts-ignore
expect(formatBytesLong(bytes.in)).toBe(bytes.out_l);
}
});

View File

@@ -0,0 +1,693 @@
import { describe, it, expect } from "vitest";
import {
HtmlElementCreator
} from '../src/utils/HtmlElementCreator.mjs';
let hec = new HtmlElementCreator();
/*
A cel object
{
"content": "",
"css": [],
"id": "",
"name": undefined,
"options": {},
"sub": [],
"tag": ""
};
*/
/**
* build cel block
* auto set default if undefined in the in object
* @param {Object} cel_in array for creating one entry
* @returns {Object}
*/
function celCreate(cel_in)
{
let cel_out;
if (cel_in.id === undefined) {
cel_out = hec.cel(cel_in.tag);
} else if (cel_in.content === undefined) {
cel_out = hec.cel(
cel_in.tag,
cel_in.id,
);
} else if (cel_in.css === undefined) {
cel_out = cel_out = hec.cel(
cel_in.tag,
cel_in.id,
cel_in.content,
);
} else if (cel_in.options === undefined) {
cel_out = cel_out = hec.cel(
cel_in.tag,
cel_in.id,
cel_in.content,
cel_in.css,
);
} else {
cel_out = hec.cel(
cel_in.tag,
cel_in.id,
cel_in.content,
cel_in.css,
cel_in.options
);
}
return cel_out;
}
describe("cel", () => {
it('should create HTML Element block and return an Object', () => {
// test list for various calls
let cel_list = [
{
"id": "tag only",
"in": {
"tag": "div",
},
"out": {
"content": "",
"css": [],
"id": "",
"name": undefined,
"options": {},
"sub": [],
"tag": "div"
}
},
{
"id": "tag+id only",
"in": {
"tag": "div",
"id": "div-id",
},
"out": {
"content": "",
"css": [],
"id": "div-id",
"name": undefined,
"options": {},
"sub": [],
"tag": "div"
}
},
{
"id": "tag+id+content only",
"in": {
"tag": "div",
"id": "div-id",
"content": "text entry",
},
"out": {
"content": "text entry",
"css": [],
"id": "div-id",
"name": undefined,
"options": {},
"sub": [],
"tag": "div"
}
},
{
"id": "tag+id+content+css only",
"in": {
"tag": "div",
"id": "div-id",
"content": "text entry",
"css": ['css-a', 'css-b'],
},
"out": {
"content": "text entry",
"css": ['css-a', 'css-b'],
"id": "div-id",
"name": undefined,
"options": {},
"sub": [],
"tag": "div"
}
},
{
"id": "tag+id+content+css+options only",
"in": {
"tag": "div",
"id": "div-id",
"content": "text entry",
"css": ['css-a', 'css-b'],
"options": {"onclick": "doThis();"}
},
"out": {
"content": "text entry",
"css": ['css-a', 'css-b'],
"id": "div-id",
"name": undefined,
"options": {"onclick": "doThis();"},
"sub": [],
"tag": "div"
}
},
// various in random
{
"id": "only css",
"in": {
"tag": "div",
"id": "",
"content": "",
"css": ["abc"],
"options": undefined,
},
"out": {
"content": "",
"css": ['abc'],
"id": "",
"name": undefined,
"options": {},
"sub": [],
"tag": "div"
}
},
{
"id": "set name",
"in": {
"tag": "div",
"id": "foo-bar",
"content": "",
"css": [],
"options": {
"name": "baz"
},
},
"out": {
"content": "",
"css": [],
"id": "foo-bar",
"name": "baz",
"options": {"name": "baz"},
"sub": [],
"tag": "div"
}
},
];
for (const cel_entry of cel_list) {
expect(celCreate(cel_entry.in)).toEqual(cel_entry.out);
}
});
});
describe("ael", () => {
it('should attach one HTML Element block to another and return an Object', () => {
let ael_block = hec.ael(
hec.cel('div'),
hec.cel('div')
);
expect(ael_block).toEqual(
{
"content": "",
"css": [],
"id": "",
"name": undefined,
"options": {},
"sub": [
{
"content": "",
"css": [],
"id": "",
"name": undefined,
"options": {},
"sub": [],
"tag": "div"
}
],
"tag": "div"
}
);
ael_block = hec.ael(
ael_block,
hec.cel('div')
);
expect(ael_block).toEqual(
{
"content": "",
"css": [],
"id": "",
"name": undefined,
"options": {},
"sub": [
{
"content": "",
"css": [],
"id": "",
"name": undefined,
"options": {},
"sub": [],
"tag": "div"
},
{
"content": "",
"css": [],
"id": "",
"name": undefined,
"options": {},
"sub": [],
"tag": "div"
}
],
"tag": "div"
}
);
let test_cel = hec.ael(
hec.cel('div', 'block-id'),
hec.cel('div', 'sub-id'),
);
expect(hec.ael(test_cel, hec.cel('div', 'new-block'), 'sub-id')).toEqual(
{
"content": "",
"css": [],
"id": "block-id",
"name": undefined,
"options": {},
"sub": [
{
"content": "",
"css": [],
"id": "sub-id",
"name": undefined,
"options": {},
"sub": [
{
"content": "",
"css": [],
"id": "new-block",
"name": undefined,
"options": {},
"sub": [],
"tag": "div"
}
],
"tag": "div"
}
],
"tag": "div"
}
);
});
});
describe("aelx", () => {
it('should attach one or more HTML Element block to another and return an Object', () => {
let ael_block = hec.aelx(
hec.cel('div'),
hec.cel('div')
);
expect(ael_block).toEqual(
{
"content": "",
"css": [],
"id": "",
"name": undefined,
"options": {},
"sub": [
{
"content": "",
"css": [],
"id": "",
"name": undefined,
"options": {},
"sub": [],
"tag": "div"
}
],
"tag": "div"
}
);
ael_block = hec.aelx(
ael_block,
hec.cel('div'),
hec.cel('div'),
hec.cel('div')
);
expect(ael_block).toEqual(
{
"content": "",
"css": [],
"id": "",
"name": undefined,
"options": {},
"sub": [
{
"content": "",
"css": [],
"id": "",
"name": undefined,
"options": {},
"sub": [],
"tag": "div"
},
{
"content": "",
"css": [],
"id": "",
"name": undefined,
"options": {},
"sub": [],
"tag": "div"
},
{
"content": "",
"css": [],
"id": "",
"name": undefined,
"options": {},
"sub": [],
"tag": "div"
},
{
"content": "",
"css": [],
"id": "",
"name": undefined,
"options": {},
"sub": [],
"tag": "div"
},
],
"tag": "div"
}
);
});
});
describe("aelxar", () => {
it('should attach one or more HTML Element block arrays to another and return an Object', () => {
let ael_block = hec.aelxar(
hec.cel('div'),
[hec.cel('div')]
);
expect(ael_block).toEqual(
{
"content": "",
"css": [],
"id": "",
"name": undefined,
"options": {},
"sub": [
{
"content": "",
"css": [],
"id": "",
"name": undefined,
"options": {},
"sub": [],
"tag": "div"
}
],
"tag": "div"
}
);
ael_block = hec.aelxar(
ael_block,
[
hec.cel('div'),
hec.cel('div'),
hec.cel('div')
]
);
expect(ael_block).toEqual(
{
"content": "",
"css": [],
"id": "",
"name": undefined,
"options": {},
"sub": [
{
"content": "",
"css": [],
"id": "",
"name": undefined,
"options": {},
"sub": [],
"tag": "div"
},
{
"content": "",
"css": [],
"id": "",
"name": undefined,
"options": {},
"sub": [],
"tag": "div"
},
{
"content": "",
"css": [],
"id": "",
"name": undefined,
"options": {},
"sub": [],
"tag": "div"
},
{
"content": "",
"css": [],
"id": "",
"name": undefined,
"options": {},
"sub": [],
"tag": "div"
},
],
"tag": "div"
}
);
});
});
describe("rel", () => {
it('should reset the sub entry array in an element and return an Object', () => {
let ael_block = hec.ael(
hec.cel('div'),
hec.cel('div')
);
expect(ael_block).toEqual(
{
"content": "",
"css": [],
"id": "",
"name": undefined,
"options": {},
"sub": [
{
"content": "",
"css": [],
"id": "",
"name": undefined,
"options": {},
"sub": [],
"tag": "div"
}
],
"tag": "div"
}
);
let ael_removed = hec.rel(ael_block);
expect(ael_removed).toEqual(
{
"content": "",
"css": [],
"id": "",
"name": undefined,
"options": {},
"sub": [],
"tag": "div"
}
);
});
});
// grouped CSS together
describe("rcssel/acssel/scssel", () => {
it('should remove/add/replace css entries in an element and return an object', () => {
let cel_entry = hec.cel('div');
let css_test = hec.acssel(cel_entry, 'foo');
expect(css_test).toEqual(
{
"content": "",
"css": ['foo'],
"id": "",
"name": undefined,
"options": {},
"sub": [],
"tag": "div"
}
);
css_test = hec.rcssel(cel_entry, 'foo');
expect(css_test).toEqual(
{
"content": "",
"css": [],
"id": "",
"name": undefined,
"options": {},
"sub": [],
"tag": "div"
}
);
css_test = hec.acssel(cel_entry, 'foo');
expect(css_test).toEqual(
{
"content": "",
"css": ['foo'],
"id": "",
"name": undefined,
"options": {},
"sub": [],
"tag": "div"
}
);
cel_entry = hec.scssel(cel_entry, 'foo', 'bar');
expect(css_test).toEqual(
{
"content": "",
"css": ['bar'],
"id": "",
"name": undefined,
"options": {},
"sub": [],
"tag": "div"
}
);
});
});
// render
describe("phfo", () => {
it('should render an object tree out to HTML', () => {
let cel_list = [
{
"id": "tag only",
"in": {
"tag": "div",
},
"out": '<div></div>'
},
{
"id": "tag+id only",
"in": {
"tag": "div",
"id": "div-id",
},
"out": '<div id="div-id"></div>'
},
{
"id": "tag+id+content only",
"in": {
"tag": "div",
"id": "div-id",
"content": "text entry",
},
"out": '<div id="div-id">text entry</div>'
},
{
"id": "tag+id+content+css only",
"in": {
"tag": "div",
"id": "div-id",
"content": "text entry",
"css": ['css-a', 'css-b'],
},
"out": '<div id="div-id" class="css-a css-b">text entry</div>'
},
{
"id": "tag+id+content+css+options only",
"in": {
"tag": "div",
"id": "div-id",
"content": "text entry",
"css": ['css-a', 'css-b'],
"options": {"onclick": "doThis();"}
},
"out": '<div id="div-id" class="css-a css-b" onclick="doThis();">text entry</div>'
},
// various in random
{
"id": "first",
"in": {
"tag": "div",
"id": "",
"content": "",
"css": ["abc"],
"options": undefined,
},
"out": '<div class="abc"></div>'
}
];
for (const cel_entry of cel_list) {
expect(hec.phfo(
celCreate(cel_entry.in)
)).toEqual(cel_entry.out);
}
// nested
expect(hec.phfo(
hec.ael(hec.cel('div', 'B1'),
hec.aelx(
hec.cel('div', 'A'),
hec.cel('div', 'T1'),
hec.cel('div', 'T2')
)
)
)).toEqual(
'<div id="B1"><div id="A"><div id="T1"></div><div id="T2"></div></div></div>'
);
});
});
describe("phfa", () => {
it('should render an array tree out to HTML', () => {
let el_list = [
hec.cel('div', 'A'),
hec.cel('div', 'B'),
hec.cel('div', 'C'),
];
expect(hec.phfa(el_list)).toEqual(
'<div id="A"></div><div id="B"></div><div id="C"></div>'
);
});
});
// build check
describe("phfo", () => {
it('should render an object tree out to HTML, extended', () => {
let cel_list = [
{
"id": "text input",
"in": hec.cel("input", 'text-id', '', ['abc']),
"out": '<input id="text-id" name="text-id" class="abc">'
},
{
"id": "text input, different name",
"in": hec.cel("input", 'text-id', '', ['abc'], {"name": "other-name"}),
"out": '<input id="text-id" name="other-name" class="abc">'
},
{
"id": "block test",
"in": hec.aelx(hec.cel('div', 'outer-id'),
hec.aelx(hec.cel('div', 'inner-id'),
hec.cel('input', 'some-id', '', ['abc'], {"type": "button", "onclick": "send()"}),
hec.cel('div', '', 'content')
)
),
"out": '<div id="outer-id"><div id="inner-id"><input id="some-id" name="some-id" class="abc" type="button" onclick="send()"><div>content</div></div></div>'
}
];
for (const cel_entry of cel_list) {
expect(hec.phfo(
cel_entry.in
)).toEqual(cel_entry.out);
}
});
});
// __END__

View File

@@ -24,6 +24,8 @@ describe("roundPrecision", () => {
it('should round numbers to a given precision', () => {
let val = roundPrecision(10.1234, 2);
expect(val).toBe(10.12);
// @ts-ignore
expect(roundPrecision("abc", 2)).toBe("abc");
});
});

View File

@@ -5,17 +5,99 @@ import {
getQueryStringParam,
} from '../src/utils/UrlParser.mjs';
describe("parseQueryString", () => {
it('Should parse query string for key', () => {
let kv = parseQueryString("http://foor.org?key=value");
expect(kv).toEqual({"http://foor.org?key": "value"});
});
});
let url_list = [
{
"id": "no params",
"in": {
"query": "http://foor.org",
"search": "",
"single": false
},
"out": {}
},
{
"id": "no params",
"in": {
"query": "http://foor.org/?param",
"search": "",
"single": false
},
"out": {"param": ""}
},
{
"id": "one params",
"in": {
"query": "http://foor.org/?param=foo",
"search": "",
"single": false
},
"out": {"param": "foo"}
},
{
"id": "two params",
"in": {
"query": "http://foor.org/?param=foo&bar=other",
"search": "",
"single": false
},
"out": {"param": "foo", "bar": "other"}
},
{
"id": "two params, select",
"in": {
"query": "http://foor.org/?param=foo&bar=other",
"search": "bar",
"single": false
},
"out": "other"
},
{
"id": "two params, same",
"in": {
"query": "http://foor.org/?param=foo&param=other",
"search": "",
"single": false
},
"out": {"param": ["foo", "other"]}
},
{
"id": "two params, same, single but no search",
"in": {
"query": "http://foor.org/?param=foo&param=other",
"search": "",
"single": true
},
// "out": {"param": ["foo", "other"]}
"out": {"param": "foo"}
},
{
"id": "three params, same, search",
"in": {
"query": "http://foor.org/?param=foo&param=other&different=1",
"search": "param",
"single": false
},
"out": ["foo", "other"]
},
];
describe("getQueryStringParam", () => {
it('Should parse query string for key', () => {
let kv = getQueryStringParam("key", "http://foor.org?key=value");
expect(kv).toEqual("value");
for (const url of url_list) {
expect(
getQueryStringParam(url.in.search, url.in.query, url.in.single)
).toEqual(url.out);
}
});
});
describe("parseQueryString", () => {
it('Should parse query string for key', () => {
// let kv = getQueryStringParam("key", "http://foor.org?key=value");
// expect(kv).toEqual("value");
for (const url of url_list) {
expect(
parseQueryString(url.in.query, url.in.search, url.in.single)
).toEqual(url.out);
}
});
});

19
vitest.config.js Normal file
View File

@@ -0,0 +1,19 @@
import { defineConfig } from 'vitest/config';
export default defineConfig({
test: {
include: [
'tests/**/*.{test,spec}.?(c|m)[jt]s?(x)'
],
// exclude: [],
coverage: {
include: [
'src/',
],
exclude: [
'src/utils.mjs',
]
}
},
});