@player-ui/common-types-plugin 0.4.0 → 0.4.1-next.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/src/index.ts CHANGED
@@ -1,10 +1,20 @@
1
- import type { Player, PlayerPlugin } from '@player-ui/player';
1
+ import type { Player, ExtendedPlayerPlugin } from '@player-ui/player';
2
2
  import { TypesProviderPlugin } from '@player-ui/types-provider-plugin';
3
3
 
4
4
  import * as validators from './validators';
5
5
  import * as dataTypes from './data-types/types';
6
6
  import * as dataRefs from './data-types/refs';
7
7
  import * as formats from './formats';
8
+ import type {
9
+ BooleanType,
10
+ IntegerType,
11
+ IntegerPosType,
12
+ IntegerNNType,
13
+ StringType,
14
+ CollectionType,
15
+ DateType,
16
+ PhoneType,
17
+ } from './data-types/types';
8
18
 
9
19
  export { validators, dataTypes, dataRefs, formats };
10
20
  export * from './formats/utils';
@@ -12,7 +22,24 @@ export * from './formats/utils';
12
22
  /**
13
23
  * Exposes a lot of common DataTypes, validations, and formats to Player instance.
14
24
  */
15
- export class CommonTypesPlugin implements PlayerPlugin {
25
+ export class CommonTypesPlugin
26
+ implements
27
+ ExtendedPlayerPlugin<
28
+ [],
29
+ [],
30
+ [],
31
+ [
32
+ typeof BooleanType,
33
+ typeof IntegerType,
34
+ typeof IntegerPosType,
35
+ typeof IntegerNNType,
36
+ typeof StringType,
37
+ typeof CollectionType,
38
+ typeof DateType,
39
+ typeof PhoneType
40
+ ]
41
+ >
42
+ {
16
43
  name = 'CommonTypes';
17
44
 
18
45
  apply(player: Player) {
@@ -1,4 +1,5 @@
1
1
  import type { Expression } from '@player-ui/types';
2
+ import { resolveDataRefs } from '@player-ui/player';
2
3
  import type { ValidatorFunction } from '@player-ui/player';
3
4
 
4
5
  // Shamelessly lifted from Scott Gonzalez via the Bassistance Validation plugin http://projects.scottsplayground.com/email_address_validation/
@@ -177,12 +178,13 @@ export const regex: ValidatorFunction<{
177
178
  return;
178
179
  }
179
180
 
181
+ const resolvedRegex = resolveDataRefs(options.regex, context);
180
182
  // Split up /pattern/flags into [pattern, flags]
181
- const patternMatch = options.regex.match(/^\/(.*)\/(\w)*$/);
183
+ const patternMatch = resolvedRegex.match(/^\/(.*)\/(\w)*$/);
182
184
 
183
185
  const regexp = patternMatch
184
186
  ? new RegExp(patternMatch[1], patternMatch[2])
185
- : new RegExp(options.regex);
187
+ : new RegExp(resolvedRegex);
186
188
 
187
189
  if (!regexp.test(value)) {
188
190
  const message = context.constants.getConstants(