react-screen-wake-lock
Advanced tools
Comparing version 3.0.0 to 3.0.1
@@ -1,2 +0,2 @@ | ||
import*as e from"react";var r="production"===process.env.NODE_ENV;function n(e,n){if(!r){if(e)return;var t="Warning: "+n;"undefined"!=typeof console&&console.warn(t);try{throw Error(t)}catch(e){}}}var t=function(r){var t=void 0===r?{}:r,o=t.onError,u=t.onRequest,c=t.onRelease,s=e.useState(),i=s[0],a=s[1],l=e.useRef(null),f="undefined"!=typeof window&&"wakeLock"in navigator,v=e.useCallback(function(e){void 0===e&&(e="screen");try{var r=null!=l.current;if(!f||r)return n(!f,"Calling the `request` function has no effect, Wake Lock Screen API isn't supported"),n(r,"Calling `request` multiple times without `release` has no effect"),Promise.resolve();var t=function(r,n){try{var t=Promise.resolve(navigator.wakeLock.request(e)).then(function(e){l.current=e,l.current.onrelease=function(e){a(l.current&&l.current.released||!0),c&&c(e),l.current=null},u&&u(),a(l.current&&l.current.released||!1)})}catch(e){return n(e)}return t&&t.then?t.then(void 0,n):t}(0,function(e){o&&o(e)});return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},[f,u,o,c]),d=e.useCallback(function(){try{var e=null==l.current;return!f||e?(n(!f,"Calling the `release` function has no effect, Wake Lock Screen API isn't supported"),n(e,"Calling `release` before `request` has no effect."),Promise.resolve()):Promise.resolve(l.current?Promise.resolve(l.current.release()).then(function(e){}):void 0)}catch(e){return Promise.reject(e)}},[f]);return{isSupported:f,request:v,released:i,release:d,type:l.current&&l.current.type||void 0}};export{t as useWakeLock}; | ||
import*as e from"react";var r=function(e){return console.warn("[react-screen-wake-lock]: "+e)},n=function(n){var t=void 0===n?{}:n,o=t.onError,u=t.onRequest,c=t.onRelease,s=e.useState(),a=s[0],i=s[1],l=e.useRef(null),f="undefined"!=typeof window&&"wakeLock"in navigator,v=e.useCallback(function(e){void 0===e&&(e="screen");try{var n=null!=l.current;if(!f)return Promise.resolve(r("Calling the `request` function has no effect, Wake Lock Screen API isn't supported"));if(n)return Promise.resolve(r("Calling `request` multiple times without `release` has no effect"));var t=function(r,n){try{var t=Promise.resolve(navigator.wakeLock.request(e)).then(function(e){l.current=e,l.current.onrelease=function(e){i(l.current&&l.current.released||!0),c&&c(e),l.current=null},u&&u(),i(l.current&&l.current.released||!1)})}catch(e){return n(e)}return t&&t.then?t.then(void 0,n):t}(0,function(e){o&&o(e)});return Promise.resolve(t&&t.then?t.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},[f,u,o,c]),h=e.useCallback(function(){try{return Promise.resolve(f?null==l.current?r("Calling `release` before `request` has no effect."):l.current?Promise.resolve(l.current.release()).then(function(e){}):void 0:r("Calling the `release` function has no effect, Wake Lock Screen API isn't supported"))}catch(e){return Promise.reject(e)}},[f]);return{isSupported:f,request:v,released:a,release:h,type:l.current&&l.current.type||void 0}};export{n as useWakeLock}; | ||
//# sourceMappingURL=react-screen-wake-lock.esm.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],r):r((e||self).reactScreenWakeLock={},e.react)}(this,function(e,r){function t(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach(function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}}),r.default=e,r}var n=/*#__PURE__*/t(r);e.useWakeLock=function(e){var r=void 0===e?{}:e,t=r.onError,o=r.onRequest,u=r.onRelease,c=n.useState(),i=c[0],a=c[1],s=n.useRef(null),l="undefined"!=typeof window&&"wakeLock"in navigator,f=n.useCallback(function(e){void 0===e&&(e="screen");try{if(!l||null!=s.current)return Promise.resolve();var r=function(r,t){try{var n=Promise.resolve(navigator.wakeLock.request(e)).then(function(e){s.current=e,s.current.onrelease=function(e){a(s.current&&s.current.released||!0),u&&u(e),s.current=null},o&&o(),a(s.current&&s.current.released||!1)})}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}(0,function(e){t&&t(e)});return Promise.resolve(r&&r.then?r.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},[l,o,t,u]),d=n.useCallback(function(){try{return l&&null!=s.current?Promise.resolve(s.current?Promise.resolve(s.current.release()).then(function(e){}):void 0):Promise.resolve()}catch(e){return Promise.reject(e)}},[l]);return{isSupported:l,request:f,released:i,release:d,type:s.current&&s.current.type||void 0}}}); | ||
!function(e,r){"object"==typeof exports&&"undefined"!=typeof module?r(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],r):r((e||self).reactScreenWakeLock={},e.react)}(this,function(e,r){function t(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach(function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}}),r.default=e,r}var n=/*#__PURE__*/t(r),o=function(e){return console.warn("[react-screen-wake-lock]: "+e)};e.useWakeLock=function(e){var r=void 0===e?{}:e,t=r.onError,u=r.onRequest,c=r.onRelease,i=n.useState(),a=i[0],s=i[1],l=n.useRef(null),f="undefined"!=typeof window&&"wakeLock"in navigator,d=n.useCallback(function(e){void 0===e&&(e="screen");try{var r=null!=l.current;if(!f)return Promise.resolve(o("Calling the `request` function has no effect, Wake Lock Screen API isn't supported"));if(r)return Promise.resolve(o("Calling `request` multiple times without `release` has no effect"));var n=function(r,t){try{var n=Promise.resolve(navigator.wakeLock.request(e)).then(function(e){l.current=e,l.current.onrelease=function(e){s(l.current&&l.current.released||!0),c&&c(e),l.current=null},u&&u(),s(l.current&&l.current.released||!1)})}catch(e){return t(e)}return n&&n.then?n.then(void 0,t):n}(0,function(e){t&&t(e)});return Promise.resolve(n&&n.then?n.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},[f,u,t,c]),v=n.useCallback(function(){try{return Promise.resolve(f?null==l.current?o("Calling `release` before `request` has no effect."):l.current?Promise.resolve(l.current.release()).then(function(e){}):void 0:o("Calling the `release` function has no effect, Wake Lock Screen API isn't supported"))}catch(e){return Promise.reject(e)}},[f]);return{isSupported:f,request:d,released:a,release:v,type:l.current&&l.current.type||void 0}}}); | ||
//# sourceMappingURL=react-screen-wake-lock.umd.js.map |
{ | ||
"name": "react-screen-wake-lock", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "React implementation of the Screen Wake Lock API. It provides a way to prevent devices from dimming or locking the screen when an application needs to keep running.", | ||
@@ -43,3 +43,5 @@ "author": { | ||
"scripts": { | ||
"postinstall": "yarn husky install", | ||
"_postinstall": "husky install", | ||
"prepack": "pinst --disable", | ||
"postpack": "pinst --enable", | ||
"start": "microbundle watch", | ||
@@ -57,5 +59,5 @@ "prebuild": "rimraf dist", | ||
"devDependencies": { | ||
"@testing-library/dom": "^7.30.1", | ||
"@testing-library/react": "^11.2.5", | ||
"@testing-library/react-hooks": "^5.1.0", | ||
"@testing-library/dom": "^8.18.1", | ||
"@testing-library/react": "^13.4.0", | ||
"@testing-library/react-hooks": "^8.0.1", | ||
"@types/dom-screen-wake-lock": "^1.0.0", | ||
@@ -70,3 +72,4 @@ "@types/jest": "^29.1.1", | ||
"eslint-plugin-react-hooks": "^4.2.0", | ||
"eslint-plugin-testing-library": "^5.7.0", | ||
"eslint-plugin-testing-library": "^5.7.2", | ||
"husky": "^8.0.1", | ||
"jest": "^29.1.2", | ||
@@ -78,2 +81,3 @@ "jest-environment-jsdom": "^29.1.2", | ||
"npm-run-all": "^4.1.5", | ||
"pinst": "^3.0.0", | ||
"prettier": "^2.2.1", | ||
@@ -84,3 +88,2 @@ "react": "18.2.0", | ||
"rimraf": "^3.0.2", | ||
"tiny-warning": "^1.0.3", | ||
"ts-jest": "^29.0.3", | ||
@@ -94,5 +97,3 @@ "ts-node": "^10.9.1", | ||
}, | ||
"dependencies": { | ||
"husky": "^8.0.1" | ||
} | ||
"dependencies": {} | ||
} |
@@ -19,5 +19,6 @@ <div align="center"><h1>🌗 react-screen-wake-lock</h1></div> | ||
- 🌐 Follows the **[W3C Screen Wake Lock API specifications](https://w3c.github.io/screen-wake-lock/)** | ||
- 🎣 **Easy to use** - just one react hook `useWakeLock` | ||
- 🪶 **Lightweight** - _less than **[370b](https://bundlephobia.com/result?p=react-screen-wake-lock)**_ | ||
- 🔌 **Easily integration** - _it works without additional configuration (React, remix, Next.js...)_ | ||
- 🪝 **Easy to use** - Just one react hook `useWakeLock` | ||
- 🪶 **Lightweight & 0 Dependency** - _Less than **[650b](https://bundlephobia.com/result?p=react-screen-wake-lock)**_ | ||
- 🔌 **Easily integration** - _It works without additional configuration (React, remix, Next.js...)_ | ||
- 🧪 **Ready to test** - Mocks the Screen Wake Lock with [Jest](https://github.com/jorisre/jest-wake-lock-mock#readme) | ||
- ⚠️ **Browser Support** - [Screen Wake Lock API](https://caniuse.com/wake-lock) | ||
@@ -24,0 +25,0 @@ |
import * as React from 'react'; | ||
import warning from 'tiny-warning'; | ||
const warn = (content: string) => | ||
console.warn('[react-screen-wake-lock]: ' + content); | ||
export interface WakeLockOptions { | ||
@@ -24,12 +26,11 @@ onError?: (error: Error) => void; | ||
const isWakeLockAlreadyDefined = wakeLock.current != null; | ||
if (!isSupported || isWakeLockAlreadyDefined) { | ||
warning( | ||
!isSupported, | ||
if (!isSupported) { | ||
return warn( | ||
"Calling the `request` function has no effect, Wake Lock Screen API isn't supported" | ||
); | ||
warning( | ||
isWakeLockAlreadyDefined, | ||
} | ||
if (isWakeLockAlreadyDefined) { | ||
return warn( | ||
'Calling `request` multiple times without `release` has no effect' | ||
); | ||
return; | ||
} | ||
@@ -58,13 +59,10 @@ | ||
const isWakeLockUndefined = wakeLock.current == null; | ||
if (!isSupported || isWakeLockUndefined) { | ||
warning( | ||
!isSupported, | ||
if (!isSupported) { | ||
return warn( | ||
"Calling the `release` function has no effect, Wake Lock Screen API isn't supported" | ||
); | ||
} | ||
warning( | ||
isWakeLockUndefined, | ||
'Calling `release` before `request` has no effect.' | ||
); | ||
return; | ||
if (isWakeLockUndefined) { | ||
return warn('Calling `release` before `request` has no effect.'); | ||
} | ||
@@ -71,0 +69,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
Install scripts
Supply chain riskInstall scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
28682
1
109
0
0
29
- Removedhusky@^8.0.1
- Removedhusky@8.0.3(transitive)