@pallasoft/ps-utilities 2.11.0 → 2.12.0

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.
@@ -1,5 +1,7 @@
1
+ import { AmountDirection } from './constants/amount-direction';
1
2
  export declare class AmountService {
2
3
  static normalise(raw: string): string;
3
4
  static toNumber(raw: string): number;
4
5
  static isAmount(raw: string): boolean;
6
+ static direction(raw: string): AmountDirection;
5
7
  }
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AmountService = void 0;
4
4
  var amount_config_1 = require("./constants/amount-config");
5
+ var amount_direction_1 = require("./constants/amount-direction");
5
6
  var AmountService = /** @class */ (function () {
6
7
  function AmountService() {
7
8
  }
@@ -30,6 +31,14 @@ var AmountService = /** @class */ (function () {
30
31
  var normalised = AmountService.normalise(raw);
31
32
  return (normalised !== '' && normalised !== amount_config_1.AmountConfig.minus && Number.isFinite(Number(normalised)));
32
33
  };
34
+ AmountService.direction = function (raw) {
35
+ if (!AmountService.isAmount(raw))
36
+ return amount_direction_1.AmountDirection.Neutral;
37
+ var normalised = AmountService.normalise(raw);
38
+ if (amount_config_1.AmountConfig.zeroPattern.test(normalised))
39
+ return amount_direction_1.AmountDirection.Neutral;
40
+ return normalised.startsWith(amount_config_1.AmountConfig.minus) ? amount_direction_1.AmountDirection.Out : amount_direction_1.AmountDirection.In;
41
+ };
33
42
  return AmountService;
34
43
  }());
35
44
  exports.AmountService = AmountService;
@@ -4,4 +4,5 @@ export declare const AmountConfig: {
4
4
  readonly minus: "-";
5
5
  readonly openBracket: "(";
6
6
  readonly point: ".";
7
+ readonly zeroPattern: RegExp;
7
8
  };
@@ -7,4 +7,5 @@ exports.AmountConfig = {
7
7
  minus: '-',
8
8
  openBracket: '(',
9
9
  point: '.',
10
+ zeroPattern: /^-?0*\.?0*$/,
10
11
  };
@@ -0,0 +1,5 @@
1
+ export declare enum AmountDirection {
2
+ In = "in",
3
+ Neutral = "neutral",
4
+ Out = "out"
5
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AmountDirection = void 0;
4
+ var AmountDirection;
5
+ (function (AmountDirection) {
6
+ AmountDirection["In"] = "in";
7
+ AmountDirection["Neutral"] = "neutral";
8
+ AmountDirection["Out"] = "out";
9
+ })(AmountDirection || (exports.AmountDirection = AmountDirection = {}));
@@ -0,0 +1,4 @@
1
+ export declare const ErrorResponseConfig: {
2
+ clientErrorStart: number;
3
+ serverErrorStart: number;
4
+ };
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ErrorResponseConfig = void 0;
4
+ exports.ErrorResponseConfig = {
5
+ clientErrorStart: 400,
6
+ serverErrorStart: 500,
7
+ };
@@ -8,3 +8,5 @@ export * from './validation-config';
8
8
  export * from './file-size-config';
9
9
  export * from './socket-token-config';
10
10
  export * from './user-agent-config';
11
+ export * from './amount-direction';
12
+ export * from './error-response-config';
@@ -24,3 +24,5 @@ __exportStar(require("./validation-config"), exports);
24
24
  __exportStar(require("./file-size-config"), exports);
25
25
  __exportStar(require("./socket-token-config"), exports);
26
26
  __exportStar(require("./user-agent-config"), exports);
27
+ __exportStar(require("./amount-direction"), exports);
28
+ __exportStar(require("./error-response-config"), exports);
@@ -0,0 +1,7 @@
1
+ export declare class ErrorResponseService {
2
+ static code(error: unknown): number | null;
3
+ static isClientError(status: number): boolean;
4
+ static pageContent<Content extends {
5
+ description: string;
6
+ }>(status: number, message: string | undefined, base: Content): Content;
7
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.ErrorResponseService = void 0;
15
+ var error_response_config_1 = require("./constants/error-response-config");
16
+ var ErrorResponseService = /** @class */ (function () {
17
+ function ErrorResponseService() {
18
+ }
19
+ ErrorResponseService.code = function (error) {
20
+ if (typeof error !== 'object' || error === null || !('code' in error))
21
+ return null;
22
+ return typeof error.code === 'number' ? error.code : null;
23
+ };
24
+ ErrorResponseService.isClientError = function (status) {
25
+ return (status >= error_response_config_1.ErrorResponseConfig.clientErrorStart &&
26
+ status < error_response_config_1.ErrorResponseConfig.serverErrorStart);
27
+ };
28
+ ErrorResponseService.pageContent = function (status, message, base) {
29
+ return ErrorResponseService.isClientError(status) && message !== undefined && message !== ''
30
+ ? __assign(__assign({}, base), { description: message }) : base;
31
+ };
32
+ return ErrorResponseService;
33
+ }());
34
+ exports.ErrorResponseService = ErrorResponseService;
@@ -19,3 +19,4 @@ export * from './url-service';
19
19
  export * from './user-agent-service';
20
20
  export * from './user-token-service';
21
21
  export * from './validation-service';
22
+ export * from './error-response-service';
@@ -35,3 +35,4 @@ __exportStar(require("./url-service"), exports);
35
35
  __exportStar(require("./user-agent-service"), exports);
36
36
  __exportStar(require("./user-token-service"), exports);
37
37
  __exportStar(require("./validation-service"), exports);
38
+ __exportStar(require("./error-response-service"), exports);
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ import * as ClientNamespace from './client';
2
2
  import * as CommonNamespace from './common';
3
3
  export declare const Common: typeof CommonNamespace;
4
4
  export declare const Client: typeof ClientNamespace;
5
+ export { AmountDirection } from './common/constants/amount-direction';
5
6
  export type { EmailPreviewInput } from './models/email-preview-input';
6
7
  export type { SignedTokenHeader } from './models/signed-token-header';
7
8
  export type { SignedTokenKeyPair } from './models/signed-token-key-pair';
package/dist/index.js CHANGED
@@ -33,8 +33,10 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.Client = exports.Common = void 0;
36
+ exports.AmountDirection = exports.Client = exports.Common = void 0;
37
37
  var ClientNamespace = __importStar(require("./client"));
38
38
  var CommonNamespace = __importStar(require("./common"));
39
39
  exports.Common = CommonNamespace;
40
40
  exports.Client = ClientNamespace;
41
+ var amount_direction_1 = require("./common/constants/amount-direction");
42
+ Object.defineProperty(exports, "AmountDirection", { enumerable: true, get: function () { return amount_direction_1.AmountDirection; } });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pallasoft/ps-utilities",
3
- "version": "2.11.0",
3
+ "version": "2.12.0",
4
4
  "private": false,
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",