0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

🔖型判定

/*
通常モード(第2引数は省略可)
  typ(対象) ⇒ [型名]
判定モード (分岐判定時)
  typ(対象,1) ⇒ TRUE / FALSE
*/

function typ(n,e) {
  /*型判定*/
  var rtn, mch, rSt, ertn
  /*型名リスト*/
    lst = {
      String: '字',
      Number: '数',
      Object: '物',
      Array: '列',
      Date: '日',
      Undefined: '未',
      Invalid: '偽',
      NaN: 'N'
    },
  /*判定リスト*/
  echk = [ '字' , '数' , '物' , '列' ,'日' ];
  /*型判定文取得*/
  rSt = Object.prototype.toString.call(n);
  /*文字切出*/
  mch = rSt.match(/[\w]+/g)[1];
  /*NaN判定*/
  if ((mch == 'Number') && (n != n)) mch = 'NaN';
  /*偽日時判定*/
  if ((mch == 'Date') && (Number.isNaN(new Date(n).getTime())) ) mch = 'Invalid';
  rtn = (lst[mch] ||'');

 /*判定出力*/
  if(e)return (echk.includes(rtn));

 /*通常出力*/
  return `[${(rtn||mch)}]`;
}


/*関数動作チェック*/
var t,
  /*NaN*/
  a = (0 / 0),
  /*偽日時*/
  e = (new Date('yyyy,mm,dd')),
  /*現日時*/
  d = (new Date(Date.now())),
  /*零文字*/
  p = "0",
  /*数値化*/
  v = (1 * p) + 1;

/*判定確認*/
alert(`\n[[判定確認]]\n
   _変数:検_[型]_実行値\n
❌判定検査
 未定義_t:${(typ(t,1)?'X':'O')} ${typ(t)}_${t}
 NaN_a:${(typ(a,1)?'X':'O')} ${typ(a)}_${a}
 偽日時_e:${(typ(e,1)?'X':'O')} ${typ(e)}_${e}\n
️⭕️判定検査
 現日時_d:${(typ(d,1)?'O':'X')} ${typ(d)}_${(d.toLocaleString('JP'))}
 零文字_p:${(typ(p,1)?'O':'X')} ${typ(p)}_${p}
 数値化_v:${(typ(v,1)?'O':'X')} ${typ(v)}_${v}\n`
);

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?