This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* HTMLエスケープ | |
* | |
* @param {String} str 変換したい文字列 | |
*/ | |
var escapeHTML = function (str) { | |
return str | |
.replace(/&/g, '&') | |
.replace(/</g, '<') | |
.replace(/>/g, '>') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 文字列を整数にして返す(parseInt) | |
* | |
* 全角の数字は半角にする | |
* 全角ハイフン、全角ダッシュ、全角マイナス記号、長音符は半角ハイフンに変換 | |
* 先頭のマイナス以外のハイフンは削除 | |
* | |
* 「abcd -ー123かー456」→「-123456」 | |
* 「abc123456def」→「123456」 | |
* 「A0000123456」→「123456」 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 改行をBRタグに変換 | |
* | |
* @param {String} str 変換したい文字列 | |
*/ | |
var nl2br = function (str) { | |
return str.replace(/\n/g, '<br>'); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* タブ文字をnum数のスペースに変換後、改行以外の制御文字を削除 | |
* 改行文字は\nに変換 | |
* | |
* @param {String} str 変換したい文字列 | |
* @param {Number} num スペースの文字数(デフォルトは4) | |
*/ | |
var removeCtl = function (str, num) { | |
num = parseInt(num, 10); | |
var space = new Array(isNaN(num) ? 5 : num + 1).join(' '); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 数字のみにして桁区切り(小数点以下の桁数を指定) | |
* | |
* @param {String} val 変換する文字列 | |
* @param {Number} num 小数点以下の桁数 | |
* | |
* @return {string} 文字列から数字、ドット、ハイフン以外の文字を取り除き | |
* parseFloatで変換した数値を桁区切りにして返す | |
* 最初に全角の数字、ドット、ハイフン、マイナスは半角に変換 | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 文字列を整数にして返す | |
* | |
* @param {String} val 変換する文字列 | |
* @return {integer} parseIntで10進数に変換した数値 | |
* 整数に変換できない場合は0を返す | |
* 最初に全角の数字、ドット、ハイフン、マイナスは半角に変換 | |
*/ | |
var toInteger = function (val) { | |
// 保険でtoStringしておく |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 任意の桁数に切り取った文字列を返す | |
* 桁数に足りない場合は任意の文字で左側を埋める | |
* | |
* @param {String} val 元の文字 | |
* @param {Number} num 桁数 | |
* @param {String} pad 文字埋めに使用する文字列 | |
* @return {String} 作成した文字列 | |
*/ | |
var padSlice = function(val, num, pad) { |