This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { createContext, useState } from 'react'; | |
import PropTypes from 'prop-types'; | |
const mq = 'screen and (max-width: 671px)'; | |
const ResponsiveContext = createContext(); | |
const ResponsiveContextProvider = ({ children }) => { | |
const [isMobile, setIsMobile] = useState(window.matchMedia(mq).matches); | |
matchMedia(mq).addEventListener('change', e => setIsMobile(e.matches)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const trimAnything = (str, trimChar, opts = { start: false, end: true }) => { | |
if (str.length > 1 || opts.allowEmpty) { | |
let pattern; | |
if (opts.start && !opts.end) { | |
pattern = `^\\${trimChar}+`; | |
} else if (!opts.start && opts.end) { | |
pattern = `\\${trimChar}+$`; | |
} else { | |
pattern = `^\\${trimChar}+|\\${trimChar}+$`; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const net = require('net'); | |
const getOpenPort = async (port, maxPort) => { | |
const isPortAvail = (currentPort) => new Promise((resolve, reject) => { | |
const tester = net.createServer() | |
.once('error', (err) => (err.code === 'EADDRINUSE' ? resolve(false) : reject(err))) | |
.once('listening', () => tester.once('close', () => resolve(true)).close()) | |
.listen(currentPort); | |
}); | |
OlderNewer