UNPKG

is-any-type

Version:

is-any-type simple functionality alternative to check data type references such as typeof and instanceof

71 lines (70 loc) 3.77 kB
export class Compare { constructor() { this.isTypeData = ['array', 'buffer', 'promise', 'function', 'object', 'null', 'undefined', 'string', 'number', 'boolean']; } isArrayCompare(data, compare) { this.isArrayCheckCompare = Array.isArray(data) && Array.isArray(compare) && 'array'; this.isMatch = this.isTypeData.indexOf(this.isArrayCheckCompare); this.isResult = this.isTypeData[this.isMatch]; return this.isResult === 'array' ? true : false; } isBufferCompare(data, compare) { this.isBufferCheckCompare = Buffer.isBuffer(data) && Buffer.isBuffer(compare) && 'buffer'; this.isMatch = this.isTypeData.indexOf(this.isBufferCheckCompare); this.isResult = this.isTypeData[this.isMatch]; return this.isResult === 'buffer' ? true : false; } isPromiseCompare(data, compare) { this.isPromiseCheckCompare = data instanceof Promise && compare instanceof Promise && 'promise'; this.isMatch = this.isTypeData.indexOf(this.isPromiseCheckCompare); this.isResult = this.isTypeData[this.isMatch]; return this.isResult === 'promise' ? true : false; } isFunctionCompare(data, compare) { this.isFunctionCheckCompare = data instanceof Function && compare instanceof Function && 'function'; this.isMatch = this.isTypeData.indexOf(this.isFunctionCheckCompare); this.isResult = this.isTypeData[this.isMatch]; return this.isResult === 'function' ? true : false; } isObjectCompare(data, compare) { this.isObjectCheckCompare = Object.getOwnPropertyNames(data)[0] !== (undefined || null || 'length') && Object.getOwnPropertyNames(compare)[0] !== (undefined || null || 'length') || Object.create(data) === Object.create({}) || Object.create(compare) === Object.create({}) ? 'object' : 'undefined'; this.isMatch = this.isTypeData.indexOf(this.isObjectCheckCompare); this.isResult = this.isTypeData[this.isMatch]; return this.isResult === 'object' ? true : false; } isNullCompare(data, compare) { this.isNullCheckCompare = data === null && compare === null && 'null'; this.isMatch = this.isTypeData.indexOf(this.isNullCheckCompare); this.isResult = this.isTypeData[this.isMatch]; return this.isResult === 'null' ? true : false; } isUndefinedCompare(data, compare) { this.isUndefinedCheckCompare = data === undefined && compare === undefined && 'undefined'; this.isMatch = this.isTypeData.indexOf(this.isUndefinedCheckCompare); this.isResult = this.isTypeData[this.isMatch]; return this.isResult === 'undefined' ? true : false; } isStringCompare(data, compare) { this.isStringCheckCompare = typeof data === 'string' && typeof compare === 'string' && 'string'; this.isMatch = this.isTypeData.indexOf(this.isStringCheckCompare); this.isResult = this.isTypeData[this.isMatch]; return this.isResult === 'string' ? true : false; } isNumberCompare(data, compare) { this.isNumberCheckCompare = typeof data === 'number' && typeof compare === 'number' && 'number'; this.isMatch = this.isTypeData.indexOf(this.isNumberCheckCompare); this.isResult = this.isTypeData[this.isMatch]; return this.isResult === 'number' ? true : false; } isBooleanCompare(data, compare) { this.isBooleanCheckCompare = typeof data === 'boolean' && typeof compare === 'boolean' && 'boolean'; this.isMatch = this.isTypeData.indexOf(this.isBooleanCheckCompare); this.isResult = this.isTypeData[this.isMatch]; return this.isResult === 'boolean' ? true : false; } }