View slugify.ts
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(); | |
} |
View removeAccents.ts
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, |
View machine.js
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) |
View mapReactChildrenRecursively.ts
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; | |
} |
View validate-spotify-uri.ts
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; | |
} | |
} |
View getTypeFromPropTypes.jsx
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 = { |
View comparator.js
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]; |
View randomID.js
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; | |
} |
View HtmlWrapper.js
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
@@ -0,0 +1,21 @@ | |
import React from 'react'; | |
import PropTypes from 'prop-types'; | |
import ReactHtmlParser from 'react-html-parser'; | |
export default class HtmlWrapper extends React.Component { | |
static propTypes = { | |
element: PropTypes.oneOfType([ | |
PropTypes.string, | |
PropTypes.object, |
View measurements.js
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 measurementsData = require('./measurements.json'); | |
const newData = measurementsData.table.measurements.reduce((acc, val, idx) => { | |
acc.labels.push(val.name); | |
val.sizes.forEach((d, i) => { | |
let row = acc.data.find(r => r[0] === d.name); | |
if (!row) { | |
acc.data.push([d.name]); |
NewerOlder