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
#!/usr/bin/env node | |
'use strict'; | |
// > npm i -g commander; npm i -g canvas; | |
// this also requires Cairo: https://www.npmjs.com/package/canvas | |
// > brew install pkg-config cairo libpng jpeg giflib | |
const path = require('path'); | |
const fs = require('fs'); | |
const cmdr = require('commander'); |
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 fullwidth = args => ( | |
args | |
.split('') | |
.map(v=>( | |
String.fromCharCode( | |
/^\s$/.test(v)? 0x3000 : | |
parseInt( (v+'').charCodeAt(0) ) + 65248 | |
) | |
)) | |
.join('') |
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 run = (...args) => (args.map(f=>f())) |
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
//I have no idea whether this should be on `Object` or `Object.prototype` | |
Object.values=function(_obj){ | |
return Object.keys(_obj) | |
.filter(function(k){return _obj.hasOwnProperty(k)&&_obj.propertyIsEnumerable(k)}) | |
.map(function(k){return _obj[k]}) | |
} | |
//And as an arrow function | |
Object.values= _obj => Object.keys(_obj).filter(k => _obj.hasOwnProperty(k)&&_obj.propertyIsEnumerable(k)).map(k => _obj[k]) |
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 pureConcat = (...objects) => (Object.assign({},...objects)) |
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 ah/*ActionHelper*/ = (g='DEFAULT',n='ACTION') => (o={}) => (Object.assign({type:`${g}_${n}`.toUpperCase()},o)) | |
const ach/*ActionCreatorHelper*/ = (n,arr) => (arr.reduce((a,b)=>Object.assign(a,{[b]:ah(n,b)}),{})) | |
/* | |
Example usage | |
//Helper strings | |
const C='create',R='read',U='update',D='delete',S='success',F='failure'; | |
const Sync = ach('sync',[S,F]); |
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 normyHelper = (...args) => { | |
const obj = {}; | |
( args[1] && /string/.test(typeof args[0]) ? args[1].map(c=>c[args[0]]) : args[0] ) | |
.forEach((c,i)=>{obj[(c.id?c.id:i)]=c}); | |
return obj; | |
} | |
//> normyHelper('foo', [ {foo:{name:'foobar',id:1}}, {foo:{name:'barbaz',id:2}} ]) | |
// { '1': { name: 'foobar', id: 1 }, | |
// '2': { name: 'barbaz', id: 2 } } |
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 hhmmToMinutes = hhmm => hhmm.split(':').map((c,i)=>(i===0?parseInt(c)*60:parseInt(c))).reduce((a,b)=>(a+b),0) | |
const minutesToHhmm = min => (`${Math.floor(min/60)<10?0:''}${Math.floor(min/60)}:${min%60<10?0:''}${min%60}`) | |
// hhmmToMinutes('8:59') //539 (480+59) | |
// minutesToHhmm(539) //'08:59' |
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 uToJsx = s => s.replace(/\\u\d{4}/g,m=>(String.fromCharCode(parseInt(m.substring(2),16)))) |
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
/* | |
Used like: | |
<RadioList | |
radioOptions={ [ | |
{value:5,label:"5 – blah blah blah"}, | |
{value:4,label:"4 – bleh bleh bleh"}, | |
{value:3,label:"3 – foo bar baz"}, | |
{value:2,label:"2 – electric boogaloo"}, | |
{value:1,label:"1 – jinkies"} |