@ntnyq/utils 0.4.1 → 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
@@ -18,8 +18,8 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
20
  // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
23
  NOOP: () => NOOP,
24
24
  at: () => at,
25
25
  cAF: () => cAF,
@@ -38,6 +38,7 @@ __export(src_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(src_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,
@@ -94,7 +96,7 @@ __export(src_exports, {
94
96
  warnOnce: () => warnOnce,
95
97
  weeks: () => weeks
96
98
  });
97
- module.exports = __toCommonJS(src_exports);
99
+ module.exports = __toCommonJS(index_exports);
98
100
 
99
101
  // src/is/isDeepEqual.ts
100
102
  function isDeepEqual(value1, value2) {
@@ -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
@@ -174,6 +174,18 @@ declare function unique<T>(array: T[]): T[];
174
174
  */
175
175
  declare function uniqueBy<T>(array: T[], equalFn: (a: T, b: T) => boolean): T[];
176
176
 
177
+ type JsonArray = JsonValue[] | readonly JsonValue[];
178
+ type JsonObject = {
179
+ [Key in string]: JsonValue;
180
+ } & {
181
+ [Key in string]?: JsonValue | undefined;
182
+ };
183
+ type JsonPrimitive = boolean | number | string | null;
184
+ /**
185
+ * @copyright {@link https://github.com/sindresorhus/type-fest/blob/main/source/basic.d.ts}
186
+ */
187
+ type JsonValue = JsonArray | JsonObject | JsonPrimitive;
188
+
177
189
  /**
178
190
  * interop module
179
191
  */
@@ -184,6 +196,7 @@ type InteropModuleDefault<T> = T extends {
184
196
  type AnyFn<T = any, R = any> = (...args: T[]) => R;
185
197
  type Arrayable<T> = T | T[];
186
198
  type Awaitable<T> = Promise<T> | T;
199
+ type Callable<T> = AnyFn<any, T> | T;
187
200
  type MayBe<T> = T | undefined;
188
201
  type Nullable<T> = T | null;
189
202
  type PrimitiveType = bigint | boolean | number | string | symbol | null | undefined;
@@ -362,4 +375,49 @@ declare function sortObject<T extends Record<string, any>>(obj: T, options?: Sor
362
375
  */
363
376
  declare const capitalize: typeof upperFirst;
364
377
 
365
- export { type AnyFn, type Arrayable, type Awaitable, type CleanObjectOptions, type InteropModuleDefault, 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
@@ -174,6 +174,18 @@ declare function unique<T>(array: T[]): T[];
174
174
  */
175
175
  declare function uniqueBy<T>(array: T[], equalFn: (a: T, b: T) => boolean): T[];
176
176
 
177
+ type JsonArray = JsonValue[] | readonly JsonValue[];
178
+ type JsonObject = {
179
+ [Key in string]: JsonValue;
180
+ } & {
181
+ [Key in string]?: JsonValue | undefined;
182
+ };
183
+ type JsonPrimitive = boolean | number | string | null;
184
+ /**
185
+ * @copyright {@link https://github.com/sindresorhus/type-fest/blob/main/source/basic.d.ts}
186
+ */
187
+ type JsonValue = JsonArray | JsonObject | JsonPrimitive;
188
+
177
189
  /**
178
190
  * interop module
179
191
  */
@@ -184,6 +196,7 @@ type InteropModuleDefault<T> = T extends {
184
196
  type AnyFn<T = any, R = any> = (...args: T[]) => R;
185
197
  type Arrayable<T> = T | T[];
186
198
  type Awaitable<T> = Promise<T> | T;
199
+ type Callable<T> = AnyFn<any, T> | T;
187
200
  type MayBe<T> = T | undefined;
188
201
  type Nullable<T> = T | null;
189
202
  type PrimitiveType = bigint | boolean | number | string | symbol | null | undefined;
@@ -362,4 +375,49 @@ declare function sortObject<T extends Record<string, any>>(obj: T, options?: Sor
362
375
  */
363
376
  declare const capitalize: typeof upperFirst;
364
377
 
365
- export { type AnyFn, type Arrayable, type Awaitable, type CleanObjectOptions, type InteropModuleDefault, 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.1",
4
+ "version": "0.4.3",
5
5
  "description": "Common used utils.",
6
6
  "keywords": [
7
7
  "utils"
@@ -40,18 +40,18 @@
40
40
  "scule": "^1.3.0"
41
41
  },
42
42
  "devDependencies": {
43
- "@ntnyq/eslint-config": "^3.8.1",
43
+ "@ntnyq/eslint-config": "^3.10.4",
44
44
  "@ntnyq/prettier-config": "^1.22.0",
45
- "@vitest/coverage-v8": "^2.1.8",
46
- "bumpp": "^9.8.1",
47
- "eslint": "^9.16.0",
45
+ "@vitest/coverage-v8": "^3.0.0-beta.3",
46
+ "bumpp": "^9.9.2",
47
+ "eslint": "^9.17.0",
48
48
  "husky": "^9.1.7",
49
49
  "nano-staged": "^0.8.0",
50
- "npm-run-all2": "^7.0.1",
50
+ "npm-run-all2": "^7.0.2",
51
51
  "prettier": "^3.4.2",
52
52
  "tsup": "^8.3.5",
53
53
  "typescript": "^5.7.2",
54
- "vitest": "^2.1.8"
54
+ "vitest": "^3.0.0-beta.3"
55
55
  },
56
56
  "engines": {
57
57
  "node": ">=18.18.0"