Skip to content

Instantly share code, notes, and snippets.

View uto-usui's full-sized avatar
🐈
... 🐈 ... 🐈

uto usui uto-usui

🐈
... 🐈 ... 🐈
View GitHub Profile
@uto-usui
uto-usui / arg.ts
Created November 28, 2020 00:12
引数の分割代入.ts
function exFunc(arg: number, {
a = 0,
b = 'func'
}: {
a?: number,
b?: string
} = {}) {
// funk!
}
@uto-usui
uto-usui / getFile.js
Created March 6, 2020 14:42
node.js で 特定の拡張子のファイルのパスを取得して何かする。サンプルは vue ファイルを取得して、そのファイル名でコンポーネントを登録する。
const FileType = {
File: 'file',
Directory: 'directory',
Unknown: 'unknown',
}
/**
* ファイルの種類を取得する
* @param {string} path パス
* @return {FileType} ファイルの種類
@uto-usui
uto-usui / SetCssVar.js
Created February 5, 2020 05:41
Creating and setting CSS variables
const SetVar = ({propertyName, value, el, pre = 'my'}) => {
if (!el) {
document.documentElement.style.setProperty(`--${pre}-${propertyName}`, value)
} else {
el.style.setProperty(`--${pre}-${propertyName}`, value)
}
}
export default SetVar
@uto-usui
uto-usui / Clipboard.js
Last active February 5, 2020 05:34
Minimum clipboard script.
const Clipboard = (text) => {
let textarea = document.createElement('textarea')
textarea.value = text
textarea.className = 'js-clip'
document.body.appendChild(textarea)
textarea.focus()
textarea.select()
document.execCommand('copy')
@uto-usui
uto-usui / Vector2D.js
Last active January 24, 2020 08:25
Simple Vector class For Canvas2d
export class Vector2d {
constructor(x = 0, y = 0) {
this.x = x
this.y = y
}
// return the angle of the vector in radians
getDirection() {
return Math.atan2(this.y, this.x)
}
@uto-usui
uto-usui / AddClassListPropToSvgElement.js
Created October 10, 2019 06:49
SVG に classList を追加する
const getter = Object.getOwnPropertyDescriptor(
HTMLElement.prototype,
'classList',
).get
// Add to classList SVGElement getter
Object.defineProperty(SVGElement.prototype, 'classList', {
get: getter,
})
@uto-usui
uto-usui / checkVideoType.js
Created August 15, 2019 06:52
Return mp4 or webm extension if available
const video = document.createElement('video')
const checkVideoType = () => {
if (video.canPlayType('video/webm') === 'maybe') {
return 'webm'
} else if (video.canPlayType('video/mp4') === 'maybe') {
return 'mp4'
} else {
return null
}
@uto-usui
uto-usui / DeleteServiceWorker.js
Created June 21, 2019 05:32
ServiceWorker の cache を削除する
navigator.serviceWorker.getRegistrations().then(function(registrations) {
for(let registration of registrations) {
registration.unregister();
}
});
caches.keys().then(function(keys) {
var promises = [];
keys.forEach(function(cacheName) {
if (cacheName) {
promises.push(caches.delete(cacheName));
@uto-usui
uto-usui / ScrollManagement.js
Last active April 5, 2019 07:05
スクロールの on / off をコントロールする
function scrollControl(event) {
event.preventDefault()
}
function noScroll() {
document.addEventListener('mousewheel', scroll_control, { passive: false })
document.addEventListener('touchmove', scroll_control, { passive: false })
}
function returnScroll() {
@uto-usui
uto-usui / GitCommitEmoji.md
Created February 12, 2019 04:55 — forked from parmentf/GitCommitEmoji.md
Git Commit message Emoji