@neovici/cosmoz-omnitable 14.22.1 → 14.23.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.
package/dist/lib/types.d.ts
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
export type LimitFunction = (a: number, b: number) => number | undefined;
|
|
2
|
-
export type Currency =
|
|
2
|
+
export type Currency = string;
|
|
3
|
+
export type Rates = Partial<Record<Currency, number>> & Record<string, number>;
|
|
3
4
|
export interface Amount {
|
|
4
|
-
amount:
|
|
5
|
-
currency: Currency
|
|
5
|
+
amount: number;
|
|
6
|
+
currency: Currency;
|
|
6
7
|
}
|
|
7
8
|
export type GetPath = string | (string | number)[];
|
|
8
9
|
export interface Column {
|
|
9
10
|
valuePath?: GetPath;
|
|
10
|
-
locale?:
|
|
11
|
+
locale?: Currency;
|
|
11
12
|
}
|
|
12
13
|
export interface NumberColumn extends Column {
|
|
13
14
|
minimumFractionDigits?: number | null;
|
|
14
15
|
maximumFractionDigits?: number | null;
|
|
15
16
|
}
|
|
17
|
+
export interface AmountColumn extends Column {
|
|
18
|
+
rates?: Rates;
|
|
19
|
+
}
|
|
16
20
|
export type DateColumn = Column;
|
|
17
21
|
export interface Limit<T> {
|
|
18
22
|
min: T;
|
package/dist/lib/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;AAEzE,MAAM,MAAM,QAAQ,GAAG,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/lib/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,MAAM,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| null | undefined;
|
|
20
|
-
export function getCurrency({ valuePath }: {
|
|
21
|
-
valuePath: any;
|
|
22
|
-
}, item: any): any;
|
|
23
|
-
export function getInputString({ valuePath }: {
|
|
24
|
-
valuePath: any;
|
|
25
|
-
}, item: any): any;
|
|
1
|
+
import { Amount, Currency, GetPath, AmountColumn, Item, AmountLimit, Rates, LimitFunction } from './types';
|
|
2
|
+
export declare const toAmount: (rates: Rates | undefined, value: unknown, limit?: AmountLimit | null, limitFunc?: LimitFunction) => Amount | null | undefined;
|
|
3
|
+
export declare const getComparableValue: <T extends AmountColumn>({ valuePath, rates }: T, item: Item) => number | undefined;
|
|
4
|
+
export declare const applySingleFilter: (column: AmountColumn, filter: AmountLimit) => (item: Item) => boolean;
|
|
5
|
+
export declare const formatters: Record<string, Intl.NumberFormat>;
|
|
6
|
+
export declare const getFormatter: (currency: Currency | string, locale?: Currency) => Intl.NumberFormat;
|
|
7
|
+
export declare const renderValue: (rates: Rates | undefined, value: Amount | unknown, locale?: Currency) => Intl.NumberFormat | string;
|
|
8
|
+
export declare const getString: <T extends AmountColumn>({ valuePath, rates, locale }: T, item: Item) => Intl.NumberFormat | string;
|
|
9
|
+
export declare const toHashString: (value: Amount | null) => string;
|
|
10
|
+
export declare const fromHashString: (value: string | null) => Amount | null | undefined;
|
|
11
|
+
export declare const getCurrency: ({ valuePath }: {
|
|
12
|
+
valuePath?: GetPath;
|
|
13
|
+
}, item: Item) => string | null;
|
|
14
|
+
export declare const getInputString: ({ valuePath }: {
|
|
15
|
+
valuePath?: GetPath;
|
|
16
|
+
}, item: Item) => string | number | undefined;
|
|
26
17
|
//# sourceMappingURL=utils-amount.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils-amount.d.ts","sourceRoot":"","sources":["../../src/lib/utils-amount.
|
|
1
|
+
{"version":3,"file":"utils-amount.d.ts","sourceRoot":"","sources":["../../src/lib/utils-amount.ts"],"names":[],"mappings":"AAEA,OAAO,EACN,MAAM,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AG,IAA2D,CAAC;AAExE,eAAO,MAAM,cAAc,GAC1B,eAAe;IAAE,SAAS,CAAC,EAAE,OAAO,CAAA;CAAE,EACtC,MAAM,IAAI,KACR,MAAM,GAAG,MAAM,GAAG,SACgC,CAAC"}
|
package/dist/lib/utils-amount.js
CHANGED
|
@@ -1,14 +1,7 @@
|
|
|
1
1
|
import { get } from '@polymer/polymer/lib/utils/path';
|
|
2
2
|
import { toNumber } from './utils-number';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*
|
|
6
|
-
* @param {Object} rates The rates
|
|
7
|
-
* @param {Object} value The value to convert to number
|
|
8
|
-
* @param {Object} limit The value used to limit the number
|
|
9
|
-
* @param {Function} limitFunc The function used to limit the number (Math.min|Math.max)
|
|
10
|
-
* @returns {Object|void} Value converted to Number or void
|
|
11
|
-
*/ toAmount = (rates = {}, value, limit, limitFunc) => {
|
|
3
|
+
// Converts a value to an amount object optionaly limiting it.
|
|
4
|
+
export const toAmount = (rates = {}, value, limit, limitFunc) => {
|
|
12
5
|
if (value == null || value === '') {
|
|
13
6
|
return;
|
|
14
7
|
}
|
|
@@ -30,9 +23,12 @@ export const /**
|
|
|
30
23
|
return amount;
|
|
31
24
|
}
|
|
32
25
|
// calculate value and limit amounts with rates
|
|
33
|
-
const valAmount = amount.amount * (rates[amount.currency] || 1)
|
|
26
|
+
const valAmount = amount.amount * (rates[amount.currency] || 1);
|
|
27
|
+
const limAmount = lAmount.amount * (rates[lAmount.currency] || 1);
|
|
28
|
+
const lNumber = toNumber(valAmount, limAmount, limitFunc);
|
|
34
29
|
return lNumber === valAmount ? amount : lAmount;
|
|
35
|
-
}
|
|
30
|
+
};
|
|
31
|
+
export const getComparableValue = ({ valuePath, rates }, item) => {
|
|
36
32
|
if (item == null) {
|
|
37
33
|
return;
|
|
38
34
|
}
|
|
@@ -40,24 +36,32 @@ export const /**
|
|
|
40
36
|
if (valuePath != null) {
|
|
41
37
|
value = get(item, valuePath);
|
|
42
38
|
}
|
|
43
|
-
|
|
44
|
-
if (
|
|
39
|
+
const amountValue = toAmount(rates, value);
|
|
40
|
+
if (amountValue == null) {
|
|
45
41
|
return;
|
|
46
42
|
}
|
|
47
|
-
const amount = toNumber(
|
|
48
|
-
if (rates == null) {
|
|
43
|
+
const amount = toNumber(amountValue.amount);
|
|
44
|
+
if (rates == null || amount == null) {
|
|
49
45
|
return amount;
|
|
50
46
|
}
|
|
51
|
-
return amount * (rates[
|
|
52
|
-
}
|
|
47
|
+
return amount * (rates?.[amountValue.currency] || 1);
|
|
48
|
+
};
|
|
49
|
+
export const applySingleFilter = (column, filter) => (item) => {
|
|
53
50
|
const value = getComparableValue(column, item);
|
|
54
|
-
if (value
|
|
51
|
+
if (value === undefined) {
|
|
55
52
|
return false;
|
|
56
53
|
}
|
|
57
|
-
const min = getComparableValue({ ...column, valuePath: 'min' }, filter)
|
|
54
|
+
const min = getComparableValue({ ...column, valuePath: 'min' }, filter);
|
|
55
|
+
const max = getComparableValue({ ...column, valuePath: 'max' }, filter);
|
|
56
|
+
if (min === undefined || max === undefined) {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
58
59
|
return !(value < min || value > max);
|
|
59
|
-
}
|
|
60
|
-
|
|
60
|
+
};
|
|
61
|
+
export const formatters = {};
|
|
62
|
+
export const getFormatter = (currency, locale) => {
|
|
63
|
+
const id = locale ? locale : '';
|
|
64
|
+
const key = currency + id || '';
|
|
61
65
|
if (formatters[key]) {
|
|
62
66
|
return formatters[key];
|
|
63
67
|
}
|
|
@@ -66,14 +70,16 @@ export const /**
|
|
|
66
70
|
currency,
|
|
67
71
|
});
|
|
68
72
|
return formatters[key];
|
|
69
|
-
}
|
|
73
|
+
};
|
|
74
|
+
export const renderValue = (rates, value, locale) => {
|
|
70
75
|
const amount = toAmount(rates, value);
|
|
71
76
|
if (amount == null) {
|
|
72
77
|
return '';
|
|
73
78
|
}
|
|
74
79
|
return getFormatter(amount.currency, locale).format(amount.amount);
|
|
75
|
-
}
|
|
76
|
-
|
|
80
|
+
};
|
|
81
|
+
export const getString = ({ valuePath, rates, locale }, item) => {
|
|
82
|
+
const value = toAmount(rates, valuePath ? get(item, valuePath) : undefined);
|
|
77
83
|
if (value === undefined) {
|
|
78
84
|
return '';
|
|
79
85
|
}
|
|
@@ -81,19 +87,23 @@ export const /**
|
|
|
81
87
|
return 'Invalid value';
|
|
82
88
|
}
|
|
83
89
|
return renderValue(rates, value, locale);
|
|
84
|
-
}
|
|
90
|
+
};
|
|
91
|
+
export const toHashString = (value) => {
|
|
85
92
|
if (!value) {
|
|
86
93
|
return '';
|
|
87
94
|
}
|
|
88
95
|
return value.amount + value.currency;
|
|
89
|
-
}
|
|
96
|
+
};
|
|
97
|
+
export const fromHashString = (value) => {
|
|
90
98
|
if (value == null || value === '') {
|
|
91
|
-
return;
|
|
99
|
+
return undefined;
|
|
92
100
|
}
|
|
93
101
|
const params = value.match(/^(-?[\d]+)([\D]+?)$/iu);
|
|
94
102
|
if (!Array.isArray(params) || params.length < 0) {
|
|
95
|
-
return
|
|
103
|
+
return undefined;
|
|
96
104
|
}
|
|
97
|
-
return { amount: params[1], currency: params[2] };
|
|
98
|
-
}
|
|
105
|
+
return { amount: Number(params[1]), currency: params[2] };
|
|
106
|
+
};
|
|
107
|
+
export const getCurrency = ({ valuePath }, item) => (valuePath ? get(item, valuePath)?.currency : null);
|
|
108
|
+
export const getInputString = ({ valuePath }, item) => valuePath ? get(item, valuePath)?.amount : undefined;
|
|
99
109
|
//# sourceMappingURL=utils-amount.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@neovici/cosmoz-omnitable",
|
|
3
|
-
"version": "14.
|
|
3
|
+
"version": "14.23.0",
|
|
4
4
|
"description": "[](https://travis-ci.org/Neovici/cosmoz-omnitable)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"web-components"
|