@ntnyq/utils 0.7.2 → 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 CHANGED
@@ -183,7 +183,16 @@ 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 const isBrowser: () => boolean;
186
+ declare function isBrowser(): boolean;
187
+ //#endregion
188
+ //#region src/file/removeExtension.d.ts
189
+ /**
190
+ * Removes the file extension from a filename.
191
+ *
192
+ * @param filename - The filename to remove the extension from.
193
+ * @returns The filename without the extension.
194
+ */
195
+ declare function removeFileExtension(filename: string): string;
187
196
  //#endregion
188
197
  //#region src/html/escape.d.ts
189
198
  /**
@@ -196,6 +205,10 @@ declare function escapeHTML(str: string): string;
196
205
  declare function unescapeHTML(str: string): string;
197
206
  //#endregion
198
207
  //#region src/misc/raf.d.ts
208
+ /**
209
+ * Gets the global root object.
210
+ * @returns the global root object
211
+ */
199
212
  declare function getRoot(): Window | typeof globalThis;
200
213
  /**
201
214
  * Request animation frame
@@ -217,15 +230,35 @@ declare function cAF(id: number): void;
217
230
  * @file time utils
218
231
  * @module Time
219
232
  */
220
- declare const ONE_SECOND_MILLSECONDS: number;
221
- declare const ONE_MINUTE_MILLSECONDS: number;
222
- declare const ONE_HOUR_MILLSECONDS: number;
223
- declare const ONE_DAY_MILLSECONDS: number;
224
- declare const ONE_WEEK_MILLSECONDS: number;
233
+ /**
234
+ * Converts seconds to milliseconds.
235
+ * @param count - The number of seconds.
236
+ * @returns The equivalent number of milliseconds.
237
+ */
225
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
+ */
226
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
+ */
227
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
+ */
228
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
+ */
229
262
  declare function weeks(count: number): number;
230
263
  //#endregion
231
264
  //#region src/misc/clamp.d.ts
@@ -738,4 +771,4 @@ declare const RE_LINE_COMMENT: RegExp;
738
771
  */
739
772
  declare const RE_BLOCK_COMMENT: RegExp;
740
773
  //#endregion
741
- export { AnyFn, Arrayable, Awaitable, Callable, CleanObjectOptions, Color, CreatePadStringOptions, DeepRequired, GetStringSimilarityOptions, InteropModuleDefault, JsonArray, JsonObject, JsonPrimitive, JsonValue, LiteralUnion, MayBe, Merge, NOOP, NonEmptyObject, NonEmptyString, Nullable, ONE_DAY_MILLSECONDS, ONE_HOUR_MILLSECONDS, ONE_MINUTE_MILLSECONDS, ONE_SECOND_MILLSECONDS, ONE_WEEK_MILLSECONDS, 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, resolveSubOptions, scrollElementIntoView, seconds, slash, slugify, sortObject, throttle, toArray, toInteger, unescapeHTML, unindent, unique, uniqueBy, waitFor, warnOnce, weeks };
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,21 @@ function isElementVisibleInViewport(element, targetWindow = window) {
221
221
  *
222
222
  * @returns boolean - true if the code is running in a browser
223
223
  */
224
- const isBrowser = () => typeof document !== "undefined";
224
+ function isBrowser() {
225
+ return typeof document !== "undefined";
226
+ }
227
+
228
+ //#endregion
229
+ //#region src/file/removeExtension.ts
230
+ /**
231
+ * Removes the file extension from a filename.
232
+ *
233
+ * @param filename - The filename to remove the extension from.
234
+ * @returns The filename without the extension.
235
+ */
236
+ function removeFileExtension(filename) {
237
+ return filename.replace(/\.[^/.]+$/, "");
238
+ }
225
239
 
226
240
  //#endregion
227
241
  //#region src/html/escape.ts
@@ -261,17 +275,13 @@ function unescapeHTML(str) {
261
275
 
262
276
  //#endregion
263
277
  //#region src/misc/raf.ts
278
+ /**
279
+ * Gets the global root object.
280
+ * @returns the global root object
281
+ */
264
282
  function getRoot() {
265
283
  return isBrowser() ? window : globalThis;
266
284
  }
267
- let prev = Date.now();
268
- function mockRAF(fn) {
269
- const curr = Date.now();
270
- const ms = Math.max(0, 16 - (curr - prev));
271
- const id = setTimeout(fn, ms);
272
- prev = curr + ms;
273
- return id;
274
- }
275
285
  /**
276
286
  * Request animation frame
277
287
  *
@@ -280,7 +290,7 @@ function mockRAF(fn) {
280
290
  */
281
291
  function rAF(fn) {
282
292
  const root = getRoot();
283
- const raf = root.requestAnimationFrame || mockRAF;
293
+ const raf = root.requestAnimationFrame;
284
294
  return raf.call(root, fn);
285
295
  }
286
296
  /**
@@ -291,7 +301,7 @@ function rAF(fn) {
291
301
  */
292
302
  function cAF(id) {
293
303
  const root = getRoot();
294
- const caf = root.cancelAnimationFrame || root.clearTimeout;
304
+ const caf = root.cancelAnimationFrame;
295
305
  return caf.call(root, id);
296
306
  }
297
307
 
@@ -301,25 +311,45 @@ function cAF(id) {
301
311
  * @file time utils
302
312
  * @module Time
303
313
  */
304
- const ONE_SECOND_MILLSECONDS = 1e3;
305
- const ONE_MINUTE_MILLSECONDS = 60 * ONE_SECOND_MILLSECONDS;
306
- const ONE_HOUR_MILLSECONDS = 60 * ONE_MINUTE_MILLSECONDS;
307
- const ONE_DAY_MILLSECONDS = 24 * ONE_HOUR_MILLSECONDS;
308
- const ONE_WEEK_MILLSECONDS = 7 * ONE_DAY_MILLSECONDS;
314
+ /**
315
+ * Converts seconds to milliseconds.
316
+ * @param count - The number of seconds.
317
+ * @returns The equivalent number of milliseconds.
318
+ */
309
319
  function seconds(count) {
310
- return count * ONE_SECOND_MILLSECONDS;
320
+ return count * 1e3;
311
321
  }
322
+ /**
323
+ * Converts minutes to milliseconds.
324
+ * @param count - The number of minutes.
325
+ * @returns The equivalent number of milliseconds.
326
+ */
312
327
  function minutes(count) {
313
- return count * ONE_MINUTE_MILLSECONDS;
328
+ return count * 60 * 1e3;
314
329
  }
330
+ /**
331
+ * Converts hours to milliseconds.
332
+ * @param count - The number of hours.
333
+ * @returns The equivalent number of milliseconds.
334
+ */
315
335
  function hours(count) {
316
- return count * ONE_HOUR_MILLSECONDS;
336
+ return count * 60 * 60 * 1e3;
317
337
  }
338
+ /**
339
+ * Converts days to milliseconds.
340
+ * @param count - The number of days.
341
+ * @returns The equivalent number of milliseconds.
342
+ */
318
343
  function days(count) {
319
- return count * ONE_DAY_MILLSECONDS;
344
+ return count * 24 * 60 * 60 * 1e3;
320
345
  }
346
+ /**
347
+ * Converts weeks to milliseconds.
348
+ * @param count - The number of weeks.
349
+ * @returns The equivalent number of milliseconds.
350
+ */
321
351
  function weeks(count) {
322
- return count * ONE_WEEK_MILLSECONDS;
352
+ return count * 7 * 24 * 60 * 60 * 1e3;
323
353
  }
324
354
 
325
355
  //#endregion
@@ -753,10 +783,6 @@ function getStringSimilarity(str1, str2, options = {}) {
753
783
 
754
784
  //#endregion
755
785
  //#region src/color/color.ts
756
- const pad2 = createPadString({
757
- length: 2,
758
- char: "0"
759
- });
760
786
  const RE_VALID_HEX_COLOR = /^#(?:[0-9a-f]{6}|[0-9a-f]{3})$/i;
761
787
  function validateHexColor(hex) {
762
788
  if (hex.length !== 4 && hex.length !== 7) return false;
@@ -802,6 +828,10 @@ var Color = class Color {
802
828
  return !this.isDark;
803
829
  }
804
830
  toHexString(isUpperCase = true) {
831
+ const pad2 = createPadString({
832
+ length: 2,
833
+ char: "0"
834
+ });
805
835
  const hexString = `#${pad2(this.red.toString(16))}${pad2(this.green.toString(16))}${pad2(this.blue.toString(16))}`;
806
836
  return isUpperCase ? hexString.toUpperCase() : hexString;
807
837
  }
@@ -1053,4 +1083,4 @@ const RE_LINE_COMMENT = /\/\/.*/;
1053
1083
  const RE_BLOCK_COMMENT = /\/\*[\s\S]*?\*\//g;
1054
1084
 
1055
1085
  //#endregion
1056
- export { Color, NOOP, ONE_DAY_MILLSECONDS, ONE_HOUR_MILLSECONDS, ONE_MINUTE_MILLSECONDS, ONE_SECOND_MILLSECONDS, ONE_WEEK_MILLSECONDS, 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, resolveSubOptions, scrollElementIntoView, seconds, slash, slugify, sortObject, throttle, toArray, toInteger, unescapeHTML, unindent, unique, uniqueBy, waitFor, warnOnce, weeks };
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 };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ntnyq/utils",
3
3
  "type": "module",
4
- "version": "0.7.2",
4
+ "version": "0.8.1",
5
5
  "description": "Common used utils.",
6
6
  "keywords": [
7
7
  "utils"
@@ -30,17 +30,17 @@
30
30
  ],
31
31
  "sideEffects": false,
32
32
  "devDependencies": {
33
- "@ntnyq/eslint-config": "^5.0.0-beta.5",
34
- "@ntnyq/prettier-config": "^2.2.0",
35
- "bumpp": "^10.1.1",
36
- "eslint": "^9.28.0",
33
+ "@ntnyq/eslint-config": "^5.0.0",
34
+ "@ntnyq/prettier-config": "^3.0.1",
35
+ "bumpp": "^10.2.0",
36
+ "eslint": "^9.30.1",
37
37
  "husky": "^9.1.7",
38
38
  "nano-staged": "^0.8.0",
39
39
  "npm-run-all2": "^8.0.4",
40
- "prettier": "^3.5.3",
41
- "tsdown": "^0.12.7",
40
+ "prettier": "^3.6.2",
41
+ "tsdown": "^0.12.9",
42
42
  "typescript": "^5.8.3",
43
- "vitest": "^3.2.2"
43
+ "vitest": "^3.2.4"
44
44
  },
45
45
  "engines": {
46
46
  "node": ">=18.18.0"