breakdancer
Advanced tools
Comparing version 1.1.1 to 1.1.2
# CHANGELOG | ||
### 1.1.2 | ||
- [#13] Use separate file for `Breakdancer` base class, allows React Native to resolve `Breakdancer`. | ||
## 1.1.1 | ||
- Removed `react-native` from peerDependencies. See #11 #12 | ||
- [#11], [#12] Removed `react-native` from peerDependencies. |
108
index.js
@@ -0,1 +1,2 @@ | ||
import Breakdancer from './breakdancer'; | ||
import get from 'propget'; | ||
@@ -24,11 +25,7 @@ | ||
*/ | ||
export default class Breakdancer { | ||
export default class WebDancer extends Breakdancer { | ||
constructor(specification, windows) { | ||
super(specification); | ||
this.window = windows || win; | ||
// | ||
// Setup our default values after the window has been set so we don't have | ||
// any undefined references. | ||
// | ||
this.specification = this.normalize(specification); | ||
this.breakpoint = this.currently(); | ||
@@ -38,21 +35,12 @@ } | ||
/** | ||
* Normalize the specification. | ||
* Return the current view port. | ||
* | ||
* @param {Array|Object} specification Different breakpoints we need to know. | ||
* @returns {Array} List of media query specifications | ||
* @private | ||
* @returns {Object} viewport | ||
* @public | ||
*/ | ||
normalize(specification) { | ||
if (Array.isArray(specification)) return specification; | ||
return Object.keys(specification).reduce(function reduce(memo, key) { | ||
var breakpoint = specification[key]; | ||
// | ||
// If there is no name specified, use the key as name. | ||
// | ||
breakpoint.name = breakpoint.name || key; | ||
memo.push(breakpoint); | ||
return memo; | ||
}, []); | ||
viewport() { | ||
return { | ||
height: this.height(), | ||
width: this.width() | ||
}; | ||
} | ||
@@ -85,74 +73,2 @@ | ||
} | ||
/** | ||
* Check if the setup has changed since we've last checked the real estate. | ||
* | ||
* @param {Object} viewport The view port specification. | ||
* @returns {Boolean} True if the breakpoint for the viewport has changed. | ||
* @public | ||
*/ | ||
changed(viewport) { | ||
var breakpoint = this.breakpoint; | ||
this.breakpoint = this.currently(viewport); | ||
return this.breakpoint !== breakpoint; | ||
} | ||
/** | ||
* Return the current view port. | ||
* | ||
* @returns {Object} viewport | ||
* @public | ||
*/ | ||
viewport() { | ||
return { | ||
height: this.height(), | ||
width: this.width() | ||
}; | ||
} | ||
/** | ||
* Check if a given specification matches our current set resolution. | ||
* | ||
* @param {Object} viewport The view port specification. | ||
* @param {Object} specification The supplied specification. | ||
* @returns {Boolean} True if viewport fits into the specification. | ||
* @private | ||
*/ | ||
matches(viewport, specification) { | ||
viewport = viewport || this.viewport(); | ||
let matched = false; | ||
if ('height' in specification) { | ||
matched = viewport.height < specification.height; | ||
if (!matched) return matched; | ||
} | ||
if ('width' in specification) { | ||
matched = viewport.width < specification.width; | ||
} | ||
return matched; | ||
} | ||
/** | ||
* Find out which breakpoint we're currently triggering. | ||
* | ||
* @param {Object} viewport The view port specification. | ||
* @returns {String} The current breakpoint that we got triggered. | ||
* @public | ||
*/ | ||
currently(viewport) { | ||
viewport = viewport || this.viewport(); | ||
for (var i = 0, l = this.specification.length; i < l; i++) { | ||
var spec = this.specification[i]; | ||
if (this.matches(viewport, spec)) return spec.name; | ||
} | ||
return 'unknown'; | ||
} | ||
} |
@@ -1,5 +0,18 @@ | ||
import Breakdancer from './'; | ||
import Breakdancer from './breakdancer'; | ||
import { Dimensions } from 'react-native'; | ||
/** | ||
* Breakdancer is a simple breakpoint utility. | ||
* | ||
* @constructor | ||
* @param {Object} specification Different breakpoints we need to know. | ||
* @public | ||
*/ | ||
export default class NativeDancer extends Breakdancer { | ||
constructor(specification) { | ||
super(specification); | ||
this.breakpoint = this.currently(); | ||
} | ||
/** | ||
@@ -6,0 +19,0 @@ * Return the current view port. |
146
lib/index.js
@@ -9,2 +9,6 @@ 'use strict'; | ||
var _breakdancer = require('./breakdancer'); | ||
var _breakdancer2 = _interopRequireDefault(_breakdancer); | ||
var _propget = require('propget'); | ||
@@ -18,2 +22,6 @@ | ||
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; } | ||
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; } | ||
/** | ||
@@ -41,40 +49,30 @@ * Small fallback for when the `window` global is not accessible in a given | ||
var Breakdancer = function () { | ||
function Breakdancer(specification, windows) { | ||
_classCallCheck(this, Breakdancer); | ||
var WebDancer = function (_Breakdancer) { | ||
_inherits(WebDancer, _Breakdancer); | ||
this.window = windows || win; | ||
function WebDancer(specification, windows) { | ||
_classCallCheck(this, WebDancer); | ||
// | ||
// Setup our default values after the window has been set so we don't have | ||
// any undefined references. | ||
// | ||
this.specification = this.normalize(specification); | ||
this.breakpoint = this.currently(); | ||
var _this = _possibleConstructorReturn(this, (WebDancer.__proto__ || Object.getPrototypeOf(WebDancer)).call(this, specification)); | ||
_this.window = windows || win; | ||
_this.breakpoint = _this.currently(); | ||
return _this; | ||
} | ||
/** | ||
* Normalize the specification. | ||
* Return the current view port. | ||
* | ||
* @param {Array|Object} specification Different breakpoints we need to know. | ||
* @returns {Array} List of media query specifications | ||
* @private | ||
* @returns {Object} viewport | ||
* @public | ||
*/ | ||
_createClass(Breakdancer, [{ | ||
key: 'normalize', | ||
value: function normalize(specification) { | ||
if (Array.isArray(specification)) return specification; | ||
return Object.keys(specification).reduce(function reduce(memo, key) { | ||
var breakpoint = specification[key]; | ||
// | ||
// If there is no name specified, use the key as name. | ||
// | ||
breakpoint.name = breakpoint.name || key; | ||
memo.push(breakpoint); | ||
return memo; | ||
}, []); | ||
_createClass(WebDancer, [{ | ||
key: 'viewport', | ||
value: function viewport() { | ||
return { | ||
height: this.height(), | ||
width: this.width() | ||
}; | ||
} | ||
@@ -107,91 +105,7 @@ | ||
} | ||
/** | ||
* Check if the setup has changed since we've last checked the real estate. | ||
* | ||
* @param {Object} viewport The view port specification. | ||
* @returns {Boolean} True if the breakpoint for the viewport has changed. | ||
* @public | ||
*/ | ||
}, { | ||
key: 'changed', | ||
value: function changed(viewport) { | ||
var breakpoint = this.breakpoint; | ||
this.breakpoint = this.currently(viewport); | ||
return this.breakpoint !== breakpoint; | ||
} | ||
/** | ||
* Return the current view port. | ||
* | ||
* @returns {Object} viewport | ||
* @public | ||
*/ | ||
}, { | ||
key: 'viewport', | ||
value: function viewport() { | ||
return { | ||
height: this.height(), | ||
width: this.width() | ||
}; | ||
} | ||
/** | ||
* Check if a given specification matches our current set resolution. | ||
* | ||
* @param {Object} viewport The view port specification. | ||
* @param {Object} specification The supplied specification. | ||
* @returns {Boolean} True if viewport fits into the specification. | ||
* @private | ||
*/ | ||
}, { | ||
key: 'matches', | ||
value: function matches(viewport, specification) { | ||
viewport = viewport || this.viewport(); | ||
var matched = false; | ||
if ('height' in specification) { | ||
matched = viewport.height < specification.height; | ||
if (!matched) return matched; | ||
} | ||
if ('width' in specification) { | ||
matched = viewport.width < specification.width; | ||
} | ||
return matched; | ||
} | ||
/** | ||
* Find out which breakpoint we're currently triggering. | ||
* | ||
* @param {Object} viewport The view port specification. | ||
* @returns {String} The current breakpoint that we got triggered. | ||
* @public | ||
*/ | ||
}, { | ||
key: 'currently', | ||
value: function currently(viewport) { | ||
viewport = viewport || this.viewport(); | ||
for (var i = 0, l = this.specification.length; i < l; i++) { | ||
var spec = this.specification[i]; | ||
if (this.matches(viewport, spec)) return spec.name; | ||
} | ||
return 'unknown'; | ||
} | ||
}]); | ||
return Breakdancer; | ||
}(); | ||
return WebDancer; | ||
}(_breakdancer2.default); | ||
exports.default = Breakdancer; | ||
exports.default = WebDancer; |
{ | ||
"name": "breakdancer", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "A breakpoint tracking utility", | ||
@@ -11,3 +11,3 @@ "main": "./lib", | ||
"test:native": "mocha --require react-native-mock/mock.js --compilers js:babel-register ./test.native.js", | ||
"build": "babel index.js -d ./lib", | ||
"build": "babel index.js breakdancer.js -d ./lib", | ||
"prepublish": "npm run build", | ||
@@ -14,0 +14,0 @@ "pretest": "npm run lint", |
@@ -1,2 +0,2 @@ | ||
import Breakdancer from './'; | ||
import Breakdancer from './index'; | ||
import assume from 'assume'; | ||
@@ -3,0 +3,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27944
13
597
1