source: imaps-frontend/node_modules/jsx-ast-utils/lib/hasProp.js

main
Last change on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 2.5 KB
Line 
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = hasProp;
7exports.hasAnyProp = hasAnyProp;
8exports.hasEveryProp = hasEveryProp;
9
10var _propName = require('./propName');
11
12var _propName2 = _interopRequireDefault(_propName);
13
14function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
16var DEFAULT_OPTIONS = {
17 spreadStrict: true,
18 ignoreCase: true
19};
20
21/**
22 * Returns boolean indicating whether an prop exists on the props
23 * property of a JSX element node.
24 */
25function hasProp() {
26 var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
27 var prop = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
28 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DEFAULT_OPTIONS;
29
30 var propToCheck = options.ignoreCase ? prop.toUpperCase() : prop;
31
32 return props.some(function (attribute) {
33 // If the props contain a spread prop, then refer to strict param.
34 if (attribute.type === 'JSXSpreadAttribute') {
35 return !options.spreadStrict;
36 }
37
38 var currentProp = options.ignoreCase ? (0, _propName2.default)(attribute).toUpperCase() : (0, _propName2.default)(attribute);
39
40 return propToCheck === currentProp;
41 });
42}
43
44/**
45 * Given the props on a node and a list of props to check, this returns a boolean
46 * indicating if any of them exist on the node.
47 */
48function hasAnyProp() {
49 var nodeProps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
50 var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
51 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DEFAULT_OPTIONS;
52
53 var propsToCheck = typeof props === 'string' ? props.split(' ') : props;
54
55 return propsToCheck.some(function (prop) {
56 return hasProp(nodeProps, prop, options);
57 });
58}
59
60/**
61 * Given the props on a node and a list of props to check, this returns a boolean
62 * indicating if all of them exist on the node
63 */
64function hasEveryProp() {
65 var nodeProps = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
66 var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
67 var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DEFAULT_OPTIONS;
68
69 var propsToCheck = typeof props === 'string' ? props.split(' ') : props;
70
71 return propsToCheck.every(function (prop) {
72 return hasProp(nodeProps, prop, options);
73 });
74}
Note: See TracBrowser for help on using the repository browser.