@hairy/utils 1.46.0 → 1.47.0
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/dist/index.cjs +34 -19
- package/dist/index.d.ts +21 -8
- package/dist/index.global.js +32 -19
- package/dist/index.js +33 -19
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -163,6 +163,7 @@ __export(index_exports, {
|
|
|
163
163
|
selectImages: () => selectImages,
|
|
164
164
|
sentenceCase: () => sentenceCase,
|
|
165
165
|
set: () => set_default,
|
|
166
|
+
shortenId: () => shortenId,
|
|
166
167
|
showOpenFilePicker: () => showOpenFilePicker,
|
|
167
168
|
showOpenImagePicker: () => showOpenImagePicker,
|
|
168
169
|
size: () => size,
|
|
@@ -3705,34 +3706,42 @@ function pipe(...fns) {
|
|
|
3705
3706
|
pipe.promise = pPipe;
|
|
3706
3707
|
|
|
3707
3708
|
// src/util/proxy.ts
|
|
3708
|
-
function proxy(initObject) {
|
|
3709
|
-
initObject && Reflect.set(initObject, "
|
|
3710
|
-
let target = initObject || {
|
|
3711
|
-
const
|
|
3709
|
+
function proxy(initObject, initExtend, options) {
|
|
3710
|
+
initObject && Reflect.set(initObject, "__proxy_updated", true);
|
|
3711
|
+
let target = initObject || { __proxy_updated: false };
|
|
3712
|
+
const extended = initExtend || {};
|
|
3713
|
+
const proxy2 = {
|
|
3714
|
+
update(object) {
|
|
3715
|
+
if (!object) {
|
|
3716
|
+
target = void 0;
|
|
3717
|
+
return;
|
|
3718
|
+
}
|
|
3719
|
+
Reflect.set(object, "__proxy_updated", true);
|
|
3720
|
+
target = object;
|
|
3721
|
+
},
|
|
3722
|
+
get source() {
|
|
3723
|
+
return Reflect.get(target, "__proxy_updated") ? target : void 0;
|
|
3724
|
+
},
|
|
3725
|
+
strictMessage: options?.strictMessage || "Proxy not updated. Call object.proxy.update() to update the proxy."
|
|
3726
|
+
};
|
|
3727
|
+
const proxyed = new Proxy({}, {
|
|
3712
3728
|
get: (_, p) => {
|
|
3713
3729
|
if (p === "proxy")
|
|
3714
|
-
return
|
|
3715
|
-
if (
|
|
3716
|
-
|
|
3730
|
+
return proxy2;
|
|
3731
|
+
if (p in extended)
|
|
3732
|
+
return Reflect.get(extended, p);
|
|
3733
|
+
if (!Reflect.get(target, "__proxy_updated"))
|
|
3734
|
+
throw new Error(proxy2.strictMessage);
|
|
3717
3735
|
return typeof target?.[p] === "function" ? target?.[p].bind(target) : target?.[p];
|
|
3718
3736
|
},
|
|
3719
3737
|
set: (_, p, v) => {
|
|
3738
|
+
if (p in extended)
|
|
3739
|
+
return Reflect.set(extended, p, v);
|
|
3720
3740
|
target[p] = v;
|
|
3721
3741
|
return true;
|
|
3722
3742
|
}
|
|
3723
3743
|
});
|
|
3724
|
-
|
|
3725
|
-
if (!object) {
|
|
3726
|
-
target = void 0;
|
|
3727
|
-
return;
|
|
3728
|
-
}
|
|
3729
|
-
Reflect.set(object, "proxyUpdated", true);
|
|
3730
|
-
target = object;
|
|
3731
|
-
}
|
|
3732
|
-
function original() {
|
|
3733
|
-
return Reflect.get(target, "proxyUpdated") ? target : void 0;
|
|
3734
|
-
}
|
|
3735
|
-
return proxy2;
|
|
3744
|
+
return proxyed;
|
|
3736
3745
|
}
|
|
3737
3746
|
|
|
3738
3747
|
// src/util/random.ts
|
|
@@ -3965,6 +3974,11 @@ function formatNumeric(value = "0", options) {
|
|
|
3965
3974
|
function cover(value, mode, symbol = "*") {
|
|
3966
3975
|
return value.slice(0, mode[0]) + symbol.repeat(mode[1]) + value.slice(-mode[2]);
|
|
3967
3976
|
}
|
|
3977
|
+
function shortenId(value, startWith = 6, endWith = 4) {
|
|
3978
|
+
if (!value)
|
|
3979
|
+
return "";
|
|
3980
|
+
return `${value.slice(0, startWith)}...${value.slice(-endWith)}`;
|
|
3981
|
+
}
|
|
3968
3982
|
function slash(str) {
|
|
3969
3983
|
return str.replace(/\\/g, "/");
|
|
3970
3984
|
}
|
|
@@ -4145,6 +4159,7 @@ function unindent(str) {
|
|
|
4145
4159
|
selectImages,
|
|
4146
4160
|
sentenceCase,
|
|
4147
4161
|
set,
|
|
4162
|
+
shortenId,
|
|
4148
4163
|
showOpenFilePicker,
|
|
4149
4164
|
showOpenImagePicker,
|
|
4150
4165
|
size,
|
package/dist/index.d.ts
CHANGED
|
@@ -334,6 +334,17 @@ declare function formatNumeric(value?: Numberish, options?: FormatNumericOptions
|
|
|
334
334
|
* @param symbol
|
|
335
335
|
*/
|
|
336
336
|
declare function cover(value: string, mode: [number, number, number], symbol?: string): string;
|
|
337
|
+
/**
|
|
338
|
+
* Shortens an identifier string by showing only the beginning and end portions,
|
|
339
|
+
* with ellipsis in the middle. Suitable for various types of identifiers like
|
|
340
|
+
* IPFS CID, transaction hashes, EVM addresses, user IDs, etc.
|
|
341
|
+
*
|
|
342
|
+
* @param value - The identifier string to shorten
|
|
343
|
+
* @param startWith - Number of characters to show at the start (default: 6)
|
|
344
|
+
* @param endWith - Number of characters to show at the end (default: 6)
|
|
345
|
+
* @returns Shortened identifier string with ellipsis, or empty string if id is null/undefined
|
|
346
|
+
*/
|
|
347
|
+
declare function shortenId(value: string | null | undefined, startWith?: number, endWith?: number): string;
|
|
337
348
|
/**
|
|
338
349
|
* Replace backslash to slash
|
|
339
350
|
*
|
|
@@ -626,12 +637,12 @@ declare namespace pipe {
|
|
|
626
637
|
var promise: typeof pPipe;
|
|
627
638
|
}
|
|
628
639
|
|
|
629
|
-
type Proxyed<T extends object> = T & {
|
|
640
|
+
type Proxyed<T extends object, E extends object = {}> = T & {
|
|
630
641
|
proxy: {
|
|
631
642
|
update: (object?: T) => void;
|
|
632
|
-
|
|
643
|
+
source: T | undefined;
|
|
633
644
|
};
|
|
634
|
-
};
|
|
645
|
+
} & E;
|
|
635
646
|
/**
|
|
636
647
|
* Creates a proxy object that updates the original object when the proxy is updated.
|
|
637
648
|
* @param initObject - The initial object to proxy.
|
|
@@ -642,21 +653,23 @@ type Proxyed<T extends object> = T & {
|
|
|
642
653
|
* const obj = proxy({ name: 'John' })
|
|
643
654
|
* console.log(obj.name) // John
|
|
644
655
|
*
|
|
645
|
-
* proxy.update({ name: 'Jane' })
|
|
656
|
+
* obj.proxy.update({ name: 'Jane' })
|
|
646
657
|
* console.log(obj.name) // Jane
|
|
647
658
|
*
|
|
648
659
|
* const obj2 = proxy()
|
|
649
660
|
*
|
|
650
661
|
* obj2.any // Error: Proxy not updated. Call object.proxy.update() to update the proxy.
|
|
651
662
|
*
|
|
652
|
-
* proxy.
|
|
663
|
+
* obj2.proxy.source // undefined
|
|
653
664
|
* obj2.update({ name: 'John' })
|
|
654
665
|
*
|
|
655
666
|
* // get the original object
|
|
656
|
-
* proxy.
|
|
667
|
+
* obj2.proxy.source // { name: 'John' }
|
|
657
668
|
* ```
|
|
658
669
|
*/
|
|
659
|
-
declare function proxy<T extends object>(initObject?: T
|
|
670
|
+
declare function proxy<T extends object, E extends object = {}>(initObject?: T, initExtend?: E, options?: {
|
|
671
|
+
strictMessage?: string;
|
|
672
|
+
}): Proxyed<T, E>;
|
|
660
673
|
|
|
661
674
|
/**
|
|
662
675
|
* Get a random item from an array.
|
|
@@ -806,4 +819,4 @@ declare function unwrap<T extends object>(value: T | (() => T)): T;
|
|
|
806
819
|
declare function whenever<T, C extends (value: Exclude<T, null | undefined>) => any>(value: T, callback: C): ReturnType<C> | undefined;
|
|
807
820
|
declare function call<T extends Fn$1<any>>(fn: T, ...args: Parameters<T>): ReturnType<T>;
|
|
808
821
|
|
|
809
|
-
export { type AnyFn, type ArgumentsType, type Arrayable, type Assign, type Awaitable, BIG_INTS, Bignumber, type BooleanLike, type BrowserNativeObject, type ConstructorType, DEFAULT_BIGNUM_CONFIG, type DecimalOptions, type DeepKeyof, type DeepMap, type DeepMerge, type DeepPartial, type DeepReadonly, type DeepReplace, type DeepRequired, Deferred, type Delimiter, type Dimension, type DynamicObject, type ElementOf, type Fn$1 as Fn, type FormatGroupOptions, type FormatNumericOptions, type IfAny, type IsAny, type Key, type Looper, type MergeInsertions, type NonUndefined, type Noop, type Nullable, type NumberObject, type Numberish, type Numeric, type NumericObject, type OmitBy, type OpenFilePickerOptions, type OpenImagePickerOptions, type Option, type Overwrite, type PickBy, type PromiseFn, type PromiseType, type Promisify, type Proxyed, type ReaderType, type StringObject, type SymbolObject, arange, average, bignumber, call, camelCase, capitalCase, compose, constantCase, cover, decimal, delay, dialsPhone, divide, dotCase, downloadBlobFile, downloadNetworkFile, downloadUrlFile, ensurePrefix, ensureSuffix, formatNumeric, formdataToObject, gt, gte, integer, isAndroid, isBrowser, isChrome, isEdge, isFF, isFormData, isIE, isIE11, isIE9, isIOS, isMobile, isPhantomJS, isTruthy, isWeex, isWindow, kebabCase, loop, lt, lte, multiply, noCase, nonnanable, noop, numberify, numberish, objectToFormdata, off, on, openFilePicker, openImagePicker, parseNumeric, pascalCase, pascalSnakeCase, pathCase, percentage, pipe, plus, proxy, randomItem, randomNumber, randomString, readFileReader, redirectTo, riposte, select, selectImages, sentenceCase, showOpenFilePicker, showOpenImagePicker, size, slash, snakeCase, stringify, template, to, toArray, trainCase, tryParseJson, unindent, unit, unwrap, whenever, zeroRemove, zerofill };
|
|
822
|
+
export { type AnyFn, type ArgumentsType, type Arrayable, type Assign, type Awaitable, BIG_INTS, Bignumber, type BooleanLike, type BrowserNativeObject, type ConstructorType, DEFAULT_BIGNUM_CONFIG, type DecimalOptions, type DeepKeyof, type DeepMap, type DeepMerge, type DeepPartial, type DeepReadonly, type DeepReplace, type DeepRequired, Deferred, type Delimiter, type Dimension, type DynamicObject, type ElementOf, type Fn$1 as Fn, type FormatGroupOptions, type FormatNumericOptions, type IfAny, type IsAny, type Key, type Looper, type MergeInsertions, type NonUndefined, type Noop, type Nullable, type NumberObject, type Numberish, type Numeric, type NumericObject, type OmitBy, type OpenFilePickerOptions, type OpenImagePickerOptions, type Option, type Overwrite, type PickBy, type PromiseFn, type PromiseType, type Promisify, type Proxyed, type ReaderType, type StringObject, type SymbolObject, arange, average, bignumber, call, camelCase, capitalCase, compose, constantCase, cover, decimal, delay, dialsPhone, divide, dotCase, downloadBlobFile, downloadNetworkFile, downloadUrlFile, ensurePrefix, ensureSuffix, formatNumeric, formdataToObject, gt, gte, integer, isAndroid, isBrowser, isChrome, isEdge, isFF, isFormData, isIE, isIE11, isIE9, isIOS, isMobile, isPhantomJS, isTruthy, isWeex, isWindow, kebabCase, loop, lt, lte, multiply, noCase, nonnanable, noop, numberify, numberish, objectToFormdata, off, on, openFilePicker, openImagePicker, parseNumeric, pascalCase, pascalSnakeCase, pathCase, percentage, pipe, plus, proxy, randomItem, randomNumber, randomString, readFileReader, redirectTo, riposte, select, selectImages, sentenceCase, shortenId, showOpenFilePicker, showOpenImagePicker, size, slash, snakeCase, stringify, template, to, toArray, trainCase, tryParseJson, unindent, unit, unwrap, whenever, zeroRemove, zerofill };
|
package/dist/index.global.js
CHANGED
|
@@ -4858,34 +4858,42 @@
|
|
|
4858
4858
|
pipe.promise = pPipe;
|
|
4859
4859
|
|
|
4860
4860
|
// src/util/proxy.ts
|
|
4861
|
-
function proxy(initObject) {
|
|
4862
|
-
initObject && Reflect.set(initObject, "
|
|
4863
|
-
let target = initObject || {
|
|
4864
|
-
const
|
|
4861
|
+
function proxy(initObject, initExtend, options) {
|
|
4862
|
+
initObject && Reflect.set(initObject, "__proxy_updated", true);
|
|
4863
|
+
let target = initObject || { __proxy_updated: false };
|
|
4864
|
+
const extended = initExtend || {};
|
|
4865
|
+
const proxy2 = {
|
|
4866
|
+
update(object) {
|
|
4867
|
+
if (!object) {
|
|
4868
|
+
target = void 0;
|
|
4869
|
+
return;
|
|
4870
|
+
}
|
|
4871
|
+
Reflect.set(object, "__proxy_updated", true);
|
|
4872
|
+
target = object;
|
|
4873
|
+
},
|
|
4874
|
+
get source() {
|
|
4875
|
+
return Reflect.get(target, "__proxy_updated") ? target : void 0;
|
|
4876
|
+
},
|
|
4877
|
+
strictMessage: options?.strictMessage || "Proxy not updated. Call object.proxy.update() to update the proxy."
|
|
4878
|
+
};
|
|
4879
|
+
const proxyed = new Proxy({}, {
|
|
4865
4880
|
get: (_, p) => {
|
|
4866
4881
|
if (p === "proxy")
|
|
4867
|
-
return
|
|
4868
|
-
if (
|
|
4869
|
-
|
|
4882
|
+
return proxy2;
|
|
4883
|
+
if (p in extended)
|
|
4884
|
+
return Reflect.get(extended, p);
|
|
4885
|
+
if (!Reflect.get(target, "__proxy_updated"))
|
|
4886
|
+
throw new Error(proxy2.strictMessage);
|
|
4870
4887
|
return typeof target?.[p] === "function" ? target?.[p].bind(target) : target?.[p];
|
|
4871
4888
|
},
|
|
4872
4889
|
set: (_, p, v) => {
|
|
4890
|
+
if (p in extended)
|
|
4891
|
+
return Reflect.set(extended, p, v);
|
|
4873
4892
|
target[p] = v;
|
|
4874
4893
|
return true;
|
|
4875
4894
|
}
|
|
4876
4895
|
});
|
|
4877
|
-
|
|
4878
|
-
if (!object) {
|
|
4879
|
-
target = void 0;
|
|
4880
|
-
return;
|
|
4881
|
-
}
|
|
4882
|
-
Reflect.set(object, "proxyUpdated", true);
|
|
4883
|
-
target = object;
|
|
4884
|
-
}
|
|
4885
|
-
function original() {
|
|
4886
|
-
return Reflect.get(target, "proxyUpdated") ? target : void 0;
|
|
4887
|
-
}
|
|
4888
|
-
return proxy2;
|
|
4896
|
+
return proxyed;
|
|
4889
4897
|
}
|
|
4890
4898
|
|
|
4891
4899
|
// src/util/random.ts
|
|
@@ -5118,6 +5126,11 @@
|
|
|
5118
5126
|
function cover(value, mode, symbol = "*") {
|
|
5119
5127
|
return value.slice(0, mode[0]) + symbol.repeat(mode[1]) + value.slice(-mode[2]);
|
|
5120
5128
|
}
|
|
5129
|
+
function shortenId(value, startWith = 6, endWith = 4) {
|
|
5130
|
+
if (!value)
|
|
5131
|
+
return "";
|
|
5132
|
+
return `${value.slice(0, startWith)}...${value.slice(-endWith)}`;
|
|
5133
|
+
}
|
|
5121
5134
|
function slash(str) {
|
|
5122
5135
|
return str.replace(/\\/g, "/");
|
|
5123
5136
|
}
|
package/dist/index.js
CHANGED
|
@@ -3515,34 +3515,42 @@ function pipe(...fns) {
|
|
|
3515
3515
|
pipe.promise = pPipe;
|
|
3516
3516
|
|
|
3517
3517
|
// src/util/proxy.ts
|
|
3518
|
-
function proxy(initObject) {
|
|
3519
|
-
initObject && Reflect.set(initObject, "
|
|
3520
|
-
let target = initObject || {
|
|
3521
|
-
const
|
|
3518
|
+
function proxy(initObject, initExtend, options) {
|
|
3519
|
+
initObject && Reflect.set(initObject, "__proxy_updated", true);
|
|
3520
|
+
let target = initObject || { __proxy_updated: false };
|
|
3521
|
+
const extended = initExtend || {};
|
|
3522
|
+
const proxy2 = {
|
|
3523
|
+
update(object) {
|
|
3524
|
+
if (!object) {
|
|
3525
|
+
target = void 0;
|
|
3526
|
+
return;
|
|
3527
|
+
}
|
|
3528
|
+
Reflect.set(object, "__proxy_updated", true);
|
|
3529
|
+
target = object;
|
|
3530
|
+
},
|
|
3531
|
+
get source() {
|
|
3532
|
+
return Reflect.get(target, "__proxy_updated") ? target : void 0;
|
|
3533
|
+
},
|
|
3534
|
+
strictMessage: options?.strictMessage || "Proxy not updated. Call object.proxy.update() to update the proxy."
|
|
3535
|
+
};
|
|
3536
|
+
const proxyed = new Proxy({}, {
|
|
3522
3537
|
get: (_, p) => {
|
|
3523
3538
|
if (p === "proxy")
|
|
3524
|
-
return
|
|
3525
|
-
if (
|
|
3526
|
-
|
|
3539
|
+
return proxy2;
|
|
3540
|
+
if (p in extended)
|
|
3541
|
+
return Reflect.get(extended, p);
|
|
3542
|
+
if (!Reflect.get(target, "__proxy_updated"))
|
|
3543
|
+
throw new Error(proxy2.strictMessage);
|
|
3527
3544
|
return typeof target?.[p] === "function" ? target?.[p].bind(target) : target?.[p];
|
|
3528
3545
|
},
|
|
3529
3546
|
set: (_, p, v) => {
|
|
3547
|
+
if (p in extended)
|
|
3548
|
+
return Reflect.set(extended, p, v);
|
|
3530
3549
|
target[p] = v;
|
|
3531
3550
|
return true;
|
|
3532
3551
|
}
|
|
3533
3552
|
});
|
|
3534
|
-
|
|
3535
|
-
if (!object) {
|
|
3536
|
-
target = void 0;
|
|
3537
|
-
return;
|
|
3538
|
-
}
|
|
3539
|
-
Reflect.set(object, "proxyUpdated", true);
|
|
3540
|
-
target = object;
|
|
3541
|
-
}
|
|
3542
|
-
function original() {
|
|
3543
|
-
return Reflect.get(target, "proxyUpdated") ? target : void 0;
|
|
3544
|
-
}
|
|
3545
|
-
return proxy2;
|
|
3553
|
+
return proxyed;
|
|
3546
3554
|
}
|
|
3547
3555
|
|
|
3548
3556
|
// src/util/random.ts
|
|
@@ -3775,6 +3783,11 @@ function formatNumeric(value = "0", options) {
|
|
|
3775
3783
|
function cover(value, mode, symbol = "*") {
|
|
3776
3784
|
return value.slice(0, mode[0]) + symbol.repeat(mode[1]) + value.slice(-mode[2]);
|
|
3777
3785
|
}
|
|
3786
|
+
function shortenId(value, startWith = 6, endWith = 4) {
|
|
3787
|
+
if (!value)
|
|
3788
|
+
return "";
|
|
3789
|
+
return `${value.slice(0, startWith)}...${value.slice(-endWith)}`;
|
|
3790
|
+
}
|
|
3778
3791
|
function slash(str) {
|
|
3779
3792
|
return str.replace(/\\/g, "/");
|
|
3780
3793
|
}
|
|
@@ -3954,6 +3967,7 @@ export {
|
|
|
3954
3967
|
selectImages,
|
|
3955
3968
|
sentenceCase,
|
|
3956
3969
|
set_default as set,
|
|
3970
|
+
shortenId,
|
|
3957
3971
|
showOpenFilePicker,
|
|
3958
3972
|
showOpenImagePicker,
|
|
3959
3973
|
size,
|