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
// @flow | |
import * as React from 'react' | |
class Maybe extends React.Component<{ | |
flag: boolean, | |
children?: React.Node, | |
else: React.Node, | |
}> { | |
render() { | |
const { props } = this |
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
GHQ=`ghq root`/github.com | |
ME=`git config --get user.name` | |
gcd() { | |
ghq get -p $1 | |
if [ `dirname "$1"` = "." ]; then | |
cd $GHQ/$ME/$1 | |
else | |
cd $GHQ/$1 | |
fi |
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
$ curl localhost:3000?name=tj | |
["express","koa","mocha","stylus","co"] |
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
$ yarn add cli-to-api | |
$ yarn run cli-to-api cli.js -o server.js | |
$ node server.js | |
listening on 3000 |
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
$ yarn add mri // or minimist |
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
$ node cli.js --name tj | |
[ 'express', 'koa', 'mocha', 'stylus', 'co' ] | |
$ chmod +x cli.js | |
$ cli.js --name kittens | |
[ 'babel', 'yarn' ] |
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
'use strict' | |
const parse = require('mri') // or require('minimist') | |
// node cli.js --name tj | |
const { name } = parse(process.argv.slice(2)) | |
const jsers = { | |
tj: ['express', 'koa', 'mocha', 'stylus', 'co'], | |
sindersorhus: ['ava', 'chalk', 'xo', 'yaomen'], | |
rauchg: ['socket.io', 'next.js'], |
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
$ mkdir cli-app-demo | |
$ cd cli-app-demo | |
$ yarn init -y | |
$ touch cli.js |
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
try { | |
await f() | |
} catch (err) { | |
handleErr1(err) | |
} | |
try { | |
await g() | |
} catch (err) { | |
handleErr2(err) | |
} |
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 name = ‘ゲスト’ | |
try { | |
name = awiat getName() | |
} catch (err) { } | |
console.log(`ようこそ ${name}さん`) | |
// => ようこそ ゲストさん | |
/// ↓ ↓ ↓ | |
const name = await getName().catch(() => ‘ゲスト’) |