Skip to content
This repository has been archived by the owner on May 15, 2023. It is now read-only.

currency filter not applying decimal from server #83

Open
uptownhr opened this issue Oct 15, 2019 · 0 comments
Open

currency filter not applying decimal from server #83

uptownhr opened this issue Oct 15, 2019 · 0 comments

Comments

@uptownhr
Copy link

Recently upgraded from version 3.2.3 to 3.4.3 and the currency filter is not applying the thousands symbol anymore. I verified on the frontend works great but for some reason will not apply the thousands when ran from node.

failing test

test('renders renders with proper VueCurrencyFilter formatting', async t => {
  const template = '<div>${{pay | currency({ fractionCount: 0 })}}</div>'
  const vars = {
    pay: '5000'
  }

  const html = await renderTemplate(template, vars)

  t.is('<div>$5,000</div>', html)
})

render method

const Vue = require('vue')
const VueCurrencyFilter = require('vue-currency-filter')
const { createRenderer } = require('vue-server-renderer')
const moment = require('moment')

const renderer = createRenderer()
const { specialCharacters } = require('./utils')

Vue.use(VueCurrencyFilter, {
  symbol: '$',
  thousandsSeparator: ',',
  fractionCount: 2,
  fractionSeparator: '.',
  symbolPosition: 'front',
  symbolSpacing: false
})

module.exports = async function (template, data) {
  const sanitized_template = template.replace(specialCharacters, '')
  const app = new Vue({
    template: sanitized_template,
    data,
    filters: {
      date (val) {
        return moment(val).format('M/D/YYYY')
      }
    }
  })

  const html = await renderer.renderToString(app)

  return html.replace(' data-server-rendered="true"', '')
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant