明日の下書き
- 高円寺.dev #3 用の資料 https://koenji.connpass.com/event/160886/
- フロントエンド専門じゃない人向けの、フロントエンドの最先端〜やや未来の話です
- このレイヤーでは Node.js を使うべき/使うと強いという部分がありますが、他言語を否定しているわけではありません。むしろ他言語でこのアーキテクチャを模倣してほしいという話です。
明日の下書き
jsprimerというJavaScriptの書籍を書いている。 これを書いてるときに参考にしているものを書いていく。
ECMAScriptのLiving Standardな仕様書ページ。 スナップショットなECMAScriptの仕様書ページもあるけど、基本的にはLiving Standardの方しか見てない。
// Inspired by https://twitter.com/coderitual/status/1112297299307384833 and https://tapajyoti-bose.medium.com/7-killer-one-liners-in-javascript-33db6798f5bf | |
// Remove any duplicates from an array of primitives. | |
const unique = [...new Set(arr)] | |
// Sleep in async functions. Use: await sleep(2000). | |
const sleep = (ms) => (new Promise(resolve => setTimeout(resolve, ms))); | |
// or | |
const sleep = util.promisify(setTimeout); |
JSONは NaN
/ Infinity
/ -Infinity
や Date
型等に対応していない。
しかし、JavaScriptのJSONは、これらを解消する仕組みを持っている。
それは JSON.parse
の第二引数の reviver
とJSON.stringify
の第二引数の replacer
だ。
注意が必要なのは、 Date
型は toJSON
メソッドを持つため replacer
に値が渡る前に文字列になってしまうこと。
これに対応するには toJSON
メソッドを一時退避してしまえば良い。
これらを上手く駆使すれば、JSONに型を保ったまま値を保存し復元することができる。
# Install brew | |
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" | |
# Install composer | |
brew install homebrew/php/composer | |
### PHPCS | |
composer global require "squizlabs/php_codesniffer=*" | |
# Add to your .bash_profile |
# ==== Emojis ==== | |
# 🐛 :bug: バグ修正 | |
# 👍 :+1: 機能改善 | |
# ✨ :sparkles: 部分的な機能追加 | |
# 🎉 :tada: 盛大に祝うべき大きな機能追加 | |
# ♻️ :recycle: リファクタリング | |
# 🚿 :shower: 不要な機能・使われなくなった機能の削除 | |
# 💚 :green_heart: テストやCIの修正・改善 |
<?php | |
/** | |
* Plugin Name: WP REST API Batch Requests | |
* Description: Enabled a multi / batch requests endpoint for the WP RES API | |
* Author: Joe Hoyle | |
* Version: 1.0-alpha1 | |
* Plugin URI: https://github.com/WP-API/WP-API | |
* License: GPL2+ | |
*/ |
<?php | |
/** | |
* Improves the WordPress caption shortcode with HTML5 figure & figcaption, microdata & wai-aria attributes | |
* | |
* Author: @joostkiens | |
* Licensed under the MIT license | |
* | |
* @param string $val Empty | |
* @param array $attr Shortcode attributes | |
* @param string $content Shortcode content |
// A mixin for media queries: @mq | |
// | |
// Use with keywords in $medias array: | |
// @include mq($media: iphone) { | |
// ... | |
// } | |
// | |
// Use with manual queries: | |
// @include mq("all and (min-width:33em)") { | |
// ... |