JSFiddle - React, Tailwind, and code Playground

by evgkch

JavaScript

const Types = {

  isFunc(target) {
    return target && typeof target === 'function';
  },

  isObject(target) {
    return typeof target === 'object' && !Array.isArray(target) && target !== null;
  },

  isPromise(target) {
    return target instanceof Promise;
  },

  isArray(target) {
    return typeof target === 'object' && Array.isArray(target);
  },

  isUndefined(target) {
    return typeof target === 'undefined';
  },

  isNull(target) {
    return typeof target === 'object' && !target;
  },

  isNullOrUndefined(target) {
    return Types.isNull(target) || Types.isUndefined(target);
  },

  isBool(target) {
    return target === true || target === false;
  },

  isString(target) {
    return typeof target === 'string';
  }

}

class ConditionSetting {

	static for(target) {
  	if (Types.isObject(target))
    	return new ConditionSetting(target, 'object');
    if (Types.isArray(target))
    	return new ConditionSetting(target, 'array');
  }
  
}

class Condition {

	static for(target) {
    if (Types.isArray(target))
    	return new Condition(target);
    else
    	throw new Error(`target must be an array but git ${typeof target}`);
  }
  
  static and(a, b) {
  	if (a == undefined)
    	return b;
    else
  		return a && b;
  }
  
  static or(a, b) {
  	if (a == undefined)
    	return b;
    else
  		return a || b;
  }
  
  static check(condition) {
  	if (condition == 'every')
    	return Condition.and;
    if (condition == 'some')
    	return Condition.or;
  }
  
  get result() {
  	return this._result;
  }
  
  set result(res) {
  	this._result = res;
  }
  
  get some() {
  	this.method = 'some';
    return this;
  }
  
  get every() {
  	this.method = 'every';
    return this;
  }
  
  constructor(target) {  	
  	this.target = target;
  }
  
  _do(callback) {
  	if (this._from == undefined)
    	this.from(0);
    if (this._to == undefined)
    	this.to(this.target.length - 1);
    for (let i = this._from; i <= this._to; i++)
    {
			callback(i);
  ...