@player-ui/common-types-plugin 0.0.1-next.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.
@@ -0,0 +1,250 @@
1
+ import { PlayerPlugin, Player } from '@player-ui/player';
2
+ import { Expression, Schema, Language } from '@player-ui/types';
3
+ import { ValidatorFunction } from '@player-ui/validator';
4
+ import { FormatType } from '@player-ui/schema';
5
+
6
+ /** Checks to see if the data-type is a string */
7
+ declare const string: ValidatorFunction;
8
+ /** Validation for a non-mutable property */
9
+ declare const readonly: ValidatorFunction;
10
+ /** Check to see if the value represents an array of items */
11
+ declare const collection: ValidatorFunction;
12
+ /** Checks to see if the value is an integer */
13
+ declare const integer$1: ValidatorFunction;
14
+ /** An enum check to see if the value is in a provided list of acceptable options */
15
+ declare const oneOf: ValidatorFunction<{
16
+ /** The enum values that are acceptable */
17
+ options: Array<unknown>;
18
+ }>;
19
+ /** A validator that evaluates an expression for validation */
20
+ declare const expression: ValidatorFunction<{
21
+ /**
22
+ * The expression to evaluate.
23
+ * Falsy values indicate an invalid response
24
+ */
25
+ exp: Expression;
26
+ }>;
27
+ /** A validator that requires a non-null value */
28
+ declare const required: ValidatorFunction<{
29
+ /** An optional expression to limit the required check only if true */
30
+ if?: Expression;
31
+ /** An optional expression to limit the required check only if false */
32
+ ifNot?: Expression;
33
+ }>;
34
+ /** A validator that uses a regular expression */
35
+ declare const regex: ValidatorFunction<{
36
+ /**
37
+ * The regular expression to test: /pattern/
38
+ * Can optionally include flags after the pattern: /pattern/flags
39
+ */
40
+ regex: string;
41
+ }>;
42
+ /** Checks the length of a value */
43
+ declare const length: ValidatorFunction<{
44
+ /** The minimum length to check against */
45
+ min?: number;
46
+ /** The maximum length to check against */
47
+ max?: number;
48
+ } | {
49
+ /** The exact length to match against */
50
+ exact: number;
51
+ }>;
52
+ /**
53
+ * Checks that the given value is at least the expected one
54
+ */
55
+ declare const min: ValidatorFunction<{
56
+ /** The minimum value */
57
+ value: number;
58
+ }>;
59
+ /**
60
+ * Checks that the given value is at least the expected one
61
+ */
62
+ declare const max: ValidatorFunction<{
63
+ /** The minimum value */
64
+ value: number;
65
+ }>;
66
+ /** Checks that the given value represents an email */
67
+ declare const email: ValidatorFunction<unknown>;
68
+ /** Checks that the given value represents a phone number */
69
+ declare const phone$1: ValidatorFunction<unknown>;
70
+ /** Checks that the given value represents a phone number */
71
+ declare const zip: ValidatorFunction<unknown>;
72
+
73
+ declare const index$1_string: typeof string;
74
+ declare const index$1_readonly: typeof readonly;
75
+ declare const index$1_collection: typeof collection;
76
+ declare const index$1_oneOf: typeof oneOf;
77
+ declare const index$1_expression: typeof expression;
78
+ declare const index$1_required: typeof required;
79
+ declare const index$1_regex: typeof regex;
80
+ declare const index$1_length: typeof length;
81
+ declare const index$1_min: typeof min;
82
+ declare const index$1_max: typeof max;
83
+ declare const index$1_email: typeof email;
84
+ declare const index$1_zip: typeof zip;
85
+ declare namespace index$1 {
86
+ export {
87
+ index$1_string as string,
88
+ index$1_readonly as readonly,
89
+ index$1_collection as collection,
90
+ integer$1 as integer,
91
+ index$1_oneOf as oneOf,
92
+ index$1_expression as expression,
93
+ index$1_required as required,
94
+ index$1_regex as regex,
95
+ index$1_length as length,
96
+ index$1_min as min,
97
+ index$1_max as max,
98
+ index$1_email as email,
99
+ phone$1 as phone,
100
+ index$1_zip as zip,
101
+ };
102
+ }
103
+
104
+ declare const BooleanType: Schema.DataType<boolean>;
105
+ declare const IntegerType: Schema.DataType<number>;
106
+ declare const IntegerPosType: Schema.DataType<number>;
107
+ declare const IntegerNNType: Schema.DataType<number>;
108
+ declare const StringType: Schema.DataType<string>;
109
+ declare const CollectionType: Schema.DataType<Array<unknown>>;
110
+ declare const DateType: Schema.DataType<string>;
111
+ declare const PhoneType: Schema.DataType<string>;
112
+
113
+ declare const types_BooleanType: typeof BooleanType;
114
+ declare const types_IntegerType: typeof IntegerType;
115
+ declare const types_IntegerPosType: typeof IntegerPosType;
116
+ declare const types_IntegerNNType: typeof IntegerNNType;
117
+ declare const types_StringType: typeof StringType;
118
+ declare const types_CollectionType: typeof CollectionType;
119
+ declare const types_DateType: typeof DateType;
120
+ declare const types_PhoneType: typeof PhoneType;
121
+ declare namespace types {
122
+ export {
123
+ types_BooleanType as BooleanType,
124
+ types_IntegerType as IntegerType,
125
+ types_IntegerPosType as IntegerPosType,
126
+ types_IntegerNNType as IntegerNNType,
127
+ types_StringType as StringType,
128
+ types_CollectionType as CollectionType,
129
+ types_DateType as DateType,
130
+ types_PhoneType as PhoneType,
131
+ };
132
+ }
133
+
134
+ declare const BooleanTypeRef: Language.DataTypeRef;
135
+ declare const IntegerTypeRef: Language.DataTypeRef;
136
+ declare const IntegerPosTypeRef: Language.DataTypeRef;
137
+ declare const IntegerNNTypeRef: Language.DataTypeRef;
138
+ declare const StringTypeRef: Language.DataTypeRef;
139
+ declare const CollectionTypeRef: Language.DataTypeRef;
140
+ declare const DateTypeRef: Language.DataTypeRef;
141
+ declare const PhoneTypeRef: Language.DataTypeRef;
142
+
143
+ declare const refs_BooleanTypeRef: typeof BooleanTypeRef;
144
+ declare const refs_IntegerTypeRef: typeof IntegerTypeRef;
145
+ declare const refs_IntegerPosTypeRef: typeof IntegerPosTypeRef;
146
+ declare const refs_IntegerNNTypeRef: typeof IntegerNNTypeRef;
147
+ declare const refs_StringTypeRef: typeof StringTypeRef;
148
+ declare const refs_CollectionTypeRef: typeof CollectionTypeRef;
149
+ declare const refs_DateTypeRef: typeof DateTypeRef;
150
+ declare const refs_PhoneTypeRef: typeof PhoneTypeRef;
151
+ declare namespace refs {
152
+ export {
153
+ refs_BooleanTypeRef as BooleanTypeRef,
154
+ refs_IntegerTypeRef as IntegerTypeRef,
155
+ refs_IntegerPosTypeRef as IntegerPosTypeRef,
156
+ refs_IntegerNNTypeRef as IntegerNNTypeRef,
157
+ refs_StringTypeRef as StringTypeRef,
158
+ refs_CollectionTypeRef as CollectionTypeRef,
159
+ refs_DateTypeRef as DateTypeRef,
160
+ refs_PhoneTypeRef as PhoneTypeRef,
161
+ };
162
+ }
163
+
164
+ /**
165
+ * Converts an integer to and from a string for display
166
+ */
167
+ declare const integer: FormatType<number, string>;
168
+ /** Converts a number to/from a comma separated version */
169
+ declare const commaNumber: FormatType<number, string, {
170
+ /** The number of decimal places to show */
171
+ precision?: number;
172
+ }>;
173
+ declare const date: FormatType<string, string, {
174
+ /** The mask to use to format the date */
175
+ mask?: string;
176
+ }>;
177
+ declare const currency: FormatType<number, string, {
178
+ /** The symbol to use for currency */
179
+ currencySymbol?: string;
180
+ /** Use parenthesis instead of a - sign for negative values */
181
+ useParensForNeg?: boolean;
182
+ /** The number of decimal places to show */
183
+ precision?: number;
184
+ }>;
185
+ declare const phone: FormatType<string>;
186
+
187
+ declare const index_integer: typeof integer;
188
+ declare const index_commaNumber: typeof commaNumber;
189
+ declare const index_date: typeof date;
190
+ declare const index_currency: typeof currency;
191
+ declare const index_phone: typeof phone;
192
+ declare namespace index {
193
+ export {
194
+ index_integer as integer,
195
+ index_commaNumber as commaNumber,
196
+ index_date as date,
197
+ index_currency as currency,
198
+ index_phone as phone,
199
+ };
200
+ }
201
+
202
+ declare const PLACEHOLDER = "#";
203
+ /**
204
+ * Remove any formatting characters in the 'mask' from 'value'
205
+ *
206
+ * @param value - The string to remove the control characters from
207
+ * @param mask - The mask to use and test against
208
+ * @param reserved - The reserved _slots_ (these are the chars that you expect new values to be subbed into)
209
+ *
210
+ * @example
211
+ * removeFormatCharactersFromMaskedString('123-456', '###-###', ['#']) => '123456'
212
+ */
213
+ declare const removeFormatCharactersFromMaskedString: (value: string, mask: string, reserved?: string[]) => string;
214
+ /**
215
+ * Format the given string using one of the accepted values
216
+ * Optionally, the value can be choose to ignore case when formatting, or to autocomplete if only 1 option is viable
217
+ * If no such option is viable, undefined is returned
218
+ */
219
+ declare const formatAsEnum: (value: string, acceptedValues: string[], options?: {
220
+ /** Ignore the case of the provided value when comparing to the acceptedValues */
221
+ ignoreCase?: boolean | undefined;
222
+ /** If only 1 option is viable, autocomplete the value to the accepted one */
223
+ autocomplete?: boolean | undefined;
224
+ } | undefined) => string | undefined;
225
+ /**
226
+ * Format the given value using the mask + match
227
+ *
228
+ * @param value - The string value to format
229
+ * @param valueCharMaskMatch - A regular expression that matches characters to substitute in the match. This is typically `/\d/g` or `/\w/g`
230
+ * @param mask - The mask to format against. Use # as a placeholder for
231
+ */
232
+ declare const formatAsMasked: (value: string | number, valueCharMaskMatch: RegExp, mask: string) => string;
233
+ /**
234
+ * Creates a format definition with the given mask
235
+ * Use the `#` char as a placeholder for a number
236
+ */
237
+ declare const createMaskedNumericFormatter: (name: string, mask: string) => FormatType<string, string, {
238
+ /** An enum of values that are also acceptable, and don't fall under the mask */
239
+ exceptions?: Array<string>;
240
+ }>;
241
+
242
+ /**
243
+ * Exposes a lot of common DataTypes, validations, and formats to Player instance.
244
+ */
245
+ declare class CommonTypesPlugin implements PlayerPlugin {
246
+ name: string;
247
+ apply(player: Player): void;
248
+ }
249
+
250
+ export { CommonTypesPlugin, PLACEHOLDER, createMaskedNumericFormatter, refs as dataRefs, types as dataTypes, formatAsEnum, formatAsMasked, index as formats, removeFormatCharactersFromMaskedString, index$1 as validators };