@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.
- package/lib/components/SDropdownSectionFilter.vue +3 -3
- package/lib/components/SInputAddon.vue +3 -3
- package/lib/components/SInputCheckboxes.vue +1 -1
- package/lib/components/SInputDropdown.vue +3 -3
- package/lib/components/SInputDropdownItem.vue +2 -2
- package/lib/components/SInputDropdownItemAvatar.vue +2 -2
- package/lib/components/SInputDropdownItemText.vue +2 -2
- package/lib/components/SInputRadios.vue +8 -8
- package/lib/components/SInputSelect.vue +2 -2
- package/lib/components/SInputSwitches.vue +5 -5
- package/lib/components/STableCellNumber.vue +1 -1
- package/lib/composables/Dropdown.ts +4 -9
- package/lib/http/Http.ts +14 -16
- package/lib/support/Day.ts +43 -0
- package/lib/validation/Rule.ts +1 -1
- package/lib/validation/rules/checked.ts +11 -5
- package/lib/validation/rules/decimal.ts +11 -6
- package/lib/validation/rules/decimalOrHyphen.ts +11 -5
- package/lib/validation/rules/email.ts +11 -5
- package/lib/validation/rules/fileExtension.ts +11 -7
- package/lib/validation/rules/hms.ts +11 -8
- package/lib/validation/rules/maxFileSize.ts +11 -12
- package/lib/validation/rules/maxLength.ts +12 -7
- package/lib/validation/rules/maxTotalFileSize.ts +11 -12
- package/lib/validation/rules/maxValue.ts +12 -8
- package/lib/validation/rules/minLength.ts +12 -7
- package/lib/validation/rules/minValue.ts +12 -8
- package/lib/validation/rules/month.ts +12 -8
- package/lib/validation/rules/negativeInteger.ts +10 -5
- package/lib/validation/rules/positiveInteger.ts +10 -5
- package/lib/validation/rules/required.ts +1 -1
- package/lib/validation/rules/requiredHms.ts +10 -8
- package/lib/validation/rules/requiredIf.ts +12 -6
- package/lib/validation/rules/requiredYmd.ts +11 -8
- package/lib/validation/rules/rule.ts +12 -6
- package/lib/validation/rules/url.ts +11 -5
- package/lib/validation/rules/ymd.ts +11 -8
- package/lib/validation/rules/zeroOrNegativeInteger.ts +11 -6
- package/lib/validation/rules/zeroOrPositiveInteger.ts +11 -6
- package/lib/validation/validators/checked.ts +1 -1
- package/lib/validation/validators/decimal.ts +11 -0
- package/lib/validation/validators/email.ts +12 -0
- package/lib/validation/validators/fileExtension.ts +7 -2
- package/lib/validation/validators/hms.ts +8 -12
- package/lib/validation/validators/hyphen.ts +1 -1
- package/lib/validation/validators/index.ts +8 -0
- package/lib/validation/validators/maxFileSize.ts +9 -2
- package/lib/validation/validators/maxLength.ts +9 -0
- package/lib/validation/validators/maxTotalFileSize.ts +12 -2
- package/lib/validation/validators/maxValue.ts +7 -0
- package/lib/validation/validators/minLength.ts +9 -0
- package/lib/validation/validators/minValue.ts +7 -0
- package/lib/validation/validators/month.ts +7 -1
- package/lib/validation/validators/negativeInteger.ts +7 -1
- package/lib/validation/validators/positiveInteger.ts +7 -1
- package/lib/validation/validators/requiredHms.ts +6 -10
- package/lib/validation/validators/requiredIf.ts +19 -0
- package/lib/validation/validators/requiredYmd.ts +6 -10
- package/lib/validation/validators/url.ts +11 -0
- package/lib/validation/validators/ymd.ts +11 -15
- package/lib/validation/validators/zero.ts +1 -1
- package/package.json +1 -1
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createRule } from '../Rule'
|
|
2
|
+
import { minValue as baseMinValue } from '../validators'
|
|
2
3
|
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
export const message = {
|
|
5
|
+
en: (min: number) => `The value must be greater than or equal to ${min}.`,
|
|
6
|
+
ja: (min: number) => `この値は最大${min}です。`
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function minValue(min: number, msg?: string) {
|
|
10
|
+
return createRule({
|
|
11
|
+
message: ({ lang }) => msg ?? message[lang](min),
|
|
12
|
+
validation: (value) => baseMinValue(value, min)
|
|
13
|
+
})
|
|
10
14
|
}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { month as baseMonth } from '../validators
|
|
1
|
+
import { createRule } from '../Rule'
|
|
2
|
+
import { month as baseMonth } from '../validators'
|
|
3
|
+
|
|
4
|
+
export const message = {
|
|
5
|
+
en: 'The month is invalid.',
|
|
6
|
+
ja: '月が正しくありません。'
|
|
7
|
+
}
|
|
3
8
|
|
|
4
9
|
export function month(msg?: string) {
|
|
5
|
-
return
|
|
6
|
-
() => msg ??
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
)
|
|
10
|
+
return createRule({
|
|
11
|
+
message: ({ lang }) => msg ?? message[lang],
|
|
12
|
+
optional: true,
|
|
13
|
+
validation: baseMonth
|
|
14
|
+
})
|
|
11
15
|
}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createRule } from '../Rule'
|
|
2
2
|
import { negativeInteger as baseNegativeInteger } from '../validators'
|
|
3
3
|
|
|
4
|
+
export const message = {
|
|
5
|
+
en: 'The value must be valid negative integer.',
|
|
6
|
+
ja: 'この値は負の整数である必要があります。'
|
|
7
|
+
}
|
|
8
|
+
|
|
4
9
|
export function negativeInteger(msg?: string) {
|
|
5
|
-
return
|
|
6
|
-
() => msg ??
|
|
7
|
-
baseNegativeInteger
|
|
8
|
-
)
|
|
10
|
+
return createRule({
|
|
11
|
+
message: ({ lang }) => msg ?? message[lang],
|
|
12
|
+
validation: baseNegativeInteger
|
|
13
|
+
})
|
|
9
14
|
}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createRule } from '../Rule'
|
|
2
2
|
import { positiveInteger as basePositiveInteger } from '../validators'
|
|
3
3
|
|
|
4
|
+
export const message = {
|
|
5
|
+
en: 'The value must be valid positive integer.',
|
|
6
|
+
ja: 'この値は正の整数である必要があります。'
|
|
7
|
+
}
|
|
8
|
+
|
|
4
9
|
export function positiveInteger(msg?: string) {
|
|
5
|
-
return
|
|
6
|
-
() => msg ??
|
|
7
|
-
basePositiveInteger
|
|
8
|
-
)
|
|
10
|
+
return createRule({
|
|
11
|
+
message: ({ lang }) => msg ?? message[lang],
|
|
12
|
+
validation: basePositiveInteger
|
|
13
|
+
})
|
|
9
14
|
}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { type Hms } from '../../support/Day'
|
|
1
|
+
import { createRule } from '../Rule'
|
|
3
2
|
import { requiredHms as baseRequiredHms } from '../validators/requiredHms'
|
|
4
3
|
|
|
5
4
|
type HmsType = 'h' | 'm' | 's'
|
|
6
5
|
|
|
6
|
+
export const message = {
|
|
7
|
+
en: 'The field is required.',
|
|
8
|
+
ja: 'この項目は必須です。'
|
|
9
|
+
}
|
|
10
|
+
|
|
7
11
|
export function requiredHms(required?: HmsType[], msg?: string) {
|
|
8
|
-
return
|
|
9
|
-
() => msg ??
|
|
10
|
-
(value
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
)
|
|
12
|
+
return createRule({
|
|
13
|
+
message: ({ lang }) => msg ?? message[lang],
|
|
14
|
+
validation: (value) => baseRequiredHms(value, required)
|
|
15
|
+
})
|
|
14
16
|
}
|
|
@@ -1,11 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createRule } from '../Rule'
|
|
2
|
+
import { type RequiredIfCondition, requiredIf as baseRequiredIf } from '../validators'
|
|
3
|
+
|
|
4
|
+
export const message = {
|
|
5
|
+
en: 'The field is required.',
|
|
6
|
+
ja: 'この項目は必須です。'
|
|
7
|
+
}
|
|
2
8
|
|
|
3
9
|
export function requiredIf(
|
|
4
|
-
|
|
10
|
+
condition: RequiredIfCondition,
|
|
5
11
|
msg?: string
|
|
6
12
|
) {
|
|
7
|
-
return
|
|
8
|
-
() => msg ??
|
|
9
|
-
baseRequiredIf(
|
|
10
|
-
)
|
|
13
|
+
return createRule({
|
|
14
|
+
message: ({ lang }) => msg ?? message[lang],
|
|
15
|
+
validation: (value) => baseRequiredIf(value, condition)
|
|
16
|
+
})
|
|
11
17
|
}
|
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { type Ymd } from '../../support/Day'
|
|
1
|
+
import { createRule } from '../Rule'
|
|
3
2
|
import { requiredYmd as baseRequiredYmd } from '../validators/requiredYmd'
|
|
4
3
|
|
|
5
4
|
type YmdType = 'y' | 'm' | 'd'
|
|
6
5
|
|
|
6
|
+
export const message = {
|
|
7
|
+
en: 'The field is required.',
|
|
8
|
+
ja: 'この項目は必須です。'
|
|
9
|
+
}
|
|
10
|
+
|
|
7
11
|
export function requiredYmd(required?: YmdType[], msg?: string) {
|
|
8
|
-
return
|
|
9
|
-
() => msg ??
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
)
|
|
12
|
+
return createRule({
|
|
13
|
+
message: ({ lang }) => msg ?? message[lang],
|
|
14
|
+
optional: true,
|
|
15
|
+
validation: (value) => baseRequiredYmd(value, required)
|
|
16
|
+
})
|
|
14
17
|
}
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createRule } from '../Rule'
|
|
2
2
|
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
export const message = {
|
|
4
|
+
en: 'The value is invalid.',
|
|
5
|
+
ja: 'この値は正しくありません。'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function rule(validation: (value: unknown) => boolean, msg?: string) {
|
|
9
|
+
return createRule({
|
|
10
|
+
message: ({ lang }) => msg ?? message[lang],
|
|
11
|
+
optional: true,
|
|
12
|
+
validation: (value) => validation(value)
|
|
13
|
+
})
|
|
8
14
|
}
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createRule } from '../Rule'
|
|
2
|
+
import { url as baseUrl } from '../validators'
|
|
3
|
+
|
|
4
|
+
export const message = {
|
|
5
|
+
en: 'The URL is invalid.',
|
|
6
|
+
ja: 'URLの形式が正しくありません。'
|
|
7
|
+
}
|
|
2
8
|
|
|
3
9
|
export function url(msg?: string) {
|
|
4
|
-
return
|
|
5
|
-
() => msg ??
|
|
6
|
-
baseUrl
|
|
7
|
-
)
|
|
10
|
+
return createRule({
|
|
11
|
+
message: ({ lang }) => msg ?? message[lang],
|
|
12
|
+
validation: baseUrl
|
|
13
|
+
})
|
|
8
14
|
}
|
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { type Ymd } from '../../support/Day'
|
|
1
|
+
import { createRule } from '../Rule'
|
|
3
2
|
import { ymd as baseYmd } from '../validators/ymd'
|
|
4
3
|
|
|
5
4
|
type YmdType = 'y' | 'm' | 'd'
|
|
6
5
|
|
|
6
|
+
export const message = {
|
|
7
|
+
en: 'The field is required.',
|
|
8
|
+
ja: 'この項目は必須です。'
|
|
9
|
+
}
|
|
10
|
+
|
|
7
11
|
export function ymd(required?: YmdType[], msg?: string) {
|
|
8
|
-
return
|
|
9
|
-
() => msg ??
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
)
|
|
12
|
+
return createRule({
|
|
13
|
+
message: ({ lang }) => msg ?? message[lang],
|
|
14
|
+
optional: true,
|
|
15
|
+
validation: (value) => baseYmd(value, required)
|
|
16
|
+
})
|
|
14
17
|
}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { negativeInteger, zero } from '../validators'
|
|
1
|
+
import { createRule } from '../Rule'
|
|
2
|
+
import { negativeInteger as baseNegativeInteger, zero } from '../validators'
|
|
3
|
+
|
|
4
|
+
export const message = {
|
|
5
|
+
en: 'The value must be zero or valid negative integer.',
|
|
6
|
+
ja: 'この値はゼロまたは負の整数である必要があります。'
|
|
7
|
+
}
|
|
3
8
|
|
|
4
9
|
export function zeroOrNegativeInteger(msg?: string) {
|
|
5
|
-
return
|
|
6
|
-
() => msg ??
|
|
7
|
-
|
|
8
|
-
)
|
|
10
|
+
return createRule({
|
|
11
|
+
message: ({ lang }) => msg ?? message[lang],
|
|
12
|
+
validation: (value) => zero(value) || baseNegativeInteger(value)
|
|
13
|
+
})
|
|
9
14
|
}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { positiveInteger, zero } from '../validators'
|
|
1
|
+
import { createRule } from '../Rule'
|
|
2
|
+
import { positiveInteger as basePositiveInteger, zero } from '../validators'
|
|
3
|
+
|
|
4
|
+
export const message = {
|
|
5
|
+
en: 'The value must be zero or valid positive integer.',
|
|
6
|
+
ja: 'この値はゼロまたは正の整数である必要があります。'
|
|
7
|
+
}
|
|
3
8
|
|
|
4
9
|
export function zeroOrPositiveInteger(msg?: string) {
|
|
5
|
-
return
|
|
6
|
-
() => msg ??
|
|
7
|
-
|
|
8
|
-
)
|
|
10
|
+
return createRule({
|
|
11
|
+
message: ({ lang }) => msg ?? message[lang],
|
|
12
|
+
validation: (value) => zero(value) || basePositiveInteger(value)
|
|
13
|
+
})
|
|
9
14
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { isNumber, isString } from '../../support/Utils'
|
|
2
|
+
|
|
3
|
+
const regExp = /^[-]?\d*(\.\d+)?$/
|
|
4
|
+
|
|
5
|
+
export function decimal(value: unknown): boolean {
|
|
6
|
+
if (!(isString(value) || isNumber(value))) {
|
|
7
|
+
return false
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return regExp.test(String(value))
|
|
11
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { isString } from '../../support/Utils'
|
|
2
|
+
|
|
3
|
+
/* eslint-disable-next-line no-control-regex */
|
|
4
|
+
const regExp = /^(?:[A-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[A-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21\x23-\x5B\x5D-\x7F]|[\x01-\x09\x0B\x0C\x0E-\x7F])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9]{2,}(?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0B\x0C\x0E-\x1F\x21-\x5A\x53-\x7F]|\\[\x01-\x09\x0B\x0C\x0E-\x7F])+)\])$/i
|
|
5
|
+
|
|
6
|
+
export function email(value: string): boolean {
|
|
7
|
+
if (!isString(value)) {
|
|
8
|
+
return false
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return regExp.test(value)
|
|
12
|
+
}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import { getExtension } from '../../support/File'
|
|
2
|
+
import { isFile } from '../../support/Utils'
|
|
2
3
|
|
|
3
|
-
export function fileExtension(
|
|
4
|
-
|
|
4
|
+
export function fileExtension(value: unknown, extensions: string[]): boolean {
|
|
5
|
+
if (!isFile(value)) {
|
|
6
|
+
return false
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const fileExtension = getExtension(value)
|
|
5
10
|
|
|
6
11
|
return extensions.some((extension) => {
|
|
7
12
|
// If the extention option is `jpg`, we'll consider other variants such as
|
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { HmsMap, type HmsType, isHms } from '../../support/Day'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export function hms(value: unknown, required: HmsType[] = ['h', 'm', 's']): boolean {
|
|
4
|
+
if (!isHms(value, required)) {
|
|
5
|
+
return false
|
|
6
|
+
}
|
|
4
7
|
|
|
5
|
-
const HmsMap = {
|
|
6
|
-
h: 'hour',
|
|
7
|
-
m: 'minute',
|
|
8
|
-
s: 'second'
|
|
9
|
-
} as const
|
|
10
|
-
|
|
11
|
-
export function hms(hms: Hms, required: HmsType[] = ['h', 'm', 's']): boolean {
|
|
12
8
|
return required.every((r) => {
|
|
13
|
-
const
|
|
9
|
+
const _value = value[HmsMap[r]]
|
|
14
10
|
|
|
15
|
-
if (
|
|
11
|
+
if (_value === null) {
|
|
16
12
|
return true
|
|
17
13
|
}
|
|
18
14
|
|
|
19
|
-
const valueAsNumber = Number(
|
|
15
|
+
const valueAsNumber = Number(_value)
|
|
20
16
|
|
|
21
17
|
return (r === 'h')
|
|
22
18
|
? (valueAsNumber >= 0 && valueAsNumber < 24)
|
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
export * from './checked'
|
|
2
|
+
export * from './decimal'
|
|
3
|
+
export * from './email'
|
|
2
4
|
export * from './fileExtension'
|
|
3
5
|
export * from './hms'
|
|
4
6
|
export * from './hyphen'
|
|
5
7
|
export * from './maxFileSize'
|
|
8
|
+
export * from './maxLength'
|
|
6
9
|
export * from './maxTotalFileSize'
|
|
10
|
+
export * from './maxValue'
|
|
11
|
+
export * from './minLength'
|
|
12
|
+
export * from './minValue'
|
|
7
13
|
export * from './month'
|
|
8
14
|
export * from './negativeInteger'
|
|
9
15
|
export * from './positiveInteger'
|
|
10
16
|
export * from './required'
|
|
11
17
|
export * from './requiredHms'
|
|
18
|
+
export * from './requiredIf'
|
|
12
19
|
export * from './requiredYmd'
|
|
20
|
+
export * from './url'
|
|
13
21
|
export * from './ymd'
|
|
14
22
|
export * from './zero'
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
import { isFile } from '../../support/Utils'
|
|
2
|
+
|
|
3
|
+
export function maxFileSize(value: unknown, size: string): boolean {
|
|
4
|
+
if (!isFile(value)) {
|
|
5
|
+
return false
|
|
6
|
+
}
|
|
7
|
+
|
|
2
8
|
const factor = /gb/i.test(size)
|
|
3
9
|
? 1e9
|
|
4
10
|
: /mb/i.test(size)
|
|
@@ -6,5 +12,6 @@ export function maxFileSize(file: File, size: string): boolean {
|
|
|
6
12
|
: /kb/i.test(size)
|
|
7
13
|
? 1e3
|
|
8
14
|
: 1
|
|
9
|
-
|
|
15
|
+
|
|
16
|
+
return value.size <= factor * +size.replace(/[^\d\.]/g, '')
|
|
10
17
|
}
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
+
import { isFile } from '../../support/Utils'
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Validates if the total size of the given files is smaller than the
|
|
3
5
|
* given size.
|
|
4
6
|
*/
|
|
5
|
-
export function maxTotalFileSize(
|
|
7
|
+
export function maxTotalFileSize(value: unknown, size: string): boolean {
|
|
8
|
+
if (!isArrayOfFiles(value)) {
|
|
9
|
+
return false
|
|
10
|
+
}
|
|
11
|
+
|
|
6
12
|
const factor = /gb/i.test(size)
|
|
7
13
|
? 1e9
|
|
8
14
|
: /mb/i.test(size)
|
|
@@ -11,7 +17,11 @@ export function maxTotalFileSize(files: File[], size: string): boolean {
|
|
|
11
17
|
? 1e3
|
|
12
18
|
: 1
|
|
13
19
|
|
|
14
|
-
const total =
|
|
20
|
+
const total = value.reduce((total, file) => total + file.size, 0)
|
|
15
21
|
|
|
16
22
|
return total <= factor * +size.replace(/[^\d\.]/g, '')
|
|
17
23
|
}
|
|
24
|
+
|
|
25
|
+
function isArrayOfFiles(value: unknown): value is File[] {
|
|
26
|
+
return Array.isArray(value) && value.every((v) => isFile(v))
|
|
27
|
+
}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { isNumber } from '../../support/Utils'
|
|
2
|
+
|
|
3
|
+
export function negativeInteger(value: unknown): boolean {
|
|
4
|
+
if (!isNumber(value)) {
|
|
5
|
+
return false
|
|
6
|
+
}
|
|
7
|
+
|
|
2
8
|
return Number.isInteger(value) && value < 0
|
|
3
9
|
}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { isNumber } from '../../support/Utils'
|
|
2
|
+
|
|
3
|
+
export function positiveInteger(value: unknown): boolean {
|
|
4
|
+
if (!isNumber(value)) {
|
|
5
|
+
return false
|
|
6
|
+
}
|
|
7
|
+
|
|
2
8
|
return Number.isInteger(value) && value > 0
|
|
3
9
|
}
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { HmsMap, type HmsType, isHms } from '../../support/Day'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export function requiredHms(value: unknown, required: HmsType[] = ['h', 'm', 's']): boolean {
|
|
4
|
+
if (!isHms(value, required)) {
|
|
5
|
+
return false
|
|
6
|
+
}
|
|
4
7
|
|
|
5
|
-
|
|
6
|
-
h: 'hour',
|
|
7
|
-
m: 'minute',
|
|
8
|
-
s: 'second'
|
|
9
|
-
} as const
|
|
10
|
-
|
|
11
|
-
export function requiredHms(hms: Hms, required: HmsType[] = ['h', 'm', 's']): boolean {
|
|
12
|
-
return required.every((r) => hms[HmsMap[r]] != null)
|
|
8
|
+
return required.every((r) => value[HmsMap[r]] != null)
|
|
13
9
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { required } from './required'
|
|
2
|
+
|
|
3
|
+
export type RequiredIfCondition = boolean | string | (() => boolean) | (() => Promise<boolean>)
|
|
4
|
+
|
|
5
|
+
export async function requiredIf(value: unknown, condition: RequiredIfCondition): Promise<boolean> {
|
|
6
|
+
if (typeof condition === 'boolean' && condition) {
|
|
7
|
+
return required(value)
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (typeof condition === 'string' && condition) {
|
|
11
|
+
return required(value)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (typeof condition === 'function' && (await condition())) {
|
|
15
|
+
return required(value)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return true
|
|
19
|
+
}
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { YmdMap, type YmdType, isYmd } from '../../support/Day'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
export function requiredYmd(value: unknown, required: YmdType[] = ['y', 'm', 'd']): boolean {
|
|
4
|
+
if (!isYmd(value, required)) {
|
|
5
|
+
return false
|
|
6
|
+
}
|
|
4
7
|
|
|
5
|
-
|
|
6
|
-
y: 'year',
|
|
7
|
-
m: 'month',
|
|
8
|
-
d: 'date'
|
|
9
|
-
} as const
|
|
10
|
-
|
|
11
|
-
export function requiredYmd(ymd: Ymd, required: YmdType[] = ['y', 'm', 'd']): boolean {
|
|
12
|
-
return required.every((r) => ymd[YmdMap[r]] != null)
|
|
8
|
+
return required.every((r) => value[YmdMap[r]] != null)
|
|
13
9
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { isString } from '../../support/Utils'
|
|
2
|
+
|
|
3
|
+
const regExp = /^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z0-9\u00A1-\uFFFF][a-z0-9\u00A1-\uFFFF_-]{0,62})?[a-z0-9\u00A1-\uFFFF]\.)+(?:[a-z\u00A1-\uFFFF]{2,}\.?))(?::\d{2,5})?(?:[/?#]\S*)?$/i
|
|
4
|
+
|
|
5
|
+
export function url(value: unknown): boolean {
|
|
6
|
+
if (!isString(value)) {
|
|
7
|
+
return false
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
return regExp.test(value)
|
|
11
|
+
}
|
|
@@ -1,33 +1,29 @@
|
|
|
1
1
|
import day from 'dayjs'
|
|
2
|
-
import { type
|
|
2
|
+
import { YmdMap, type YmdType, isYmd } from '../../support/Day'
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
export function ymd(value: unknown, required: YmdType[] = ['y', 'm', 'd']): boolean {
|
|
5
|
+
if (!isYmd(value, required)) {
|
|
6
|
+
return false
|
|
7
|
+
}
|
|
5
8
|
|
|
6
|
-
const YmdMap = {
|
|
7
|
-
y: 'year',
|
|
8
|
-
m: 'month',
|
|
9
|
-
d: 'date'
|
|
10
|
-
} as const
|
|
11
|
-
|
|
12
|
-
export function ymd(ymd: Ymd, required: YmdType[] = ['y', 'm', 'd']): boolean {
|
|
13
9
|
return required.every((r) => {
|
|
14
|
-
const
|
|
10
|
+
const _value = value[YmdMap[r]]
|
|
15
11
|
|
|
16
|
-
if (
|
|
12
|
+
if (_value === null) {
|
|
17
13
|
return true
|
|
18
14
|
}
|
|
19
15
|
|
|
20
16
|
if (r === 'y') {
|
|
21
|
-
return
|
|
17
|
+
return _value > 0 && _value <= 9999
|
|
22
18
|
}
|
|
23
19
|
|
|
24
20
|
if (r === 'm') {
|
|
25
|
-
return
|
|
21
|
+
return _value > 0 && _value <= 12
|
|
26
22
|
}
|
|
27
23
|
|
|
28
|
-
const d = day(new Date(2020,
|
|
24
|
+
const d = day(new Date(2020, value.month ? value.month - 1 : 1, _value))
|
|
29
25
|
|
|
30
|
-
if (d.month() + 1 !== (
|
|
26
|
+
if (d.month() + 1 !== (value.month ?? 1)) {
|
|
31
27
|
return false
|
|
32
28
|
}
|
|
33
29
|
|