@globalbrain/sefirot 3.13.1 → 3.15.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.
- package/lib/components/SInputBase.vue +1 -1
- package/lib/components/SInputCheckbox.vue +1 -1
- package/lib/components/SInputCheckboxes.vue +1 -1
- package/lib/components/SInputDate.vue +1 -1
- package/lib/components/SInputDropdown.vue +1 -1
- package/lib/components/SInputFile.vue +1 -1
- package/lib/components/SInputHMS.vue +1 -1
- package/lib/components/SInputImage.vue +1 -1
- package/lib/components/SInputNumber.vue +1 -1
- package/lib/components/SInputRadio.vue +1 -1
- package/lib/components/SInputRadios.vue +1 -1
- package/lib/components/SInputSegments.vue +1 -1
- package/lib/components/SInputSelect.vue +1 -1
- package/lib/components/SInputSwitch.vue +1 -1
- package/lib/components/SInputSwitches.vue +1 -1
- package/lib/components/SInputText.vue +1 -1
- package/lib/components/SInputTextarea.vue +1 -1
- package/lib/components/SInputYMD.vue +1 -1
- package/lib/components/STrans.vue +13 -0
- package/lib/composables/Card.ts +4 -4
- package/lib/composables/D.ts +21 -0
- package/lib/composables/Data.ts +4 -0
- package/lib/composables/Form.ts +4 -0
- package/lib/composables/Lang.ts +34 -0
- package/lib/composables/V.ts +73 -0
- package/lib/composables/Validation.ts +4 -0
- package/lib/validation/Rule.ts +30 -0
- package/lib/validation/rules/index.ts +24 -24
- package/lib/validation/rules/required.ts +11 -5
- package/lib/validation/validators/index.ts +1 -0
- package/lib/validation/validators/required.ts +25 -0
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { type IconifyIcon } from '@iconify/vue/dist/offline'
|
|
3
3
|
import IconQuestion from '@iconify-icons/ph/question'
|
|
4
4
|
import { type DefineComponent, computed, unref, useSlots } from 'vue'
|
|
5
|
-
import { type Validatable } from '../composables/
|
|
5
|
+
import { type Validatable } from '../composables/V'
|
|
6
6
|
import SIcon from './SIcon.vue'
|
|
7
7
|
import STooltip from './STooltip.vue'
|
|
8
8
|
|
|
@@ -3,7 +3,7 @@ import { type IconifyIcon } from '@iconify/vue/dist/offline'
|
|
|
3
3
|
import IconCheck from '@iconify-icons/ph/check-bold'
|
|
4
4
|
import IconMinus from '@iconify-icons/ph/minus-bold'
|
|
5
5
|
import { computed } from 'vue'
|
|
6
|
-
import { type Validatable } from '../composables/
|
|
6
|
+
import { type Validatable } from '../composables/V'
|
|
7
7
|
import SIcon from './SIcon.vue'
|
|
8
8
|
import SInputBase from './SInputBase.vue'
|
|
9
9
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { type IconifyIcon } from '@iconify/vue/dist/offline'
|
|
3
3
|
import { computed } from 'vue'
|
|
4
|
-
import { type Validatable } from '../composables/
|
|
4
|
+
import { type Validatable } from '../composables/V'
|
|
5
5
|
import SInputBase from './SInputBase.vue'
|
|
6
6
|
import SInputCheckbox from './SInputCheckbox.vue'
|
|
7
7
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { type IconifyIcon } from '@iconify/vue/dist/offline'
|
|
3
3
|
import { DatePicker } from 'v-calendar'
|
|
4
4
|
import { computed } from 'vue'
|
|
5
|
-
import { type Validatable } from '../composables/
|
|
5
|
+
import { type Validatable } from '../composables/V'
|
|
6
6
|
import { type Day, day } from '../support/Day'
|
|
7
7
|
import SInputBase from './SInputBase.vue'
|
|
8
8
|
|
|
@@ -6,7 +6,7 @@ import xor from 'lodash-es/xor'
|
|
|
6
6
|
import { type DefineComponent, computed, ref } from 'vue'
|
|
7
7
|
import { type DropdownSectionFilter, useManualDropdownPosition } from '../composables/Dropdown'
|
|
8
8
|
import { useFlyout } from '../composables/Flyout'
|
|
9
|
-
import { type Validatable } from '../composables/
|
|
9
|
+
import { type Validatable } from '../composables/V'
|
|
10
10
|
import { isArray } from '../support/Utils'
|
|
11
11
|
import SDropdown from './SDropdown.vue'
|
|
12
12
|
import SIcon from './SIcon.vue'
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { type IconifyIcon } from '@iconify/vue/dist/offline'
|
|
3
3
|
import { type DefineComponent, computed, ref } from 'vue'
|
|
4
|
-
import { type Validatable } from '../composables/
|
|
4
|
+
import { type Validatable } from '../composables/V'
|
|
5
5
|
import SInputBase from './SInputBase.vue'
|
|
6
6
|
|
|
7
7
|
export type Size = 'mini' | 'small' | 'medium'
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { type IconifyIcon } from '@iconify/vue/dist/offline'
|
|
3
3
|
import { type DefineComponent, computed, ref } from 'vue'
|
|
4
|
-
import { type Validatable } from '../composables/
|
|
4
|
+
import { type Validatable } from '../composables/V'
|
|
5
5
|
import SInputBase from './SInputBase.vue'
|
|
6
6
|
|
|
7
7
|
export type Size = 'mini' | 'small' | 'medium'
|
|
@@ -3,7 +3,7 @@ import { type IconifyIcon } from '@iconify/vue/dist/offline'
|
|
|
3
3
|
import IconImage from '@iconify-icons/ph/image-bold'
|
|
4
4
|
import { computed, ref } from 'vue'
|
|
5
5
|
import { useImageSrcFromFile } from '../composables/Image'
|
|
6
|
-
import { type Validatable } from '../composables/
|
|
6
|
+
import { type Validatable } from '../composables/V'
|
|
7
7
|
import SButton from './SButton.vue'
|
|
8
8
|
import SIcon from './SIcon.vue'
|
|
9
9
|
import SInputBase from './SInputBase.vue'
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { type IconifyIcon } from '@iconify/vue/dist/offline'
|
|
3
3
|
import { type DefineComponent, computed } from 'vue'
|
|
4
|
-
import { type Validatable } from '../composables/
|
|
4
|
+
import { type Validatable } from '../composables/V'
|
|
5
5
|
import { isNullish, isString } from '../support/Utils'
|
|
6
6
|
import SInputText from './SInputText.vue'
|
|
7
7
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { type IconifyIcon } from '@iconify/vue/dist/offline'
|
|
3
3
|
import { type DefineComponent, computed } from 'vue'
|
|
4
|
-
import { type Validatable } from '../composables/
|
|
4
|
+
import { type Validatable } from '../composables/V'
|
|
5
5
|
import SInputBase from './SInputBase.vue'
|
|
6
6
|
|
|
7
7
|
export type Size = 'mini' | 'small' | 'medium'
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { type IconifyIcon } from '@iconify/vue/dist/offline'
|
|
3
3
|
import { type DefineComponent, computed } from 'vue'
|
|
4
|
-
import { type Validatable } from '../composables/
|
|
4
|
+
import { type Validatable } from '../composables/V'
|
|
5
5
|
import SInputBase from './SInputBase.vue'
|
|
6
6
|
import SInputRadio from './SInputRadio.vue'
|
|
7
7
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts" generic="T extends string | number | boolean">
|
|
2
2
|
import { type IconifyIcon } from '@iconify/vue/dist/offline'
|
|
3
3
|
import { computed } from 'vue'
|
|
4
|
-
import { type Validatable } from '../composables/
|
|
4
|
+
import { type Validatable } from '../composables/V'
|
|
5
5
|
import SInputBase from './SInputBase.vue'
|
|
6
6
|
import SInputSegmentsOption, { type Mode } from './SInputSegmentsOption.vue'
|
|
7
7
|
|
|
@@ -3,7 +3,7 @@ import { type IconifyIcon } from '@iconify/vue/dist/offline'
|
|
|
3
3
|
import IconCaretDown from '@iconify-icons/ph/caret-down-bold'
|
|
4
4
|
import IconCaretUp from '@iconify-icons/ph/caret-up-bold'
|
|
5
5
|
import { type DefineComponent, computed, ref } from 'vue'
|
|
6
|
-
import { type Validatable } from '../composables/
|
|
6
|
+
import { type Validatable } from '../composables/V'
|
|
7
7
|
import SIcon from './SIcon.vue'
|
|
8
8
|
import SInputBase from './SInputBase.vue'
|
|
9
9
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { type IconifyIcon } from '@iconify/vue/dist/offline'
|
|
3
3
|
import { type DefineComponent, computed } from 'vue'
|
|
4
|
-
import { type Validatable } from '../composables/
|
|
4
|
+
import { type Validatable } from '../composables/V'
|
|
5
5
|
import SInputBase from './SInputBase.vue'
|
|
6
6
|
|
|
7
7
|
export type Size = 'mini' | 'small' | 'medium'
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { type IconifyIcon } from '@iconify/vue/dist/offline'
|
|
3
3
|
import { type DefineComponent, computed } from 'vue'
|
|
4
|
-
import { type Validatable } from '../composables/
|
|
4
|
+
import { type Validatable } from '../composables/V'
|
|
5
5
|
import SInputBase from './SInputBase.vue'
|
|
6
6
|
import SInputSwitch from './SInputSwitch.vue'
|
|
7
7
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { type IconifyIcon } from '@iconify/vue/dist/offline'
|
|
3
3
|
import { type DefineComponent, computed, ref } from 'vue'
|
|
4
|
-
import { type Validatable } from '../composables/
|
|
4
|
+
import { type Validatable } from '../composables/V'
|
|
5
5
|
import { isString } from '../support/Utils'
|
|
6
6
|
import SIcon from './SIcon.vue'
|
|
7
7
|
import SInputBase from './SInputBase.vue'
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { type IconifyIcon } from '@iconify/vue/dist/offline'
|
|
3
3
|
import { computed } from 'vue'
|
|
4
|
-
import { type Validatable } from '../composables/
|
|
4
|
+
import { type Validatable } from '../composables/V'
|
|
5
5
|
import SInputBase from './SInputBase.vue'
|
|
6
6
|
|
|
7
7
|
export type Size = 'mini' | 'small' | 'medium'
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { type IconifyIcon } from '@iconify/vue/dist/offline'
|
|
3
3
|
import { type DefineComponent, computed, ref } from 'vue'
|
|
4
|
-
import { type Validatable } from '../composables/
|
|
4
|
+
import { type Validatable } from '../composables/V'
|
|
5
5
|
import SInputBase from './SInputBase.vue'
|
|
6
6
|
|
|
7
7
|
export type Size = 'mini' | 'small' | 'medium'
|
package/lib/composables/Card.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Ref, inject, provide, ref } from 'vue'
|
|
2
2
|
|
|
3
3
|
export interface CardState {
|
|
4
4
|
isCollapsed: Ref<boolean>
|
|
@@ -6,7 +6,7 @@ export interface CardState {
|
|
|
6
6
|
toggleCollapse(): void
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
export const
|
|
9
|
+
export const CardStateKey = 'card-state'
|
|
10
10
|
|
|
11
11
|
export function provideCardState(): CardState {
|
|
12
12
|
const isCollapsed = ref(false)
|
|
@@ -25,13 +25,13 @@ export function provideCardState(): CardState {
|
|
|
25
25
|
toggleCollapse
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
provide(
|
|
28
|
+
provide(CardStateKey, cardState)
|
|
29
29
|
|
|
30
30
|
return cardState
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
export function useCardState(): CardState {
|
|
34
|
-
const cardState = inject(
|
|
34
|
+
const cardState = inject<CardState | null>(CardStateKey, null)
|
|
35
35
|
|
|
36
36
|
if (!cardState) {
|
|
37
37
|
throw new Error(
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type Ref, ref } from 'vue'
|
|
2
|
+
|
|
3
|
+
export interface D<T extends Record<string, any>> {
|
|
4
|
+
data: Ref<T>
|
|
5
|
+
init(): void
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function useD<T extends Record<string, any>>(data: T): D<T> {
|
|
9
|
+
const initialData = JSON.parse(JSON.stringify(data))
|
|
10
|
+
|
|
11
|
+
const refData = ref(data) as Ref<T>
|
|
12
|
+
|
|
13
|
+
function init(): void {
|
|
14
|
+
refData.value = initialData
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
data: refData,
|
|
19
|
+
init
|
|
20
|
+
}
|
|
21
|
+
}
|
package/lib/composables/Data.ts
CHANGED
package/lib/composables/Form.ts
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { inject, provide } from 'vue'
|
|
2
|
+
|
|
3
|
+
export type Lang = 'en' | 'ja'
|
|
4
|
+
|
|
5
|
+
export interface Trans<T> {
|
|
6
|
+
t: T
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface TransMessages<T> {
|
|
10
|
+
en: T
|
|
11
|
+
ja: T
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const SefirotLangKey = 'sefirot-lang-key'
|
|
15
|
+
|
|
16
|
+
export function provideLang(lang: Lang) {
|
|
17
|
+
provide(SefirotLangKey, lang)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function useLang(): Lang {
|
|
21
|
+
// Doing `||` check here because for some reason it doesn't return
|
|
22
|
+
// the default value in tests but becomes `undefined`.
|
|
23
|
+
return inject(SefirotLangKey, 'en') || 'en'
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function useTrans<T>(messages: TransMessages<T>): Trans<T> {
|
|
27
|
+
const lang = useLang()
|
|
28
|
+
|
|
29
|
+
const t = messages[lang]
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
t
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { type Validation, type ValidationArgs, useVuelidate } from '@vuelidate/core'
|
|
2
|
+
import { type MaybeRefOrGetter, type Ref, computed, toValue } from 'vue'
|
|
3
|
+
import { type Snackbar, useSnackbars } from '../stores/Snackbars'
|
|
4
|
+
import { useTrans } from './Lang'
|
|
5
|
+
|
|
6
|
+
export interface V<
|
|
7
|
+
Data extends { [key in keyof Rules]: any },
|
|
8
|
+
Rules extends ValidationArgs = ValidationArgs
|
|
9
|
+
> {
|
|
10
|
+
validation: Ref<Validation<Rules, Data>>
|
|
11
|
+
validate(): Promise<boolean>
|
|
12
|
+
validateAndNotify(message?: Snackbar): Promise<boolean>
|
|
13
|
+
reset(): void
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface Validatable {
|
|
17
|
+
readonly $dirty: boolean
|
|
18
|
+
readonly $invalid: boolean
|
|
19
|
+
readonly $errors: ValidatableError[]
|
|
20
|
+
readonly $touch: () => void
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface ValidatableError {
|
|
24
|
+
readonly $message: string | Ref<string>
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function useV<
|
|
28
|
+
Data extends { [key in keyof Rules]: any },
|
|
29
|
+
Rules extends ValidationArgs = ValidationArgs
|
|
30
|
+
>(
|
|
31
|
+
data: MaybeRefOrGetter<Data>,
|
|
32
|
+
rules: MaybeRefOrGetter<Rules>
|
|
33
|
+
): V<Data, Rules> {
|
|
34
|
+
const { t } = useTrans({
|
|
35
|
+
en: { notify: 'Form contains errors. Please correct them and try again.' },
|
|
36
|
+
ja: { notify: 'フォームにエラーがあります。内容を確認し、再度お試しください。' }
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
const snackbars = useSnackbars()
|
|
40
|
+
|
|
41
|
+
const d = computed(() => toValue(data))
|
|
42
|
+
const r = computed(() => toValue(rules))
|
|
43
|
+
|
|
44
|
+
const validation = useVuelidate(r, d)
|
|
45
|
+
|
|
46
|
+
function reset(): void {
|
|
47
|
+
validation.value.$reset()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function validate(): Promise<boolean> {
|
|
51
|
+
return validation.value.$validate()
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function validateAndNotify(message?: Snackbar): Promise<boolean> {
|
|
55
|
+
const valid = await validate()
|
|
56
|
+
|
|
57
|
+
if (!valid) {
|
|
58
|
+
snackbars.push(message ?? {
|
|
59
|
+
mode: 'danger',
|
|
60
|
+
text: t.notify
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return valid
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
validation,
|
|
69
|
+
validate,
|
|
70
|
+
validateAndNotify,
|
|
71
|
+
reset
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { type ValidationRuleWithParams } from '@vuelidate/core'
|
|
2
|
+
import { type MessageProps as VMessageProps, helpers } from '@vuelidate/validators'
|
|
3
|
+
import { type Lang, useLang } from '../composables/Lang'
|
|
4
|
+
|
|
5
|
+
export interface RuleOptions {
|
|
6
|
+
optional?: boolean
|
|
7
|
+
message(params: MessageProps): string
|
|
8
|
+
validation(value: unknown): boolean
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export interface MessageProps extends VMessageProps {
|
|
12
|
+
lang: Lang
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function createRule(
|
|
16
|
+
options: RuleOptions
|
|
17
|
+
): ValidationRuleWithParams {
|
|
18
|
+
const lang = useLang()
|
|
19
|
+
|
|
20
|
+
return helpers.withMessage(
|
|
21
|
+
(params) => {
|
|
22
|
+
return options.message({ ...params, lang })
|
|
23
|
+
},
|
|
24
|
+
(value) => {
|
|
25
|
+
return options.optional && !helpers.req(value)
|
|
26
|
+
? true
|
|
27
|
+
: options.validation(value)
|
|
28
|
+
}
|
|
29
|
+
)
|
|
30
|
+
}
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
export { and, not, or } from '@vuelidate/validators'
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
6
|
-
export
|
|
7
|
-
export
|
|
8
|
-
export
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
14
|
-
export
|
|
15
|
-
export
|
|
16
|
-
export
|
|
17
|
-
export
|
|
18
|
-
export
|
|
19
|
-
export
|
|
20
|
-
export
|
|
21
|
-
export
|
|
22
|
-
export
|
|
23
|
-
export
|
|
24
|
-
export
|
|
25
|
-
export
|
|
2
|
+
export { checked } from './checked'
|
|
3
|
+
export { decimal } from './decimal'
|
|
4
|
+
export { decimalOrHyphen } from './decimalOrHyphen'
|
|
5
|
+
export { email } from './email'
|
|
6
|
+
export { fileExtension } from './fileExtension'
|
|
7
|
+
export { hms } from './hms'
|
|
8
|
+
export { maxFileSize } from './maxFileSize'
|
|
9
|
+
export { maxLength } from './maxLength'
|
|
10
|
+
export { maxTotalFileSize } from './maxTotalFileSize'
|
|
11
|
+
export { maxValue } from './maxValue'
|
|
12
|
+
export { minLength } from './minLength'
|
|
13
|
+
export { minValue } from './minValue'
|
|
14
|
+
export { month } from './month'
|
|
15
|
+
export { negativeInteger } from './negativeInteger'
|
|
16
|
+
export { positiveInteger } from './positiveInteger'
|
|
17
|
+
export { required } from './required'
|
|
18
|
+
export { requiredHms } from './requiredHms'
|
|
19
|
+
export { requiredIf } from './requiredIf'
|
|
20
|
+
export { requiredYmd } from './requiredYmd'
|
|
21
|
+
export { rule } from './rule'
|
|
22
|
+
export { url } from './url'
|
|
23
|
+
export { ymd } from './ymd'
|
|
24
|
+
export { zeroOrNegativeInteger } from './zeroOrNegativeInteger'
|
|
25
|
+
export { zeroOrPositiveInteger } from './zeroOrPositiveInteger'
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createRule } from '../Rule'
|
|
2
|
+
import { required as baseRequired } from '../validators'
|
|
3
|
+
|
|
4
|
+
export const message = {
|
|
5
|
+
en: 'The field is required.',
|
|
6
|
+
ja: 'この項目は必須です。'
|
|
7
|
+
}
|
|
2
8
|
|
|
3
9
|
export function required(msg?: string) {
|
|
4
|
-
return
|
|
5
|
-
() => msg ??
|
|
6
|
-
baseRequired
|
|
7
|
-
)
|
|
10
|
+
return createRule({
|
|
11
|
+
message: ({ lang }) => msg ?? message[lang],
|
|
12
|
+
validation: (value) => baseRequired(value)
|
|
13
|
+
})
|
|
8
14
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { isArray, isNullish, isString } from '../../support/Utils'
|
|
2
|
+
|
|
3
|
+
export function required(value: unknown): boolean {
|
|
4
|
+
if (isArray(value)) {
|
|
5
|
+
return !!value.length
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
if (isNullish(value)) {
|
|
9
|
+
return false
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
if (value === false) {
|
|
13
|
+
return true
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
if (value instanceof Date) {
|
|
17
|
+
return !Number.isNaN(value.getTime())
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (isString(value)) {
|
|
21
|
+
value = value.trim()
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return !!String(value).length
|
|
25
|
+
}
|