Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

use-media

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-media - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

7

CHANGELOG.md

@@ -0,1 +1,8 @@

# [1.2.0](https://github.com/streamich/use-media/compare/v1.1.0...v1.2.0) (2019-02-18)
### Features
* transpile down to ES5 ([c389ab8](https://github.com/streamich/use-media/commit/c389ab8))
# [1.1.0](https://github.com/streamich/use-media/compare/v1.0.0...v1.1.0) (2019-02-10)

@@ -2,0 +9,0 @@

36

lib/index.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const React = require("react");
const { useState, useEffect } = React;
const camelToHyphen = (str) => str.replace(/[A-Z]/g, m => `-${m.toLowerCase()}`).toLowerCase();
const objectToString = (query) => {
var React = require("react");
var useState = React.useState, useEffect = React.useEffect;
var camelToHyphen = function (str) {
return str.replace(/[A-Z]/g, function (m) { return "-" + m.toLowerCase(); }).toLowerCase();
};
var objectToString = function (query) {
if (typeof query === 'string')
return query;
return Object.entries(query)
.map(([feature, value]) => {
.map(function (_a) {
var feature = _a[0], value = _a[1];
feature = camelToHyphen(feature);
if (typeof value === 'boolean') {
return value ? feature : `not ${feature}`;
return value ? feature : "not " + feature;
}
if (typeof value === 'number' && /[height|width]$/.test(feature)) {
value = `${value}px`;
value = value + "px";
}
return `(${feature}: ${value})`;
return "(" + feature + ": " + value + ")";
})
.join(' and ');
};
exports.useMedia = (rawQuery, defaultState = false) => {
const [state, setState] = useState(defaultState);
const query = objectToString(rawQuery);
useEffect(() => {
let mounted = true;
const mql = window.matchMedia(query);
const onChange = () => {
exports.useMedia = function (rawQuery, defaultState) {
if (defaultState === void 0) { defaultState = false; }
var _a = useState(defaultState), state = _a[0], setState = _a[1];
var query = objectToString(rawQuery);
useEffect(function () {
var mounted = true;
var mql = window.matchMedia(query);
var onChange = function () {
if (!mounted)

@@ -35,3 +39,3 @@ return;

setState(mql.matches);
return () => {
return function () {
mounted = false;

@@ -38,0 +42,0 @@ mql.removeListener(onChange);

{
"name": "use-media",
"version": "1.1.0",
"version": "1.2.0",
"description": "useMedia React hook",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc