A lightweight JavaScript library that provides functional utilities for DOM manipulation, variables, math operations, and control flow.
npm install @topmyster/funcscriptimport { doc, vars, markup, math } from '@topmyster/funcscript';
// Variables
vars.set('counter', 0);
vars.addVar('counter', 5);
console.log(vars.get('counter')); // 5
// DOM Manipulation
const button = markup.newEl('button', 'myBtn', { class: 'btn' }, 'Click me');
markup.appendEl('app', button);
// Events
doc.event('myBtn', 'click', () => {
doc.log('Button clicked!');
});
// Conditionals
doc.cond('if', vars.get('counter') > 0, () => {
doc.log('Counter is positive');
});
// Math
math.add(10);
math.mul(2);
console.log(math.clear()); // 0vars.decl(varName, value)- Declare a variablevars.set(varName, value)- Set a variable valuevars.get(varName)- Get a variable valuevars.addVar(varName, value)- Add to a variablevars.subVar(varName, value)- Subtract from a variablevars.mulVar(varName, value)- Multiply a variablevars.divVar(varName, value)- Divide a variablevars.remove(varName)- Remove a variablevars.clearVars()- Clear all variables
markup.newEl(el, id, props, content)- Create a new elementmarkup.appendEl(id, content)- Append to an elementmarkup.prependEl(id, content)- Prepend to an elementmarkup.delEl(id)- Delete an elementmarkup.updateEl(id, props, content)- Update an elementmarkup.replaceEl(id, content)- Replace an element
doc.log(x)- Console logdoc.alert(x)- Show alertdoc.event(id, event, callback)- Add event listenerdoc.cond(statement, condition, result)- Conditional execution- Statements:
'if','else','while','for'
- Statements:
math.add(number)- Add to totalmath.sub(number)- Subtract from totalmath.mul(number)- Multiply totalmath.div(number)- Divide totalmath.clear()- Reset total to 0
See the examples/ directory for a counter demo.