Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tests.js 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. 'use strict';
  2. var SafeString = require('./runtime').SafeString;
  3. /**
  4. * Returns `true` if the object is a function, otherwise `false`.
  5. * @param { any } value
  6. * @returns { boolean }
  7. */
  8. function callable(value) {
  9. return typeof value === 'function';
  10. }
  11. exports.callable = callable;
  12. /**
  13. * Returns `true` if the object is strictly not `undefined`.
  14. * @param { any } value
  15. * @returns { boolean }
  16. */
  17. function defined(value) {
  18. return value !== undefined;
  19. }
  20. exports.defined = defined;
  21. /**
  22. * Returns `true` if the operand (one) is divisble by the test's argument
  23. * (two).
  24. * @param { number } one
  25. * @param { number } two
  26. * @returns { boolean }
  27. */
  28. function divisibleby(one, two) {
  29. return one % two === 0;
  30. }
  31. exports.divisibleby = divisibleby;
  32. /**
  33. * Returns true if the string has been escaped (i.e., is a SafeString).
  34. * @param { any } value
  35. * @returns { boolean }
  36. */
  37. function escaped(value) {
  38. return value instanceof SafeString;
  39. }
  40. exports.escaped = escaped;
  41. /**
  42. * Returns `true` if the arguments are strictly equal.
  43. * @param { any } one
  44. * @param { any } two
  45. */
  46. function equalto(one, two) {
  47. return one === two;
  48. }
  49. exports.equalto = equalto; // Aliases
  50. exports.eq = exports.equalto;
  51. exports.sameas = exports.equalto;
  52. /**
  53. * Returns `true` if the value is evenly divisible by 2.
  54. * @param { number } value
  55. * @returns { boolean }
  56. */
  57. function even(value) {
  58. return value % 2 === 0;
  59. }
  60. exports.even = even;
  61. /**
  62. * Returns `true` if the value is falsy - if I recall correctly, '', 0, false,
  63. * undefined, NaN or null. I don't know if we should stick to the default JS
  64. * behavior or attempt to replicate what Python believes should be falsy (i.e.,
  65. * empty arrays, empty dicts, not 0...).
  66. * @param { any } value
  67. * @returns { boolean }
  68. */
  69. function falsy(value) {
  70. return !value;
  71. }
  72. exports.falsy = falsy;
  73. /**
  74. * Returns `true` if the operand (one) is greater or equal to the test's
  75. * argument (two).
  76. * @param { number } one
  77. * @param { number } two
  78. * @returns { boolean }
  79. */
  80. function ge(one, two) {
  81. return one >= two;
  82. }
  83. exports.ge = ge;
  84. /**
  85. * Returns `true` if the operand (one) is greater than the test's argument
  86. * (two).
  87. * @param { number } one
  88. * @param { number } two
  89. * @returns { boolean }
  90. */
  91. function greaterthan(one, two) {
  92. return one > two;
  93. }
  94. exports.greaterthan = greaterthan; // alias
  95. exports.gt = exports.greaterthan;
  96. /**
  97. * Returns `true` if the operand (one) is less than or equal to the test's
  98. * argument (two).
  99. * @param { number } one
  100. * @param { number } two
  101. * @returns { boolean }
  102. */
  103. function le(one, two) {
  104. return one <= two;
  105. }
  106. exports.le = le;
  107. /**
  108. * Returns `true` if the operand (one) is less than the test's passed argument
  109. * (two).
  110. * @param { number } one
  111. * @param { number } two
  112. * @returns { boolean }
  113. */
  114. function lessthan(one, two) {
  115. return one < two;
  116. }
  117. exports.lessthan = lessthan; // alias
  118. exports.lt = exports.lessthan;
  119. /**
  120. * Returns `true` if the string is lowercased.
  121. * @param { string } value
  122. * @returns { boolean }
  123. */
  124. function lower(value) {
  125. return value.toLowerCase() === value;
  126. }
  127. exports.lower = lower;
  128. /**
  129. * Returns `true` if the operand (one) is less than or equal to the test's
  130. * argument (two).
  131. * @param { number } one
  132. * @param { number } two
  133. * @returns { boolean }
  134. */
  135. function ne(one, two) {
  136. return one !== two;
  137. }
  138. exports.ne = ne;
  139. /**
  140. * Returns true if the value is strictly equal to `null`.
  141. * @param { any }
  142. * @returns { boolean }
  143. */
  144. function nullTest(value) {
  145. return value === null;
  146. }
  147. exports.null = nullTest;
  148. /**
  149. * Returns true if value is a number.
  150. * @param { any }
  151. * @returns { boolean }
  152. */
  153. function number(value) {
  154. return typeof value === 'number';
  155. }
  156. exports.number = number;
  157. /**
  158. * Returns `true` if the value is *not* evenly divisible by 2.
  159. * @param { number } value
  160. * @returns { boolean }
  161. */
  162. function odd(value) {
  163. return value % 2 === 1;
  164. }
  165. exports.odd = odd;
  166. /**
  167. * Returns `true` if the value is a string, `false` if not.
  168. * @param { any } value
  169. * @returns { boolean }
  170. */
  171. function string(value) {
  172. return typeof value === 'string';
  173. }
  174. exports.string = string;
  175. /**
  176. * Returns `true` if the value is not in the list of things considered falsy:
  177. * '', null, undefined, 0, NaN and false.
  178. * @param { any } value
  179. * @returns { boolean }
  180. */
  181. function truthy(value) {
  182. return !!value;
  183. }
  184. exports.truthy = truthy;
  185. /**
  186. * Returns `true` if the value is undefined.
  187. * @param { any } value
  188. * @returns { boolean }
  189. */
  190. function undefinedTest(value) {
  191. return value === undefined;
  192. }
  193. exports.undefined = undefinedTest;
  194. /**
  195. * Returns `true` if the string is uppercased.
  196. * @param { string } value
  197. * @returns { boolean }
  198. */
  199. function upper(value) {
  200. return value.toUpperCase() === value;
  201. }
  202. exports.upper = upper;
  203. /**
  204. * If ES6 features are available, returns `true` if the value implements the
  205. * `Symbol.iterator` method. If not, it's a string or Array.
  206. *
  207. * Could potentially cause issues if a browser exists that has Set and Map but
  208. * not Symbol.
  209. *
  210. * @param { any } value
  211. * @returns { boolean }
  212. */
  213. function iterable(value) {
  214. if (typeof Symbol !== 'undefined') {
  215. return !!value[Symbol.iterator];
  216. } else {
  217. return Array.isArray(value) || typeof value === 'string';
  218. }
  219. }
  220. exports.iterable = iterable;
  221. /**
  222. * If ES6 features are available, returns `true` if the value is an object hash
  223. * or an ES6 Map. Otherwise just return if it's an object hash.
  224. * @param { any } value
  225. * @returns { boolean }
  226. */
  227. function mapping(value) {
  228. // only maps and object hashes
  229. var bool = value !== null && value !== undefined && typeof value === 'object' && !Array.isArray(value);
  230. if (Set) {
  231. return bool && !(value instanceof Set);
  232. } else {
  233. return bool;
  234. }
  235. }
  236. exports.mapping = mapping;