$ npm i ts-pattern
import { match, P } from 'ts-pattern'
$ npm i ts-pattern
import { match, P } from 'ts-pattern'
<!-- | |
@link https://qiita.com/CloudRemix/items/92e68a048a0da93ed240 | |
--> | |
<!-- gif 39 bytes --> | |
<img src="data:image/gif;base64,R0lGODlhAQABAGAAACH5BAEKAP8ALAAAAAABAAEAAAgEAP8FBAA7" alt="" height="1" width="1"> | |
<!-- png 68 bytes --> | |
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVQI12NgYAAAAAMAASDVlMcAAAAASUVORK5CYII=" alt="" height="1" width="1"> |
/** | |
* 単純な 100% の配分で重み付けできる「値:重み」の列挙から、加重平均値を導出する | |
* | |
* @link https://jp.indeed.com/career-advice/career-development/how-to-calculate-weighted-average | |
* @example percentWeightedAvg([ | |
* { value: 150, weight: 320 }, | |
* { value: 200, weight: 180 }, | |
* ]) // 168 | |
*/ | |
const percentWeightedAvg = (data = [{ value: 0, weight: 0 }]) => { |
motion.dev/
motion-hooks - github.com/tanvesh01/motion-hooks
tanvesh01/motion-hooks Web Animations APIを使った軽量で高速なオープンソースのアニメーションライブラリ・「Motion One」
useAutoAnimate
みたいな hook で実装可能/** | |
* @example chunk([1, 2, 3, 4, 5, 6, 7], 3) // [[1, 2, 3], [4, 5, 6], [7]] | |
* @link https://qiita.com/yarnaimo/items/e92600237d65876f8dd8 | |
*/ | |
export const chunk = <T>(arr: T[], size: number) => ( | |
arr.reduce((newarr, _, i) => ( | |
i % size ? newarr : [...newarr, arr.slice(i, i + size)] | |
), [] as T[][]) | |
) |
/** | |
* https://ja.javascript.info/mutation-observer | |
*/ | |
const origin = document.querySelector('p#origin') | |
const copy = document.querySelector('p#copy') | |
// origin の変更を検知して innerText を copy へ転記、的な... | |
const obs = new MutationObserver(mutations => { | |
// mutations に変更内容の詳細が配列で入ってる感じ | |
// 正直ここで origin を api から読み取ったほうが見やすいけど |
get ゲッター - developer.mozilla.org
set セッター - developer.mozilla.org
プロパティ getters と setters
【JavaScript】Self Objectの値を参照してプロパティ値設定したい
普通の言語でよくある getter, setter を object に生やせる。caniuse 見るに結構いにしえの構文っぽいけど知らんかった ... 多分 IE が NG だったからかな。
/** | |
* string[] から /(パターン1|パターン2)/g みたいなやつ | |
* 動的につくりたいよおお | |
*/ | |
const words = ['パターン1', 'パターン2'] | |
const regex = new RegExp(`(${words.join('|')})`, 'g') |