genish.js
Version:
45 lines (31 loc) • 936 B
JavaScript
let gen = require('./gen.js')
let proto = {
basename:'pow',
gen() {
let out,
inputs = gen.getInputs( this )
const isWorklet = gen.mode === 'worklet'
const ref = isWorklet? '' : 'gen.'
if( isNaN( inputs[0] ) || isNaN( inputs[1] ) ) {
gen.closures.add({ 'pow': isWorklet ? 'Math.pow' : Math.pow })
out = `${ref}pow( ${inputs[0]}, ${inputs[1]} )`
} else {
if( typeof inputs[0] === 'string' && inputs[0][0] === '(' ) {
inputs[0] = inputs[0].slice(1,-1)
}
if( typeof inputs[1] === 'string' && inputs[1][0] === '(' ) {
inputs[1] = inputs[1].slice(1,-1)
}
out = Math.pow( parseFloat( inputs[0] ), parseFloat( inputs[1]) )
}
return out
}
}
module.exports = (x,y) => {
let pow = Object.create( proto )
pow.inputs = [ x,y ]
pow.id = gen.getUID()
pow.name = `${pow.basename}{pow.id}`
return pow
}