@streamscloud/kit 0.93.0 → 0.93.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.
@@ -2,7 +2,11 @@ import type { TextValidation, TextWithFormatValidation } from './types';
2
2
  import * as yup from 'yup';
3
3
  /** Value-level rules of `textValidationSchema`. Judges a real value — `null` / `undefined` are decided by the schema modifiers the caller adds. */
4
4
  export declare const isValidText: (value: string, rules: TextValidation) => boolean;
5
- /** Value-level rules of `formattedTextValidationSchema` — `isValidText` plus the format, which an empty value skips. */
6
- export declare const isValidFormattedText: (value: string, rules: TextWithFormatValidation) => boolean;
5
+ /**
6
+ * Value-level rules of `formattedTextValidationSchema` — `isValidText` plus the format, which an empty value skips.
7
+ * @param unicode compiles the format with the `u` flag, so Unicode property escapes like `\p{L}` work. @default true
8
+ */
9
+ export declare const isValidFormattedText: (value: string, rules: TextWithFormatValidation, unicode?: boolean) => boolean;
7
10
  export declare const textValidationSchema: (rules: TextValidation) => yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
8
- export declare const formattedTextValidationSchema: (rules: TextWithFormatValidation, fieldName: string, formatMessage?: string) => yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
11
+ /** @param unicode compiles the format with the `u` flag, so Unicode property escapes like `\p{L}` work. @default true */
12
+ export declare const formattedTextValidationSchema: (rules: TextWithFormatValidation, fieldName: string, formatMessage?: string, unicode?: boolean) => yup.StringSchema<string | undefined, yup.AnyObject, undefined, "">;
@@ -1,13 +1,17 @@
1
1
  import { ValidationLocalization } from './validation-localization';
2
2
  import * as yup from 'yup';
3
3
  const isEmptyOrHasContent = (value) => !value || value.trim().length > 0;
4
+ const matchesFormat = (value, format, unicode) => new RegExp(format, unicode ? 'u' : '').test(value);
4
5
  /** Value-level rules of `textValidationSchema`. Judges a real value — `null` / `undefined` are decided by the schema modifiers the caller adds. */
5
6
  export const isValidText = (value, rules) => {
6
7
  return isEmptyOrHasContent(value) && value.length >= rules.minLength && value.length <= rules.maxLength;
7
8
  };
8
- /** Value-level rules of `formattedTextValidationSchema` — `isValidText` plus the format, which an empty value skips. */
9
- export const isValidFormattedText = (value, rules) => {
10
- return isValidText(value, rules) && (!value || new RegExp(rules.format).test(value));
9
+ /**
10
+ * Value-level rules of `formattedTextValidationSchema` — `isValidText` plus the format, which an empty value skips.
11
+ * @param unicode compiles the format with the `u` flag, so Unicode property escapes like `\p{L}` work. @default true
12
+ */
13
+ export const isValidFormattedText = (value, rules, unicode = true) => {
14
+ return isValidText(value, rules) && (!value || matchesFormat(value, rules.format, unicode));
11
15
  };
12
16
  export const textValidationSchema = (rules) => {
13
17
  const msg = new ValidationLocalization();
@@ -22,7 +26,8 @@ export const textValidationSchema = (rules) => {
22
26
  return schema.min(rules.minLength, msg.minLength(rules.minLength));
23
27
  }
24
28
  };
25
- export const formattedTextValidationSchema = (rules, fieldName, formatMessage) => {
29
+ /** @param unicode compiles the format with the `u` flag, so Unicode property escapes like `\p{L}` work. @default true */
30
+ export const formattedTextValidationSchema = (rules, fieldName, formatMessage, unicode = true) => {
26
31
  const msg = new ValidationLocalization();
27
- return textValidationSchema(rules).test(`${fieldName}-format`, formatMessage ?? msg.badFormat, (val) => !val || new RegExp(rules.format).test(val));
32
+ return textValidationSchema(rules).test(`${fieldName}-format`, formatMessage ?? msg.badFormat, (val) => !val || matchesFormat(val, rules.format, unicode));
28
33
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamscloud/kit",
3
- "version": "0.93.0",
3
+ "version": "0.93.1",
4
4
  "author": "StreamsCloud",
5
5
  "repository": {
6
6
  "type": "git",