@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
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Point2d } from './point-2d';
|
|
2
|
-
import { Plane2d } from './plane-2d';
|
|
3
|
-
import { Line2d } from './line-2d';
|
|
4
|
-
import { PolyLine2d } from './poly-line-2d';
|
|
1
|
+
import { Point2d } from './point-2d.js';
|
|
2
|
+
import { Plane2d } from './plane-2d.js';
|
|
3
|
+
import { Line2d } from './line-2d.js';
|
|
4
|
+
import { PolyLine2d } from './poly-line-2d.js';
|
|
5
5
|
export declare class Ratchet2d {
|
|
6
6
|
private constructor();
|
|
7
7
|
static translateToOriginVector(points: Point2d[]): Point2d;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { Ratchet2d } from './ratchet-2d.js';
|
|
2
|
+
describe('#ratchet2d', function () {
|
|
3
|
+
it('should check for valid planes', function () {
|
|
4
|
+
expect(Ratchet2d.validPlane(null)).toEqual(false);
|
|
5
|
+
expect(Ratchet2d.validPlane({ width: null, height: null })).toEqual(false);
|
|
6
|
+
expect(Ratchet2d.validPlane({ width: 0, height: null })).toEqual(false);
|
|
7
|
+
expect(Ratchet2d.validPlane({ width: 0, height: 2 })).toEqual(false);
|
|
8
|
+
expect(Ratchet2d.validPlane({ width: 1, height: 7 })).toEqual(true);
|
|
9
|
+
});
|
|
10
|
+
it('should check for valid lines', function () {
|
|
11
|
+
expect(Ratchet2d.validLine(null)).toEqual(false);
|
|
12
|
+
expect(Ratchet2d.validLine({ p1: null, p2: null })).toEqual(false);
|
|
13
|
+
expect(Ratchet2d.validLine({ p1: { x: null, y: 0 }, p2: null })).toEqual(false);
|
|
14
|
+
expect(Ratchet2d.validLine({ p1: { x: 0, y: 0 }, p2: { x: 27, y: null } })).toEqual(false);
|
|
15
|
+
expect(Ratchet2d.validLine({ p1: { x: 0, y: 0 }, p2: { x: 27, y: 0 } })).toEqual(true);
|
|
16
|
+
expect(Ratchet2d.validLine({ p1: { x: 1, y: 0 }, p2: { x: 1, y: 0 } })).toEqual(false);
|
|
17
|
+
expect(Ratchet2d.validLine({ p1: { x: 0, y: 0 }, p2: { x: 27, y: 13 } })).toEqual(true);
|
|
18
|
+
});
|
|
19
|
+
it('should transform points from one plane to another (scale)', function () {
|
|
20
|
+
const plane1 = { height: 10, width: 10 };
|
|
21
|
+
const plane2 = { height: 100, width: 50 };
|
|
22
|
+
const p1 = { x: 5, y: 5 };
|
|
23
|
+
const out1 = Ratchet2d.transformPointToNewPlane(p1, plane1, plane2);
|
|
24
|
+
const out2 = Ratchet2d.transformPointToNewPlane(out1, plane2, plane1);
|
|
25
|
+
expect(out1.x).toEqual(25);
|
|
26
|
+
expect(out1.y).toEqual(50);
|
|
27
|
+
expect(out2.x).toEqual(p1.x);
|
|
28
|
+
expect(out2.y).toEqual(p1.y);
|
|
29
|
+
});
|
|
30
|
+
it('should transform points from one plane to another (mirror)', function () {
|
|
31
|
+
const plane1 = { height: 10, width: 10 };
|
|
32
|
+
const plane2 = { height: 10, width: 10, rightToLeft: true, topToBottom: true };
|
|
33
|
+
const p1 = { x: 2, y: 8 };
|
|
34
|
+
const out1 = Ratchet2d.transformPointToNewPlane(p1, plane1, plane2);
|
|
35
|
+
const out2 = Ratchet2d.transformPointToNewPlane(out1, plane2, plane1);
|
|
36
|
+
expect(out1.x).toEqual(7);
|
|
37
|
+
expect(out1.y).toEqual(1);
|
|
38
|
+
expect(out2.x).toEqual(p1.x);
|
|
39
|
+
expect(out2.y).toEqual(p1.y);
|
|
40
|
+
});
|
|
41
|
+
it('should check for containment', function () {
|
|
42
|
+
const plane = {
|
|
43
|
+
width: 100,
|
|
44
|
+
height: 100,
|
|
45
|
+
};
|
|
46
|
+
expect(Ratchet2d.planeContainsPoint({ x: -1, y: 10 }, plane)).toEqual(false);
|
|
47
|
+
expect(Ratchet2d.planeContainsPoint({ x: 101, y: 10 }, plane)).toEqual(false);
|
|
48
|
+
expect(Ratchet2d.planeContainsPoint({ x: 1, y: -10 }, plane)).toEqual(false);
|
|
49
|
+
expect(Ratchet2d.planeContainsPoint({ x: 10, y: 101 }, plane)).toEqual(false);
|
|
50
|
+
expect(Ratchet2d.planeContainsPoint({ x: 10, y: 100 }, plane)).toEqual(false);
|
|
51
|
+
expect(Ratchet2d.planeContainsPoint({ x: 1, y: 10 }, plane)).toEqual(true);
|
|
52
|
+
expect(Ratchet2d.planeContainsPoint({ x: 10, y: 10 }, plane)).toEqual(true);
|
|
53
|
+
expect(Ratchet2d.planeContainsPoints([
|
|
54
|
+
{ x: 10, y: 10 },
|
|
55
|
+
{ x: 100, y: 10 },
|
|
56
|
+
], plane)).toEqual(false);
|
|
57
|
+
expect(Ratchet2d.planeContainsPoints([
|
|
58
|
+
{ x: 10, y: 10 },
|
|
59
|
+
{ x: 11, y: 10 },
|
|
60
|
+
], plane)).toEqual(true);
|
|
61
|
+
expect(Ratchet2d.planeContainsLine({
|
|
62
|
+
p1: { x: 10, y: 10 },
|
|
63
|
+
p2: { x: 100, y: 10 },
|
|
64
|
+
}, plane)).toEqual(false);
|
|
65
|
+
expect(Ratchet2d.planeContainsLine({
|
|
66
|
+
p1: { x: 10, y: 10 },
|
|
67
|
+
p2: { x: 11, y: 10 },
|
|
68
|
+
}, plane)).toEqual(true);
|
|
69
|
+
});
|
|
70
|
+
it('should fit input to curve', function () {
|
|
71
|
+
const curve = [
|
|
72
|
+
{ x: 0, y: 50 },
|
|
73
|
+
{ x: 0.5, y: 50 },
|
|
74
|
+
{ x: 0.8, y: 60 },
|
|
75
|
+
{ x: 1, y: 70 },
|
|
76
|
+
{ x: 1.2, y: 80 },
|
|
77
|
+
{ x: 1.5, y: 90 },
|
|
78
|
+
{ x: 1.6, y: 91 },
|
|
79
|
+
{ x: 1.7, y: 92 },
|
|
80
|
+
{ x: 1.8, y: 93 },
|
|
81
|
+
{ x: 1.9, y: 94 },
|
|
82
|
+
{ x: 2, y: 95 },
|
|
83
|
+
{
|
|
84
|
+
x: 3,
|
|
85
|
+
y: 98,
|
|
86
|
+
},
|
|
87
|
+
{ x: 4, y: 99 },
|
|
88
|
+
{ x: 5, y: 100 },
|
|
89
|
+
];
|
|
90
|
+
expect(Ratchet2d.fitCurve(curve, -1)).toEqual(50);
|
|
91
|
+
expect(Ratchet2d.fitCurve(curve, 0)).toEqual(50);
|
|
92
|
+
expect(Ratchet2d.fitCurve(curve, 0.3)).toEqual(50);
|
|
93
|
+
expect(Ratchet2d.fitCurve(curve, 0.5)).toEqual(50);
|
|
94
|
+
expect(Ratchet2d.fitCurve(curve, 0.8)).toEqual(60);
|
|
95
|
+
expect(Ratchet2d.fitCurve(curve, 1)).toEqual(70);
|
|
96
|
+
expect(Ratchet2d.fitCurve(curve, 5)).toEqual(100);
|
|
97
|
+
expect(Ratchet2d.fitCurve(curve, 6)).toEqual(100);
|
|
98
|
+
expect(Ratchet2d.fitCurve(curve, 1.65)).toEqual(91.5);
|
|
99
|
+
});
|
|
100
|
+
it('rotate about origin', function () {
|
|
101
|
+
const points = [
|
|
102
|
+
{ x: 1, y: 0 },
|
|
103
|
+
{ x: 2, y: 1 },
|
|
104
|
+
{ x: 3, y: 2 },
|
|
105
|
+
{ x: 4, y: 3 },
|
|
106
|
+
{ x: 4, y: 1 },
|
|
107
|
+
{ x: 6, y: 1 },
|
|
108
|
+
];
|
|
109
|
+
const r1 = Ratchet2d.rotateRightAboutOrigin90Degrees(points);
|
|
110
|
+
expect(r1.length).toEqual(6);
|
|
111
|
+
const r3 = Ratchet2d.rotateRightAboutOrigin90Degrees(points, 3);
|
|
112
|
+
const r2 = Ratchet2d.rotateRightAboutOrigin90Degrees(points, 4);
|
|
113
|
+
expect(r2.length).toEqual(6);
|
|
114
|
+
expect(r2[0].x).toEqual(points[0].x);
|
|
115
|
+
expect(r2[0].y).toEqual(points[0].y);
|
|
116
|
+
});
|
|
117
|
+
});
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import { HistogramEntry } from './histogram-entry';
|
|
2
|
-
/**
|
|
3
|
-
* Implements a simple histogram (for each object, how many times does it appear)
|
|
4
|
-
*/
|
|
1
|
+
import { HistogramEntry } from './histogram-entry.js';
|
|
5
2
|
export declare class Histogram<T> {
|
|
6
3
|
private entries;
|
|
7
4
|
update(val: T, addValue?: number): void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Histogram } from './histogram.js';
|
|
2
|
+
describe('#histogram', function () {
|
|
3
|
+
it('should count the values correctly', function () {
|
|
4
|
+
const histogram = new Histogram();
|
|
5
|
+
histogram.update('a');
|
|
6
|
+
histogram.update('a');
|
|
7
|
+
histogram.update('b');
|
|
8
|
+
histogram.update('c');
|
|
9
|
+
expect(histogram.getTotalCount()).toEqual(4);
|
|
10
|
+
expect(histogram.countForValue('a')).toEqual(2);
|
|
11
|
+
expect(histogram.countForValue('b')).toEqual(1);
|
|
12
|
+
expect(histogram.countForValue('c')).toEqual(1);
|
|
13
|
+
expect(histogram.countForValue('d')).toEqual(0);
|
|
14
|
+
expect(histogram.percentForValue('a')).toEqual(0.5);
|
|
15
|
+
expect(histogram.percentForValue('b')).toEqual(0.25);
|
|
16
|
+
expect(histogram.percentForValue('c')).toEqual(0.25);
|
|
17
|
+
expect(histogram.percentForValue('d')).toEqual(0);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
import { JwtTokenBase } from './jwt-token-base';
|
|
2
|
-
import { LoggerLevelName } from '../logger/logger-level-name';
|
|
3
|
-
import { ExpiredJwtHandling } from './expired-jwt-handling';
|
|
4
|
-
/**
|
|
5
|
-
* Classes implementing this interface have Functions to help with creating and decoding JWTs
|
|
6
|
-
*/
|
|
1
|
+
import { JwtTokenBase } from './jwt-token-base.js';
|
|
2
|
+
import { LoggerLevelName } from '../logger/logger-level-name.js';
|
|
3
|
+
import { ExpiredJwtHandling } from './expired-jwt-handling.js';
|
|
7
4
|
export interface JwtRatchetLike {
|
|
8
5
|
get encryptionKeyPromise(): Promise<string | string[]>;
|
|
9
6
|
get decryptKeysPromise(): Promise<string[]>;
|
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
import { JwtTokenBase } from './jwt-token-base';
|
|
2
|
-
import { LoggerLevelName } from '../logger/logger-level-name';
|
|
3
|
-
import { ExpiredJwtHandling } from './expired-jwt-handling';
|
|
4
|
-
import { JwtRatchetLike } from './jwt-ratchet-like';
|
|
5
|
-
/**
|
|
6
|
-
* Functions to help with creating and decoding JWTs
|
|
7
|
-
*
|
|
8
|
-
* JWTRatchet accepts promises for its inputs for the simple reason that best practice dictates that the keys
|
|
9
|
-
* should never be in the code, which means it is likely somewhere else. That MIGHT be somewhere synchronous
|
|
10
|
-
* like an environmental variable, but it could very likely be someplace remote like a secure key store. By
|
|
11
|
-
* accepting promises here, we make it easy to do JwtRatchet construction in a place (like an IOT container)
|
|
12
|
-
* that itself must be synchronous
|
|
13
|
-
*/
|
|
1
|
+
import { JwtTokenBase } from './jwt-token-base.js';
|
|
2
|
+
import { LoggerLevelName } from '../logger/logger-level-name.js';
|
|
3
|
+
import { ExpiredJwtHandling } from './expired-jwt-handling.js';
|
|
4
|
+
import { JwtRatchetLike } from './jwt-ratchet-like.js';
|
|
14
5
|
export declare class JwtRatchet implements JwtRatchetLike {
|
|
15
6
|
private _encryptionKeyPromise;
|
|
16
7
|
private _decryptKeysPromise?;
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import jwt from 'jsonwebtoken';
|
|
2
|
-
import { RequireRatchet } from '../lang/require-ratchet';
|
|
3
|
-
import { Logger } from '../logger/logger';
|
|
4
|
-
import { StringRatchet } from '../lang/string-ratchet';
|
|
5
|
-
import { DurationRatchet } from '../lang/duration-ratchet';
|
|
6
|
-
import { LoggerLevelName } from '../logger/logger-level-name';
|
|
7
|
-
import { ExpiredJwtHandling } from './expired-jwt-handling';
|
|
2
|
+
import { RequireRatchet } from '../lang/require-ratchet.js';
|
|
3
|
+
import { Logger } from '../logger/logger.js';
|
|
4
|
+
import { StringRatchet } from '../lang/string-ratchet.js';
|
|
5
|
+
import { DurationRatchet } from '../lang/duration-ratchet.js';
|
|
6
|
+
import { LoggerLevelName } from '../logger/logger-level-name.js';
|
|
7
|
+
import { ExpiredJwtHandling } from './expired-jwt-handling.js';
|
|
8
8
|
export class JwtRatchet {
|
|
9
|
+
_encryptionKeyPromise;
|
|
10
|
+
_decryptKeysPromise;
|
|
11
|
+
_jtiGenerator;
|
|
12
|
+
_decryptOnlyKeyUseLogLevel;
|
|
13
|
+
_parseFailureLogLevel;
|
|
14
|
+
static EXPIRED_FLAG_NAME = '__jwtServiceExpiredFlag';
|
|
9
15
|
constructor(_encryptionKeyPromise, _decryptKeysPromise, _jtiGenerator = StringRatchet.createType4Guid, _decryptOnlyKeyUseLogLevel = LoggerLevelName.info, _parseFailureLogLevel = LoggerLevelName.debug) {
|
|
10
16
|
this._encryptionKeyPromise = _encryptionKeyPromise;
|
|
11
17
|
this._decryptKeysPromise = _decryptKeysPromise;
|
|
@@ -156,4 +162,3 @@ export class JwtRatchet {
|
|
|
156
162
|
}
|
|
157
163
|
}
|
|
158
164
|
}
|
|
159
|
-
JwtRatchet.EXPIRED_FLAG_NAME = '__jwtServiceExpiredFlag';
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { JwtRatchet } from './jwt-ratchet.js';
|
|
2
|
+
import { ExpiredJwtHandling } from './expired-jwt-handling.js';
|
|
3
|
+
describe('#jwtRatchet', function () {
|
|
4
|
+
it('should test expiration flag for a token with millisecond expiration', async () => {
|
|
5
|
+
const jwt = new JwtRatchet(Promise.resolve('test1234'), Promise.resolve([]));
|
|
6
|
+
const token1 = await jwt.createTokenString({ test: 1, exp: Date.now() - 100 }, null);
|
|
7
|
+
const output = await jwt.decodeToken(token1, ExpiredJwtHandling.ADD_FLAG);
|
|
8
|
+
expect(output).not.toBeNull();
|
|
9
|
+
expect(JwtRatchet.hasExpiredFlag(output)).toBeTruthy();
|
|
10
|
+
});
|
|
11
|
+
it('should test expiration calculation for a token', async () => {
|
|
12
|
+
const jwt = new JwtRatchet(Promise.resolve('test1234'), Promise.resolve([]));
|
|
13
|
+
const token1 = await jwt.createTokenString({ test: 1 }, 120);
|
|
14
|
+
const output = await JwtRatchet.secondsRemainingUntilExpiration(token1);
|
|
15
|
+
expect(output).not.toBeNull();
|
|
16
|
+
expect(output).toBeLessThan(121);
|
|
17
|
+
expect(output).toBeGreaterThan(115);
|
|
18
|
+
});
|
|
19
|
+
it('should test round-trip for a token', async () => {
|
|
20
|
+
const jwt = new JwtRatchet(Promise.resolve('test1234'), Promise.resolve([]));
|
|
21
|
+
const token1 = await jwt.createTokenString({ test: 1 }, 120);
|
|
22
|
+
const output = await jwt.decodeToken(token1);
|
|
23
|
+
expect(output).not.toBeNull();
|
|
24
|
+
expect(output['test']).toEqual(1);
|
|
25
|
+
});
|
|
26
|
+
it('should test round-trip for a token with array enc keys', async () => {
|
|
27
|
+
const jwt = new JwtRatchet(Promise.resolve(['test1234', 'test5678']), Promise.resolve([]));
|
|
28
|
+
const token1 = await jwt.createTokenString({ test: 1 }, 120);
|
|
29
|
+
const token2 = await jwt.createTokenString({ test: 1 }, 120);
|
|
30
|
+
const token3 = await jwt.createTokenString({ test: 1 }, 120);
|
|
31
|
+
const output1 = await jwt.decodeToken(token1);
|
|
32
|
+
const output2 = await jwt.decodeToken(token2);
|
|
33
|
+
const output3 = await jwt.decodeToken(token3);
|
|
34
|
+
expect(output1).not.toBeNull();
|
|
35
|
+
expect(output1['test']).toEqual(1);
|
|
36
|
+
expect(output2).not.toBeNull();
|
|
37
|
+
expect(output2['test']).toEqual(1);
|
|
38
|
+
expect(output3).not.toBeNull();
|
|
39
|
+
expect(output3['test']).toEqual(1);
|
|
40
|
+
});
|
|
41
|
+
it('should decode with a decode key', async () => {
|
|
42
|
+
const jwtOld = new JwtRatchet(Promise.resolve('oldKey'), Promise.resolve([]));
|
|
43
|
+
const jwtNew = new JwtRatchet(Promise.resolve('newKey'), Promise.resolve(['oldKey']));
|
|
44
|
+
const token1 = await jwtOld.createTokenString({ test: 1 }, 120);
|
|
45
|
+
const output = await jwtNew.decodeToken(token1);
|
|
46
|
+
expect(output).not.toBeNull();
|
|
47
|
+
expect(output['test']).toEqual(1);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare class ArrayRatchet {
|
|
2
|
+
static wrapElementsInArray(input: any[]): any[][];
|
|
3
|
+
static compareTwoArrays<T>(ar1: T[], ar2: T[], fn: ComparisonFunction<T>): MatchReport<T>;
|
|
4
|
+
static extractSubarrayFromSortedByNumberField<T>(input: T[], fieldDotPath: string, minInclusive: number, maxExclusive: number): T[];
|
|
5
|
+
static findSplit(input: any[], fieldDotPath: string, target: number): number;
|
|
6
|
+
}
|
|
7
|
+
export interface ComparisonFunction<T> {
|
|
8
|
+
(t1: T, t2: T): number;
|
|
9
|
+
}
|
|
10
|
+
export interface MatchReport<T> {
|
|
11
|
+
matching: T[];
|
|
12
|
+
setOneOnly: T[];
|
|
13
|
+
setTwoOnly: T[];
|
|
14
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { RequireRatchet } from './require-ratchet';
|
|
2
|
-
import { MapRatchet } from './map-ratchet';
|
|
1
|
+
import { RequireRatchet } from './require-ratchet.js';
|
|
2
|
+
import { MapRatchet } from './map-ratchet.js';
|
|
3
3
|
export class ArrayRatchet {
|
|
4
4
|
static wrapElementsInArray(input) {
|
|
5
5
|
return input.map((i) => [i]);
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { ArrayRatchet } from './array-ratchet.js';
|
|
2
|
+
const sortedArr = [
|
|
3
|
+
{
|
|
4
|
+
n: 'test1',
|
|
5
|
+
v: 1,
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
n: 'test1',
|
|
9
|
+
v: 2,
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
n: 'test1',
|
|
13
|
+
v: 4,
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
n: 'test1',
|
|
17
|
+
v: 4,
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
n: 'test1',
|
|
21
|
+
v: 7,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
n: 'test1',
|
|
25
|
+
v: 12,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
n: 'test1',
|
|
29
|
+
v: 25,
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
n: 'test1',
|
|
33
|
+
v: 30,
|
|
34
|
+
},
|
|
35
|
+
];
|
|
36
|
+
describe('#extractSubarrayFromSortedByNumberField', function () {
|
|
37
|
+
it('should extract the subarray', function () {
|
|
38
|
+
const subArr1 = ArrayRatchet.extractSubarrayFromSortedByNumberField(sortedArr, 'v', 5, 14);
|
|
39
|
+
expect(subArr1.length).toEqual(2);
|
|
40
|
+
const subArr2 = ArrayRatchet.extractSubarrayFromSortedByNumberField(sortedArr, 'v', null, 4);
|
|
41
|
+
expect(subArr2.length).toEqual(4);
|
|
42
|
+
const subArr3 = ArrayRatchet.extractSubarrayFromSortedByNumberField(sortedArr, 'v', 7, null);
|
|
43
|
+
expect(subArr3.length).toEqual(4);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
describe('#compareTwoArrays', function () {
|
|
47
|
+
it('should create a match report', function () {
|
|
48
|
+
const arr1 = ['a', 'b', 'c'];
|
|
49
|
+
const arr2 = ['a', 'e', 'i', 'o', 'u'];
|
|
50
|
+
const report = ArrayRatchet.compareTwoArrays(arr1, arr2, (a, b) => a.localeCompare(b));
|
|
51
|
+
expect(report).toBeTruthy();
|
|
52
|
+
expect(report.setOneOnly.length).toEqual(2);
|
|
53
|
+
expect(report.setTwoOnly.length).toEqual(4);
|
|
54
|
+
expect(report.matching.length).toEqual(1);
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
describe('#findSplit', function () {
|
|
58
|
+
it('should find the split', function () {
|
|
59
|
+
const split10 = ArrayRatchet.findSplit(sortedArr, 'v', 10);
|
|
60
|
+
const split4 = ArrayRatchet.findSplit(sortedArr, 'v', 4);
|
|
61
|
+
const split0 = ArrayRatchet.findSplit(sortedArr, 'v', 0);
|
|
62
|
+
const split32 = ArrayRatchet.findSplit(sortedArr, 'v', 32);
|
|
63
|
+
expect(split10).toEqual(4);
|
|
64
|
+
expect(split4).toEqual(3);
|
|
65
|
+
expect(split0).toEqual(null);
|
|
66
|
+
expect(split32).toEqual(7);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Base64Ratchet } from './base64-ratchet.js';
|
|
2
|
+
describe('#base64', function () {
|
|
3
|
+
it('should parse a buffer from base64', function () {
|
|
4
|
+
const result = Base64Ratchet.base64StringToBuffer('dGVzdHVzZXI6dGVzdHBhc3M=');
|
|
5
|
+
expect(result).toBeTruthy();
|
|
6
|
+
expect(result.length).toEqual(17);
|
|
7
|
+
});
|
|
8
|
+
it('should parse a string from base64', function () {
|
|
9
|
+
const result = Base64Ratchet.base64StringToString('dGVzdHVzZXI6dGVzdHBhc3M=');
|
|
10
|
+
expect(result).toBeTruthy();
|
|
11
|
+
expect(result.length).toEqual(17);
|
|
12
|
+
});
|
|
13
|
+
it('should round-trip a string', function () {
|
|
14
|
+
const testString = 'teststring';
|
|
15
|
+
const enc = Base64Ratchet.generateBase64VersionOfString(testString);
|
|
16
|
+
const result = Base64Ratchet.base64StringToString(enc);
|
|
17
|
+
expect(result).toBeTruthy();
|
|
18
|
+
expect(result).toEqual(testString);
|
|
19
|
+
});
|
|
20
|
+
it('should round-trip an object', function () {
|
|
21
|
+
const testOb = { a: 'teststring', b: 27 };
|
|
22
|
+
const enc = Base64Ratchet.safeObjectToBase64JSON(testOb);
|
|
23
|
+
const result = Base64Ratchet.safeBase64JSONParse(enc);
|
|
24
|
+
expect(result).toBeTruthy();
|
|
25
|
+
expect(result.a).toEqual(testOb.a);
|
|
26
|
+
expect(result.b).toEqual(testOb.b);
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { BooleanRatchet } from './boolean-ratchet.js';
|
|
2
|
+
import { NumberRatchet } from './number-ratchet.js';
|
|
3
|
+
describe('#parseBool', function () {
|
|
4
|
+
it('should check all true', function () {
|
|
5
|
+
expect(BooleanRatchet.allTrue(null)).toEqual(false);
|
|
6
|
+
expect(BooleanRatchet.allTrue([])).toEqual(false);
|
|
7
|
+
expect(BooleanRatchet.allTrue([], true)).toEqual(true);
|
|
8
|
+
expect(BooleanRatchet.allTrue([true])).toEqual(true);
|
|
9
|
+
expect(BooleanRatchet.allTrue([true, true])).toEqual(true);
|
|
10
|
+
expect(BooleanRatchet.allTrue([true, false, true])).toEqual(false);
|
|
11
|
+
expect(BooleanRatchet.allTrue([false])).toEqual(false);
|
|
12
|
+
expect(BooleanRatchet.allTrue([false, false])).toEqual(false);
|
|
13
|
+
});
|
|
14
|
+
it('should check any true', function () {
|
|
15
|
+
expect(BooleanRatchet.anyTrue(null)).toEqual(false);
|
|
16
|
+
expect(BooleanRatchet.anyTrue([])).toEqual(false);
|
|
17
|
+
expect(BooleanRatchet.anyTrue([], true)).toEqual(true);
|
|
18
|
+
expect(BooleanRatchet.anyTrue([true])).toEqual(true);
|
|
19
|
+
expect(BooleanRatchet.anyTrue([true, true])).toEqual(true);
|
|
20
|
+
expect(BooleanRatchet.anyTrue([true, false, true])).toEqual(true);
|
|
21
|
+
expect(BooleanRatchet.anyTrue([false])).toEqual(false);
|
|
22
|
+
expect(BooleanRatchet.anyTrue([false, false])).toEqual(false);
|
|
23
|
+
});
|
|
24
|
+
it('should xxx', function () {
|
|
25
|
+
const val = 'false';
|
|
26
|
+
const r1 = BooleanRatchet.parseBool(val);
|
|
27
|
+
const r2 = BooleanRatchet.intToBool(val);
|
|
28
|
+
const result = BooleanRatchet.parseBool(val) || BooleanRatchet.intToBool(NumberRatchet.safeNumber(val));
|
|
29
|
+
expect(result).toEqual(false);
|
|
30
|
+
});
|
|
31
|
+
it('should parse the string true as true', function () {
|
|
32
|
+
const result = BooleanRatchet.parseBool('true');
|
|
33
|
+
expect(result).toEqual(true);
|
|
34
|
+
});
|
|
35
|
+
it('should parse the string TRUE as true', function () {
|
|
36
|
+
const result = BooleanRatchet.parseBool('TRUE');
|
|
37
|
+
expect(result).toEqual(true);
|
|
38
|
+
});
|
|
39
|
+
it('should parse the boolean true as true', function () {
|
|
40
|
+
const result = BooleanRatchet.parseBool(true);
|
|
41
|
+
expect(result).toEqual(true);
|
|
42
|
+
});
|
|
43
|
+
it('should parse the empty string as false', function () {
|
|
44
|
+
const result = BooleanRatchet.parseBool('');
|
|
45
|
+
expect(result).toEqual(false);
|
|
46
|
+
});
|
|
47
|
+
it('should parse null as false', function () {
|
|
48
|
+
const result = BooleanRatchet.parseBool(null);
|
|
49
|
+
expect(result).toEqual(false);
|
|
50
|
+
});
|
|
51
|
+
it('should parse "asdf" as false', function () {
|
|
52
|
+
const result = BooleanRatchet.parseBool('asdf');
|
|
53
|
+
expect(result).toEqual(false);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
describe('#intToBool', function () {
|
|
57
|
+
it('should parse null as false', function () {
|
|
58
|
+
const result = BooleanRatchet.intToBool(null);
|
|
59
|
+
expect(result).toEqual(false);
|
|
60
|
+
});
|
|
61
|
+
it('should parse 0 as false', function () {
|
|
62
|
+
const result = BooleanRatchet.intToBool(0);
|
|
63
|
+
expect(result).toEqual(false);
|
|
64
|
+
});
|
|
65
|
+
it('should parse "0" as false', function () {
|
|
66
|
+
const result = BooleanRatchet.intToBool('0');
|
|
67
|
+
expect(result).toEqual(false);
|
|
68
|
+
});
|
|
69
|
+
it('should parse 1 as true', function () {
|
|
70
|
+
const result = BooleanRatchet.intToBool(1);
|
|
71
|
+
expect(result).toEqual(true);
|
|
72
|
+
});
|
|
73
|
+
it('should parse "1" as true', function () {
|
|
74
|
+
const result = BooleanRatchet.intToBool('1');
|
|
75
|
+
expect(result).toEqual(true);
|
|
76
|
+
});
|
|
77
|
+
it('should parse "2" as true', function () {
|
|
78
|
+
const result = BooleanRatchet.intToBool('2');
|
|
79
|
+
expect(result).toEqual(true);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { LastSuccessProvider } from './last-success-provider';
|
|
1
|
+
import { LastSuccessProvider } from './last-success-provider.js';
|
|
3
2
|
export declare class CompositeLastSuccessProvider implements LastSuccessProvider {
|
|
4
3
|
private sources;
|
|
5
4
|
private mostRecent;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { CompositeLastSuccessProvider } from './composite-last-success-provider.js';
|
|
2
|
+
describe('#lastSuccess', function () {
|
|
3
|
+
const last5 = {
|
|
4
|
+
lastSuccess() {
|
|
5
|
+
return 5;
|
|
6
|
+
},
|
|
7
|
+
};
|
|
8
|
+
const last4 = {
|
|
9
|
+
lastSuccess() {
|
|
10
|
+
return 4;
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
const lastNull = {
|
|
14
|
+
lastSuccess() {
|
|
15
|
+
return null;
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
it('should return 4 as last (min)', function () {
|
|
19
|
+
const result = new CompositeLastSuccessProvider([last5, last4, lastNull], false).lastSuccess();
|
|
20
|
+
expect(result).toEqual(4);
|
|
21
|
+
});
|
|
22
|
+
it('should return 5 as last (max)', function () {
|
|
23
|
+
const result = new CompositeLastSuccessProvider([last5, last4, lastNull], true).lastSuccess();
|
|
24
|
+
expect(result).toEqual(5);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { DateTime } from 'luxon';
|
|
2
2
|
export class DateRatchet {
|
|
3
|
+
static COMMON_US_DATE_FORMAT = 'MM/dd/yyyy';
|
|
4
|
+
static DEFAULT_DATE_FORMAT = 'yyyy-MM-dd';
|
|
5
|
+
static FULL_DATE_FORMAT = 'yyyy-MM-dd_HH_mm_ss';
|
|
6
|
+
static PACIFIC_TIME_ZONE = 'America/Los_Angeles';
|
|
7
|
+
static UTC_TIME_ZONE = 'etc/UTC';
|
|
3
8
|
static formatFullDate(input) {
|
|
4
9
|
return DateTime.fromJSDate(input).toFormat(DateRatchet.FULL_DATE_FORMAT);
|
|
5
10
|
}
|
|
@@ -22,8 +27,3 @@ export class DateRatchet {
|
|
|
22
27
|
return rval;
|
|
23
28
|
}
|
|
24
29
|
}
|
|
25
|
-
DateRatchet.COMMON_US_DATE_FORMAT = 'MM/dd/yyyy';
|
|
26
|
-
DateRatchet.DEFAULT_DATE_FORMAT = 'yyyy-MM-dd';
|
|
27
|
-
DateRatchet.FULL_DATE_FORMAT = 'yyyy-MM-dd_HH_mm_ss';
|
|
28
|
-
DateRatchet.PACIFIC_TIME_ZONE = 'America/Los_Angeles';
|
|
29
|
-
DateRatchet.UTC_TIME_ZONE = 'etc/UTC';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DateRatchet } from './date-ratchet.js';
|
|
2
|
+
describe('#dateRatchet', function () {
|
|
3
|
+
it('should parse my common date format', function () {
|
|
4
|
+
const dt = DateRatchet.parseDefaultDate('1976-07-04');
|
|
5
|
+
expect(dt.getFullYear()).toEqual(1976);
|
|
6
|
+
expect(dt.getMonth()).toEqual(6);
|
|
7
|
+
expect(dt.getDate()).toEqual(4);
|
|
8
|
+
});
|
|
9
|
+
it('should parse us with slashes', function () {
|
|
10
|
+
const dt = DateRatchet.parseCommonUsDate('07/04/1976');
|
|
11
|
+
expect(dt.getFullYear()).toEqual(1976);
|
|
12
|
+
expect(dt.getMonth()).toEqual(6);
|
|
13
|
+
expect(dt.getDate()).toEqual(4);
|
|
14
|
+
});
|
|
15
|
+
it('should parse us with dashes', function () {
|
|
16
|
+
const dt = DateRatchet.parseCommonUsDate('07-04-1976');
|
|
17
|
+
expect(dt.getFullYear()).toEqual(1976);
|
|
18
|
+
expect(dt.getMonth()).toEqual(6);
|
|
19
|
+
expect(dt.getDate()).toEqual(4);
|
|
20
|
+
});
|
|
21
|
+
});
|