@leather.io/utils 0.43.0 → 0.44.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/.turbo/turbo-build.log +6 -6
- package/CHANGELOG.md +14 -0
- package/dist/index.d.ts +32 -1
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
- package/src/flatten-object.spec.ts +263 -0
- package/src/flatten-object.ts +55 -0
- package/src/index.ts +1 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @leather.io/utils@0.
|
|
2
|
+
> @leather.io/utils@0.44.1 build /home/runner/work/mono/mono/packages/utils
|
|
3
3
|
> tsup
|
|
4
4
|
|
|
5
5
|
[34mCLI[39m Building entry: src/index.ts
|
|
@@ -8,9 +8,9 @@
|
|
|
8
8
|
[34mCLI[39m Using tsup config: /home/runner/work/mono/mono/packages/utils/tsup.config.ts
|
|
9
9
|
[34mCLI[39m Target: es2022
|
|
10
10
|
[34mESM[39m Build start
|
|
11
|
-
[32mESM[39m [1mdist/index.js [22m[
|
|
12
|
-
[32mESM[39m [1mdist/index.js.map [22m[
|
|
13
|
-
[32mESM[39m ⚡️ Build success in
|
|
11
|
+
[32mESM[39m [1mdist/index.js [22m[32m72.48 KB[39m
|
|
12
|
+
[32mESM[39m [1mdist/index.js.map [22m[32m137.40 KB[39m
|
|
13
|
+
[32mESM[39m ⚡️ Build success in 32ms
|
|
14
14
|
[34mDTS[39m Build start
|
|
15
|
-
[32mDTS[39m ⚡️ Build success in
|
|
16
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[
|
|
15
|
+
[32mDTS[39m ⚡️ Build success in 1847ms
|
|
16
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m14.39 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -332,6 +332,20 @@
|
|
|
332
332
|
* @leather.io/constants bumped to 0.25.1
|
|
333
333
|
* @leather.io/models bumped to 0.39.1
|
|
334
334
|
|
|
335
|
+
### Dependencies
|
|
336
|
+
|
|
337
|
+
* The following workspace dependencies were updated
|
|
338
|
+
* dependencies
|
|
339
|
+
* @leather.io/constants bumped to 0.25.3
|
|
340
|
+
* @leather.io/models bumped to 0.41.0
|
|
341
|
+
|
|
342
|
+
## [0.44.0](https://github.com/leather-io/mono/compare/@leather.io/utils-v0.43.0...@leather.io/utils-v0.44.0) (2025-08-27)
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
### Features
|
|
346
|
+
|
|
347
|
+
* flatten object util ([cdebfec](https://github.com/leather-io/mono/commit/cdebfec46d68cb1ac9d12b844b9b4c7e976237d4))
|
|
348
|
+
|
|
335
349
|
## [0.43.0](https://github.com/leather-io/mono/compare/@leather.io/utils-v0.42.4...@leather.io/utils-v0.43.0) (2025-08-26)
|
|
336
350
|
|
|
337
351
|
|
package/dist/index.d.ts
CHANGED
|
@@ -170,6 +170,37 @@ declare function createCurrencyFormatter({ locale, onError }: CreateCurrencyForm
|
|
|
170
170
|
formatPercentage: (amount: number, decimals?: number) => string;
|
|
171
171
|
};
|
|
172
172
|
|
|
173
|
+
type ObjectValue = string | number | boolean | null | NestedObject | ObjectValue[];
|
|
174
|
+
interface NestedObject {
|
|
175
|
+
[key: string]: ObjectValue;
|
|
176
|
+
}
|
|
177
|
+
interface FlattenedObject {
|
|
178
|
+
[key: string]: string | number | boolean | null;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Flattens a nested object or array into a flat object with dot-notation key paths.
|
|
182
|
+
*
|
|
183
|
+
* @param input - The object or array to flatten
|
|
184
|
+
* @param prefix - Internal parameter for recursion, represents the current key path
|
|
185
|
+
* @returns A flat object where keys represent the path to the original nested value
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* // Object example
|
|
190
|
+
* flattenObject({ layer1: { layer2: 'value' } })
|
|
191
|
+
* // Returns: { 'layer1.layer2': 'value' }
|
|
192
|
+
*
|
|
193
|
+
* // Array example
|
|
194
|
+
* flattenObject([{ key: 'value' }])
|
|
195
|
+
* // Returns: { '[0].key': 'value' }
|
|
196
|
+
*
|
|
197
|
+
* // Mixed example
|
|
198
|
+
* flattenObject({ users: [{ name: 'John', age: 30 }] })
|
|
199
|
+
* // Returns: { 'users[0].name': 'John', 'users[0].age': 30 }
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
declare function flattenObject(input: ObjectValue, prefix?: string): FlattenedObject;
|
|
203
|
+
|
|
173
204
|
interface SpamFilterArgs {
|
|
174
205
|
input: string;
|
|
175
206
|
whitelist: string[];
|
|
@@ -249,4 +280,4 @@ declare function match<Variant extends string | number>(): <T>(variant: Variant,
|
|
|
249
280
|
declare function removeTrailingNullCharacters(s: string): string;
|
|
250
281
|
declare function isNumberOrNumberList(value: unknown): value is number | number[];
|
|
251
282
|
|
|
252
|
-
export { type CreateInscriptionData, type FormatAmountOptions, aggregateBaseCryptoAssetBalances, aggregateBtcBalances, aggregateStxBalances, assertExistence, assertIsTruthy, assertUnreachable, baseCurrencyAmountInQuote, baseCurrencyAmountInQuoteWithFallback, btcToSat, calculateMeanAverage, capitalize, convertAmountToBaseUnit, convertAmountToFractionalUnit, convertToMoneyTypeWithDefaultOfZero, countDecimals, createAccountAddresses, createBaseCryptoAssetBalance, createBtcBalance, createCounter, createCurrencyFormatter, createInscriptionAsset, createMoney, createMoneyFromDecimal, createNullArrayOfLength, createNumArrayOfRange, createStxBalance, dateToUnixTimestamp, daysInMs, daysInSec, defaultWalletKeyId, delay, ensureArray, extractPhraseFromString, fibonacciGenerator, fiveMinInMs, getAssetDisplayName, getAssetId, getTicker, hasBitcoinAddress, hasStacksAddress, hexToNumber, hoursInMs, hoursInSec, increaseValueByOneMicroStx, initBigNumber, invertExchangeRate, isBigInt, isBoolean, isDefined, isEmpty, isEmptyArray, isEmptyString, isError, isEven, isFiatCurrencyCode, isFulfilled, isFunction, isHexString, isMoney, isMoneyGreaterThanZero, isNumber, isNumberOrNumberList, isObject, isRejected, isString, isTypedArray, isUndefined, isValidPrecision, makeNumberRange, makeStacksTxExplorerLink, mapObject, match, matchesAssetId, maxMoney, microStxToStx, migratePositiveAssetBalancesToTop, minMoney, minutesInMs, minutesInSec, moneyToBaseUnit, noop, oneDayInMs, oneMinInMs, oneWeekInMs, propIfDefined, pxStringToNumber, quoteCurrencyAmountToBase, rebaseMarketData, removeTrailingNullCharacters, reverseBytes, safelyFormatHexTxid, sanitizeContent, satToBtc, scaleValue, secondsInMs, sortAssetsByName, spamFilter, stxToMicroStx, subtractMoney, sumMoney, sumNumbers, toHexString, truncateMiddle, undefinedIfLengthZero, uniqueArray, unitToFractionalUnit, weeksInMs, weeksInSec, whenInscriptionMimeType, whenNetwork };
|
|
283
|
+
export { type CreateInscriptionData, type FormatAmountOptions, aggregateBaseCryptoAssetBalances, aggregateBtcBalances, aggregateStxBalances, assertExistence, assertIsTruthy, assertUnreachable, baseCurrencyAmountInQuote, baseCurrencyAmountInQuoteWithFallback, btcToSat, calculateMeanAverage, capitalize, convertAmountToBaseUnit, convertAmountToFractionalUnit, convertToMoneyTypeWithDefaultOfZero, countDecimals, createAccountAddresses, createBaseCryptoAssetBalance, createBtcBalance, createCounter, createCurrencyFormatter, createInscriptionAsset, createMoney, createMoneyFromDecimal, createNullArrayOfLength, createNumArrayOfRange, createStxBalance, dateToUnixTimestamp, daysInMs, daysInSec, defaultWalletKeyId, delay, ensureArray, extractPhraseFromString, fibonacciGenerator, fiveMinInMs, flattenObject, getAssetDisplayName, getAssetId, getTicker, hasBitcoinAddress, hasStacksAddress, hexToNumber, hoursInMs, hoursInSec, increaseValueByOneMicroStx, initBigNumber, invertExchangeRate, isBigInt, isBoolean, isDefined, isEmpty, isEmptyArray, isEmptyString, isError, isEven, isFiatCurrencyCode, isFulfilled, isFunction, isHexString, isMoney, isMoneyGreaterThanZero, isNumber, isNumberOrNumberList, isObject, isRejected, isString, isTypedArray, isUndefined, isValidPrecision, makeNumberRange, makeStacksTxExplorerLink, mapObject, match, matchesAssetId, maxMoney, microStxToStx, migratePositiveAssetBalancesToTop, minMoney, minutesInMs, minutesInSec, moneyToBaseUnit, noop, oneDayInMs, oneMinInMs, oneWeekInMs, propIfDefined, pxStringToNumber, quoteCurrencyAmountToBase, rebaseMarketData, removeTrailingNullCharacters, reverseBytes, safelyFormatHexTxid, sanitizeContent, satToBtc, scaleValue, secondsInMs, sortAssetsByName, spamFilter, stxToMicroStx, subtractMoney, sumMoney, sumNumbers, toHexString, truncateMiddle, undefinedIfLengthZero, uniqueArray, unitToFractionalUnit, weeksInMs, weeksInSec, whenInscriptionMimeType, whenNetwork };
|
package/dist/index.js
CHANGED
|
@@ -1942,6 +1942,29 @@ function deriveFractionOptions(amount, decimals, compact, presetNumberFormatOpti
|
|
|
1942
1942
|
};
|
|
1943
1943
|
}
|
|
1944
1944
|
|
|
1945
|
+
// src/flatten-object.ts
|
|
1946
|
+
function flattenObject(input, prefix = "") {
|
|
1947
|
+
const result = {};
|
|
1948
|
+
if (input === null || typeof input !== "object") {
|
|
1949
|
+
if (prefix === "") return { value: input };
|
|
1950
|
+
return { [prefix]: input };
|
|
1951
|
+
}
|
|
1952
|
+
if (Array.isArray(input)) {
|
|
1953
|
+
input.forEach((item, index) => {
|
|
1954
|
+
const key = prefix === "" ? `[${index}]` : `${prefix}[${index}]`;
|
|
1955
|
+
const flattened = flattenObject(item, key);
|
|
1956
|
+
Object.assign(result, flattened);
|
|
1957
|
+
});
|
|
1958
|
+
} else {
|
|
1959
|
+
Object.entries(input).forEach(([key, value]) => {
|
|
1960
|
+
const newKey = prefix === "" ? key : `${prefix}.${key}`;
|
|
1961
|
+
const flattened = flattenObject(value, newKey);
|
|
1962
|
+
Object.assign(result, flattened);
|
|
1963
|
+
});
|
|
1964
|
+
}
|
|
1965
|
+
return result;
|
|
1966
|
+
}
|
|
1967
|
+
|
|
1945
1968
|
// src/spam-filter/tlds-list.ts
|
|
1946
1969
|
var tlds = [
|
|
1947
1970
|
"AAA",
|
|
@@ -3651,6 +3674,7 @@ export {
|
|
|
3651
3674
|
extractPhraseFromString,
|
|
3652
3675
|
fibonacciGenerator,
|
|
3653
3676
|
fiveMinInMs,
|
|
3677
|
+
flattenObject,
|
|
3654
3678
|
getAssetDisplayName,
|
|
3655
3679
|
getAssetId,
|
|
3656
3680
|
getTicker,
|