-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
99 lines (84 loc) · 2.73 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// ------------------------------------------------
// load original React prop-types
// ------------------------------------------------
var REACT_ELEMENT_TYPE = (typeof Symbol === 'function' &&
Symbol.for &&
Symbol.for('react.element')) ||
0xeac7;
var isValidElement = function (object) {
return typeof object === 'object' &&
object !== null &&
object.$$typeof === REACT_ELEMENT_TYPE;
};
var throwOnDirectAccess = true;
var PropTypes = require('../prop-types/factoryWithTypeCheckers')(isValidElement, throwOnDirectAccess);
// ------------------------------------------------
// ------------------------------------------------
// ------------------------------------------------
var AxePropTypes = {};
// function to add key value pair to proptype
var enhancePropType = function (propType, values) {
propType.info = Object.assign(
propType.info ? propType.info : {},
values
);
if (propType.isRequired) {
propType.isRequired.info = Object.assign(
propType.isRequired && propType.isRequired.info ? propType.isRequired.info : {},
values
);
propType.isRequired.info.isRequired = true;
propType.info.isRequired = false;
}
return propType;
};
// copy original PropTypes to AxePropTypes
Object.keys(PropTypes).forEach(function (propTypeName) {
if (propTypeName === 'PropTypes') return false;
AxePropTypes[propTypeName] = enhancePropType(PropTypes[propTypeName], { propTypeName: propTypeName });
});
// override "instanceOf"
AxePropTypes.instanceOf = function (jsClass) {
return enhancePropType(PropTypes.instanceOf(jsClass), {
className: jsClass && jsClass.name,
propTypeName: 'instanceOf'
});
};
// override "oneOf"
AxePropTypes.oneOf = function (allowedValues) {
return enhancePropType(PropTypes.oneOf(allowedValues), {
allowedValues: allowedValues,
propTypeName: 'oneOf'
});
};
// override "oneOfType"
AxePropTypes.oneOfType = function (allowedPropTypes) {
return enhancePropType(PropTypes.oneOfType(allowedPropTypes), {
allowedPropTypes: allowedPropTypes,
propTypeName: 'oneOfType'
});
};
// override "arrayOf"
AxePropTypes.arrayOf = function (allowedChildrenPropType) {
return enhancePropType(PropTypes.arrayOf(allowedChildrenPropType), {
allowedChildrenPropType: allowedChildrenPropType,
propTypeName: 'arrayOf'
});
};
// override "objectOf"
AxePropTypes.objectOf = function (allowedChildrenPropType) {
return enhancePropType(PropTypes.objectOf(allowedChildrenPropType), {
allowedChildrenPropType: allowedChildrenPropType,
propTypeName: 'objectOf'
});
};
// override "shape"
AxePropTypes.shape = function (objectShape) {
return enhancePropType(PropTypes.shape(objectShape), {
objectShape: objectShape,
propTypeName: 'shape'
});
};
// export
AxePropTypes.PropTypes = AxePropTypes;
module.exports = AxePropTypes;