diff --git a/lib/index.js b/lib/index.js index 2d7324e..b60873d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.reactDeviceBattery=t():e.reactDeviceBattery=t()}(this,function(){return function(e){function t(m){if(n[m])return n[m].exports;var r=n[m]={i:m,l:!1,exports:{}};return e[m].call(r.exports,r,r.exports,t),r.l=!0,r.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,m){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:m})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=0)}([function(e,t){throw new Error("Module build failed: SyntaxError: Unexpected token (27:15)\n\n  25 |  return parseFloat((battery.level * 100).toFixed(2));\n  26 |  }\n> 27 |  handleChange = () => {\n  |  ^\n  28 |  this.setBatteryState();\n  29 |  }\n  30 |  componentDidMount() {\n")}])}); +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("react")):"function"==typeof define&&define.amd?define(["react"],t):"object"==typeof exports?exports.reactDeviceBattery=t(require("react")):e.reactDeviceBattery=t(e.React)}(this,function(e){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,t),o.l=!0,o.exports}var n={};return t.m=e,t.c=n,t.i=function(e){return e},t.d=function(e,n,r){t.o(e,n)||Object.defineProperty(e,n,{configurable:!1,enumerable:!0,get:r})},t.n=function(e){var n=e&&e.__esModule?function(){return e.default}:function(){return e};return t.d(n,"a",n),n},t.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},t.p="",t(t.s=1)}([function(t,n){t.exports=e},function(e,t,n){"use strict";function r(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){if(!e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!t||"object"!=typeof t&&"function"!=typeof t?e:t}function a(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function, not "+typeof t);e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}),t&&(Object.setPrototypeOf?Object.setPrototypeOf(e,t):e.__proto__=t)}Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n\\u001b[22m\\u001b[39m\\u001b[90m 27 | \\u001b[39m handleChange \\u001b[33m=\\u001b[39m () \\u001b[33m=>\\u001b[39m {\\n \\u001b[90m | \\u001b[39m \\u001b[31m\\u001b[1m^\\u001b[22m\\u001b[39m\\n \\u001b[90m 28 | \\u001b[39m \\u001b[36mthis\\u001b[39m\\u001b[33m.\\u001b[39msetBatteryState()\\u001b[33m;\\u001b[39m\\n \\u001b[90m 29 | \\u001b[39m }\\n \\u001b[90m 30 | \\u001b[39m componentDidMount() {\\u001b[0m\\n\");\n\n/***/ })\n/******/ ]);\n});\n\n\n// WEBPACK FOOTER //\n// index.js"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// identity function for calling harmony imports with the correct context\n \t__webpack_require__.i = function(value) { return value; };\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 0);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap 4c6da86bcf96561de5d5"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack:///webpack/universalModuleDefinition","webpack:///index.js","webpack:///webpack/bootstrap 36551ef895fe110597c1","webpack:///external {\"root\":\"React\",\"commonjs2\":\"react\",\"commonjs\":\"react\",\"amd\":\"react\"}","webpack:///./src/index.js"],"names":["root","factory","exports","module","require","define","amd","this","__WEBPACK_EXTERNAL_MODULE_0__","modules","__webpack_require__","moduleId","installedModules","i","l","call","m","c","value","d","name","getter","o","Object","defineProperty","configurable","enumerable","get","n","__esModule","object","property","prototype","hasOwnProperty","p","s","_classCallCheck","instance","Constructor","TypeError","_possibleConstructorReturn","self","ReferenceError","_inherits","subClass","superClass","create","constructor","writable","setPrototypeOf","__proto__","_createClass","defineProperties","target","props","length","descriptor","key","protoProps","staticProps","_react","Battery","obj","_Component","_this","getPrototypeOf","state","battery","handleChange","bind","navigator","getBattery","mozBattery","_this2","then","percentage","getBatteryLevel","onChange","setState","parseFloat","level","toFixed","setBatteryState","_this3","isBatteryStatusAPISupported","addEventListener","_this4","removeEventListener","render","Component","default"],"mappings":"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","file":"index.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(\"react\"));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([\"react\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"reactDeviceBattery\"] = factory(require(\"react\"));\n\telse\n\t\troot[\"reactDeviceBattery\"] = factory(root[\"React\"]);\n})(this, function(__WEBPACK_EXTERNAL_MODULE_0__) {\nreturn \n\n\n// WEBPACK FOOTER //\n// webpack/universalModuleDefinition","(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory(require(\"react\"));\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([\"react\"], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"reactDeviceBattery\"] = factory(require(\"react\"));\n\telse\n\t\troot[\"reactDeviceBattery\"] = factory(root[\"React\"]);\n})(this, function(__WEBPACK_EXTERNAL_MODULE_0__) {\nreturn /******/ (function(modules) { // webpackBootstrap\n/******/ \t// The module cache\n/******/ \tvar installedModules = {};\n/******/\n/******/ \t// The require function\n/******/ \tfunction __webpack_require__(moduleId) {\n/******/\n/******/ \t\t// Check if module is in cache\n/******/ \t\tif(installedModules[moduleId]) {\n/******/ \t\t\treturn installedModules[moduleId].exports;\n/******/ \t\t}\n/******/ \t\t// Create a new module (and put it into the cache)\n/******/ \t\tvar module = installedModules[moduleId] = {\n/******/ \t\t\ti: moduleId,\n/******/ \t\t\tl: false,\n/******/ \t\t\texports: {}\n/******/ \t\t};\n/******/\n/******/ \t\t// Execute the module function\n/******/ \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n/******/\n/******/ \t\t// Flag the module as loaded\n/******/ \t\tmodule.l = true;\n/******/\n/******/ \t\t// Return the exports of the module\n/******/ \t\treturn module.exports;\n/******/ \t}\n/******/\n/******/\n/******/ \t// expose the modules object (__webpack_modules__)\n/******/ \t__webpack_require__.m = modules;\n/******/\n/******/ \t// expose the module cache\n/******/ \t__webpack_require__.c = installedModules;\n/******/\n/******/ \t// identity function for calling harmony imports with the correct context\n/******/ \t__webpack_require__.i = function(value) { return value; };\n/******/\n/******/ \t// define getter function for harmony exports\n/******/ \t__webpack_require__.d = function(exports, name, getter) {\n/******/ \t\tif(!__webpack_require__.o(exports, name)) {\n/******/ \t\t\tObject.defineProperty(exports, name, {\n/******/ \t\t\t\tconfigurable: false,\n/******/ \t\t\t\tenumerable: true,\n/******/ \t\t\t\tget: getter\n/******/ \t\t\t});\n/******/ \t\t}\n/******/ \t};\n/******/\n/******/ \t// getDefaultExport function for compatibility with non-harmony modules\n/******/ \t__webpack_require__.n = function(module) {\n/******/ \t\tvar getter = module && module.__esModule ?\n/******/ \t\t\tfunction getDefault() { return module['default']; } :\n/******/ \t\t\tfunction getModuleExports() { return module; };\n/******/ \t\t__webpack_require__.d(getter, 'a', getter);\n/******/ \t\treturn getter;\n/******/ \t};\n/******/\n/******/ \t// Object.prototype.hasOwnProperty.call\n/******/ \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n/******/\n/******/ \t// __webpack_public_path__\n/******/ \t__webpack_require__.p = \"\";\n/******/\n/******/ \t// Load entry module and return exports\n/******/ \treturn __webpack_require__(__webpack_require__.s = 1);\n/******/ })\n/************************************************************************/\n/******/ ([\n/* 0 */\n/***/ (function(module, exports) {\n\nmodule.exports = __WEBPACK_EXTERNAL_MODULE_0__;\n\n/***/ }),\n/* 1 */\n/***/ (function(module, exports, __webpack_require__) {\n\n\"use strict\";\n\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _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; }; }();\n\nvar _react = __webpack_require__(0);\n\nvar _react2 = _interopRequireDefault(_react);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _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; }\n\nfunction _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; }\n\nvar Battery = function (_Component) {\n _inherits(Battery, _Component);\n\n function Battery(props) {\n _classCallCheck(this, Battery);\n\n var _this = _possibleConstructorReturn(this, (Battery.__proto__ || Object.getPrototypeOf(Battery)).call(this, props));\n\n _this.state = {\n battery: null\n };\n _this.handleChange = _this.handleChange.bind(_this);\n return _this;\n }\n\n _createClass(Battery, [{\n key: 'isBatteryStatusAPISupported',\n value: function isBatteryStatusAPISupported() {\n if (navigator.getBattery || navigator.battery || navigator.mozBattery) {\n return true;\n }\n return false;\n }\n }, {\n key: 'setBatteryState',\n value: function setBatteryState() {\n var _this2 = this;\n\n navigator.getBattery().then(function (battery) {\n var percentage = _this2.getBatteryLevel(battery);\n _this2.props.onChange(percentage);\n _this2.setState({ battery: percentage });\n });\n }\n }, {\n key: 'getBatteryLevel',\n value: function getBatteryLevel(battery) {\n return parseFloat((battery.level * 100).toFixed(2));\n }\n }, {\n key: 'handleChange',\n value: function handleChange() {\n this.setBatteryState();\n }\n }, {\n key: 'componentDidMount',\n value: function componentDidMount() {\n var _this3 = this;\n\n if (this.isBatteryStatusAPISupported()) {\n this.setBatteryState();\n this.props.onChange(this.state.battery);\n navigator.getBattery().then(function (battery) {\n battery.addEventListener(\"levelchange\", _this3.handleChange);\n });\n }\n }\n }, {\n key: 'componentWillUnmount',\n value: function componentWillUnmount() {\n var _this4 = this;\n\n navigator.getBattery().then(function (battery) {\n battery.removeEventListener(\"levelchange\", _this4.handleChange);\n });\n }\n }, {\n key: 'render',\n value: function render() {\n return this.props.render(this.state);\n }\n }]);\n\n return Battery;\n}(_react.Component);\n\nif (false) {\n Battery.defaultProps = {\n render: function render() {\n return null;\n },\n onChange: function onChange() {}\n };\n}\n\nexports.default = Battery;\n\n/***/ })\n/******/ ]);\n});\n\n\n// WEBPACK FOOTER //\n// index.js"," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// identity function for calling harmony imports with the correct context\n \t__webpack_require__.i = function(value) { return value; };\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 1);\n\n\n\n// WEBPACK FOOTER //\n// webpack/bootstrap 36551ef895fe110597c1","module.exports = __WEBPACK_EXTERNAL_MODULE_0__;\n\n\n//////////////////\n// WEBPACK FOOTER\n// external {\"root\":\"React\",\"commonjs2\":\"react\",\"commonjs\":\"react\",\"amd\":\"react\"}\n// module id = 0\n// module chunks = 0","import React, {Component} from 'react';\nimport PropTypes from 'prop-types';\n\nclass Battery extends Component {\n constructor(props) {\n super(props);\n this.state = {\n battery: null\n };\n this.handleChange = this.handleChange.bind(this);\n }\n isBatteryStatusAPISupported() {\n if (navigator.getBattery || navigator.battery || navigator.mozBattery) {\n return true;\n }\n return false;\n }\n setBatteryState() {\n navigator.getBattery().then( battery => {\n const percentage = this.getBatteryLevel(battery);\n this.props.onChange(percentage);\n this.setState({ battery: percentage });\n });\n }\n getBatteryLevel(battery) {\n return parseFloat((battery.level * 100).toFixed(2));\n }\n handleChange() {\n this.setBatteryState();\n }\n componentDidMount() {\n if (this.isBatteryStatusAPISupported()) {\n this.setBatteryState();\n this.props.onChange(this.state.battery);\n navigator.getBattery().then(battery => {\n battery.addEventListener(\"levelchange\", this.handleChange); \n });\n }\n }\n componentWillUnmount() {\n navigator.getBattery().then(battery => {\n battery.removeEventListener(\"levelchange\", this.handleChange);\n });\n }\n render() {\n return this.props.render(this.state);\n }\n}\nif (process.env.NODE_ENV !== \"production\") {\n Battery.defaultProps = {\n render: () => null,\n onChange: () => { }\n };\n Battery.propTypes = {\n render: PropTypes.func.isRequired,\n onChange: PropTypes.func\n };\n}\n\nexport default Battery;\n\n\n// WEBPACK FOOTER //\n// ./src/index.js"],"sourceRoot":""} \ No newline at end of file