namirasoft-core
Advanced tools
Comparing version 1.0.13 to 1.0.14
export declare abstract class ConvertService { | ||
private mandatory; | ||
constructor(mandatory?: boolean); | ||
abstract getNullString(): string | null; | ||
private checkMandatory; | ||
protected onMandatoryError(): void; | ||
getString(_default?: string): string; | ||
@@ -4,0 +8,0 @@ getNullInt(): number | null; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ConvertService = void 0; | ||
const ErrorOperation_1 = require("./ErrorOperation"); | ||
class ConvertService { | ||
constructor(mandatory = false) { | ||
this.mandatory = mandatory; | ||
} | ||
checkMandatory(value) { | ||
if (this.mandatory) | ||
if (value == null || value == undefined || !value) | ||
this.onMandatoryError(); | ||
return value; | ||
} | ||
onMandatoryError() { | ||
ErrorOperation_1.ErrorOperation.throwHTTP(500, "Object value can not be converted."); | ||
} | ||
getString(_default = "") { | ||
var _a; | ||
return (_a = this.getNullString()) !== null && _a !== void 0 ? _a : _default; | ||
return (_a = this.checkMandatory(this.getNullString())) !== null && _a !== void 0 ? _a : _default; | ||
} | ||
@@ -20,3 +33,3 @@ getNullInt() { | ||
var _a; | ||
return (_a = this.getNullInt()) !== null && _a !== void 0 ? _a : _default; | ||
return (_a = this.checkMandatory(this.getNullInt())) !== null && _a !== void 0 ? _a : _default; | ||
} | ||
@@ -34,3 +47,3 @@ getNullFloat() { | ||
var _a; | ||
return (_a = this.getNullFloat()) !== null && _a !== void 0 ? _a : _default; | ||
return (_a = this.checkMandatory(this.getNullFloat())) !== null && _a !== void 0 ? _a : _default; | ||
} | ||
@@ -50,3 +63,3 @@ getNullBoolean() { | ||
var _a; | ||
return (_a = this.getNullBoolean()) !== null && _a !== void 0 ? _a : _default; | ||
return (_a = this.checkMandatory(this.getNullBoolean())) !== null && _a !== void 0 ? _a : _default; | ||
} | ||
@@ -53,0 +66,0 @@ getStringArray(delimiter = ",") { |
{ | ||
"name": "namirasoft-core", | ||
"description": "Namira Software Corporation Core NPM Package", | ||
"version": "1.0.13", | ||
"version": "1.0.14", | ||
"main": "./dist/index.js", | ||
@@ -6,0 +6,0 @@ "types": "./dist/index.d.ts", |
@@ -0,7 +1,25 @@ | ||
import { ErrorOperation } from "./ErrorOperation"; | ||
export abstract class ConvertService | ||
{ | ||
private mandatory: boolean; | ||
constructor(mandatory: boolean = false) | ||
{ | ||
this.mandatory = mandatory; | ||
} | ||
abstract getNullString(): string | null; | ||
private checkMandatory<D>(value: D): D | ||
{ | ||
if (this.mandatory) | ||
if (value == null || value == undefined || !value) | ||
this.onMandatoryError(); | ||
return value; | ||
} | ||
protected onMandatoryError(): void | ||
{ | ||
ErrorOperation.throwHTTP(500, "Object value can not be converted."); | ||
} | ||
getString(_default: string = ""): string | ||
{ | ||
return this.getNullString() ?? _default; | ||
return this.checkMandatory(this.getNullString()) ?? _default; | ||
} | ||
@@ -20,3 +38,3 @@ getNullInt(): number | null | ||
{ | ||
return this.getNullInt() ?? _default; | ||
return this.checkMandatory(this.getNullInt()) ?? _default; | ||
} | ||
@@ -35,3 +53,3 @@ getNullFloat(): number | null | ||
{ | ||
return this.getNullFloat() ?? _default; | ||
return this.checkMandatory(this.getNullFloat()) ?? _default; | ||
} | ||
@@ -52,3 +70,3 @@ getNullBoolean(): boolean | null | ||
{ | ||
return this.getNullBoolean() ?? _default; | ||
return this.checkMandatory(this.getNullBoolean()) ?? _default; | ||
} | ||
@@ -55,0 +73,0 @@ getStringArray(delimiter: string = ","): string[] |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
222619
3241