@ntnyq/utils 0.8.0 → 0.8.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/dist/index.d.ts +31 -7
- package/dist/index.js +40 -22
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -183,7 +183,7 @@ declare function isElementVisibleInViewport(element: HTMLElement, targetWindow?:
|
|
|
183
183
|
*
|
|
184
184
|
* @returns boolean - true if the code is running in a browser
|
|
185
185
|
*/
|
|
186
|
-
declare
|
|
186
|
+
declare function isBrowser(): boolean;
|
|
187
187
|
//#endregion
|
|
188
188
|
//#region src/file/removeExtension.d.ts
|
|
189
189
|
/**
|
|
@@ -205,6 +205,10 @@ declare function escapeHTML(str: string): string;
|
|
|
205
205
|
declare function unescapeHTML(str: string): string;
|
|
206
206
|
//#endregion
|
|
207
207
|
//#region src/misc/raf.d.ts
|
|
208
|
+
/**
|
|
209
|
+
* Gets the global root object.
|
|
210
|
+
* @returns the global root object
|
|
211
|
+
*/
|
|
208
212
|
declare function getRoot(): Window | typeof globalThis;
|
|
209
213
|
/**
|
|
210
214
|
* Request animation frame
|
|
@@ -226,15 +230,35 @@ declare function cAF(id: number): void;
|
|
|
226
230
|
* @file time utils
|
|
227
231
|
* @module Time
|
|
228
232
|
*/
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
233
|
+
/**
|
|
234
|
+
* Converts seconds to milliseconds.
|
|
235
|
+
* @param count - The number of seconds.
|
|
236
|
+
* @returns The equivalent number of milliseconds.
|
|
237
|
+
*/
|
|
234
238
|
declare function seconds(count: number): number;
|
|
239
|
+
/**
|
|
240
|
+
* Converts minutes to milliseconds.
|
|
241
|
+
* @param count - The number of minutes.
|
|
242
|
+
* @returns The equivalent number of milliseconds.
|
|
243
|
+
*/
|
|
235
244
|
declare function minutes(count: number): number;
|
|
245
|
+
/**
|
|
246
|
+
* Converts hours to milliseconds.
|
|
247
|
+
* @param count - The number of hours.
|
|
248
|
+
* @returns The equivalent number of milliseconds.
|
|
249
|
+
*/
|
|
236
250
|
declare function hours(count: number): number;
|
|
251
|
+
/**
|
|
252
|
+
* Converts days to milliseconds.
|
|
253
|
+
* @param count - The number of days.
|
|
254
|
+
* @returns The equivalent number of milliseconds.
|
|
255
|
+
*/
|
|
237
256
|
declare function days(count: number): number;
|
|
257
|
+
/**
|
|
258
|
+
* Converts weeks to milliseconds.
|
|
259
|
+
* @param count - The number of weeks.
|
|
260
|
+
* @returns The equivalent number of milliseconds.
|
|
261
|
+
*/
|
|
238
262
|
declare function weeks(count: number): number;
|
|
239
263
|
//#endregion
|
|
240
264
|
//#region src/misc/clamp.d.ts
|
|
@@ -747,4 +771,4 @@ declare const RE_LINE_COMMENT: RegExp;
|
|
|
747
771
|
*/
|
|
748
772
|
declare const RE_BLOCK_COMMENT: RegExp;
|
|
749
773
|
//#endregion
|
|
750
|
-
export { AnyFn, Arrayable, Awaitable, Callable, CleanObjectOptions, Color, CreatePadStringOptions, DeepRequired, GetStringSimilarityOptions, InteropModuleDefault, JsonArray, JsonObject, JsonPrimitive, JsonValue, LiteralUnion, MayBe, Merge, NOOP, NonEmptyObject, NonEmptyString, Nullable,
|
|
774
|
+
export { AnyFn, Arrayable, Awaitable, Callable, CleanObjectOptions, Color, CreatePadStringOptions, DeepRequired, GetStringSimilarityOptions, InteropModuleDefault, JsonArray, JsonObject, JsonPrimitive, JsonValue, LiteralUnion, MayBe, Merge, NOOP, NonEmptyObject, NonEmptyString, Nullable, OpenExternalURLOptions, Overwrite, Prettify, PrettifyV2, Primitive, RE_BLOCK_COMMENT, RE_COMMENTS, RE_LINE_COMMENT, RamdomNumberOptions, ResolvedOptions, SPECIAL_CHAR, SortObjectOptions, ThrottleDebounceOptions, ToIntegerOptions, Whitespace, at, cAF, chunk, clamp, cleanObject, createPadString, days, debounce, enhance, ensurePrefix, ensureSuffix, escapeHTML, flattenArrayable, getObjectType, getRoot, getStringLength, getStringSimilarity, hasOwn, hours, interopDefault, intersect, isArray, isArrayEqual, isBigInt, isBoolean, isBrowser, isDeepEqual, isElementVisibleInViewport, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isEmptyStringOrWhitespace, isError, isFunction, isHTMLElement, 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, removeFileExtension, resolveSubOptions, scrollElementIntoView, seconds, slash, slugify, sortObject, throttle, toArray, toInteger, unescapeHTML, unindent, unique, uniqueBy, waitFor, warnOnce, weeks };
|
package/dist/index.js
CHANGED
|
@@ -221,7 +221,9 @@ function isElementVisibleInViewport(element, targetWindow = window) {
|
|
|
221
221
|
*
|
|
222
222
|
* @returns boolean - true if the code is running in a browser
|
|
223
223
|
*/
|
|
224
|
-
|
|
224
|
+
function isBrowser() {
|
|
225
|
+
return typeof document !== "undefined";
|
|
226
|
+
}
|
|
225
227
|
|
|
226
228
|
//#endregion
|
|
227
229
|
//#region src/file/removeExtension.ts
|
|
@@ -273,17 +275,13 @@ function unescapeHTML(str) {
|
|
|
273
275
|
|
|
274
276
|
//#endregion
|
|
275
277
|
//#region src/misc/raf.ts
|
|
278
|
+
/**
|
|
279
|
+
* Gets the global root object.
|
|
280
|
+
* @returns the global root object
|
|
281
|
+
*/
|
|
276
282
|
function getRoot() {
|
|
277
283
|
return isBrowser() ? window : globalThis;
|
|
278
284
|
}
|
|
279
|
-
let prev = Date.now();
|
|
280
|
-
function mockRAF(fn) {
|
|
281
|
-
const curr = Date.now();
|
|
282
|
-
const ms = Math.max(0, 16 - (curr - prev));
|
|
283
|
-
const id = setTimeout(fn, ms);
|
|
284
|
-
prev = curr + ms;
|
|
285
|
-
return id;
|
|
286
|
-
}
|
|
287
285
|
/**
|
|
288
286
|
* Request animation frame
|
|
289
287
|
*
|
|
@@ -292,7 +290,7 @@ function mockRAF(fn) {
|
|
|
292
290
|
*/
|
|
293
291
|
function rAF(fn) {
|
|
294
292
|
const root = getRoot();
|
|
295
|
-
const raf = root.requestAnimationFrame
|
|
293
|
+
const raf = root.requestAnimationFrame;
|
|
296
294
|
return raf.call(root, fn);
|
|
297
295
|
}
|
|
298
296
|
/**
|
|
@@ -303,7 +301,7 @@ function rAF(fn) {
|
|
|
303
301
|
*/
|
|
304
302
|
function cAF(id) {
|
|
305
303
|
const root = getRoot();
|
|
306
|
-
const caf = root.cancelAnimationFrame
|
|
304
|
+
const caf = root.cancelAnimationFrame;
|
|
307
305
|
return caf.call(root, id);
|
|
308
306
|
}
|
|
309
307
|
|
|
@@ -313,25 +311,45 @@ function cAF(id) {
|
|
|
313
311
|
* @file time utils
|
|
314
312
|
* @module Time
|
|
315
313
|
*/
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
314
|
+
/**
|
|
315
|
+
* Converts seconds to milliseconds.
|
|
316
|
+
* @param count - The number of seconds.
|
|
317
|
+
* @returns The equivalent number of milliseconds.
|
|
318
|
+
*/
|
|
321
319
|
function seconds(count) {
|
|
322
|
-
return count *
|
|
320
|
+
return count * 1e3;
|
|
323
321
|
}
|
|
322
|
+
/**
|
|
323
|
+
* Converts minutes to milliseconds.
|
|
324
|
+
* @param count - The number of minutes.
|
|
325
|
+
* @returns The equivalent number of milliseconds.
|
|
326
|
+
*/
|
|
324
327
|
function minutes(count) {
|
|
325
|
-
return count *
|
|
328
|
+
return count * 60 * 1e3;
|
|
326
329
|
}
|
|
330
|
+
/**
|
|
331
|
+
* Converts hours to milliseconds.
|
|
332
|
+
* @param count - The number of hours.
|
|
333
|
+
* @returns The equivalent number of milliseconds.
|
|
334
|
+
*/
|
|
327
335
|
function hours(count) {
|
|
328
|
-
return count *
|
|
336
|
+
return count * 60 * 60 * 1e3;
|
|
329
337
|
}
|
|
338
|
+
/**
|
|
339
|
+
* Converts days to milliseconds.
|
|
340
|
+
* @param count - The number of days.
|
|
341
|
+
* @returns The equivalent number of milliseconds.
|
|
342
|
+
*/
|
|
330
343
|
function days(count) {
|
|
331
|
-
return count *
|
|
344
|
+
return count * 24 * 60 * 60 * 1e3;
|
|
332
345
|
}
|
|
346
|
+
/**
|
|
347
|
+
* Converts weeks to milliseconds.
|
|
348
|
+
* @param count - The number of weeks.
|
|
349
|
+
* @returns The equivalent number of milliseconds.
|
|
350
|
+
*/
|
|
333
351
|
function weeks(count) {
|
|
334
|
-
return count *
|
|
352
|
+
return count * 7 * 24 * 60 * 60 * 1e3;
|
|
335
353
|
}
|
|
336
354
|
|
|
337
355
|
//#endregion
|
|
@@ -1065,4 +1083,4 @@ const RE_LINE_COMMENT = /\/\/.*/;
|
|
|
1065
1083
|
const RE_BLOCK_COMMENT = /\/\*[\s\S]*?\*\//g;
|
|
1066
1084
|
|
|
1067
1085
|
//#endregion
|
|
1068
|
-
export { Color, NOOP,
|
|
1086
|
+
export { Color, NOOP, RE_BLOCK_COMMENT, RE_COMMENTS, RE_LINE_COMMENT, SPECIAL_CHAR, at, cAF, chunk, clamp, cleanObject, createPadString, days, debounce, enhance, ensurePrefix, ensureSuffix, escapeHTML, flattenArrayable, getObjectType, getRoot, getStringLength, getStringSimilarity, hasOwn, hours, interopDefault, intersect, isArray, isArrayEqual, isBigInt, isBoolean, isBrowser, isDeepEqual, isElementVisibleInViewport, isEmptyArray, isEmptyMap, isEmptyObject, isEmptySet, isEmptyString, isEmptyStringOrWhitespace, isError, isFunction, isHTMLElement, 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, removeFileExtension, resolveSubOptions, scrollElementIntoView, seconds, slash, slugify, sortObject, throttle, toArray, toInteger, unescapeHTML, unindent, unique, uniqueBy, waitFor, warnOnce, weeks };
|