namirasoft-core 1.4.9 → 1.4.10

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.
@@ -0,0 +1,9 @@
1
+ import { ConvertService } from "./ConvertService";
2
+ export declare class CookieService extends ConvertService {
3
+ private cookies;
4
+ private cookies_object;
5
+ private name;
6
+ constructor(cookies: string, name: string, mandatory?: boolean);
7
+ getNullString(): string | null;
8
+ protected onMandatoryError(): void;
9
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CookieService = void 0;
4
+ const ConvertService_1 = require("./ConvertService");
5
+ class CookieService extends ConvertService_1.ConvertService {
6
+ constructor(cookies, name, mandatory = false) {
7
+ super(mandatory);
8
+ this.cookies = cookies;
9
+ this.name = name;
10
+ this.cookies_object = this.cookies.split(';').reduce((acc, cookie) => {
11
+ const [key, value] = cookie.trim().split('=');
12
+ acc[key] = decodeURIComponent(value);
13
+ return acc;
14
+ }, {});
15
+ }
16
+ getNullString() {
17
+ let ans = this.cookies_object[this.name];
18
+ if (ans)
19
+ return ans;
20
+ return null;
21
+ }
22
+ onMandatoryError() {
23
+ if (!process.env.NAMIRASOFT_MUTE)
24
+ throw new Error(`Cookie value was not provided: ${this.name}`);
25
+ }
26
+ }
27
+ exports.CookieService = CookieService;
28
+ //# sourceMappingURL=CookieService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CookieService.js","sourceRoot":"","sources":["../src/CookieService.ts"],"names":[],"mappings":";;;AAAA,qDAAkD;AAElD,MAAa,aAAc,SAAQ,+BAAc;IAO7C,YAAY,OAAe,EAAE,IAAY,EAAE,YAAqB,KAAK;QAEjE,KAAK,CAAC,SAAS,CAAC,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,GAA8B,EAAE,MAAM,EAAE,EAAE;YAE5F,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,MAAM,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC9C,GAAG,CAAC,GAAG,CAAC,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;YACrC,OAAO,GAAG,CAAC;QACf,CAAC,EAAE,EAAE,CAAC,CAAC;IACX,CAAC;IACQ,aAAa;QAElB,IAAI,GAAG,GAAG,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACzC,IAAI,GAAG;YACH,OAAO,GAAG,CAAC;QACf,OAAO,IAAI,CAAC;IAChB,CAAC;IACkB,gBAAgB;QAE/B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe;YAC5B,MAAM,IAAI,KAAK,CAAC,kCAAkC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IACvE,CAAC;CACJ;AA/BD,sCA+BC"}
package/package.json CHANGED
@@ -8,7 +8,7 @@
8
8
  "framework": "npm",
9
9
  "application": "package",
10
10
  "private": false,
11
- "version": "1.4.9",
11
+ "version": "1.4.10",
12
12
  "author": "Amir Abolhasani",
13
13
  "license": "MIT",
14
14
  "main": "./dist/index.js",
@@ -0,0 +1,34 @@
1
+ import { ConvertService } from "./ConvertService";
2
+
3
+ export class CookieService extends ConvertService
4
+ {
5
+ private cookies: string;
6
+ private cookies_object: {
7
+ [key: string]: string;
8
+ };
9
+ private name: string;
10
+ constructor(cookies: string, name: string, mandatory: boolean = false)
11
+ {
12
+ super(mandatory);
13
+ this.cookies = cookies;
14
+ this.name = name;
15
+ this.cookies_object = this.cookies.split(';').reduce((acc: { [key: string]: string }, cookie) =>
16
+ {
17
+ const [key, value] = cookie.trim().split('=');
18
+ acc[key] = decodeURIComponent(value);
19
+ return acc;
20
+ }, {});
21
+ }
22
+ override getNullString()
23
+ {
24
+ let ans = this.cookies_object[this.name];
25
+ if (ans)
26
+ return ans;
27
+ return null;
28
+ }
29
+ protected override onMandatoryError(): void
30
+ {
31
+ if (!process.env.NAMIRASOFT_MUTE)
32
+ throw new Error(`Cookie value was not provided: ${this.name}`);
33
+ }
34
+ }