@globalbrain/sefirot 0.72.0 → 2.0.0-draft.4

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 (175) hide show
  1. package/CHANGELOG.md +8 -808
  2. package/README.md +1 -1
  3. package/lib/assets/styles/bootstrap.css +1 -2
  4. package/lib/assets/styles/variables.css +14 -47
  5. package/lib/components/SAvatar.vue +9 -18
  6. package/lib/components/SButton.vue +35 -48
  7. package/lib/components/SDialog.vue +16 -34
  8. package/lib/components/SDropdown.vue +36 -55
  9. package/lib/components/SDropdownItem.vue +27 -39
  10. package/lib/components/SDropdownItemText.vue +4 -9
  11. package/lib/components/SDropdownItemUser.vue +4 -12
  12. package/lib/components/SInputBase.vue +33 -45
  13. package/lib/components/SInputCheckbox.vue +17 -37
  14. package/lib/components/SInputDropdown.vue +109 -171
  15. package/lib/components/SInputDropdownItem.vue +26 -32
  16. package/lib/components/SInputDropdownItemText.vue +6 -11
  17. package/lib/components/SInputDropdownItemTextTag.vue +10 -17
  18. package/lib/components/SInputDropdownItemUser.vue +5 -13
  19. package/lib/components/SInputDropdownItemUserTag.vue +9 -16
  20. package/lib/components/SInputFile.vue +38 -53
  21. package/lib/components/SInputHMS.vue +91 -114
  22. package/lib/components/SInputNumber.vue +27 -106
  23. package/lib/components/SInputRadio.vue +21 -34
  24. package/lib/components/SInputRadios.vue +36 -46
  25. package/lib/components/SInputText.vue +72 -628
  26. package/lib/components/SInputTextarea.vue +54 -113
  27. package/lib/components/SInputYMD.vue +94 -105
  28. package/lib/components/SLink.vue +16 -52
  29. package/lib/components/SModal.vue +39 -98
  30. package/lib/components/SPortalModals.vue +37 -54
  31. package/lib/components/SPortalSnackbars.vue +9 -24
  32. package/lib/components/SSheet.vue +73 -28
  33. package/lib/components/SSheetFooter.vue +5 -3
  34. package/lib/components/SSheetFooterAction.vue +10 -15
  35. package/lib/components/SSheetFooterActions.vue +2 -4
  36. package/lib/components/SSheetMedium.vue +14 -22
  37. package/lib/components/SSheetTitle.vue +20 -0
  38. package/lib/components/SSnackbar.vue +18 -28
  39. package/lib/composables/Dialog.ts +9 -17
  40. package/lib/composables/Dropdown.ts +2 -2
  41. package/lib/composables/{Menu.ts → Flyout.ts} +11 -4
  42. package/lib/composables/Form.ts +42 -44
  43. package/lib/composables/Modal.ts +11 -19
  44. package/lib/composables/Snackbar.ts +18 -0
  45. package/lib/composables/Validation.ts +28 -0
  46. package/lib/mixins/Sheet.ts +5 -7
  47. package/lib/store/Sefirot.ts +8 -13
  48. package/lib/store/dialog/index.ts +20 -10
  49. package/lib/store/modal/index.ts +11 -18
  50. package/lib/store/snackbars/index.ts +3 -4
  51. package/lib/support/{Util.ts → Utils.ts} +0 -2
  52. package/lib/types/Utils.ts +0 -7
  53. package/lib/types/vue-shims.d.ts +7 -0
  54. package/lib/validation/rules/checked.ts +6 -10
  55. package/lib/validation/rules/fileExtension.ts +9 -9
  56. package/lib/validation/rules/hms.ts +9 -9
  57. package/lib/validation/rules/index.ts +10 -74
  58. package/lib/validation/rules/maxLength.ts +10 -9
  59. package/lib/validation/rules/minLength.ts +12 -0
  60. package/lib/validation/rules/required.ts +2 -10
  61. package/lib/validation/rules/requiredHms.ts +11 -0
  62. package/lib/validation/rules/requiredIf.ts +3 -11
  63. package/lib/validation/rules/requiredYmd.ts +11 -0
  64. package/lib/validation/rules/ymd.ts +11 -0
  65. package/lib/validation/validators/checked.ts +1 -1
  66. package/lib/validation/validators/fileExtension.ts +1 -1
  67. package/lib/validation/validators/hms.ts +5 -5
  68. package/lib/validation/validators/requiredHms.ts +17 -0
  69. package/lib/validation/validators/requiredYmd.ts +7 -0
  70. package/lib/validation/validators/ymd.ts +41 -0
  71. package/package.json +45 -50
  72. package/lib/components/SAction.vue +0 -37
  73. package/lib/components/SActionAvatar.vue +0 -25
  74. package/lib/components/SActionButton.vue +0 -40
  75. package/lib/components/SActionPill.vue +0 -35
  76. package/lib/components/SActionSwitch.vue +0 -37
  77. package/lib/components/SAlert.vue +0 -145
  78. package/lib/components/SButtonGroup.vue +0 -160
  79. package/lib/components/SCard.vue +0 -111
  80. package/lib/components/SCardFooter.vue +0 -74
  81. package/lib/components/SCardHeader.vue +0 -213
  82. package/lib/components/SGrid.vue +0 -237
  83. package/lib/components/SGridActionLink.vue +0 -53
  84. package/lib/components/SGridActionMulti.vue +0 -139
  85. package/lib/components/SGridActionSingle.vue +0 -64
  86. package/lib/components/SHeader.vue +0 -180
  87. package/lib/components/SInputCheckboxes.vue +0 -87
  88. package/lib/components/SInputDate.vue +0 -192
  89. package/lib/components/SInputDay.vue +0 -87
  90. package/lib/components/SInputMonth.vue +0 -86
  91. package/lib/components/SInputSelect.vue +0 -298
  92. package/lib/components/SInputSwitch.vue +0 -212
  93. package/lib/components/SInputSwitches.vue +0 -108
  94. package/lib/components/SInputTime.vue +0 -255
  95. package/lib/components/SInputYear.vue +0 -60
  96. package/lib/components/SMarkdown.vue +0 -56
  97. package/lib/components/SPlaceholderBlank.vue +0 -113
  98. package/lib/components/SPlaceholderImage.vue +0 -83
  99. package/lib/components/SPortalScreens.vue +0 -62
  100. package/lib/components/SProgressBar.vue +0 -89
  101. package/lib/components/SResponsive.vue +0 -46
  102. package/lib/components/SScreen.vue +0 -81
  103. package/lib/components/SSheetHeader.vue +0 -75
  104. package/lib/components/SSheetHeaderTitle.vue +0 -17
  105. package/lib/components/SStep.vue +0 -107
  106. package/lib/components/SSteps.vue +0 -75
  107. package/lib/components/STag.vue +0 -67
  108. package/lib/components/STooltip.vue +0 -134
  109. package/lib/components/SWindow.vue +0 -158
  110. package/lib/components/icons/SIconCopy.vue +0 -6
  111. package/lib/composables/Action.ts +0 -141
  112. package/lib/composables/Alert.ts +0 -50
  113. package/lib/composables/Card.ts +0 -46
  114. package/lib/composables/FormValidation.ts +0 -150
  115. package/lib/composables/Header.ts +0 -72
  116. package/lib/composables/InputDropdown.ts +0 -6
  117. package/lib/composables/Markdown.ts +0 -138
  118. package/lib/composables/Router.ts +0 -20
  119. package/lib/composables/Step.ts +0 -7
  120. package/lib/composables/Store.ts +0 -9
  121. package/lib/composables/Tag.ts +0 -32
  122. package/lib/composables/Tooltip.ts +0 -91
  123. package/lib/composables/Utils.ts +0 -115
  124. package/lib/composables/markdown/LinkPlugin.ts +0 -45
  125. package/lib/compositions/useForm.ts +0 -17
  126. package/lib/compositions/useResizeObserver.ts +0 -25
  127. package/lib/compositions/useTime.ts +0 -26
  128. package/lib/store/alert/index.ts +0 -32
  129. package/lib/store/screen/index.ts +0 -46
  130. package/lib/types/v-calendar.d.ts +0 -5
  131. package/lib/validation/Validation.ts +0 -151
  132. package/lib/validation/rules/day.ts +0 -11
  133. package/lib/validation/rules/email.ts +0 -11
  134. package/lib/validation/rules/every.ts +0 -38
  135. package/lib/validation/rules/include.ts +0 -11
  136. package/lib/validation/rules/includeSome.ts +0 -11
  137. package/lib/validation/rules/integer.ts +0 -11
  138. package/lib/validation/rules/maxValue.ts +0 -11
  139. package/lib/validation/rules/minValue.ts +0 -11
  140. package/lib/validation/rules/month.ts +0 -11
  141. package/lib/validation/rules/not.ts +0 -10
  142. package/lib/validation/rules/regex.ts +0 -11
  143. package/lib/validation/rules/requiredHMS.ts +0 -11
  144. package/lib/validation/rules/requiredMonthDate.ts +0 -11
  145. package/lib/validation/rules/requiredYearMonth.ts +0 -11
  146. package/lib/validation/rules/requiredYearMonthDate.ts +0 -11
  147. package/lib/validation/rules/rule.ts +0 -5
  148. package/lib/validation/rules/sameAs.ts +0 -11
  149. package/lib/validation/rules/url.ts +0 -11
  150. package/lib/validation/rules/validateIf.ts +0 -27
  151. package/lib/validation/rules/year.ts +0 -11
  152. package/lib/validation/rules/yearMonth.ts +0 -11
  153. package/lib/validation/rules/yearMonthDate.ts +0 -11
  154. package/lib/validation/validators/day.ts +0 -29
  155. package/lib/validation/validators/email.ts +0 -5
  156. package/lib/validation/validators/include.ts +0 -5
  157. package/lib/validation/validators/includeSome.ts +0 -5
  158. package/lib/validation/validators/index.ts +0 -51
  159. package/lib/validation/validators/integer.ts +0 -6
  160. package/lib/validation/validators/maxLength.ts +0 -3
  161. package/lib/validation/validators/maxValue.ts +0 -3
  162. package/lib/validation/validators/minValue.ts +0 -3
  163. package/lib/validation/validators/month.ts +0 -3
  164. package/lib/validation/validators/monthDate.ts +0 -20
  165. package/lib/validation/validators/regex.ts +0 -3
  166. package/lib/validation/validators/required.ts +0 -27
  167. package/lib/validation/validators/requiredHMS.ts +0 -17
  168. package/lib/validation/validators/requiredMonthDate.ts +0 -8
  169. package/lib/validation/validators/requiredYearMonth.ts +0 -8
  170. package/lib/validation/validators/requiredYearMonthDate.ts +0 -9
  171. package/lib/validation/validators/sameAs.ts +0 -5
  172. package/lib/validation/validators/url.ts +0 -5
  173. package/lib/validation/validators/year.ts +0 -3
  174. package/lib/validation/validators/yearMonth.ts +0 -20
  175. package/lib/validation/validators/yearMonthDate.ts +0 -21
@@ -1,151 +0,0 @@
1
- import { ref, computed, toRefs, Ref } from '@vue/composition-api'
2
- import { Rule } from './rules'
3
-
4
- export interface Validation {
5
- _isValidation: boolean
6
- $data: Ref<any>
7
- $initData: any
8
- $isDirty: Ref<boolean>
9
- $isValid: Ref<boolean>
10
- $errors: Ref<readonly Error[]>
11
- $touch: () => void
12
- $reset: () => void
13
- $init: () => void
14
- $validate: () => boolean
15
- [name: string]: MaybeValidation
16
- }
17
-
18
- export type Data = Record<string, any>
19
- export type Rules = Record<string, Rule[] | Record<string, any>>
20
- export type InitData = any
21
- export type Error = [string, string]
22
- export type MaybeValidation = any | boolean | Ref<boolean> | Ref<readonly Error[]> | Function | Validation
23
-
24
- export function createValidation(data: Data, rules: Rules, rootData?: Data): Validation {
25
- const validation = createInitialValidation()
26
- setNestedValidations(validation, data, rootData ?? data, rules)
27
- setValidation(validation)
28
- return validation
29
- }
30
-
31
- function createInitialValidation(): Validation {
32
- return {
33
- _isValidation: true,
34
- $data: ref(null),
35
- $initData: null,
36
- $isDirty: ref(false),
37
- $isValid: ref(false),
38
- $errors: ref([]),
39
- $touch: () => {},
40
- $reset: () => {},
41
- $init: () => {},
42
- $validate: () => false
43
- }
44
- }
45
-
46
- function createNestedValidation(name: string, data: Data, rootData: Data, validators: Rule[]): Validation {
47
- const initData = data[name]
48
- const dataRef = toRefs(data)[name]
49
-
50
- const isDirty = ref(false)
51
-
52
- const errors = computed(() => {
53
- return validators.reduce<Error[]>((errors, validator) => {
54
- const d = data[name]
55
-
56
- if (validator.optional && (d === undefined || d === null || d === '')) {
57
- return errors
58
- }
59
-
60
- if (!validator.validate(d, rootData)) {
61
- errors.push([validator.name, validator.message])
62
- }
63
-
64
- return errors
65
- }, [])
66
- })
67
-
68
- const isValid = computed(() => errors.value.length === 0)
69
-
70
- const touch = () => { isDirty.value = true }
71
- const reset = () => { isDirty.value = false }
72
-
73
- const init = () => {
74
- reset()
75
- dataRef.value = initData
76
- }
77
-
78
- const validate = () => {
79
- touch()
80
- return isValid.value
81
- }
82
-
83
- return {
84
- _isValidation: true,
85
- $data: dataRef,
86
- $initData: initData,
87
- $isDirty: isDirty,
88
- $errors: errors,
89
- $isValid: isValid,
90
- $touch: touch,
91
- $reset: reset,
92
- $init: init,
93
- $validate: validate
94
- }
95
- }
96
-
97
- function setValidation(validation: Validation): void {
98
- const isDirty = computed(() => {
99
- return Object.keys(validation).every((field) => {
100
- const v = validation[field]
101
- return isValidation(v) ? v.$isDirty.value : true
102
- }, [])
103
- })
104
-
105
- const errors = computed(() => {
106
- return Object.keys(validation).reduce<Error[]>((errors, field) => {
107
- const v = validation[field]
108
- return isValidation(v) ? errors.concat(v.$errors.value) : errors
109
- }, [])
110
- })
111
-
112
- const isValid = computed(() => errors.value.length === 0)
113
-
114
- const touch = () => { callAll(validation, 'touch') }
115
- const reset = () => { callAll(validation, 'reset') }
116
- const init = () => { callAll(validation, 'init') }
117
-
118
- const validate = () => {
119
- touch()
120
- return isValid.value
121
- }
122
-
123
- validation.$isDirty = isDirty
124
- validation.$errors = errors
125
- validation.$isValid = isValid
126
- validation.$touch = touch
127
- validation.$reset = reset
128
- validation.$init = init
129
- validation.$validate = validate
130
- }
131
-
132
- function setNestedValidations(validation: Validation, data: Data, rootData: Data, rules: Rules): void {
133
- for (const name in rules) {
134
- const validators = rules[name]
135
-
136
- validation[name] = Array.isArray(validators)
137
- ? createNestedValidation(name, data, rootData, validators)
138
- : createValidation(data[name], validators, rootData)
139
- }
140
- }
141
-
142
- function callAll(validation: Validation, method: 'touch' | 'reset' | 'init'): void {
143
- for (const field in validation) {
144
- const v = validation[field]
145
- isValidation(v) && v[`$${method}`]()
146
- }
147
- }
148
-
149
- function isValidation(value: MaybeValidation): value is Validation {
150
- return value !== null && typeof value === 'object' && !Array.isArray(value) && value._isValidation
151
- }
@@ -1,11 +0,0 @@
1
- import { day as baseDay } from '../validators'
2
- import { Rule } from './'
3
-
4
- export default function day(year?: string, month?: string, message?: string): Rule {
5
- return {
6
- name: 'day',
7
- message: message ?? 'The Date is invalid.',
8
- optional: true,
9
- validate: (value, data) => baseDay(value, data[year!], data[month!])
10
- }
11
- }
@@ -1,11 +0,0 @@
1
- import { email as baseEmail } from '../validators'
2
- import { Rule } from './'
3
-
4
- export default function email(message?: string): Rule {
5
- return {
6
- name: 'email',
7
- message: message ?? 'The Email address is invalid.',
8
- optional: true,
9
- validate: baseEmail
10
- }
11
- }
@@ -1,38 +0,0 @@
1
- import { Rule } from './'
2
-
3
- interface Options {
4
- [name: string]: Rule[]
5
- }
6
-
7
- export default function every(options: Options): Rule {
8
- return {
9
- name: 'each',
10
- message: 'Error found in items.',
11
- optional: true,
12
- validate(value: Record<string, any>[], data): boolean {
13
- return value.every(item => check(options, item, data))
14
- }
15
- }
16
- }
17
-
18
- function check(
19
- options: Options,
20
- item: Record<string, any>,
21
- data: any
22
- ): boolean {
23
- for (const key in item) {
24
- const rules = options[key]
25
-
26
- if (!rules) {
27
- continue
28
- }
29
-
30
- const result = rules.every(rule => rule.validate(item[key], data))
31
-
32
- if (!result) {
33
- return false
34
- }
35
- }
36
-
37
- return true
38
- }
@@ -1,11 +0,0 @@
1
- import { include as baseInclude } from '../validators'
2
- import { Rule } from './'
3
-
4
- export default function required(other: string, message?: string): Rule {
5
- return {
6
- name: 'include',
7
- message: message ?? `The value must include ${other}.`,
8
- optional: true,
9
- validate: (value, data) => baseInclude(value, data[other])
10
- }
11
- }
@@ -1,11 +0,0 @@
1
- import { includeSome as baseIncludeSome } from '../validators'
2
- import { Rule } from './'
3
-
4
- export default function required(other: string, message?: string): Rule {
5
- return {
6
- name: 'includeSome',
7
- message: message ?? `The value must include some of ${other}.`,
8
- optional: true,
9
- validate: (value, data) => baseIncludeSome(value, data[other])
10
- }
11
- }
@@ -1,11 +0,0 @@
1
- import { integer as baseInteger } from '../validators'
2
- import { Rule } from './'
3
-
4
- export default function integer(message?: string): Rule {
5
- return {
6
- name: 'maxValue',
7
- message: message ?? 'The value must not contain decimals.',
8
- optional: true,
9
- validate: baseInteger
10
- }
11
- }
@@ -1,11 +0,0 @@
1
- import { maxValue as baseMaxValue } from '../validators'
2
- import { Rule } from './'
3
-
4
- export default function maxValue(max: number, message?: string): Rule {
5
- return {
6
- name: 'maxValue',
7
- message: message ?? `The value must be ${max} or less.`,
8
- optional: true,
9
- validate: value => baseMaxValue(value, max)
10
- }
11
- }
@@ -1,11 +0,0 @@
1
- import { minValue as baseMinValue } from '../validators'
2
- import { Rule } from './'
3
-
4
- export default function minValue(min: number, message?: string): Rule {
5
- return {
6
- name: 'minValue',
7
- message: message ?? `The value must be ${min} or more.`,
8
- optional: true,
9
- validate: value => baseMinValue(value, min)
10
- }
11
- }
@@ -1,11 +0,0 @@
1
- import { month as baseMonth } from '../validators'
2
- import { Rule } from './'
3
-
4
- export default function month(message?: string): Rule {
5
- return {
6
- name: 'month',
7
- message: message ?? 'The month is invalid.',
8
- optional: true,
9
- validate: baseMonth
10
- }
11
- }
@@ -1,10 +0,0 @@
1
- import { Rule } from './'
2
-
3
- export default function not(rule: Rule, message?: string): Rule {
4
- return {
5
- name: `not-${rule.name}`,
6
- message: message ?? '',
7
- optional: true,
8
- validate: (value, data) => !rule.validate(value, data)
9
- }
10
- }
@@ -1,11 +0,0 @@
1
- import { regex as baseRegex } from '../validators'
2
- import { Rule } from './'
3
-
4
- export default function required(regExp: RegExp, message?: string): Rule {
5
- return {
6
- name: 'regex',
7
- message: message ?? 'The value is invalid.',
8
- optional: true,
9
- validate: value => baseRegex(value, regExp)
10
- }
11
- }
@@ -1,11 +0,0 @@
1
- import baseRequiredHMS, { HMSType } from '../validators/requiredHMS'
2
- import { Rule } from './'
3
-
4
- export default function requiredHMS(required?: HMSType[], message?: string): Rule {
5
- return {
6
- name: 'requiredHMS',
7
- message: message ?? 'The field is required.',
8
- optional: true,
9
- validate: v => baseRequiredHMS(v, required)
10
- }
11
- }
@@ -1,11 +0,0 @@
1
- import { requiredMonthDate as baseRequiredMonthDate } from '../validators'
2
- import { Rule } from './'
3
-
4
- export default function requiredMonthDate(message?: string): Rule {
5
- return {
6
- name: 'requiredMonthDate',
7
- message: message ?? 'The field is required.',
8
- optional: true,
9
- validate: baseRequiredMonthDate
10
- }
11
- }
@@ -1,11 +0,0 @@
1
- import { requiredYearMonth as baseRequiredYearMonth } from '../validators'
2
- import { Rule } from './'
3
-
4
- export default function requiredYearMonth(message?: string): Rule {
5
- return {
6
- name: 'requiredYearMonth',
7
- message: message ?? 'The field is required.',
8
- optional: true,
9
- validate: baseRequiredYearMonth
10
- }
11
- }
@@ -1,11 +0,0 @@
1
- import { requiredYearMonthDate as baseRequiredYearMonthDate } from '../validators'
2
- import { Rule } from './'
3
-
4
- export default function requiredYearMonthDate(message?: string): Rule {
5
- return {
6
- name: 'requiredYearMonthDate',
7
- message: message ?? 'The field is required.',
8
- optional: true,
9
- validate: baseRequiredYearMonthDate
10
- }
11
- }
@@ -1,5 +0,0 @@
1
- import { Rule } from './'
2
-
3
- export default function rule(options: Rule): Rule {
4
- return options
5
- }
@@ -1,11 +0,0 @@
1
- import { sameAs as baseSameAs } from '../validators'
2
- import { Rule } from './'
3
-
4
- export default function required(other: string, message?: string): Rule {
5
- return {
6
- name: 'sameAs',
7
- message: message ?? `The value must match ${other}.`,
8
- optional: true,
9
- validate: (value, data) => baseSameAs(value, data[other])
10
- }
11
- }
@@ -1,11 +0,0 @@
1
- import { url as baseUrl } from '../validators'
2
- import { Rule } from './'
3
-
4
- export default function url(message?: string): Rule {
5
- return {
6
- name: 'url',
7
- message: message ?? 'The URL is invalid.',
8
- optional: true,
9
- validate: baseUrl
10
- }
11
- }
@@ -1,27 +0,0 @@
1
- import { required } from '../validators'
2
- import { Rule, Locator, locate } from './'
3
-
4
- export default function validateIf(locator: Locator, rules: Rule[]): Rule {
5
- return {
6
- name: 'validateIf',
7
- message: 'Default message.',
8
- optional: false,
9
- validate(value, data) {
10
- if (!locate(data, locator)) {
11
- return true
12
- }
13
-
14
- return rules.every((rule) => {
15
- if (rule.optional && !required(value)) {
16
- return true
17
- }
18
-
19
- const result = rule.validate(value, data)
20
-
21
- this.message = rule.message
22
-
23
- return result
24
- })
25
- }
26
- }
27
- }
@@ -1,11 +0,0 @@
1
- import { year as baseYear } from '../validators'
2
- import { Rule } from './'
3
-
4
- export default function year(message?: string): Rule {
5
- return {
6
- name: 'year',
7
- message: message ?? 'The year is invalid.',
8
- optional: true,
9
- validate: baseYear
10
- }
11
- }
@@ -1,11 +0,0 @@
1
- import { yearMonth as baseYearMonth } from '../validators'
2
- import { Rule } from './'
3
-
4
- export default function yearMonth(message?: string): Rule {
5
- return {
6
- name: 'yearMonth',
7
- message: message ?? 'The date is invalid.',
8
- optional: true,
9
- validate: baseYearMonth
10
- }
11
- }
@@ -1,11 +0,0 @@
1
- import { yearMonthDate as baseYearMonthDate } from '../validators'
2
- import { Rule } from './'
3
-
4
- export default function year(message?: string): Rule {
5
- return {
6
- name: 'yearMonthDate',
7
- message: message ?? 'The date is invalid.',
8
- optional: true,
9
- validate: baseYearMonthDate
10
- }
11
- }
@@ -1,29 +0,0 @@
1
- import dayjs from 'dayjs'
2
-
3
- export default function day(value: number, year?: number, month?: number): boolean {
4
- if (year && !month) {
5
- return validateDateOnly(value)
6
- }
7
-
8
- if (!year && month) {
9
- return validateWithMonth(month, value)
10
- }
11
-
12
- if (year && month) {
13
- return validateWithYearMonth(year, month, value)
14
- }
15
-
16
- return validateDateOnly(value)
17
- }
18
-
19
- function validateDateOnly(date: number): boolean {
20
- return date > 0 && date < 32
21
- }
22
-
23
- function validateWithMonth(month: number, date: number): boolean {
24
- return dayjs().year(2020).month(month - 1).date(date).date() === date
25
- }
26
-
27
- function validateWithYearMonth(year: number, month: number, date: number): boolean {
28
- return dayjs().year(year).month(month - 1).date(date).date() === date
29
- }
@@ -1,5 +0,0 @@
1
- const regex = /(^$|^(([^<>()[\]\\.,;:\s@"]+(\.[^<>()[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$)/
2
-
3
- export default function email(value: any): boolean {
4
- return regex.test(value)
5
- }
@@ -1,5 +0,0 @@
1
- import { isEqual } from '../../support/Util'
2
-
3
- export default function include(value: any[], other: any): boolean {
4
- return value.some(v => isEqual(v, other))
5
- }
@@ -1,5 +0,0 @@
1
- import { isEqual } from '../../support/Util'
2
-
3
- export default function includeSome(value: any[], other: any[]): boolean {
4
- return value.some(v => other.some(o => isEqual(v, o)))
5
- }
@@ -1,51 +0,0 @@
1
- import checked from './checked'
2
- import day from './day'
3
- import email from './email'
4
- import fileExtension from './fileExtension'
5
- import hms from './hms'
6
- import include from './include'
7
- import includeSome from './includeSome'
8
- import integer from './integer'
9
- import maxLength from './maxLength'
10
- import maxValue from './maxValue'
11
- import minValue from './minValue'
12
- import month from './month'
13
- import monthDate from './monthDate'
14
- import regex from './regex'
15
- import required from './required'
16
- import requiredHMS from './requiredHMS'
17
- import requiredMonthDate from './requiredMonthDate'
18
- import requiredYearMonth from './requiredYearMonth'
19
- import requiredYearMonthDate from './requiredYearMonthDate'
20
- import sameAs from './sameAs'
21
- import url from './url'
22
- import year from './year'
23
- import yearMonthDate from './yearMonthDate'
24
- import yearMonth from './yearMonth'
25
-
26
- export {
27
- checked,
28
- day,
29
- email,
30
- fileExtension,
31
- hms,
32
- include,
33
- includeSome,
34
- integer,
35
- maxLength,
36
- maxValue,
37
- minValue,
38
- month,
39
- monthDate,
40
- regex,
41
- required,
42
- requiredHMS,
43
- requiredMonthDate,
44
- requiredYearMonth,
45
- requiredYearMonthDate,
46
- sameAs,
47
- url,
48
- year,
49
- yearMonthDate,
50
- yearMonth
51
- }
@@ -1,6 +0,0 @@
1
- export default function integer(value: number): boolean {
2
- // ^[0-9]*$ - for empty string and positive integer.
3
- // ^-[0-9]+$ - only for negative integer (minus sign without at least
4
- // 1 digit is not a number)
5
- return /(^[0-9]*$)|(^-[0-9]+$)/.test(String(value))
6
- }
@@ -1,3 +0,0 @@
1
- export default function maxLength(value: string | string[], max: number): boolean {
2
- return value.length <= max
3
- }
@@ -1,3 +0,0 @@
1
- export default function maxValue(value: number, max: number): boolean {
2
- return value <= max
3
- }
@@ -1,3 +0,0 @@
1
- export default function minValue(value: number, min: number): boolean {
2
- return min <= value
3
- }
@@ -1,3 +0,0 @@
1
- export default function month(value: number): boolean {
2
- return value > 0 && value < 13
3
- }
@@ -1,20 +0,0 @@
1
- import day from 'dayjs'
2
-
3
- export interface MonthDate {
4
- month?: number
5
- date?: number
6
- }
7
-
8
- export default function monthDate(value: MonthDate): boolean {
9
- if (value.month === undefined || value.date === undefined) {
10
- return true
11
- }
12
-
13
- const d = day(new Date(2020, value.month - 1, value.date))
14
-
15
- if (d.month() + 1 !== value.month) {
16
- return false
17
- }
18
-
19
- return d.isValid()
20
- }
@@ -1,3 +0,0 @@
1
- export default function regex(value: any, regExp: RegExp): boolean {
2
- return regExp.test(value)
3
- }
@@ -1,27 +0,0 @@
1
- export default function required(value: any): boolean {
2
- if (Array.isArray(value)) {
3
- return !!value.length
4
- }
5
-
6
- if (value === undefined || value === null) {
7
- return false
8
- }
9
-
10
- if (value === false) {
11
- return true
12
- }
13
-
14
- if (value instanceof Date) {
15
- return true
16
- }
17
-
18
- if (typeof value === 'object') {
19
- for (const _ in value) {
20
- return true
21
- }
22
-
23
- return false
24
- }
25
-
26
- return !!String(value).length
27
- }
@@ -1,17 +0,0 @@
1
- export interface HMS {
2
- hour?: string
3
- minute?: string
4
- second?: string
5
- }
6
-
7
- export type HMSType = 'h' | 'm' | 's'
8
-
9
- const HMSMap = {
10
- h: 'hour',
11
- m: 'minute',
12
- s: 'second'
13
- } as const
14
-
15
- export default function requiredHMS(hms: HMS, required: HMSType[] = ['h', 'm', 's']): boolean {
16
- return required.every(r => hms[HMSMap[r]] !== undefined)
17
- }