@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.
Files changed (134) hide show
  1. package/client.d.ts +5 -0
  2. package/config/nuxt.d.ts +1 -0
  3. package/config/nuxt.js +8 -5
  4. package/config/vite.js +4 -13
  5. package/lib/components/SActionList.vue +2 -2
  6. package/lib/components/SActionMenu.vue +43 -7
  7. package/lib/components/SAvatar.vue +1 -1
  8. package/lib/components/SAvatarStack.vue +12 -12
  9. package/lib/components/SButton.vue +5 -7
  10. package/lib/components/SCard.vue +2 -2
  11. package/lib/components/SChartBar.vue +37 -12
  12. package/lib/components/SChartPie.vue +13 -7
  13. package/lib/components/SControlActionBarCollapse.vue +2 -4
  14. package/lib/components/SControlInputSearch.vue +7 -2
  15. package/lib/components/SDataListItem.vue +1 -3
  16. package/lib/components/SDescAvatar.vue +1 -1
  17. package/lib/components/SDescDay.vue +2 -2
  18. package/lib/components/SDescFile.vue +2 -4
  19. package/lib/components/SDescItem.vue +2 -1
  20. package/lib/components/SDescLabel.vue +1 -1
  21. package/lib/components/SDescLink.vue +2 -7
  22. package/lib/components/SDescPill.vue +2 -4
  23. package/lib/components/SDescText.vue +3 -3
  24. package/lib/components/SDropdown.vue +1 -1
  25. package/lib/components/SDropdownSectionFilter.vue +11 -11
  26. package/lib/components/SFragment.vue +1 -1
  27. package/lib/components/SInputAddon.vue +13 -11
  28. package/lib/components/SInputBase.vue +11 -11
  29. package/lib/components/SInputCheckbox.vue +6 -3
  30. package/lib/components/SInputCheckboxes.vue +7 -3
  31. package/lib/components/SInputDate.vue +3 -5
  32. package/lib/components/SInputDropdown.vue +26 -28
  33. package/lib/components/SInputDropdownItem.vue +21 -11
  34. package/lib/components/SInputFile.vue +9 -6
  35. package/lib/components/SInputFileUpload.vue +9 -11
  36. package/lib/components/SInputFileUploadItem.vue +8 -4
  37. package/lib/components/SInputHMS.vue +3 -1
  38. package/lib/components/SInputImage.vue +4 -2
  39. package/lib/components/SInputNumber.vue +9 -10
  40. package/lib/components/SInputRadio.vue +3 -2
  41. package/lib/components/SInputRadios.vue +6 -5
  42. package/lib/components/SInputSegments.vue +5 -7
  43. package/lib/components/SInputSegmentsOption.vue +1 -2
  44. package/lib/components/SInputSelect.vue +6 -4
  45. package/lib/components/SInputSwitch.vue +4 -1
  46. package/lib/components/SInputSwitches.vue +5 -3
  47. package/lib/components/SInputText.vue +16 -16
  48. package/lib/components/SInputTextarea.vue +7 -3
  49. package/lib/components/SInputYMD.vue +3 -1
  50. package/lib/components/SLink.vue +2 -2
  51. package/lib/components/SLocalNav.vue +1 -1
  52. package/lib/components/SLocalNavActions.vue +1 -1
  53. package/lib/components/SLocalNavMenu.vue +2 -2
  54. package/lib/components/SLoginPagePasswordDialog.vue +2 -2
  55. package/lib/components/SM.vue +1 -1
  56. package/lib/components/SMFade.vue +1 -1
  57. package/lib/components/SMarkdown.vue +3 -2
  58. package/lib/components/SModal.vue +2 -2
  59. package/lib/components/SSnackbar.vue +2 -2
  60. package/lib/components/SSteps.vue +6 -6
  61. package/lib/components/STable.vue +70 -27
  62. package/lib/components/STableCell.vue +14 -17
  63. package/lib/components/STableCellAvatars.vue +1 -1
  64. package/lib/components/STableCellDay.vue +12 -5
  65. package/lib/components/STableCellNumber.vue +2 -3
  66. package/lib/components/STableCellPath.vue +2 -2
  67. package/lib/components/STableCellText.vue +2 -3
  68. package/lib/components/STableColumn.vue +38 -16
  69. package/lib/components/STableFooter.vue +10 -2
  70. package/lib/components/STableHeader.vue +0 -1
  71. package/lib/components/STableHeaderMenu.vue +4 -4
  72. package/lib/components/STableHeaderMenuItem.vue +1 -1
  73. package/lib/components/STooltip.vue +3 -3
  74. package/lib/composables/Api.ts +1 -1
  75. package/lib/composables/App.ts +13 -11
  76. package/lib/composables/Dropdown.ts +10 -1
  77. package/lib/composables/Error.ts +37 -37
  78. package/lib/composables/Grid.ts +1 -4
  79. package/lib/composables/Image.ts +2 -3
  80. package/lib/composables/Lang.ts +8 -16
  81. package/lib/composables/Markdown.ts +1 -1
  82. package/lib/composables/Table.ts +0 -2
  83. package/lib/composables/Theme.ts +1 -13
  84. package/lib/composables/Utils.ts +11 -4
  85. package/lib/composables/Validation.ts +1 -4
  86. package/lib/http/Http.ts +23 -17
  87. package/lib/styles/variables-deprecated.css +0 -1
  88. package/lib/styles/variables.css +16 -16
  89. package/lib/support/Chart.ts +0 -1
  90. package/lib/support/DateRange.ts +1 -1
  91. package/lib/support/Day.ts +12 -65
  92. package/lib/support/File.ts +7 -16
  93. package/lib/support/Utils.ts +7 -40
  94. package/lib/validation/Rule.ts +6 -21
  95. package/lib/validation/rules/decimal.ts +3 -3
  96. package/lib/validation/rules/email.ts +1 -1
  97. package/lib/validation/rules/index.ts +1 -1
  98. package/lib/validation/rules/negativeInteger.ts +1 -1
  99. package/lib/validation/rules/positiveInteger.ts +1 -1
  100. package/lib/validation/rules/requiredHms.ts +2 -2
  101. package/lib/validation/rules/requiredIf.ts +1 -4
  102. package/lib/validation/rules/requiredYmd.ts +2 -2
  103. package/lib/validation/rules/slackChannelName.ts +4 -1
  104. package/lib/validation/rules/zeroOrNegativeInteger.ts +1 -1
  105. package/lib/validation/rules/zeroOrPositiveInteger.ts +1 -1
  106. package/lib/validation/validators/after.ts +1 -5
  107. package/lib/validation/validators/afterOrEqual.ts +1 -5
  108. package/lib/validation/validators/before.ts +1 -4
  109. package/lib/validation/validators/beforeOrEqual.ts +1 -5
  110. package/lib/validation/validators/decimal.ts +7 -9
  111. package/lib/validation/validators/email.ts +4 -8
  112. package/lib/validation/validators/fileExtension.ts +7 -15
  113. package/lib/validation/validators/hms.ts +26 -15
  114. package/lib/validation/validators/index.ts +0 -2
  115. package/lib/validation/validators/maxFileSize.ts +3 -13
  116. package/lib/validation/validators/maxLength.ts +1 -7
  117. package/lib/validation/validators/maxTotalFileSize.ts +3 -26
  118. package/lib/validation/validators/maxValue.ts +2 -6
  119. package/lib/validation/validators/minLength.ts +1 -7
  120. package/lib/validation/validators/minValue.ts +2 -6
  121. package/lib/validation/validators/month.ts +1 -7
  122. package/lib/validation/validators/negativeInteger.ts +1 -7
  123. package/lib/validation/validators/positiveInteger.ts +1 -7
  124. package/lib/validation/validators/required.ts +5 -28
  125. package/lib/validation/validators/requiredHmsIf.ts +11 -13
  126. package/lib/validation/validators/requiredIf.ts +5 -11
  127. package/lib/validation/validators/requiredYmdIf.ts +11 -13
  128. package/lib/validation/validators/slackChannelName.ts +11 -11
  129. package/lib/validation/validators/url.ts +7 -5
  130. package/lib/validation/validators/ymd.ts +36 -30
  131. package/package.json +44 -42
  132. package/lib/composables/Http.ts +0 -18
  133. package/lib/validation/validators/requiredHms.ts +0 -9
  134. package/lib/validation/validators/requiredYmd.ts +0 -9
@@ -1,49 +1,16 @@
1
- // eslint-disable-next-line @typescript-eslint/prefer-ts-expect-error
2
- // @ts-ignore internal
3
- import baseGetTag from 'lodash-es/_baseGetTag'
4
-
5
- import _isDate from 'lodash-es/isDate'
6
- import _isError from 'lodash-es/isError'
7
- import _isNumber from 'lodash-es/isNumber'
8
- import _isPlainObject from 'lodash-es/isPlainObject'
9
- import _isString from 'lodash-es/isString'
10
-
11
- export function isBlob(value: unknown): value is Blob {
12
- return value instanceof Blob || baseGetTag(value) === '[object Blob]'
13
- }
14
-
15
- export function isDate(value: unknown): value is Date {
16
- return _isDate(value)
17
- }
18
-
19
- export function isError<T extends Error = Error>(value: unknown): value is T {
20
- return _isError(value)
21
- }
22
-
23
- export function isFile(value: unknown): value is File {
24
- return value instanceof File || baseGetTag(value) === '[object File]'
25
- }
26
-
27
- export function isFormData(value: unknown): value is FormData {
28
- return value instanceof FormData || baseGetTag(value) === '[object FormData]'
29
- }
30
-
1
+ /** @deprecated */
31
2
  export function isNumber(value: unknown): value is number {
32
- return _isNumber(value)
3
+ return Number.isFinite(value)
33
4
  }
34
5
 
35
6
  export function isObject(value: unknown): value is Record<string, unknown> {
36
- return _isPlainObject(value)
37
- }
38
-
39
- export function isRequest(value: unknown): value is Request {
40
- return value instanceof Request || baseGetTag(value) === '[object Request]'
41
- }
7
+ if (value == null || typeof value !== 'object') { return false }
42
8
 
43
- export function isResponse(value: unknown): value is Response {
44
- return value instanceof Response || baseGetTag(value) === '[object Response]'
9
+ const proto = Object.getPrototypeOf(value)
10
+ return proto === null || proto === Object.prototype
45
11
  }
46
12
 
13
+ /** @deprecated */
47
14
  export function isString(value: unknown): value is string {
48
- return _isString(value)
15
+ return typeof value === 'string'
49
16
  }
@@ -1,7 +1,7 @@
1
1
  import { type ValidationRuleWithParams } from '@vuelidate/core'
2
2
  import { type MessageProps as VMessageProps, helpers } from '@vuelidate/validators'
3
3
  import { type Lang } from '../composables/Lang'
4
- import { _required } from './validators'
4
+ import { required } from './validators'
5
5
 
6
6
  export interface RuleOptions {
7
7
  optional?: boolean
@@ -15,34 +15,19 @@ export interface MessageProps extends VMessageProps {
15
15
  lang: Lang
16
16
  }
17
17
 
18
- export function createRule(
19
- options: RuleOptions
20
- ): ValidationRuleWithParams {
18
+ export function createRule(options: RuleOptions): ValidationRuleWithParams {
21
19
  const lang = typeof document !== 'undefined'
22
20
  ? (document.documentElement.lang === 'ja' ? 'ja' : 'en')
23
21
  : 'en'
24
22
 
25
23
  const params = options.params ?? {}
26
24
 
27
- const validator = helpers.withParams(
28
- params,
29
- (value: unknown) => {
30
- return options.optional && !_required(value)
31
- ? true
32
- : options.validation(value)
33
- }
34
- )
25
+ const validator = helpers.withParams(params, (value: unknown) => {
26
+ return options.optional && !required(value, false) ? true : options.validation(value)
27
+ })
35
28
 
36
29
  return helpers.withMessage(
37
30
  (params) => options.message({ ...params, lang }),
38
- options.async
39
- ? helpers.withAsync(validator, createParamsForAsyncValidator(params))
40
- : validator
31
+ options.async ? helpers.withAsync(validator, Object.values(params)) : validator
41
32
  )
42
33
  }
43
-
44
- function createParamsForAsyncValidator(params: Record<string, any>) {
45
- return Object.keys(params).map((key) => {
46
- return params[key]
47
- })
48
- }
@@ -1,8 +1,8 @@
1
1
  import { createRule } from '../Rule'
2
- import { decimal as baseDecimal, hyphen } from '../validators'
2
+ import { decimal as baseDecimal } from '../validators'
3
3
 
4
4
  export const message = {
5
- en: 'The value must be valid decimal numbers.',
5
+ en: 'The value must be a valid decimal number.',
6
6
  ja: 'この値は小数または10進数である必要があります。'
7
7
  }
8
8
 
@@ -10,6 +10,6 @@ export function decimal(msg?: string) {
10
10
  return createRule({
11
11
  message: ({ lang }) => msg ?? message[lang],
12
12
  optional: true,
13
- validation: (value) => !hyphen(value) && baseDecimal(value)
13
+ validation: (value) => baseDecimal(value)
14
14
  })
15
15
  }
@@ -2,7 +2,7 @@ import { createRule } from '../Rule'
2
2
  import { email as baseEmail } from '../validators'
3
3
 
4
4
  export const message = {
5
- en: 'The Email is invalid.',
5
+ en: 'The email is invalid.',
6
6
  ja: 'Emailの形式が正しくありません。'
7
7
  }
8
8
 
@@ -1,4 +1,3 @@
1
- export { and, not, or } from '@vuelidate/validators'
2
1
  export { after } from './after'
3
2
  export { afterOrEqual } from './afterOrEqual'
4
3
  export { before } from './before'
@@ -30,3 +29,4 @@ export { url } from './url'
30
29
  export { ymd } from './ymd'
31
30
  export { zeroOrNegativeInteger } from './zeroOrNegativeInteger'
32
31
  export { zeroOrPositiveInteger } from './zeroOrPositiveInteger'
32
+ export { and, not, or } from '@vuelidate/validators'
@@ -2,7 +2,7 @@ import { createRule } from '../Rule'
2
2
  import { negativeInteger as baseNegativeInteger } from '../validators'
3
3
 
4
4
  export const message = {
5
- en: 'The value must be valid negative integer.',
5
+ en: 'The value must be a valid negative integer.',
6
6
  ja: 'この値は負の整数である必要があります。'
7
7
  }
8
8
 
@@ -2,7 +2,7 @@ import { createRule } from '../Rule'
2
2
  import { positiveInteger as basePositiveInteger } from '../validators'
3
3
 
4
4
  export const message = {
5
- en: 'The value must be valid positive integer.',
5
+ en: 'The value must be a valid positive integer.',
6
6
  ja: 'この値は正の整数である必要があります。'
7
7
  }
8
8
 
@@ -1,6 +1,6 @@
1
1
  import { type HmsType } from '../../support/Day'
2
2
  import { createRule } from '../Rule'
3
- import { requiredHms as baseRequiredHms } from '../validators/requiredHms'
3
+ import { hms as baseHms } from '../validators/hms'
4
4
 
5
5
  export const message = {
6
6
  en: 'The field is required.',
@@ -10,6 +10,6 @@ export const message = {
10
10
  export function requiredHms(required?: HmsType[], msg?: string) {
11
11
  return createRule({
12
12
  message: ({ lang }) => msg ?? message[lang],
13
- validation: (value) => baseRequiredHms(value, required)
13
+ validation: (value) => baseHms(value, required, true)
14
14
  })
15
15
  }
@@ -6,10 +6,7 @@ export const message = {
6
6
  ja: 'この項目は必須です。'
7
7
  }
8
8
 
9
- export function requiredIf(
10
- condition: RequiredIfCondition,
11
- msg?: string
12
- ) {
9
+ export function requiredIf(condition: RequiredIfCondition, msg?: string) {
13
10
  return createRule({
14
11
  async: true,
15
12
  params: { condition },
@@ -1,6 +1,6 @@
1
1
  import { type YmdType } from '../../support/Day'
2
2
  import { createRule } from '../Rule'
3
- import { requiredYmd as baseRequiredYmd } from '../validators/requiredYmd'
3
+ import { ymd as baseYmd } from '../validators/ymd'
4
4
 
5
5
  export const message = {
6
6
  en: 'The field is required.',
@@ -10,6 +10,6 @@ export const message = {
10
10
  export function requiredYmd(required?: YmdType[], msg?: string) {
11
11
  return createRule({
12
12
  message: ({ lang }) => msg ?? message[lang],
13
- validation: (value) => baseRequiredYmd(value, required)
13
+ validation: (value) => baseYmd(value, required, true)
14
14
  })
15
15
  }
@@ -1,5 +1,8 @@
1
1
  import { createRule } from '../Rule'
2
- import { type SlackChannelNameOptions, slackChannelName as baseSlackChannelName } from '../validators'
2
+ import {
3
+ type SlackChannelNameOptions,
4
+ slackChannelName as baseSlackChannelName
5
+ } from '../validators'
3
6
 
4
7
  export const message = {
5
8
  en: 'The slack channel name is invalid.',
@@ -2,7 +2,7 @@ import { createRule } from '../Rule'
2
2
  import { negativeInteger as baseNegativeInteger, zero } from '../validators'
3
3
 
4
4
  export const message = {
5
- en: 'The value must be zero or valid negative integer.',
5
+ en: 'The value must be zero or a valid negative integer.',
6
6
  ja: 'この値はゼロまたは負の整数である必要があります。'
7
7
  }
8
8
 
@@ -2,7 +2,7 @@ import { createRule } from '../Rule'
2
2
  import { positiveInteger as basePositiveInteger, zero } from '../validators'
3
3
 
4
4
  export const message = {
5
- en: 'The value must be zero or valid positive integer.',
5
+ en: 'The value must be zero or a valid positive integer.',
6
6
  ja: 'この値はゼロまたは正の整数である必要があります。'
7
7
  }
8
8
 
@@ -1,9 +1,5 @@
1
1
  import { type Day, isDay } from '../../support/Day'
2
2
 
3
3
  export function after(value: unknown, date: Day): boolean {
4
- if (!isDay(value) || !isDay(date)) {
5
- return false
6
- }
7
-
8
- return value.isAfter(date)
4
+ return isDay(value) && isDay(date) && value.isAfter(date, 'day')
9
5
  }
@@ -1,9 +1,5 @@
1
1
  import { type Day, isDay } from '../../support/Day'
2
2
 
3
3
  export function afterOrEqual(value: unknown, date: Day): boolean {
4
- if (!isDay(value) || !isDay(date)) {
5
- return false
6
- }
7
-
8
- return value.isAfter(date) || value.isSame(date)
4
+ return isDay(value) && isDay(date) && (value.isAfter(date, 'day') || value.isSame(date, 'day'))
9
5
  }
@@ -1,8 +1,5 @@
1
1
  import { type Day, isDay } from '../../support/Day'
2
2
 
3
3
  export function before(value: unknown, date: Day): boolean {
4
- if (!isDay(value) || !isDay(date)) {
5
- return false
6
- }
7
- return value.isBefore(date)
4
+ return isDay(value) && isDay(date) && value.isBefore(date, 'day')
8
5
  }
@@ -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
- if (!isDay(value) || !isDay(date)) {
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
- if (!(isString(value) || isNumber(value))) {
7
- return false
8
- }
9
-
10
- return regExp.test(String(value))
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
- import { isString } from '../../support/Utils'
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
- /* 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
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
- if (!isString(value)) {
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 (!isFile(value)) {
6
- return false
7
- }
2
+ if (!(value instanceof File)) { return false }
8
3
 
9
- const fileExtension = getExtension(value)
4
+ extensions = extensions.map((ext) => ext.toLowerCase())
5
+ const fileExtension = value.name.split('.').pop()!.toLowerCase()
10
6
 
11
- return extensions.some((extension) => {
12
- // If the extention option is `jpg`, we'll consider other variants such as
13
- // `JPG`, `jpeg`, or `JPEG` to be valid as well for the sake of simplicity.
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
- return fileExtension === extension
19
- })
11
+ return extensions.includes(fileExtension)
20
12
  }
@@ -1,21 +1,32 @@
1
- import { HmsMap, type HmsType, isHms } from '../../support/Day'
1
+ import { type HmsType } from '../../support/Day'
2
+ import { isObject } from '../../support/Utils'
2
3
 
3
- export function hms(value: unknown, required: HmsType[] = ['h', 'm', 's']): boolean {
4
- if (!isHms(value, required)) {
5
- return false
6
- }
4
+ const hourRE = /^(?:[01]?\d|2[0-3])$/
5
+ const minuteAndSecondRE = /^[0-5]?\d$/
7
6
 
8
- return required.every((r) => {
9
- const _value = value[HmsMap[r]]
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
- if (_value === null) {
12
- return true
13
- }
14
+ const { hour, minute, second } = value
15
+ const requiredSet = new Set(required)
14
16
 
15
- const valueAsNumber = Number(_value)
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
- return (r === 'h')
18
- ? (valueAsNumber >= 0 && valueAsNumber < 24)
19
- : (valueAsNumber >= 0 && valueAsNumber < 60)
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 (!isFile(value)) {
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 * +size.replace(/[^\d\.]/g, '')
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
- if (!(isString(value) || Array.isArray(value))) {
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 (!isArrayOfFiles(value)) {
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 * +size.replace(/[^\d\.]/g, '')
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 { isDate, isNumber, isString } from '../../support/Utils'
1
+ import { decimal } from './decimal'
2
2
 
3
3
  export function maxValue(value: unknown, max: number) {
4
- if (isNumber(value) || isString(value) || isDate(value)) {
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
- if (!(isString(value) || Array.isArray(value))) {
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 { isDate, isNumber, isString } from '../../support/Utils'
1
+ import { decimal } from './decimal'
2
2
 
3
3
  export function minValue(value: unknown, min: number) {
4
- if (isNumber(value) || isString(value) || isDate(value)) {
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 month(value: unknown): boolean {
4
- if (!isNumber(value)) {
5
- return false
6
- }
7
-
8
- return value > 0 && value < 13
2
+ return Number.isInteger(value) && value > 0 && value < 13
9
3
  }
@@ -1,9 +1,3 @@
1
- import { isNumber } from '../../support/Utils'
2
-
3
1
  export function negativeInteger(value: unknown): boolean {
4
- if (!isNumber(value)) {
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
- if (!isNumber(value)) {
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
- import { isDate, isString } from '../../support/Utils'
2
-
3
- export function required(value: unknown): boolean {
4
- if (isString(value)) {
5
- value = value.trim()
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 { requiredHms } from './requiredHms'
2
+ import { hms } from './hms'
3
3
  import { type RequiredIfCondition } from './requiredIf'
4
4
 
5
- export async function requiredHmsIf(value: unknown, condition: RequiredIfCondition, required: HmsType[] = ['h', 'm', 's']): Promise<boolean> {
6
- if (typeof condition === 'boolean' && condition) {
7
- return requiredHms(value, required)
8
- }
9
-
10
- if (typeof condition === 'string' && condition) {
11
- return requiredHms(value, required)
12
- }
13
-
14
- if (typeof condition === 'function' && (await condition())) {
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
  }