genish.js
Version:
36 lines (23 loc) • 585 B
JavaScript
let gen = require('./gen.js')
let proto = {
name:'round',
gen() {
let out,
inputs = gen.getInputs( this )
const isWorklet = gen.mode === 'worklet'
const ref = isWorklet? '' : 'gen.'
if( isNaN( inputs[0] ) ) {
gen.closures.add({ [ this.name ]: isWorklet ? 'Math.round' : Math.round })
out = `${ref}round( ${inputs[0]} )`
} else {
out = Math.round( parseFloat( inputs[0] ) )
}
return out
}
}
module.exports = x => {
let round = Object.create( proto )
round.inputs = [ x ]
return round
}