@bitblit/ratchet-common 4.0.99-alpha → 4.0.103-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (298) hide show
  1. package/{dist/types → lib}/2d/line-2d.d.ts +1 -1
  2. package/{dist/types → lib}/2d/poly-line-2d.d.ts +1 -1
  3. package/{dist/types → lib}/2d/ratchet-2d.d.ts +4 -4
  4. package/{dist/es → lib}/2d/ratchet-2d.js +1 -1
  5. package/lib/2d/ratchet-2d.spec.js +117 -0
  6. package/{dist/types → lib}/build/ratchet-common-info.d.ts +1 -1
  7. package/{dist/types → lib}/histogram/histogram.d.ts +1 -4
  8. package/{dist/es → lib}/histogram/histogram.js +1 -3
  9. package/lib/histogram/histogram.spec.js +19 -0
  10. package/lib/jwt/common-jwt-token.d.ts +6 -0
  11. package/{dist/types → lib}/jwt/jwt-ratchet-like.d.ts +3 -6
  12. package/{dist/types → lib}/jwt/jwt-ratchet.d.ts +4 -13
  13. package/{dist/es → lib}/jwt/jwt-ratchet.js +12 -7
  14. package/lib/jwt/jwt-ratchet.spec.js +49 -0
  15. package/{dist/types → lib}/jwt/jwt-token-base.d.ts +0 -4
  16. package/lib/lang/array-ratchet.d.ts +14 -0
  17. package/{dist/es → lib}/lang/array-ratchet.js +2 -2
  18. package/lib/lang/array-ratchet.spec.js +68 -0
  19. package/{dist/types → lib}/lang/base64-ratchet.d.ts +1 -1
  20. package/{dist/es → lib}/lang/base64-ratchet.js +1 -1
  21. package/lib/lang/base64-ratchet.spec.js +28 -0
  22. package/{dist/es → lib}/lang/boolean-ratchet.js +1 -1
  23. package/lib/lang/boolean-ratchet.spec.js +81 -0
  24. package/{dist/types → lib}/lang/composite-last-success-provider.d.ts +1 -2
  25. package/{dist/es → lib}/lang/composite-last-success-provider.js +2 -0
  26. package/lib/lang/composite-last-success-provider.spec.js +26 -0
  27. package/{dist/es → lib}/lang/date-ratchet.js +5 -5
  28. package/lib/lang/date-ratchet.spec.js +21 -0
  29. package/{dist/es → lib}/lang/duration-ratchet.js +1 -1
  30. package/lib/lang/duration-ratchet.spec.js +39 -0
  31. package/lib/lang/enum-ratchet.d.ts +5 -0
  32. package/{dist/es → lib}/lang/enum-ratchet.js +1 -1
  33. package/lib/lang/enum-ratchet.spec.d.ts +5 -0
  34. package/lib/lang/enum-ratchet.spec.js +31 -0
  35. package/{dist/es → lib}/lang/error-ratchet.js +1 -1
  36. package/lib/lang/error-ratchet.spec.js +20 -0
  37. package/lib/lang/esm-ratchet.d.ts +4 -0
  38. package/lib/lang/esm-ratchet.js +11 -0
  39. package/{dist/types → lib}/lang/expiring-object.d.ts +1 -1
  40. package/{dist/es → lib}/lang/expiring-object.js +13 -4
  41. package/lib/lang/expiring-object.spec.js +51 -0
  42. package/{dist/es → lib}/lang/geolocation-ratchet.js +4 -4
  43. package/lib/lang/geolocation-ratchet.spec.d.ts +1 -0
  44. package/lib/lang/geolocation-ratchet.spec.js +74 -0
  45. package/{dist/es → lib}/lang/global-ratchet.js +3 -3
  46. package/lib/lang/global-ratchet.spec.d.ts +1 -0
  47. package/lib/lang/global-ratchet.spec.js +14 -0
  48. package/{dist/es → lib}/lang/key-value.js +2 -0
  49. package/lib/lang/last-success-provider.d.ts +3 -0
  50. package/lib/lang/last-success-provider.js +1 -0
  51. package/{dist/types → lib}/lang/map-ratchet.d.ts +1 -1
  52. package/{dist/es → lib}/lang/map-ratchet.js +3 -3
  53. package/lib/lang/map-ratchet.spec.d.ts +1 -0
  54. package/lib/lang/map-ratchet.spec.js +90 -0
  55. package/lib/lang/no.spec.d.ts +1 -0
  56. package/lib/lang/no.spec.js +7 -0
  57. package/{dist/es → lib}/lang/number-ratchet.js +3 -3
  58. package/lib/lang/number-ratchet.spec.d.ts +1 -0
  59. package/lib/lang/number-ratchet.spec.js +118 -0
  60. package/lib/lang/parsed-url.js +1 -0
  61. package/lib/lang/promise-ratchet.d.ts +18 -0
  62. package/{dist/es → lib}/lang/promise-ratchet.js +5 -5
  63. package/lib/lang/promise-ratchet.spec.d.ts +1 -0
  64. package/lib/lang/promise-ratchet.spec.js +74 -0
  65. package/{dist/es → lib}/lang/require-ratchet.js +1 -1
  66. package/lib/lang/require-ratchet.spec.d.ts +3 -0
  67. package/lib/lang/require-ratchet.spec.js +80 -0
  68. package/{dist/types → lib}/lang/stop-watch.d.ts +1 -1
  69. package/{dist/es → lib}/lang/stop-watch.js +9 -8
  70. package/{dist/es → lib}/lang/string-ratchet.js +2 -2
  71. package/lib/lang/string-ratchet.spec.d.ts +1 -0
  72. package/lib/lang/string-ratchet.spec.js +158 -0
  73. package/lib/lang/time-zone-ratchet.d.ts +19 -0
  74. package/{dist/es → lib}/lang/time-zone-ratchet.js +2 -1
  75. package/lib/lang/time-zone-ratchet.spec.d.ts +1 -0
  76. package/lib/lang/time-zone-ratchet.spec.js +40 -0
  77. package/{dist/types → lib}/lang/timeout-token.d.ts +1 -1
  78. package/{dist/es → lib}/lang/timeout-token.js +5 -3
  79. package/lib/lang/timeout-token.spec.d.ts +1 -0
  80. package/lib/lang/timeout-token.spec.js +9 -0
  81. package/{dist/types → lib}/lang/transform-ratchet.d.ts +1 -1
  82. package/{dist/es → lib}/lang/transform-ratchet.js +1 -1
  83. package/lib/lang/transform-ratchet.spec.d.ts +1 -0
  84. package/lib/lang/transform-ratchet.spec.js +118 -0
  85. package/lib/logger/classic-single-line-log-message-formatter.d.ts +6 -0
  86. package/{dist/types → lib}/logger/log-message-builder.d.ts +2 -2
  87. package/{dist/es → lib}/logger/log-message-builder.js +1 -0
  88. package/{dist/types → lib}/logger/log-message-formatter.d.ts +2 -2
  89. package/lib/logger/log-message-formatter.js +1 -0
  90. package/{dist/types → lib}/logger/log-message-processor.d.ts +1 -1
  91. package/lib/logger/log-message-processor.js +1 -0
  92. package/{dist/types → lib}/logger/log-message.d.ts +1 -1
  93. package/lib/logger/log-message.js +1 -0
  94. package/{dist/types → lib}/logger/log-snapshot.d.ts +1 -1
  95. package/lib/logger/log-snapshot.js +1 -0
  96. package/{dist/types → lib}/logger/logger-instance.d.ts +6 -6
  97. package/{dist/es → lib}/logger/logger-instance.js +15 -8
  98. package/{dist/types → lib}/logger/logger-meta.d.ts +1 -1
  99. package/lib/logger/logger-meta.js +1 -0
  100. package/{dist/types → lib}/logger/logger-options.d.ts +4 -4
  101. package/lib/logger/logger-options.js +1 -0
  102. package/{dist/types → lib}/logger/logger-ring-buffer.d.ts +2 -2
  103. package/{dist/es → lib}/logger/logger-ring-buffer.js +7 -6
  104. package/{dist/types → lib}/logger/logger-util.d.ts +2 -2
  105. package/{dist/es → lib}/logger/logger-util.js +10 -10
  106. package/lib/logger/logger-util.spec.d.ts +1 -0
  107. package/lib/logger/logger-util.spec.js +9 -0
  108. package/{dist/types → lib}/logger/logger.d.ts +7 -16
  109. package/{dist/es → lib}/logger/logger.js +14 -14
  110. package/lib/logger/logger.spec.d.ts +1 -0
  111. package/lib/logger/logger.spec.js +134 -0
  112. package/lib/logger/none-log-message-formatter.d.ts +6 -0
  113. package/lib/logger/structured-json-log-message-formatter.d.ts +6 -0
  114. package/{dist/types → lib}/network/browser-local-ip-provider.d.ts +1 -1
  115. package/{dist/es → lib}/network/browser-local-ip-provider.js +3 -3
  116. package/lib/network/browser-local-ip-provider.spec.d.ts +1 -0
  117. package/lib/network/browser-local-ip-provider.spec.js +16 -0
  118. package/{dist/types → lib}/network/fixed-local-ip-provider.d.ts +1 -1
  119. package/{dist/es → lib}/network/fixed-local-ip-provider.js +1 -0
  120. package/lib/network/local-ip-provider.d.ts +3 -0
  121. package/lib/network/local-ip-provider.js +1 -0
  122. package/{dist/types → lib}/network/network-ratchet.d.ts +1 -1
  123. package/{dist/es → lib}/network/network-ratchet.js +2 -2
  124. package/lib/network/network-ratchet.spec.d.ts +1 -0
  125. package/lib/network/network-ratchet.spec.js +13 -0
  126. package/{dist/types → lib}/stream/buffer-writable.d.ts +2 -2
  127. package/{dist/es → lib}/stream/buffer-writable.js +1 -1
  128. package/lib/stream/multi-stream.d.ts +7 -0
  129. package/lib/stream/multi-stream.js +12 -0
  130. package/{dist/types → lib}/stream/stream-ratchet.d.ts +2 -2
  131. package/{dist/es → lib}/stream/stream-ratchet.js +2 -2
  132. package/lib/stream/stream-ratchet.spec.d.ts +1 -0
  133. package/lib/stream/stream-ratchet.spec.js +13 -0
  134. package/{dist/types → lib}/stream/string-writable.d.ts +1 -1
  135. package/{dist/es → lib}/stream/string-writable.js +1 -1
  136. package/lib/stream/string-writable.spec.d.ts +1 -0
  137. package/lib/stream/string-writable.spec.js +12 -0
  138. package/{dist/es → lib}/third-party/google/google-recaptcha-ratchet.js +3 -3
  139. package/lib/third-party/google/google-recaptcha-ratchet.spec.d.ts +1 -0
  140. package/lib/third-party/google/google-recaptcha-ratchet.spec.js +20 -0
  141. package/{dist/types → lib}/third-party/twilio/twilio-ratchet.d.ts +0 -4
  142. package/{dist/es → lib}/third-party/twilio/twilio-ratchet.js +8 -5
  143. package/{dist/types → lib}/transform/built-in-transforms.d.ts +1 -1
  144. package/{dist/es → lib}/transform/built-in-transforms.js +2 -2
  145. package/lib/transform/transform-rule.js +1 -0
  146. package/{dist/types → lib}/tx/transaction-configuration.d.ts +2 -2
  147. package/lib/tx/transaction-configuration.js +1 -0
  148. package/{dist/types → lib}/tx/transaction-ratchet.d.ts +3 -3
  149. package/{dist/es → lib}/tx/transaction-ratchet.js +4 -4
  150. package/lib/tx/transaction-ratchet.spec.d.ts +1 -0
  151. package/lib/tx/transaction-ratchet.spec.js +130 -0
  152. package/{dist/types → lib}/tx/transaction-result.d.ts +1 -1
  153. package/lib/tx/transaction-result.js +1 -0
  154. package/lib/tx/transaction-step.js +1 -0
  155. package/package.json +11 -12
  156. package/dist/cjs/2d/line-2d.js +0 -2
  157. package/dist/cjs/2d/plane-2d.js +0 -2
  158. package/dist/cjs/2d/point-2d.js +0 -2
  159. package/dist/cjs/2d/poly-line-2d.js +0 -2
  160. package/dist/cjs/2d/ratchet-2d.js +0 -250
  161. package/dist/cjs/build/build-information.js +0 -2
  162. package/dist/cjs/build/ratchet-common-info.js +0 -18
  163. package/dist/cjs/histogram/histogram-entry.js +0 -2
  164. package/dist/cjs/histogram/histogram.js +0 -54
  165. package/dist/cjs/index.js +0 -74
  166. package/dist/cjs/jwt/common-jwt-token.js +0 -2
  167. package/dist/cjs/jwt/expired-jwt-handling.js +0 -9
  168. package/dist/cjs/jwt/jwt-ratchet-like.js +0 -2
  169. package/dist/cjs/jwt/jwt-ratchet.js +0 -164
  170. package/dist/cjs/jwt/jwt-token-base.js +0 -2
  171. package/dist/cjs/lang/array-ratchet.js +0 -87
  172. package/dist/cjs/lang/base64-ratchet.js +0 -49
  173. package/dist/cjs/lang/boolean-ratchet.js +0 -49
  174. package/dist/cjs/lang/composite-last-success-provider.js +0 -28
  175. package/dist/cjs/lang/date-ratchet.js +0 -33
  176. package/dist/cjs/lang/duration-ratchet.js +0 -46
  177. package/dist/cjs/lang/enum-ratchet.js +0 -34
  178. package/dist/cjs/lang/error-ratchet.js +0 -49
  179. package/dist/cjs/lang/expiring-object.js +0 -68
  180. package/dist/cjs/lang/geolocation-ratchet.js +0 -267
  181. package/dist/cjs/lang/global-ratchet.js +0 -48
  182. package/dist/cjs/lang/key-value.js +0 -6
  183. package/dist/cjs/lang/last-success-provider.js +0 -2
  184. package/dist/cjs/lang/map-ratchet.js +0 -168
  185. package/dist/cjs/lang/no.js +0 -8
  186. package/dist/cjs/lang/number-ratchet.js +0 -159
  187. package/dist/cjs/lang/parsed-url.js +0 -2
  188. package/dist/cjs/lang/promise-ratchet.js +0 -142
  189. package/dist/cjs/lang/require-ratchet.js +0 -60
  190. package/dist/cjs/lang/stop-watch.js +0 -117
  191. package/dist/cjs/lang/string-ratchet.js +0 -195
  192. package/dist/cjs/lang/time-zone-ratchet.js +0 -80
  193. package/dist/cjs/lang/timeout-token.js +0 -19
  194. package/dist/cjs/lang/transform-ratchet.js +0 -70
  195. package/dist/cjs/logger/classic-single-line-log-message-formatter.js +0 -18
  196. package/dist/cjs/logger/log-message-builder.js +0 -51
  197. package/dist/cjs/logger/log-message-format-type.js +0 -9
  198. package/dist/cjs/logger/log-message-formatter.js +0 -2
  199. package/dist/cjs/logger/log-message-processor.js +0 -2
  200. package/dist/cjs/logger/log-message.js +0 -2
  201. package/dist/cjs/logger/log-snapshot.js +0 -2
  202. package/dist/cjs/logger/logger-instance.js +0 -207
  203. package/dist/cjs/logger/logger-level-name.js +0 -12
  204. package/dist/cjs/logger/logger-meta.js +0 -2
  205. package/dist/cjs/logger/logger-options.js +0 -2
  206. package/dist/cjs/logger/logger-output-function.js +0 -9
  207. package/dist/cjs/logger/logger-ring-buffer.js +0 -76
  208. package/dist/cjs/logger/logger-util.js +0 -49
  209. package/dist/cjs/logger/logger.js +0 -139
  210. package/dist/cjs/logger/none-log-message-formatter.js +0 -9
  211. package/dist/cjs/logger/structured-json-log-message-formatter.js +0 -24
  212. package/dist/cjs/network/browser-local-ip-provider.js +0 -25
  213. package/dist/cjs/network/fixed-local-ip-provider.js +0 -12
  214. package/dist/cjs/network/local-ip-provider.js +0 -2
  215. package/dist/cjs/network/network-ratchet.js +0 -106
  216. package/dist/cjs/stream/buffer-writable.js +0 -20
  217. package/dist/cjs/stream/stream-ratchet.js +0 -72
  218. package/dist/cjs/stream/string-writable.js +0 -18
  219. package/dist/cjs/third-party/google/google-recaptcha-ratchet.js +0 -33
  220. package/dist/cjs/third-party/twilio/twilio-ratchet.js +0 -75
  221. package/dist/cjs/transform/built-in-transforms.js +0 -195
  222. package/dist/cjs/transform/transform-rule.js +0 -2
  223. package/dist/cjs/tx/transaction-configuration.js +0 -2
  224. package/dist/cjs/tx/transaction-final-state.js +0 -9
  225. package/dist/cjs/tx/transaction-ratchet.js +0 -80
  226. package/dist/cjs/tx/transaction-result.js +0 -2
  227. package/dist/cjs/tx/transaction-step.js +0 -2
  228. package/dist/es/index.js +0 -71
  229. package/dist/tsconfig.cjs.tsbuildinfo +0 -1
  230. package/dist/tsconfig.es.tsbuildinfo +0 -1
  231. package/dist/tsconfig.types.tsbuildinfo +0 -1
  232. package/dist/types/index.d.ts +0 -74
  233. package/dist/types/jwt/common-jwt-token.d.ts +0 -17
  234. package/dist/types/lang/array-ratchet.d.ts +0 -30
  235. package/dist/types/lang/enum-ratchet.d.ts +0 -12
  236. package/dist/types/lang/last-success-provider.d.ts +0 -4
  237. package/dist/types/lang/promise-ratchet.d.ts +0 -32
  238. package/dist/types/lang/time-zone-ratchet.d.ts +0 -50
  239. package/dist/types/logger/classic-single-line-log-message-formatter.d.ts +0 -6
  240. package/dist/types/logger/none-log-message-formatter.d.ts +0 -6
  241. package/dist/types/logger/structured-json-log-message-formatter.d.ts +0 -6
  242. package/dist/types/network/local-ip-provider.d.ts +0 -4
  243. /package/{dist/es → lib}/2d/line-2d.js +0 -0
  244. /package/{dist/types → lib}/2d/plane-2d.d.ts +0 -0
  245. /package/{dist/es → lib}/2d/plane-2d.js +0 -0
  246. /package/{dist/types → lib}/2d/point-2d.d.ts +0 -0
  247. /package/{dist/es → lib}/2d/point-2d.js +0 -0
  248. /package/{dist/es → lib}/2d/poly-line-2d.js +0 -0
  249. /package/{dist/es/build/build-information.js → lib/2d/ratchet-2d.spec.d.ts} +0 -0
  250. /package/{dist/types → lib}/build/build-information.d.ts +0 -0
  251. /package/{dist/es/histogram/histogram-entry.js → lib/build/build-information.js} +0 -0
  252. /package/{dist/es → lib}/build/ratchet-common-info.js +0 -0
  253. /package/{dist/types → lib}/histogram/histogram-entry.d.ts +0 -0
  254. /package/{dist/es/jwt/common-jwt-token.js → lib/histogram/histogram-entry.js} +0 -0
  255. /package/{dist/es/jwt/jwt-ratchet-like.js → lib/histogram/histogram.spec.d.ts} +0 -0
  256. /package/{dist/es/jwt/jwt-token-base.js → lib/index.d.ts} +0 -0
  257. /package/{dist/es/lang/last-success-provider.js → lib/index.js} +0 -0
  258. /package/{dist/es/lang/parsed-url.js → lib/jwt/common-jwt-token.js} +0 -0
  259. /package/{dist/types → lib}/jwt/expired-jwt-handling.d.ts +0 -0
  260. /package/{dist/es → lib}/jwt/expired-jwt-handling.js +0 -0
  261. /package/{dist/es/logger/log-message-formatter.js → lib/jwt/jwt-ratchet-like.js} +0 -0
  262. /package/{dist/es/logger/log-message-processor.js → lib/jwt/jwt-ratchet.spec.d.ts} +0 -0
  263. /package/{dist/es/logger/log-message.js → lib/jwt/jwt-token-base.js} +0 -0
  264. /package/{dist/es/logger/log-snapshot.js → lib/lang/array-ratchet.spec.d.ts} +0 -0
  265. /package/{dist/es/logger/logger-meta.js → lib/lang/base64-ratchet.spec.d.ts} +0 -0
  266. /package/{dist/types → lib}/lang/boolean-ratchet.d.ts +0 -0
  267. /package/{dist/es/logger/logger-options.js → lib/lang/boolean-ratchet.spec.d.ts} +0 -0
  268. /package/{dist/es/network/local-ip-provider.js → lib/lang/composite-last-success-provider.spec.d.ts} +0 -0
  269. /package/{dist/types → lib}/lang/date-ratchet.d.ts +0 -0
  270. /package/{dist/es/transform/transform-rule.js → lib/lang/date-ratchet.spec.d.ts} +0 -0
  271. /package/{dist/types → lib}/lang/duration-ratchet.d.ts +0 -0
  272. /package/{dist/es/tx/transaction-configuration.js → lib/lang/duration-ratchet.spec.d.ts} +0 -0
  273. /package/{dist/types → lib}/lang/error-ratchet.d.ts +0 -0
  274. /package/{dist/es/tx/transaction-result.js → lib/lang/error-ratchet.spec.d.ts} +0 -0
  275. /package/{dist/es/tx/transaction-step.js → lib/lang/expiring-object.spec.d.ts} +0 -0
  276. /package/{dist/types → lib}/lang/geolocation-ratchet.d.ts +0 -0
  277. /package/{dist/types → lib}/lang/global-ratchet.d.ts +0 -0
  278. /package/{dist/types → lib}/lang/key-value.d.ts +0 -0
  279. /package/{dist/types → lib}/lang/no.d.ts +0 -0
  280. /package/{dist/es → lib}/lang/no.js +0 -0
  281. /package/{dist/types → lib}/lang/number-ratchet.d.ts +0 -0
  282. /package/{dist/types → lib}/lang/parsed-url.d.ts +0 -0
  283. /package/{dist/types → lib}/lang/require-ratchet.d.ts +0 -0
  284. /package/{dist/types → lib}/lang/string-ratchet.d.ts +0 -0
  285. /package/{dist/es → lib}/logger/classic-single-line-log-message-formatter.js +0 -0
  286. /package/{dist/types → lib}/logger/log-message-format-type.d.ts +0 -0
  287. /package/{dist/es → lib}/logger/log-message-format-type.js +0 -0
  288. /package/{dist/types → lib}/logger/logger-level-name.d.ts +0 -0
  289. /package/{dist/es → lib}/logger/logger-level-name.js +0 -0
  290. /package/{dist/types → lib}/logger/logger-output-function.d.ts +0 -0
  291. /package/{dist/es → lib}/logger/logger-output-function.js +0 -0
  292. /package/{dist/es → lib}/logger/none-log-message-formatter.js +0 -0
  293. /package/{dist/es → lib}/logger/structured-json-log-message-formatter.js +0 -0
  294. /package/{dist/types → lib}/third-party/google/google-recaptcha-ratchet.d.ts +0 -0
  295. /package/{dist/types → lib}/transform/transform-rule.d.ts +0 -0
  296. /package/{dist/types → lib}/tx/transaction-final-state.d.ts +0 -0
  297. /package/{dist/es → lib}/tx/transaction-final-state.js +0 -0
  298. /package/{dist/types → lib}/tx/transaction-step.d.ts +0 -0
@@ -0,0 +1,39 @@
1
+ import { DurationRatchet } from './duration-ratchet.js';
2
+ import { DateTime } from 'luxon';
3
+ describe('#formatMsDuration', function () {
4
+ it('should format less than one second', function () {
5
+ const result = DurationRatchet.formatMsDuration(409, true);
6
+ expect(result).toEqual('00h00m00.409s');
7
+ });
8
+ it('should format more than one day', function () {
9
+ const result = DurationRatchet.formatMsDuration(1000 * 60 * 60 * 123, true);
10
+ expect(result).toEqual('5d03h00m00.000s');
11
+ });
12
+ });
13
+ describe('#colonFormatMsDuration', function () {
14
+ it('should format less than one second', function () {
15
+ const result = DurationRatchet.colonFormatMsDuration(409, true);
16
+ expect(result).toEqual('00:00:00.409');
17
+ });
18
+ it('should format more than ten hours', function () {
19
+ const result = DurationRatchet.colonFormatMsDuration(1000 * 60 * 60 * 11, false);
20
+ expect(result).toEqual('11:00:00');
21
+ });
22
+ it('should format more than one hundred hours', function () {
23
+ const result = DurationRatchet.colonFormatMsDuration(1000 * 60 * 60 * 123, false);
24
+ expect(result).toEqual('123:00:00');
25
+ });
26
+ it('should format 15 seconds', function () {
27
+ const result = DurationRatchet.colonFormatMsDuration(15000, false);
28
+ expect(result).toEqual('00:00:15');
29
+ });
30
+ });
31
+ describe('#createSteps', function () {
32
+ it('should create steps', function () {
33
+ const tt = DateTime.fromFormat('2019-01-01', 'yyyy-MM-dd');
34
+ const startEpochMS = DateTime.fromFormat('2019-01-01', 'yyyy-MM-dd').toJSDate().getTime();
35
+ const endEpochMS = DateTime.fromFormat('2019-01-05', 'yyyy-MM-dd').toJSDate().getTime();
36
+ const steps = DurationRatchet.createSteps(startEpochMS, endEpochMS, 'etc/GMT', 'yyyy-MM-dd', { days: 1 });
37
+ expect(steps.length).toEqual(4);
38
+ });
39
+ });
@@ -0,0 +1,5 @@
1
+ export declare class EnumRatchet {
2
+ static listEnumKeys(enumeration: any): string[];
3
+ static keyToEnum<T>(enumeration: any, val: string, caseSensitive?: boolean): T;
4
+ static parseCsvToEnumArray<T>(enumeration: any, input: string): T[];
5
+ }
@@ -1,5 +1,5 @@
1
1
  import { $enum } from 'ts-enum-util';
2
- import { StringRatchet } from './string-ratchet';
2
+ import { StringRatchet } from './string-ratchet.js';
3
3
  export class EnumRatchet {
4
4
  static listEnumKeys(enumeration) {
5
5
  const rval = $enum(enumeration).getValues();
@@ -0,0 +1,5 @@
1
+ export declare enum TestEnum {
2
+ A = "a",
3
+ B = "b",
4
+ C = "c"
5
+ }
@@ -0,0 +1,31 @@
1
+ import { EnumRatchet } from './enum-ratchet.js';
2
+ describe('#enumRatchet', function () {
3
+ it('should list keys', async () => {
4
+ const keys = EnumRatchet.listEnumKeys(TestEnum);
5
+ expect(keys).toBeTruthy();
6
+ expect(keys.length).toBeGreaterThan(1);
7
+ });
8
+ it('should find key case insensitive', async () => {
9
+ const t1 = EnumRatchet.keyToEnum(TestEnum, 'a');
10
+ const t2 = EnumRatchet.keyToEnum(TestEnum, 'b');
11
+ const t3 = EnumRatchet.keyToEnum(TestEnum, 'A', true);
12
+ const t4 = EnumRatchet.keyToEnum(TestEnum, 'A');
13
+ const fixed = TestEnum.A;
14
+ expect(t1).toBeTruthy();
15
+ expect(t2).toBeTruthy();
16
+ expect(t3).toBeNull();
17
+ expect(t4).toEqual(fixed);
18
+ expect(t4 === fixed).toBeTruthy();
19
+ });
20
+ it('should parse a csv of enums', async () => {
21
+ const vals = EnumRatchet.parseCsvToEnumArray(TestEnum, 'a, b');
22
+ expect(vals).toBeTruthy();
23
+ expect(vals.length).toEqual(2);
24
+ });
25
+ });
26
+ export var TestEnum;
27
+ (function (TestEnum) {
28
+ TestEnum["A"] = "a";
29
+ TestEnum["B"] = "b";
30
+ TestEnum["C"] = "c";
31
+ })(TestEnum || (TestEnum = {}));
@@ -1,4 +1,4 @@
1
- import { Logger } from '../logger/logger';
1
+ import { Logger } from '../logger/logger.js';
2
2
  import util from 'util';
3
3
  export class ErrorRatchet {
4
4
  static safeStringifyErr(err, log = true) {
@@ -0,0 +1,20 @@
1
+ import { ErrorRatchet } from './error-ratchet.js';
2
+ describe('#errorRatchet', function () {
3
+ it('should cast to error', async () => {
4
+ const e1 = new Error('test1');
5
+ const e2 = 'test2';
6
+ const e1p = ErrorRatchet.asErr(e1);
7
+ const e2p = ErrorRatchet.asErr(e2);
8
+ const en = ErrorRatchet.asErr(null);
9
+ expect(en).toBeNull();
10
+ expect(e1p).toEqual(e1);
11
+ expect(e2p).not.toEqual(e2);
12
+ expect(e2p instanceof Error).toBeTruthy();
13
+ });
14
+ it('should correctly stringify', async () => {
15
+ const flag = 'test1';
16
+ const e1 = new Error(flag);
17
+ const out = ErrorRatchet.safeStringifyErr(e1);
18
+ expect(out).toEqual(flag);
19
+ });
20
+ });
@@ -0,0 +1,4 @@
1
+ export declare class EsmRatchet {
2
+ static fetchDirName(): string;
3
+ static fetchFileName(): string;
4
+ }
@@ -0,0 +1,11 @@
1
+ import url from 'url';
2
+ export class EsmRatchet {
3
+ static fetchDirName() {
4
+ const rval = url.fileURLToPath(new URL('.', import.meta.url));
5
+ return rval;
6
+ }
7
+ static fetchFileName() {
8
+ const rval = url.fileURLToPath(import.meta.url);
9
+ return rval;
10
+ }
11
+ }
@@ -1,4 +1,4 @@
1
- import { LoggerLevelName } from '../logger/logger-level-name';
1
+ import { LoggerLevelName } from '../logger/logger-level-name.js';
2
2
  export declare class ExpiringObject<T> {
3
3
  private _config;
4
4
  private _cacheObject;
@@ -1,7 +1,11 @@
1
- import { Logger } from '../logger/logger';
2
- import { ErrorRatchet } from './error-ratchet';
3
- import { LoggerLevelName } from '../logger/logger-level-name';
1
+ import { Logger } from '../logger/logger.js';
2
+ import { ErrorRatchet } from './error-ratchet.js';
3
+ import { LoggerLevelName } from '../logger/logger-level-name.js';
4
4
  export class ExpiringObject {
5
+ _config;
6
+ _cacheObject;
7
+ _lastUpdatedEpochMS;
8
+ _timeRemainingMS;
5
9
  constructor(inputConfig) {
6
10
  this._config = Object.assign({}, this.defaultConfig(), inputConfig || {});
7
11
  if (this._config.overrideTimeRemainingMS && this._config.timeToLiveMS) {
@@ -21,7 +25,7 @@ export class ExpiringObject {
21
25
  initialValue: null,
22
26
  logLevel: LoggerLevelName.debug,
23
27
  overrideTimeRemainingMS: null,
24
- timeToLiveMS: 1000 * 60,
28
+ timeToLiveMS: 1_000 * 60,
25
29
  };
26
30
  return rval;
27
31
  }
@@ -60,4 +64,9 @@ export class ExpiringObject {
60
64
  }
61
65
  }
62
66
  export class ExpiringObjectConfig {
67
+ timeToLiveMS;
68
+ generator;
69
+ initialValue;
70
+ logLevel;
71
+ overrideTimeRemainingMS;
63
72
  }
@@ -0,0 +1,51 @@
1
+ import { ExpiringObject } from './expiring-object.js';
2
+ import { PromiseRatchet } from './promise-ratchet.js';
3
+ import { LoggerLevelName } from '../logger/logger-level-name.js';
4
+ describe('#expiringObject', function () {
5
+ it('should default the object', async () => {
6
+ const expObject = new ExpiringObject({
7
+ initialValue: 7,
8
+ timeToLiveMS: 50_000,
9
+ logLevel: LoggerLevelName.info,
10
+ });
11
+ const val = await expObject.fetch();
12
+ expect(val).toEqual(7);
13
+ });
14
+ it('should expire the object', async () => {
15
+ const expObject = new ExpiringObject({
16
+ initialValue: 7,
17
+ timeToLiveMS: 100,
18
+ logLevel: LoggerLevelName.info,
19
+ });
20
+ const val = await expObject.fetch();
21
+ expect(val).toEqual(7);
22
+ await PromiseRatchet.wait(101);
23
+ const val2 = await expObject.fetch();
24
+ expect(val2).toBeNull();
25
+ });
26
+ it('should regen the object', async () => {
27
+ const expObject = new ExpiringObject({
28
+ initialValue: 7,
29
+ timeToLiveMS: 100,
30
+ generator: async () => 8,
31
+ logLevel: LoggerLevelName.info,
32
+ });
33
+ const val = await expObject.fetch();
34
+ expect(val).toEqual(7);
35
+ await PromiseRatchet.wait(101);
36
+ const val2 = await expObject.fetch();
37
+ expect(val2).toEqual(8);
38
+ });
39
+ it('should return time remaining', async () => {
40
+ const expObject = new ExpiringObject({
41
+ initialValue: 7,
42
+ timeToLiveMS: 10_000,
43
+ logLevel: LoggerLevelName.info,
44
+ });
45
+ const val = await expObject.fetch();
46
+ expect(val).toEqual(7);
47
+ const rem = await expObject.fetchCacheObjectTimeRemainingMS();
48
+ expect(rem).toBeGreaterThan(0);
49
+ expect(rem).toBeLessThanOrEqual(10_000);
50
+ });
51
+ });
@@ -1,7 +1,7 @@
1
- import { RequireRatchet } from './require-ratchet';
2
- import { NumberRatchet } from './number-ratchet';
3
- import { ErrorRatchet } from './error-ratchet';
4
- import { Logger } from '../logger/logger';
1
+ import { RequireRatchet } from './require-ratchet.js';
2
+ import { NumberRatchet } from './number-ratchet.js';
3
+ import { ErrorRatchet } from './error-ratchet.js';
4
+ import { Logger } from '../logger/logger.js';
5
5
  export class GeolocationRatchet {
6
6
  constructor() { }
7
7
  static distanceBetweenLocations(lat1, lon1, lat2, lon2, unit = 'M') {
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,74 @@
1
+ import { GeolocationRatchet } from './geolocation-ratchet.js';
2
+ import fs from 'fs';
3
+ import { NumberRatchet } from './number-ratchet.js';
4
+ import path from 'path';
5
+ import { EsmRatchet } from './esm-ratchet.js';
6
+ describe('#geolocationRatchet', function () {
7
+ it('should canonicalize', function () {
8
+ expect(GeolocationRatchet.combineBounds([])).toBeNull();
9
+ expect(GeolocationRatchet.combineBounds(null)).toBeNull();
10
+ });
11
+ it('should canonicalize', function () {
12
+ const bounds = {
13
+ origin: {
14
+ lat: 4,
15
+ lng: 3,
16
+ },
17
+ extent: {
18
+ lat: 2,
19
+ lng: 5,
20
+ },
21
+ };
22
+ const result = GeolocationRatchet.canonicalizeBounds(bounds);
23
+ expect(result.origin.lat).toEqual(2);
24
+ expect(result.origin.lng).toEqual(3);
25
+ expect(result.extent.lat).toEqual(4);
26
+ expect(result.extent.lng).toEqual(5);
27
+ });
28
+ it('should calc point in bounds', function () {
29
+ const input = fs
30
+ .readFileSync(path.join(EsmRatchet.fetchDirName(), '../../../../test-data/sample_geo_locations.csv'))
31
+ .toString();
32
+ const locations = input
33
+ .split('\n')
34
+ .map((line) => {
35
+ const vals = line.split(',');
36
+ if (!!vals && vals.length === 2) {
37
+ return {
38
+ lat: NumberRatchet.safeNumber(vals[0]),
39
+ lng: NumberRatchet.safeNumber(vals[1]),
40
+ };
41
+ }
42
+ else {
43
+ return null;
44
+ }
45
+ })
46
+ .filter((s) => !!s);
47
+ const bounds = locations.map((l) => GeolocationRatchet.locationToBounds(l, 10));
48
+ const mapping = GeolocationRatchet.buildRatchetLocationBoundsMap(bounds);
49
+ const testPoint1 = locations[100];
50
+ const testPoint2 = { lng: 5, lat: 5 };
51
+ const testPoint3 = {
52
+ lat: 40.7566,
53
+ lng: -73.9887,
54
+ };
55
+ const testPoint4 = {
56
+ lat: 33.74616,
57
+ lng: -84.3708,
58
+ };
59
+ const testPoint5 = {
60
+ lat: 37.790336,
61
+ lng: -122.405399,
62
+ };
63
+ const pt1In = GeolocationRatchet.pointInAnyBound(testPoint1, bounds);
64
+ const pt2In = GeolocationRatchet.pointInAnyBound(testPoint2, bounds);
65
+ const pt3In = GeolocationRatchet.pointInAnyBound(testPoint3, bounds);
66
+ const pt4In = GeolocationRatchet.pointInAnyBound(testPoint4, bounds);
67
+ const pt5In = GeolocationRatchet.pointInRatchetLocationBoundsMap(testPoint5, mapping);
68
+ expect(pt1In).toBeTruthy();
69
+ expect(pt2In).toBeFalsy();
70
+ expect(pt3In).toBeTruthy();
71
+ expect(pt4In).toBeTruthy();
72
+ expect(pt5In).toBeTruthy();
73
+ });
74
+ });
@@ -1,6 +1,6 @@
1
- import { ErrorRatchet } from './error-ratchet';
2
- import { RequireRatchet } from './require-ratchet';
3
- import { Logger } from '../logger/logger';
1
+ import { ErrorRatchet } from './error-ratchet.js';
2
+ import { RequireRatchet } from './require-ratchet.js';
3
+ import { Logger } from '../logger/logger.js';
4
4
  export class GlobalRatchet {
5
5
  constructor() { }
6
6
  static fetchGlobalRecord(returnNullOnNone) {
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ import { GlobalRatchet } from './global-ratchet.js';
2
+ import { StringRatchet } from './string-ratchet.js';
3
+ describe('#globalRatchet', function () {
4
+ it('fetch and set global variables', async () => {
5
+ const tester = StringRatchet.createType4Guid();
6
+ const tester2 = StringRatchet.createType4Guid();
7
+ process.env['GLOBALTEST'] = tester;
8
+ const value = GlobalRatchet.fetchGlobalVar('GLOBALTEST');
9
+ expect(value).toEqual(tester);
10
+ GlobalRatchet.setGlobalVar('GLOBALTEST', tester2);
11
+ const value2 = GlobalRatchet.fetchGlobalVar('GLOBALTEST');
12
+ expect(value2).toEqual(tester2);
13
+ });
14
+ });
@@ -1,2 +1,4 @@
1
1
  export class KeyValue {
2
+ key;
3
+ value;
2
4
  }
@@ -0,0 +1,3 @@
1
+ export interface LastSuccessProvider {
2
+ lastSuccess(): number;
3
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,4 @@
1
- import { KeyValue } from './key-value';
1
+ import { KeyValue } from './key-value.js';
2
2
  export declare class MapRatchet {
3
3
  static expandNestedKeys<T>(src: any): T;
4
4
  static mapByUniqueProperty<T, R>(input: T[], propName: string): Map<R, T>;
@@ -1,6 +1,6 @@
1
- import { Logger } from '../logger/logger';
2
- import { ErrorRatchet } from './error-ratchet';
3
- import { set } from 'lodash';
1
+ import { Logger } from '../logger/logger.js';
2
+ import { ErrorRatchet } from './error-ratchet.js';
3
+ import { set } from 'lodash-es';
4
4
  export class MapRatchet {
5
5
  static expandNestedKeys(src) {
6
6
  const rval = {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,90 @@
1
+ import { MapRatchet } from './map-ratchet.js';
2
+ describe('#toKeyValueList', function () {
3
+ it('should expand a maps nested keys', function () {
4
+ const test = { 'a.b': 'c', 'c.d[0].e': 2 };
5
+ const out = MapRatchet.expandNestedKeys(test);
6
+ expect(out).toBeTruthy();
7
+ expect(out.a).toBeTruthy();
8
+ expect(out.a.b).toBeTruthy();
9
+ expect(out.a.b).toEqual('c');
10
+ expect(out.c).toBeTruthy();
11
+ expect(out.c.d).toBeTruthy();
12
+ expect(out.c.d.length).toEqual(1);
13
+ expect(out.c.d[0].e).toBeTruthy();
14
+ expect(out.c.d[0].e).toEqual(2);
15
+ });
16
+ it('should convert a map to a key-value list and back', function () {
17
+ const test = { key1: 'value1', key2: 'value2' };
18
+ const kvl = MapRatchet.toKeyValueList(test);
19
+ expect(kvl.length).toEqual(2);
20
+ const back = MapRatchet.fromKeyValueList(kvl);
21
+ expect(back['key1']).toEqual('value1');
22
+ expect(back['key2']).toEqual('value2');
23
+ });
24
+ it('should remove null and empty strings but not 0', function () {
25
+ const test = {
26
+ key1: '',
27
+ key2: null,
28
+ key3: 0,
29
+ key4: 'fine',
30
+ key5: {
31
+ key6: null,
32
+ key7: 'also_fine',
33
+ },
34
+ };
35
+ const clean = MapRatchet.cleanup(test);
36
+ expect(Object.keys(clean).length).toEqual(3);
37
+ expect(Object.keys(clean).indexOf('key1')).toEqual(-1);
38
+ expect(Object.keys(clean).indexOf('key2')).toEqual(-1);
39
+ expect(Object.keys(clean).indexOf('key3')).toBeGreaterThan(-1);
40
+ expect(Object.keys(clean).indexOf('key4')).toBeGreaterThan(-1);
41
+ expect(Object.keys(clean).indexOf('key5')).toBeGreaterThan(-1);
42
+ expect(clean['key5']['key7']).toEqual('also_fine');
43
+ });
44
+ it('should extract values ignoring case', function () {
45
+ const test = {
46
+ 'this-Test': 'a',
47
+ test22: 'b',
48
+ };
49
+ expect(MapRatchet.extractValueFromMapIgnoreCase(test, 'THIS-TEST')).toEqual('a');
50
+ expect(MapRatchet.extractValueFromMapIgnoreCase(test, 'tEst22')).toEqual('b');
51
+ });
52
+ it('should group values', function () {
53
+ const test = [
54
+ {
55
+ id: 1,
56
+ type: 'a',
57
+ },
58
+ {
59
+ id: 2,
60
+ type: 'a',
61
+ },
62
+ {
63
+ id: 3,
64
+ type: 'b',
65
+ },
66
+ ];
67
+ const grouped = MapRatchet.groupByProperty(test, 'type');
68
+ expect(grouped).toBeTruthy();
69
+ const aGroup = grouped.get('a');
70
+ expect(aGroup).toBeTruthy();
71
+ expect(aGroup.length).toEqual(2);
72
+ expect(grouped.has('b')).toBeTruthy();
73
+ expect(grouped.has('c')).toBeFalsy();
74
+ });
75
+ it('should fetch a value with a case-insensitive key', function () {
76
+ const testOb = {
77
+ test1: 'a',
78
+ Test2: 'b',
79
+ test3: 'c',
80
+ Test3: 'd',
81
+ };
82
+ expect(MapRatchet.caseInsensitiveAccess(null, null)).toBeNull();
83
+ expect(MapRatchet.caseInsensitiveAccess({}, null)).toBeNull();
84
+ expect(MapRatchet.caseInsensitiveAccess(null, 'a')).toBeNull();
85
+ expect(MapRatchet.caseInsensitiveAccess(testOb, 'test1')).toEqual('a');
86
+ expect(MapRatchet.caseInsensitiveAccess(testOb, 'test2')).toEqual('b');
87
+ expect(MapRatchet.caseInsensitiveAccess(testOb, 'TEST2')).toEqual('b');
88
+ expect(MapRatchet.caseInsensitiveAccess(testOb, 'test3')).toEqual('c');
89
+ });
90
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,7 @@
1
+ import { PromiseRatchet } from './promise-ratchet.js';
2
+ import { No } from './no.js';
3
+ describe('#no', function () {
4
+ it('should do nothing', () => {
5
+ PromiseRatchet.wait(100).then(No.op);
6
+ });
7
+ });
@@ -1,6 +1,7 @@
1
- import { Logger } from '../logger/logger';
2
- import { RequireRatchet } from './require-ratchet';
1
+ import { Logger } from '../logger/logger.js';
2
+ import { RequireRatchet } from './require-ratchet.js';
3
3
  export class NumberRatchet {
4
+ static MAX_LEADING_ZEROS_FORMAT_LENGTH = 1000;
4
5
  static toFixedDecimalNumber(input, placesAfterPoint) {
5
6
  const v = NumberRatchet.safeNumber(input);
6
7
  return v === null || v === undefined ? v : NumberRatchet.safeNumber(v.toFixed(placesAfterPoint));
@@ -152,4 +153,3 @@ export class NumberRatchet {
152
153
  return rval;
153
154
  }
154
155
  }
155
- NumberRatchet.MAX_LEADING_ZEROS_FORMAT_LENGTH = 1000;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,118 @@
1
+ import { NumberRatchet } from './number-ratchet.js';
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+ import { EsmRatchet } from './esm-ratchet.js';
5
+ describe('#toFixedDecimalNumber', function () {
6
+ it('should convert "5.1234 to 5.12', function () {
7
+ expect(NumberRatchet.toFixedDecimalNumber(5.1234, 2)).toEqual(5.12);
8
+ expect(NumberRatchet.toFixedDecimalNumber('5.1234', 2)).toEqual(5.12);
9
+ });
10
+ it('should convert "5.5678 to 5.57', function () {
11
+ expect(NumberRatchet.toFixedDecimalNumber(5.5678, 2)).toEqual(5.57);
12
+ expect(NumberRatchet.toFixedDecimalNumber('5.5678', 2)).toEqual(5.57);
13
+ });
14
+ });
15
+ describe('#leadingZeros', function () {
16
+ it('should convert "5" to 05', function () {
17
+ const result = NumberRatchet.leadingZeros('5', 2);
18
+ expect(result).toEqual('05');
19
+ });
20
+ it('should leave 166 alone', function () {
21
+ const result = NumberRatchet.leadingZeros('166', 2);
22
+ expect(result).toEqual('166');
23
+ });
24
+ });
25
+ describe('#safeToNumber', function () {
26
+ it('should convert "55" to 55', function () {
27
+ const result = NumberRatchet.safeNumber('55');
28
+ expect(result).toEqual(55);
29
+ });
30
+ it('should leave 66 alone', function () {
31
+ const result = NumberRatchet.safeNumber(66);
32
+ expect(result).toEqual(66);
33
+ });
34
+ it('should return the default when it cannot parse', function () {
35
+ const result = NumberRatchet.safeNumber({ test: 'test' }, 42);
36
+ expect(result).toEqual(42);
37
+ });
38
+ it('should return the default for the empty string', function () {
39
+ const result = NumberRatchet.safeNumber({ test: '' }, 42);
40
+ expect(result).toEqual(42);
41
+ });
42
+ it('should return the default for null/undefined if set true', function () {
43
+ const result = NumberRatchet.safeNumber(null, 42, true);
44
+ expect(result).toEqual(42);
45
+ const result2 = NumberRatchet.safeNumber(undefined, 46, true);
46
+ expect(result2).toEqual(46);
47
+ });
48
+ it('should return the passed value for null/undefined if set false', function () {
49
+ const result = NumberRatchet.safeNumber(null, 42, false);
50
+ expect(result).toEqual(null);
51
+ const result2 = NumberRatchet.safeNumber(undefined, 46, false);
52
+ expect(result2).toEqual(undefined);
53
+ });
54
+ it('should return the passed value for null/undefined if not set', function () {
55
+ const result = NumberRatchet.safeNumber(null, 42);
56
+ expect(result).toEqual(null);
57
+ const result2 = NumberRatchet.safeNumber(undefined, 46);
58
+ expect(result2).toEqual(undefined);
59
+ });
60
+ });
61
+ describe('#parseCSV', function () {
62
+ it('should convert "1,2,3" to [1,2,3]', function () {
63
+ const result = NumberRatchet.numberCSVToList('1,2,3');
64
+ expect(result.length).toEqual(3);
65
+ });
66
+ it('should convert " 1, 2,3 " to [1,2,3]', function () {
67
+ const result = NumberRatchet.numberCSVToList(' 1, 2,3 ');
68
+ expect(result.length).toEqual(3);
69
+ });
70
+ it('should convert " a1, 2,b " to [2]', function () {
71
+ const result = NumberRatchet.numberCSVToList(' a1, 2,b ');
72
+ expect(result.length).toEqual(1);
73
+ expect(result[0]).toEqual(2);
74
+ });
75
+ });
76
+ describe('#fitToWindow', function () {
77
+ it('should fit input to the window', function () {
78
+ expect(NumberRatchet.fitToWindow(5, 8, 10)).toEqual(9);
79
+ expect(NumberRatchet.fitToWindow(8, 2, 10)).toEqual(8);
80
+ expect(NumberRatchet.fitToWindow(8, 9, 9)).toEqual(9);
81
+ expect(NumberRatchet.fitToWindow(12, 2, 10)).toEqual(4);
82
+ });
83
+ });
84
+ describe('#groupNumbersIntoContiguousRanges', function () {
85
+ it('should group numbers', function () {
86
+ let input = JSON.parse(fs.readFileSync(path.join(EsmRatchet.fetchDirName(), '../../../../test-data/number_set.json')).toString());
87
+ input = input.map((i) => NumberRatchet.safeNumber(i));
88
+ const grouped = NumberRatchet.groupNumbersIntoContiguousRanges(input, 5);
89
+ expect(grouped).toBeTruthy();
90
+ });
91
+ });
92
+ describe('#distributeItemsEvenly', function () {
93
+ it('should distribute evenly', function () {
94
+ const test1 = NumberRatchet.distributeItemsEvenly(4, 6);
95
+ expect(test1).toBeTruthy();
96
+ const test2 = NumberRatchet.distributeItemsEvenly(12, 6);
97
+ expect(test2).toBeTruthy();
98
+ const test3 = NumberRatchet.distributeItemsEvenly(5, 6);
99
+ expect(test3).toBeTruthy();
100
+ const test4 = NumberRatchet.distributeItemsEvenly(192, 11);
101
+ expect(test4).toBeTruthy();
102
+ const test5 = NumberRatchet.distributeItemsEvenly(11, 192);
103
+ expect(test5).toBeTruthy();
104
+ });
105
+ });
106
+ describe('#createRange', function () {
107
+ it('should create ranges', function () {
108
+ const test1 = NumberRatchet.createRange(0, 5, 1);
109
+ expect(test1).toBeTruthy();
110
+ expect(test1.length).toEqual(5);
111
+ const test2 = NumberRatchet.createRange(1, 5, 1);
112
+ expect(test2).toBeTruthy();
113
+ expect(test2.length).toEqual(4);
114
+ const test3 = NumberRatchet.createRange(0, 10, 2);
115
+ expect(test3).toBeTruthy();
116
+ expect(test3.length).toEqual(5);
117
+ });
118
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,18 @@
1
+ import { TimeoutToken } from './timeout-token.js';
2
+ import { LoggerLevelName } from '../logger/logger-level-name.js';
3
+ export declare class PromiseRatchet {
4
+ static resolveOnEvent<T>(evtSrc: any, okEvtNames: string[], errEvtNames?: string[], rval?: T): Promise<T>;
5
+ static timeout<T>(srcPromise: Promise<T>, title: string, timeoutMS: number): Promise<T | TimeoutToken>;
6
+ static createTimeoutPromise(title: string, timeoutMS: number): Promise<TimeoutToken>;
7
+ static wait(time: number): Promise<void>;
8
+ static dumpResult(result: any, autoDebug?: boolean): void;
9
+ static dumpError(err: any, autoDebug?: boolean): void;
10
+ static logErrorAndReturnNull(err: any, autoDebug?: boolean): void;
11
+ static runPromiseAndDump<T>(promise: Promise<T>): void;
12
+ static waitFor(testFunction: (n: number) => any, expectedValue: any, intervalMS: number, maxCycles: number, label?: string, count?: number): Promise<boolean>;
13
+ static runBoundedParallel<T>(promiseFn: Function, params: any[][], context: any, maxConcurrent?: number, logLevel?: LoggerLevelName): Promise<T[]>;
14
+ static runBoundedParallelSingleParam<T>(promiseFn: Function, params: any[], context: any, maxConcurrent?: number, logLevel?: LoggerLevelName): Promise<T[]>;
15
+ static asyncForEachSerial(array: any[], callback: Function): Promise<void>;
16
+ static asyncForEachParallel(array: any[], callback: Function): Promise<void>;
17
+ private constructor();
18
+ }