breakdancer 3.0.1 → 4.1.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # CHANGELOG
2
2
 
3
+ ### 4.0.0
4
+
5
+ - Upgrade to `babel@7`.
6
+
7
+ ### 3.0.2
8
+
9
+ - Removed react-native from peerDependencies.
10
+
3
11
  ### 3.0.1
4
12
 
5
13
  - [#15] Updated peerDependencies ranges to include React 16.
package/SECURITY.md ADDED
@@ -0,0 +1,19 @@
1
+ # Reporting Security Issues
2
+
3
+ We take security very seriously at GoDaddy. We appreciate your efforts to
4
+ responsibly disclose your findings, and will make every effort to acknowledge
5
+ your contributions.
6
+
7
+ ## Where should I report security issues?
8
+
9
+ In order to give the community time to respond and upgrade, we strongly urge you
10
+ report all security issues privately.
11
+
12
+ To report a security issue in one of our Open Source projects email us directly
13
+ at **oss@godaddy.com** and include the word "SECURITY" in the subject line.
14
+
15
+ This mail is delivered to our Open Source Security team.
16
+
17
+ After the initial reply to your report, the team will keep you informed of the
18
+ progress being made towards a fix and announcement, and may ask for additional
19
+ information or guidance.
@@ -1,13 +1,16 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
-
7
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
6
+ exports.default = void 0;
8
7
 
9
8
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
10
9
 
10
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
11
+
12
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
13
+
11
14
  /**
12
15
  * Breakdancer is a simple breakpoint utility.
13
16
  *
@@ -15,7 +18,9 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
15
18
  * @param {Object} specification Different breakpoints we need to know.
16
19
  * @public
17
20
  */
18
- var Breakdancer = function () {
21
+ var Breakdancer =
22
+ /*#__PURE__*/
23
+ function () {
19
24
  function Breakdancer(specification) {
20
25
  _classCallCheck(this, Breakdancer);
21
26
 
@@ -25,7 +30,6 @@ var Breakdancer = function () {
25
30
  //
26
31
  this.specification = this.normalize(specification);
27
32
  }
28
-
29
33
  /**
30
34
  * Normalize the specification.
31
35
  *
@@ -36,22 +40,19 @@ var Breakdancer = function () {
36
40
 
37
41
 
38
42
  _createClass(Breakdancer, [{
39
- key: 'normalize',
43
+ key: "normalize",
40
44
  value: function normalize(specification) {
41
45
  if (Array.isArray(specification)) return specification;
42
-
43
46
  return Object.keys(specification).reduce(function reduce(memo, key) {
44
- var breakpoint = specification[key];
45
-
46
- //
47
+ var breakpoint = specification[key]; //
47
48
  // If there is no name specified, use the key as name.
48
49
  //
50
+
49
51
  breakpoint.name = breakpoint.name || key;
50
52
  memo.push(breakpoint);
51
53
  return memo;
52
54
  }, []);
53
55
  }
54
-
55
56
  /**
56
57
  * Check if the setup has changed since we've last checked the real estate.
57
58
  *
@@ -61,14 +62,12 @@ var Breakdancer = function () {
61
62
  */
62
63
 
63
64
  }, {
64
- key: 'changed',
65
+ key: "changed",
65
66
  value: function changed(viewport) {
66
67
  var breakpoint = this.breakpoint;
67
68
  this.breakpoint = this.currently(viewport);
68
-
69
69
  return this.breakpoint !== breakpoint;
70
70
  }
71
-
72
71
  /**
73
72
  * Check if a given specification matches our current set resolution.
74
73
  *
@@ -79,15 +78,13 @@ var Breakdancer = function () {
79
78
  */
80
79
 
81
80
  }, {
82
- key: 'matches',
81
+ key: "matches",
83
82
  value: function matches(viewport, specification) {
84
83
  viewport = viewport || this.viewport();
85
-
86
84
  var matched = false;
87
85
 
88
86
  if ('height' in specification) {
89
87
  matched = viewport.height < specification.height;
90
-
91
88
  if (!matched) return matched;
92
89
  }
93
90
 
@@ -97,7 +94,6 @@ var Breakdancer = function () {
97
94
 
98
95
  return matched;
99
96
  }
100
-
101
97
  /**
102
98
  * Find out which breakpoint we're currently triggering.
103
99
  *
@@ -107,19 +103,17 @@ var Breakdancer = function () {
107
103
  */
108
104
 
109
105
  }, {
110
- key: 'currently',
106
+ key: "currently",
111
107
  value: function currently(viewport) {
112
108
  viewport = viewport || this.viewport();
113
109
 
114
110
  for (var i = 0, l = this.specification.length; i < l; i++) {
115
111
  var spec = this.specification[i];
116
-
117
112
  if (this.matches(viewport, spec)) return spec.name;
118
113
  }
119
114
 
120
115
  return 'unknown';
121
116
  }
122
-
123
117
  /**
124
118
  * Returns the difference between the current width and the given breakpoint. This
125
119
  * can be used to check if the window is "greater" than a breakpoint. If either the
@@ -134,18 +128,18 @@ var Breakdancer = function () {
134
128
  */
135
129
 
136
130
  }, {
137
- key: 'compare',
131
+ key: "compare",
138
132
  value: function compare(breakpoint, property) {
139
133
  var desiredSpec = this.specification.filter(function (spec) {
140
134
  return spec.name === breakpoint;
141
135
  })[0];
142
136
 
143
137
  if (!desiredSpec) {
144
- return new TypeError(breakpoint + ' is not part of the given specifications');
138
+ return new TypeError("".concat(breakpoint, " is not part of the given specifications"));
145
139
  }
146
140
 
147
141
  if (!desiredSpec[property]) {
148
- return new TypeError(breakpoint + '.' + property + ' is not part of the given specifications');
142
+ return new TypeError("".concat(breakpoint, ".").concat(property, " is not part of the given specifications"));
149
143
  }
150
144
 
151
145
  return this[property]() - desiredSpec[property];
package/lib/index.js CHANGED
@@ -1,26 +1,33 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.default = void 0;
6
7
 
7
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
8
+ var _breakdancer = _interopRequireDefault(require("./breakdancer"));
8
9
 
9
- var _breakdancer = require('./breakdancer');
10
+ var _propget = _interopRequireDefault(require("propget"));
10
11
 
11
- var _breakdancer2 = _interopRequireDefault(_breakdancer);
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
13
 
13
- var _propget = require('propget');
14
+ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
14
15
 
15
- var _propget2 = _interopRequireDefault(_propget);
16
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
16
17
 
17
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
18
19
 
19
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
20
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
21
+
22
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
23
+
24
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
25
+
26
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
20
27
 
21
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
28
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
22
29
 
23
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
30
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
24
31
 
25
32
  /**
26
33
  * Small fallback for when the `window` global is not accessible in a given
@@ -34,7 +41,6 @@ var win = typeof window !== 'undefined' ? window : {
34
41
  innerWidth: 1280,
35
42
  innerHeight: 768
36
43
  };
37
-
38
44
  /**
39
45
  * Breakdancer is a simple breakpoint utility.
40
46
  *
@@ -44,19 +50,21 @@ var win = typeof window !== 'undefined' ? window : {
44
50
  * @public
45
51
  */
46
52
 
47
- var WebDancer = function (_Breakdancer) {
53
+ var WebDancer =
54
+ /*#__PURE__*/
55
+ function (_Breakdancer) {
48
56
  _inherits(WebDancer, _Breakdancer);
49
57
 
50
58
  function WebDancer(specification, windows) {
51
- _classCallCheck(this, WebDancer);
59
+ var _this;
52
60
 
53
- var _this = _possibleConstructorReturn(this, (WebDancer.__proto__ || Object.getPrototypeOf(WebDancer)).call(this, specification));
61
+ _classCallCheck(this, WebDancer);
54
62
 
63
+ _this = _possibleConstructorReturn(this, _getPrototypeOf(WebDancer).call(this, specification));
55
64
  _this.window = windows || win;
56
65
  _this.breakpoint = _this.currently();
57
66
  return _this;
58
67
  }
59
-
60
68
  /**
61
69
  * Return the current view port.
62
70
  *
@@ -66,14 +74,13 @@ var WebDancer = function (_Breakdancer) {
66
74
 
67
75
 
68
76
  _createClass(WebDancer, [{
69
- key: 'viewport',
77
+ key: "viewport",
70
78
  value: function viewport() {
71
79
  return {
72
80
  height: this.height(),
73
81
  width: this.width()
74
82
  };
75
83
  }
76
-
77
84
  /**
78
85
  * Lookup the view port width.
79
86
  *
@@ -82,11 +89,10 @@ var WebDancer = function (_Breakdancer) {
82
89
  */
83
90
 
84
91
  }, {
85
- key: 'width',
92
+ key: "width",
86
93
  value: function width() {
87
- return (0, _propget2.default)(this.window, 'innerWidth') || (0, _propget2.default)(this.window, 'document.documentElement.clientWidth') || (0, _propget2.default)(this.window, 'document.body.clientWidth') || 0;
94
+ return (0, _propget.default)(this.window, 'innerWidth') || (0, _propget.default)(this.window, 'document.documentElement.clientWidth') || (0, _propget.default)(this.window, 'document.body.clientWidth') || 0;
88
95
  }
89
-
90
96
  /**
91
97
  * Lookup the view port height.
92
98
  *
@@ -95,13 +101,13 @@ var WebDancer = function (_Breakdancer) {
95
101
  */
96
102
 
97
103
  }, {
98
- key: 'height',
104
+ key: "height",
99
105
  value: function height() {
100
- return (0, _propget2.default)(this.window, 'innerHeight') || (0, _propget2.default)(this.window, 'document.documentElement.clientHeight') || (0, _propget2.default)(this.window, 'document.body.clientHeight') || 0;
106
+ return (0, _propget.default)(this.window, 'innerHeight') || (0, _propget.default)(this.window, 'document.documentElement.clientHeight') || (0, _propget.default)(this.window, 'document.body.clientHeight') || 0;
101
107
  }
102
108
  }]);
103
109
 
104
110
  return WebDancer;
105
- }(_breakdancer2.default);
111
+ }(_breakdancer.default);
106
112
 
107
113
  exports.default = WebDancer;
@@ -1,24 +1,33 @@
1
- 'use strict';
1
+ "use strict";
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.default = void 0;
6
7
 
7
- var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
8
+ var _breakdancer = _interopRequireDefault(require("./breakdancer"));
8
9
 
9
- var _breakdancer = require('./breakdancer');
10
-
11
- var _breakdancer2 = _interopRequireDefault(_breakdancer);
12
-
13
- var _reactNative = require('react-native');
10
+ var _reactNative = require("react-native");
14
11
 
15
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
13
 
14
+ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
15
+
17
16
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
18
17
 
19
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
18
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
19
+
20
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
21
+
22
+ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
23
+
24
+ function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
25
+
26
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
20
27
 
21
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
28
+ function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
29
+
30
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
22
31
 
23
32
  /**
24
33
  * Breakdancer is a simple breakpoint utility.
@@ -27,18 +36,20 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
27
36
  * @param {Object} specification Different breakpoints we need to know.
28
37
  * @public
29
38
  */
30
- var NativeDancer = function (_Breakdancer) {
39
+ var NativeDancer =
40
+ /*#__PURE__*/
41
+ function (_Breakdancer) {
31
42
  _inherits(NativeDancer, _Breakdancer);
32
43
 
33
44
  function NativeDancer(specification) {
34
- _classCallCheck(this, NativeDancer);
45
+ var _this;
35
46
 
36
- var _this = _possibleConstructorReturn(this, (NativeDancer.__proto__ || Object.getPrototypeOf(NativeDancer)).call(this, specification));
47
+ _classCallCheck(this, NativeDancer);
37
48
 
49
+ _this = _possibleConstructorReturn(this, _getPrototypeOf(NativeDancer).call(this, specification));
38
50
  _this.breakpoint = _this.currently();
39
51
  return _this;
40
52
  }
41
-
42
53
  /**
43
54
  * Return the current view port.
44
55
  *
@@ -48,11 +59,10 @@ var NativeDancer = function (_Breakdancer) {
48
59
 
49
60
 
50
61
  _createClass(NativeDancer, [{
51
- key: 'viewport',
62
+ key: "viewport",
52
63
  value: function viewport() {
53
64
  return _reactNative.Dimensions.get('window');
54
65
  }
55
-
56
66
  /**
57
67
  * Lookup the view port width.
58
68
  *
@@ -61,11 +71,10 @@ var NativeDancer = function (_Breakdancer) {
61
71
  */
62
72
 
63
73
  }, {
64
- key: 'width',
74
+ key: "width",
65
75
  value: function width() {
66
76
  return _reactNative.Dimensions.get('window').width;
67
77
  }
68
-
69
78
  /**
70
79
  * Lookup the view port height.
71
80
  *
@@ -74,13 +83,13 @@ var NativeDancer = function (_Breakdancer) {
74
83
  */
75
84
 
76
85
  }, {
77
- key: 'height',
86
+ key: "height",
78
87
  value: function height() {
79
88
  return _reactNative.Dimensions.get('window').height;
80
89
  }
81
90
  }]);
82
91
 
83
92
  return NativeDancer;
84
- }(_breakdancer2.default);
93
+ }(_breakdancer.default);
85
94
 
86
95
  exports.default = NativeDancer;
package/lib/test.js ADDED
@@ -0,0 +1,177 @@
1
+ "use strict";
2
+
3
+ var _index = _interopRequireDefault(require("./index"));
4
+
5
+ var _assume = _interopRequireDefault(require("assume"));
6
+
7
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
8
+
9
+ it('is exposed as a function', function () {
10
+ (0, _assume.default)(_index.default).is.a('function');
11
+ });
12
+ describe('breakdancer', function () {
13
+ var breakdancer;
14
+ var specification = [{
15
+ name: 'mobile',
16
+ width: 400,
17
+ height: 600
18
+ }, {
19
+ name: 'desktop',
20
+ width: 1024
21
+ }, {
22
+ name: 'whatever',
23
+ width: 1409
24
+ }];
25
+ beforeEach(function () {
26
+ breakdancer = new _index.default(specification);
27
+ });
28
+ it('safely works without existing windows object', function () {
29
+ breakdancer = new _index.default(specification, {});
30
+ (0, _assume.default)(breakdancer.height()).equals(0);
31
+ (0, _assume.default)(breakdancer.width()).equals(0);
32
+ });
33
+ describe('constructor', function () {
34
+ it('stores the specification as arrays', function () {
35
+ (0, _assume.default)(breakdancer.specification).is.a('array');
36
+ (0, _assume.default)(breakdancer.specification[0].name).equals('mobile');
37
+ });
38
+ it('sets the current breakpoint', function () {
39
+ (0, _assume.default)(breakdancer.breakpoint).is.a('string');
40
+ (0, _assume.default)(breakdancer.breakpoint).is.either(['mobile', 'desktop', 'whatever']);
41
+ });
42
+ it('can be supplied with a custom window object', function () {
43
+ var bd = new _index.default(specification, {
44
+ innerHeight: 10,
45
+ innerWidth: 10
46
+ });
47
+ (0, _assume.default)(bd.breakpoint).equals('mobile');
48
+ });
49
+ });
50
+ describe('#height', function () {
51
+ it('defaults to documentElement clientHeight on missing innerHeight', function () {
52
+ var bd = new _index.default(specification, {
53
+ document: {
54
+ documentElement: {
55
+ clientHeight: 1337,
56
+ clientWidth: 1337
57
+ }
58
+ }
59
+ });
60
+ (0, _assume.default)(bd.height()).equals(1337);
61
+ });
62
+ it('defaults to innerHeight', function () {
63
+ var bd = new _index.default(specification, {
64
+ innerHeight: 10,
65
+ innerWidth: 11,
66
+ document: {
67
+ documentElement: {
68
+ clientHeight: 1337,
69
+ clientWidth: 1338
70
+ }
71
+ }
72
+ });
73
+ (0, _assume.default)(bd.height()).equals(10);
74
+ });
75
+ });
76
+ describe('#width', function () {
77
+ it('defaults to documentElement clientHeight on missing innerWidth', function () {
78
+ var bd = new _index.default(specification, {
79
+ document: {
80
+ documentElement: {
81
+ clientHeight: 1337,
82
+ clientWidth: 1338
83
+ }
84
+ }
85
+ });
86
+ (0, _assume.default)(bd.width()).equals(1338);
87
+ });
88
+ it('defaults to innerWidth', function () {
89
+ var bd = new _index.default(specification, {
90
+ innerHeight: 10,
91
+ innerWidth: 11,
92
+ document: {
93
+ documentElement: {
94
+ clientHeight: 1337,
95
+ clientWidth: 1338
96
+ }
97
+ }
98
+ });
99
+ (0, _assume.default)(bd.width()).equals(11);
100
+ });
101
+ });
102
+ describe('#changed', function () {
103
+ it('returns a boolean if the breakpoint has changed', function () {
104
+ (0, _assume.default)(breakdancer.changed()).is.false();
105
+ (0, _assume.default)(breakdancer.changed()).is.false();
106
+ (0, _assume.default)(breakdancer.changed()).is.false();
107
+ var viewport = {
108
+ width: 200,
109
+ height: 500
110
+ };
111
+ (0, _assume.default)(breakdancer.changed(viewport)).is.true();
112
+ });
113
+ it('updates the .breakpoint', function () {
114
+ var viewport = {
115
+ width: 200,
116
+ height: 500
117
+ };
118
+ (0, _assume.default)(breakdancer.breakpoint).does.not.equal('mobile');
119
+ (0, _assume.default)(breakdancer.changed(viewport)).is.true();
120
+ (0, _assume.default)(breakdancer.breakpoint).equals('mobile');
121
+ });
122
+ });
123
+ describe('#currently', function () {
124
+ it('matches as desktop', function () {
125
+ var viewport = {
126
+ width: 800,
127
+ height: 600
128
+ };
129
+ (0, _assume.default)(breakdancer.currently(viewport)).equals('desktop');
130
+ });
131
+ it('matches as mobile', function () {
132
+ var viewport = {
133
+ width: 200,
134
+ height: 500
135
+ };
136
+ (0, _assume.default)(breakdancer.currently(viewport)).equals('mobile');
137
+ });
138
+ it('matches unknown', function () {
139
+ var viewport = {
140
+ width: 1800,
141
+ height: 1600
142
+ };
143
+ (0, _assume.default)(breakdancer.currently(viewport)).equals('unknown');
144
+ });
145
+ });
146
+ describe('#viewport', function () {
147
+ it('returns the width and height', function () {
148
+ var viewport = breakdancer.viewport();
149
+ (0, _assume.default)(viewport.width).is.above(0);
150
+ (0, _assume.default)(viewport.width).equals(breakdancer.width());
151
+ (0, _assume.default)(viewport.height).is.above(0);
152
+ (0, _assume.default)(viewport.height).equals(breakdancer.height());
153
+ });
154
+ });
155
+ describe('#compare', function () {
156
+ var bd = new _index.default(specification, {
157
+ innerWidth: 1234,
158
+ innerHeight: 1000,
159
+ document: {
160
+ documentElement: {
161
+ clientHeight: 1337,
162
+ clientWidth: 1338
163
+ }
164
+ }
165
+ });
166
+ it('should throw an error when looking at an unspecified breakpoint', function () {
167
+ (0, _assume.default)(bd.compare('hologram', 'width')).throws(TypeError);
168
+ });
169
+ it('should throw an error when the given dimension does not exist for the given breakpoint', function () {
170
+ (0, _assume.default)(bd.compare('whatever', 'height')).throws(TypeError);
171
+ });
172
+ it('should return the difference in width between the current and specified breakpoint', function () {
173
+ (0, _assume.default)(bd.compare('mobile', 'width')).equals(1234 - 400);
174
+ (0, _assume.default)(bd.compare('mobile', 'height')).equals(1000 - 600);
175
+ });
176
+ });
177
+ });
@@ -0,0 +1,105 @@
1
+ "use strict";
2
+
3
+ var _index = _interopRequireDefault(require("./index.native"));
4
+
5
+ var _assume = _interopRequireDefault(require("assume"));
6
+
7
+ var _reactNative = require("react-native");
8
+
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+
11
+ it('is exposed as a function', function () {
12
+ (0, _assume.default)(_index.default).is.a('function');
13
+ });
14
+ describe('nativeDancer', function () {
15
+ var nativeDancer;
16
+ var specification = [{
17
+ name: 'mobile',
18
+ width: 400,
19
+ height: 600
20
+ }, {
21
+ name: 'tablet',
22
+ width: 1024
23
+ }, {
24
+ name: 'whatever',
25
+ width: 1409
26
+ }];
27
+ beforeEach(function () {
28
+ nativeDancer = new _index.default(specification);
29
+ });
30
+ describe('constructor', function () {
31
+ it('stores the specification as arrays', function () {
32
+ (0, _assume.default)(nativeDancer.specification).is.a('array');
33
+ (0, _assume.default)(nativeDancer.specification[0].name).equals('mobile');
34
+ });
35
+ it('sets the current breakpoint', function () {
36
+ (0, _assume.default)(nativeDancer.breakpoint).is.a('string');
37
+ (0, _assume.default)(nativeDancer.breakpoint).is.either(['mobile', 'tablet', 'whatever']);
38
+ });
39
+ });
40
+ describe('#height', function () {
41
+ it('equals to device\'s height', function () {
42
+ var bd = new _index.default(specification);
43
+ (0, _assume.default)(bd.height()).equals(_reactNative.Dimensions.get('window').height);
44
+ });
45
+ });
46
+ describe('#width', function () {
47
+ it('equals to device\'s width', function () {
48
+ var bd = new _index.default(specification);
49
+ (0, _assume.default)(bd.width()).equals(_reactNative.Dimensions.get('window').width);
50
+ });
51
+ });
52
+ describe('#changed', function () {
53
+ it('returns a boolean if the breakpoint has changed', function () {
54
+ (0, _assume.default)(nativeDancer.changed()).is.false();
55
+ (0, _assume.default)(nativeDancer.changed()).is.false();
56
+ (0, _assume.default)(nativeDancer.changed()).is.false();
57
+ var viewport = {
58
+ width: 200,
59
+ height: 500
60
+ };
61
+ (0, _assume.default)(nativeDancer.changed(viewport)).is.true();
62
+ });
63
+ it('updates the .breakpoint', function () {
64
+ var viewport = {
65
+ width: 200,
66
+ height: 500
67
+ };
68
+ (0, _assume.default)(nativeDancer.breakpoint).does.not.equal('mobile');
69
+ (0, _assume.default)(nativeDancer.changed(viewport)).is.true();
70
+ (0, _assume.default)(nativeDancer.breakpoint).equals('mobile');
71
+ });
72
+ });
73
+ describe('#currently', function () {
74
+ it('matches as tablet', function () {
75
+ var viewport = {
76
+ width: 800,
77
+ height: 600
78
+ };
79
+ (0, _assume.default)(nativeDancer.currently(viewport)).equals('tablet');
80
+ });
81
+ it('matches as mobile', function () {
82
+ var viewport = {
83
+ width: 200,
84
+ height: 500
85
+ };
86
+ (0, _assume.default)(nativeDancer.currently(viewport)).equals('mobile');
87
+ });
88
+ it('matches unknown', function () {
89
+ var viewport = {
90
+ width: 1800,
91
+ height: 1600
92
+ };
93
+ (0, _assume.default)(nativeDancer.currently(viewport)).equals('unknown');
94
+ });
95
+ });
96
+ describe('#viewport', function () {
97
+ it('returns the width and height', function () {
98
+ var viewport = nativeDancer.viewport();
99
+ (0, _assume.default)(viewport.width).is.above(0);
100
+ (0, _assume.default)(viewport.width).equals(nativeDancer.width());
101
+ (0, _assume.default)(viewport.height).is.above(0);
102
+ (0, _assume.default)(viewport.height).equals(nativeDancer.height());
103
+ });
104
+ });
105
+ });
package/package.json CHANGED
@@ -1,13 +1,14 @@
1
1
  {
2
2
  "name": "breakdancer",
3
- "version": "3.0.1",
3
+ "version": "4.1.1",
4
4
  "description": "A breakpoint tracking utility",
5
5
  "main": "./lib",
6
- "browser": "./index",
6
+ "browser": "./lib",
7
+ "module": "./index",
7
8
  "scripts": {
8
9
  "lint": "eslint-godaddy *.js",
9
- "test:platforms": "mocha --require react-native-mock/mock.js --require babel-register ./test.js ./test.native.js",
10
- "build": "babel index.js index.native.js breakdancer.js -d ./lib",
10
+ "test:platforms": "mocha --require react-native-mock/mock.js --require @babel/register ./test.js ./test.native.js",
11
+ "build": "babel *.js -d ./lib",
11
12
  "prepublish": "npm run build",
12
13
  "pretest": "npm run lint",
13
14
  "test": "nyc --reporter=text --reporter=json-summary npm run test:platforms",
@@ -27,39 +28,34 @@
27
28
  ],
28
29
  "license": "MIT",
29
30
  "devDependencies": {
31
+ "@babel/cli": "^7.0.0",
32
+ "@babel/core": "^7.0.0",
33
+ "@babel/preset-env": "^7.0.0",
34
+ "@babel/register": "^7.0.0",
30
35
  "assume": "^1.5.2",
31
- "babel-cli": "^6.26.0",
32
- "babel-preset-es2015": "^6.24.0",
33
- "babel-register": "^6.26.0",
34
36
  "coveralls": "^3.0.0",
35
- "eslint": "^4.17.0",
37
+ "eslint": "^5.12.1",
36
38
  "eslint-config-godaddy": "^2.0.0",
37
39
  "eslint-plugin-json": "^1.2.0",
38
40
  "eslint-plugin-mocha": "^4.11.0",
39
41
  "mocha": "^5.0.0",
40
- "nyc": "^11.4.1",
42
+ "nyc": "^13.2.0",
41
43
  "pre-commit": "^1.2.2",
42
- "react": "^15.4.2",
43
- "react-dom": "^15.4.2",
44
- "react-native": "^0.42.3",
44
+ "react": ">=15",
45
+ "react-dom": ">=15",
46
+ "react-native": "^0.58.3",
45
47
  "react-native-mock": "^0.3.1"
46
48
  },
47
49
  "pre-commit": "lint, test",
48
- "browserify": {
49
- "transform": [
50
- "babelify"
51
- ]
52
- },
53
50
  "dependencies": {
54
51
  "propget": "^1.1.0"
55
52
  },
56
53
  "babel": {
57
54
  "presets": [
58
- "babel-preset-es2015"
55
+ "@babel/preset-env"
59
56
  ]
60
57
  },
61
58
  "peerDependencies": {
62
- "react": "^15.0.0 || ^16.0.0",
63
- "react-native": "^0.42.0 || ^0.52.0"
59
+ "react": ">=15"
64
60
  }
65
61
  }