@elliemae/ds-props-helpers 3.0.0-next.2 → 3.0.0-next.3

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 (173) hide show
  1. package/dist/cjs/defaultProps/index.js +28 -0
  2. package/dist/cjs/defaultProps/index.js.map +7 -0
  3. package/dist/cjs/defaultProps/useMemoMergePropsWithDefault.js +62 -0
  4. package/dist/cjs/defaultProps/useMemoMergePropsWithDefault.js.map +7 -0
  5. package/dist/cjs/getProps/index.js +37 -0
  6. package/dist/cjs/getProps/index.js.map +7 -0
  7. package/dist/cjs/globalProps/constants.js +397 -0
  8. package/dist/cjs/globalProps/constants.js.map +7 -0
  9. package/dist/cjs/globalProps/globalAttributesPropTypes.js +398 -0
  10. package/dist/cjs/globalProps/globalAttributesPropTypes.js.map +7 -0
  11. package/dist/cjs/globalProps/index.js +29 -0
  12. package/dist/cjs/globalProps/index.js.map +7 -0
  13. package/dist/cjs/globalProps/useGetGlobalAttributes.js +56 -0
  14. package/dist/cjs/globalProps/useGetGlobalAttributes.js.map +7 -0
  15. package/dist/cjs/index.js +34 -0
  16. package/dist/cjs/index.js.map +7 -0
  17. package/dist/cjs/propTypes/PropTypes.js +149 -0
  18. package/dist/cjs/propTypes/PropTypes.js.map +7 -0
  19. package/dist/cjs/propTypes/customPropTypes.js +38 -0
  20. package/dist/cjs/propTypes/customPropTypes.js.map +7 -0
  21. package/dist/cjs/propTypes/describe.js +81 -0
  22. package/dist/cjs/propTypes/describe.js.map +7 -0
  23. package/dist/cjs/propTypes/describeConversions.js +96 -0
  24. package/dist/cjs/propTypes/describeConversions.js.map +7 -0
  25. package/dist/cjs/propTypes/describeGuards.js +49 -0
  26. package/dist/cjs/propTypes/describeGuards.js.map +7 -0
  27. package/dist/cjs/propTypes/index.js +37 -0
  28. package/dist/cjs/propTypes/index.js.map +7 -0
  29. package/dist/cjs/propTypes/toTypescript.js +154 -0
  30. package/dist/cjs/propTypes/toTypescript.js.map +7 -0
  31. package/dist/cjs/propTypes/types.js +27 -0
  32. package/dist/cjs/propTypes/types.js.map +7 -0
  33. package/dist/cjs/tests/globalProps/TestComponent.js +54 -0
  34. package/dist/cjs/tests/globalProps/TestComponent.js.map +7 -0
  35. package/dist/cjs/tests/validation/test.schema.js +67 -0
  36. package/dist/cjs/tests/validation/test.schema.js.map +7 -0
  37. package/dist/cjs/tests/xstyledProps/TestComponent.js +60 -0
  38. package/dist/cjs/tests/xstyledProps/TestComponent.js.map +7 -0
  39. package/dist/cjs/useDeprecateComponent/index.js +40 -0
  40. package/dist/cjs/useDeprecateComponent/index.js.map +7 -0
  41. package/dist/cjs/validation/errorTemplates.js +48 -0
  42. package/dist/cjs/validation/errorTemplates.js.map +7 -0
  43. package/dist/cjs/validation/index.js +30 -0
  44. package/dist/cjs/validation/index.js.map +7 -0
  45. package/dist/cjs/validation/typescriptGuards.js +65 -0
  46. package/dist/cjs/validation/typescriptGuards.js.map +7 -0
  47. package/dist/cjs/validation/typescriptParsers.js +76 -0
  48. package/dist/cjs/validation/typescriptParsers.js.map +7 -0
  49. package/dist/cjs/validation/typescriptValidator.js +171 -0
  50. package/dist/cjs/validation/typescriptValidator.js.map +7 -0
  51. package/dist/cjs/validation/validator.js +55 -0
  52. package/dist/cjs/validation/validator.js.map +7 -0
  53. package/dist/cjs/xstyledProps/constants.js +88 -0
  54. package/dist/cjs/xstyledProps/constants.js.map +7 -0
  55. package/dist/cjs/xstyledProps/index.js +29 -0
  56. package/dist/cjs/xstyledProps/index.js.map +7 -0
  57. package/dist/cjs/xstyledProps/useGetXstyledProps.js +48 -0
  58. package/dist/cjs/xstyledProps/useGetXstyledProps.js.map +7 -0
  59. package/dist/cjs/xstyledProps/xstyledPropTypes.js +92 -0
  60. package/dist/cjs/xstyledProps/xstyledPropTypes.js.map +7 -0
  61. package/dist/esm/defaultProps/index.js +3 -0
  62. package/dist/esm/defaultProps/index.js.map +7 -0
  63. package/dist/esm/defaultProps/useMemoMergePropsWithDefault.js +35 -0
  64. package/dist/esm/defaultProps/useMemoMergePropsWithDefault.js.map +7 -0
  65. package/dist/esm/getProps/index.js +8 -0
  66. package/dist/esm/getProps/index.js.map +7 -0
  67. package/dist/esm/globalProps/constants.js +368 -0
  68. package/dist/esm/globalProps/constants.js.map +7 -0
  69. package/dist/esm/globalProps/globalAttributesPropTypes.js +369 -0
  70. package/dist/esm/globalProps/globalAttributesPropTypes.js.map +7 -0
  71. package/dist/esm/globalProps/index.js +4 -0
  72. package/dist/esm/globalProps/index.js.map +7 -0
  73. package/dist/esm/globalProps/useGetGlobalAttributes.js +27 -0
  74. package/dist/esm/globalProps/useGetGlobalAttributes.js.map +7 -0
  75. package/dist/esm/index.js +9 -0
  76. package/dist/esm/index.js.map +7 -0
  77. package/dist/esm/propTypes/PropTypes.js +122 -0
  78. package/dist/esm/propTypes/PropTypes.js.map +7 -0
  79. package/dist/esm/propTypes/customPropTypes.js +9 -0
  80. package/dist/esm/propTypes/customPropTypes.js.map +7 -0
  81. package/dist/esm/propTypes/describe.js +52 -0
  82. package/dist/esm/propTypes/describe.js.map +7 -0
  83. package/dist/esm/propTypes/describeConversions.js +76 -0
  84. package/dist/esm/propTypes/describeConversions.js.map +7 -0
  85. package/dist/esm/propTypes/describeGuards.js +20 -0
  86. package/dist/esm/propTypes/describeGuards.js.map +7 -0
  87. package/dist/esm/propTypes/index.js +8 -0
  88. package/dist/esm/propTypes/index.js.map +7 -0
  89. package/dist/esm/propTypes/toTypescript.js +127 -0
  90. package/dist/esm/propTypes/toTypescript.js.map +7 -0
  91. package/dist/esm/propTypes/types.js +2 -0
  92. package/dist/esm/propTypes/types.js.map +7 -0
  93. package/dist/esm/tests/globalProps/TestComponent.js +27 -0
  94. package/dist/esm/tests/globalProps/TestComponent.js.map +7 -0
  95. package/dist/esm/tests/validation/test.schema.js +38 -0
  96. package/dist/esm/tests/validation/test.schema.js.map +7 -0
  97. package/dist/esm/tests/xstyledProps/TestComponent.js +33 -0
  98. package/dist/esm/tests/xstyledProps/TestComponent.js.map +7 -0
  99. package/dist/esm/useDeprecateComponent/index.js +11 -0
  100. package/dist/esm/useDeprecateComponent/index.js.map +7 -0
  101. package/dist/esm/validation/errorTemplates.js +19 -0
  102. package/dist/esm/validation/errorTemplates.js.map +7 -0
  103. package/dist/esm/validation/index.js +5 -0
  104. package/dist/esm/validation/index.js.map +7 -0
  105. package/dist/esm/validation/typescriptGuards.js +36 -0
  106. package/dist/esm/validation/typescriptGuards.js.map +7 -0
  107. package/dist/esm/validation/typescriptParsers.js +47 -0
  108. package/dist/esm/validation/typescriptParsers.js.map +7 -0
  109. package/dist/esm/validation/typescriptValidator.js +153 -0
  110. package/dist/esm/validation/typescriptValidator.js.map +7 -0
  111. package/dist/esm/validation/validator.js +26 -0
  112. package/dist/esm/validation/validator.js.map +7 -0
  113. package/dist/esm/xstyledProps/constants.js +59 -0
  114. package/dist/esm/xstyledProps/constants.js.map +7 -0
  115. package/dist/esm/xstyledProps/index.js +4 -0
  116. package/dist/esm/xstyledProps/index.js.map +7 -0
  117. package/dist/esm/xstyledProps/useGetXstyledProps.js +19 -0
  118. package/dist/esm/xstyledProps/useGetXstyledProps.js.map +7 -0
  119. package/dist/esm/xstyledProps/xstyledPropTypes.js +63 -0
  120. package/dist/esm/xstyledProps/xstyledPropTypes.js.map +7 -0
  121. package/package.json +91 -45
  122. package/cjs/defaultProps/index.js +0 -9
  123. package/cjs/defaultProps/useMemoMergePropsWithDefault.js +0 -48
  124. package/cjs/getProps/index.js +0 -20
  125. package/cjs/globalProps/constants.js +0 -15
  126. package/cjs/globalProps/globalAttributesPropTypes.js +0 -372
  127. package/cjs/globalProps/index.js +0 -11
  128. package/cjs/globalProps/useGetGlobalAttributes.js +0 -36
  129. package/cjs/index.js +0 -24
  130. package/cjs/validation/errorTemplates.js +0 -16
  131. package/cjs/validation/index.js +0 -15
  132. package/cjs/validation/typescriptGuards.js +0 -36
  133. package/cjs/validation/typescriptParsers.js +0 -45
  134. package/cjs/validation/typescriptValidator.js +0 -207
  135. package/cjs/validation/validator.js +0 -36
  136. package/esm/defaultProps/index.js +0 -1
  137. package/esm/defaultProps/useMemoMergePropsWithDefault.js +0 -39
  138. package/esm/getProps/index.js +0 -15
  139. package/esm/globalProps/constants.js +0 -11
  140. package/esm/globalProps/globalAttributesPropTypes.js +0 -368
  141. package/esm/globalProps/index.js +0 -2
  142. package/esm/globalProps/useGetGlobalAttributes.js +0 -32
  143. package/esm/index.js +0 -7
  144. package/esm/validation/errorTemplates.js +0 -11
  145. package/esm/validation/index.js +0 -3
  146. package/esm/validation/typescriptGuards.js +0 -23
  147. package/esm/validation/typescriptParsers.js +0 -41
  148. package/esm/validation/typescriptValidator.js +0 -202
  149. package/esm/validation/validator.js +0 -32
  150. package/types/defaultProps/index.d.ts +0 -1
  151. package/types/defaultProps/useMemoMergePropsWithDefault.d.ts +0 -1
  152. package/types/getProps/index.d.ts +0 -2
  153. package/types/globalProps/constants.d.ts +0 -3
  154. package/types/globalProps/globalAttributesPropTypes.d.ts +0 -2169
  155. package/types/globalProps/index.d.ts +0 -2
  156. package/types/globalProps/useGetGlobalAttributes.d.ts +0 -5
  157. package/types/index.d.ts +0 -4
  158. package/types/tests/any.validation.test.d.ts +0 -1
  159. package/types/tests/array.validation.test.d.ts +0 -1
  160. package/types/tests/boolean.validation.test.d.ts +0 -1
  161. package/types/tests/function.validation.test.d.ts +0 -1
  162. package/types/tests/number.validation.test.d.ts +0 -1
  163. package/types/tests/object.validation.test.d.ts +0 -1
  164. package/types/tests/schema.validation.test.d.ts +0 -1
  165. package/types/tests/string.validation.test.d.ts +0 -1
  166. package/types/tests/test.schema.d.ts +0 -1
  167. package/types/tests/union.validation.test.d.ts +0 -1
  168. package/types/validation/errorTemplates.d.ts +0 -2
  169. package/types/validation/index.d.ts +0 -3
  170. package/types/validation/typescriptGuards.d.ts +0 -12
  171. package/types/validation/typescriptParsers.d.ts +0 -1
  172. package/types/validation/typescriptValidator.d.ts +0 -15
  173. package/types/validation/validator.d.ts +0 -1
@@ -1,202 +0,0 @@
1
- import 'core-js/modules/esnext.async-iterator.for-each.js';
2
- import 'core-js/modules/esnext.iterator.constructor.js';
3
- import 'core-js/modules/esnext.iterator.for-each.js';
4
- import 'core-js/modules/web.dom-collections.iterator.js';
5
- import { describe } from 'react-desc';
6
- import { useState, useMemo } from 'react';
7
- import { throwRequiredError, throwTypeError } from './errorTemplates.js';
8
- import { isUndefined, isNull, isPrimitiveType, isUnion, isString, isArray, isObject, isFunction, isJSXorNode, isSomethingWithParenthesis } from './typescriptGuards.js';
9
- import { typescriptObjectParser } from './typescriptParsers.js';
10
-
11
- // =============================================================================
12
- // Atom Validators
13
- // =============================================================================
14
- // This functions will validate something from the data
15
- // and optionally recursively apply `validateValueWithFormat`
16
- // in smaller parts
17
- const validateUndefined = (schemaName, key, value, format) => {
18
- if (value !== undefined || value === 'undefined') {
19
- throwTypeError(schemaName, key, value, format);
20
- }
21
- };
22
-
23
- const validateNull = (schemaName, key, value, format) => {
24
- if (value !== null || value === 'null') {
25
- throwTypeError(schemaName, key, value, format);
26
- }
27
- };
28
-
29
- const validatePrimitiveType = (schemaName, key, value, format) => {
30
- if (typeof value !== format) {
31
- throwTypeError(schemaName, key, value, format);
32
- }
33
- };
34
-
35
- const validateString = (schemaName, key, value, format) => {
36
- if (value !== format.slice(1, -1)) {
37
- throwTypeError(schemaName, key, value, format);
38
- }
39
- };
40
-
41
- const validateArray = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {
42
- // Check that we have an array
43
- if (!Array.isArray(value)) {
44
- throwTypeError(schemaName, key, value, format);
45
- } // Check that each element inside satisfies the format
46
-
47
-
48
- value.forEach((val, index) => {
49
- // this is a recursive func, we need to invoke it before it's defined.
50
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
51
- validateValueWithFormat(schemaName, "".concat(key, "[").concat(index, "]"), val, format.slice(0, -2), validationsMemo, nextValidationsMemo);
52
- });
53
- };
54
-
55
- function isObjectType(value) {
56
- return !(typeof value !== 'object' || Array.isArray(value));
57
- }
58
-
59
- const validateObject = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {
60
- const valuesIsObject = isObjectType(value); // Check that we have an object
61
-
62
- if (!valuesIsObject) {
63
- throwTypeError(schemaName, key, value, format);
64
- return;
65
- }
66
-
67
- if (format === 'object') return;
68
- const keyValuePairs = typescriptObjectParser(format); // Now we have the key - value pairs
69
- // Each key could either be required or not
70
- // Just recursively check the object
71
-
72
- keyValuePairs.forEach(_ref => {
73
- let [objectKey, objectValue] = _ref;
74
- const trueKey = objectKey.slice(-1) === '?' ? objectKey.slice(0, -1) : objectKey;
75
-
76
- if (trueKey === objectKey && !(trueKey in value)) {
77
- throwRequiredError(schemaName, key);
78
- }
79
-
80
- if (trueKey in value) {
81
- // this is a recursive func, we need to invoke it before it's defined.
82
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
83
- validateValueWithFormat(schemaName, "".concat(key, "[").concat(trueKey, "]"), value[trueKey], objectValue, validationsMemo, nextValidationsMemo);
84
- }
85
- });
86
- };
87
-
88
- const validateUnion = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {
89
- const possibilities = format.split(/\s?\|\s?/);
90
- const errors = [];
91
- possibilities.forEach(possibility => {
92
- try {
93
- // this is a recursive func, we need to invoke it before it's defined.
94
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
95
- validateValueWithFormat(schemaName, key, value, possibility, validationsMemo, nextValidationsMemo);
96
- } catch (e) {
97
- errors.push(e);
98
- }
99
- });
100
-
101
- if (errors.length === possibilities.length) {
102
- throwTypeError(schemaName, key, value, format);
103
- }
104
- };
105
-
106
- const validateFunction = (schemaName, key, value, format) => {
107
- // Check that we have a function
108
- if (typeof value !== 'function') {
109
- throwTypeError(schemaName, key, value, format);
110
- }
111
- };
112
-
113
- function isJSXElement(value) {
114
- return value === null || typeof value === 'object' && value !== null && '$$typeof' in value;
115
- }
116
-
117
- const validateJSXorNode = (schemaName, key, value, format) => {
118
- const valueIsJSX = isJSXElement(value);
119
-
120
- if (format === 'JSX.Element' && !valueIsJSX) {
121
- throwTypeError(schemaName, key, value, format);
122
- }
123
- }; // =============================================================================
124
- // Schema validator
125
- // =============================================================================
126
-
127
-
128
- const validateValueWithFormat = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {
129
- nextValidationsMemo[value] = format;
130
-
131
- if (value in validationsMemo) {
132
- // We already validated this value on this format
133
- return;
134
- }
135
-
136
- if (isUndefined(format)) {
137
- validateUndefined(schemaName, key, value, format);
138
- } else if (isNull(format)) {
139
- validateNull(schemaName, key, value, format);
140
- } else if (isPrimitiveType(format)) {
141
- validatePrimitiveType(schemaName, key, value, format);
142
- } else if (isUnion(format)) {
143
- validateUnion(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
144
- } else if (isString(format)) {
145
- validateString(schemaName, key, value, format);
146
- } else if (isArray(format)) {
147
- validateArray(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
148
- } else if (isObject(format)) {
149
- validateObject(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
150
- } else if (isFunction(format)) {
151
- validateFunction(schemaName, key, value, format);
152
- } else if (isJSXorNode(format)) {
153
- validateJSXorNode(schemaName, key, value, format);
154
- } else if (isSomethingWithParenthesis(format)) {
155
- validateValueWithFormat(schemaName, key, value, format.slice(1, -1), validationsMemo, nextValidationsMemo);
156
- }
157
- };
158
-
159
- const validateTypescriptPropTypesImplementation = function (props, schema) {
160
- let validationsMemo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
161
- let nextValidationsMemo = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
162
- const {
163
- properties,
164
- name: schemaName
165
- } = schema;
166
- properties.forEach(property => {
167
- const {
168
- name,
169
- format,
170
- required
171
- } = property;
172
-
173
- if (required && !(name in props)) {
174
- throwRequiredError(schema.name, name);
175
- }
176
-
177
- if (name in props && (props[name] !== undefined || required)) {
178
- validateValueWithFormat(schemaName, name, props[name], format, validationsMemo, nextValidationsMemo);
179
- }
180
- });
181
- }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
182
-
183
- const useValidateTypescriptPropTypes = (props, propTypes) => {
184
- const [validationsMemo, setValidationsMemo] = useState({}); // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
185
-
186
- const ComponentWithSchema = useMemo(() => {
187
- const Component = () => {}; // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call
188
-
189
-
190
- return describe(Component);
191
- }, []); // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment
192
-
193
- ComponentWithSchema.propTypes = propTypes;
194
- useMemo(() => {
195
- const nextValidationsMemo = {};
196
- validateTypescriptPropTypesImplementation(props, // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
197
- ComponentWithSchema.toTypescript(), validationsMemo, nextValidationsMemo);
198
- setValidationsMemo(nextValidationsMemo); // eslint-disable-next-line react-hooks/exhaustive-deps
199
- }, [props]);
200
- };
201
-
202
- export { useValidateTypescriptPropTypes, validateTypescriptPropTypesImplementation };
@@ -1,32 +0,0 @@
1
- import 'core-js/modules/esnext.async-iterator.for-each.js';
2
- import 'core-js/modules/esnext.iterator.constructor.js';
3
- import 'core-js/modules/esnext.iterator.for-each.js';
4
- import { throwRequiredError, throwTypeError } from './errorTemplates.js';
5
-
6
- const useValidatePropTypes = (props, schema) => {
7
- schema.properties.forEach(property => {
8
- const propertyName = property.name;
9
- const currentProp = props[propertyName];
10
- const currentPropTypeOf = typeof currentProp; // eslint-disable-next-line max-len
11
-
12
- const currentFormat = property.format; // this is csv representing types e.g.: "string"/"string,number"/"[object],string"
13
-
14
- let isValidReactElement = false; // this depends on react desc definition
15
-
16
- if (property.required && !Object.prototype.hasOwnProperty.call(props, property.name)) {
17
- throwRequiredError(schema.name, property.name);
18
- }
19
-
20
- if (currentPropTypeOf !== 'undefined' && currentProp !== null) {
21
- if (currentPropTypeOf === 'object' && Object.prototype.hasOwnProperty.call(currentProp, '$$typeof') && (currentFormat.includes('node') || currentFormat.includes('element'))) {
22
- isValidReactElement = true;
23
- }
24
-
25
- if (!currentFormat.includes(currentPropTypeOf) && !currentFormat.includes(currentProp) && !isValidReactElement) {
26
- throwTypeError(schema.name, propertyName, currentProp, currentFormat);
27
- }
28
- }
29
- });
30
- };
31
-
32
- export { useValidatePropTypes };
@@ -1 +0,0 @@
1
- export * from './useMemoMergePropsWithDefault';
@@ -1 +0,0 @@
1
- export declare const useMemoMergePropsWithDefault: <T = Record<string, any>>(props: Partial<T>, defaultProps: Partial<T>, compare?: (a: any, b: any) => boolean) => T;
@@ -1,2 +0,0 @@
1
- export declare const getAriaProps: (props: Record<string, unknown>) => Record<string, unknown>;
2
- export declare const getDataProps: (props: Record<string, unknown>) => Record<string, unknown>;
@@ -1,3 +0,0 @@
1
- import { AriaAttributes, DOMAttributes, HTMLAttributes } from 'react';
2
- export declare type GlobalAttributes<T = true> = Record<keyof (AriaAttributes & DOMAttributes<Element> & HTMLAttributes<Element>), T>;
3
- export declare const globalAttributes: GlobalAttributes<true>;