@lightsparkdev/core 1.0.6 → 1.0.8
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/CHANGELOG.md +12 -0
- package/dist/{chunk-W5XKQOE6.js → chunk-UU6SHVGX.js} +7 -1
- package/dist/index.cjs +14 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +9 -2
- package/dist/utils/index.cjs +8 -1
- package/dist/utils/index.d.ts +5 -1
- package/dist/utils/index.js +3 -1
- package/package.json +1 -2
- package/src/requester/Requester.ts +8 -1
- package/src/utils/currency.ts +8 -1
- package/src/utils/tests/currency.test.ts +67 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @lightsparkdev/core
|
|
2
2
|
|
|
3
|
+
## 1.0.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- a59d636: Remove crypto as dep - available directly in Node
|
|
8
|
+
|
|
9
|
+
## 1.0.7
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 24782f5: separateCurrencyStrParts and tests
|
|
14
|
+
|
|
3
15
|
## 1.0.6
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -689,6 +689,11 @@ function formatCurrencyStr(amount, maxFractionDigits, compact, showBtcSymbol = f
|
|
|
689
689
|
});
|
|
690
690
|
}
|
|
691
691
|
}
|
|
692
|
+
function separateCurrencyStrParts(currencyStr) {
|
|
693
|
+
const symbol = currencyStr.replace(/[0-9\s\u00a0.,]/g, "");
|
|
694
|
+
const amount = currencyStr.replace(/[^\d.,-]/g, "");
|
|
695
|
+
return { symbol, amount };
|
|
696
|
+
}
|
|
692
697
|
function localeToCurrencySymbol(locale) {
|
|
693
698
|
const currencyCode = localeToCurrencyCode(locale);
|
|
694
699
|
const formatted = new Intl.NumberFormat(locale, {
|
|
@@ -699,7 +704,7 @@ function localeToCurrencySymbol(locale) {
|
|
|
699
704
|
minimumFractionDigits: 0,
|
|
700
705
|
maximumFractionDigits: 0
|
|
701
706
|
}).format(0);
|
|
702
|
-
const symbol = formatted
|
|
707
|
+
const { symbol } = separateCurrencyStrParts(formatted);
|
|
703
708
|
return symbol;
|
|
704
709
|
}
|
|
705
710
|
|
|
@@ -879,6 +884,7 @@ export {
|
|
|
879
884
|
isCurrencyMap,
|
|
880
885
|
abbrCurrencyUnit,
|
|
881
886
|
formatCurrencyStr,
|
|
887
|
+
separateCurrencyStrParts,
|
|
882
888
|
localeToCurrencySymbol,
|
|
883
889
|
isError,
|
|
884
890
|
isErrorWithMessage,
|
package/dist/index.cjs
CHANGED
|
@@ -77,6 +77,7 @@ __export(src_exports, {
|
|
|
77
77
|
mapCurrencyAmount: () => mapCurrencyAmount,
|
|
78
78
|
pollUntil: () => pollUntil,
|
|
79
79
|
round: () => round,
|
|
80
|
+
separateCurrencyStrParts: () => separateCurrencyStrParts,
|
|
80
81
|
sleep: () => sleep,
|
|
81
82
|
urlsafe_b64decode: () => urlsafe_b64decode
|
|
82
83
|
});
|
|
@@ -1018,6 +1019,11 @@ function formatCurrencyStr(amount, maxFractionDigits, compact, showBtcSymbol = f
|
|
|
1018
1019
|
});
|
|
1019
1020
|
}
|
|
1020
1021
|
}
|
|
1022
|
+
function separateCurrencyStrParts(currencyStr) {
|
|
1023
|
+
const symbol = currencyStr.replace(/[0-9\s\u00a0.,]/g, "");
|
|
1024
|
+
const amount = currencyStr.replace(/[^\d.,-]/g, "");
|
|
1025
|
+
return { symbol, amount };
|
|
1026
|
+
}
|
|
1021
1027
|
function localeToCurrencySymbol(locale) {
|
|
1022
1028
|
const currencyCode = localeToCurrencyCode(locale);
|
|
1023
1029
|
const formatted = new Intl.NumberFormat(locale, {
|
|
@@ -1028,7 +1034,7 @@ function localeToCurrencySymbol(locale) {
|
|
|
1028
1034
|
minimumFractionDigits: 0,
|
|
1029
1035
|
maximumFractionDigits: 0
|
|
1030
1036
|
}).format(0);
|
|
1031
|
-
const symbol = formatted
|
|
1037
|
+
const { symbol } = separateCurrencyStrParts(formatted);
|
|
1032
1038
|
return symbol;
|
|
1033
1039
|
}
|
|
1034
1040
|
|
|
@@ -1427,7 +1433,12 @@ var Requester = class {
|
|
|
1427
1433
|
if (!urlWithProtocol.startsWith("https://") && !urlWithProtocol.startsWith("http://")) {
|
|
1428
1434
|
urlWithProtocol = `https://${urlWithProtocol}`;
|
|
1429
1435
|
}
|
|
1430
|
-
const
|
|
1436
|
+
const url = `${urlWithProtocol}/${this.schemaEndpoint}`;
|
|
1437
|
+
logger.info(`Requester.makeRawRequest`, {
|
|
1438
|
+
url,
|
|
1439
|
+
variables
|
|
1440
|
+
});
|
|
1441
|
+
const response = await fetch(url, {
|
|
1431
1442
|
method: "POST",
|
|
1432
1443
|
headers,
|
|
1433
1444
|
body: JSON.stringify(bodyData)
|
|
@@ -1560,6 +1571,7 @@ var ServerEnvironment_default = ServerEnvironment;
|
|
|
1560
1571
|
mapCurrencyAmount,
|
|
1561
1572
|
pollUntil,
|
|
1562
1573
|
round,
|
|
1574
|
+
separateCurrencyStrParts,
|
|
1563
1575
|
sleep,
|
|
1564
1576
|
urlsafe_b64decode
|
|
1565
1577
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Observable } from 'zen-observable-ts';
|
|
2
|
-
export { ById, CurrencyAmountArg, CurrencyAmountObj, CurrencyAmountType, CurrencyCodes, CurrencyLocales, CurrencyMap, CurrencyUnit, ExpandRecursively, Maybe, OmitTypename, abbrCurrencyUnit, b64decode, b64encode, bytesToHex, clamp, convertCurrencyAmount, convertCurrencyAmountValue, countryCodesToCurrencyCodes, createSha256Hash, defaultCurrencyCode, formatCurrencyStr, getCurrentLocale, getErrorMsg, hexToBytes, isBrowser, isCurrencyAmount, isCurrencyAmountObj, isCurrencyMap, isError, isErrorMsg, isErrorWithMessage, isNode, isNumber, isTest, isType, linearInterpolate, localeToCurrencyCode, localeToCurrencySymbol, mapCurrencyAmount, pollUntil, round, sleep, urlsafe_b64decode } from './utils/index.js';
|
|
2
|
+
export { ById, CurrencyAmountArg, CurrencyAmountObj, CurrencyAmountType, CurrencyCodes, CurrencyLocales, CurrencyMap, CurrencyUnit, ExpandRecursively, Maybe, OmitTypename, abbrCurrencyUnit, b64decode, b64encode, bytesToHex, clamp, convertCurrencyAmount, convertCurrencyAmountValue, countryCodesToCurrencyCodes, createSha256Hash, defaultCurrencyCode, formatCurrencyStr, getCurrentLocale, getErrorMsg, hexToBytes, isBrowser, isCurrencyAmount, isCurrencyAmountObj, isCurrencyMap, isError, isErrorMsg, isErrorWithMessage, isNode, isNumber, isTest, isType, linearInterpolate, localeToCurrencyCode, localeToCurrencySymbol, mapCurrencyAmount, pollUntil, round, separateCurrencyStrParts, sleep, urlsafe_b64decode } from './utils/index.js';
|
|
3
3
|
|
|
4
4
|
type Headers = Record<string, string>;
|
|
5
5
|
type WsConnectionParams = Record<string, unknown>;
|
package/dist/index.js
CHANGED
|
@@ -32,9 +32,10 @@ import {
|
|
|
32
32
|
mapCurrencyAmount,
|
|
33
33
|
pollUntil,
|
|
34
34
|
round,
|
|
35
|
+
separateCurrencyStrParts,
|
|
35
36
|
sleep,
|
|
36
37
|
urlsafe_b64decode
|
|
37
|
-
} from "./chunk-
|
|
38
|
+
} from "./chunk-UU6SHVGX.js";
|
|
38
39
|
|
|
39
40
|
// src/auth/LightsparkAuthException.ts
|
|
40
41
|
var LightsparkAuthException = class extends LightsparkException_default {
|
|
@@ -526,7 +527,12 @@ var Requester = class {
|
|
|
526
527
|
if (!urlWithProtocol.startsWith("https://") && !urlWithProtocol.startsWith("http://")) {
|
|
527
528
|
urlWithProtocol = `https://${urlWithProtocol}`;
|
|
528
529
|
}
|
|
529
|
-
const
|
|
530
|
+
const url = `${urlWithProtocol}/${this.schemaEndpoint}`;
|
|
531
|
+
logger.info(`Requester.makeRawRequest`, {
|
|
532
|
+
url,
|
|
533
|
+
variables
|
|
534
|
+
});
|
|
535
|
+
const response = await fetch(url, {
|
|
530
536
|
method: "POST",
|
|
531
537
|
headers,
|
|
532
538
|
body: JSON.stringify(bodyData)
|
|
@@ -658,6 +664,7 @@ export {
|
|
|
658
664
|
mapCurrencyAmount,
|
|
659
665
|
pollUntil,
|
|
660
666
|
round,
|
|
667
|
+
separateCurrencyStrParts,
|
|
661
668
|
sleep,
|
|
662
669
|
urlsafe_b64decode
|
|
663
670
|
};
|
package/dist/utils/index.cjs
CHANGED
|
@@ -62,6 +62,7 @@ __export(utils_exports, {
|
|
|
62
62
|
mapCurrencyAmount: () => mapCurrencyAmount,
|
|
63
63
|
pollUntil: () => pollUntil,
|
|
64
64
|
round: () => round,
|
|
65
|
+
separateCurrencyStrParts: () => separateCurrencyStrParts,
|
|
65
66
|
sleep: () => sleep,
|
|
66
67
|
urlsafe_b64decode: () => urlsafe_b64decode
|
|
67
68
|
});
|
|
@@ -758,6 +759,11 @@ function formatCurrencyStr(amount, maxFractionDigits, compact, showBtcSymbol = f
|
|
|
758
759
|
});
|
|
759
760
|
}
|
|
760
761
|
}
|
|
762
|
+
function separateCurrencyStrParts(currencyStr) {
|
|
763
|
+
const symbol = currencyStr.replace(/[0-9\s\u00a0.,]/g, "");
|
|
764
|
+
const amount = currencyStr.replace(/[^\d.,-]/g, "");
|
|
765
|
+
return { symbol, amount };
|
|
766
|
+
}
|
|
761
767
|
function localeToCurrencySymbol(locale) {
|
|
762
768
|
const currencyCode = localeToCurrencyCode(locale);
|
|
763
769
|
const formatted = new Intl.NumberFormat(locale, {
|
|
@@ -768,7 +774,7 @@ function localeToCurrencySymbol(locale) {
|
|
|
768
774
|
minimumFractionDigits: 0,
|
|
769
775
|
maximumFractionDigits: 0
|
|
770
776
|
}).format(0);
|
|
771
|
-
const symbol = formatted
|
|
777
|
+
const { symbol } = separateCurrencyStrParts(formatted);
|
|
772
778
|
return symbol;
|
|
773
779
|
}
|
|
774
780
|
|
|
@@ -953,6 +959,7 @@ var isType = (typename) => (node) => {
|
|
|
953
959
|
mapCurrencyAmount,
|
|
954
960
|
pollUntil,
|
|
955
961
|
round,
|
|
962
|
+
separateCurrencyStrParts,
|
|
956
963
|
sleep,
|
|
957
964
|
urlsafe_b64decode
|
|
958
965
|
});
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -93,6 +93,10 @@ declare function mapCurrencyAmount(currencyAmountArg: CurrencyAmountArg, centsPe
|
|
|
93
93
|
declare const isCurrencyMap: (currencyMap: unknown) => currencyMap is CurrencyMap;
|
|
94
94
|
declare const abbrCurrencyUnit: (unit: CurrencyUnit) => "USD" | "BTC" | "SAT" | "MSAT" | "Unsupported CurrencyUnit";
|
|
95
95
|
declare function formatCurrencyStr(amount: CurrencyAmountArg, maxFractionDigits?: number, compact?: boolean, showBtcSymbol?: boolean, options?: Intl.NumberFormatOptions): string;
|
|
96
|
+
declare function separateCurrencyStrParts(currencyStr: string): {
|
|
97
|
+
symbol: string;
|
|
98
|
+
amount: string;
|
|
99
|
+
};
|
|
96
100
|
declare function localeToCurrencySymbol(locale: string): string;
|
|
97
101
|
|
|
98
102
|
declare const isBrowser: boolean;
|
|
@@ -212,4 +216,4 @@ declare const isType: <T extends string>(typename: T) => <N extends {
|
|
|
212
216
|
__typename: T;
|
|
213
217
|
}>;
|
|
214
218
|
|
|
215
|
-
export { ById, CurrencyAmountArg, CurrencyAmountObj, CurrencyAmountType, CurrencyCodes, CurrencyLocales, CurrencyMap, CurrencyUnit, ExpandRecursively, Maybe, OmitTypename, abbrCurrencyUnit, b64decode, b64encode, bytesToHex, clamp, convertCurrencyAmount, convertCurrencyAmountValue, countryCodesToCurrencyCodes, createSha256Hash, defaultCurrencyCode, formatCurrencyStr, getCurrentLocale, getErrorMsg, hexToBytes, isBrowser, isCurrencyAmount, isCurrencyAmountObj, isCurrencyMap, isError, isErrorMsg, isErrorWithMessage, isNode, isNumber, isTest, isType, linearInterpolate, localeToCurrencyCode, localeToCurrencySymbol, mapCurrencyAmount, pollUntil, round, sleep, urlsafe_b64decode };
|
|
219
|
+
export { ById, CurrencyAmountArg, CurrencyAmountObj, CurrencyAmountType, CurrencyCodes, CurrencyLocales, CurrencyMap, CurrencyUnit, ExpandRecursively, Maybe, OmitTypename, abbrCurrencyUnit, b64decode, b64encode, bytesToHex, clamp, convertCurrencyAmount, convertCurrencyAmountValue, countryCodesToCurrencyCodes, createSha256Hash, defaultCurrencyCode, formatCurrencyStr, getCurrentLocale, getErrorMsg, hexToBytes, isBrowser, isCurrencyAmount, isCurrencyAmountObj, isCurrencyMap, isError, isErrorMsg, isErrorWithMessage, isNode, isNumber, isTest, isType, linearInterpolate, localeToCurrencyCode, localeToCurrencySymbol, mapCurrencyAmount, pollUntil, round, separateCurrencyStrParts, sleep, urlsafe_b64decode };
|
package/dist/utils/index.js
CHANGED
|
@@ -31,9 +31,10 @@ import {
|
|
|
31
31
|
mapCurrencyAmount,
|
|
32
32
|
pollUntil,
|
|
33
33
|
round,
|
|
34
|
+
separateCurrencyStrParts,
|
|
34
35
|
sleep,
|
|
35
36
|
urlsafe_b64decode
|
|
36
|
-
} from "../chunk-
|
|
37
|
+
} from "../chunk-UU6SHVGX.js";
|
|
37
38
|
export {
|
|
38
39
|
CurrencyUnit,
|
|
39
40
|
abbrCurrencyUnit,
|
|
@@ -67,6 +68,7 @@ export {
|
|
|
67
68
|
mapCurrencyAmount,
|
|
68
69
|
pollUntil,
|
|
69
70
|
round,
|
|
71
|
+
separateCurrencyStrParts,
|
|
70
72
|
sleep,
|
|
71
73
|
urlsafe_b64decode
|
|
72
74
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lightsparkdev/core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.8",
|
|
4
4
|
"description": "Lightspark JS SDK",
|
|
5
5
|
"author": "Lightspark Inc.",
|
|
6
6
|
"keywords": [
|
|
@@ -77,7 +77,6 @@
|
|
|
77
77
|
"license": "Apache-2.0",
|
|
78
78
|
"dependencies": {
|
|
79
79
|
"auto-bind": "^5.0.1",
|
|
80
|
-
"crypto": "^1.0.1",
|
|
81
80
|
"crypto-browserify": "^3.12.0",
|
|
82
81
|
"dayjs": "^1.11.7",
|
|
83
82
|
"graphql": "^16.6.0",
|
|
@@ -161,7 +161,14 @@ class Requester {
|
|
|
161
161
|
) {
|
|
162
162
|
urlWithProtocol = `https://${urlWithProtocol}`;
|
|
163
163
|
}
|
|
164
|
-
|
|
164
|
+
|
|
165
|
+
const url = `${urlWithProtocol}/${this.schemaEndpoint}`;
|
|
166
|
+
|
|
167
|
+
logger.info(`Requester.makeRawRequest`, {
|
|
168
|
+
url,
|
|
169
|
+
variables,
|
|
170
|
+
});
|
|
171
|
+
const response = await fetch(url, {
|
|
165
172
|
method: "POST",
|
|
166
173
|
headers: headers,
|
|
167
174
|
body: JSON.stringify(bodyData),
|
package/src/utils/currency.ts
CHANGED
|
@@ -455,6 +455,13 @@ export function formatCurrencyStr(
|
|
|
455
455
|
}
|
|
456
456
|
}
|
|
457
457
|
|
|
458
|
+
export function separateCurrencyStrParts(currencyStr: string) {
|
|
459
|
+
// split the currency string into the symbol and the amount
|
|
460
|
+
const symbol = currencyStr.replace(/[0-9\s\u00a0.,]/g, "");
|
|
461
|
+
const amount = currencyStr.replace(/[^\d.,-]/g, "");
|
|
462
|
+
return { symbol, amount };
|
|
463
|
+
}
|
|
464
|
+
|
|
458
465
|
export function localeToCurrencySymbol(locale: string) {
|
|
459
466
|
const currencyCode = localeToCurrencyCode(locale);
|
|
460
467
|
const formatted = new Intl.NumberFormat(locale, {
|
|
@@ -466,6 +473,6 @@ export function localeToCurrencySymbol(locale: string) {
|
|
|
466
473
|
}).format(0);
|
|
467
474
|
|
|
468
475
|
// Remove numeric and non-breaking space characters to extract the currency symbol
|
|
469
|
-
const symbol = formatted
|
|
476
|
+
const { symbol } = separateCurrencyStrParts(formatted);
|
|
470
477
|
return symbol;
|
|
471
478
|
}
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
CurrencyUnit,
|
|
6
6
|
localeToCurrencySymbol,
|
|
7
7
|
mapCurrencyAmount,
|
|
8
|
+
separateCurrencyStrParts,
|
|
8
9
|
} from "../currency.js";
|
|
9
10
|
|
|
10
11
|
describe("convertCurrencyAmountValue", () => {
|
|
@@ -171,7 +172,7 @@ describe("mapCurrencyAmount", () => {
|
|
|
171
172
|
});
|
|
172
173
|
});
|
|
173
174
|
|
|
174
|
-
describe("
|
|
175
|
+
describe("localeToCurrencySymbol", () => {
|
|
175
176
|
it("should return the expected currency symbol", () => {
|
|
176
177
|
expect(localeToCurrencySymbol("en-US")).toBe("$");
|
|
177
178
|
expect(localeToCurrencySymbol("en-GB")).toBe("£");
|
|
@@ -188,3 +189,68 @@ describe("getCurrencySymbol", () => {
|
|
|
188
189
|
expect(localeToCurrencySymbol("es-AR")).toBe("$");
|
|
189
190
|
});
|
|
190
191
|
});
|
|
192
|
+
|
|
193
|
+
describe("separateCurrencyStrParts", () => {
|
|
194
|
+
const usdFormatted = new Intl.NumberFormat("en-US", {
|
|
195
|
+
style: "currency",
|
|
196
|
+
currency: "USD",
|
|
197
|
+
}).format(5);
|
|
198
|
+
expect(separateCurrencyStrParts(usdFormatted)).toEqual({
|
|
199
|
+
amount: "5.00",
|
|
200
|
+
symbol: "$",
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
const gbpFormatted = new Intl.NumberFormat("en-GB", {
|
|
204
|
+
style: "currency",
|
|
205
|
+
currency: "GBP",
|
|
206
|
+
}).format(5);
|
|
207
|
+
expect(separateCurrencyStrParts(gbpFormatted)).toEqual({
|
|
208
|
+
amount: "5.00",
|
|
209
|
+
symbol: "£",
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
const eurFormatted = new Intl.NumberFormat("en-IE", {
|
|
213
|
+
style: "currency",
|
|
214
|
+
currency: "EUR",
|
|
215
|
+
}).format(5);
|
|
216
|
+
expect(separateCurrencyStrParts(eurFormatted)).toEqual({
|
|
217
|
+
amount: "5.00",
|
|
218
|
+
symbol: "€",
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
const inrFormatted = new Intl.NumberFormat("en-IN", {
|
|
222
|
+
style: "currency",
|
|
223
|
+
currency: "INR",
|
|
224
|
+
}).format(5);
|
|
225
|
+
expect(separateCurrencyStrParts(inrFormatted)).toEqual({
|
|
226
|
+
amount: "5.00",
|
|
227
|
+
symbol: "₹",
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
const brlFormatted = new Intl.NumberFormat("pt-BR", {
|
|
231
|
+
style: "currency",
|
|
232
|
+
currency: "BRL",
|
|
233
|
+
}).format(5);
|
|
234
|
+
expect(separateCurrencyStrParts(brlFormatted)).toEqual({
|
|
235
|
+
amount: "5,00",
|
|
236
|
+
symbol: "R$",
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
const arsFormatted = new Intl.NumberFormat("es-AR", {
|
|
240
|
+
style: "currency",
|
|
241
|
+
currency: "ARS",
|
|
242
|
+
}).format(5);
|
|
243
|
+
expect(separateCurrencyStrParts(arsFormatted)).toEqual({
|
|
244
|
+
amount: "5,00",
|
|
245
|
+
symbol: "$",
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
const mxnFormatted = new Intl.NumberFormat("es-MX", {
|
|
249
|
+
style: "currency",
|
|
250
|
+
currency: "MXN",
|
|
251
|
+
}).format(5);
|
|
252
|
+
expect(separateCurrencyStrParts(mxnFormatted)).toEqual({
|
|
253
|
+
amount: "5.00",
|
|
254
|
+
symbol: "$",
|
|
255
|
+
});
|
|
256
|
+
});
|