mirror of
https://github.com/Ocelot-Social-Community/Ocelot-Social.git
synced 2025-12-13 07:46:06 +00:00
added accounting package and number formatter
This commit is contained in:
parent
f73c535bbb
commit
3b8b21f400
@ -18,6 +18,7 @@
|
||||
"dependencies": {
|
||||
"@nuxtjs/apollo": "^4.0.0-rc3",
|
||||
"@nuxtjs/dotenv": "^1.3.0",
|
||||
"accounting": "^0.4.1",
|
||||
"cross-env": "^5.2.0",
|
||||
"date-fns": "^1.29.0",
|
||||
"express": "^4.16.3",
|
||||
|
||||
@ -3,6 +3,8 @@ import Vue from 'vue'
|
||||
import format from 'date-fns/format'
|
||||
import addSeconds from 'date-fns/add_seconds'
|
||||
|
||||
import accounting from 'accounting'
|
||||
|
||||
export default ({ app }) => {
|
||||
app.$filters = Object.assign(app.$filters || {}, {
|
||||
date: (value, fmt = 'DD. MMM YYYY') => {
|
||||
@ -13,6 +15,18 @@ export default ({ app }) => {
|
||||
if (!value) return ''
|
||||
return format(new Date(value), fmt)
|
||||
},
|
||||
number: (
|
||||
value,
|
||||
precision = 2,
|
||||
thousands = '.',
|
||||
decimals = ',',
|
||||
fallback = null
|
||||
) => {
|
||||
if (isNaN(value) && fallback) {
|
||||
return fallback
|
||||
}
|
||||
return accounting.formatNumber(value || 0, precision, thousands, decimals)
|
||||
},
|
||||
// format seconds or milliseconds to durations HH:mm:ss
|
||||
duration: (value, unit = 's') => {
|
||||
if (unit === 'ms') {
|
||||
@ -46,7 +60,7 @@ export default ({ app }) => {
|
||||
}
|
||||
return value.join(glue)
|
||||
},
|
||||
listByKey(values, key, glue, truncate) {
|
||||
listByKey: (values, key, glue, truncate) => {
|
||||
return app.$filters.list(values.map(item => item[key]), glue, truncate)
|
||||
},
|
||||
camelCase: (value = '') => {
|
||||
|
||||
@ -1024,6 +1024,10 @@ accepts@^1.3.5, accepts@~1.3.5:
|
||||
mime-types "~2.1.18"
|
||||
negotiator "0.6.1"
|
||||
|
||||
accounting@^0.4.1:
|
||||
version "0.4.1"
|
||||
resolved "https://registry.yarnpkg.com/accounting/-/accounting-0.4.1.tgz#87dd4103eff7f4460f1e186f5c677ed6cf566883"
|
||||
|
||||
acorn-dynamic-import@^3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/acorn-dynamic-import/-/acorn-dynamic-import-3.0.0.tgz#901ceee4c7faaef7e07ad2a47e890675da50a278"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user