first commit
This commit is contained in:
+9
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
comment
|
||||
*/
|
||||
|
||||
function isHoge(arg){
|
||||
return arg;
|
||||
}
|
||||
|
||||
export default isHoge;
|
||||
+123
@@ -0,0 +1,123 @@
|
||||
/*
|
||||
可変長引数ではないis関数詰め合わせモジュール
|
||||
略称版メソッドもなし
|
||||
*/
|
||||
|
||||
// 型・インスタンス
|
||||
import isArray from './is-array.mjs';
|
||||
import isBoolean from './is-boolean.mjs';
|
||||
import isBuffer from './is-buffer.mjs';
|
||||
import isArrayBuffer from './is-array-buffer.mjs';
|
||||
import isError from './is-error.mjs';
|
||||
import isFunction from './is-function.mjs';
|
||||
import isAsyncFunction from './is-async-function.mjs';
|
||||
import isAsyncGeneratorFunction from './is-async-generator-function.mjs';
|
||||
import isGeneratorFunction from './is-generator-function.mjs';
|
||||
import isNumber from './is-number.mjs';
|
||||
import isRegExp from './is-reg-exp.mjs';
|
||||
import isStats from './is-stats.mjs';
|
||||
import isString from './is-string.mjs';
|
||||
import isUndefined from './is-undefined.mjs';
|
||||
import isNull from './is-null.mjs';
|
||||
import isNaN from './is-nan.mjs';
|
||||
import isDate from './is-date.mjs';
|
||||
import isEvent from './is-event.mjs';
|
||||
import isEventTarget from './is-event-target.mjs';
|
||||
import isObject from './is-object.mjs';
|
||||
import isPromise from './is-promise.mjs';
|
||||
import isAbortController from './is-abort-controller.mjs';
|
||||
import isAbortSignal from './is-abort-signal.mjs';
|
||||
|
||||
// Number系
|
||||
import isOdd from './is-odd.mjs';
|
||||
import isEven from './is-even.mjs';
|
||||
import isMultiple from './is-multiple.mjs';
|
||||
|
||||
// String系
|
||||
import isLowercase from './is-lowercase.mjs';
|
||||
import isUppercase from './is-uppercase.mjs';
|
||||
import isIPv4 from './is-ipv4.mjs';
|
||||
import isHostname from './is-hostname.mjs';
|
||||
|
||||
// DOM
|
||||
import isNode from './is-node.mjs';
|
||||
import isTextNode from './is-text-node.mjs';
|
||||
import isElement from './is-element.mjs';
|
||||
import isDocumentFragment from './is-document-fragment.mjs';
|
||||
|
||||
|
||||
// 雑多
|
||||
import isTrue from './is-true.mjs';
|
||||
import isFalse from './is-false.mjs';
|
||||
import isTruthy from './is-truthy.mjs';
|
||||
import isFalsy from './is-falsy.mjs';
|
||||
import isInstance from './is-instance.mjs';
|
||||
import isInstanceof from './is-instanceof.mjs';
|
||||
import isInstanceOfClassName from './is-instance-of-classname.mjs';
|
||||
import isNullish from './is-nullish.mjs';
|
||||
import isObjectLiteral from './is-object-literal.mjs';
|
||||
import isArrayLike from './is-array-like.mjs';
|
||||
import isComparisonOperator from './is-comparison-operator.mjs';
|
||||
import isSameDay from './is-same-day.mjs';
|
||||
import isSemVer from './is-sem-ver.mjs';
|
||||
import isVersion from './is-version.mjs';
|
||||
import isEmpty from './is-empty.mjs';
|
||||
import isLeapYear from './is-leap-year.mjs';
|
||||
import isValidDate from './is-valid-date.mjs';
|
||||
|
||||
// 返り値
|
||||
const _is = {
|
||||
isArray,
|
||||
isBoolean,
|
||||
isBuffer,
|
||||
isArrayBuffer,
|
||||
isError,
|
||||
isFunction,
|
||||
isAsyncFunction,
|
||||
isAsyncGeneratorFunction,
|
||||
isGeneratorFunction,
|
||||
isNumber,
|
||||
isRegExp,
|
||||
isStats,
|
||||
isString,
|
||||
isUndefined,
|
||||
isNull,
|
||||
isNaN,
|
||||
isDate,
|
||||
isEvent,
|
||||
isEventTarget,
|
||||
isObject,
|
||||
isPromise,
|
||||
isAbortController,
|
||||
isAbortSignal,
|
||||
isOdd,
|
||||
isEven,
|
||||
isMultiple,
|
||||
isLowercase,
|
||||
isUppercase,
|
||||
isIPv4,
|
||||
isHostname,
|
||||
isNode,
|
||||
isTextNode,
|
||||
isElement,
|
||||
isDocumentFragment,
|
||||
isTrue,
|
||||
isFalse,
|
||||
isTruthy,
|
||||
isFalsy,
|
||||
isInstance,
|
||||
isInstanceof,
|
||||
isInstanceOfClassName,
|
||||
isNullish,
|
||||
isObjectLiteral,
|
||||
isArrayLike,
|
||||
isComparisonOperator,
|
||||
isSameDay,
|
||||
isSemVer,
|
||||
isVersion,
|
||||
isEmpty,
|
||||
isLeapYear,
|
||||
isValidDate
|
||||
}
|
||||
|
||||
export default _is;
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
import isObj from './is-object.mjs';
|
||||
import isFunc from './is-function.mjs';
|
||||
|
||||
/*
|
||||
引数がAbortControllerインスタンスか
|
||||
Polyfillでも機能するようにしている。
|
||||
*/
|
||||
function isAbortController(ac){
|
||||
return isObj(ac)
|
||||
&& isFunc(ac.constructor)
|
||||
&& ac.constructor.name==='AbortController';
|
||||
}
|
||||
|
||||
export default isAbortController;
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
import isObj from './is-object.mjs';
|
||||
import isFunc from './is-function.mjs';
|
||||
|
||||
/*
|
||||
引数がAbortSignalインスタンスか
|
||||
Polyfillでも機能するようにしている。
|
||||
*/
|
||||
function isAbortSignal(abortSignal){
|
||||
// const isETExtend = abortSignal instanceof EventTarget;
|
||||
return isObj(abortSignal)
|
||||
&& isFunc(abortSignal.constructor)
|
||||
&& abortSignal.constructor.name==='AbortSignal';
|
||||
}
|
||||
|
||||
export default isAbortSignal;
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// Mod
|
||||
import isInstance from './is-instance.mjs';
|
||||
|
||||
/*
|
||||
ArrayBufferインスタンスか
|
||||
|
||||
args
|
||||
1: any
|
||||
result
|
||||
boolean
|
||||
*/
|
||||
function isArrayBuffer(arg){
|
||||
return isInstance(arg, ArrayBuffer);
|
||||
}
|
||||
|
||||
export default isArrayBuffer;
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
定義: truthyで、.lengthで数値を返すもの
|
||||
*/
|
||||
|
||||
function isArrayLike(arg){
|
||||
return !!arg && typeof arg.length==='number';
|
||||
}
|
||||
|
||||
|
||||
export default isArrayLike;
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
function isArray(arg){
|
||||
return Array.isArray(arg);
|
||||
}
|
||||
|
||||
export default isArray;
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
import isInstanceof from './is-instanceof.mjs';
|
||||
|
||||
let AsyncFunction;
|
||||
|
||||
function isAsyncFunction(arg){
|
||||
|
||||
if( !AsyncFunction ){
|
||||
AsyncFunction = (async()=>0).constructor;
|
||||
}
|
||||
|
||||
return isInstanceof(arg, AsyncFunction);
|
||||
}
|
||||
|
||||
export default isAsyncFunction;
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
import isInstanceof from './is-instanceof.mjs';
|
||||
|
||||
let AsyncGeneratorFunction;
|
||||
|
||||
function isAsyncGeneratorFunction(arg){
|
||||
|
||||
if( !AsyncGeneratorFunction ){
|
||||
AsyncGeneratorFunction = (async function*(){}).constructor;
|
||||
}
|
||||
|
||||
return isInstanceof(arg, AsyncGeneratorFunction);
|
||||
}
|
||||
|
||||
export default isAsyncGeneratorFunction;
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
function isBoolean(arg){
|
||||
return typeof arg==='boolean';
|
||||
}
|
||||
|
||||
export default isBoolean;
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
function isBuffer(arg){
|
||||
return Buffer.isBuffer(arg);
|
||||
}
|
||||
|
||||
export default isBuffer;
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
有効な比較演算子の文字列か
|
||||
[比較演算子 - JavaScript | MDN](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/Comparison_Operators)
|
||||
*/
|
||||
|
||||
// 有効な比較演算子のset
|
||||
const set_co = new Set([
|
||||
'<',
|
||||
'>',
|
||||
'<=',
|
||||
'>=',
|
||||
'==',
|
||||
'!=',
|
||||
'===',
|
||||
'!=='
|
||||
]);
|
||||
|
||||
function isComparisonOperator(arg){
|
||||
return typeof arg==='string' && set_co.has(arg);
|
||||
}
|
||||
|
||||
export default isComparisonOperator;
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
function isDate(arg){
|
||||
return arg instanceof Date;
|
||||
}
|
||||
|
||||
export default isDate;
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
comment
|
||||
*/
|
||||
import isNode from './is-node.mjs';
|
||||
|
||||
function isDocumentFragment(arg){
|
||||
return isNode(arg) && arg.nodeType===11;
|
||||
}
|
||||
|
||||
export default isDocumentFragment;
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
comment
|
||||
*/
|
||||
function isElement(arg){
|
||||
return arg instanceof Element;
|
||||
}
|
||||
|
||||
export default isElement;
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
引数が空か
|
||||
|
||||
判定基準
|
||||
文字列
|
||||
長さが0の場合
|
||||
配列
|
||||
長さが0の場合
|
||||
オブジェクト
|
||||
keyが存在しない場合
|
||||
それ以外
|
||||
常にfalse
|
||||
*/
|
||||
function isEmpty(arg){
|
||||
if(typeof arg==='string'){
|
||||
return !arg.length;
|
||||
}else if( Array.isArray(arg) ){
|
||||
return !arg.length;
|
||||
}else if(typeof arg==='object' && arg instanceof Object){
|
||||
return !Object.getOwnPropertyNames(arg).length;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export default isEmpty;
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
comment
|
||||
*/
|
||||
|
||||
function isError(arg){
|
||||
return arg instanceof Error;
|
||||
}
|
||||
|
||||
export default isError;
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// Mod
|
||||
import isNumber from './is-number.mjs';
|
||||
|
||||
/*
|
||||
偶数判定(0含む)
|
||||
*/
|
||||
function isEven(num){
|
||||
return isNumber(num) && !(num % 2);
|
||||
}
|
||||
|
||||
export default isEven;
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
comment
|
||||
*/
|
||||
function isEventTarget(arg){
|
||||
return arg instanceof EventTarget;
|
||||
}
|
||||
|
||||
export default isEventTarget;
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
comment
|
||||
*/
|
||||
function isEvent(arg){
|
||||
return arg instanceof Event;
|
||||
}
|
||||
|
||||
export default isEvent;
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
comment
|
||||
*/
|
||||
|
||||
function isFalse(arg){
|
||||
return arg===false;
|
||||
}
|
||||
|
||||
export default isFalse;
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
|
||||
function isFalsy(arg){
|
||||
return !arg;
|
||||
}
|
||||
|
||||
export default isFalsy;
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
function isFunction(arg){
|
||||
return typeof arg==='function';
|
||||
}
|
||||
|
||||
export default isFunction;
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
import isInstanceof from './is-instanceof.mjs';
|
||||
|
||||
let GeneratorFunction;
|
||||
|
||||
function isGeneratorFunction(arg){
|
||||
|
||||
if( !GeneratorFunction ){
|
||||
GeneratorFunction = (function*(){}).constructor;
|
||||
}
|
||||
|
||||
return isInstanceof(arg, GeneratorFunction);
|
||||
}
|
||||
|
||||
export default isGeneratorFunction;
|
||||
+33
@@ -0,0 +1,33 @@
|
||||
// Var
|
||||
const re_label = /[a-z0-9][a-z0-9-]*[a-z0-9]/;
|
||||
const re_tld = /[a-z]{2,}|[a-z]{2}\.[a-z]{2}/;
|
||||
const re_domain = new RegExp(`${re_label.source}\.${re_tld.source}`);
|
||||
const re_hostname = new RegExp(`^(${re_label.source}\\.)*${re_domain.source}$`, 'i');
|
||||
|
||||
|
||||
/*
|
||||
ホスト名文字列か
|
||||
厳密な仕様がよくわからないのでルーズに判定している。
|
||||
大文字・小文字を区別しない。
|
||||
実際には混在しているものがあるため。
|
||||
dotで区切られた半角英数&ハイフン(ラベル)。
|
||||
大文字・小文字は区別しない。
|
||||
ハイフンは先頭・末尾NG.
|
||||
ラベル毎の長さは2-63文字。
|
||||
どこかで3文字以上と見たが、実際は二文字もよく振られている。
|
||||
ドメイン部分は2文字もある。
|
||||
合計255文字まで。
|
||||
|
||||
args
|
||||
1: string
|
||||
result
|
||||
boolean
|
||||
*/
|
||||
function isHostname(str){
|
||||
const isU256 = str.length <= 255;
|
||||
return isU256 && re_hostname.test(str);
|
||||
}
|
||||
|
||||
|
||||
|
||||
export default isHostname;
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
// mod
|
||||
import isInstance from './is-instance.mjs';
|
||||
import isString from './is-string.mjs';
|
||||
|
||||
/*
|
||||
インスタンスの親クラスが指定した名称か
|
||||
|
||||
args
|
||||
1: instance
|
||||
2: string
|
||||
3: op, object
|
||||
return
|
||||
boolean
|
||||
*/
|
||||
|
||||
|
||||
function isInstanceOfClassName(instance, str_name, options={debug:false}){
|
||||
|
||||
options.debug && console.log('isInstanceOfClassName()', instance, str_name);
|
||||
|
||||
if( !isInstance(instance) ){
|
||||
throw new TypeError('arg1 not instance');
|
||||
}
|
||||
if( !isString(str_name) ){
|
||||
throw new TypeError('arg2 not string');
|
||||
}
|
||||
|
||||
return instance.constructor.name===str_name;
|
||||
}
|
||||
|
||||
export default isInstanceOfClassName;
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
// Mod
|
||||
import isObject from './is-object.mjs';
|
||||
import isFunction from './is-function.mjs';
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
args === 2
|
||||
引数なにかのコンストラクタ関数・クラスのインスタンスか
|
||||
true条件
|
||||
オブジェクト
|
||||
.constructorが関数
|
||||
.__proto__が上記関数のprototype
|
||||
|
||||
args
|
||||
1: any
|
||||
result
|
||||
boolean
|
||||
*/
|
||||
function isInstance(any){
|
||||
if( isObject(any) ){
|
||||
const parent = any.constructor;
|
||||
return isFunction(parent) &&
|
||||
Object.getPrototypeOf(any)===parent.prototype;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export default isInstance;
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
|
||||
/*
|
||||
instanceof
|
||||
|
||||
args
|
||||
1: any
|
||||
2: any
|
||||
result
|
||||
boolean
|
||||
*/
|
||||
function isInstanceof(arg, arg2){
|
||||
try{
|
||||
return arg instanceof arg2;
|
||||
}catch(e){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export default isInstanceof;
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
|
||||
// Var
|
||||
const re_0to255 = /(\d|[1-9]\d|1\d{2}|2(5[0-5]|[0-4]\d))/;
|
||||
const re_ipv4 = new RegExp(`^(${re_0to255.source}\\.){3}${re_0to255.source}$`);
|
||||
|
||||
/*
|
||||
IPv4アドレス文字列か
|
||||
dotで区切られた0-255が4つ。
|
||||
|
||||
args
|
||||
1: string
|
||||
result
|
||||
boolean
|
||||
*/
|
||||
function isIPv4(str){
|
||||
return re_ipv4.test(str);
|
||||
}
|
||||
|
||||
export default isIPv4;
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
閏年判定
|
||||
|
||||
引数
|
||||
1: date or number
|
||||
返り値
|
||||
boolean
|
||||
|
||||
参考
|
||||
[うるう年とは - はてなキーワード](http://d.hatena.ne.jp/keyword/%A4%A6%A4%EB%A4%A6%C7%AF)
|
||||
*/
|
||||
import isNumber from './is-number.mjs';
|
||||
import isDate from './is-date.mjs';
|
||||
|
||||
function isLeapYear(arg){
|
||||
if( isNumber(arg) ){
|
||||
return isLeapYear_number(arg)
|
||||
}else if( isDate(arg) ){
|
||||
return isLeapYear_date(arg);
|
||||
}else{
|
||||
throw new TypeError(`Invalid arguments: ${arg}`);
|
||||
}
|
||||
}
|
||||
|
||||
// dateインスタンス用
|
||||
function isLeapYear_date(date){
|
||||
const year = date.getFullYear();
|
||||
return isLeapYear_number(year);
|
||||
}
|
||||
|
||||
// 数値(年)用、本体
|
||||
function isLeapYear_number(year){
|
||||
return year % 4 === 0 && (year % 100!==0 || year % 400===0);
|
||||
}
|
||||
|
||||
export default isLeapYear;
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// Mod
|
||||
import isString from './is-string.mjs';
|
||||
|
||||
/*
|
||||
引数文字列がすべて半角小文字か
|
||||
*/
|
||||
function isLowercase(arg){
|
||||
|
||||
if( !isString(arg) ){
|
||||
return false;
|
||||
}
|
||||
|
||||
return /^[a-z]+$/.test(arg);
|
||||
}
|
||||
|
||||
export default isLowercase;
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
// Mod
|
||||
import isNumber from './is-number.mjs';
|
||||
|
||||
/*
|
||||
倍数判定
|
||||
引数1が引数2の倍数か
|
||||
|
||||
args
|
||||
1: number
|
||||
2: number
|
||||
result
|
||||
boolean
|
||||
*/
|
||||
|
||||
function isMultiple(arg1, arg2){
|
||||
|
||||
// validation
|
||||
if( !isNumber(arg1) ){
|
||||
throw TypeError('Invalid arguments 1');
|
||||
}
|
||||
if( !isNumber(arg2) ){
|
||||
throw TypeError('Invalid arguments 1');
|
||||
}
|
||||
|
||||
return !(arg1%arg2);
|
||||
}
|
||||
|
||||
export default isMultiple;
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// arg!=argでいい気もするがPolyfill前提のコンセプトのため
|
||||
function isNaN(arg){
|
||||
return Number.isNaN(arg);
|
||||
}
|
||||
|
||||
export default isNaN;
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// Mod
|
||||
import isNumber from './is-number.mjs';
|
||||
import isObject from './is-object.mjs';
|
||||
|
||||
function isNode(arg){
|
||||
return arg instanceof Node;
|
||||
}
|
||||
|
||||
export default isNode;
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
comment
|
||||
*/
|
||||
function isNull(arg){
|
||||
return arg===null;
|
||||
}
|
||||
|
||||
export default isNull;
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
null or undef
|
||||
|
||||
args
|
||||
1: any
|
||||
result
|
||||
boolean
|
||||
*/
|
||||
function isNullish(arg){
|
||||
if( arg===null ){
|
||||
return true;
|
||||
}else if( arg===undefined ){
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export default isNullish;
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
|
||||
function isNumber(arg){
|
||||
return typeof arg==='number';
|
||||
}
|
||||
|
||||
export default isNumber;
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
const obj = {} みたいなの
|
||||
arg.constructor===Object でもよさそう。
|
||||
|
||||
2020.11.08
|
||||
Object#__proto__ => Object.getPrototypeOf()
|
||||
*/
|
||||
function isObjectLiteral(arg){
|
||||
return Object.getPrototypeOf(arg)===Object.prototype;
|
||||
}
|
||||
|
||||
export default isObjectLiteral;
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
typeofと違ってnullは弾く
|
||||
|
||||
ChangeLog
|
||||
2020.10.25
|
||||
判定をinstanceofから以前の方法に戻した。
|
||||
Object.create(null) で作られたものを検出できなかったため。
|
||||
*/
|
||||
function isObject(arg){
|
||||
return !!arg && arg===Object(arg);
|
||||
}
|
||||
|
||||
export default isObject;
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
奇数判定(0含む)
|
||||
*/
|
||||
import isNumber from './is-number.mjs';
|
||||
|
||||
function isOdd(num){
|
||||
return isNumber(num) && !!(num % 2);
|
||||
}
|
||||
|
||||
export default isOdd;
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
/*
|
||||
引数がPromiseインスタンスか
|
||||
*/
|
||||
function isPromise(arg){
|
||||
return arg instanceof Promise;
|
||||
}
|
||||
|
||||
export default isPromise;
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
|
||||
function isRegExp(arg){
|
||||
return arg instanceof RegExp;
|
||||
}
|
||||
|
||||
export default isRegExp;
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
import isDate from './is-date.mjs';
|
||||
|
||||
/*
|
||||
引数のdateインスタンスが同じ日か
|
||||
|
||||
args
|
||||
1...: date
|
||||
result
|
||||
boolean
|
||||
*/
|
||||
function isSameday(...arr_date){
|
||||
let str_baseDateText;
|
||||
|
||||
for(let date of arr_date ){
|
||||
if( !isDate(date) ){
|
||||
throw new TypeError(`Invalid arguments: ${index}`);
|
||||
}
|
||||
|
||||
if( !str_baseDateText ){
|
||||
str_baseDateText = date.toDateString();
|
||||
}else{
|
||||
const str_dateText = date.toDateString();
|
||||
if(str_baseDateText!==str_dateText){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
export default isSameday;
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
SemVerな文字列かどうか
|
||||
regexpを長々と繋げて頑張ると次弄るときに頭痛くなるから極力分割する
|
||||
参考
|
||||
[SemVerのv1.0.0とv2.0.0-rc.1、node-semverを見比べてみた - /var/log/kozy4324](http://kozy4324.github.io/blog/2012/12/19/semver/)
|
||||
*/
|
||||
|
||||
function isSemVer(arg){
|
||||
if( typeof arg!=='string'){
|
||||
return false;
|
||||
}
|
||||
|
||||
if( /^\d\.\d\.\d$/.test(arg) ){
|
||||
return true;
|
||||
}
|
||||
|
||||
if( /^\d\.\d\.\d-[0-9A-Za-z-.]*$/.test(arg) ){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
export default isSemVer;
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// Mod
|
||||
import fs from 'fs';
|
||||
|
||||
function isStats(arg){
|
||||
try{
|
||||
return arg instanceof fs.Stats;
|
||||
}catch(e){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
export default isStats;
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
function isString(arg){
|
||||
return typeof arg==='string';
|
||||
}
|
||||
|
||||
export default isString;
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
comment
|
||||
*/
|
||||
import isNode from './is-node.mjs';
|
||||
|
||||
function isTextNode(arg){
|
||||
return isNode(arg) && arg.nodeType===3;
|
||||
}
|
||||
|
||||
export default isTextNode;
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
/*
|
||||
comment
|
||||
*/
|
||||
|
||||
function isTrue(arg){
|
||||
return arg===true;
|
||||
}
|
||||
|
||||
export default isTrue;
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
function isTruthy(arg){
|
||||
return !!arg;
|
||||
}
|
||||
|
||||
export default isTruthy;
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
|
||||
function isUndefined(arg){
|
||||
return arg===undefined;
|
||||
}
|
||||
|
||||
export default isUndefined;
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// Mod
|
||||
import isString from './is-string.mjs';
|
||||
|
||||
/*
|
||||
引数文字列がすべて大文字か
|
||||
*/
|
||||
function isUppercase(arg){
|
||||
|
||||
if( !isString(arg) ){
|
||||
return false;
|
||||
}
|
||||
|
||||
return /^[A-Z]+$/.test(arg);
|
||||
}
|
||||
|
||||
export default isUppercase;
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
引数の日時が存在するものかをBooleanで返す
|
||||
|
||||
引数
|
||||
1, 2, 3: number
|
||||
返り値
|
||||
boolean
|
||||
|
||||
参考
|
||||
[Vanilla JavaScriptで簡単に日付が有効かどうかチェックする方法 | Rriver](https://parashuto.com/rriver/development/validate-date-using-vanilla-js)
|
||||
*/
|
||||
|
||||
// Mod
|
||||
import isNumber from './is-number.mjs';
|
||||
|
||||
function isValidDate(year, month, day){
|
||||
|
||||
if( !isNumber(year, month, day) ){
|
||||
throw new TypeError(`Invalid arguments`);
|
||||
}
|
||||
|
||||
const date = new Date(year, month-1, day);
|
||||
const isSameYear = date.getFullYear()===year;
|
||||
const isSameMonth = date.getMonth()===(month-1);
|
||||
const isSameDay = date.getDate()===day;
|
||||
const result = isSameYear && isSameMonth && isSameDay;
|
||||
return result;
|
||||
}
|
||||
|
||||
export default isValidDate;
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
versionを表した数字とdotの文字列か
|
||||
|
||||
セーフ
|
||||
1
|
||||
1.2
|
||||
1.2.3
|
||||
1.2.3.4
|
||||
アウト
|
||||
1.2A
|
||||
其の弐
|
||||
*/
|
||||
|
||||
function isVersion(arg){
|
||||
return typeof arg==='string' && /^\d(|[0-9.]*\d)$/.test(arg);
|
||||
}
|
||||
|
||||
export default isVersion;
|
||||
Reference in New Issue
Block a user