1+ import currency from 'currency.js' ;
2+ import { addDays , format , parse } from 'date-fns' ;
13import { startCase as _startCase , upperFirst as _upperFirst } from 'lodash' ;
24
5+ import { VfOptions } from '@/config' ;
6+
37import { desnakeCase , formatNumber , formatPhone , formatUSCurrency } from '..' ;
48
59function bytes ( value : number ) {
@@ -48,6 +52,12 @@ function upperCase(value: string | null) {
4852 return value ? value . toUpperCase ( ) : null ;
4953}
5054
55+ function upperWords ( value : null ) : null ;
56+ function upperWords ( value : string ) : string ;
57+ function upperWords ( value : string | null ) {
58+ return value ? startCase ( value . toLowerCase ( ) ) : null ;
59+ }
60+
5161function desnake ( value : null ) : null ;
5262function desnake ( value : string ) : string ;
5363function desnake ( value : string | null ) {
@@ -58,6 +68,30 @@ function usCurrency(value: string | number, divisor = 1) {
5868 return formatUSCurrency ( value , divisor ) ;
5969}
6070
71+ function divide ( value : number , divisor : number ) {
72+ return currency ( value ) . divide ( divisor ) . value ;
73+ }
74+
75+ function date ( value : string | null , formatStr ?: string ) {
76+ if ( ! value ) return value ;
77+ return format ( new Date ( value ) , formatStr ?? VfOptions . defaultDateFormat ) ;
78+ }
79+
80+ function time ( value : string | null , formatStr ?: string ) {
81+ if ( ! value ) return value ;
82+ return format ( new Date ( value ) , formatStr ?? VfOptions . defaultTimeFormat ) ;
83+ }
84+
85+ function dateTime ( value : string | null , formatStr ?: string ) {
86+ if ( ! value ) return value ;
87+ return format ( new Date ( value ) , formatStr ?? VfOptions . defaultDateFormat ) ;
88+ }
89+
90+ function oneDayForward ( date ?: string | null ) {
91+ if ( ! date ) return date ;
92+ return format ( addDays ( parse ( date , 'yyyy-MM-dd' , new Date ( ) ) , 1 ) , VfOptions . defaultDateFormat ) ;
93+ }
94+
6195const FilterFns = {
6296 bytes,
6397 dash,
@@ -67,8 +101,14 @@ const FilterFns = {
67101 upperFirst,
68102 startCase,
69103 upperCase,
104+ upperWords,
70105 desnake,
71- usCurrency
106+ usCurrency,
107+ divide,
108+ date,
109+ time,
110+ dateTime,
111+ oneDayForward
72112} ;
73113
74114// type FilterFn = (value: any, ...unknown: any[]) => any;
0 commit comments