Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(validation): format numbers to make them more readable #563

Merged
merged 3 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/validation/rules/maxLength.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { format } from '../../support/Num'
import { createRule } from '../Rule'
import { maxLength as baseMaxLength } from '../validators'

export const message = {
en: (length: number) => `The value must be less than or equal to ${length} characters.`,
ja: (length: number) => `この値は最大${length}文字までです。`
en: (length: string) => `The value must be less than or equal to ${length} characters.`,
ja: (length: string) => `この値は最大${length}文字までです。`
}

export function maxLength(length: number, msg?: string) {
return createRule({
message: ({ lang }) => msg ?? message[lang](length),
message: ({ lang }) => msg ?? message[lang](format(length)),
optional: true,
validation: (value) => baseMaxLength(value, length)
})
Expand Down
7 changes: 4 additions & 3 deletions lib/validation/rules/maxValue.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { format } from '../../support/Num'
import { createRule } from '../Rule'
import { maxValue as baseMaxValue } from '../validators'

export const message = {
en: (max: number) => `The value must be less than or equal to ${max}.`,
ja: (max: number) => `この値は最大${max}です。`
en: (max: string) => `The value must be less than or equal to ${max}.`,
ja: (max: string) => `この値は最大${max}です。`
}

export function maxValue(max: number, msg?: string) {
return createRule({
message: ({ lang }) => msg ?? message[lang](max),
message: ({ lang }) => msg ?? message[lang](format(max)),
optional: true,
validation: (value) => baseMaxValue(value, max)
})
Expand Down
7 changes: 4 additions & 3 deletions lib/validation/rules/minLength.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { format } from '../../support/Num'
import { createRule } from '../Rule'
import { minLength as baseMinLength } from '../validators'

export const message = {
en: (min: number) => `The value must be greater than or equal to ${min} characters.`,
ja: (min: number) => `この値は最小${min}文字です。`
en: (min: string) => `The value must be greater than or equal to ${min} characters.`,
ja: (min: string) => `この値は最小${min}文字です。`
}

export function minLength(length: number, msg?: string) {
return createRule({
message: ({ lang }) => msg ?? message[lang](length),
message: ({ lang }) => msg ?? message[lang](format(length)),
optional: true,
validation: (value) => baseMinLength(value, length)
})
Expand Down
7 changes: 4 additions & 3 deletions lib/validation/rules/minValue.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { format } from '../../support/Num'
import { createRule } from '../Rule'
import { minValue as baseMinValue } from '../validators'

export const message = {
en: (min: number) => `The value must be greater than or equal to ${min}.`,
ja: (min: number) => `この値は最大${min}です。`
en: (min: string) => `The value must be greater than or equal to ${min}.`,
ja: (min: string) => `この値は最大${min}です。`
}

export function minValue(min: number, msg?: string) {
return createRule({
message: ({ lang }) => msg ?? message[lang](min),
message: ({ lang }) => msg ?? message[lang](format(min)),
optional: true,
validation: (value) => baseMinValue(value, min)
})
Expand Down
66 changes: 33 additions & 33 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@globalbrain/sefirot",
"type": "module",
"version": "4.6.0",
"packageManager": "pnpm@9.12.1",
"packageManager": "pnpm@9.13.2",
"description": "Vue Components for Global Brain Design System.",
"author": "Kia Ishii <ka.ishii@globalbrains.com>",
"license": "MIT",
Expand Down Expand Up @@ -43,58 +43,58 @@
"release": "release-it"
},
"peerDependencies": {
"@iconify-json/ph": "^1.2.0",
"@iconify-json/ri": "^1.2.0",
"@iconify-json/ph": "^1.2.1",
"@iconify-json/ri": "^1.2.3",
"@types/body-scroll-lock": "^3.1.2",
"@types/lodash-es": "^4.17.12",
"@types/markdown-it": "^14.1.2",
"@vue/reactivity": "^3.5.11",
"@vue/reactivity": "^3.5.13",
"@vuelidate/core": "^2.0.3",
"@vuelidate/validators": "^2.0.4",
"@vueuse/core": "^11.1.0",
"@vueuse/core": "^11.2.0",
"body-scroll-lock": "4.0.0-beta.0",
"dayjs": "^1.11.13",
"fuse.js": "^7.0.0",
"lodash-es": "^4.17.21",
"markdown-it": "^14.1.0",
"normalize.css": "^8.0.1",
"pinia": "^2.2.4",
"postcss": "^8.4.47",
"postcss-nested": "^6.2.0",
"pinia": "^2.2.6",
"postcss": "^8.4.49",
"postcss-nested": "^7.0.2",
"v-calendar": "3.0.1",
"vue": "^3.5.11",
"vue": "^3.5.13",
"vue-router": "^4.4.5"
},
"dependencies": {
"@sentry/browser": "^8.33.1",
"@sentry/browser": "^8.38.0",
"@tanstack/vue-virtual": "3.0.0-beta.62",
"@tinyhttp/content-disposition": "^2.2.2",
"@tinyhttp/cookie": "^2.1.1",
"@types/file-saver": "^2.0.7",
"@types/qs": "^6.9.16",
"@types/qs": "^6.9.17",
"file-saver": "^2.0.5",
"magic-string": "^0.30.11",
"ofetch": "^1.4.0",
"qs": "^6.13.0",
"unplugin-icons": "^0.19.3"
"magic-string": "^0.30.12",
"ofetch": "^1.4.1",
"qs": "^6.13.1",
"unplugin-icons": "^0.20.1"
},
"devDependencies": {
"@globalbrain/eslint-config": "^1.7.1",
"@histoire/plugin-vue": "0.16.5",
"@iconify-json/ph": "^1.2.0",
"@iconify-json/ri": "^1.2.0",
"@release-it/conventional-changelog": "^8.0.2",
"@iconify-json/ph": "^1.2.1",
"@iconify-json/ri": "^1.2.3",
"@release-it/conventional-changelog": "^9.0.3",
"@types/body-scroll-lock": "^3.1.2",
"@types/lodash-es": "^4.17.12",
"@types/markdown-it": "^14.1.2",
"@types/node": "^22.7.5",
"@vitejs/plugin-vue": "^5.1.4",
"@vitest/coverage-v8": "^2.1.2",
"@vue/reactivity": "^3.5.11",
"@types/node": "^22.9.0",
"@vitejs/plugin-vue": "^5.2.0",
"@vitest/coverage-v8": "^2.1.5",
"@vue/reactivity": "^3.5.13",
"@vue/test-utils": "^2.4.6",
"@vuelidate/core": "^2.0.3",
"@vuelidate/validators": "^2.0.4",
"@vueuse/core": "^11.1.0",
"@vueuse/core": "^11.2.0",
"body-scroll-lock": "4.0.0-beta.0",
"dayjs": "^1.11.13",
"eslint": "8.57.0",
Expand All @@ -104,18 +104,18 @@
"lodash-es": "^4.17.21",
"markdown-it": "^14.1.0",
"normalize.css": "^8.0.1",
"pinia": "^2.2.4",
"postcss": "^8.4.47",
"postcss-nested": "^6.2.0",
"pinia": "^2.2.6",
"postcss": "^8.4.49",
"postcss-nested": "^7.0.2",
"punycode": "^2.3.1",
"release-it": "^17.7.0",
"typescript": "~5.6.2",
"release-it": "^17.10.0",
"typescript": "~5.6.3",
"v-calendar": "3.0.1",
"vite": "^5.4.8",
"vitepress": "^1.4.0",
"vitest": "^2.1.2",
"vue": "^3.5.11",
"vite": "^5.4.11",
"vitepress": "^1.5.0",
"vitest": "^2.1.5",
"vue": "^3.5.13",
"vue-router": "^4.4.5",
"vue-tsc": "^2.1.6"
"vue-tsc": "^2.1.10"
}
}
Loading