@ntnyq/utils 0.6.2 → 0.6.3
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/README.md +0 -1
- package/dist/index.cjs +16 -0
- package/dist/index.d.cts +85 -56
- package/dist/index.d.ts +85 -56
- package/dist/index.js +14 -0
- package/package.json +6 -8
package/README.md
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
[](https://github.com/ntnyq/utils/actions)
|
|
4
4
|
[](https://www.npmjs.com/package/@ntnyq/utils)
|
|
5
5
|
[](https://www.npmjs.com/package/@ntnyq/utils)
|
|
6
|
-
[](https://codecov.io/github/ntnyq/utils)
|
|
7
6
|
[](https://github.com/ntnyq/utils/blob/main/LICENSE)
|
|
8
7
|
|
|
9
8
|
> Common used utils.
|
package/dist/index.cjs
CHANGED
|
@@ -25,6 +25,7 @@ __export(index_exports, {
|
|
|
25
25
|
RE_BLOCK_COMMENT: () => RE_BLOCK_COMMENT,
|
|
26
26
|
RE_COMMENTS: () => RE_COMMENTS,
|
|
27
27
|
RE_LINE_COMMENT: () => RE_LINE_COMMENT,
|
|
28
|
+
SPECIAL_CHAR: () => SPECIAL_CHAR,
|
|
28
29
|
at: () => at,
|
|
29
30
|
cAF: () => cAF,
|
|
30
31
|
chunk: () => chunk,
|
|
@@ -86,6 +87,7 @@ __export(index_exports, {
|
|
|
86
87
|
noop: () => noop,
|
|
87
88
|
omit: () => omit,
|
|
88
89
|
once: () => once,
|
|
90
|
+
openExternalURL: () => openExternalURL,
|
|
89
91
|
pick: () => pick,
|
|
90
92
|
rAF: () => rAF,
|
|
91
93
|
randomHexColor: () => randomHexColor,
|
|
@@ -279,6 +281,13 @@ function scrollElementIntoView(element, options = {}) {
|
|
|
279
281
|
}
|
|
280
282
|
}
|
|
281
283
|
|
|
284
|
+
// src/dom/openExternalURL.ts
|
|
285
|
+
function openExternalURL(url, options = {}) {
|
|
286
|
+
const { target = "_blank" } = options;
|
|
287
|
+
const proxy = window.open(url, target);
|
|
288
|
+
return proxy;
|
|
289
|
+
}
|
|
290
|
+
|
|
282
291
|
// src/dom/isVisibleInViewport.ts
|
|
283
292
|
function isElementVisibleInViewport(element, targetWindow = window) {
|
|
284
293
|
const { top, left, bottom, right } = element.getBoundingClientRect();
|
|
@@ -808,6 +817,11 @@ function sortObject(obj, options = {}) {
|
|
|
808
817
|
return sortKeys(obj);
|
|
809
818
|
}
|
|
810
819
|
|
|
820
|
+
// src/constants/char.ts
|
|
821
|
+
var SPECIAL_CHAR = {
|
|
822
|
+
newline: "\n"
|
|
823
|
+
};
|
|
824
|
+
|
|
811
825
|
// src/constants/regexp.ts
|
|
812
826
|
var RE_COMMENTS = /(?:<!--|\/\*)([\s\S]*?)(?:-->|\*\/)/g;
|
|
813
827
|
var RE_LINE_COMMENT = /\/\/.*/;
|
|
@@ -819,6 +833,7 @@ var RE_BLOCK_COMMENT = /\/\*[\s\S]*?\*\//g;
|
|
|
819
833
|
RE_BLOCK_COMMENT,
|
|
820
834
|
RE_COMMENTS,
|
|
821
835
|
RE_LINE_COMMENT,
|
|
836
|
+
SPECIAL_CHAR,
|
|
822
837
|
at,
|
|
823
838
|
cAF,
|
|
824
839
|
chunk,
|
|
@@ -880,6 +895,7 @@ var RE_BLOCK_COMMENT = /\/\*[\s\S]*?\*\//g;
|
|
|
880
895
|
noop,
|
|
881
896
|
omit,
|
|
882
897
|
once,
|
|
898
|
+
openExternalURL,
|
|
883
899
|
pick,
|
|
884
900
|
rAF,
|
|
885
901
|
randomHexColor,
|
package/dist/index.d.cts
CHANGED
|
@@ -71,6 +71,83 @@ interface Options extends ScrollIntoViewOptions {
|
|
|
71
71
|
*/
|
|
72
72
|
declare function scrollElementIntoView(element: HTMLElement, options?: Options): void;
|
|
73
73
|
|
|
74
|
+
type JsonArray = JsonValue[] | readonly JsonValue[];
|
|
75
|
+
type JsonObject = {
|
|
76
|
+
[Key in string]: JsonValue;
|
|
77
|
+
} & {
|
|
78
|
+
[Key in string]?: JsonValue | undefined;
|
|
79
|
+
};
|
|
80
|
+
type JsonPrimitive = boolean | number | string | null;
|
|
81
|
+
/**
|
|
82
|
+
* @copyright {@link https://github.com/sindresorhus/type-fest/blob/main/source/basic.d.ts}
|
|
83
|
+
*/
|
|
84
|
+
type JsonValue = JsonArray | JsonObject | JsonPrimitive;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* A literal type that supports custom further strings but preserves autocompletion in IDEs.
|
|
88
|
+
*
|
|
89
|
+
* @see https://github.com/microsoft/TypeScript/issues/29729#issuecomment-471566609
|
|
90
|
+
*/
|
|
91
|
+
type LiteralUnion<Union extends Base, Base = string> = Union | (Base & {
|
|
92
|
+
zz_IGNORE_ME?: never;
|
|
93
|
+
});
|
|
94
|
+
/**
|
|
95
|
+
* Non empty object `{}`
|
|
96
|
+
*/
|
|
97
|
+
type NonEmptyObject<T> = T extends Record<string, never> ? never : T;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* interop module
|
|
101
|
+
*/
|
|
102
|
+
type InteropModuleDefault<T> = T extends {
|
|
103
|
+
default: infer U;
|
|
104
|
+
} ? U : T;
|
|
105
|
+
|
|
106
|
+
type AnyFn<T = any, R = any> = (...args: T[]) => R;
|
|
107
|
+
type Arrayable<T> = T | T[];
|
|
108
|
+
type Awaitable<T> = Promise<T> | T;
|
|
109
|
+
type Callable<T> = AnyFn<any, T> | T;
|
|
110
|
+
type MayBe<T> = T | undefined;
|
|
111
|
+
type Nullable<T> = T | null;
|
|
112
|
+
/**
|
|
113
|
+
* Overwrite some keys type
|
|
114
|
+
*/
|
|
115
|
+
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
|
|
116
|
+
/**
|
|
117
|
+
* Prettify object type
|
|
118
|
+
*/
|
|
119
|
+
type Prettify<T> = {
|
|
120
|
+
[K in keyof T]: T[K];
|
|
121
|
+
} & {};
|
|
122
|
+
type PrettifyV2<T> = Omit<T, never>;
|
|
123
|
+
type PrimitiveType = bigint | boolean | number | string | symbol | null | undefined;
|
|
124
|
+
/**
|
|
125
|
+
* Resolve `boolean | Record<string, any>` to `Record<string, any>`
|
|
126
|
+
*/
|
|
127
|
+
type ResolvedOptions<T> = T extends boolean ? never : NonNullable<T>;
|
|
128
|
+
|
|
129
|
+
interface OpenExternalURLOptions {
|
|
130
|
+
/**
|
|
131
|
+
* open target
|
|
132
|
+
*
|
|
133
|
+
* @default `_blank`
|
|
134
|
+
*/
|
|
135
|
+
target?: LiteralUnion<'_self' | '_top' | '_blank' | '_parent'>;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Open external url
|
|
139
|
+
* @param url - URL to open
|
|
140
|
+
* @param options - open options
|
|
141
|
+
* @returns window proxy
|
|
142
|
+
*/
|
|
143
|
+
declare function openExternalURL(url: string | URL, options?: OpenExternalURLOptions): WindowProxy | null;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Check if element is in viewport
|
|
147
|
+
* @param element - checked element
|
|
148
|
+
* @param targetWindow - window
|
|
149
|
+
* @returns true if element is in viewport, false otherwise
|
|
150
|
+
*/
|
|
74
151
|
declare function isElementVisibleInViewport(element: HTMLElement, targetWindow?: Window): boolean;
|
|
75
152
|
|
|
76
153
|
/**
|
|
@@ -208,61 +285,6 @@ declare function unique<T>(array: T[]): T[];
|
|
|
208
285
|
*/
|
|
209
286
|
declare function uniqueBy<T>(array: T[], equalFn: (a: T, b: T) => boolean): T[];
|
|
210
287
|
|
|
211
|
-
type JsonArray = JsonValue[] | readonly JsonValue[];
|
|
212
|
-
type JsonObject = {
|
|
213
|
-
[Key in string]: JsonValue;
|
|
214
|
-
} & {
|
|
215
|
-
[Key in string]?: JsonValue | undefined;
|
|
216
|
-
};
|
|
217
|
-
type JsonPrimitive = boolean | number | string | null;
|
|
218
|
-
/**
|
|
219
|
-
* @copyright {@link https://github.com/sindresorhus/type-fest/blob/main/source/basic.d.ts}
|
|
220
|
-
*/
|
|
221
|
-
type JsonValue = JsonArray | JsonObject | JsonPrimitive;
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* A literal type that supports custom further strings but preserves autocompletion in IDEs.
|
|
225
|
-
*
|
|
226
|
-
* @see https://github.com/microsoft/TypeScript/issues/29729#issuecomment-471566609
|
|
227
|
-
*/
|
|
228
|
-
type LiteralUnion<Union extends Base, Base = string> = Union | (Base & {
|
|
229
|
-
zz_IGNORE_ME?: never;
|
|
230
|
-
});
|
|
231
|
-
/**
|
|
232
|
-
* Non empty object `{}`
|
|
233
|
-
*/
|
|
234
|
-
type NonEmptyObject<T> = T extends Record<string, never> ? never : T;
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* interop module
|
|
238
|
-
*/
|
|
239
|
-
type InteropModuleDefault<T> = T extends {
|
|
240
|
-
default: infer U;
|
|
241
|
-
} ? U : T;
|
|
242
|
-
|
|
243
|
-
type AnyFn<T = any, R = any> = (...args: T[]) => R;
|
|
244
|
-
type Arrayable<T> = T | T[];
|
|
245
|
-
type Awaitable<T> = Promise<T> | T;
|
|
246
|
-
type Callable<T> = AnyFn<any, T> | T;
|
|
247
|
-
type MayBe<T> = T | undefined;
|
|
248
|
-
type Nullable<T> = T | null;
|
|
249
|
-
/**
|
|
250
|
-
* Overwrite some keys type
|
|
251
|
-
*/
|
|
252
|
-
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
|
|
253
|
-
/**
|
|
254
|
-
* Prettify object type
|
|
255
|
-
*/
|
|
256
|
-
type Prettify<T> = {
|
|
257
|
-
[K in keyof T]: T[K];
|
|
258
|
-
} & {};
|
|
259
|
-
type PrettifyV2<T> = Omit<T, never>;
|
|
260
|
-
type PrimitiveType = bigint | boolean | number | string | symbol | null | undefined;
|
|
261
|
-
/**
|
|
262
|
-
* Resolve `boolean | Record<string, any>` to `Record<string, any>`
|
|
263
|
-
*/
|
|
264
|
-
type ResolvedOptions<T> = T extends boolean ? never : NonNullable<T>;
|
|
265
|
-
|
|
266
288
|
/**
|
|
267
289
|
* Converts a value to an array.
|
|
268
290
|
* @param array - The value to convert.
|
|
@@ -564,6 +586,13 @@ declare function ensurePrefix(input: string, prefix: string): string;
|
|
|
564
586
|
|
|
565
587
|
declare function ensureSuffix(input: string, suffix: string): string;
|
|
566
588
|
|
|
589
|
+
/**
|
|
590
|
+
* Special chars
|
|
591
|
+
*/
|
|
592
|
+
declare const SPECIAL_CHAR: {
|
|
593
|
+
newline: string;
|
|
594
|
+
};
|
|
595
|
+
|
|
567
596
|
/**
|
|
568
597
|
* 注释正则
|
|
569
598
|
*
|
|
@@ -579,4 +608,4 @@ declare const RE_LINE_COMMENT: RegExp;
|
|
|
579
608
|
*/
|
|
580
609
|
declare const RE_BLOCK_COMMENT: RegExp;
|
|
581
610
|
|
|
582
|
-
export { type AnyFn, type Arrayable, type Awaitable, type Callable, type CleanObjectOptions, Color, type CreatePadStringOptions, type InteropModuleDefault, type JsonArray, type JsonObject, type JsonPrimitive, type JsonValue, type LiteralUnion, type MayBe, NOOP, type NonEmptyObject, type NonEmptyString, type Nullable, type Overwrite, type Prettify, type PrettifyV2, type PrimitiveType, RE_BLOCK_COMMENT, RE_COMMENTS, RE_LINE_COMMENT, type RamdomNumberOptions, type ResolvedOptions, type SortObjectOptions, type ThrottleDebounceOptions, type Whitespace, at, cAF, chunk, clamp, cleanObject, createPadString, days, debounce, enhance, ensurePrefix, ensureSuffix, escapeHTML, flattenArrayable, getObjectType, hasOwn, hours, interopDefault, intersect, isArray, isArrayEqual, isBigInt, isBoolean, isBrowser, isDeepEqual, isElementVisibleInViewport, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isEmptyStringOrWhitespace, isError, isFunction, isInteger, isIterable, isMap, isNaN, isNativePromise, isNil, isNonEmptyArray, isNonEmptyString, isNull, isNullOrUndefined, isNumber, isNumbericString, isObject, isPromise, isRegExp, isSet, isString, isTruthy, isUndefined, isWhitespaceString, isZero, join, last, mergeArrayable, minutes, noop, omit, once, pick, rAF, randomHexColor, randomNumber, randomRGBAColor, randomRGBColor, randomString, resolveSubOptions, scrollElementIntoView, seconds, slash, slugify, sortObject, throttle, toArray, unescapeHTML, unindent, unique, uniqueBy, waitFor, warnOnce, weeks };
|
|
611
|
+
export { type AnyFn, type Arrayable, type Awaitable, type Callable, type CleanObjectOptions, Color, type CreatePadStringOptions, type InteropModuleDefault, type JsonArray, type JsonObject, type JsonPrimitive, type JsonValue, type LiteralUnion, type MayBe, NOOP, type NonEmptyObject, type NonEmptyString, type Nullable, type OpenExternalURLOptions, type Overwrite, type Prettify, type PrettifyV2, type PrimitiveType, RE_BLOCK_COMMENT, RE_COMMENTS, RE_LINE_COMMENT, type RamdomNumberOptions, type ResolvedOptions, SPECIAL_CHAR, type SortObjectOptions, type ThrottleDebounceOptions, type Whitespace, at, cAF, chunk, clamp, cleanObject, createPadString, days, debounce, enhance, ensurePrefix, ensureSuffix, escapeHTML, flattenArrayable, getObjectType, hasOwn, hours, interopDefault, intersect, isArray, isArrayEqual, isBigInt, isBoolean, isBrowser, isDeepEqual, isElementVisibleInViewport, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isEmptyStringOrWhitespace, isError, isFunction, isInteger, isIterable, isMap, isNaN, isNativePromise, isNil, isNonEmptyArray, isNonEmptyString, isNull, isNullOrUndefined, isNumber, isNumbericString, isObject, isPromise, isRegExp, isSet, isString, isTruthy, isUndefined, isWhitespaceString, isZero, join, last, mergeArrayable, minutes, noop, omit, once, openExternalURL, pick, rAF, randomHexColor, randomNumber, randomRGBAColor, randomRGBColor, randomString, resolveSubOptions, scrollElementIntoView, seconds, slash, slugify, sortObject, throttle, toArray, unescapeHTML, unindent, unique, uniqueBy, waitFor, warnOnce, weeks };
|
package/dist/index.d.ts
CHANGED
|
@@ -71,6 +71,83 @@ interface Options extends ScrollIntoViewOptions {
|
|
|
71
71
|
*/
|
|
72
72
|
declare function scrollElementIntoView(element: HTMLElement, options?: Options): void;
|
|
73
73
|
|
|
74
|
+
type JsonArray = JsonValue[] | readonly JsonValue[];
|
|
75
|
+
type JsonObject = {
|
|
76
|
+
[Key in string]: JsonValue;
|
|
77
|
+
} & {
|
|
78
|
+
[Key in string]?: JsonValue | undefined;
|
|
79
|
+
};
|
|
80
|
+
type JsonPrimitive = boolean | number | string | null;
|
|
81
|
+
/**
|
|
82
|
+
* @copyright {@link https://github.com/sindresorhus/type-fest/blob/main/source/basic.d.ts}
|
|
83
|
+
*/
|
|
84
|
+
type JsonValue = JsonArray | JsonObject | JsonPrimitive;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* A literal type that supports custom further strings but preserves autocompletion in IDEs.
|
|
88
|
+
*
|
|
89
|
+
* @see https://github.com/microsoft/TypeScript/issues/29729#issuecomment-471566609
|
|
90
|
+
*/
|
|
91
|
+
type LiteralUnion<Union extends Base, Base = string> = Union | (Base & {
|
|
92
|
+
zz_IGNORE_ME?: never;
|
|
93
|
+
});
|
|
94
|
+
/**
|
|
95
|
+
* Non empty object `{}`
|
|
96
|
+
*/
|
|
97
|
+
type NonEmptyObject<T> = T extends Record<string, never> ? never : T;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* interop module
|
|
101
|
+
*/
|
|
102
|
+
type InteropModuleDefault<T> = T extends {
|
|
103
|
+
default: infer U;
|
|
104
|
+
} ? U : T;
|
|
105
|
+
|
|
106
|
+
type AnyFn<T = any, R = any> = (...args: T[]) => R;
|
|
107
|
+
type Arrayable<T> = T | T[];
|
|
108
|
+
type Awaitable<T> = Promise<T> | T;
|
|
109
|
+
type Callable<T> = AnyFn<any, T> | T;
|
|
110
|
+
type MayBe<T> = T | undefined;
|
|
111
|
+
type Nullable<T> = T | null;
|
|
112
|
+
/**
|
|
113
|
+
* Overwrite some keys type
|
|
114
|
+
*/
|
|
115
|
+
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
|
|
116
|
+
/**
|
|
117
|
+
* Prettify object type
|
|
118
|
+
*/
|
|
119
|
+
type Prettify<T> = {
|
|
120
|
+
[K in keyof T]: T[K];
|
|
121
|
+
} & {};
|
|
122
|
+
type PrettifyV2<T> = Omit<T, never>;
|
|
123
|
+
type PrimitiveType = bigint | boolean | number | string | symbol | null | undefined;
|
|
124
|
+
/**
|
|
125
|
+
* Resolve `boolean | Record<string, any>` to `Record<string, any>`
|
|
126
|
+
*/
|
|
127
|
+
type ResolvedOptions<T> = T extends boolean ? never : NonNullable<T>;
|
|
128
|
+
|
|
129
|
+
interface OpenExternalURLOptions {
|
|
130
|
+
/**
|
|
131
|
+
* open target
|
|
132
|
+
*
|
|
133
|
+
* @default `_blank`
|
|
134
|
+
*/
|
|
135
|
+
target?: LiteralUnion<'_self' | '_top' | '_blank' | '_parent'>;
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Open external url
|
|
139
|
+
* @param url - URL to open
|
|
140
|
+
* @param options - open options
|
|
141
|
+
* @returns window proxy
|
|
142
|
+
*/
|
|
143
|
+
declare function openExternalURL(url: string | URL, options?: OpenExternalURLOptions): WindowProxy | null;
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Check if element is in viewport
|
|
147
|
+
* @param element - checked element
|
|
148
|
+
* @param targetWindow - window
|
|
149
|
+
* @returns true if element is in viewport, false otherwise
|
|
150
|
+
*/
|
|
74
151
|
declare function isElementVisibleInViewport(element: HTMLElement, targetWindow?: Window): boolean;
|
|
75
152
|
|
|
76
153
|
/**
|
|
@@ -208,61 +285,6 @@ declare function unique<T>(array: T[]): T[];
|
|
|
208
285
|
*/
|
|
209
286
|
declare function uniqueBy<T>(array: T[], equalFn: (a: T, b: T) => boolean): T[];
|
|
210
287
|
|
|
211
|
-
type JsonArray = JsonValue[] | readonly JsonValue[];
|
|
212
|
-
type JsonObject = {
|
|
213
|
-
[Key in string]: JsonValue;
|
|
214
|
-
} & {
|
|
215
|
-
[Key in string]?: JsonValue | undefined;
|
|
216
|
-
};
|
|
217
|
-
type JsonPrimitive = boolean | number | string | null;
|
|
218
|
-
/**
|
|
219
|
-
* @copyright {@link https://github.com/sindresorhus/type-fest/blob/main/source/basic.d.ts}
|
|
220
|
-
*/
|
|
221
|
-
type JsonValue = JsonArray | JsonObject | JsonPrimitive;
|
|
222
|
-
|
|
223
|
-
/**
|
|
224
|
-
* A literal type that supports custom further strings but preserves autocompletion in IDEs.
|
|
225
|
-
*
|
|
226
|
-
* @see https://github.com/microsoft/TypeScript/issues/29729#issuecomment-471566609
|
|
227
|
-
*/
|
|
228
|
-
type LiteralUnion<Union extends Base, Base = string> = Union | (Base & {
|
|
229
|
-
zz_IGNORE_ME?: never;
|
|
230
|
-
});
|
|
231
|
-
/**
|
|
232
|
-
* Non empty object `{}`
|
|
233
|
-
*/
|
|
234
|
-
type NonEmptyObject<T> = T extends Record<string, never> ? never : T;
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* interop module
|
|
238
|
-
*/
|
|
239
|
-
type InteropModuleDefault<T> = T extends {
|
|
240
|
-
default: infer U;
|
|
241
|
-
} ? U : T;
|
|
242
|
-
|
|
243
|
-
type AnyFn<T = any, R = any> = (...args: T[]) => R;
|
|
244
|
-
type Arrayable<T> = T | T[];
|
|
245
|
-
type Awaitable<T> = Promise<T> | T;
|
|
246
|
-
type Callable<T> = AnyFn<any, T> | T;
|
|
247
|
-
type MayBe<T> = T | undefined;
|
|
248
|
-
type Nullable<T> = T | null;
|
|
249
|
-
/**
|
|
250
|
-
* Overwrite some keys type
|
|
251
|
-
*/
|
|
252
|
-
type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
|
|
253
|
-
/**
|
|
254
|
-
* Prettify object type
|
|
255
|
-
*/
|
|
256
|
-
type Prettify<T> = {
|
|
257
|
-
[K in keyof T]: T[K];
|
|
258
|
-
} & {};
|
|
259
|
-
type PrettifyV2<T> = Omit<T, never>;
|
|
260
|
-
type PrimitiveType = bigint | boolean | number | string | symbol | null | undefined;
|
|
261
|
-
/**
|
|
262
|
-
* Resolve `boolean | Record<string, any>` to `Record<string, any>`
|
|
263
|
-
*/
|
|
264
|
-
type ResolvedOptions<T> = T extends boolean ? never : NonNullable<T>;
|
|
265
|
-
|
|
266
288
|
/**
|
|
267
289
|
* Converts a value to an array.
|
|
268
290
|
* @param array - The value to convert.
|
|
@@ -564,6 +586,13 @@ declare function ensurePrefix(input: string, prefix: string): string;
|
|
|
564
586
|
|
|
565
587
|
declare function ensureSuffix(input: string, suffix: string): string;
|
|
566
588
|
|
|
589
|
+
/**
|
|
590
|
+
* Special chars
|
|
591
|
+
*/
|
|
592
|
+
declare const SPECIAL_CHAR: {
|
|
593
|
+
newline: string;
|
|
594
|
+
};
|
|
595
|
+
|
|
567
596
|
/**
|
|
568
597
|
* 注释正则
|
|
569
598
|
*
|
|
@@ -579,4 +608,4 @@ declare const RE_LINE_COMMENT: RegExp;
|
|
|
579
608
|
*/
|
|
580
609
|
declare const RE_BLOCK_COMMENT: RegExp;
|
|
581
610
|
|
|
582
|
-
export { type AnyFn, type Arrayable, type Awaitable, type Callable, type CleanObjectOptions, Color, type CreatePadStringOptions, type InteropModuleDefault, type JsonArray, type JsonObject, type JsonPrimitive, type JsonValue, type LiteralUnion, type MayBe, NOOP, type NonEmptyObject, type NonEmptyString, type Nullable, type Overwrite, type Prettify, type PrettifyV2, type PrimitiveType, RE_BLOCK_COMMENT, RE_COMMENTS, RE_LINE_COMMENT, type RamdomNumberOptions, type ResolvedOptions, type SortObjectOptions, type ThrottleDebounceOptions, type Whitespace, at, cAF, chunk, clamp, cleanObject, createPadString, days, debounce, enhance, ensurePrefix, ensureSuffix, escapeHTML, flattenArrayable, getObjectType, hasOwn, hours, interopDefault, intersect, isArray, isArrayEqual, isBigInt, isBoolean, isBrowser, isDeepEqual, isElementVisibleInViewport, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isEmptyStringOrWhitespace, isError, isFunction, isInteger, isIterable, isMap, isNaN, isNativePromise, isNil, isNonEmptyArray, isNonEmptyString, isNull, isNullOrUndefined, isNumber, isNumbericString, isObject, isPromise, isRegExp, isSet, isString, isTruthy, isUndefined, isWhitespaceString, isZero, join, last, mergeArrayable, minutes, noop, omit, once, pick, rAF, randomHexColor, randomNumber, randomRGBAColor, randomRGBColor, randomString, resolveSubOptions, scrollElementIntoView, seconds, slash, slugify, sortObject, throttle, toArray, unescapeHTML, unindent, unique, uniqueBy, waitFor, warnOnce, weeks };
|
|
611
|
+
export { type AnyFn, type Arrayable, type Awaitable, type Callable, type CleanObjectOptions, Color, type CreatePadStringOptions, type InteropModuleDefault, type JsonArray, type JsonObject, type JsonPrimitive, type JsonValue, type LiteralUnion, type MayBe, NOOP, type NonEmptyObject, type NonEmptyString, type Nullable, type OpenExternalURLOptions, type Overwrite, type Prettify, type PrettifyV2, type PrimitiveType, RE_BLOCK_COMMENT, RE_COMMENTS, RE_LINE_COMMENT, type RamdomNumberOptions, type ResolvedOptions, SPECIAL_CHAR, type SortObjectOptions, type ThrottleDebounceOptions, type Whitespace, at, cAF, chunk, clamp, cleanObject, createPadString, days, debounce, enhance, ensurePrefix, ensureSuffix, escapeHTML, flattenArrayable, getObjectType, hasOwn, hours, interopDefault, intersect, isArray, isArrayEqual, isBigInt, isBoolean, isBrowser, isDeepEqual, isElementVisibleInViewport, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isEmptyStringOrWhitespace, isError, isFunction, isInteger, isIterable, isMap, isNaN, isNativePromise, isNil, isNonEmptyArray, isNonEmptyString, isNull, isNullOrUndefined, isNumber, isNumbericString, isObject, isPromise, isRegExp, isSet, isString, isTruthy, isUndefined, isWhitespaceString, isZero, join, last, mergeArrayable, minutes, noop, omit, once, openExternalURL, pick, rAF, randomHexColor, randomNumber, randomRGBAColor, randomRGBColor, randomString, resolveSubOptions, scrollElementIntoView, seconds, slash, slugify, sortObject, throttle, toArray, unescapeHTML, unindent, unique, uniqueBy, waitFor, warnOnce, weeks };
|
package/dist/index.js
CHANGED
|
@@ -166,6 +166,13 @@ function scrollElementIntoView(element, options = {}) {
|
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
+
// src/dom/openExternalURL.ts
|
|
170
|
+
function openExternalURL(url, options = {}) {
|
|
171
|
+
const { target = "_blank" } = options;
|
|
172
|
+
const proxy = window.open(url, target);
|
|
173
|
+
return proxy;
|
|
174
|
+
}
|
|
175
|
+
|
|
169
176
|
// src/dom/isVisibleInViewport.ts
|
|
170
177
|
function isElementVisibleInViewport(element, targetWindow = window) {
|
|
171
178
|
const { top, left, bottom, right } = element.getBoundingClientRect();
|
|
@@ -695,6 +702,11 @@ function sortObject(obj, options = {}) {
|
|
|
695
702
|
return sortKeys(obj);
|
|
696
703
|
}
|
|
697
704
|
|
|
705
|
+
// src/constants/char.ts
|
|
706
|
+
var SPECIAL_CHAR = {
|
|
707
|
+
newline: "\n"
|
|
708
|
+
};
|
|
709
|
+
|
|
698
710
|
// src/constants/regexp.ts
|
|
699
711
|
var RE_COMMENTS = /(?:<!--|\/\*)([\s\S]*?)(?:-->|\*\/)/g;
|
|
700
712
|
var RE_LINE_COMMENT = /\/\/.*/;
|
|
@@ -705,6 +717,7 @@ export {
|
|
|
705
717
|
RE_BLOCK_COMMENT,
|
|
706
718
|
RE_COMMENTS,
|
|
707
719
|
RE_LINE_COMMENT,
|
|
720
|
+
SPECIAL_CHAR,
|
|
708
721
|
at,
|
|
709
722
|
cAF,
|
|
710
723
|
chunk,
|
|
@@ -766,6 +779,7 @@ export {
|
|
|
766
779
|
noop,
|
|
767
780
|
omit,
|
|
768
781
|
once,
|
|
782
|
+
openExternalURL,
|
|
769
783
|
pick,
|
|
770
784
|
rAF,
|
|
771
785
|
randomHexColor,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ntnyq/utils",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.6.
|
|
4
|
+
"version": "0.6.3",
|
|
5
5
|
"description": "Common used utils.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"utils"
|
|
@@ -37,28 +37,26 @@
|
|
|
37
37
|
],
|
|
38
38
|
"sideEffects": false,
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@ntnyq/eslint-config": "^4.0.
|
|
40
|
+
"@ntnyq/eslint-config": "^4.0.3",
|
|
41
41
|
"@ntnyq/prettier-config": "^2.0.0",
|
|
42
|
-
"@vitest/coverage-v8": "^3.0.9",
|
|
43
42
|
"bumpp": "^10.1.0",
|
|
44
|
-
"eslint": "^9.
|
|
43
|
+
"eslint": "^9.24.0",
|
|
45
44
|
"husky": "^9.1.7",
|
|
46
45
|
"nano-staged": "^0.8.0",
|
|
47
46
|
"npm-run-all2": "^7.0.2",
|
|
48
47
|
"prettier": "^3.5.3",
|
|
49
48
|
"tsup": "^8.4.0",
|
|
50
|
-
"typescript": "^5.8.
|
|
51
|
-
"vitest": "^3.
|
|
49
|
+
"typescript": "^5.8.3",
|
|
50
|
+
"vitest": "^3.1.1"
|
|
52
51
|
},
|
|
53
52
|
"engines": {
|
|
54
53
|
"node": ">=18.18.0"
|
|
55
54
|
},
|
|
56
55
|
"nano-staged": {
|
|
57
|
-
"*.{js,ts,mjs,cjs,md,yml,yaml,json}": "eslint --fix"
|
|
56
|
+
"*.{js,ts,mjs,cjs,md,yml,yaml,toml,json}": "eslint --fix"
|
|
58
57
|
},
|
|
59
58
|
"scripts": {
|
|
60
59
|
"build": "tsup",
|
|
61
|
-
"coverage": "vitest --coverage",
|
|
62
60
|
"dev": "tsup --watch src",
|
|
63
61
|
"lint": "eslint",
|
|
64
62
|
"release": "run-s release:check release:version release:publish",
|