Skip to content

Instantly share code, notes, and snippets.

View manabuyasuda's full-sized avatar

安田 学 manabuyasuda

View GitHub Profile
@manabuyasuda
manabuyasuda / adjustLineBreaks.js
Last active February 14, 2023 18:13
Googleの「budoux」で文字列に適切な改行を挿入します。
import { loadDefaultJapaneseParser } from 'budoux'
const parser = loadDefaultJapaneseParser()
/**
* 文字列を解析して、適切に改行されるように`wbr`タグを挿入します。
* IEは`wbr`タグに対応していません。
* @see https://caniuse.com/wbr-element
* @see https://github.com/google/budoux/tree/main/javascript
* @param {HTMLElement} element 最適化する要素
//- @param {Object} params
//- @param {String} params.name [""] SVGスプライトのid名
//-
//- @examples Input
//- +Icon({ name: "menu" })
//- @examples Output
//- <svg role="img">
//- <use xlink:href="/assets/svg/sprite.svg#menu"></use>
//- </svg>
mixin Icon(params={})
//- @param {Object} params
//- @param {String} params.src [""] 画像パス
//- @param {String} params.srcset [""] 画像のalt属性値
//-
//- @examples Input
//- +Picture({ src: "https://placehold.jp/300x300.png", alt: "" })
//- +Picture_Source({ media: "lg", srcset: "https://placehold.jp/1000x1000.png" })
//- +Picture_Source({ media: "md", srcset: "https://placehold.jp/600x600.png" })
//-
//- @examples Output
//- @param {Object} params
//- @param {String} params.type ["button"] type属性値
//- @param {boolean|string} params.size [false] ボタンのサイズ指定(`auto`,`full`)
//- @param {boolean|string} params.icon [false] ボタンのアイコン指定(`more`)
//- @param {boolean} params.disabled [false] disabled属性値を出力するかの真偽値
//-
//- @examples Input
//- +Button デフォルトボタン
//- @examples Output
//- <button class="sw-Button" type="button">デフォルトボタン</button>
//- @param {Object} params
//- @param {boolean|string} params.start [false] start属性値を出力するかの真偽値、または出力する数値
//-
//- @examples Input
//- +ListOrder
//- +ListOrder_Item リスト1
//- +ListOrder_Item リスト2
//- +ListOrder_Child
//- +ListOrder_Item リスト2-1
//- +ListOrder_Item リスト2-2
//- @param {Object} params
//- @param {String} params.id [""] id属性値
//- @param {String} params.name [""] name属性値
//- @param {String} params.value [""] value属性値
//- @param {boolean} params.disabled [false] disabled属性値を出力するかの真偽値
//- @param {boolean} params.error [false] エラー表示用のクラスを出力するかの真偽値
//-
//- @examples Input
//- +Checkbox({id: "checkbox1-1", name: "checkbox1", value: "0"}) チェックボックス1
//-
@manabuyasuda
manabuyasuda / duplicateFiles.js
Last active October 13, 2021 10:04
あるディレクトリ内のファイルすべてを複製する
// package.jsonの`scripts`に以下のように指定する
// "duplicateFiles": "node scripts/duplicateFiles.js"
const fs = require('fs-extra')
// 複製元のパス
const src = './src/'
// 複製先のパス
const dest = './public/'
// `dest`をフォルダごと、すべて削除する
try {
@manabuyasuda
manabuyasuda / canScrolled.js
Last active September 30, 2021 09:26
要素が横スクロール可能な状態かを返します。
/**
* 要素が横スクロール可能な状態かを返します。
* @param {HTMLElement} element テーブルをスクロールしている親要素
* @return Boolean
* @example
* const tables = document.querySelectorAll('.table-wrap')
* Array.from(tables).forEach((table) => {
* canScrolled(table) ? canFunc() : notFunc()
* })
*/
@manabuyasuda
manabuyasuda / dashed-line.scss
Created September 23, 2021 08:49
`background-image`で破線を作ります
// @desc - `background-image`で破線を作ります
// @param {String} $height [1px] - 破線の高さを指定します。
// @param {String} $borderWidth [4px] - ボーダー(実線)の幅を指定します。
// @param {String} $borderColor [currentColor] - ボーダー(実線)の色を指定します。
// @param {String} $intervalWidth [2px] - 間隔の幅を指定します。
// @param {String} $intervalColor [transparent] - 間隔の色を指定します。
// @example scss - Usage
// .foo { @include dashed-line(1px, 4px, #000, 2px, transparent); }
//
// @example css - CSS output
@manabuyasuda
manabuyasuda / generateJsonFromAPI.js
Last active September 9, 2021 07:47
npmスクリプトで、APIからJSONファイルを生成する。
require('dotenv').config({
path: '.env.local',
})
const Client = require('node-rest-client').Client
const fs = require('fs')
const CMS_ROOT_ENDPOINT = `${process.env.CMS_ROOT_ENDPOINT}`
const CMC_API_KEY = `${process.env.CMC_API_KEY}`