@globalbrain/sefirot 4.30.1 → 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.
- package/client.d.ts +5 -0
- package/config/nuxt.d.ts +1 -0
- package/config/nuxt.js +8 -5
- package/config/vite.js +4 -13
- package/lib/components/SActionList.vue +2 -2
- package/lib/components/SActionMenu.vue +43 -7
- package/lib/components/SAvatar.vue +1 -1
- package/lib/components/SAvatarStack.vue +12 -12
- package/lib/components/SButton.vue +5 -7
- package/lib/components/SCard.vue +2 -2
- package/lib/components/SChartBar.vue +37 -12
- package/lib/components/SChartPie.vue +13 -7
- package/lib/components/SControlActionBarCollapse.vue +2 -4
- package/lib/components/SControlInputSearch.vue +7 -2
- package/lib/components/SDataListItem.vue +1 -3
- package/lib/components/SDescAvatar.vue +1 -1
- package/lib/components/SDescDay.vue +2 -2
- package/lib/components/SDescFile.vue +2 -4
- package/lib/components/SDescItem.vue +2 -1
- package/lib/components/SDescLabel.vue +1 -1
- package/lib/components/SDescLink.vue +2 -7
- package/lib/components/SDescPill.vue +2 -4
- package/lib/components/SDescText.vue +3 -3
- package/lib/components/SDropdown.vue +1 -1
- package/lib/components/SDropdownSectionFilter.vue +11 -11
- package/lib/components/SFragment.vue +1 -1
- package/lib/components/SInputAddon.vue +13 -11
- package/lib/components/SInputBase.vue +11 -11
- package/lib/components/SInputCheckbox.vue +6 -3
- package/lib/components/SInputCheckboxes.vue +7 -3
- package/lib/components/SInputDate.vue +3 -5
- package/lib/components/SInputDropdown.vue +26 -28
- package/lib/components/SInputDropdownItem.vue +21 -11
- package/lib/components/SInputFile.vue +9 -6
- package/lib/components/SInputFileUpload.vue +9 -11
- package/lib/components/SInputFileUploadItem.vue +8 -4
- package/lib/components/SInputHMS.vue +3 -1
- package/lib/components/SInputImage.vue +4 -2
- package/lib/components/SInputNumber.vue +9 -10
- package/lib/components/SInputRadio.vue +3 -2
- package/lib/components/SInputRadios.vue +6 -5
- package/lib/components/SInputSegments.vue +5 -7
- package/lib/components/SInputSegmentsOption.vue +1 -2
- package/lib/components/SInputSelect.vue +6 -4
- package/lib/components/SInputSwitch.vue +4 -1
- package/lib/components/SInputSwitches.vue +5 -3
- package/lib/components/SInputText.vue +16 -16
- package/lib/components/SInputTextarea.vue +7 -3
- package/lib/components/SInputYMD.vue +3 -1
- package/lib/components/SLink.vue +2 -2
- package/lib/components/SLocalNav.vue +1 -1
- package/lib/components/SLocalNavActions.vue +1 -1
- package/lib/components/SLocalNavMenu.vue +2 -2
- package/lib/components/SLoginPagePasswordDialog.vue +2 -2
- package/lib/components/SM.vue +1 -1
- package/lib/components/SMFade.vue +1 -1
- package/lib/components/SMarkdown.vue +3 -2
- package/lib/components/SModal.vue +2 -2
- package/lib/components/SSnackbar.vue +2 -2
- package/lib/components/SSteps.vue +6 -6
- package/lib/components/STable.vue +70 -27
- package/lib/components/STableCell.vue +14 -17
- package/lib/components/STableCellAvatars.vue +1 -1
- package/lib/components/STableCellDay.vue +12 -5
- package/lib/components/STableCellNumber.vue +2 -3
- package/lib/components/STableCellPath.vue +2 -2
- package/lib/components/STableCellText.vue +2 -3
- package/lib/components/STableColumn.vue +38 -16
- package/lib/components/STableFooter.vue +10 -2
- package/lib/components/STableHeader.vue +0 -1
- package/lib/components/STableHeaderMenu.vue +4 -4
- package/lib/components/STableHeaderMenuItem.vue +1 -1
- package/lib/components/STooltip.vue +3 -3
- package/lib/composables/Api.ts +1 -1
- package/lib/composables/App.ts +13 -11
- package/lib/composables/Dropdown.ts +10 -1
- package/lib/composables/Error.ts +37 -37
- package/lib/composables/Grid.ts +1 -4
- package/lib/composables/Image.ts +2 -3
- package/lib/composables/Lang.ts +8 -16
- package/lib/composables/Markdown.ts +1 -1
- package/lib/composables/Table.ts +0 -2
- package/lib/composables/Theme.ts +1 -13
- package/lib/composables/Utils.ts +11 -4
- package/lib/composables/Validation.ts +1 -4
- package/lib/http/Http.ts +23 -17
- package/lib/styles/variables-deprecated.css +0 -1
- package/lib/styles/variables.css +16 -16
- package/lib/support/Chart.ts +0 -1
- package/lib/support/DateRange.ts +1 -1
- package/lib/support/Day.ts +12 -65
- package/lib/support/File.ts +7 -16
- package/lib/support/Utils.ts +7 -40
- package/lib/validation/Rule.ts +6 -21
- package/lib/validation/rules/decimal.ts +3 -3
- package/lib/validation/rules/email.ts +1 -1
- package/lib/validation/rules/index.ts +1 -1
- package/lib/validation/rules/negativeInteger.ts +1 -1
- package/lib/validation/rules/positiveInteger.ts +1 -1
- package/lib/validation/rules/requiredHms.ts +2 -2
- package/lib/validation/rules/requiredIf.ts +1 -4
- package/lib/validation/rules/requiredYmd.ts +2 -2
- package/lib/validation/rules/slackChannelName.ts +4 -1
- package/lib/validation/rules/zeroOrNegativeInteger.ts +1 -1
- package/lib/validation/rules/zeroOrPositiveInteger.ts +1 -1
- package/lib/validation/validators/after.ts +1 -5
- package/lib/validation/validators/afterOrEqual.ts +1 -5
- package/lib/validation/validators/before.ts +1 -4
- package/lib/validation/validators/beforeOrEqual.ts +1 -5
- package/lib/validation/validators/decimal.ts +7 -9
- package/lib/validation/validators/email.ts +4 -8
- package/lib/validation/validators/fileExtension.ts +7 -15
- package/lib/validation/validators/hms.ts +26 -15
- package/lib/validation/validators/index.ts +0 -2
- package/lib/validation/validators/maxFileSize.ts +3 -13
- package/lib/validation/validators/maxLength.ts +1 -7
- package/lib/validation/validators/maxTotalFileSize.ts +3 -26
- package/lib/validation/validators/maxValue.ts +2 -6
- package/lib/validation/validators/minLength.ts +1 -7
- package/lib/validation/validators/minValue.ts +2 -6
- package/lib/validation/validators/month.ts +1 -7
- package/lib/validation/validators/negativeInteger.ts +1 -7
- package/lib/validation/validators/positiveInteger.ts +1 -7
- package/lib/validation/validators/required.ts +5 -28
- package/lib/validation/validators/requiredHmsIf.ts +11 -13
- package/lib/validation/validators/requiredIf.ts +5 -11
- package/lib/validation/validators/requiredYmdIf.ts +11 -13
- package/lib/validation/validators/slackChannelName.ts +11 -11
- package/lib/validation/validators/url.ts +7 -5
- package/lib/validation/validators/ymd.ts +36 -30
- package/package.json +44 -42
- package/lib/composables/Http.ts +0 -18
- package/lib/validation/validators/requiredHms.ts +0 -9
- package/lib/validation/validators/requiredYmd.ts +0 -9
package/lib/support/Utils.ts
CHANGED
|
@@ -1,49 +1,16 @@
|
|
|
1
|
-
|
|
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
|
|
3
|
+
return Number.isFinite(value)
|
|
33
4
|
}
|
|
34
5
|
|
|
35
6
|
export function isObject(value: unknown): value is Record<string, unknown> {
|
|
36
|
-
|
|
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
|
-
|
|
44
|
-
return
|
|
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
|
|
15
|
+
return typeof value === 'string'
|
|
49
16
|
}
|
package/lib/validation/Rule.ts
CHANGED
|
@@ -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 {
|
|
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
|
-
|
|
29
|
-
|
|
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
|
|
2
|
+
import { decimal as baseDecimal } from '../validators'
|
|
3
3
|
|
|
4
4
|
export const message = {
|
|
5
|
-
en: 'The value must be valid decimal
|
|
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) =>
|
|
13
|
+
validation: (value) => baseDecimal(value)
|
|
14
14
|
})
|
|
15
15
|
}
|
|
@@ -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 {
|
|
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) =>
|
|
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 {
|
|
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) =>
|
|
13
|
+
validation: (value) => baseYmd(value, required, true)
|
|
14
14
|
})
|
|
15
15
|
}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { createRule } from '../Rule'
|
|
2
|
-
import {
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
5
|
-
return false
|
|
6
|
-
}
|
|
7
|
-
return value.isBefore(date)
|
|
4
|
+
return isDay(value) && isDay(date) && value.isBefore(date, 'day')
|
|
8
5
|
}
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { type Day, isDay } from '../../support/Day'
|
|
2
2
|
|
|
3
3
|
export function beforeOrEqual(value: unknown, date: Day): boolean {
|
|
4
|
-
|
|
5
|
-
return false
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
return value.isBefore(date) || value.isSame(date)
|
|
4
|
+
return isDay(value) && isDay(date) && (value.isBefore(date, 'day') || value.isSame(date, 'day'))
|
|
9
5
|
}
|
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { isNumber, isString } from '../../support/Utils'
|
|
2
|
-
|
|
3
|
-
const regExp = /^[-]?\d*(\.\d+)?$/
|
|
4
|
-
|
|
5
1
|
export function decimal(value: unknown): boolean {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
const num = Number(value)
|
|
3
|
+
return (
|
|
4
|
+
!Number.isNaN(num)
|
|
5
|
+
&& num >= Number.MIN_SAFE_INTEGER
|
|
6
|
+
&& num <= Number.MAX_SAFE_INTEGER
|
|
7
|
+
&& num.toString() === value?.toString().replace(/(?:(\.\d*[1-9])|\.)0+$/, '$1')
|
|
8
|
+
)
|
|
11
9
|
}
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
export const hostnameRE = /^[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*?\.(?:xn--[a-z0-9-]{2,59}|[a-z]{2,63})\.?$/i
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
const
|
|
3
|
+
// https://colinhacks.com/essays/reasonable-email-regex
|
|
4
|
+
const emailRE = new RegExp(`^(?!\\.)(?!.+\\.\\.)[\\w'+\\-.]*[\\w'+\\-]@${hostnameRE.source.slice(1)}`, 'i')
|
|
5
5
|
|
|
6
6
|
export function email(value: unknown): boolean {
|
|
7
|
-
|
|
8
|
-
return false
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
return regExp.test(value)
|
|
7
|
+
return typeof value === 'string' && emailRE.test(value)
|
|
12
8
|
}
|
|
@@ -1,20 +1,12 @@
|
|
|
1
|
-
import { getExtension } from '../../support/File'
|
|
2
|
-
import { isFile } from '../../support/Utils'
|
|
3
|
-
|
|
4
1
|
export function fileExtension(value: unknown, extensions: string[]): boolean {
|
|
5
|
-
if (!
|
|
6
|
-
return false
|
|
7
|
-
}
|
|
2
|
+
if (!(value instanceof File)) { return false }
|
|
8
3
|
|
|
9
|
-
|
|
4
|
+
extensions = extensions.map((ext) => ext.toLowerCase())
|
|
5
|
+
const fileExtension = value.name.split('.').pop()!.toLowerCase()
|
|
10
6
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
if (extension === 'jpg') {
|
|
15
|
-
return ['jpg', 'jpeg', 'JPG', 'JPEG'].includes(fileExtension)
|
|
16
|
-
}
|
|
7
|
+
if (fileExtension === 'jpg' || fileExtension === 'jpeg') {
|
|
8
|
+
return extensions.includes('jpg') || extensions.includes('jpeg')
|
|
9
|
+
}
|
|
17
10
|
|
|
18
|
-
|
|
19
|
-
})
|
|
11
|
+
return extensions.includes(fileExtension)
|
|
20
12
|
}
|
|
@@ -1,21 +1,32 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type HmsType } from '../../support/Day'
|
|
2
|
+
import { isObject } from '../../support/Utils'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
return false
|
|
6
|
-
}
|
|
4
|
+
const hourRE = /^(?:[01]?\d|2[0-3])$/
|
|
5
|
+
const minuteAndSecondRE = /^[0-5]?\d$/
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
export function hms(
|
|
8
|
+
value: unknown,
|
|
9
|
+
required: HmsType[] = ['h', 'm', 's'],
|
|
10
|
+
rejectNull = false
|
|
11
|
+
): boolean {
|
|
12
|
+
if (!isObject(value)) { return false }
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
+
const { hour, minute, second } = value
|
|
15
|
+
const requiredSet = new Set(required)
|
|
14
16
|
|
|
15
|
-
|
|
17
|
+
return (
|
|
18
|
+
isValidPart(hour, requiredSet.has('h'), hourRE)
|
|
19
|
+
&& isValidPart(minute, requiredSet.has('m'), minuteAndSecondRE)
|
|
20
|
+
&& isValidPart(second, requiredSet.has('s'), minuteAndSecondRE)
|
|
21
|
+
)
|
|
16
22
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
23
|
+
function isValidPart(
|
|
24
|
+
v: unknown,
|
|
25
|
+
req: boolean,
|
|
26
|
+
re: RegExp
|
|
27
|
+
): v is string | null | undefined {
|
|
28
|
+
if (v === undefined) { return !req }
|
|
29
|
+
if (v === null) { return !rejectNull || !req }
|
|
30
|
+
return typeof v === 'string' && re.test(v)
|
|
31
|
+
}
|
|
21
32
|
}
|
|
@@ -18,10 +18,8 @@ export * from './month'
|
|
|
18
18
|
export * from './negativeInteger'
|
|
19
19
|
export * from './positiveInteger'
|
|
20
20
|
export * from './required'
|
|
21
|
-
export * from './requiredHms'
|
|
22
21
|
export * from './requiredHmsIf'
|
|
23
22
|
export * from './requiredIf'
|
|
24
|
-
export * from './requiredYmd'
|
|
25
23
|
export * from './requiredYmdIf'
|
|
26
24
|
export * from './slackChannelName'
|
|
27
25
|
export * from './url'
|
|
@@ -1,17 +1,7 @@
|
|
|
1
|
-
import { isFile } from '../../support/Utils'
|
|
2
|
-
|
|
3
1
|
export function maxFileSize(value: unknown, size: string): boolean {
|
|
4
|
-
if (!
|
|
5
|
-
return false
|
|
6
|
-
}
|
|
2
|
+
if (!(value instanceof File)) { return false }
|
|
7
3
|
|
|
8
|
-
const factor = /gb/i.test(size)
|
|
9
|
-
? 1e9
|
|
10
|
-
: /mb/i.test(size)
|
|
11
|
-
? 1e6
|
|
12
|
-
: /kb/i.test(size)
|
|
13
|
-
? 1e3
|
|
14
|
-
: 1
|
|
4
|
+
const factor = /gb/i.test(size) ? 1e9 : /mb/i.test(size) ? 1e6 : /kb/i.test(size) ? 1e3 : 1
|
|
15
5
|
|
|
16
|
-
return value.size <= factor *
|
|
6
|
+
return value.size <= factor * Number.parseFloat(size.replace(/[^\d.]/g, ''))
|
|
17
7
|
}
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
import { isString } from '../../support/Utils'
|
|
2
|
-
|
|
3
1
|
export function maxLength(value: unknown, length: number): boolean {
|
|
4
|
-
|
|
5
|
-
return false
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
return value.length <= length
|
|
2
|
+
return (typeof value === 'string' || Array.isArray(value)) && value.length <= length
|
|
9
3
|
}
|
|
@@ -1,31 +1,8 @@
|
|
|
1
|
-
import { isFile } from '../../support/Utils'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Validates if the total size of the given files is smaller than the
|
|
5
|
-
* given size.
|
|
6
|
-
*/
|
|
7
1
|
export function maxTotalFileSize(value: unknown, size: string): boolean {
|
|
8
|
-
if (!
|
|
9
|
-
return false
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
if (value.length === 0) {
|
|
13
|
-
return true
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const factor = /gb/i.test(size)
|
|
17
|
-
? 1e9
|
|
18
|
-
: /mb/i.test(size)
|
|
19
|
-
? 1e6
|
|
20
|
-
: /kb/i.test(size)
|
|
21
|
-
? 1e3
|
|
22
|
-
: 1
|
|
2
|
+
if (!Array.isArray(value) || value.some((v) => !(v instanceof File))) { return false }
|
|
23
3
|
|
|
4
|
+
const factor = /gb/i.test(size) ? 1e9 : /mb/i.test(size) ? 1e6 : /kb/i.test(size) ? 1e3 : 1
|
|
24
5
|
const total = value.reduce((total, file) => total + file.size, 0)
|
|
25
6
|
|
|
26
|
-
return total <= factor *
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function isArrayOfFiles(value: unknown): value is File[] {
|
|
30
|
-
return Array.isArray(value) && value.every((v) => isFile(v))
|
|
7
|
+
return total <= factor * Number.parseFloat(size.replace(/[^\d.]/g, ''))
|
|
31
8
|
}
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { decimal } from './decimal'
|
|
2
2
|
|
|
3
3
|
export function maxValue(value: unknown, max: number) {
|
|
4
|
-
|
|
5
|
-
return +value <= max
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
return false
|
|
4
|
+
return (decimal(value) || value instanceof Date) && Number(value) <= max
|
|
9
5
|
}
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
import { isString } from '../../support/Utils'
|
|
2
|
-
|
|
3
1
|
export function minLength(value: unknown, length: number): boolean {
|
|
4
|
-
|
|
5
|
-
return false
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
return value.length >= length
|
|
2
|
+
return (typeof value === 'string' || Array.isArray(value)) && value.length >= length
|
|
9
3
|
}
|
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { decimal } from './decimal'
|
|
2
2
|
|
|
3
3
|
export function minValue(value: unknown, min: number) {
|
|
4
|
-
|
|
5
|
-
return +value >= min
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
return false
|
|
4
|
+
return (decimal(value) || value instanceof Date) && Number(value) >= min
|
|
9
5
|
}
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
import { isNumber } from '../../support/Utils'
|
|
2
|
-
|
|
3
1
|
export function negativeInteger(value: unknown): boolean {
|
|
4
|
-
|
|
5
|
-
return false
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
return Number.isInteger(value) && value < 0
|
|
2
|
+
return Number.isInteger(value) && value < 0 && value >= Number.MIN_SAFE_INTEGER
|
|
9
3
|
}
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
import { isNumber } from '../../support/Utils'
|
|
2
|
-
|
|
3
1
|
export function positiveInteger(value: unknown): boolean {
|
|
4
|
-
|
|
5
|
-
return false
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
return Number.isInteger(value) && value > 0
|
|
2
|
+
return Number.isInteger(value) && value > 0 && value <= Number.MAX_SAFE_INTEGER
|
|
9
3
|
}
|
|
@@ -1,29 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
if (
|
|
5
|
-
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
return _required(value)
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function _required(value: unknown): boolean {
|
|
12
|
-
if (Array.isArray(value)) {
|
|
13
|
-
return !!value.length
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
if (value == null) {
|
|
17
|
-
return false
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
if (value === false) {
|
|
21
|
-
return true
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
if (isDate(value)) {
|
|
25
|
-
return !Number.isNaN(value.getTime())
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
return !!String(value).length
|
|
1
|
+
export function required(value: unknown, trim = true): boolean {
|
|
2
|
+
if (value == null) { return false }
|
|
3
|
+
if (typeof value === 'number' || value instanceof Date) { return !Number.isNaN(+value) }
|
|
4
|
+
if (Array.isArray(value)) { return !!value.length }
|
|
5
|
+
return trim ? !!String(value).trim() : !!String(value)
|
|
29
6
|
}
|
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
import { type HmsType } from '../../support/Day'
|
|
2
|
-
import {
|
|
2
|
+
import { hms } from './hms'
|
|
3
3
|
import { type RequiredIfCondition } from './requiredIf'
|
|
4
4
|
|
|
5
|
-
export async function requiredHmsIf(
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return requiredHms(value, required)
|
|
16
|
-
}
|
|
5
|
+
export async function requiredHmsIf(
|
|
6
|
+
value: unknown,
|
|
7
|
+
condition: RequiredIfCondition,
|
|
8
|
+
required: HmsType[] = ['h', 'm', 's']
|
|
9
|
+
): Promise<boolean> {
|
|
10
|
+
if (
|
|
11
|
+
(typeof condition === 'boolean' && condition)
|
|
12
|
+
|| (typeof condition === 'string' && condition)
|
|
13
|
+
|| (typeof condition === 'function' && (await condition()))
|
|
14
|
+
) { return hms(value, required, true) }
|
|
17
15
|
|
|
18
16
|
return true
|
|
19
17
|
}
|