@lightsparkdev/core 1.2.0 → 1.2.2

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 CHANGED
@@ -1,5 +1,19 @@
1
1
  # @lightsparkdev/core
2
2
 
3
+ ## 1.2.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 07900ac: - Upgrade deps
8
+ - Upgrade TypeScript to 5.6.2 and some related type fixes
9
+ - Improve clean scripts
10
+
11
+ ## 1.2.1
12
+
13
+ ### Patch Changes
14
+
15
+ - b43609d: - Add isObject
16
+
3
17
  ## 1.2.0
4
18
 
5
19
  ### Minor Changes
@@ -1,3 +1,8 @@
1
+ // src/utils/arrays.ts
2
+ function ensureArray(value) {
3
+ return Array.isArray(value) ? value : [value];
4
+ }
5
+
1
6
  // src/utils/base64.ts
2
7
  var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
3
8
  var Base64 = {
@@ -737,7 +742,7 @@ function localeToCurrencySymbol(locale) {
737
742
  // src/utils/errors.ts
738
743
  var isError = (e) => {
739
744
  return Boolean(
740
- typeof e === "object" && e !== null && "name" in e && typeof e.name === "string" && "message" in e && typeof e.message === "string" && "stack" in e && (!e.stack || typeof e.stack === "string")
745
+ typeof e === "object" && e !== null && "name" in e && typeof e.name === "string" && "message" in e && typeof e.message === "string"
741
746
  );
742
747
  };
743
748
  var isErrorWithMessage = (e) => {
@@ -921,8 +926,12 @@ function lsidToUUID(lsid) {
921
926
  }
922
927
 
923
928
  // src/utils/typeGuards.ts
924
- function isUint8Array(variable) {
925
- return variable instanceof Uint8Array;
929
+ function isUint8Array(value) {
930
+ return value instanceof Uint8Array;
931
+ }
932
+ function isObject2(value) {
933
+ const type = typeof value;
934
+ return value != null && (type == "object" || type == "function");
926
935
  }
927
936
 
928
937
  // src/utils/types.ts
@@ -935,12 +944,13 @@ function notNullUndefined(value) {
935
944
 
936
945
  export {
937
946
  LightsparkException_default,
938
- isBrowser,
939
- isNode,
940
- isTest,
941
947
  b64decode,
942
948
  urlsafe_b64decode,
943
949
  b64encode,
950
+ ensureArray,
951
+ isBrowser,
952
+ isNode,
953
+ isTest,
944
954
  bytesToHex,
945
955
  hexToBytes,
946
956
  createSha256Hash,
@@ -976,6 +986,7 @@ export {
976
986
  pollUntil,
977
987
  lsidToUUID,
978
988
  isUint8Array,
989
+ isObject2 as isObject,
979
990
  isType,
980
991
  notNullUndefined
981
992
  };
@@ -4,6 +4,8 @@ declare const ConfigKeys: {
4
4
  };
5
5
  type ConfigKeys = (typeof ConfigKeys)[keyof typeof ConfigKeys];
6
6
 
7
+ declare function ensureArray<T>(value: T | T[]): T[];
8
+
7
9
  declare const b64decode: (encoded: string) => Uint8Array;
8
10
  declare const urlsafe_b64decode: (encoded: string) => Uint8Array;
9
11
  declare const b64encode: (data: ArrayBuffer) => string;
@@ -108,7 +110,7 @@ type ById<T> = {
108
110
  type OmitTypename<T> = Omit<T, "__typename">;
109
111
  declare const isType: <T extends string>(typename: T) => <N extends {
110
112
  __typename: string;
111
- }>(node: N | null | undefined) => node is Extract<N, {
113
+ }>(node: N | undefined | null) => node is Extract<N, {
112
114
  __typename: T;
113
115
  }>;
114
116
  type DeepPartial<T> = T extends object ? {
@@ -140,11 +142,6 @@ declare function errorToJSON(err: unknown): JSONType;
140
142
  declare const bytesToHex: (bytes: Uint8Array) => string;
141
143
  declare const hexToBytes: (hex: string) => Uint8Array;
142
144
 
143
- declare function getLocalStorageConfigItem(key: ConfigKeys): boolean;
144
- declare function getLocalStorageBoolean(key: string): boolean;
145
- declare function setLocalStorageBoolean(key: string, value: boolean): void;
146
- declare const deleteLocalStorageItem: (key: string) => void;
147
-
148
145
  declare function getCurrentLocale(): string;
149
146
 
150
147
  declare const countryCodesToCurrencyCodes: {
@@ -218,6 +215,11 @@ type CurrencyLocales = keyof typeof countryCodesToCurrencyCodes;
218
215
  type CurrencyCodes = (typeof countryCodesToCurrencyCodes)[CurrencyLocales];
219
216
  declare function localeToCurrencyCode(locale: string): CurrencyCodes;
220
217
 
218
+ declare function getLocalStorageConfigItem(key: ConfigKeys): boolean;
219
+ declare function getLocalStorageBoolean(key: string): boolean;
220
+ declare function setLocalStorageBoolean(key: string, value: boolean): void;
221
+ declare const deleteLocalStorageItem: (key: string) => void;
222
+
221
223
  declare function clamp(val: number, min: number, max: number): number;
222
224
  declare function linearInterpolate(value: number, fromRangeStart: number, fromRangeEnd: number, toRangeStart: number, toRangeEnd: number): number;
223
225
  declare function round(num: number, decimalPlaces?: number): number;
@@ -236,6 +238,7 @@ declare function sleep(ms: number): Promise<unknown>;
236
238
 
237
239
  declare function lsidToUUID(lsid: string): string;
238
240
 
239
- declare function isUint8Array(variable: unknown): variable is Uint8Array;
241
+ declare function isUint8Array(value: unknown): value is Uint8Array;
242
+ declare function isObject(value: unknown): value is Record<string, unknown>;
240
243
 
241
- export { isType as $, isErrorMsg as A, errorToJSON as B, ConfigKeys as C, bytesToHex as D, hexToBytes as E, getLocalStorageConfigItem as F, getLocalStorageBoolean as G, setLocalStorageBoolean as H, deleteLocalStorageItem as I, getCurrentLocale as J, countryCodesToCurrencyCodes as K, CurrencyLocales as L, CurrencyCodes as M, localeToCurrencyCode as N, clamp as O, linearInterpolate as P, round as Q, isNumber as R, SDKCurrencyAmountType as S, pollUntil as T, sleep as U, lsidToUUID as V, isUint8Array as W, Maybe as X, ExpandRecursively as Y, ById as Z, OmitTypename as _, b64encode as a, DeepPartial as a0, JSONLiteral as a1, JSONType as a2, JSONObject as a3, NN as a4, notNullUndefined as a5, PartialBy as a6, Complete as a7, b64decode as b, createSha256Hash as c, defaultCurrencyCode as d, CurrencyUnit as e, CurrencyUnitType as f, convertCurrencyAmountValue as g, convertCurrencyAmount as h, CurrencyMap as i, CurrencyAmountObj as j, CurrencyAmountArg as k, isCurrencyAmountObj as l, isSDKCurrencyAmount as m, mapCurrencyAmount as n, isCurrencyMap as o, abbrCurrencyUnit as p, formatCurrencyStr as q, localeToCurrencySymbol as r, separateCurrencyStrParts as s, isBrowser as t, urlsafe_b64decode as u, isNode as v, isTest as w, isError as x, isErrorWithMessage as y, getErrorMsg as z };
244
+ export { type ById as $, getErrorMsg as A, isErrorMsg as B, ConfigKeys as C, errorToJSON as D, bytesToHex as E, hexToBytes as F, getCurrentLocale as G, countryCodesToCurrencyCodes as H, type CurrencyLocales as I, type CurrencyCodes as J, localeToCurrencyCode as K, getLocalStorageConfigItem as L, getLocalStorageBoolean as M, setLocalStorageBoolean as N, deleteLocalStorageItem as O, clamp as P, linearInterpolate as Q, round as R, type SDKCurrencyAmountType as S, isNumber as T, pollUntil as U, sleep as V, lsidToUUID as W, isUint8Array as X, isObject as Y, type Maybe as Z, type ExpandRecursively as _, b64encode as a, type OmitTypename as a0, isType as a1, type DeepPartial as a2, type JSONLiteral as a3, type JSONType as a4, type JSONObject as a5, type NN as a6, notNullUndefined as a7, type PartialBy as a8, type Complete as a9, b64decode as b, createSha256Hash as c, defaultCurrencyCode as d, ensureArray as e, CurrencyUnit as f, type CurrencyUnitType as g, convertCurrencyAmountValue as h, convertCurrencyAmount as i, type CurrencyMap as j, type CurrencyAmountObj as k, type CurrencyAmountArg as l, isCurrencyAmountObj as m, isSDKCurrencyAmount as n, mapCurrencyAmount as o, isCurrencyMap as p, abbrCurrencyUnit as q, formatCurrencyStr as r, separateCurrencyStrParts as s, localeToCurrencySymbol as t, urlsafe_b64decode as u, isBrowser as v, isNode as w, isTest as x, isError as y, isErrorWithMessage as z };
@@ -0,0 +1,244 @@
1
+ declare const ConfigKeys: {
2
+ readonly LoggingEnabled: "lightspark-logging-enabled";
3
+ readonly ConsoleToolsEnabled: "lightspark-console-tools-enabled";
4
+ };
5
+ type ConfigKeys = (typeof ConfigKeys)[keyof typeof ConfigKeys];
6
+
7
+ declare function ensureArray<T>(value: T | T[]): T[];
8
+
9
+ declare const b64decode: (encoded: string) => Uint8Array;
10
+ declare const urlsafe_b64decode: (encoded: string) => Uint8Array;
11
+ declare const b64encode: (data: ArrayBuffer) => string;
12
+
13
+ type SourceData = Uint8Array | string;
14
+ declare function createSha256Hash(data: SourceData): Promise<Uint8Array>;
15
+ declare function createSha256Hash(data: SourceData, asHex: true): Promise<string>;
16
+
17
+ declare const defaultCurrencyCode = "USD";
18
+ declare const CurrencyUnit: {
19
+ readonly FUTURE_VALUE: "FUTURE_VALUE";
20
+ readonly BITCOIN: "BITCOIN";
21
+ readonly SATOSHI: "SATOSHI";
22
+ readonly MILLISATOSHI: "MILLISATOSHI";
23
+ readonly USD: "USD";
24
+ readonly NANOBITCOIN: "NANOBITCOIN";
25
+ readonly MICROBITCOIN: "MICROBITCOIN";
26
+ readonly MILLIBITCOIN: "MILLIBITCOIN";
27
+ readonly Bitcoin: "BITCOIN";
28
+ readonly Microbitcoin: "MICROBITCOIN";
29
+ readonly Millibitcoin: "MILLIBITCOIN";
30
+ readonly Millisatoshi: "MILLISATOSHI";
31
+ readonly Nanobitcoin: "NANOBITCOIN";
32
+ readonly Satoshi: "SATOSHI";
33
+ readonly Usd: "USD";
34
+ };
35
+ type CurrencyUnitType = (typeof CurrencyUnit)[keyof typeof CurrencyUnit];
36
+ type SDKCurrencyAmountType = {
37
+ originalValue: number;
38
+ originalUnit: CurrencyUnitType;
39
+ preferredCurrencyUnit: CurrencyUnitType;
40
+ preferredCurrencyValueRounded: number;
41
+ preferredCurrencyValueApprox: number;
42
+ };
43
+ declare function convertCurrencyAmountValue(fromUnit: CurrencyUnitType, toUnit: CurrencyUnitType, amount: number, centsPerBtc?: number): number;
44
+ declare const convertCurrencyAmount: (from: SDKCurrencyAmountType, toUnit: CurrencyUnitType) => SDKCurrencyAmountType;
45
+ type CurrencyMap = {
46
+ sats: number;
47
+ msats: number;
48
+ btc: number;
49
+ [CurrencyUnit.BITCOIN]: number;
50
+ [CurrencyUnit.SATOSHI]: number;
51
+ [CurrencyUnit.MILLISATOSHI]: number;
52
+ [CurrencyUnit.MICROBITCOIN]: number;
53
+ [CurrencyUnit.MILLIBITCOIN]: number;
54
+ [CurrencyUnit.NANOBITCOIN]: number;
55
+ [CurrencyUnit.USD]: number;
56
+ [CurrencyUnit.FUTURE_VALUE]: number;
57
+ formatted: {
58
+ sats: string;
59
+ msats: string;
60
+ btc: string;
61
+ [CurrencyUnit.BITCOIN]: string;
62
+ [CurrencyUnit.SATOSHI]: string;
63
+ [CurrencyUnit.MILLISATOSHI]: string;
64
+ [CurrencyUnit.MILLIBITCOIN]: string;
65
+ [CurrencyUnit.MICROBITCOIN]: string;
66
+ [CurrencyUnit.NANOBITCOIN]: string;
67
+ [CurrencyUnit.USD]: string;
68
+ [CurrencyUnit.FUTURE_VALUE]: string;
69
+ };
70
+ isZero: boolean;
71
+ isLessThan: (other: CurrencyMap | CurrencyAmountObj | number) => boolean;
72
+ isGreaterThan: (other: CurrencyMap | CurrencyAmountObj | number) => boolean;
73
+ isEqualTo: (other: CurrencyMap | CurrencyAmountObj | number) => boolean;
74
+ type: "CurrencyMap";
75
+ };
76
+ type CurrencyAmountObj = {
77
+ value?: number | string | null;
78
+ unit?: CurrencyUnitType;
79
+ __typename?: "CurrencyAmount" | undefined;
80
+ };
81
+ type CurrencyAmountArg = CurrencyAmountObj | SDKCurrencyAmountType | undefined | null;
82
+ declare function isCurrencyAmountObj(arg: unknown): arg is CurrencyAmountObj;
83
+ declare function isSDKCurrencyAmount(arg: unknown): arg is SDKCurrencyAmountType;
84
+ declare function mapCurrencyAmount(currencyAmountArg: CurrencyAmountArg, centsPerBtc?: number): CurrencyMap;
85
+ declare const isCurrencyMap: (currencyMap: unknown) => currencyMap is CurrencyMap;
86
+ declare const abbrCurrencyUnit: (unit: CurrencyUnitType) => "USD" | "BTC" | "SAT" | "MSAT" | "Unsupported CurrencyUnit";
87
+ type FormatCurrencyStrOptions = {
88
+ precision?: number | "full" | undefined;
89
+ compact?: boolean | undefined;
90
+ showBtcSymbol?: boolean | undefined;
91
+ };
92
+ declare function formatCurrencyStr(amount: CurrencyAmountArg, options?: FormatCurrencyStrOptions): string;
93
+ declare function separateCurrencyStrParts(currencyStr: string): {
94
+ symbol: string;
95
+ amount: string;
96
+ };
97
+ declare function localeToCurrencySymbol(locale: string): string;
98
+
99
+ declare const isBrowser: boolean;
100
+ declare const isNode: boolean;
101
+ declare const isTest: boolean;
102
+
103
+ type Maybe<T> = T | null | undefined;
104
+ type ExpandRecursively<T> = T extends object ? T extends infer O ? {
105
+ [K in keyof O]: ExpandRecursively<O[K]>;
106
+ } : never : T;
107
+ type ById<T> = {
108
+ [id: string]: T;
109
+ };
110
+ type OmitTypename<T> = Omit<T, "__typename">;
111
+ declare const isType: <T extends string>(typename: T) => <N extends {
112
+ __typename: string;
113
+ }>(node: N | undefined | null) => node is Extract<N, {
114
+ __typename: T;
115
+ }>;
116
+ type DeepPartial<T> = T extends object ? {
117
+ [P in keyof T]?: DeepPartial<T[P]>;
118
+ } : T;
119
+ type JSONLiteral = string | number | boolean | null;
120
+ type JSONType = JSONLiteral | JSONType[] | {
121
+ [key: string]: JSONType;
122
+ };
123
+ type JSONObject = {
124
+ [key: string]: JSONType;
125
+ };
126
+ type NN<T> = NonNullable<T>;
127
+ declare function notNullUndefined<TValue>(value: TValue | null | undefined): value is TValue;
128
+ type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
129
+ type Complete<T> = {
130
+ [P in keyof T]-?: NonNullable<T[P]>;
131
+ };
132
+
133
+ declare const isError: (e: unknown) => e is Error;
134
+ type ErrorWithMessage = {
135
+ message: string;
136
+ };
137
+ declare const isErrorWithMessage: (e: unknown) => e is ErrorWithMessage;
138
+ declare const getErrorMsg: (e: unknown) => string;
139
+ declare const isErrorMsg: (e: unknown, msg: string) => boolean;
140
+ declare function errorToJSON(err: unknown): JSONType;
141
+
142
+ declare const bytesToHex: (bytes: Uint8Array) => string;
143
+ declare const hexToBytes: (hex: string) => Uint8Array;
144
+
145
+ declare function getCurrentLocale(): string;
146
+
147
+ declare const countryCodesToCurrencyCodes: {
148
+ readonly AD: "EUR";
149
+ readonly AR: "ARS";
150
+ readonly AS: "USD";
151
+ readonly AT: "EUR";
152
+ readonly AU: "AUD";
153
+ readonly AX: "EUR";
154
+ readonly BE: "EUR";
155
+ readonly BL: "EUR";
156
+ readonly BQ: "USD";
157
+ readonly BR: "BRL";
158
+ readonly CA: "CAD";
159
+ readonly CO: "COP";
160
+ readonly CY: "EUR";
161
+ readonly DE: "EUR";
162
+ readonly EC: "USD";
163
+ readonly EE: "EUR";
164
+ readonly ES: "EUR";
165
+ readonly FI: "EUR";
166
+ readonly FM: "USD";
167
+ readonly FR: "EUR";
168
+ readonly GB: "GBP";
169
+ readonly GF: "EUR";
170
+ readonly GG: "GBP";
171
+ readonly GP: "EUR";
172
+ readonly GR: "EUR";
173
+ readonly GS: "GBP";
174
+ readonly GU: "USD";
175
+ readonly IE: "EUR";
176
+ readonly IM: "GBP";
177
+ readonly IN: "INR";
178
+ readonly IO: "USD";
179
+ readonly IT: "EUR";
180
+ readonly JE: "GBP";
181
+ readonly LT: "EUR";
182
+ readonly LU: "EUR";
183
+ readonly LV: "EUR";
184
+ readonly MC: "EUR";
185
+ readonly ME: "EUR";
186
+ readonly MF: "EUR";
187
+ readonly MH: "USD";
188
+ readonly MP: "USD";
189
+ readonly MQ: "EUR";
190
+ readonly MT: "EUR";
191
+ readonly MX: "MXN";
192
+ readonly NF: "AUD";
193
+ readonly NL: "EUR";
194
+ readonly NR: "AUD";
195
+ readonly PM: "EUR";
196
+ readonly PR: "USD";
197
+ readonly PT: "EUR";
198
+ readonly PW: "USD";
199
+ readonly RE: "EUR";
200
+ readonly SI: "EUR";
201
+ readonly SK: "EUR";
202
+ readonly SM: "EUR";
203
+ readonly TC: "USD";
204
+ readonly TF: "EUR";
205
+ readonly TL: "USD";
206
+ readonly TV: "AUD";
207
+ readonly UM: "USD";
208
+ readonly US: "USD";
209
+ readonly VA: "EUR";
210
+ readonly VG: "USD";
211
+ readonly VI: "USD";
212
+ readonly YT: "EUR";
213
+ };
214
+ type CurrencyLocales = keyof typeof countryCodesToCurrencyCodes;
215
+ type CurrencyCodes = (typeof countryCodesToCurrencyCodes)[CurrencyLocales];
216
+ declare function localeToCurrencyCode(locale: string): CurrencyCodes;
217
+
218
+ declare function getLocalStorageConfigItem(key: ConfigKeys): boolean;
219
+ declare function getLocalStorageBoolean(key: string): boolean;
220
+ declare function setLocalStorageBoolean(key: string, value: boolean): void;
221
+ declare const deleteLocalStorageItem: (key: string) => void;
222
+
223
+ declare function clamp(val: number, min: number, max: number): number;
224
+ declare function linearInterpolate(value: number, fromRangeStart: number, fromRangeEnd: number, toRangeStart: number, toRangeEnd: number): number;
225
+ declare function round(num: number, decimalPlaces?: number): number;
226
+ declare function isNumber(value: unknown): value is number;
227
+
228
+ type GetValueResult<T> = {
229
+ stopPolling: boolean;
230
+ value: null | T;
231
+ };
232
+ declare function pollUntil<D extends () => Promise<unknown>, T>(asyncFn: D, getValue: (data: Awaited<ReturnType<D>>, response: {
233
+ stopPolling: boolean;
234
+ value: null | T;
235
+ }) => GetValueResult<T>, maxPolls?: number, pollIntervalMs?: number, ignoreErrors?: boolean | ((e: unknown) => boolean), getMaxPollsError?: (maxPolls: number) => Error): Promise<T>;
236
+
237
+ declare function sleep(ms: number): Promise<unknown>;
238
+
239
+ declare function lsidToUUID(lsid: string): string;
240
+
241
+ declare function isUint8Array(value: unknown): value is Uint8Array;
242
+ declare function isObject(value: unknown): value is Record<string, unknown>;
243
+
244
+ export { type ById as $, getErrorMsg as A, isErrorMsg as B, ConfigKeys as C, errorToJSON as D, bytesToHex as E, hexToBytes as F, getCurrentLocale as G, countryCodesToCurrencyCodes as H, type CurrencyLocales as I, type CurrencyCodes as J, localeToCurrencyCode as K, getLocalStorageConfigItem as L, getLocalStorageBoolean as M, setLocalStorageBoolean as N, deleteLocalStorageItem as O, clamp as P, linearInterpolate as Q, round as R, type SDKCurrencyAmountType as S, isNumber as T, pollUntil as U, sleep as V, lsidToUUID as W, isUint8Array as X, isObject as Y, type Maybe as Z, type ExpandRecursively as _, b64encode as a, type OmitTypename as a0, isType as a1, type DeepPartial as a2, type JSONLiteral as a3, type JSONType as a4, type JSONObject as a5, type NN as a6, notNullUndefined as a7, type PartialBy as a8, type Complete as a9, b64decode as b, createSha256Hash as c, defaultCurrencyCode as d, ensureArray as e, CurrencyUnit as f, type CurrencyUnitType as g, convertCurrencyAmountValue as h, convertCurrencyAmount as i, type CurrencyMap as j, type CurrencyAmountObj as k, type CurrencyAmountArg as l, isCurrencyAmountObj as m, isSDKCurrencyAmount as n, mapCurrencyAmount as o, isCurrencyMap as p, abbrCurrencyUnit as q, formatCurrencyStr as r, separateCurrencyStrParts as s, localeToCurrencySymbol as t, urlsafe_b64decode as u, isBrowser as v, isNode as w, isTest as x, isError as y, isErrorWithMessage as z };