Add working module based clone from original openrc-run generator

See http://openrc.run/

This able to split the same working piece as a node and browser module
This commit is contained in:
Lenny Andreu 2025-05-17 20:38:35 -04:00
parent 1163906176
commit 331d7980be
3 changed files with 129 additions and 13 deletions

31
index.js Normal file
View file

@ -0,0 +1,31 @@
import { convert } from './magic.js'
function convertForBrowser (convertFunction){
return function(event){
event.preventDefault();
const raw = document.getElementById('unit').value;
const response = convertFunction(raw)
const validated = response.validated;
const result = response.result;
if (validated !== null) {
document.getElementById('error').innerHTML = validated;
return;
} else {
document.getElementById('error').innerHTML = '';
}
document.getElementById('openrc').innerText = result;
}
}
function setup(){
if(typeof window !== "undefined" && typeof window.document !== "undefined"){
const convertFunction = convertForBrowser(convert)
document.addEventListener("DOMContentLoaded", function () {
document.getElementById('convert').addEventListener('click', convertFunction);
});
}
}
setup();