38 lines
784 B
JavaScript
38 lines
784 B
JavaScript
function weight(money) {
|
|
|
|
const baseValue = money * 1000 // to get to gramms (1/1000 Stone)
|
|
|
|
const stone = Math.floor(baseValue / 1000)
|
|
const remainder = baseValue - (stone * 1000)
|
|
const ounces = remainder / 25
|
|
|
|
return {
|
|
stone,
|
|
ounces,
|
|
}
|
|
|
|
}
|
|
|
|
function registerHelper(hbs) {
|
|
hbs?.registerHelper('weight', (data) => {
|
|
|
|
let template = `<span class="weight">`
|
|
|
|
const {stone, ounces} = weight(data)
|
|
if (stone > 0) {
|
|
template += `<span class="stone">${stone}</span>`
|
|
}
|
|
if (ounces > 0) {
|
|
template += `<span class="ounces">${ounces}</span>`
|
|
}
|
|
|
|
template += `</span>`
|
|
|
|
return new Handlebars.SafeString(template)
|
|
})
|
|
}
|
|
|
|
export {
|
|
weight,
|
|
registerHelper
|
|
} |