javascript

JavaScriptでのURL末尾スラッシュ除去

stackoverflow.com 正規表現で 正規表現で置換するパターン。 function removeTrailingSlash(url) { return url.replace(/\/$/, '') } String.prototype.substr()で substrで判定するパターン。 function removeTrailingSlash(url) { if (url.substr(-1) ===…

Reactコンポーネントをnpmで公開するときにやること

React コンポーネントを webpack、babel等を使ってnpmとして公開するまでの手順。 環境準備 まずはプロジェクトディレクトリを作成して、必要なファイルを作成する(ドットファイルだったりREADMEだったり)。 $ mkdir react-hoge $ cd react-hoge $ touch R…

SFCでのeslintの'React' is defined but never used

SFC(stateless functional component) ではReactが未使用の変数としてeslintに検知された。 import React from 'react' // <- 'React' is defined but never used no-unused-vars const Header = props => { return ( <header> <h1>{ props.title }</h1> </header> ) } export default …

ponyfillとは何なのか

github.com A polyfill is code that adds missing functionality by monkey patching an API. Unfortunately, it usually globally patches built-ins, which affects all code running in the environment. polyfillはAPIにパッチをあてることで欠けている…