@lightsparkdev/core 1.0.5 → 1.0.7

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.
@@ -6,25 +6,8 @@ type SourceData = Uint8Array | string;
6
6
  declare function createSha256Hash(data: SourceData): Promise<Uint8Array>;
7
7
  declare function createSha256Hash(data: SourceData, asHex: true): Promise<string>;
8
8
 
9
- /** Represents the value and unit for an amount of currency. **/
10
- type CurrencyAmount = {
11
- /** The original numeric value for this CurrencyAmount. **/
12
- originalValue: number;
13
- /** The original unit of currency for this CurrencyAmount. **/
14
- originalUnit: CurrencyUnit;
15
- /** The unit of user's preferred currency. **/
16
- preferredCurrencyUnit: CurrencyUnit;
17
- /**
18
- * The rounded numeric value for this CurrencyAmount in the very base level of user's preferred
19
- * currency. For example, for USD, the value will be in cents.
20
- **/
21
- preferredCurrencyValueRounded: number;
22
- /**
23
- * The approximate float value for this CurrencyAmount in the very base level of user's preferred
24
- * currency. For example, for USD, the value will be in cents.
25
- **/
26
- preferredCurrencyValueApprox: number;
27
- };
9
+ declare const defaultCurrencyCode = "USD";
10
+ /** This enum identifies the unit of currency associated with a CurrencyAmount. **/
28
11
  declare enum CurrencyUnit {
29
12
  /**
30
13
  * This is an enum value that represents values that could be added in the future.
@@ -46,7 +29,75 @@ declare enum CurrencyUnit {
46
29
  /** 0.001 (10e-3) Bitcoin or a thousandth of a Bitcoin. We recommend using the Satoshi unit instead when possible. **/
47
30
  MILLIBITCOIN = "MILLIBITCOIN"
48
31
  }
49
- declare const convertCurrencyAmount: (from: CurrencyAmount, toUnit: CurrencyUnit) => CurrencyAmount;
32
+ /** This object represents the value and unit for an amount of currency. **/
33
+ type CurrencyAmountType = {
34
+ /** The original numeric value for this CurrencyAmount. **/
35
+ originalValue: number;
36
+ /** The original unit of currency for this CurrencyAmount. **/
37
+ originalUnit: CurrencyUnit;
38
+ /** The unit of user's preferred currency. **/
39
+ preferredCurrencyUnit: CurrencyUnit;
40
+ /**
41
+ * The rounded numeric value for this CurrencyAmount in the very base level of user's preferred
42
+ * currency. For example, for USD, the value will be in cents.
43
+ **/
44
+ preferredCurrencyValueRounded: number;
45
+ /**
46
+ * The approximate float value for this CurrencyAmount in the very base level of user's preferred
47
+ * currency. For example, for USD, the value will be in cents.
48
+ **/
49
+ preferredCurrencyValueApprox: number;
50
+ };
51
+ declare function convertCurrencyAmountValue(fromUnit: CurrencyUnit, toUnit: CurrencyUnit, amount: number, centsPerBtc?: number): number;
52
+ declare const convertCurrencyAmount: (from: CurrencyAmountType, toUnit: CurrencyUnit) => CurrencyAmountType;
53
+ type CurrencyMap = {
54
+ sats: number;
55
+ msats: number;
56
+ btc: number;
57
+ [CurrencyUnit.BITCOIN]: number;
58
+ [CurrencyUnit.SATOSHI]: number;
59
+ [CurrencyUnit.MILLISATOSHI]: number;
60
+ [CurrencyUnit.MICROBITCOIN]: number;
61
+ [CurrencyUnit.MILLIBITCOIN]: number;
62
+ [CurrencyUnit.NANOBITCOIN]: number;
63
+ [CurrencyUnit.USD]: number;
64
+ [CurrencyUnit.FUTURE_VALUE]: number;
65
+ formatted: {
66
+ sats: string;
67
+ msats: string;
68
+ btc: string;
69
+ [CurrencyUnit.BITCOIN]: string;
70
+ [CurrencyUnit.SATOSHI]: string;
71
+ [CurrencyUnit.MILLISATOSHI]: string;
72
+ [CurrencyUnit.MILLIBITCOIN]: string;
73
+ [CurrencyUnit.MICROBITCOIN]: string;
74
+ [CurrencyUnit.NANOBITCOIN]: string;
75
+ [CurrencyUnit.USD]: string;
76
+ [CurrencyUnit.FUTURE_VALUE]: string;
77
+ };
78
+ isZero: boolean;
79
+ isLessThan: (other: CurrencyMap | CurrencyAmountObj | number) => boolean;
80
+ isGreaterThan: (other: CurrencyMap | CurrencyAmountObj | number) => boolean;
81
+ isEqualTo: (other: CurrencyMap | CurrencyAmountObj | number) => boolean;
82
+ type: "CurrencyMap";
83
+ };
84
+ type CurrencyAmountObj = {
85
+ value?: number | string | null;
86
+ unit?: CurrencyUnit;
87
+ __typename?: "CurrencyAmount";
88
+ };
89
+ type CurrencyAmountArg = CurrencyAmountObj | CurrencyAmountType | undefined | null;
90
+ declare function isCurrencyAmountObj(arg: unknown): arg is CurrencyAmountObj;
91
+ declare function isCurrencyAmount(arg: unknown): arg is CurrencyAmountType;
92
+ declare function mapCurrencyAmount(currencyAmountArg: CurrencyAmountArg, centsPerBtc?: number): CurrencyMap;
93
+ declare const isCurrencyMap: (currencyMap: unknown) => currencyMap is CurrencyMap;
94
+ declare const abbrCurrencyUnit: (unit: CurrencyUnit) => "USD" | "BTC" | "SAT" | "MSAT" | "Unsupported CurrencyUnit";
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
+ };
100
+ declare function localeToCurrencySymbol(locale: string): string;
50
101
 
51
102
  declare const isBrowser: boolean;
52
103
  declare const isNode: boolean;
@@ -63,6 +114,84 @@ declare const isErrorMsg: (e: unknown, msg: string) => boolean;
63
114
  declare const bytesToHex: (bytes: Uint8Array) => string;
64
115
  declare const hexToBytes: (hex: string) => Uint8Array;
65
116
 
117
+ declare function getCurrentLocale(): string;
118
+
119
+ declare const countryCodesToCurrencyCodes: {
120
+ readonly AD: "EUR";
121
+ readonly AR: "ARS";
122
+ readonly AS: "USD";
123
+ readonly AT: "EUR";
124
+ readonly AU: "AUD";
125
+ readonly AX: "EUR";
126
+ readonly BE: "EUR";
127
+ readonly BL: "EUR";
128
+ readonly BQ: "USD";
129
+ readonly BR: "BRL";
130
+ readonly CA: "CAD";
131
+ readonly CO: "COP";
132
+ readonly CY: "EUR";
133
+ readonly DE: "EUR";
134
+ readonly EC: "USD";
135
+ readonly EE: "EUR";
136
+ readonly ES: "EUR";
137
+ readonly FI: "EUR";
138
+ readonly FM: "USD";
139
+ readonly FR: "EUR";
140
+ readonly GB: "GBP";
141
+ readonly GF: "EUR";
142
+ readonly GG: "GBP";
143
+ readonly GP: "EUR";
144
+ readonly GR: "EUR";
145
+ readonly GS: "GBP";
146
+ readonly GU: "USD";
147
+ readonly IE: "EUR";
148
+ readonly IM: "GBP";
149
+ readonly IN: "INR";
150
+ readonly IO: "USD";
151
+ readonly IT: "EUR";
152
+ readonly JE: "GBP";
153
+ readonly LT: "EUR";
154
+ readonly LU: "EUR";
155
+ readonly LV: "EUR";
156
+ readonly MC: "EUR";
157
+ readonly ME: "EUR";
158
+ readonly MF: "EUR";
159
+ readonly MH: "USD";
160
+ readonly MP: "USD";
161
+ readonly MQ: "EUR";
162
+ readonly MT: "EUR";
163
+ readonly MX: "MXN";
164
+ readonly NF: "AUD";
165
+ readonly NL: "EUR";
166
+ readonly NR: "AUD";
167
+ readonly PM: "EUR";
168
+ readonly PR: "USD";
169
+ readonly PT: "EUR";
170
+ readonly PW: "USD";
171
+ readonly RE: "EUR";
172
+ readonly SI: "EUR";
173
+ readonly SK: "EUR";
174
+ readonly SM: "EUR";
175
+ readonly TC: "USD";
176
+ readonly TF: "EUR";
177
+ readonly TL: "USD";
178
+ readonly TV: "AUD";
179
+ readonly UM: "USD";
180
+ readonly US: "USD";
181
+ readonly VA: "EUR";
182
+ readonly VG: "USD";
183
+ readonly VI: "USD";
184
+ readonly YT: "EUR";
185
+ };
186
+ type CurrencyLocales = keyof typeof countryCodesToCurrencyCodes;
187
+ type CurrencyCodes = (typeof countryCodesToCurrencyCodes)[CurrencyLocales];
188
+ declare function localeToCurrencyCode(locale: string): CurrencyCodes;
189
+
190
+ declare function clamp(val: number, min: number, max: number): number;
191
+ declare function linearInterpolate(value: number, fromRangeStart: number, fromRangeEnd: number, toRangeStart: number, toRangeEnd: number): number;
192
+ declare function round(num: number, decimalPlaces?: number): number;
193
+ declare function isNumber(value: unknown): value is number;
194
+
66
195
  declare function pollUntil<D extends () => Promise<unknown>, T>(asyncFn: D, getValue: (data: Awaited<ReturnType<D>>, response: {
67
196
  stopPolling: boolean;
68
197
  value: null | T;
@@ -87,4 +216,4 @@ declare const isType: <T extends string>(typename: T) => <N extends {
87
216
  __typename: T;
88
217
  }>;
89
218
 
90
- export { ById, ExpandRecursively, Maybe, OmitTypename, b64decode, b64encode, bytesToHex, convertCurrencyAmount, createSha256Hash, getErrorMsg, hexToBytes, isBrowser, isError, isErrorMsg, isErrorWithMessage, isNode, isTest, isType, pollUntil, 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 };
@@ -1,38 +1,74 @@
1
1
  import {
2
+ CurrencyUnit,
3
+ abbrCurrencyUnit,
2
4
  b64decode,
3
5
  b64encode,
4
6
  bytesToHex,
7
+ clamp,
5
8
  convertCurrencyAmount,
9
+ convertCurrencyAmountValue,
10
+ countryCodesToCurrencyCodes,
6
11
  createSha256Hash,
12
+ defaultCurrencyCode,
13
+ formatCurrencyStr,
14
+ getCurrentLocale,
7
15
  getErrorMsg,
8
16
  hexToBytes,
9
17
  isBrowser,
18
+ isCurrencyAmount,
19
+ isCurrencyAmountObj,
20
+ isCurrencyMap,
10
21
  isError,
11
22
  isErrorMsg,
12
23
  isErrorWithMessage,
13
24
  isNode,
25
+ isNumber,
14
26
  isTest,
15
27
  isType,
28
+ linearInterpolate,
29
+ localeToCurrencyCode,
30
+ localeToCurrencySymbol,
31
+ mapCurrencyAmount,
16
32
  pollUntil,
33
+ round,
34
+ separateCurrencyStrParts,
17
35
  sleep,
18
36
  urlsafe_b64decode
19
- } from "../chunk-5P2KZ44N.js";
37
+ } from "../chunk-UU6SHVGX.js";
20
38
  export {
39
+ CurrencyUnit,
40
+ abbrCurrencyUnit,
21
41
  b64decode,
22
42
  b64encode,
23
43
  bytesToHex,
44
+ clamp,
24
45
  convertCurrencyAmount,
46
+ convertCurrencyAmountValue,
47
+ countryCodesToCurrencyCodes,
25
48
  createSha256Hash,
49
+ defaultCurrencyCode,
50
+ formatCurrencyStr,
51
+ getCurrentLocale,
26
52
  getErrorMsg,
27
53
  hexToBytes,
28
54
  isBrowser,
55
+ isCurrencyAmount,
56
+ isCurrencyAmountObj,
57
+ isCurrencyMap,
29
58
  isError,
30
59
  isErrorMsg,
31
60
  isErrorWithMessage,
32
61
  isNode,
62
+ isNumber,
33
63
  isTest,
34
64
  isType,
65
+ linearInterpolate,
66
+ localeToCurrencyCode,
67
+ localeToCurrencySymbol,
68
+ mapCurrencyAmount,
35
69
  pollUntil,
70
+ round,
71
+ separateCurrencyStrParts,
36
72
  sleep,
37
73
  urlsafe_b64decode
38
74
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lightsparkdev/core",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "Lightspark JS SDK",
5
5
  "author": "Lightspark Inc.",
6
6
  "keywords": [
@@ -70,7 +70,7 @@
70
70
  "lint:watch": "esw ./src -w --ext .ts,.tsx,.js --color",
71
71
  "lint": "eslint .",
72
72
  "postversion": "yarn build",
73
- "test": "echo \"TODO\"",
73
+ "test": "node --experimental-vm-modules $(yarn bin jest) --no-cache --runInBand --bail src/**/tests/**/*.test.ts",
74
74
  "types:watch": "tsc-absolute --watch",
75
75
  "types": "tsc"
76
76
  },
@@ -91,6 +91,7 @@
91
91
  "@lightsparkdev/eslint-config": "*",
92
92
  "@lightsparkdev/tsconfig": "0.0.0",
93
93
  "@types/crypto-js": "^4.1.1",
94
+ "@types/jest": "^29.5.3",
94
95
  "@types/secp256k1": "^4.0.3",
95
96
  "@types/ws": "^8.5.4",
96
97
  "eslint": "^8.3.0",