@globalbrain/sefirot 3.23.0 → 3.24.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/lib/components/SDropdownSectionFilter.vue +3 -3
  2. package/lib/components/SInputAddon.vue +3 -3
  3. package/lib/components/SInputCheckboxes.vue +1 -1
  4. package/lib/components/SInputDropdown.vue +3 -3
  5. package/lib/components/SInputDropdownItem.vue +2 -2
  6. package/lib/components/SInputDropdownItemAvatar.vue +2 -2
  7. package/lib/components/SInputDropdownItemText.vue +2 -2
  8. package/lib/components/SInputRadios.vue +8 -8
  9. package/lib/components/SInputSelect.vue +2 -2
  10. package/lib/components/SInputSwitches.vue +5 -5
  11. package/lib/components/STableCellNumber.vue +1 -1
  12. package/lib/composables/Dropdown.ts +4 -9
  13. package/lib/http/Http.ts +14 -16
  14. package/lib/support/Day.ts +43 -0
  15. package/lib/validation/Rule.ts +1 -1
  16. package/lib/validation/rules/checked.ts +11 -5
  17. package/lib/validation/rules/decimal.ts +11 -6
  18. package/lib/validation/rules/decimalOrHyphen.ts +11 -5
  19. package/lib/validation/rules/email.ts +11 -5
  20. package/lib/validation/rules/fileExtension.ts +11 -7
  21. package/lib/validation/rules/hms.ts +11 -8
  22. package/lib/validation/rules/maxFileSize.ts +11 -12
  23. package/lib/validation/rules/maxLength.ts +12 -7
  24. package/lib/validation/rules/maxTotalFileSize.ts +11 -12
  25. package/lib/validation/rules/maxValue.ts +12 -8
  26. package/lib/validation/rules/minLength.ts +12 -7
  27. package/lib/validation/rules/minValue.ts +12 -8
  28. package/lib/validation/rules/month.ts +12 -8
  29. package/lib/validation/rules/negativeInteger.ts +10 -5
  30. package/lib/validation/rules/positiveInteger.ts +10 -5
  31. package/lib/validation/rules/required.ts +1 -1
  32. package/lib/validation/rules/requiredHms.ts +10 -8
  33. package/lib/validation/rules/requiredIf.ts +12 -6
  34. package/lib/validation/rules/requiredYmd.ts +11 -8
  35. package/lib/validation/rules/rule.ts +12 -6
  36. package/lib/validation/rules/url.ts +11 -5
  37. package/lib/validation/rules/ymd.ts +11 -8
  38. package/lib/validation/rules/zeroOrNegativeInteger.ts +11 -6
  39. package/lib/validation/rules/zeroOrPositiveInteger.ts +11 -6
  40. package/lib/validation/validators/checked.ts +1 -1
  41. package/lib/validation/validators/decimal.ts +11 -0
  42. package/lib/validation/validators/email.ts +12 -0
  43. package/lib/validation/validators/fileExtension.ts +7 -2
  44. package/lib/validation/validators/hms.ts +8 -12
  45. package/lib/validation/validators/hyphen.ts +1 -1
  46. package/lib/validation/validators/index.ts +8 -0
  47. package/lib/validation/validators/maxFileSize.ts +9 -2
  48. package/lib/validation/validators/maxLength.ts +9 -0
  49. package/lib/validation/validators/maxTotalFileSize.ts +12 -2
  50. package/lib/validation/validators/maxValue.ts +7 -0
  51. package/lib/validation/validators/minLength.ts +9 -0
  52. package/lib/validation/validators/minValue.ts +7 -0
  53. package/lib/validation/validators/month.ts +7 -1
  54. package/lib/validation/validators/negativeInteger.ts +7 -1
  55. package/lib/validation/validators/positiveInteger.ts +7 -1
  56. package/lib/validation/validators/requiredHms.ts +6 -10
  57. package/lib/validation/validators/requiredIf.ts +19 -0
  58. package/lib/validation/validators/requiredYmd.ts +6 -10
  59. package/lib/validation/validators/url.ts +11 -0
  60. package/lib/validation/validators/ymd.ts +11 -15
  61. package/lib/validation/validators/zero.ts +1 -1
  62. package/package.json +1 -1
@@ -11,7 +11,7 @@ const props = defineProps<{
11
11
  search?: boolean
12
12
  selected: MaybeRef<DropdownSectionFilterSelectedValue>
13
13
  options: MaybeRef<DropdownSectionFilterOption[]>
14
- onClick?(value: string | number | boolean): void
14
+ onClick?(value: any): void
15
15
  }>()
16
16
 
17
17
  const input = ref<HTMLElement | null>(null)
@@ -35,7 +35,7 @@ onMounted(() => {
35
35
  input.value?.focus()
36
36
  })
37
37
 
38
- function isActive(value: string | number | boolean) {
38
+ function isActive(value: any) {
39
39
  const selected = unref(props.selected)
40
40
 
41
41
  return isArray(selected)
@@ -51,7 +51,7 @@ function focusNext(event: any) {
51
51
  event.target.parentNode.nextElementSibling?.firstElementChild?.focus()
52
52
  }
53
53
 
54
- function handleClick(option: DropdownSectionFilterOption, value: string | number | boolean) {
54
+ function handleClick(option: DropdownSectionFilterOption, value: any) {
55
55
  option.onClick && option.onClick(value)
56
56
  props.onClick && props.onClick(value)
57
57
  }
@@ -1,12 +1,12 @@
1
1
  <script setup lang="ts">
2
2
  import IconCaretDown from '@iconify-icons/ph/caret-down-bold'
3
+ import { computed, ref } from 'vue'
3
4
  import {
4
5
  type DropdownSection,
5
6
  getSelectedOption,
6
7
  useManualDropdownPosition
7
- } from 'sefirot/composables/Dropdown'
8
- import { useFlyout } from 'sefirot/composables/Flyout'
9
- import { computed, ref } from 'vue'
8
+ } from '../composables/Dropdown'
9
+ import { useFlyout } from '../composables/Flyout'
10
10
  import { isString } from '../support/Utils'
11
11
  import SDropdown from './SDropdown.vue'
12
12
  import SIcon from './SIcon.vue'
@@ -8,7 +8,7 @@ import SInputCheckbox from './SInputCheckbox.vue'
8
8
  export type Size = 'mini' | 'small' | 'medium'
9
9
  export type Color = 'neutral' | 'mute' | 'info' | 'success' | 'warning' | 'danger'
10
10
 
11
- export type Value = string | number | boolean
11
+ export type Value = any
12
12
 
13
13
  export interface Option {
14
14
  label: string
@@ -16,9 +16,9 @@ import SInputDropdownItem from './SInputDropdownItem.vue'
16
16
  export type Size = 'mini' | 'small' | 'medium'
17
17
  export type Color = 'neutral' | 'mute' | 'info' | 'success' | 'warning' | 'danger'
18
18
 
19
- export type PrimitiveValue = string | number | boolean | null
20
- export type ArrayValue = (string | number | boolean)[]
21
- export type OptionValue = string | number | boolean
19
+ export type PrimitiveValue = any
20
+ export type ArrayValue = any[]
21
+ export type OptionValue = any
22
22
 
23
23
  export type Option = OptionText | OptionAvatar
24
24
 
@@ -6,7 +6,7 @@ export type Item = ItemText | ItemAvatar
6
6
 
7
7
  export interface ItemBase {
8
8
  type?: 'text' | 'avatar'
9
- value: string | number | boolean
9
+ value: any
10
10
  }
11
11
 
12
12
  export interface ItemText extends ItemBase {
@@ -27,7 +27,7 @@ defineProps<{
27
27
  }>()
28
28
 
29
29
  defineEmits<{
30
- (e: 'remove', value: string | number | boolean): void
30
+ (e: 'remove', value: any): void
31
31
  }>()
32
32
  </script>
33
33
 
@@ -6,13 +6,13 @@ import SIcon from './SIcon.vue'
6
6
  defineProps<{
7
7
  label: string
8
8
  image?: string | null
9
- value: string | number | boolean
9
+ value: any
10
10
  removable: boolean
11
11
  disabled: boolean
12
12
  }>()
13
13
 
14
14
  defineEmits<{
15
- (e: 'remove', value: string | number | boolean): void
15
+ (e: 'remove', value: any): void
16
16
  }>()
17
17
  </script>
18
18
 
@@ -4,13 +4,13 @@ import SIcon from './SIcon.vue'
4
4
 
5
5
  defineProps<{
6
6
  label: string
7
- value: string | number | boolean
7
+ value: any
8
8
  removable: boolean
9
9
  disabled: boolean
10
10
  }>()
11
11
 
12
12
  defineEmits<{
13
- (e: 'remove', value: string | number | boolean): void
13
+ (e: 'remove', value: any): void
14
14
  }>()
15
15
  </script>
16
16
 
@@ -10,7 +10,7 @@ export type Color = 'neutral' | 'mute' | 'info' | 'success' | 'warning' | 'dange
10
10
 
11
11
  export interface Option {
12
12
  label: string
13
- value: string | number | boolean
13
+ value: any
14
14
  disabled?: boolean
15
15
  }
16
16
 
@@ -27,8 +27,8 @@ const props = withDefaults(defineProps<{
27
27
  options: Option[]
28
28
  nullable?: boolean
29
29
  disabled?: boolean
30
- value?: string | number | boolean | null
31
- modelValue?: string | number | boolean | null
30
+ value?: any
31
+ modelValue?: any
32
32
  validation?: Validatable
33
33
  hideError?: boolean
34
34
  }>(), {
@@ -37,8 +37,8 @@ const props = withDefaults(defineProps<{
37
37
  })
38
38
 
39
39
  const emit = defineEmits<{
40
- (e: 'update:model-value', value: string | number | boolean | null): void
41
- (e: 'change', value: string | number | boolean | null): void
40
+ (e: 'update:model-value', value: any): void
41
+ (e: 'change', value: any): void
42
42
  }>()
43
43
 
44
44
  const _value = computed(() => {
@@ -47,11 +47,11 @@ const _value = computed(() => {
47
47
  : props.value !== undefined ? props.value : null
48
48
  })
49
49
 
50
- function isChecked(value: string | number | boolean) {
50
+ function isChecked(value: any) {
51
51
  return value === _value.value
52
52
  }
53
53
 
54
- function onUpdate(value: string | number | boolean) {
54
+ function onUpdate(value: any) {
55
55
  if (value !== _value.value) {
56
56
  emit('update:model-value', value)
57
57
  return
@@ -62,7 +62,7 @@ function onUpdate(value: string | number | boolean) {
62
62
  }
63
63
  }
64
64
 
65
- function onChange(value: string | number | boolean) {
65
+ function onChange(value: any) {
66
66
  if (value !== _value.value) {
67
67
  emit('change', value)
68
68
  return
@@ -9,11 +9,11 @@ import SInputBase from './SInputBase.vue'
9
9
 
10
10
  export type Size = 'mini' | 'small' | 'medium'
11
11
  export type Color = 'neutral' | 'mute' | 'info' | 'success' | 'warning' | 'danger'
12
- export type Value = string | number | boolean | null
12
+ export type Value = any
13
13
 
14
14
  export interface Option {
15
15
  label: string
16
- value: string | number | boolean
16
+ value: any
17
17
  disabled?: boolean
18
18
  }
19
19
 
@@ -10,7 +10,7 @@ export type CheckColor = 'neutral' | 'mute' | 'info' | 'success' | 'warning' | '
10
10
 
11
11
  export interface Option {
12
12
  label: string
13
- value: string | number | boolean
13
+ value: any
14
14
  }
15
15
 
16
16
  const props = defineProps<{
@@ -25,24 +25,24 @@ const props = defineProps<{
25
25
  checkColor?: CheckColor
26
26
  options: Option[]
27
27
  disabled?: boolean
28
- modelValue: (string | number | boolean)[]
28
+ modelValue: any[]
29
29
  hideError?: boolean
30
30
  validation?: Validatable
31
31
  }>()
32
32
 
33
33
  const emit = defineEmits<{
34
- (e: 'update:modelValue', value: (string | number | boolean)[]): void
34
+ (e: 'update:modelValue', value: any[]): void
35
35
  }>()
36
36
 
37
37
  const classes = computed(() => [
38
38
  props.size ?? 'small'
39
39
  ])
40
40
 
41
- function isChecked(value: string | number | boolean): boolean {
41
+ function isChecked(value: any): boolean {
42
42
  return props.modelValue.includes(value)
43
43
  }
44
44
 
45
- function handleChange(value: string | number | boolean): void {
45
+ function handleChange(value: any): void {
46
46
  const difference = props.modelValue
47
47
  .filter((v) => v !== value)
48
48
  .concat(props.modelValue.includes(value) ? [] : [value])
@@ -1,7 +1,7 @@
1
1
  <script setup lang="ts">
2
- import { format } from 'sefirot/support/Num'
3
2
  import { computed } from 'vue'
4
3
  import { type TableCellValueColor } from '../composables/Table'
4
+ import { format } from '../support/Num'
5
5
  import SIcon from './SIcon.vue'
6
6
  import SLink from './SLink.vue'
7
7
 
@@ -31,15 +31,10 @@ export interface DropdownSectionFilter extends DropdownSectionBase {
31
31
  search?: boolean
32
32
  selected: MaybeRef<DropdownSectionFilterSelectedValue>
33
33
  options: MaybeRef<DropdownSectionFilterOption[]>
34
- onClick?(value: string | number | boolean): void
34
+ onClick?(value: any): void
35
35
  }
36
36
 
37
- export type DropdownSectionFilterSelectedValue =
38
- | string
39
- | number
40
- | boolean
41
- | null
42
- | (string | number | boolean)[]
37
+ export type DropdownSectionFilterSelectedValue = any
43
38
 
44
39
  export type DropdownSectionFilterOption =
45
40
  | DropdownSectionFilterOptionText
@@ -48,9 +43,9 @@ export type DropdownSectionFilterOption =
48
43
  export interface DropdownSectionFilterOptionBase {
49
44
  type?: 'text' | 'avatar'
50
45
  label: string
51
- value: string | number | boolean
46
+ value: any
52
47
  disabled?: boolean
53
- onClick?(value: string | number | boolean): void
48
+ onClick?(value: any): void
54
49
  }
55
50
 
56
51
  export interface DropdownSectionFilterOptionText extends DropdownSectionFilterOptionBase {
package/lib/http/Http.ts CHANGED
@@ -140,25 +140,23 @@ export class Http {
140
140
  const fd = form || new FormData()
141
141
  let formKey: string
142
142
 
143
- for (const property in obj) {
144
- if (Reflect.has(obj, property)) {
145
- if (namespace) {
146
- formKey = `${namespace}[${property}]`
147
- } else {
148
- formKey = property
149
- }
143
+ Object.keys(obj).forEach((property) => {
144
+ if (namespace) {
145
+ formKey = `${namespace}[${property}]`
146
+ } else {
147
+ formKey = property
148
+ }
150
149
 
151
- if (obj[property] === undefined) {
152
- continue
153
- }
150
+ if (obj[property] === undefined) {
151
+ return
152
+ }
154
153
 
155
- if (typeof obj[property] === 'object' && !(obj[property] instanceof Blob)) {
156
- this.objectToFormData(obj[property], fd, property)
157
- } else {
158
- fd.append(formKey, obj[property])
159
- }
154
+ if (typeof obj[property] === 'object' && !(obj[property] instanceof Blob)) {
155
+ this.objectToFormData(obj[property], fd, property)
156
+ } else {
157
+ fd.append(formKey, obj[property])
160
158
  }
161
- }
159
+ })
162
160
 
163
161
  return fd
164
162
  }
@@ -2,6 +2,7 @@ import dayjs, { type ConfigType, type Dayjs } from 'dayjs'
2
2
  import PluginRelativeTime from 'dayjs/plugin/relativeTime'
3
3
  import PluginTimezone from 'dayjs/plugin/timezone'
4
4
  import PluginUtc from 'dayjs/plugin/utc'
5
+ import { isNumber, isObject, isString } from './Utils'
5
6
 
6
7
  dayjs.extend(PluginUtc)
7
8
  dayjs.extend(PluginTimezone)
@@ -19,6 +20,14 @@ export interface Ymd {
19
20
  date: number | null
20
21
  }
21
22
 
23
+ export type YmdType = 'y' | 'm' | 'd'
24
+
25
+ export const YmdMap = {
26
+ y: 'year',
27
+ m: 'month',
28
+ d: 'date'
29
+ } as const
30
+
22
31
  /**
23
32
  * The hour, minute, and second object interface.
24
33
  */
@@ -28,6 +37,14 @@ export interface Hms {
28
37
  second: string | null
29
38
  }
30
39
 
40
+ export type HmsType = 'h' | 'm' | 's'
41
+
42
+ export const HmsMap = {
43
+ h: 'hour',
44
+ m: 'minute',
45
+ s: 'second'
46
+ } as const
47
+
31
48
  export function day(input?: Input): Day {
32
49
  return dayjs(input)
33
50
  }
@@ -69,3 +86,29 @@ export function createHms(
69
86
  second
70
87
  }
71
88
  }
89
+
90
+ export function isYmd(value: unknown, required: YmdType[] = ['y', 'm', 'd']): value is Ymd {
91
+ if (!isObject(value)) {
92
+ return false
93
+ }
94
+
95
+ return required
96
+ .reduce<string[]>((keys, type) => {
97
+ keys.push(YmdMap[type])
98
+ return keys
99
+ }, [])
100
+ .every((key) => value[key] === null || isNumber(value[key]))
101
+ }
102
+
103
+ export function isHms(value: unknown, required: HmsType[] = ['h', 'm', 's']): value is Hms {
104
+ if (!isObject(value)) {
105
+ return false
106
+ }
107
+
108
+ return required
109
+ .reduce<string[]>((keys, type) => {
110
+ keys.push(HmsMap[type])
111
+ return keys
112
+ }, [])
113
+ .every((key) => value[key] === null || isString(value[key]))
114
+ }
@@ -5,7 +5,7 @@ import { type Lang, useLang } from '../composables/Lang'
5
5
  export interface RuleOptions {
6
6
  optional?: boolean
7
7
  message(params: MessageProps): string
8
- validation(value: unknown): boolean
8
+ validation(value: unknown): boolean | Promise<boolean>
9
9
  }
10
10
 
11
11
  export interface MessageProps extends VMessageProps {
@@ -1,9 +1,15 @@
1
- import { helpers } from '@vuelidate/validators'
1
+ import { createRule } from '../Rule'
2
2
  import { checked as baseChecked } from '../validators/checked'
3
3
 
4
+ export const message = {
5
+ en: 'You must check the field.',
6
+ ja: 'この項目は選択が必須です。'
7
+ }
8
+
4
9
  export function checked(msg?: string) {
5
- return helpers.withMessage(
6
- () => msg ?? 'You must check the field.',
7
- (value: boolean) => !helpers.req(value) || baseChecked(value)
8
- )
10
+ return createRule({
11
+ message: ({ lang }) => msg ?? message[lang],
12
+ optional: true,
13
+ validation: baseChecked
14
+ })
9
15
  }
@@ -1,9 +1,14 @@
1
- import { and, decimal as baseDecimal, helpers, not } from '@vuelidate/validators'
2
- import { hyphen } from '../validators'
1
+ import { createRule } from '../Rule'
2
+ import { decimal as baseDecimal, hyphen } from '../validators'
3
+
4
+ export const message = {
5
+ en: 'The value must be valid decimal numbers.',
6
+ ja: 'この値は小数または10進数である必要があります。'
7
+ }
3
8
 
4
9
  export function decimal(msg?: string) {
5
- return helpers.withMessage(
6
- () => msg ?? 'The value must be valid decimal numbers.',
7
- and(not(hyphen), baseDecimal)
8
- )
10
+ return createRule({
11
+ message: ({ lang }) => msg ?? message[lang],
12
+ validation: (value) => !hyphen(value) && baseDecimal(value)
13
+ })
9
14
  }
@@ -1,8 +1,14 @@
1
- import { decimal as baseDecimal, helpers } from '@vuelidate/validators'
1
+ import { createRule } from '../Rule'
2
+ import { decimal as baseDecimal, hyphen } from '../validators'
3
+
4
+ export const message = {
5
+ en: 'The value must be valid decimal numbers or just a hyphen.',
6
+ ja: 'この値は小数、10進数、またはハイフンである必要があります。'
7
+ }
2
8
 
3
9
  export function decimalOrHyphen(msg?: string) {
4
- return helpers.withMessage(
5
- () => msg ?? 'The value must be valid decimal numbers or just a hyphen.',
6
- baseDecimal
7
- )
10
+ return createRule({
11
+ message: ({ lang }) => msg ?? message[lang],
12
+ validation: (value) => hyphen(value) || baseDecimal(value)
13
+ })
8
14
  }
@@ -1,8 +1,14 @@
1
- import { email as baseEmail, helpers } from '@vuelidate/validators'
1
+ import { createRule } from '../Rule'
2
+ import { email as baseEmail } from '../validators'
3
+
4
+ export const message = {
5
+ en: 'The Email is invalid.',
6
+ ja: 'Emailの形式が正しくありません。'
7
+ }
2
8
 
3
9
  export function email(msg?: string) {
4
- return helpers.withMessage(
5
- () => msg ?? 'The Email is invalid.',
6
- baseEmail
7
- )
10
+ return createRule({
11
+ message: ({ lang }) => msg ?? message[lang],
12
+ validation: baseEmail
13
+ })
8
14
  }
@@ -1,11 +1,15 @@
1
- import { helpers } from '@vuelidate/validators'
1
+ import { createRule } from '../Rule'
2
2
  import { fileExtension as baseFileExtension } from '../validators/fileExtension'
3
3
 
4
+ export const message = {
5
+ en: 'The file extension is invalid.',
6
+ ja: 'ファイル拡張子が正しくありません。'
7
+ }
8
+
4
9
  export function fileExtension(extensions: string[], msg?: string) {
5
- return helpers.withMessage(
6
- () => msg ?? 'The file extension is invalid.',
7
- (value: File) => {
8
- return !helpers.req(value) || baseFileExtension(value, extensions)
9
- }
10
- )
10
+ return createRule({
11
+ message: ({ lang }) => msg ?? message[lang],
12
+ optional: true,
13
+ validation: (value) => baseFileExtension(value, extensions)
14
+ })
11
15
  }
@@ -1,14 +1,17 @@
1
- import { helpers } from '@vuelidate/validators'
2
- import { type Hms } from '../../support/Day'
1
+ import { createRule } from '../Rule'
3
2
  import { hms as baseHms } from '../validators/hms'
4
3
 
5
4
  type HmsType = 'h' | 'm' | 's'
6
5
 
6
+ export const message = {
7
+ en: 'The time is invalid.',
8
+ ja: '時間表記が正しくありません。'
9
+ }
10
+
7
11
  export function hms(required?: HmsType[], msg?: string) {
8
- return helpers.withMessage(
9
- () => msg ?? 'The time is invalid.',
10
- (value: Hms) => {
11
- return !helpers.req(value) || baseHms(value, required)
12
- }
13
- )
12
+ return createRule({
13
+ message: ({ lang }) => msg ?? message[lang],
14
+ optional: true,
15
+ validation: (value) => baseHms(value, required)
16
+ })
14
17
  }
@@ -1,16 +1,15 @@
1
- import { helpers } from '@vuelidate/validators'
1
+ import { createRule } from '../Rule'
2
2
  import { maxFileSize as baseMaxFileSize } from '../validators/maxFileSize'
3
3
 
4
+ export const message = {
5
+ en: (size: string) => `The file must be smaller than or equal to ${size}.`,
6
+ ja: (size: string) => `ファイルは${size}よりも小さい必要があります。`
7
+ }
8
+
4
9
  export function maxFileSize(size: string, msg?: string) {
5
- return helpers.withParams(
6
- { size },
7
- helpers.withMessage(
8
- ({ $params }) => {
9
- return msg ?? `The file must be smaller than ${$params.size}.`
10
- },
11
- (value: File) => {
12
- return !helpers.req(value) || baseMaxFileSize(value, size)
13
- }
14
- )
15
- )
10
+ return createRule({
11
+ message: ({ lang }) => msg ?? message[lang](size),
12
+ optional: true,
13
+ validation: (value) => baseMaxFileSize(value, size)
14
+ })
16
15
  }
@@ -1,10 +1,15 @@
1
- import { maxLength as baseMaxLength, helpers } from '@vuelidate/validators'
1
+ import { createRule } from '../Rule'
2
+ import { maxLength as baseMaxLength } from '../validators'
3
+
4
+ export const message = {
5
+ en: (length: number) => `The value must be less than or equal to ${length} characters.`,
6
+ ja: (length: number) => `この値は、最大${length}文字までです。`
7
+ }
2
8
 
3
9
  export function maxLength(length: number, msg?: string) {
4
- return helpers.withMessage(
5
- ({ $params }) => {
6
- return msg ?? `The value must be less or equal to ${($params as any).max} characters.`
7
- },
8
- baseMaxLength(length)
9
- )
10
+ return createRule({
11
+ message: ({ lang }) => msg ?? message[lang](length),
12
+ optional: true,
13
+ validation: (value) => baseMaxLength(value, length)
14
+ })
10
15
  }
@@ -1,16 +1,15 @@
1
- import { helpers } from '@vuelidate/validators'
1
+ import { createRule } from '../Rule'
2
2
  import { maxTotalFileSize as baseMaxTotalFileSize } from '../validators/maxTotalFileSize'
3
3
 
4
+ export const message = {
5
+ en: (size: string) => `The total file size must be smaller than or equal to ${size}.`,
6
+ ja: (size: string) => `合計ファイルサイズは最大${size}までです。`
7
+ }
8
+
4
9
  export function maxTotalFileSize(size: string, msg?: string) {
5
- return helpers.withParams(
6
- { size },
7
- helpers.withMessage(
8
- ({ $params }) => {
9
- return msg ?? `The total file size must be smaller than ${$params.size}.`
10
- },
11
- (files: File[]) => {
12
- return !helpers.req(files) || baseMaxTotalFileSize(files, size)
13
- }
14
- )
15
- )
10
+ return createRule({
11
+ message: ({ lang }) => msg ?? message[lang](size),
12
+ optional: true,
13
+ validation: (value) => baseMaxTotalFileSize(value, size)
14
+ })
16
15
  }
@@ -1,10 +1,14 @@
1
- import { maxValue as baseMaxValue, helpers } from '@vuelidate/validators'
1
+ import { createRule } from '../Rule'
2
+ import { maxValue as baseMaxValue } from '../validators'
2
3
 
3
- export function maxValue(value: number, msg?: string) {
4
- return helpers.withMessage(
5
- ({ $params }) => {
6
- return msg ?? `The value must be less or equal to ${($params as any).max}.`
7
- },
8
- baseMaxValue(value)
9
- )
4
+ export const message = {
5
+ en: (max: number) => `The value must be less than or equal to ${max}.`,
6
+ ja: (max: number) => `この値は最大${max}です。`
7
+ }
8
+
9
+ export function maxValue(max: number, msg?: string) {
10
+ return createRule({
11
+ message: ({ lang }) => msg ?? message[lang](max),
12
+ validation: (value) => baseMaxValue(value, max)
13
+ })
10
14
  }
@@ -1,10 +1,15 @@
1
- import { minLength as baseMinLength, helpers } from '@vuelidate/validators'
1
+ import { createRule } from '../Rule'
2
+ import { minLength as baseMinLength } from '../validators'
3
+
4
+ export const message = {
5
+ en: (min: number) => `The value must be greater than or equal to ${min} characters.`,
6
+ ja: (min: number) => `この値は最小${min}文字です。`
7
+ }
2
8
 
3
9
  export function minLength(length: number, msg?: string) {
4
- return helpers.withMessage(
5
- ({ $params }) => {
6
- return msg ?? `The value must be greater or equal to ${($params as any).min} characters.`
7
- },
8
- baseMinLength(length)
9
- )
10
+ return createRule({
11
+ message: ({ lang }) => msg ?? message[lang](length),
12
+ optional: true,
13
+ validation: (value) => baseMinLength(value, length)
14
+ })
10
15
  }