This file contains hidden or 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
{ | |
"AE": { | |
"country": "AE", | |
"countryCode": "971", | |
"iddPrefix": "00", | |
"nddPrefix": "0", | |
"formatters": [ | |
{ | |
"leadingDigitsPattern": "60|8", | |
"formatter": [ |
This file contains hidden or 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 fs = require('fs'); | |
// Read in googles metadata json file | |
const input = fs.readFileSync(__dirname + '/metadata.json'); | |
const parsedInput = JSON.parse( input.toString() ); | |
// For storing our full output | |
const output = {}; | |
// Just formats |
This file contains hidden or 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
/* -------------------- toPath -------------------- */ | |
const toPath = (path = '') => { | |
return String.prototype.replace | |
.call(path, /\['(.+?)'\]/g, '.$1') | |
.split(/[,[\].]+?/) | |
.filter(Boolean); | |
} | |
/* --------------------- get --------------------- */ |
This file contains hidden or 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
/** | |
* Turns a JSON pointer into Java Script Propery Access Notation | |
* | |
* /foo/bar/baz/0/taz ---> foo.bar.baz[0].taz | |
* | |
* IF trim is set to true | |
* | |
* /foo/bar/baz/0/taz ---> foo.bar.baz[0] | |
*/ | |
export default function getJSPAN($ref, trim) { |
This file contains hidden or 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, { useState, useRef } from 'react'; | |
const useClipboard = () => { | |
const [copySuccess, setCopySuccess] = useState('Copy'); | |
const textAreaRef = useRef(null); | |
function copyToClipboard(e: any) { | |
// @ts-ignore | |
const copyText = textAreaRef.current.textContent; | |
const textArea = document.createElement('textarea'); |
This file contains hidden or 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 getFormatter = (formatter, value) => { | |
// If mask is a string turn it into an array; | |
if (typeof formatter === 'string') { | |
return formatter.split('').map((char) => { | |
if (char === '#') { | |
return /\d/; | |
} |
This file contains hidden or 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
let replacer = (key, value) => { | |
// if we get a function, give us the code for that function | |
if (typeof value === 'function') { | |
return value.toString(); | |
} | |
return value; | |
} | |
let reviver = (key, value) => { | |
if (typeof value === 'string' |
This file contains hidden or 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 { useState, useRef, useEffect } from 'react'; | |
// https://github.com/facebook/react/issues/14543 | |
function useStateWithGetter(initial) { | |
const ref = useRef(); | |
const mounted = useRef(true); | |
const [state, setState] = useState(initial); | |
ref.current = state; |
This file contains hidden or 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 formatDate = (d, config = {}) => { | |
const date = new Date(d); | |
return new Intl.DateTimeFormat('en-US', { | |
timeZone: 'America/Los_Angeles', | |
month: 'short', | |
day: 'numeric', | |
hour: 'numeric', | |
hour12: true, | |
...config, | |
}).format(date); |
This file contains hidden or 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 fs = require('fs'); | |
const zlib = require('zlib'); | |
// Read in a file | |
const pFile = fs.readFileSync(`${__dirname}/bigFile`); | |
// Log the byte size | |
console.log('Original Size:', Buffer.byteLength(pFile, 'utf8')); | |
// Compress it |
NewerOlder