Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@contrail/types

Package Overview
Dependencies
Maintainers
4
Versions
179
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@contrail/types - npm Package Compare versions

Comparing version 2.0.29 to 2.0.30

7

lib/formatter/property-value-formatter.d.ts

@@ -20,2 +20,9 @@ import { DateFormatingOptions, NumberFormatingOptions, TypeProperty } from '../type-properties';

formatObjectReference(object: any): any;
parseValue(value: any, typeProperty: TypeProperty): any;
parseNumberValue(value: any): number;
parseCurrencyValue(value: any): number;
parsePercentValue(value: any): number;
parseBooleanValue(value: any): any;
parseOptionValue(display: any, typeProperty: TypeProperty): any;
parseMultiOptionValues(display: any, typeProperty: TypeProperty): any;
}

@@ -151,3 +151,91 @@ "use strict";

}
parseValue(value, typeProperty) {
let parsedValue = value;
if (!value || !typeProperty) {
parsedValue = '';
}
switch (typeProperty.propertyType) {
case type_properties_1.PropertyType.Number: {
parsedValue = this.parseNumberValue(value);
break;
}
case type_properties_1.PropertyType.Currency: {
parsedValue = this.parseCurrencyValue(value);
break;
}
case type_properties_1.PropertyType.Percent: {
parsedValue = this.parsePercentValue(value);
break;
}
case type_properties_1.PropertyType.Boolean: {
parsedValue = this.parseBooleanValue(value);
break;
}
case type_properties_1.PropertyType.SingleSelect: {
parsedValue = this.parseOptionValue(value, typeProperty);
break;
}
case type_properties_1.PropertyType.MultiSelect: {
parsedValue = this.parseMultiOptionValues(value, typeProperty);
break;
}
}
return parsedValue;
}
parseNumberValue(value) {
const parsedValue = Number(value.replace(/[^0-9.-]+/g, ''));
return parsedValue;
}
parseCurrencyValue(value) {
const parsedValue = Number(value.replace(/[^0-9.-]+/g, ''));
return parsedValue;
}
parsePercentValue(value) {
let parsedValue = Number(value.replace(/[^0-9.-]+/g, ''));
parsedValue = parsedValue / 100;
return parsedValue;
}
parseBooleanValue(value) {
if (value.toUpperCase() === 'FALSE' || value.trim() === '' || value.trim() === 'undefined') {
return false;
}
else if (value.toUpperCase() === 'TRUE') {
return true;
}
return value;
}
parseOptionValue(display, typeProperty) {
if (!display) {
return '';
}
if (!typeProperty.options || !typeProperty) {
return display;
}
let optionValue = display;
typeProperty.options.map(opt => {
if (opt.display === display) {
optionValue = opt.value;
}
});
return optionValue;
}
parseMultiOptionValues(display, typeProperty) {
if (!display) {
return '';
}
if (!typeProperty.options || !typeProperty) {
return display;
}
const values = display.split(',');
if (values.length === 1) {
return this.parseOptionValue(values[0].trim(), typeProperty);
}
else if (values.length > 1) {
return values.map(value => {
return this.parseOptionValue(value.trim(), typeProperty);
});
}
return display;
}
}
exports.PropertyValueFormatter = PropertyValueFormatter;

3

lib/formulas/formula-processor.d.ts

@@ -1,7 +0,6 @@

import { TypeProperty } from "../type-properties";
import { TypeProperty } from '../type-properties';
export declare class FormulaProcessor {
static processFormula(formula: string | undefined, data: any): number | null;
static substituteValues(formula: string, data: any): string;
static processFormulasForEntities(entities: Array<any>, properties: Array<TypeProperty>): void;
static processFormulasForEntity(entity: any, properties: Array<TypeProperty>): void;
}

@@ -5,6 +5,7 @@ "use strict";

const type_properties_1 = require("../type-properties");
const util_1 = require("@contrail/util");
class FormulaProcessor {
static processFormula(formula = '', data) {
const converted = this.substituteValues(formula, data);
let value = parseFloat(eval(converted));
const converted = util_1.StringUtil.parseVariables(formula, data);
const value = parseFloat(eval(converted));
if (isNaN(value)) {

@@ -15,14 +16,2 @@ return null;

}
static substituteValues(formula, data) {
const regEx = /\{.*?\}/g;
let result = formula;
let vars = formula.match(regEx) || [];
for (let name of vars) {
while (result.indexOf(name) > -1) {
let key = name.slice(1, name.length - 1);
result = result.replace(`${name}`, data[key]);
}
}
return result;
}
static processFormulasForEntities(entities, properties) {

@@ -29,0 +18,0 @@ entities.forEach(entity => {

@@ -6,2 +6,3 @@ import { ValidationError, ValidationSummary } from './validation-summary';

export declare const VALUE_IS_NOT_A_VALID_DATE = "The value provided is not a valid date.";
export declare const VALUE_IS_NOT_A_VALID_BOOLEAN = "The value provided is not a valid boolean.";
export declare const PROPERTY_IS_NOT_EDITABLE = "The property is not editable.";

@@ -15,2 +16,3 @@ export declare class TypeManagedValidator {

static validateOptionValue(value: any, property: TypeProperty): any;
static validateBoolean(value: any, property: TypeProperty): any;
}

@@ -12,3 +12,3 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.TypeManagedValidator = exports.PROPERTY_IS_NOT_EDITABLE = exports.VALUE_IS_NOT_A_VALID_DATE = exports.VALUE_IS_NOT_A_VALID_NUMBER = exports.VALUE_IS_NOT_A_VALID_OPTION = void 0;
exports.TypeManagedValidator = exports.PROPERTY_IS_NOT_EDITABLE = exports.VALUE_IS_NOT_A_VALID_BOOLEAN = exports.VALUE_IS_NOT_A_VALID_DATE = exports.VALUE_IS_NOT_A_VALID_NUMBER = exports.VALUE_IS_NOT_A_VALID_OPTION = void 0;
const __1 = require("..");

@@ -18,2 +18,3 @@ exports.VALUE_IS_NOT_A_VALID_OPTION = 'The value provided is not a valid option for this property.';

exports.VALUE_IS_NOT_A_VALID_DATE = 'The value provided is not a valid date.';
exports.VALUE_IS_NOT_A_VALID_BOOLEAN = 'The value provided is not a valid boolean.';
exports.PROPERTY_IS_NOT_EDITABLE = 'The property is not editable.';

@@ -64,2 +65,5 @@ class TypeManagedValidator {

break;
case __1.PropertyType.Boolean:
validationErrors = this.validateBoolean(value, property);
break;
}

@@ -100,3 +104,10 @@ return validationErrors;

}
static validateBoolean(value, property) {
let errors = [];
if (typeof value !== 'boolean') {
errors.push({ value, message: exports.VALUE_IS_NOT_A_VALID_BOOLEAN });
}
return errors;
}
}
exports.TypeManagedValidator = TypeManagedValidator;
{
"name": "@contrail/types",
"version": "2.0.29",
"version": "2.0.30",
"description": "Types Utility module",

@@ -14,5 +14,5 @@ "main": "lib/index.js",

"keywords": [],
"author": "Ravi K Sharma",
"license": "ISC",
"devDependencies": {
"@contrail/util": "^1.0.14",
"@types/jest": "^23.3.14",

@@ -19,0 +19,0 @@ "jest": "^23.6.0",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc