types.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. class types {
  2. static check_string(target, none = false) {
  3. if (none && (target === undefined || target === null)) {
  4. return;
  5. }
  6. if (typeof(target) !== "string") {
  7. throw new TypeError("Target must be string.");
  8. }
  9. }
  10. static check_number(target, none = false) {
  11. if (none && (target === undefined || target === null)) {
  12. return;
  13. }
  14. if (typeof(target) !== "number") {
  15. throw new TypeError("Target must be number.");
  16. }
  17. }
  18. static check_html_element(target, none = false) {
  19. if (none && (target === undefined || target === null)) {
  20. return;
  21. }
  22. if (target instanceof HTMLElement) {
  23. return;
  24. }
  25. throw new TypeError("Target must be an HTML Element.");
  26. }
  27. static check_callback(target, none = false) {
  28. if (none && (target === undefined || target === null)) {
  29. return;
  30. }
  31. if (typeof(target) !== "function") {
  32. throw new TypeError("Target must be an callback.");
  33. }
  34. }
  35. static check_boolean(target, none = false) {
  36. if (none && (target === undefined || target === null)) {
  37. return;
  38. }
  39. if (typeof(target) !== "boolean") {
  40. throw new TypeError("Target must be an boolean.");
  41. }
  42. }
  43. static block_strings(target, blocked) {
  44. for (const string in blocked) {
  45. if (target.search(string) !== -1) {
  46. const fail = "Target can not contain \"" + string + "\".";
  47. throw new TypeError(fail);
  48. }
  49. }
  50. }
  51. }
  52. export { types };