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

@contrail/types

Package Overview
Dependencies
Maintainers
6
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.13 to 2.0.14

5

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

@@ -1,2 +0,2 @@

import { NumberFormatingOption, TypeProperty } from '../type-properties';
import { DateFormatingOptions, NumberFormatingOptions, TypeProperty } from '../type-properties';
export interface LocalizationConfig {

@@ -13,6 +13,7 @@ currencyCode: string;

formatOptionValue(value: any, property: TypeProperty): string;
formatValue(value: any, propertyType: any, numberFormat?: NumberFormatingOption): string;
formatValue(value: any, propertyType: any, numberFormat?: NumberFormatingOptions, dateFormat?: DateFormatingOptions): string;
private formatNumber;
formatCurrencyValue(value: any): string;
formatDate(isoString: string, dateFormatOptions?: DateFormatingOptions): string;
formatBoolean(value: boolean): string;
}

20

lib/formatter/property-value-formatter.entities.spec.js

@@ -15,3 +15,6 @@ "use strict";

category: 'tops',
somePercentage: .34
somePercentage: .34,
isCool: true,
dateProperty: new Date('2000-01-01'),
dateTimeProperty: new Date('2019-09-07T00:00-04:00'),
};

@@ -23,2 +26,5 @@ const somePercentage = { slug: 'somePercentage', propertyType: type_properties_1.PropertyType.Percent, label: 'Some Percent', numberFormat: { format: type_properties_1.NumberFormat.Percent, precision: 1 } };

const categoryProperty = { slug: 'category', propertyType: type_properties_1.PropertyType.SingleSelect, label: 'Category', options: [{ display: "Tops", value: 'tops' }, { display: "Bottoms", value: 'bottoms' }] };
const booleanProperty = { slug: 'isCool', propertyType: type_properties_1.PropertyType.Boolean, label: 'Is Cool' };
const dateProperty = { slug: 'dateProperty', propertyType: type_properties_1.PropertyType.Date, label: 'A Date' };
const dateTimeProperty = { slug: 'dateProperty', propertyType: type_properties_1.PropertyType.Date, label: 'A Date', dateFormat: { includeTime: true } };
const localizationConfig = {

@@ -68,2 +74,14 @@ currencyCode: 'USD',

});
it('Should Format Boolean', () => {
const objValFormatter = new property_value_formatter_1.PropertyValueFormatter();
objValFormatter.setLocalConfig(localizationConfig);
const val = objValFormatter.getDisplayValue(entity, booleanProperty);
expect(val).toEqual("Yes");
});
it('Should Format Date', () => {
const objValFormatter = new property_value_formatter_1.PropertyValueFormatter();
objValFormatter.setLocalConfig(localizationConfig);
const val = objValFormatter.getDisplayValue(entity, dateProperty);
expect(val).toEqual("12/31/1999");
});
});

@@ -35,7 +35,4 @@ "use strict";

}
else if (property.propertyType === 'boolean') {
return this.formatBoolean(value);
}
else {
return this.formatValue(value, property.propertyType, property.numberFormat);
return this.formatValue(value, property.propertyType, property.numberFormat, property.dateFormat);
}

@@ -55,3 +52,3 @@ }

}
formatValue(value, propertyType, numberFormat) {
formatValue(value, propertyType, numberFormat, dateFormat = { includeTime: false }) {
let formattedValue = value;

@@ -75,2 +72,10 @@ switch (propertyType) {

}
case type_properties_1.PropertyType.Boolean: {
formattedValue = this.formatBoolean(value);
break;
}
case type_properties_1.PropertyType.Date: {
formattedValue = this.formatDate(value, dateFormat);
break;
}
}

@@ -110,2 +115,6 @@ return formattedValue;

}
formatDate(isoString, dateFormatOptions = { includeTime: false }) {
const options = {};
return new Intl.DateTimeFormat(this.localizationConfig.locale, options).format(new Date(isoString).getTime());
}
formatBoolean(value) {

@@ -112,0 +121,0 @@ if (value) {

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

const val = objValFormatter.formatValue(75, type_properties_1.PropertyType.Currency);
expect(val).toEqual('¥75');
expect(val).toEqual('¥75');
});

@@ -81,3 +81,3 @@ it('Japanese format currency values (with decimal - override)', () => {

const val = objValFormatter.formatValue(75, type_properties_1.PropertyType.Currency, { format: type_properties_1.NumberFormat.Currency, precision: 2 });
expect(val).toEqual('¥75.00');
expect(val).toEqual('¥75.00');
});

@@ -116,2 +116,7 @@ it('Japanese Decimal format', () => {

});
it('Format Date', () => {
const objValFormatter = new property_value_formatter_1.PropertyValueFormatter();
const val = objValFormatter.formatDate(new Date('2000-01-01').toISOString());
expect(val).toEqual('12/31/1999');
});
});

@@ -8,3 +8,4 @@ import { PropertyType } from ".";

formula?: string;
numberFormat?: NumberFormatingOption;
numberFormat?: NumberFormatingOptions;
dateFormat?: DateFormatingOptions;
options?: Array<TypePropertyOption>;

@@ -21,3 +22,3 @@ inherited?: boolean;

}
export interface NumberFormatingOption {
export interface NumberFormatingOptions {
format: NumberFormat;

@@ -27,2 +28,5 @@ precision?: number;

}
export interface DateFormatingOptions {
includeTime?: boolean;
}
export declare enum NumberFormat {

@@ -29,0 +33,0 @@ Currency = "currency",

{
"name": "@contrail/types",
"version": "2.0.13",
"version": "2.0.14",
"description": "Types Utility module",

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

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