price-extractor 2.0.3 → 2.1.1
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/README.md +4 -5
- package/dist/codeToSymbol.json +5 -1
- package/dist/currenciesSymbols.json +1156 -0
- package/dist/index.d.ts +5 -3
- package/dist/index.js +41 -31
- package/dist/nativeSymbolToCode.json +5 -1
- package/dist/symbolToCode.json +4 -0
- package/package.json +22 -19
- package/yarn.lock +1670 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
declare type Json = Record<string, string | undefined>;
|
|
1
2
|
export interface ICodeResult {
|
|
2
3
|
code?: string;
|
|
3
4
|
str: string;
|
|
@@ -6,6 +7,7 @@ export interface IExtractResult {
|
|
|
6
7
|
code?: string;
|
|
7
8
|
price?: number;
|
|
8
9
|
}
|
|
9
|
-
export declare const getCodeToSymbol: () =>
|
|
10
|
-
export declare const searchCode: (moneyStr: string, fallbackCode?: string
|
|
11
|
-
export declare const searchPriceAndCode: (moneyStr: string, fallbackCode?: string
|
|
10
|
+
export declare const getCodeToSymbol: () => Json;
|
|
11
|
+
export declare const searchCode: (moneyStr: string, fallbackCode?: string) => string | undefined;
|
|
12
|
+
export declare const searchPriceAndCode: (moneyStr: string, fallbackCode?: string) => IExtractResult;
|
|
13
|
+
export {};
|
package/dist/index.js
CHANGED
|
@@ -1,33 +1,47 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.searchPriceAndCode = exports.searchCode = exports.getCodeToSymbol = void 0;
|
|
3
4
|
const symbolToCodeRaw = require("./symbolToCode.json");
|
|
4
5
|
const nativeSymbolToCodeRaw = require("./nativeSymbolToCode.json");
|
|
5
6
|
const codeToSymbolRaw = require("./codeToSymbol.json");
|
|
7
|
+
const currenciesFileRaw = require("./currenciesSymbols.json");
|
|
8
|
+
const currencies = currenciesFileRaw;
|
|
6
9
|
const symbolToCode = symbolToCodeRaw;
|
|
7
10
|
const nativeSymbolToCode = nativeSymbolToCodeRaw;
|
|
8
11
|
const codeToSymbol = codeToSymbolRaw;
|
|
9
|
-
// List of formats - https://www.thefinancials.com/Default.aspx?SubSectionID=curformat
|
|
10
12
|
const unicodeRegex = /&#(x?[0-9a-fA-F]+);/;
|
|
11
|
-
const regexReplace = /[0-9,'\-.\s]/g;
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
13
|
+
const regexReplace = /[0-9,'_\-.\s]/g;
|
|
14
|
+
const dotDecimalRegex = /^(\d{1,3}(,?\d{3})*(\.\d{1,2})?)$/; // dot decimal separator
|
|
15
|
+
const longDotDecimalRegex = /^(\d{1,3}(,?\d{3})*(\.\d{1,3})?)$/; // dot decimal separator
|
|
16
|
+
const commaDecimalRegex = /^(\d{1,3}(\.?\d{3})*(,\d{1,2})?)$/; // comma decimal separator
|
|
17
|
+
const longCommaDecimalRegex = /^(\d{1,3}(\.?\d{3})*(,\d{1,3})?)$/; // comma decimal separator
|
|
18
|
+
const getPriceNumber = (str, currency) => {
|
|
16
19
|
let price = Number.NaN;
|
|
17
|
-
let
|
|
18
|
-
if (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
let match;
|
|
21
|
+
if (currency && currency.decimal_digits === 3) {
|
|
22
|
+
if (currency.decimal_separator === ',') {
|
|
23
|
+
match = str.match(longCommaDecimalRegex);
|
|
24
|
+
if (match && match[0] === str) {
|
|
25
|
+
price = parseFloat(match[1].replace(/\./g, '').replace(/,/g, '.').trim());
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
match = str.match(longDotDecimalRegex);
|
|
30
|
+
if (match && match[0] === str) {
|
|
31
|
+
price = parseFloat(match[1].replace(/,/g, '').trim());
|
|
32
|
+
}
|
|
25
33
|
}
|
|
26
34
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (
|
|
30
|
-
price = parseFloat(
|
|
35
|
+
else {
|
|
36
|
+
match = str.match(dotDecimalRegex);
|
|
37
|
+
if (match && match[0] === str) {
|
|
38
|
+
price = parseFloat(match[1].replace(/,/g, '').trim());
|
|
39
|
+
}
|
|
40
|
+
if (isNaN(price)) {
|
|
41
|
+
match = str.match(commaDecimalRegex);
|
|
42
|
+
if (match && match[0] === str) {
|
|
43
|
+
price = parseFloat(match[1].replace(/\./g, '').replace(/,/g, '.').trim());
|
|
44
|
+
}
|
|
31
45
|
}
|
|
32
46
|
}
|
|
33
47
|
return price;
|
|
@@ -66,28 +80,24 @@ const searchCodeAndStrip = (moneyStr, fallbackCode) => {
|
|
|
66
80
|
}
|
|
67
81
|
return { str: moneyStr };
|
|
68
82
|
};
|
|
69
|
-
|
|
83
|
+
const getCodeToSymbol = () => {
|
|
70
84
|
return Object.assign({}, codeToSymbol);
|
|
71
85
|
};
|
|
72
|
-
exports.
|
|
86
|
+
exports.getCodeToSymbol = getCodeToSymbol;
|
|
87
|
+
const searchCode = (moneyStr, fallbackCode) => {
|
|
73
88
|
return searchCodeAndStrip(moneyStr, fallbackCode).code;
|
|
74
89
|
};
|
|
75
|
-
exports.
|
|
90
|
+
exports.searchCode = searchCode;
|
|
91
|
+
const searchPriceAndCode = (moneyStr, fallbackCode) => {
|
|
76
92
|
const raw = searchCodeAndStrip(moneyStr, fallbackCode);
|
|
77
93
|
const code = raw.code;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const tmpStr = str.replace(/\s/g, '.');
|
|
82
|
-
price = getPriceNumber(tmpStr);
|
|
83
|
-
}
|
|
84
|
-
if (isNaN(price) && str.match(/\s/)) {
|
|
85
|
-
const tmpStr = str.replace(/\s/g, ',');
|
|
86
|
-
price = getPriceNumber(tmpStr);
|
|
87
|
-
}
|
|
94
|
+
// Remove custom thousands separator
|
|
95
|
+
const str = raw.str.replace(/\s/g, '').replace(/'/g, '').replace(/_/g, '');
|
|
96
|
+
const price = getPriceNumber(str, currencies[code || 'foo']);
|
|
88
97
|
if (price || price === 0) {
|
|
89
98
|
return { price, code };
|
|
90
99
|
}
|
|
91
100
|
return {};
|
|
92
101
|
};
|
|
102
|
+
exports.searchPriceAndCode = searchPriceAndCode;
|
|
93
103
|
//# sourceMappingURL=index.js.map
|
|
@@ -25,6 +25,8 @@
|
|
|
25
25
|
"Kč": "CZK",
|
|
26
26
|
"L": "HNL",
|
|
27
27
|
"Lek": "ALL",
|
|
28
|
+
"Ls": "LVL",
|
|
29
|
+
"Lt": "LTL",
|
|
28
30
|
"L": "SZL",
|
|
29
31
|
"MDL": "MDL",
|
|
30
32
|
"MGA": "MGA",
|
|
@@ -55,6 +57,7 @@
|
|
|
55
57
|
"UZS": "UZS",
|
|
56
58
|
"VT": "VUV",
|
|
57
59
|
"ZK": "ZMW",
|
|
60
|
+
"ZWL$": "ZWL",
|
|
58
61
|
"kn": "HRK",
|
|
59
62
|
"kr": "_____",
|
|
60
63
|
"zł": "PLN",
|
|
@@ -62,7 +65,7 @@
|
|
|
62
65
|
"дин.": "RSD",
|
|
63
66
|
"лв.": "BGN",
|
|
64
67
|
"ман.": "AZN",
|
|
65
|
-
"руб.": "
|
|
68
|
+
"руб.": "BYN",
|
|
66
69
|
"тңг.": "KZT",
|
|
67
70
|
"դր.": "AMD",
|
|
68
71
|
"؋": "AFN",
|
|
@@ -98,6 +101,7 @@
|
|
|
98
101
|
"₱": "PHP",
|
|
99
102
|
"₲": "PYG",
|
|
100
103
|
"₴": "UAH",
|
|
104
|
+
"₽.": "RUB",
|
|
101
105
|
"﷼": "IRR",
|
|
102
106
|
"¥": "JPY"
|
|
103
107
|
}
|
package/dist/symbolToCode.json
CHANGED
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
"DT": "TND",
|
|
33
33
|
"Dkr": "DKK",
|
|
34
34
|
"EGP": "EGP",
|
|
35
|
+
"Ekr": "EEK",
|
|
35
36
|
"FBu": "BIF",
|
|
36
37
|
"FCFA": "XAF",
|
|
37
38
|
"FG": "GNF",
|
|
@@ -58,6 +59,8 @@
|
|
|
58
59
|
"L": "SZL",
|
|
59
60
|
"LB£": "LBP",
|
|
60
61
|
"LD": "LYD",
|
|
62
|
+
"Ls": "LVL",
|
|
63
|
+
"Lt": "LTL",
|
|
61
64
|
"MAD": "MAD",
|
|
62
65
|
"MDL": "MDL",
|
|
63
66
|
"MGA": "MGA",
|
|
@@ -104,6 +107,7 @@
|
|
|
104
107
|
"VT": "VUV",
|
|
105
108
|
"YR": "YER",
|
|
106
109
|
"ZK": "ZMW",
|
|
110
|
+
"ZWL$": "ZWL",
|
|
107
111
|
"din.": "RSD",
|
|
108
112
|
"kn": "HRK",
|
|
109
113
|
"man.": "AZN",
|
package/package.json
CHANGED
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "price-extractor",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "Given a price string, extract the price and currency code",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": "^6 || ^8 || ^10 || ^12 || ^14 || ^16 || ^18"
|
|
9
|
+
},
|
|
7
10
|
"scripts": {
|
|
8
|
-
"test": "
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
11
|
+
"test": "npm run lint && npm run test:cover",
|
|
12
|
+
"test:unit": "mocha --opts src/test/mocha.opts",
|
|
13
|
+
"build": "npm run lint && npm run compile",
|
|
14
|
+
"compile": "./node_modules/.bin/tsc",
|
|
15
|
+
"test:cover": "nyc --reporter=lcov --reporter=text-summary mocha --opts src/test/mocha.opts",
|
|
16
|
+
"lint": "tslint -c tslint.json 'src/**/*.ts' 'test/**/*.ts'"
|
|
14
17
|
},
|
|
15
18
|
"repository": {
|
|
16
19
|
"type": "git",
|
|
@@ -34,18 +37,18 @@
|
|
|
34
37
|
"homepage": "https://github.com/PruvoNet/price-extractor#readme",
|
|
35
38
|
"dependencies": {},
|
|
36
39
|
"devDependencies": {
|
|
37
|
-
"@istanbuljs/nyc-config-typescript": "
|
|
38
|
-
"@types/chai": "^4.2.
|
|
39
|
-
"@types/mocha": "^
|
|
40
|
-
"@types/node": "^
|
|
41
|
-
"@types/underscore": "^1.
|
|
42
|
-
"chai": "^4.
|
|
43
|
-
"mocha": "^6.2.
|
|
40
|
+
"@istanbuljs/nyc-config-typescript": "0.1.3",
|
|
41
|
+
"@types/chai": "^4.2.15",
|
|
42
|
+
"@types/mocha": "^8.2.1",
|
|
43
|
+
"@types/node": "^14.14.34",
|
|
44
|
+
"@types/underscore": "^1.11.0",
|
|
45
|
+
"chai": "^4.3.4",
|
|
46
|
+
"mocha": "^6.2.3",
|
|
44
47
|
"nyc": "^14.1.1",
|
|
45
|
-
"source-map-support": "^0.5.
|
|
46
|
-
"ts-node": "^8.
|
|
47
|
-
"tslint": "^
|
|
48
|
-
"typescript": "^
|
|
49
|
-
"underscore": "^1.
|
|
48
|
+
"source-map-support": "^0.5.21",
|
|
49
|
+
"ts-node": "^8.10.2",
|
|
50
|
+
"tslint": "^6.1.3",
|
|
51
|
+
"typescript": "^4.8.4",
|
|
52
|
+
"underscore": "^1.13.6"
|
|
50
53
|
}
|
|
51
54
|
}
|