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 { join } from 'path'; | |
export const TEMP_DIRECTORY = join(__dirname, '..', '.temp'); |
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 function cors(fn: NextApiHandler, methods = ['GET']) { | |
return async (request: NextApiRequest, response: NextApiResponse) => { | |
const allowedMethods = [...methods, 'OPTIONS'].join(','); | |
response.setHeader('Access-Control-Allow-Credentials', 'true'); | |
response.setHeader('Access-Control-Allow-Origin', '*'); | |
response.setHeader('Access-Control-Allow-Methods', allowedMethods); | |
response.setHeader( | |
'Access-Control-Allow-Headers', | |
'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Authorization, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version', |
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 function slugify(input = '') { | |
return removeAccents(input) | |
.replace(/[\u0300-\u036f]/g, '') | |
.replace(/[()]/g, '') | |
.replace(/ /g, '-') | |
.replace(/[|^{}%"<>\\`]/g, '') | |
.toLowerCase(); | |
} |
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
/** | |
* Remove accents | |
*/ | |
export function removeAccents(input: string) { | |
const removalMap = { | |
A: /[AⒶAÀÁÂẦẤẪẨÃĀĂẰẮẴẲȦǠÄǞẢÅǺǍȀȂẠẬẶḀĄ]/g, | |
AA: /[Ꜳ]/g, | |
AE: /[ÆǼǢ]/g, | |
AO: /[Ꜵ]/g, | |
AU: /[Ꜷ]/g, |
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
// Available variables: | |
// - Machine | |
// - interpret | |
// - assign | |
// - send | |
// - sendParent | |
// - spawn | |
// - raise | |
// - actions | |
// - XState (all XState exports) |
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
interface IOptions { | |
predicate: (child: React.ReactChild) => boolean; | |
props: { [key: string]: any }; | |
} | |
function mapReactChildrenRecursively(children: React.ReactNode, options: IOptions): React.ReactNode { | |
if (!options.predicate || !options.props) { | |
return children; | |
} |
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
function validateURI(input: string): boolean { | |
let isValid = false; | |
if (input && input.indexOf(':') > -1) { | |
const [key, type, id] = input.split(':'); | |
if (key && type && id && id.length === 22) { | |
isValid = true; | |
} | |
} |
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 React = require('react'); | |
const PropTypes = require('prop-types'); | |
class Component extends React.Component { | |
render() { | |
return React.createElement('h1', {}, 'Component!'); | |
} | |
} | |
Component.propTypes = { |
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
function comparator(data: Object, nextData: Object): Object { | |
return { | |
changedFrom(key: string, actual: 'string', prev: string): boolean { | |
return data[key] === prev && nextData[key] === actual; | |
}, | |
changedTo(key: string, actual: 'string'): boolean { | |
return data[key] !== actual && nextData[key] === actual; | |
}, | |
changed(key: string): boolean { | |
return data[key] !== nextData[key]; |
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
function randomID(size = 6) { | |
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | |
let text = ''; | |
for (let i = 0; i < size; i++) { | |
text += possible.charAt(Math.floor(Math.random() * possible.length)); | |
} | |
return text; | |
} |
NewerOlder