assert.js

  1. aeq = ( function ( aeq ) {
  2. aeq.extend({
  3. /**
  4. * Checks if value is null. Throws an error if it is not.
  5. * @method
  6. * @memberof aeq
  7. * @param {Any} o The value to check against null.
  8. * @param {String} err The error message to throw
  9. * @return {Boolean} `true` if no error was thrown
  10. */
  11. assertIsNull: function ( o, err ) {
  12. if ( aeq.isNullOrUndefined( o ) ) {
  13. return true;
  14. }
  15. throw new Error( err );
  16. },
  17. /**
  18. * Checks if value is null. Throws an error if it is.
  19. * @method
  20. * @memberof aeq
  21. * @param {Any} o The value to check against null.
  22. * @param {String} err The error message to throw
  23. * @return {Boolean} `true` if no error was thrown
  24. */
  25. assertIsNotNull: function ( o, err ) {
  26. if ( !aeq.isNullOrUndefined( o ) ) {
  27. return true;
  28. }
  29. throw new Error( err );
  30. },
  31. /**
  32. * Checks if value is `true`. Throws an error if it is not.
  33. * @method
  34. * @memberof aeq
  35. * @param {Any} o The value to check against `true`.
  36. * @param {String} err The error message to throw
  37. * @return {Boolean} `true` if no error was thrown
  38. */
  39. assertIsTrue: function ( o, err ) {
  40. if ( o === true ) {
  41. return true;
  42. }
  43. throw new Error( err );
  44. },
  45. /**
  46. * Checks if value is `false`. Throws an error if it is not.
  47. * @method
  48. * @memberof aeq
  49. * @param {Any} o The value to check against `false`.
  50. * @param {String} err The error message to throw
  51. * @return {Boolean} `true` if no error was thrown
  52. */
  53. assertIsFalse: function ( o, err ) {
  54. if ( o === false ) {
  55. return true;
  56. }
  57. throw new Error( err );
  58. },
  59. /**
  60. * Checks if array is empty. Throws an error if it is not.
  61. * @method
  62. * @memberof aeq
  63. * @param {Array} o The array to check is empty.
  64. * @param {String} err The error message to throw
  65. * @return {Boolean} `true` if no error was thrown
  66. */
  67. assertIsEmpty: function ( o, err ) {
  68. if ( aeq.isEmpty( o ) ) {
  69. return true;
  70. }
  71. throw new Error( err );
  72. },
  73. /**
  74. * Checks if array is empty. Throws an error if it is.
  75. * @method
  76. * @memberof aeq
  77. * @param {Array} o The array to check is empty.
  78. * @param {String} err The error message to throw
  79. * @return {Boolean} `true` if no error was thrown
  80. */
  81. assertIsNotEmpty: function ( o, err ) {
  82. if ( !aeq.isEmpty( o ) ) {
  83. return true;
  84. }
  85. throw new Error( err );
  86. }
  87. });
  88. return aeq;
  89. }( aeq || {}) );