@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.
- package/{dist/types → lib}/2d/line-2d.d.ts +1 -1
- package/{dist/types → lib}/2d/poly-line-2d.d.ts +1 -1
- package/{dist/types → lib}/2d/ratchet-2d.d.ts +4 -4
- package/{dist/es → lib}/2d/ratchet-2d.js +1 -1
- package/lib/2d/ratchet-2d.spec.js +117 -0
- package/{dist/types → lib}/build/ratchet-common-info.d.ts +1 -1
- package/{dist/types → lib}/histogram/histogram.d.ts +1 -4
- package/{dist/es → lib}/histogram/histogram.js +1 -3
- package/lib/histogram/histogram.spec.js +19 -0
- package/lib/jwt/common-jwt-token.d.ts +6 -0
- package/{dist/types → lib}/jwt/jwt-ratchet-like.d.ts +3 -6
- package/{dist/types → lib}/jwt/jwt-ratchet.d.ts +4 -13
- package/{dist/es → lib}/jwt/jwt-ratchet.js +12 -7
- package/lib/jwt/jwt-ratchet.spec.js +49 -0
- package/{dist/types → lib}/jwt/jwt-token-base.d.ts +0 -4
- package/lib/lang/array-ratchet.d.ts +14 -0
- package/{dist/es → lib}/lang/array-ratchet.js +2 -2
- package/lib/lang/array-ratchet.spec.js +68 -0
- package/{dist/types → lib}/lang/base64-ratchet.d.ts +1 -1
- package/{dist/es → lib}/lang/base64-ratchet.js +1 -1
- package/lib/lang/base64-ratchet.spec.js +28 -0
- package/{dist/es → lib}/lang/boolean-ratchet.js +1 -1
- package/lib/lang/boolean-ratchet.spec.js +81 -0
- package/{dist/types → lib}/lang/composite-last-success-provider.d.ts +1 -2
- package/{dist/es → lib}/lang/composite-last-success-provider.js +2 -0
- package/lib/lang/composite-last-success-provider.spec.js +26 -0
- package/{dist/es → lib}/lang/date-ratchet.js +5 -5
- package/lib/lang/date-ratchet.spec.js +21 -0
- package/{dist/es → lib}/lang/duration-ratchet.js +1 -1
- package/lib/lang/duration-ratchet.spec.js +39 -0
- package/lib/lang/enum-ratchet.d.ts +5 -0
- package/{dist/es → lib}/lang/enum-ratchet.js +1 -1
- package/lib/lang/enum-ratchet.spec.d.ts +5 -0
- package/lib/lang/enum-ratchet.spec.js +31 -0
- package/{dist/es → lib}/lang/error-ratchet.js +1 -1
- package/lib/lang/error-ratchet.spec.js +20 -0
- package/lib/lang/esm-ratchet.d.ts +4 -0
- package/lib/lang/esm-ratchet.js +11 -0
- package/{dist/types → lib}/lang/expiring-object.d.ts +1 -1
- package/{dist/es → lib}/lang/expiring-object.js +13 -4
- package/lib/lang/expiring-object.spec.js +51 -0
- package/{dist/es → lib}/lang/geolocation-ratchet.js +4 -4
- package/lib/lang/geolocation-ratchet.spec.d.ts +1 -0
- package/lib/lang/geolocation-ratchet.spec.js +74 -0
- package/{dist/es → lib}/lang/global-ratchet.js +3 -3
- package/lib/lang/global-ratchet.spec.d.ts +1 -0
- package/lib/lang/global-ratchet.spec.js +14 -0
- package/{dist/es → lib}/lang/key-value.js +2 -0
- package/lib/lang/last-success-provider.d.ts +3 -0
- package/lib/lang/last-success-provider.js +1 -0
- package/{dist/types → lib}/lang/map-ratchet.d.ts +1 -1
- package/{dist/es → lib}/lang/map-ratchet.js +3 -3
- package/lib/lang/map-ratchet.spec.d.ts +1 -0
- package/lib/lang/map-ratchet.spec.js +90 -0
- package/lib/lang/no.spec.d.ts +1 -0
- package/lib/lang/no.spec.js +7 -0
- package/{dist/es → lib}/lang/number-ratchet.js +3 -3
- package/lib/lang/number-ratchet.spec.d.ts +1 -0
- package/lib/lang/number-ratchet.spec.js +118 -0
- package/lib/lang/parsed-url.js +1 -0
- package/lib/lang/promise-ratchet.d.ts +18 -0
- package/{dist/es → lib}/lang/promise-ratchet.js +5 -5
- package/lib/lang/promise-ratchet.spec.d.ts +1 -0
- package/lib/lang/promise-ratchet.spec.js +74 -0
- package/{dist/es → lib}/lang/require-ratchet.js +1 -1
- package/lib/lang/require-ratchet.spec.d.ts +3 -0
- package/lib/lang/require-ratchet.spec.js +80 -0
- package/{dist/types → lib}/lang/stop-watch.d.ts +1 -1
- package/{dist/es → lib}/lang/stop-watch.js +9 -8
- package/{dist/es → lib}/lang/string-ratchet.js +2 -2
- package/lib/lang/string-ratchet.spec.d.ts +1 -0
- package/lib/lang/string-ratchet.spec.js +158 -0
- package/lib/lang/time-zone-ratchet.d.ts +19 -0
- package/{dist/es → lib}/lang/time-zone-ratchet.js +2 -1
- package/lib/lang/time-zone-ratchet.spec.d.ts +1 -0
- package/lib/lang/time-zone-ratchet.spec.js +40 -0
- package/{dist/types → lib}/lang/timeout-token.d.ts +1 -1
- package/{dist/es → lib}/lang/timeout-token.js +5 -3
- package/lib/lang/timeout-token.spec.d.ts +1 -0
- package/lib/lang/timeout-token.spec.js +9 -0
- package/{dist/types → lib}/lang/transform-ratchet.d.ts +1 -1
- package/{dist/es → lib}/lang/transform-ratchet.js +1 -1
- package/lib/lang/transform-ratchet.spec.d.ts +1 -0
- package/lib/lang/transform-ratchet.spec.js +118 -0
- package/lib/logger/classic-single-line-log-message-formatter.d.ts +6 -0
- package/{dist/types → lib}/logger/log-message-builder.d.ts +2 -2
- package/{dist/es → lib}/logger/log-message-builder.js +1 -0
- package/{dist/types → lib}/logger/log-message-formatter.d.ts +2 -2
- package/lib/logger/log-message-formatter.js +1 -0
- package/{dist/types → lib}/logger/log-message-processor.d.ts +1 -1
- package/lib/logger/log-message-processor.js +1 -0
- package/{dist/types → lib}/logger/log-message.d.ts +1 -1
- package/lib/logger/log-message.js +1 -0
- package/{dist/types → lib}/logger/log-snapshot.d.ts +1 -1
- package/lib/logger/log-snapshot.js +1 -0
- package/{dist/types → lib}/logger/logger-instance.d.ts +6 -6
- package/{dist/es → lib}/logger/logger-instance.js +15 -8
- package/{dist/types → lib}/logger/logger-meta.d.ts +1 -1
- package/lib/logger/logger-meta.js +1 -0
- package/{dist/types → lib}/logger/logger-options.d.ts +4 -4
- package/lib/logger/logger-options.js +1 -0
- package/{dist/types → lib}/logger/logger-ring-buffer.d.ts +2 -2
- package/{dist/es → lib}/logger/logger-ring-buffer.js +7 -6
- package/{dist/types → lib}/logger/logger-util.d.ts +2 -2
- package/{dist/es → lib}/logger/logger-util.js +10 -10
- package/lib/logger/logger-util.spec.d.ts +1 -0
- package/lib/logger/logger-util.spec.js +9 -0
- package/{dist/types → lib}/logger/logger.d.ts +7 -16
- package/{dist/es → lib}/logger/logger.js +14 -14
- package/lib/logger/logger.spec.d.ts +1 -0
- package/lib/logger/logger.spec.js +134 -0
- package/lib/logger/none-log-message-formatter.d.ts +6 -0
- package/lib/logger/structured-json-log-message-formatter.d.ts +6 -0
- package/{dist/types → lib}/network/browser-local-ip-provider.d.ts +1 -1
- package/{dist/es → lib}/network/browser-local-ip-provider.js +3 -3
- package/lib/network/browser-local-ip-provider.spec.d.ts +1 -0
- package/lib/network/browser-local-ip-provider.spec.js +16 -0
- package/{dist/types → lib}/network/fixed-local-ip-provider.d.ts +1 -1
- package/{dist/es → lib}/network/fixed-local-ip-provider.js +1 -0
- package/lib/network/local-ip-provider.d.ts +3 -0
- package/lib/network/local-ip-provider.js +1 -0
- package/{dist/types → lib}/network/network-ratchet.d.ts +1 -1
- package/{dist/es → lib}/network/network-ratchet.js +2 -2
- package/lib/network/network-ratchet.spec.d.ts +1 -0
- package/lib/network/network-ratchet.spec.js +13 -0
- package/{dist/types → lib}/stream/buffer-writable.d.ts +2 -2
- package/{dist/es → lib}/stream/buffer-writable.js +1 -1
- package/lib/stream/multi-stream.d.ts +7 -0
- package/lib/stream/multi-stream.js +12 -0
- package/{dist/types → lib}/stream/stream-ratchet.d.ts +2 -2
- package/{dist/es → lib}/stream/stream-ratchet.js +2 -2
- package/lib/stream/stream-ratchet.spec.d.ts +1 -0
- package/lib/stream/stream-ratchet.spec.js +13 -0
- package/{dist/types → lib}/stream/string-writable.d.ts +1 -1
- package/{dist/es → lib}/stream/string-writable.js +1 -1
- package/lib/stream/string-writable.spec.d.ts +1 -0
- package/lib/stream/string-writable.spec.js +12 -0
- package/{dist/es → lib}/third-party/google/google-recaptcha-ratchet.js +3 -3
- package/lib/third-party/google/google-recaptcha-ratchet.spec.d.ts +1 -0
- package/lib/third-party/google/google-recaptcha-ratchet.spec.js +20 -0
- package/{dist/types → lib}/third-party/twilio/twilio-ratchet.d.ts +0 -4
- package/{dist/es → lib}/third-party/twilio/twilio-ratchet.js +8 -5
- package/{dist/types → lib}/transform/built-in-transforms.d.ts +1 -1
- package/{dist/es → lib}/transform/built-in-transforms.js +2 -2
- package/lib/transform/transform-rule.js +1 -0
- package/{dist/types → lib}/tx/transaction-configuration.d.ts +2 -2
- package/lib/tx/transaction-configuration.js +1 -0
- package/{dist/types → lib}/tx/transaction-ratchet.d.ts +3 -3
- package/{dist/es → lib}/tx/transaction-ratchet.js +4 -4
- package/lib/tx/transaction-ratchet.spec.d.ts +1 -0
- package/lib/tx/transaction-ratchet.spec.js +130 -0
- package/{dist/types → lib}/tx/transaction-result.d.ts +1 -1
- package/lib/tx/transaction-result.js +1 -0
- package/lib/tx/transaction-step.js +1 -0
- package/package.json +11 -12
- package/dist/cjs/2d/line-2d.js +0 -2
- package/dist/cjs/2d/plane-2d.js +0 -2
- package/dist/cjs/2d/point-2d.js +0 -2
- package/dist/cjs/2d/poly-line-2d.js +0 -2
- package/dist/cjs/2d/ratchet-2d.js +0 -250
- package/dist/cjs/build/build-information.js +0 -2
- package/dist/cjs/build/ratchet-common-info.js +0 -18
- package/dist/cjs/histogram/histogram-entry.js +0 -2
- package/dist/cjs/histogram/histogram.js +0 -54
- package/dist/cjs/index.js +0 -74
- package/dist/cjs/jwt/common-jwt-token.js +0 -2
- package/dist/cjs/jwt/expired-jwt-handling.js +0 -9
- package/dist/cjs/jwt/jwt-ratchet-like.js +0 -2
- package/dist/cjs/jwt/jwt-ratchet.js +0 -164
- package/dist/cjs/jwt/jwt-token-base.js +0 -2
- package/dist/cjs/lang/array-ratchet.js +0 -87
- package/dist/cjs/lang/base64-ratchet.js +0 -49
- package/dist/cjs/lang/boolean-ratchet.js +0 -49
- package/dist/cjs/lang/composite-last-success-provider.js +0 -28
- package/dist/cjs/lang/date-ratchet.js +0 -33
- package/dist/cjs/lang/duration-ratchet.js +0 -46
- package/dist/cjs/lang/enum-ratchet.js +0 -34
- package/dist/cjs/lang/error-ratchet.js +0 -49
- package/dist/cjs/lang/expiring-object.js +0 -68
- package/dist/cjs/lang/geolocation-ratchet.js +0 -267
- package/dist/cjs/lang/global-ratchet.js +0 -48
- package/dist/cjs/lang/key-value.js +0 -6
- package/dist/cjs/lang/last-success-provider.js +0 -2
- package/dist/cjs/lang/map-ratchet.js +0 -168
- package/dist/cjs/lang/no.js +0 -8
- package/dist/cjs/lang/number-ratchet.js +0 -159
- package/dist/cjs/lang/parsed-url.js +0 -2
- package/dist/cjs/lang/promise-ratchet.js +0 -142
- package/dist/cjs/lang/require-ratchet.js +0 -60
- package/dist/cjs/lang/stop-watch.js +0 -117
- package/dist/cjs/lang/string-ratchet.js +0 -195
- package/dist/cjs/lang/time-zone-ratchet.js +0 -80
- package/dist/cjs/lang/timeout-token.js +0 -19
- package/dist/cjs/lang/transform-ratchet.js +0 -70
- package/dist/cjs/logger/classic-single-line-log-message-formatter.js +0 -18
- package/dist/cjs/logger/log-message-builder.js +0 -51
- package/dist/cjs/logger/log-message-format-type.js +0 -9
- package/dist/cjs/logger/log-message-formatter.js +0 -2
- package/dist/cjs/logger/log-message-processor.js +0 -2
- package/dist/cjs/logger/log-message.js +0 -2
- package/dist/cjs/logger/log-snapshot.js +0 -2
- package/dist/cjs/logger/logger-instance.js +0 -207
- package/dist/cjs/logger/logger-level-name.js +0 -12
- package/dist/cjs/logger/logger-meta.js +0 -2
- package/dist/cjs/logger/logger-options.js +0 -2
- package/dist/cjs/logger/logger-output-function.js +0 -9
- package/dist/cjs/logger/logger-ring-buffer.js +0 -76
- package/dist/cjs/logger/logger-util.js +0 -49
- package/dist/cjs/logger/logger.js +0 -139
- package/dist/cjs/logger/none-log-message-formatter.js +0 -9
- package/dist/cjs/logger/structured-json-log-message-formatter.js +0 -24
- package/dist/cjs/network/browser-local-ip-provider.js +0 -25
- package/dist/cjs/network/fixed-local-ip-provider.js +0 -12
- package/dist/cjs/network/local-ip-provider.js +0 -2
- package/dist/cjs/network/network-ratchet.js +0 -106
- package/dist/cjs/stream/buffer-writable.js +0 -20
- package/dist/cjs/stream/stream-ratchet.js +0 -72
- package/dist/cjs/stream/string-writable.js +0 -18
- package/dist/cjs/third-party/google/google-recaptcha-ratchet.js +0 -33
- package/dist/cjs/third-party/twilio/twilio-ratchet.js +0 -75
- package/dist/cjs/transform/built-in-transforms.js +0 -195
- package/dist/cjs/transform/transform-rule.js +0 -2
- package/dist/cjs/tx/transaction-configuration.js +0 -2
- package/dist/cjs/tx/transaction-final-state.js +0 -9
- package/dist/cjs/tx/transaction-ratchet.js +0 -80
- package/dist/cjs/tx/transaction-result.js +0 -2
- package/dist/cjs/tx/transaction-step.js +0 -2
- package/dist/es/index.js +0 -71
- package/dist/tsconfig.cjs.tsbuildinfo +0 -1
- package/dist/tsconfig.es.tsbuildinfo +0 -1
- package/dist/tsconfig.types.tsbuildinfo +0 -1
- package/dist/types/index.d.ts +0 -74
- package/dist/types/jwt/common-jwt-token.d.ts +0 -17
- package/dist/types/lang/array-ratchet.d.ts +0 -30
- package/dist/types/lang/enum-ratchet.d.ts +0 -12
- package/dist/types/lang/last-success-provider.d.ts +0 -4
- package/dist/types/lang/promise-ratchet.d.ts +0 -32
- package/dist/types/lang/time-zone-ratchet.d.ts +0 -50
- package/dist/types/logger/classic-single-line-log-message-formatter.d.ts +0 -6
- package/dist/types/logger/none-log-message-formatter.d.ts +0 -6
- package/dist/types/logger/structured-json-log-message-formatter.d.ts +0 -6
- package/dist/types/network/local-ip-provider.d.ts +0 -4
- /package/{dist/es → lib}/2d/line-2d.js +0 -0
- /package/{dist/types → lib}/2d/plane-2d.d.ts +0 -0
- /package/{dist/es → lib}/2d/plane-2d.js +0 -0
- /package/{dist/types → lib}/2d/point-2d.d.ts +0 -0
- /package/{dist/es → lib}/2d/point-2d.js +0 -0
- /package/{dist/es → lib}/2d/poly-line-2d.js +0 -0
- /package/{dist/es/build/build-information.js → lib/2d/ratchet-2d.spec.d.ts} +0 -0
- /package/{dist/types → lib}/build/build-information.d.ts +0 -0
- /package/{dist/es/histogram/histogram-entry.js → lib/build/build-information.js} +0 -0
- /package/{dist/es → lib}/build/ratchet-common-info.js +0 -0
- /package/{dist/types → lib}/histogram/histogram-entry.d.ts +0 -0
- /package/{dist/es/jwt/common-jwt-token.js → lib/histogram/histogram-entry.js} +0 -0
- /package/{dist/es/jwt/jwt-ratchet-like.js → lib/histogram/histogram.spec.d.ts} +0 -0
- /package/{dist/es/jwt/jwt-token-base.js → lib/index.d.ts} +0 -0
- /package/{dist/es/lang/last-success-provider.js → lib/index.js} +0 -0
- /package/{dist/es/lang/parsed-url.js → lib/jwt/common-jwt-token.js} +0 -0
- /package/{dist/types → lib}/jwt/expired-jwt-handling.d.ts +0 -0
- /package/{dist/es → lib}/jwt/expired-jwt-handling.js +0 -0
- /package/{dist/es/logger/log-message-formatter.js → lib/jwt/jwt-ratchet-like.js} +0 -0
- /package/{dist/es/logger/log-message-processor.js → lib/jwt/jwt-ratchet.spec.d.ts} +0 -0
- /package/{dist/es/logger/log-message.js → lib/jwt/jwt-token-base.js} +0 -0
- /package/{dist/es/logger/log-snapshot.js → lib/lang/array-ratchet.spec.d.ts} +0 -0
- /package/{dist/es/logger/logger-meta.js → lib/lang/base64-ratchet.spec.d.ts} +0 -0
- /package/{dist/types → lib}/lang/boolean-ratchet.d.ts +0 -0
- /package/{dist/es/logger/logger-options.js → lib/lang/boolean-ratchet.spec.d.ts} +0 -0
- /package/{dist/es/network/local-ip-provider.js → lib/lang/composite-last-success-provider.spec.d.ts} +0 -0
- /package/{dist/types → lib}/lang/date-ratchet.d.ts +0 -0
- /package/{dist/es/transform/transform-rule.js → lib/lang/date-ratchet.spec.d.ts} +0 -0
- /package/{dist/types → lib}/lang/duration-ratchet.d.ts +0 -0
- /package/{dist/es/tx/transaction-configuration.js → lib/lang/duration-ratchet.spec.d.ts} +0 -0
- /package/{dist/types → lib}/lang/error-ratchet.d.ts +0 -0
- /package/{dist/es/tx/transaction-result.js → lib/lang/error-ratchet.spec.d.ts} +0 -0
- /package/{dist/es/tx/transaction-step.js → lib/lang/expiring-object.spec.d.ts} +0 -0
- /package/{dist/types → lib}/lang/geolocation-ratchet.d.ts +0 -0
- /package/{dist/types → lib}/lang/global-ratchet.d.ts +0 -0
- /package/{dist/types → lib}/lang/key-value.d.ts +0 -0
- /package/{dist/types → lib}/lang/no.d.ts +0 -0
- /package/{dist/es → lib}/lang/no.js +0 -0
- /package/{dist/types → lib}/lang/number-ratchet.d.ts +0 -0
- /package/{dist/types → lib}/lang/parsed-url.d.ts +0 -0
- /package/{dist/types → lib}/lang/require-ratchet.d.ts +0 -0
- /package/{dist/types → lib}/lang/string-ratchet.d.ts +0 -0
- /package/{dist/es → lib}/logger/classic-single-line-log-message-formatter.js +0 -0
- /package/{dist/types → lib}/logger/log-message-format-type.d.ts +0 -0
- /package/{dist/es → lib}/logger/log-message-format-type.js +0 -0
- /package/{dist/types → lib}/logger/logger-level-name.d.ts +0 -0
- /package/{dist/es → lib}/logger/logger-level-name.js +0 -0
- /package/{dist/types → lib}/logger/logger-output-function.d.ts +0 -0
- /package/{dist/es → lib}/logger/logger-output-function.js +0 -0
- /package/{dist/es → lib}/logger/none-log-message-formatter.js +0 -0
- /package/{dist/es → lib}/logger/structured-json-log-message-formatter.js +0 -0
- /package/{dist/types → lib}/third-party/google/google-recaptcha-ratchet.d.ts +0 -0
- /package/{dist/types → lib}/transform/transform-rule.d.ts +0 -0
- /package/{dist/types → lib}/tx/transaction-final-state.d.ts +0 -0
- /package/{dist/es → lib}/tx/transaction-final-state.js +0 -0
- /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,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 = {}));
|
|
@@ -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,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,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:
|
|
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
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -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 {};
|
|
@@ -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
|
+
}
|