@xen-orchestra/web-core 0.53.0 → 0.54.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.
@@ -0,0 +1,17 @@
1
+ import { createRule, type Maybe } from '@regle/core'
2
+ import { isFilled } from '@regle/rules'
3
+
4
+ const IPV4_OCTET = '(25[0-5]|2[0-4]\\d|1\\d{2}|[1-9]?\\d)'
5
+ const IPV4_CIDR_PREFIX = '(3[0-2]|[12]?\\d)'
6
+ const IP_OR_CIDR_REGEX = new RegExp(`^${IPV4_OCTET}(\\.${IPV4_OCTET}){3}(/${IPV4_CIDR_PREFIX})?$`)
7
+
8
+ export const ipv4OrCidr = createRule({
9
+ validator(value: Maybe<string>) {
10
+ if (!isFilled(value)) {
11
+ return true
12
+ }
13
+
14
+ return IP_OR_CIDR_REGEX.test(value.trim())
15
+ },
16
+ message: 'Invalid IP address',
17
+ })
@@ -1,4 +1,5 @@
1
1
  export * from './custom-rules/out-of-range.rule.ts'
2
+ export * from './custom-rules/ipv4-or-cidr.rule.ts'
2
3
  export * from './merge-validation-configs.ts'
3
4
  export * from './types.ts'
4
5
  export * from './use-form-validation.ts'
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@xen-orchestra/web-core",
3
3
  "type": "module",
4
- "version": "0.53.0",
4
+ "version": "0.54.0",
5
5
  "private": false,
6
6
  "exports": {
7
7
  "./*": {