Skip to content

Commit 0447aa1

Browse files
committed
4.24.0: add filters, bump deps
1 parent fa4d880 commit 0447aa1

File tree

4 files changed

+226
-570
lines changed

4 files changed

+226
-570
lines changed

package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@signal24/vue-foundation",
33
"type": "module",
4-
"version": "4.23.0",
4+
"version": "4.24.0",
55
"description": "Common components, directives, and helpers for Vue 3 apps",
66
"module": "./dist/vue-foundation.es.js",
77
"exports": {
@@ -34,6 +34,7 @@
3434
},
3535
"license": "MIT",
3636
"dependencies": {
37+
"currency.js": "^2.0.4",
3738
"uuid": "^11.1.0"
3839
},
3940
"peerDependencies": {
@@ -43,7 +44,7 @@
4344
"vue": "^3.4.0"
4445
},
4546
"devDependencies": {
46-
"@eslint/js": "9.26.0",
47+
"@eslint/js": "9.27.0",
4748
"@nabla/vite-plugin-eslint": "^2.0.5",
4849
"@signal24/openapi-client-codegen": "^2.5.0",
4950
"@tsconfig/node22": "^22.0.1",
@@ -58,22 +59,22 @@
5859
"@vue/tsconfig": "^0.7.0",
5960
"cypress": "^14.3.3",
6061
"date-fns": "^4.1.0",
61-
"eslint": "9.26.0",
62+
"eslint": "9.27.0",
6263
"eslint-plugin-cypress": "^4.3.0",
6364
"eslint-plugin-simple-import-sort": "^12.1.1",
6465
"eslint-plugin-unused-imports": "^4.1.4",
6566
"eslint-plugin-vue": "^10.1.0",
6667
"jsdom": "^26.1.0",
6768
"lodash": "^4.17.21",
6869
"prettier": "^3.5.3",
69-
"sass": "^1.88.0",
70-
"start-server-and-test": "^2.0.11",
70+
"sass": "^1.89.0",
71+
"start-server-and-test": "^2.0.12",
7172
"type-fest": "^4.41.0",
7273
"typescript": "~5.8",
7374
"typescript-eslint": "^8.32.1",
7475
"vite": "^6.3.5",
7576
"vitest": "^3.1.3",
76-
"vue": "^3.5.13",
77+
"vue": "^3.5.14",
7778
"vue-tsc": "^2.2.10"
7879
},
7980
"packageManager": "[email protected]"

src/filters/index.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
import currency from 'currency.js';
2+
import { addDays, format, parse } from 'date-fns';
13
import { startCase as _startCase, upperFirst as _upperFirst } from 'lodash';
24

5+
import { VfOptions } from '@/config';
6+
37
import { desnakeCase, formatNumber, formatPhone, formatUSCurrency } from '..';
48

59
function 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+
5161
function desnake(value: null): null;
5262
function desnake(value: string): string;
5363
function 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+
6195
const 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;

src/helpers/string.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import currency from 'currency.js';
12
import { v4 as uuidv4 } from 'uuid';
23

34
// placing this here so we don't have to use the ESLint rule everywhere
@@ -19,13 +20,7 @@ export function formatPhone(value: string) {
1920
}
2021

2122
export function formatUSCurrency(value: string | number, divisor = 1) {
22-
return (
23-
'$' +
24-
(Number(value) / divisor)
25-
.toFixed(3)
26-
.replace(/0$/, '')
27-
.replace(/\B(?=(\d{3})+(?!\d))/g, ',')
28-
);
23+
return currency(value).divide(divisor).format();
2924
}
3025

3126
export function uuid() {

0 commit comments

Comments
 (0)