@ntnyq/utils 0.4.2 → 0.4.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/dist/index.cjs CHANGED
@@ -38,6 +38,7 @@ __export(index_exports, {
38
38
  getObjectType: () => getObjectType,
39
39
  hasOwn: () => hasOwn,
40
40
  hours: () => hours,
41
+ interopDefault: () => interopDefault,
41
42
  isArray: () => isArray,
42
43
  isArrayEqual: () => isArrayEqual,
43
44
  isBoolean: () => isBoolean,
@@ -77,6 +78,7 @@ __export(index_exports, {
77
78
  pascalCase: () => pascalCase,
78
79
  pick: () => pick,
79
80
  rAF: () => rAF,
81
+ resolveSubOptions: () => resolveSubOptions,
80
82
  seconds: () => seconds,
81
83
  slash: () => slash,
82
84
  snakeCase: () => snakeCase,
@@ -614,6 +616,17 @@ function titleCase(str, opts) {
614
616
 
615
617
  // src/vendor/scule.ts
616
618
  var capitalize = upperFirst;
619
+
620
+ // src/module/interopDefault.ts
621
+ async function interopDefault(mod) {
622
+ const resolved = await mod;
623
+ return resolved.default || resolved;
624
+ }
625
+
626
+ // src/module/resolveSubOptions.ts
627
+ function resolveSubOptions(options, key) {
628
+ return typeof options[key] === "boolean" ? {} : options[key] || {};
629
+ }
617
630
  // Annotate the CommonJS export names for ESM import in node:
618
631
  0 && (module.exports = {
619
632
  NOOP,
@@ -634,6 +647,7 @@ var capitalize = upperFirst;
634
647
  getObjectType,
635
648
  hasOwn,
636
649
  hours,
650
+ interopDefault,
637
651
  isArray,
638
652
  isArrayEqual,
639
653
  isBoolean,
@@ -673,6 +687,7 @@ var capitalize = upperFirst;
673
687
  pascalCase,
674
688
  pick,
675
689
  rAF,
690
+ resolveSubOptions,
676
691
  seconds,
677
692
  slash,
678
693
  snakeCase,
package/dist/index.d.cts CHANGED
@@ -375,4 +375,49 @@ declare function sortObject<T extends Record<string, any>>(obj: T, options?: Sor
375
375
  */
376
376
  declare const capitalize: typeof upperFirst;
377
377
 
378
- export { type AnyFn, type Arrayable, type Awaitable, type Callable, type CleanObjectOptions, type InteropModuleDefault, type JsonArray, type JsonObject, type JsonPrimitive, type JsonValue, type MayBe, NOOP, type NonEmptyString, type Nullable, type Overwrite, type Prettify, type PrettifyV2, type PrimitiveType, type ResolvedOptions, type SortObjectOptions, type ThrottleDebounceOptions, type Whitespace, at, cAF, capitalize, chunk, clamp, cleanObject, days, debounce, ensurePrefix, ensureSuffix, escapeHtml, flattenArrayable, getObjectType, hasOwn, hours, isArray, isArrayEqual, isBoolean, isBrowser, isDeepEqual, isEmptyArray, isEmptyObject, isEmptyString, isEmptyStringOrWhitespace, isFunction, isInteger, isNaN, isNativePromise, isNil, isNonEmptyString, isNull, isNumber, isNumbericString, isObject, isPromise, isRegExp, isSet, isString, isUndefined, isWhitespaceString, isZero, join, last, mergeArrayable, minutes, noop, omit, once, pick, rAF, seconds, slash, sortObject, throttle, toArray, unindent, unique, uniqueBy, waitFor, warnOnce, weeks };
378
+ /**
379
+ * Interop default export from a module
380
+ *
381
+ * @param mod - The module
382
+ * @returns The default export
383
+ *
384
+ * @example
385
+ *
386
+ * ```ts
387
+ * import { interopDefault } from '@ntnyq/utils'
388
+ *
389
+ * const { unindent } = await interopDefault(import('@ntnyq/utils'))
390
+ * ```
391
+ */
392
+ declare function interopDefault<T>(mod: Awaitable<T>): Promise<InteropModuleDefault<T>>;
393
+
394
+ /**
395
+ * Resolve sub options `boolean | Options` to `Options`
396
+ * @param options - core options
397
+ * @param key - sub options key
398
+ * @returns resolved sub options
399
+ *
400
+ * @example
401
+ *
402
+ * ```ts
403
+ * import { resolveSubOptions } from '@ntnyq/utils'
404
+ *
405
+ * interface Options {
406
+ * compile?: boolean | {
407
+ * include?: string[]
408
+ * exclude?: string[]
409
+ * }
410
+ * }
411
+ *
412
+ * const options: Options = {
413
+ * compile: true
414
+ * }
415
+ *
416
+ * console.log(resolveSubOptions(options, 'compile'))
417
+ *
418
+ * // => {}
419
+ * ```
420
+ */
421
+ declare function resolveSubOptions<T extends Record<string, any>, K extends keyof T>(options: T, key: K): Partial<ResolvedOptions<T[K]>>;
422
+
423
+ export { type AnyFn, type Arrayable, type Awaitable, type Callable, type CleanObjectOptions, type InteropModuleDefault, type JsonArray, type JsonObject, type JsonPrimitive, type JsonValue, type MayBe, NOOP, type NonEmptyString, type Nullable, type Overwrite, type Prettify, type PrettifyV2, type PrimitiveType, type ResolvedOptions, type SortObjectOptions, type ThrottleDebounceOptions, type Whitespace, at, cAF, capitalize, chunk, clamp, cleanObject, days, debounce, ensurePrefix, ensureSuffix, escapeHtml, flattenArrayable, getObjectType, hasOwn, hours, interopDefault, isArray, isArrayEqual, isBoolean, isBrowser, isDeepEqual, isEmptyArray, isEmptyObject, isEmptyString, isEmptyStringOrWhitespace, isFunction, isInteger, isNaN, isNativePromise, isNil, isNonEmptyString, isNull, isNumber, isNumbericString, isObject, isPromise, isRegExp, isSet, isString, isUndefined, isWhitespaceString, isZero, join, last, mergeArrayable, minutes, noop, omit, once, pick, rAF, resolveSubOptions, seconds, slash, sortObject, throttle, toArray, unindent, unique, uniqueBy, waitFor, warnOnce, weeks };
package/dist/index.d.ts CHANGED
@@ -375,4 +375,49 @@ declare function sortObject<T extends Record<string, any>>(obj: T, options?: Sor
375
375
  */
376
376
  declare const capitalize: typeof upperFirst;
377
377
 
378
- export { type AnyFn, type Arrayable, type Awaitable, type Callable, type CleanObjectOptions, type InteropModuleDefault, type JsonArray, type JsonObject, type JsonPrimitive, type JsonValue, type MayBe, NOOP, type NonEmptyString, type Nullable, type Overwrite, type Prettify, type PrettifyV2, type PrimitiveType, type ResolvedOptions, type SortObjectOptions, type ThrottleDebounceOptions, type Whitespace, at, cAF, capitalize, chunk, clamp, cleanObject, days, debounce, ensurePrefix, ensureSuffix, escapeHtml, flattenArrayable, getObjectType, hasOwn, hours, isArray, isArrayEqual, isBoolean, isBrowser, isDeepEqual, isEmptyArray, isEmptyObject, isEmptyString, isEmptyStringOrWhitespace, isFunction, isInteger, isNaN, isNativePromise, isNil, isNonEmptyString, isNull, isNumber, isNumbericString, isObject, isPromise, isRegExp, isSet, isString, isUndefined, isWhitespaceString, isZero, join, last, mergeArrayable, minutes, noop, omit, once, pick, rAF, seconds, slash, sortObject, throttle, toArray, unindent, unique, uniqueBy, waitFor, warnOnce, weeks };
378
+ /**
379
+ * Interop default export from a module
380
+ *
381
+ * @param mod - The module
382
+ * @returns The default export
383
+ *
384
+ * @example
385
+ *
386
+ * ```ts
387
+ * import { interopDefault } from '@ntnyq/utils'
388
+ *
389
+ * const { unindent } = await interopDefault(import('@ntnyq/utils'))
390
+ * ```
391
+ */
392
+ declare function interopDefault<T>(mod: Awaitable<T>): Promise<InteropModuleDefault<T>>;
393
+
394
+ /**
395
+ * Resolve sub options `boolean | Options` to `Options`
396
+ * @param options - core options
397
+ * @param key - sub options key
398
+ * @returns resolved sub options
399
+ *
400
+ * @example
401
+ *
402
+ * ```ts
403
+ * import { resolveSubOptions } from '@ntnyq/utils'
404
+ *
405
+ * interface Options {
406
+ * compile?: boolean | {
407
+ * include?: string[]
408
+ * exclude?: string[]
409
+ * }
410
+ * }
411
+ *
412
+ * const options: Options = {
413
+ * compile: true
414
+ * }
415
+ *
416
+ * console.log(resolveSubOptions(options, 'compile'))
417
+ *
418
+ * // => {}
419
+ * ```
420
+ */
421
+ declare function resolveSubOptions<T extends Record<string, any>, K extends keyof T>(options: T, key: K): Partial<ResolvedOptions<T[K]>>;
422
+
423
+ export { type AnyFn, type Arrayable, type Awaitable, type Callable, type CleanObjectOptions, type InteropModuleDefault, type JsonArray, type JsonObject, type JsonPrimitive, type JsonValue, type MayBe, NOOP, type NonEmptyString, type Nullable, type Overwrite, type Prettify, type PrettifyV2, type PrimitiveType, type ResolvedOptions, type SortObjectOptions, type ThrottleDebounceOptions, type Whitespace, at, cAF, capitalize, chunk, clamp, cleanObject, days, debounce, ensurePrefix, ensureSuffix, escapeHtml, flattenArrayable, getObjectType, hasOwn, hours, interopDefault, isArray, isArrayEqual, isBoolean, isBrowser, isDeepEqual, isEmptyArray, isEmptyObject, isEmptyString, isEmptyStringOrWhitespace, isFunction, isInteger, isNaN, isNativePromise, isNil, isNonEmptyString, isNull, isNumber, isNumbericString, isObject, isPromise, isRegExp, isSet, isString, isUndefined, isWhitespaceString, isZero, join, last, mergeArrayable, minutes, noop, omit, once, pick, rAF, resolveSubOptions, seconds, slash, sortObject, throttle, toArray, unindent, unique, uniqueBy, waitFor, warnOnce, weeks };
package/dist/index.js CHANGED
@@ -516,6 +516,17 @@ function titleCase(str, opts) {
516
516
 
517
517
  // src/vendor/scule.ts
518
518
  var capitalize = upperFirst;
519
+
520
+ // src/module/interopDefault.ts
521
+ async function interopDefault(mod) {
522
+ const resolved = await mod;
523
+ return resolved.default || resolved;
524
+ }
525
+
526
+ // src/module/resolveSubOptions.ts
527
+ function resolveSubOptions(options, key) {
528
+ return typeof options[key] === "boolean" ? {} : options[key] || {};
529
+ }
519
530
  export {
520
531
  NOOP,
521
532
  at,
@@ -535,6 +546,7 @@ export {
535
546
  getObjectType,
536
547
  hasOwn,
537
548
  hours,
549
+ interopDefault,
538
550
  isArray,
539
551
  isArrayEqual,
540
552
  isBoolean,
@@ -574,6 +586,7 @@ export {
574
586
  pascalCase,
575
587
  pick,
576
588
  rAF,
589
+ resolveSubOptions,
577
590
  seconds,
578
591
  slash,
579
592
  snakeCase,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ntnyq/utils",
3
3
  "type": "module",
4
- "version": "0.4.2",
4
+ "version": "0.4.3",
5
5
  "description": "Common used utils.",
6
6
  "keywords": [
7
7
  "utils"
@@ -40,7 +40,7 @@
40
40
  "scule": "^1.3.0"
41
41
  },
42
42
  "devDependencies": {
43
- "@ntnyq/eslint-config": "^3.10.2",
43
+ "@ntnyq/eslint-config": "^3.10.4",
44
44
  "@ntnyq/prettier-config": "^1.22.0",
45
45
  "@vitest/coverage-v8": "^3.0.0-beta.3",
46
46
  "bumpp": "^9.9.2",