@globalbrain/sefirot 4.31.0 → 4.32.0

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 (131) hide show
  1. package/client.d.ts +5 -0
  2. package/config/nuxt.d.ts +1 -0
  3. package/config/nuxt.js +1 -1
  4. package/config/vite.js +3 -2
  5. package/lib/components/SActionList.vue +2 -2
  6. package/lib/components/SActionMenu.vue +4 -4
  7. package/lib/components/SAvatar.vue +1 -1
  8. package/lib/components/SAvatarStack.vue +12 -12
  9. package/lib/components/SButton.vue +5 -7
  10. package/lib/components/SCard.vue +2 -2
  11. package/lib/components/SChartBar.vue +37 -12
  12. package/lib/components/SChartPie.vue +13 -7
  13. package/lib/components/SControlActionBarCollapse.vue +2 -4
  14. package/lib/components/SControlInputSearch.vue +7 -2
  15. package/lib/components/SDataListItem.vue +1 -3
  16. package/lib/components/SDescAvatar.vue +1 -1
  17. package/lib/components/SDescDay.vue +2 -2
  18. package/lib/components/SDescFile.vue +2 -4
  19. package/lib/components/SDescItem.vue +2 -1
  20. package/lib/components/SDescLabel.vue +1 -1
  21. package/lib/components/SDescLink.vue +2 -7
  22. package/lib/components/SDescPill.vue +2 -4
  23. package/lib/components/SDescText.vue +2 -2
  24. package/lib/components/SDropdown.vue +1 -1
  25. package/lib/components/SDropdownSectionFilter.vue +11 -11
  26. package/lib/components/SFragment.vue +1 -1
  27. package/lib/components/SInputAddon.vue +13 -11
  28. package/lib/components/SInputBase.vue +11 -11
  29. package/lib/components/SInputCheckbox.vue +6 -3
  30. package/lib/components/SInputCheckboxes.vue +7 -3
  31. package/lib/components/SInputDate.vue +3 -5
  32. package/lib/components/SInputDropdown.vue +26 -28
  33. package/lib/components/SInputDropdownItem.vue +21 -11
  34. package/lib/components/SInputFile.vue +9 -6
  35. package/lib/components/SInputFileUpload.vue +9 -11
  36. package/lib/components/SInputFileUploadItem.vue +8 -4
  37. package/lib/components/SInputHMS.vue +3 -1
  38. package/lib/components/SInputImage.vue +4 -2
  39. package/lib/components/SInputNumber.vue +9 -10
  40. package/lib/components/SInputRadio.vue +3 -2
  41. package/lib/components/SInputRadios.vue +6 -5
  42. package/lib/components/SInputSegments.vue +5 -7
  43. package/lib/components/SInputSegmentsOption.vue +1 -2
  44. package/lib/components/SInputSelect.vue +6 -4
  45. package/lib/components/SInputSwitch.vue +4 -1
  46. package/lib/components/SInputSwitches.vue +5 -3
  47. package/lib/components/SInputText.vue +16 -16
  48. package/lib/components/SInputTextarea.vue +7 -3
  49. package/lib/components/SInputYMD.vue +3 -1
  50. package/lib/components/SLink.vue +2 -2
  51. package/lib/components/SLocalNav.vue +1 -1
  52. package/lib/components/SLocalNavActions.vue +1 -1
  53. package/lib/components/SLocalNavMenu.vue +2 -2
  54. package/lib/components/SLoginPagePasswordDialog.vue +2 -2
  55. package/lib/components/SM.vue +1 -1
  56. package/lib/components/SMFade.vue +1 -1
  57. package/lib/components/SMarkdown.vue +3 -2
  58. package/lib/components/SModal.vue +2 -2
  59. package/lib/components/SSnackbar.vue +2 -2
  60. package/lib/components/SSteps.vue +6 -6
  61. package/lib/components/STable.vue +70 -27
  62. package/lib/components/STableCell.vue +14 -17
  63. package/lib/components/STableCellAvatars.vue +1 -1
  64. package/lib/components/STableCellDay.vue +12 -5
  65. package/lib/components/STableCellNumber.vue +2 -3
  66. package/lib/components/STableCellPath.vue +2 -2
  67. package/lib/components/STableCellText.vue +2 -3
  68. package/lib/components/STableColumn.vue +38 -16
  69. package/lib/components/STableFooter.vue +10 -2
  70. package/lib/components/STableHeader.vue +0 -1
  71. package/lib/components/STableHeaderMenu.vue +4 -4
  72. package/lib/components/STableHeaderMenuItem.vue +1 -1
  73. package/lib/components/STooltip.vue +3 -3
  74. package/lib/composables/Dropdown.ts +10 -1
  75. package/lib/composables/Error.ts +37 -37
  76. package/lib/composables/Grid.ts +1 -4
  77. package/lib/composables/Image.ts +2 -3
  78. package/lib/composables/Lang.ts +1 -1
  79. package/lib/composables/Markdown.ts +1 -1
  80. package/lib/composables/Table.ts +0 -2
  81. package/lib/composables/Theme.ts +1 -1
  82. package/lib/composables/Utils.ts +11 -4
  83. package/lib/composables/Validation.ts +1 -4
  84. package/lib/http/Http.ts +23 -17
  85. package/lib/styles/variables-deprecated.css +0 -1
  86. package/lib/styles/variables.css +16 -16
  87. package/lib/support/Chart.ts +0 -1
  88. package/lib/support/DateRange.ts +1 -1
  89. package/lib/support/Day.ts +12 -65
  90. package/lib/support/File.ts +7 -16
  91. package/lib/support/Utils.ts +7 -40
  92. package/lib/validation/Rule.ts +6 -21
  93. package/lib/validation/rules/decimal.ts +3 -3
  94. package/lib/validation/rules/email.ts +1 -1
  95. package/lib/validation/rules/index.ts +1 -1
  96. package/lib/validation/rules/negativeInteger.ts +1 -1
  97. package/lib/validation/rules/positiveInteger.ts +1 -1
  98. package/lib/validation/rules/requiredHms.ts +2 -2
  99. package/lib/validation/rules/requiredIf.ts +1 -4
  100. package/lib/validation/rules/requiredYmd.ts +2 -2
  101. package/lib/validation/rules/slackChannelName.ts +4 -1
  102. package/lib/validation/rules/zeroOrNegativeInteger.ts +1 -1
  103. package/lib/validation/rules/zeroOrPositiveInteger.ts +1 -1
  104. package/lib/validation/validators/after.ts +1 -5
  105. package/lib/validation/validators/afterOrEqual.ts +1 -5
  106. package/lib/validation/validators/before.ts +1 -4
  107. package/lib/validation/validators/beforeOrEqual.ts +1 -5
  108. package/lib/validation/validators/decimal.ts +7 -9
  109. package/lib/validation/validators/email.ts +4 -8
  110. package/lib/validation/validators/fileExtension.ts +7 -15
  111. package/lib/validation/validators/hms.ts +26 -15
  112. package/lib/validation/validators/index.ts +0 -2
  113. package/lib/validation/validators/maxFileSize.ts +3 -13
  114. package/lib/validation/validators/maxLength.ts +1 -7
  115. package/lib/validation/validators/maxTotalFileSize.ts +3 -26
  116. package/lib/validation/validators/maxValue.ts +2 -6
  117. package/lib/validation/validators/minLength.ts +1 -7
  118. package/lib/validation/validators/minValue.ts +2 -6
  119. package/lib/validation/validators/month.ts +1 -7
  120. package/lib/validation/validators/negativeInteger.ts +1 -7
  121. package/lib/validation/validators/positiveInteger.ts +1 -7
  122. package/lib/validation/validators/required.ts +5 -28
  123. package/lib/validation/validators/requiredHmsIf.ts +11 -13
  124. package/lib/validation/validators/requiredIf.ts +5 -11
  125. package/lib/validation/validators/requiredYmdIf.ts +11 -13
  126. package/lib/validation/validators/slackChannelName.ts +11 -11
  127. package/lib/validation/validators/url.ts +7 -5
  128. package/lib/validation/validators/ymd.ts +36 -30
  129. package/package.json +38 -38
  130. package/lib/validation/validators/requiredHms.ts +0 -9
  131. package/lib/validation/validators/requiredYmd.ts +0 -9
@@ -1,5 +1,12 @@
1
- import { type ComputedRef, type MaybeRefOrGetter, computed, getCurrentInstance, onMounted, toValue, useSlots } from 'vue'
2
- import { isString } from '../support/Utils'
1
+ import {
2
+ type ComputedRef,
3
+ type MaybeRefOrGetter,
4
+ computed,
5
+ getCurrentInstance,
6
+ onMounted,
7
+ toValue,
8
+ useSlots
9
+ } from 'vue'
3
10
 
4
11
  export type WhenCondition<T> = MaybeRefOrGetter<T>
5
12
 
@@ -22,7 +29,7 @@ export function computedWhen<T, C, D>(
22
29
  return computed(() => {
23
30
  const c = toValue(condition)
24
31
 
25
- return c ? fn(c) : whenFalse as D
32
+ return c ? fn(c) : (whenFalse as D)
26
33
  })
27
34
  }
28
35
 
@@ -68,7 +75,7 @@ export function useSlotValue(name = 'default'): ComputedRef<string | null> {
68
75
 
69
76
  return computed(() => {
70
77
  const c = slots[name]?.()[0]?.children
71
- const v = isString(c) ? c.trim() : null
78
+ const v = typeof c === 'string' ? c.trim() : null
72
79
  return v !== '' ? v : null
73
80
  })
74
81
  }
@@ -85,10 +85,7 @@ export function useVNotification(): VNotification {
85
85
  const snackbars = useSnackbars()
86
86
 
87
87
  function notify(message?: Snackbar): void {
88
- snackbars.push(message ?? {
89
- mode: 'danger',
90
- text: t.notify
91
- })
88
+ snackbars.push(message ?? { mode: 'danger', text: t.notify })
92
89
  }
93
90
 
94
91
  return {
package/lib/http/Http.ts CHANGED
@@ -3,7 +3,6 @@ import { parse as parseCookie } from '@tinyhttp/cookie'
3
3
  import FileSaver from 'file-saver'
4
4
  import { FetchError, type FetchOptions, type FetchResponse } from 'ofetch'
5
5
  import { stringify } from 'qs'
6
- import { isBlob, isError, isFormData, isRequest, isResponse, isString } from '../support/Utils'
7
6
 
8
7
  type Config = ReturnType<typeof import('../stores/HttpConfig').useHttpConfig>
9
8
 
@@ -31,9 +30,13 @@ export class Http {
31
30
 
32
31
  private async buildRequest(url: string, _options: FetchOptions = {}): Promise<[string, FetchOptions]> {
33
32
  const { method, params, query, ...options } = _options
34
- const xsrfToken = ['POST', 'PUT', 'PATCH', 'DELETE'].includes(method || '') && (await this.ensureXsrfToken())
33
+ const xsrfToken = ['POST', 'PUT', 'PATCH', 'DELETE'].includes(method || '')
34
+ && (await this.ensureXsrfToken())
35
35
 
36
- const queryString = stringify({ ...params, ...query }, { encodeValuesOnly: true, ...this.config.stringifyOptions })
36
+ const queryString = stringify(
37
+ { ...params, ...query },
38
+ { encodeValuesOnly: true, ...this.config.stringifyOptions }
39
+ )
37
40
 
38
41
  return [
39
42
  `${url}${queryString ? `?${queryString}` : ''}`,
@@ -70,11 +73,11 @@ export class Http {
70
73
  }
71
74
 
72
75
  async post<T = any>(url: string, body?: any, options?: FetchOptions): Promise<T> {
73
- if (body && !isFormData(body)) {
76
+ if (body && !(body instanceof FormData)) {
74
77
  let hasFile = false
75
78
 
76
79
  const payload = JSON.stringify(body, (_, value) => {
77
- if (isBlob(value)) {
80
+ if (value instanceof Blob) {
78
81
  hasFile = true
79
82
  return undefined
80
83
  }
@@ -120,13 +123,18 @@ export class Http {
120
123
  throw new Error('No blob')
121
124
  }
122
125
 
123
- const { filename = 'download' }
124
- = parseContentDisposition(headers.get('Content-Disposition') || '')?.parameters || {}
126
+ const { filename = 'download' } =
127
+ parseContentDisposition(headers.get('Content-Disposition') || '')?.parameters || {}
125
128
 
126
129
  FileSaver.saveAs(blob, filename as string)
127
130
  }
128
131
 
129
- private objectToFormData(obj: any, form?: FormData, namespace?: string, onlyFiles = false): FormData {
132
+ private objectToFormData(
133
+ obj: any,
134
+ form?: FormData,
135
+ namespace?: string,
136
+ onlyFiles = false
137
+ ): FormData {
130
138
  const fd = form || new FormData()
131
139
  let formKey: string
132
140
 
@@ -141,11 +149,15 @@ export class Http {
141
149
  return
142
150
  }
143
151
 
144
- if (typeof obj[property] === 'object' && !isBlob(obj[property]) && obj[property] !== null) {
152
+ if (
153
+ typeof obj[property] === 'object'
154
+ && !(obj[property] instanceof Blob)
155
+ && obj[property] !== null
156
+ ) {
145
157
  this.objectToFormData(obj[property], fd, property, onlyFiles)
146
158
  } else {
147
159
  const value = obj[property] === null ? '' : obj[property]
148
- if (onlyFiles && !isBlob(value)) {
160
+ if (onlyFiles && !(value instanceof Blob)) {
149
161
  return
150
162
  }
151
163
  fd.append(formKey, value)
@@ -157,13 +169,7 @@ export class Http {
157
169
  }
158
170
 
159
171
  export function isFetchError(e: unknown): e is FetchError {
160
- return (
161
- e instanceof FetchError
162
- || (isError<FetchError>(e)
163
- && (e.response === undefined || isResponse(e.response))
164
- && ((isString(e.request) && e.message.startsWith(`[${e.options?.method || 'GET'}] ${JSON.stringify(e.request || '/')}: `))
165
- || (isRequest(e.request) && e.message.startsWith(`[${e.request.method}] ${JSON.stringify(e.request.url)}: `))))
166
- )
172
+ return e instanceof FetchError || (e instanceof Error && e.name === 'FetchError')
167
173
  }
168
174
 
169
175
  export { FetchError, type FetchOptions, type FetchRequest, type FetchResponse } from 'ofetch'
@@ -110,7 +110,6 @@
110
110
  */
111
111
  :root {
112
112
  --c-soft: var(--c-white-soft);
113
-
114
113
  }
115
114
 
116
115
  .dark {
@@ -154,7 +154,7 @@
154
154
  * Color: Divider and Gutter
155
155
  * -------------------------------------------------------------------------- */
156
156
 
157
- :root {
157
+ :root {
158
158
  --c-divider: #e0e0e1;
159
159
  --c-gutter: #e2e2e3;
160
160
  }
@@ -290,7 +290,7 @@
290
290
  * Color: Border
291
291
  * -------------------------------------------------------------------------- */
292
292
 
293
- :root {
293
+ :root {
294
294
  --c-border-mute-1: var(--c-gray-6);
295
295
  --c-border-mute-2: var(--c-gray-7);
296
296
  --c-border-mute-3: var(--c-gray-8);
@@ -316,7 +316,7 @@
316
316
  * Color: Text
317
317
  * -------------------------------------------------------------------------- */
318
318
 
319
- :root {
319
+ :root {
320
320
  --c-text-1: var(--c-text-light-1);
321
321
  --c-text-2: var(--c-text-light-2);
322
322
  --c-text-3: var(--c-text-light-3);
@@ -367,11 +367,11 @@
367
367
  * -------------------------------------------------------------------------- */
368
368
 
369
369
  :root {
370
- --shadow-depth-1: 0 1px 2px rgba(0, 0, 0, .04), 0 1px 2px rgba(0, 0, 0, .06);
371
- --shadow-depth-2: 0 3px 12px rgba(0, 0, 0, .07), 0 1px 4px rgba(0, 0, 0, .07);
372
- --shadow-depth-3: 0 12px 32px rgba(0, 0, 0, .1), 0 2px 6px rgba(0, 0, 0, .08);
373
- --shadow-depth-4: 0 14px 44px rgba(0, 0, 0, .12), 0 3px 9px rgba(0, 0, 0, .12);
374
- --shadow-depth-5: 0 18px 56px rgba(0, 0, 0, .16), 0 4px 12px rgba(0, 0, 0, .16);
370
+ --shadow-depth-1: 0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.06);
371
+ --shadow-depth-2: 0 3px 12px rgba(0, 0, 0, 0.07), 0 1px 4px rgba(0, 0, 0, 0.07);
372
+ --shadow-depth-3: 0 12px 32px rgba(0, 0, 0, 0.1), 0 2px 6px rgba(0, 0, 0, 0.08);
373
+ --shadow-depth-4: 0 14px 44px rgba(0, 0, 0, 0.12), 0 3px 9px rgba(0, 0, 0, 0.12);
374
+ --shadow-depth-5: 0 18px 56px rgba(0, 0, 0, 0.16), 0 4px 12px rgba(0, 0, 0, 0.16);
375
375
  }
376
376
 
377
377
  /**
@@ -389,15 +389,15 @@
389
389
  * -------------------------------------------------------------------------- */
390
390
 
391
391
  :root {
392
- --ease-in-quint: cubic-bezier(.755, .05, .855, .06);
393
- --ease-in-back: cubic-bezier(1, -.75, 1, 1);
392
+ --ease-in-quint: cubic-bezier(0.755, 0.05, 0.855, 0.06);
393
+ --ease-in-back: cubic-bezier(1, -0.75, 1, 1);
394
394
 
395
- --ease-out-quint: cubic-bezier(.23, 1, .32, 1);
396
- --ease-out-expo: cubic-bezier(.19, 1, .22, 1);
397
- --ease-out-back: cubic-bezier(.175, .885, .320, 1.275);
398
- --ease-out-back-quint: cubic-bezier(.175, .885, .280, 1.5);
395
+ --ease-out-quint: cubic-bezier(0.23, 1, 0.32, 1);
396
+ --ease-out-expo: cubic-bezier(0.19, 1, 0.22, 1);
397
+ --ease-out-back: cubic-bezier(0.175, 0.885, 0.32, 1.275);
398
+ --ease-out-back-quint: cubic-bezier(0.175, 0.885, 0.28, 1.5);
399
399
 
400
- --ease-in-out-quint: cubic-bezier(.86, 0, .07, 1);
400
+ --ease-in-out-quint: cubic-bezier(0.86, 0, 0.07, 1);
401
401
  --ease-in-out-expo: cubic-bezier(1, 0, 0, 1);
402
402
  }
403
403
 
@@ -503,7 +503,7 @@
503
503
  --button-fill-black-hover-text-color: var(--c-text-dark-1);
504
504
  --button-fill-black-hover-bg-color: var(--c-neutral-light-2);
505
505
  --button-fill-black-active-border-color: transparent;
506
- --button-fill-black-active-text-color:var(--c-text-dark-1);
506
+ --button-fill-black-active-text-color: var(--c-text-dark-1);
507
507
  --button-fill-black-active-bg-color: var(--c-neutral-light-3);
508
508
  --button-fill-black-disabled-border-color: transparent;
509
509
  --button-fill-black-disabled-text-color: var(--c-text-dark-2);
@@ -37,7 +37,6 @@ export const chartColors = {
37
37
  gray: 'light-dark(#8d8d8d, #7b7b7b)'
38
38
  } as const
39
39
 
40
- // eslint-disable-next-line @typescript-eslint/ban-types
41
40
  export type ChartColor = keyof typeof chartColors | (string & {})
42
41
  export type KV = { key: string; value: number; color?: ChartColor }
43
42
  export type Margins = Partial<{ top: number; right: number; bottom: number; left: number }>
@@ -93,7 +93,7 @@ export class DateFromTo extends DateRangePresetBase {
93
93
  const f = this.getFrom()?.format('YYYY-MM-DD')
94
94
  const t = this.getTo()?.format('YYYY-MM-DD')
95
95
 
96
- return (f && t) ? `${f} – ${t}` : 'Error'
96
+ return f && t ? `${f} – ${t}` : 'Error'
97
97
  }
98
98
 
99
99
  setFrom(from: Day | null): this {
@@ -2,7 +2,6 @@ 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'
6
5
 
7
6
  dayjs.extend(PluginUtc)
8
7
  dayjs.extend(PluginTimezone)
@@ -22,12 +21,6 @@ export interface Ymd {
22
21
 
23
22
  export type YmdType = 'y' | 'm' | 'd'
24
23
 
25
- export const YmdMap = {
26
- y: 'year',
27
- m: 'month',
28
- d: 'date'
29
- } as const
30
-
31
24
  /**
32
25
  * The hour, minute, and second object interface.
33
26
  */
@@ -39,13 +32,13 @@ export interface Hms {
39
32
 
40
33
  export type HmsType = 'h' | 'm' | 's'
41
34
 
42
- export const HmsMap = {
43
- h: 'hour',
44
- m: 'minute',
45
- s: 'second'
46
- } as const
47
-
48
35
  export function day(input?: Input): Day {
36
+ // hack for histoire
37
+ if (input && typeof input === 'object' && !(input instanceof Date)) {
38
+ const { $D, $H, $M, $m, $ms, $s, $y } = input as any
39
+ input = new Date($y, $M, $D, $H, $m, $s, $ms)
40
+ }
41
+
49
42
  return dayjs(input)
50
43
  }
51
44
 
@@ -67,19 +60,9 @@ export function createYmd(
67
60
  month: number | null = null,
68
61
  date: number | null = null
69
62
  ): Ymd {
70
- if (isNumber(yearOrDay) || yearOrDay == null) {
71
- return {
72
- year: yearOrDay,
73
- month,
74
- date
75
- }
76
- }
77
-
78
- return {
79
- year: yearOrDay.year(),
80
- month: yearOrDay.month() + 1,
81
- date: yearOrDay.date()
82
- }
63
+ return isDay(yearOrDay)
64
+ ? { year: yearOrDay.year(), month: yearOrDay.month() + 1, date: yearOrDay.date() }
65
+ : { year: yearOrDay, month, date }
83
66
  }
84
67
 
85
68
  /**
@@ -92,45 +75,9 @@ export function createHms(
92
75
  minute: string | null = null,
93
76
  second: string | null = null
94
77
  ): Hms {
95
- if (isString(hourOrDay) || hourOrDay == null) {
96
- return {
97
- hour: hourOrDay,
98
- minute,
99
- second
100
- }
101
- }
102
-
103
- return {
104
- hour: hourOrDay.format('HH'),
105
- minute: hourOrDay.format('mm'),
106
- second: hourOrDay.format('ss')
107
- }
108
- }
109
-
110
- export function isYmd(value: unknown, required: YmdType[] = ['y', 'm', 'd']): value is Ymd {
111
- if (value == null || !isObject(value)) {
112
- return false
113
- }
114
-
115
- return required
116
- .reduce<string[]>((keys, type) => {
117
- keys.push(YmdMap[type])
118
- return keys
119
- }, [])
120
- .every((key) => value[key] === null || isNumber(value[key]))
121
- }
122
-
123
- export function isHms(value: unknown, required: HmsType[] = ['h', 'm', 's']): value is Hms {
124
- if (value == null || !isObject(value)) {
125
- return false
126
- }
127
-
128
- return required
129
- .reduce<string[]>((keys, type) => {
130
- keys.push(HmsMap[type])
131
- return keys
132
- }, [])
133
- .every((key) => value[key] === null || isString(value[key]))
78
+ return isDay(hourOrDay)
79
+ ? { hour: hourOrDay.format('HH'), minute: hourOrDay.format('mm'), second: hourOrDay.format('ss') }
80
+ : { hour: hourOrDay, minute, second }
134
81
  }
135
82
 
136
83
  export function isDay(value: unknown): value is Day {
@@ -1,24 +1,15 @@
1
- /**
2
- * Get extension of the given file.
3
- */
4
- export function getExtension(file: File): string {
5
- const name = file.name
6
-
7
- return name.slice((name.lastIndexOf('.') - 1 >>> 0) + 2)
8
- }
1
+ const units = ['B', 'kB', 'MB', 'GB'] as const
9
2
 
10
3
  /**
11
4
  * Formats the file size in bytes to a human-readable format. It also accepts
12
5
  * array of files and returns the total size.
13
6
  */
14
7
  export function formatSize(files: File | File[]): string {
15
- const units = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']
16
8
  files = Array.isArray(files) ? files : [files]
17
- let size = files.reduce((previous, file) => previous + file.size, 0)
18
- let index = 0
19
- while (size >= 1024 && index < units.length) {
20
- size /= 1024
21
- index++
22
- }
23
- return `${size.toFixed(2)}${units[index]}`
9
+
10
+ const size = files.reduce((sum, file) => sum + file.size, 0)
11
+ if (size === 0) { return `0 ${units[0]}` }
12
+
13
+ const i = Math.min(Math.floor(Math.log(size) / Math.log(1000)), units.length - 1)
14
+ return `${(size / 1000 ** i).toFixed(2)} ${units[i]}`
24
15
  }
@@ -1,49 +1,16 @@
1
- // eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
2
- // @ts-ignore internal
3
- import baseGetTag from 'lodash-es/_baseGetTag'
4
-
5
- import _isDate from 'lodash-es/isDate'
6
- import _isError from 'lodash-es/isError'
7
- import _isNumber from 'lodash-es/isNumber'
8
- import _isPlainObject from 'lodash-es/isPlainObject'
9
- import _isString from 'lodash-es/isString'
10
-
11
- export function isBlob(value: unknown): value is Blob {
12
- return value instanceof Blob || baseGetTag(value) === '[object Blob]'
13
- }
14
-
15
- export function isDate(value: unknown): value is Date {
16
- return _isDate(value)
17
- }
18
-
19
- export function isError<T extends Error = Error>(value: unknown): value is T {
20
- return _isError(value)
21
- }
22
-
23
- export function isFile(value: unknown): value is File {
24
- return value instanceof File || baseGetTag(value) === '[object File]'
25
- }
26
-
27
- export function isFormData(value: unknown): value is FormData {
28
- return value instanceof FormData || baseGetTag(value) === '[object FormData]'
29
- }
30
-
1
+ /** @deprecated */
31
2
  export function isNumber(value: unknown): value is number {
32
- return _isNumber(value)
3
+ return Number.isFinite(value)
33
4
  }
34
5
 
35
6
  export function isObject(value: unknown): value is Record<string, unknown> {
36
- return _isPlainObject(value)
37
- }
38
-
39
- export function isRequest(value: unknown): value is Request {
40
- return value instanceof Request || baseGetTag(value) === '[object Request]'
41
- }
7
+ if (value == null || typeof value !== 'object') { return false }
42
8
 
43
- export function isResponse(value: unknown): value is Response {
44
- return value instanceof Response || baseGetTag(value) === '[object Response]'
9
+ const proto = Object.getPrototypeOf(value)
10
+ return proto === null || proto === Object.prototype
45
11
  }
46
12
 
13
+ /** @deprecated */
47
14
  export function isString(value: unknown): value is string {
48
- return _isString(value)
15
+ return typeof value === 'string'
49
16
  }
@@ -1,7 +1,7 @@
1
1
  import { type ValidationRuleWithParams } from '@vuelidate/core'
2
2
  import { type MessageProps as VMessageProps, helpers } from '@vuelidate/validators'
3
3
  import { type Lang } from '../composables/Lang'
4
- import { _required } from './validators'
4
+ import { required } from './validators'
5
5
 
6
6
  export interface RuleOptions {
7
7
  optional?: boolean
@@ -15,34 +15,19 @@ export interface MessageProps extends VMessageProps {
15
15
  lang: Lang
16
16
  }
17
17
 
18
- export function createRule(
19
- options: RuleOptions
20
- ): ValidationRuleWithParams {
18
+ export function createRule(options: RuleOptions): ValidationRuleWithParams {
21
19
  const lang = typeof document !== 'undefined'
22
20
  ? (document.documentElement.lang === 'ja' ? 'ja' : 'en')
23
21
  : 'en'
24
22
 
25
23
  const params = options.params ?? {}
26
24
 
27
- const validator = helpers.withParams(
28
- params,
29
- (value: unknown) => {
30
- return options.optional && !_required(value)
31
- ? true
32
- : options.validation(value)
33
- }
34
- )
25
+ const validator = helpers.withParams(params, (value: unknown) => {
26
+ return options.optional && !required(value, false) ? true : options.validation(value)
27
+ })
35
28
 
36
29
  return helpers.withMessage(
37
30
  (params) => options.message({ ...params, lang }),
38
- options.async
39
- ? helpers.withAsync(validator, createParamsForAsyncValidator(params))
40
- : validator
31
+ options.async ? helpers.withAsync(validator, Object.values(params)) : validator
41
32
  )
42
33
  }
43
-
44
- function createParamsForAsyncValidator(params: Record<string, any>) {
45
- return Object.keys(params).map((key) => {
46
- return params[key]
47
- })
48
- }
@@ -1,8 +1,8 @@
1
1
  import { createRule } from '../Rule'
2
- import { decimal as baseDecimal, hyphen } from '../validators'
2
+ import { decimal as baseDecimal } from '../validators'
3
3
 
4
4
  export const message = {
5
- en: 'The value must be valid decimal numbers.',
5
+ en: 'The value must be a valid decimal number.',
6
6
  ja: 'この値は小数または10進数である必要があります。'
7
7
  }
8
8
 
@@ -10,6 +10,6 @@ export function decimal(msg?: string) {
10
10
  return createRule({
11
11
  message: ({ lang }) => msg ?? message[lang],
12
12
  optional: true,
13
- validation: (value) => !hyphen(value) && baseDecimal(value)
13
+ validation: (value) => baseDecimal(value)
14
14
  })
15
15
  }
@@ -2,7 +2,7 @@ import { createRule } from '../Rule'
2
2
  import { email as baseEmail } from '../validators'
3
3
 
4
4
  export const message = {
5
- en: 'The Email is invalid.',
5
+ en: 'The email is invalid.',
6
6
  ja: 'Emailの形式が正しくありません。'
7
7
  }
8
8
 
@@ -1,4 +1,3 @@
1
- export { and, not, or } from '@vuelidate/validators'
2
1
  export { after } from './after'
3
2
  export { afterOrEqual } from './afterOrEqual'
4
3
  export { before } from './before'
@@ -30,3 +29,4 @@ export { url } from './url'
30
29
  export { ymd } from './ymd'
31
30
  export { zeroOrNegativeInteger } from './zeroOrNegativeInteger'
32
31
  export { zeroOrPositiveInteger } from './zeroOrPositiveInteger'
32
+ export { and, not, or } from '@vuelidate/validators'
@@ -2,7 +2,7 @@ import { createRule } from '../Rule'
2
2
  import { negativeInteger as baseNegativeInteger } from '../validators'
3
3
 
4
4
  export const message = {
5
- en: 'The value must be valid negative integer.',
5
+ en: 'The value must be a valid negative integer.',
6
6
  ja: 'この値は負の整数である必要があります。'
7
7
  }
8
8
 
@@ -2,7 +2,7 @@ import { createRule } from '../Rule'
2
2
  import { positiveInteger as basePositiveInteger } from '../validators'
3
3
 
4
4
  export const message = {
5
- en: 'The value must be valid positive integer.',
5
+ en: 'The value must be a valid positive integer.',
6
6
  ja: 'この値は正の整数である必要があります。'
7
7
  }
8
8
 
@@ -1,6 +1,6 @@
1
1
  import { type HmsType } from '../../support/Day'
2
2
  import { createRule } from '../Rule'
3
- import { requiredHms as baseRequiredHms } from '../validators/requiredHms'
3
+ import { hms as baseHms } from '../validators/hms'
4
4
 
5
5
  export const message = {
6
6
  en: 'The field is required.',
@@ -10,6 +10,6 @@ export const message = {
10
10
  export function requiredHms(required?: HmsType[], msg?: string) {
11
11
  return createRule({
12
12
  message: ({ lang }) => msg ?? message[lang],
13
- validation: (value) => baseRequiredHms(value, required)
13
+ validation: (value) => baseHms(value, required, true)
14
14
  })
15
15
  }
@@ -6,10 +6,7 @@ export const message = {
6
6
  ja: 'この項目は必須です。'
7
7
  }
8
8
 
9
- export function requiredIf(
10
- condition: RequiredIfCondition,
11
- msg?: string
12
- ) {
9
+ export function requiredIf(condition: RequiredIfCondition, msg?: string) {
13
10
  return createRule({
14
11
  async: true,
15
12
  params: { condition },
@@ -1,6 +1,6 @@
1
1
  import { type YmdType } from '../../support/Day'
2
2
  import { createRule } from '../Rule'
3
- import { requiredYmd as baseRequiredYmd } from '../validators/requiredYmd'
3
+ import { ymd as baseYmd } from '../validators/ymd'
4
4
 
5
5
  export const message = {
6
6
  en: 'The field is required.',
@@ -10,6 +10,6 @@ export const message = {
10
10
  export function requiredYmd(required?: YmdType[], msg?: string) {
11
11
  return createRule({
12
12
  message: ({ lang }) => msg ?? message[lang],
13
- validation: (value) => baseRequiredYmd(value, required)
13
+ validation: (value) => baseYmd(value, required, true)
14
14
  })
15
15
  }
@@ -1,5 +1,8 @@
1
1
  import { createRule } from '../Rule'
2
- import { type SlackChannelNameOptions, slackChannelName as baseSlackChannelName } from '../validators'
2
+ import {
3
+ type SlackChannelNameOptions,
4
+ slackChannelName as baseSlackChannelName
5
+ } from '../validators'
3
6
 
4
7
  export const message = {
5
8
  en: 'The slack channel name is invalid.',
@@ -2,7 +2,7 @@ import { createRule } from '../Rule'
2
2
  import { negativeInteger as baseNegativeInteger, zero } from '../validators'
3
3
 
4
4
  export const message = {
5
- en: 'The value must be zero or valid negative integer.',
5
+ en: 'The value must be zero or a valid negative integer.',
6
6
  ja: 'この値はゼロまたは負の整数である必要があります。'
7
7
  }
8
8
 
@@ -2,7 +2,7 @@ import { createRule } from '../Rule'
2
2
  import { positiveInteger as basePositiveInteger, zero } from '../validators'
3
3
 
4
4
  export const message = {
5
- en: 'The value must be zero or valid positive integer.',
5
+ en: 'The value must be zero or a valid positive integer.',
6
6
  ja: 'この値はゼロまたは正の整数である必要があります。'
7
7
  }
8
8
 
@@ -1,9 +1,5 @@
1
1
  import { type Day, isDay } from '../../support/Day'
2
2
 
3
3
  export function after(value: unknown, date: Day): boolean {
4
- if (!isDay(value) || !isDay(date)) {
5
- return false
6
- }
7
-
8
- return value.isAfter(date)
4
+ return isDay(value) && isDay(date) && value.isAfter(date, 'day')
9
5
  }
@@ -1,9 +1,5 @@
1
1
  import { type Day, isDay } from '../../support/Day'
2
2
 
3
3
  export function afterOrEqual(value: unknown, date: Day): boolean {
4
- if (!isDay(value) || !isDay(date)) {
5
- return false
6
- }
7
-
8
- return value.isAfter(date) || value.isSame(date)
4
+ return isDay(value) && isDay(date) && (value.isAfter(date, 'day') || value.isSame(date, 'day'))
9
5
  }
@@ -1,8 +1,5 @@
1
1
  import { type Day, isDay } from '../../support/Day'
2
2
 
3
3
  export function before(value: unknown, date: Day): boolean {
4
- if (!isDay(value) || !isDay(date)) {
5
- return false
6
- }
7
- return value.isBefore(date)
4
+ return isDay(value) && isDay(date) && value.isBefore(date, 'day')
8
5
  }