@ntnyq/utils 0.3.0 → 0.3.2

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
@@ -15,6 +15,7 @@ var __copyProps = (to, from, except, desc) => {
15
15
  }
16
16
  return to;
17
17
  };
18
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
18
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
20
 
20
21
  // src/index.ts
@@ -23,7 +24,6 @@ __export(src_exports, {
23
24
  NOOP: () => NOOP,
24
25
  at: () => at,
25
26
  cAF: () => cAF,
26
- camelCase: () => camelCase,
27
27
  capitalize: () => capitalize,
28
28
  chunk: () => chunk,
29
29
  clamp: () => clamp,
@@ -31,7 +31,6 @@ __export(src_exports, {
31
31
  debounce: () => debounce,
32
32
  ensurePrefix: () => ensurePrefix,
33
33
  ensureSuffix: () => ensureSuffix,
34
- flatCase: () => flatCase,
35
34
  flattenArrayable: () => flattenArrayable,
36
35
  getObjectType: () => getObjectType,
37
36
  hasOwn: () => hasOwn,
@@ -46,6 +45,7 @@ __export(src_exports, {
46
45
  isInteger: () => isInteger,
47
46
  isNativePromise: () => isNativePromise,
48
47
  isNil: () => isNil,
48
+ isNonEmptyString: () => isNonEmptyString,
49
49
  isNull: () => isNull,
50
50
  isNumber: () => isNumber,
51
51
  isNumbericString: () => isNumbericString,
@@ -55,33 +55,24 @@ __export(src_exports, {
55
55
  isSet: () => isSet,
56
56
  isString: () => isString,
57
57
  isUndefined: () => isUndefined,
58
- isUppercase: () => isUppercase,
59
58
  isWhitespaceString: () => isWhitespaceString,
60
59
  join: () => join,
61
- kebabCase: () => kebabCase,
62
60
  last: () => last,
63
- lowerFirst: () => lowerFirst,
64
61
  mergeArrayable: () => mergeArrayable,
65
62
  minutes: () => minutes,
66
63
  noop: () => noop,
67
64
  omit: () => omit,
68
65
  once: () => once,
69
- pascalCase: () => pascalCase,
70
66
  pick: () => pick,
71
67
  rAF: () => rAF,
72
68
  seconds: () => seconds,
73
69
  slash: () => slash,
74
- snakeCase: () => snakeCase,
75
70
  sortObject: () => sortObject,
76
- splitByCase: () => splitByCase,
77
71
  throttle: () => throttle,
78
- titleCase: () => titleCase,
79
72
  toArray: () => toArray,
80
- trainCase: () => trainCase,
81
73
  unindent: () => unindent,
82
74
  unique: () => unique,
83
75
  uniqueBy: () => uniqueBy,
84
- upperFirst: () => upperFirst,
85
76
  waitFor: () => waitFor,
86
77
  warnOnce: () => warnOnce,
87
78
  weeks: () => weeks
@@ -101,6 +92,9 @@ function isNumber(value) {
101
92
  function isEmptyString(value) {
102
93
  return isString(value) && value.length === 0;
103
94
  }
95
+ function isNonEmptyString(value) {
96
+ return isString(value) && value.length > 0;
97
+ }
104
98
  function isWhitespaceString(value) {
105
99
  return isString(value) && /^\s*$/.test(value);
106
100
  }
@@ -171,88 +165,17 @@ function once(func) {
171
165
  // src/env/isBrowser.ts
172
166
  var isBrowser = () => typeof document !== "undefined";
173
167
 
174
- // node_modules/.pnpm/scule@1.3.0/node_modules/scule/dist/index.mjs
175
- var NUMBER_CHAR_RE = /\d/;
176
- var STR_SPLITTERS = ["-", "_", "/", "."];
177
- function isUppercase(char = "") {
178
- if (NUMBER_CHAR_RE.test(char)) {
179
- return void 0;
180
- }
181
- return char !== char.toLowerCase();
182
- }
183
- function splitByCase(str, separators) {
184
- const splitters = separators ?? STR_SPLITTERS;
185
- const parts = [];
186
- if (!str || typeof str !== "string") {
187
- return parts;
188
- }
189
- let buff = "";
190
- let previousUpper;
191
- let previousSplitter;
192
- for (const char of str) {
193
- const isSplitter = splitters.includes(char);
194
- if (isSplitter === true) {
195
- parts.push(buff);
196
- buff = "";
197
- previousUpper = void 0;
198
- continue;
199
- }
200
- const isUpper = isUppercase(char);
201
- if (previousSplitter === false) {
202
- if (previousUpper === false && isUpper === true) {
203
- parts.push(buff);
204
- buff = char;
205
- previousUpper = isUpper;
206
- continue;
207
- }
208
- if (previousUpper === true && isUpper === false && buff.length > 1) {
209
- const lastChar = buff.at(-1);
210
- parts.push(buff.slice(0, Math.max(0, buff.length - 1)));
211
- buff = lastChar + char;
212
- previousUpper = isUpper;
213
- continue;
214
- }
215
- }
216
- buff += char;
217
- previousUpper = isUpper;
218
- previousSplitter = isSplitter;
219
- }
220
- parts.push(buff);
221
- return parts;
222
- }
223
- function upperFirst(str) {
224
- return str ? str[0].toUpperCase() + str.slice(1) : "";
225
- }
226
- function lowerFirst(str) {
227
- return str ? str[0].toLowerCase() + str.slice(1) : "";
228
- }
229
- function pascalCase(str, opts) {
230
- return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => upperFirst(opts?.normalize ? p.toLowerCase() : p)).join("") : "";
231
- }
232
- function camelCase(str, opts) {
233
- return lowerFirst(pascalCase(str || "", opts));
234
- }
235
- function kebabCase(str, joiner) {
236
- return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => p.toLowerCase()).join(joiner ?? "-") : "";
237
- }
238
- function snakeCase(str) {
239
- return kebabCase(str || "", "_");
240
- }
241
- function flatCase(str) {
242
- return kebabCase(str || "", "");
243
- }
244
- function trainCase(str, opts) {
245
- return (Array.isArray(str) ? str : splitByCase(str)).filter(Boolean).map((p) => upperFirst(opts?.normalize ? p.toLowerCase() : p)).join("-");
246
- }
247
- var titleCaseExceptions = /^(a|an|and|as|at|but|by|for|if|in|is|nor|of|on|or|the|to|with)$/i;
248
- function titleCase(str, opts) {
249
- return (Array.isArray(str) ? str : splitByCase(str)).filter(Boolean).map(
250
- (p) => titleCaseExceptions.test(p) ? p.toLowerCase() : upperFirst(opts?.normalize ? p.toLowerCase() : p)
251
- ).join(" ");
252
- }
253
-
254
168
  // src/case.ts
255
- var capitalize = upperFirst;
169
+ var case_exports = {};
170
+ __export(case_exports, {
171
+ capitalize: () => capitalize
172
+ });
173
+ var import_scule = require("scule");
174
+ __reExport(case_exports, require("scule"));
175
+ var capitalize = import_scule.upperFirst;
176
+
177
+ // src/index.ts
178
+ __reExport(src_exports, case_exports, module.exports);
256
179
 
257
180
  // src/misc/raf.ts
258
181
  var root = isBrowser() ? window : globalThis;
@@ -523,7 +446,6 @@ function sortObject(obj, options = {}) {
523
446
  NOOP,
524
447
  at,
525
448
  cAF,
526
- camelCase,
527
449
  capitalize,
528
450
  chunk,
529
451
  clamp,
@@ -531,7 +453,6 @@ function sortObject(obj, options = {}) {
531
453
  debounce,
532
454
  ensurePrefix,
533
455
  ensureSuffix,
534
- flatCase,
535
456
  flattenArrayable,
536
457
  getObjectType,
537
458
  hasOwn,
@@ -546,6 +467,7 @@ function sortObject(obj, options = {}) {
546
467
  isInteger,
547
468
  isNativePromise,
548
469
  isNil,
470
+ isNonEmptyString,
549
471
  isNull,
550
472
  isNumber,
551
473
  isNumbericString,
@@ -555,33 +477,24 @@ function sortObject(obj, options = {}) {
555
477
  isSet,
556
478
  isString,
557
479
  isUndefined,
558
- isUppercase,
559
480
  isWhitespaceString,
560
481
  join,
561
- kebabCase,
562
482
  last,
563
- lowerFirst,
564
483
  mergeArrayable,
565
484
  minutes,
566
485
  noop,
567
486
  omit,
568
487
  once,
569
- pascalCase,
570
488
  pick,
571
489
  rAF,
572
490
  seconds,
573
491
  slash,
574
- snakeCase,
575
492
  sortObject,
576
- splitByCase,
577
493
  throttle,
578
- titleCase,
579
494
  toArray,
580
- trainCase,
581
495
  unindent,
582
496
  unique,
583
497
  uniqueBy,
584
- upperFirst,
585
498
  waitFor,
586
499
  warnOnce,
587
500
  weeks
package/dist/index.d.cts CHANGED
@@ -3,17 +3,18 @@ export * from 'scule';
3
3
 
4
4
  /**
5
5
  * @file is utils
6
- * @category is
6
+ * @module is
7
7
  * @copyright {@link https://github.com/sindresorhus/is}
8
8
  */
9
- declare function getObjectType(value: unknown): string;
10
- declare function isString(value: unknown): value is string;
11
- declare function isNumber(value: unknown): value is number;
12
- declare function isEmptyString(value: unknown): value is '';
13
9
  type Whitespace = ' ';
14
10
  type NonEmptyString = string & {
15
11
  0: '';
16
12
  };
13
+ declare function getObjectType(value: unknown): string;
14
+ declare function isString(value: unknown): value is string;
15
+ declare function isNumber(value: unknown): value is number;
16
+ declare function isEmptyString(value: unknown): value is '';
17
+ declare function isNonEmptyString(value: unknown): value is NonEmptyString;
17
18
  declare function isWhitespaceString(value: unknown): value is Whitespace;
18
19
  declare function isEmptyStringOrWhitespace(value: unknown): value is '' | Whitespace;
19
20
  declare function isNumbericString(value: unknown): value is `${number}`;
@@ -53,7 +54,7 @@ declare const isBrowser: () => boolean;
53
54
 
54
55
  /**
55
56
  * @file case utils
56
- * @category Case
57
+ * @module Case
57
58
  */
58
59
 
59
60
  /**
@@ -67,20 +68,21 @@ declare const capitalize: typeof upperFirst;
67
68
  /**
68
69
  * Request animation frame
69
70
  *
70
- * @param fn callback
71
+ * @param fn - callback
71
72
  * @returns id
72
73
  */
73
74
  declare function rAF(fn: FrameRequestCallback): number;
74
75
  /**
75
76
  * Cancel animation frame
76
77
  *
77
- * @param id id
78
+ * @param id - id
78
79
  * @returns void
79
80
  */
80
81
  declare function cAF(id: number): void;
81
82
 
82
83
  /**
83
- * @category Utils - time
84
+ * @file time utils
85
+ * @module Time
84
86
  */
85
87
  declare function seconds(count: number): number;
86
88
  declare function minutes(count: number): number;
@@ -90,9 +92,9 @@ declare function weeks(count: number): number;
90
92
 
91
93
  /**
92
94
  * Clamps a number between a minimum and maximum value
93
- * @param value the value to clamp within the given range
94
- * @param min the minimum value to clamp
95
- * @param max the maximum value to clamp
95
+ * @param value - the value to clamp within the given range
96
+ * @param min - the minimum value to clamp
97
+ * @param max - the maximum value to clamp
96
98
  * @returns the new value
97
99
  */
98
100
  declare function clamp(value: number, min?: number, max?: number): number;
@@ -100,7 +102,7 @@ declare function clamp(value: number, min?: number, max?: number): number;
100
102
  /**
101
103
  * Wait for a number of milliseconds
102
104
  *
103
- * @param ms millseconds to wait
105
+ * @param ms - millseconds to wait
104
106
  * @returns a promise that resolves after ms milliseconds
105
107
  *
106
108
  * @example
@@ -151,8 +153,8 @@ declare function last<T>(array: readonly T[]): T | undefined;
151
153
 
152
154
  /**
153
155
  * Splits an array into smaller chunks of a given size.
154
- * @param array The array to split
155
- * @param size The size of each chunk
156
+ * @param array - The array to split
157
+ * @param size - The size of each chunk
156
158
  * @returns An array of arrays, where each sub-array has `size` elements from the original array.
157
159
  */
158
160
  declare function chunk<T>(array: T[], size: number): T[][];
@@ -171,16 +173,34 @@ declare function unique<T>(array: T[]): T[];
171
173
  */
172
174
  declare function uniqueBy<T>(array: T[], equalFn: (a: T, b: T) => boolean): T[];
173
175
 
174
- type Nullable<T> = T | null;
175
- type MayBe<T> = T | undefined;
176
+ /**
177
+ * interop module
178
+ */
179
+ type InteropModuleDefault<T> = T extends {
180
+ default: infer U;
181
+ } ? U : T;
182
+
176
183
  type AnyFn<T = any, R = any> = (...args: T[]) => R;
177
184
  type Arrayable<T> = T | T[];
178
- type Awaitable<T> = T | Promise<T>;
185
+ type Awaitable<T> = Promise<T> | T;
186
+ type MayBe<T> = T | undefined;
187
+ type Nullable<T> = T | null;
188
+ type PrimitiveType = bigint | boolean | number | string | symbol | null | undefined;
189
+ /**
190
+ * Prettify object type
191
+ */
179
192
  type Prettify<T> = {
180
193
  [K in keyof T]: T[K];
181
194
  } & {};
182
195
  type PrettifyV2<T> = Omit<T, never>;
183
- type PrimitiveType = number | bigint | string | boolean | symbol | null | undefined;
196
+ /**
197
+ * Overwrite some keys type
198
+ */
199
+ type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
200
+ /**
201
+ * Resolve `boolean | Record<string, any>` to `Record<string, any>`
202
+ */
203
+ type ResolvedOptions<T> = T extends boolean ? never : NonNullable<T>;
184
204
 
185
205
  /**
186
206
  * Converts a value to an array.
@@ -227,7 +247,7 @@ declare function slash(input: string): string;
227
247
  /**
228
248
  * Remove leading whitespace from a template string
229
249
  * Empty lines at the beginning and end of the template string are also removed.
230
- * @param input template string
250
+ * @param input - template string
231
251
  *
232
252
  * @example
233
253
  *
@@ -267,4 +287,4 @@ interface SortObjectOptions {
267
287
  */
268
288
  declare function sortObject<T extends Record<string, any>>(obj: T, options?: SortObjectOptions): T;
269
289
 
270
- export { type AnyFn, type Arrayable, type Awaitable, type MayBe, NOOP, type NonEmptyString, type Nullable, type Prettify, type PrettifyV2, type PrimitiveType, type SortObjectOptions, type ThrottleDebounceOptions, type Whitespace, at, cAF, capitalize, chunk, clamp, days, debounce, ensurePrefix, ensureSuffix, flattenArrayable, getObjectType, hasOwn, hours, isArray, isArrayEqual, isBoolean, isBrowser, isEmptyString, isEmptyStringOrWhitespace, isFunction, isInteger, isNativePromise, isNil, isNull, isNumber, isNumbericString, isObject, isPromise, isRegExp, isSet, isString, isUndefined, isWhitespaceString, join, last, mergeArrayable, minutes, noop, omit, once, pick, rAF, seconds, slash, sortObject, throttle, toArray, unindent, unique, uniqueBy, waitFor, warnOnce, weeks };
290
+ export { type AnyFn, type Arrayable, type Awaitable, 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, days, debounce, ensurePrefix, ensureSuffix, flattenArrayable, getObjectType, hasOwn, hours, isArray, isArrayEqual, isBoolean, isBrowser, isEmptyString, isEmptyStringOrWhitespace, isFunction, isInteger, isNativePromise, isNil, isNonEmptyString, isNull, isNumber, isNumbericString, isObject, isPromise, isRegExp, isSet, isString, isUndefined, isWhitespaceString, join, last, mergeArrayable, minutes, noop, omit, once, pick, rAF, seconds, slash, sortObject, throttle, toArray, unindent, unique, uniqueBy, waitFor, warnOnce, weeks };
package/dist/index.d.ts CHANGED
@@ -3,17 +3,18 @@ export * from 'scule';
3
3
 
4
4
  /**
5
5
  * @file is utils
6
- * @category is
6
+ * @module is
7
7
  * @copyright {@link https://github.com/sindresorhus/is}
8
8
  */
9
- declare function getObjectType(value: unknown): string;
10
- declare function isString(value: unknown): value is string;
11
- declare function isNumber(value: unknown): value is number;
12
- declare function isEmptyString(value: unknown): value is '';
13
9
  type Whitespace = ' ';
14
10
  type NonEmptyString = string & {
15
11
  0: '';
16
12
  };
13
+ declare function getObjectType(value: unknown): string;
14
+ declare function isString(value: unknown): value is string;
15
+ declare function isNumber(value: unknown): value is number;
16
+ declare function isEmptyString(value: unknown): value is '';
17
+ declare function isNonEmptyString(value: unknown): value is NonEmptyString;
17
18
  declare function isWhitespaceString(value: unknown): value is Whitespace;
18
19
  declare function isEmptyStringOrWhitespace(value: unknown): value is '' | Whitespace;
19
20
  declare function isNumbericString(value: unknown): value is `${number}`;
@@ -53,7 +54,7 @@ declare const isBrowser: () => boolean;
53
54
 
54
55
  /**
55
56
  * @file case utils
56
- * @category Case
57
+ * @module Case
57
58
  */
58
59
 
59
60
  /**
@@ -67,20 +68,21 @@ declare const capitalize: typeof upperFirst;
67
68
  /**
68
69
  * Request animation frame
69
70
  *
70
- * @param fn callback
71
+ * @param fn - callback
71
72
  * @returns id
72
73
  */
73
74
  declare function rAF(fn: FrameRequestCallback): number;
74
75
  /**
75
76
  * Cancel animation frame
76
77
  *
77
- * @param id id
78
+ * @param id - id
78
79
  * @returns void
79
80
  */
80
81
  declare function cAF(id: number): void;
81
82
 
82
83
  /**
83
- * @category Utils - time
84
+ * @file time utils
85
+ * @module Time
84
86
  */
85
87
  declare function seconds(count: number): number;
86
88
  declare function minutes(count: number): number;
@@ -90,9 +92,9 @@ declare function weeks(count: number): number;
90
92
 
91
93
  /**
92
94
  * Clamps a number between a minimum and maximum value
93
- * @param value the value to clamp within the given range
94
- * @param min the minimum value to clamp
95
- * @param max the maximum value to clamp
95
+ * @param value - the value to clamp within the given range
96
+ * @param min - the minimum value to clamp
97
+ * @param max - the maximum value to clamp
96
98
  * @returns the new value
97
99
  */
98
100
  declare function clamp(value: number, min?: number, max?: number): number;
@@ -100,7 +102,7 @@ declare function clamp(value: number, min?: number, max?: number): number;
100
102
  /**
101
103
  * Wait for a number of milliseconds
102
104
  *
103
- * @param ms millseconds to wait
105
+ * @param ms - millseconds to wait
104
106
  * @returns a promise that resolves after ms milliseconds
105
107
  *
106
108
  * @example
@@ -151,8 +153,8 @@ declare function last<T>(array: readonly T[]): T | undefined;
151
153
 
152
154
  /**
153
155
  * Splits an array into smaller chunks of a given size.
154
- * @param array The array to split
155
- * @param size The size of each chunk
156
+ * @param array - The array to split
157
+ * @param size - The size of each chunk
156
158
  * @returns An array of arrays, where each sub-array has `size` elements from the original array.
157
159
  */
158
160
  declare function chunk<T>(array: T[], size: number): T[][];
@@ -171,16 +173,34 @@ declare function unique<T>(array: T[]): T[];
171
173
  */
172
174
  declare function uniqueBy<T>(array: T[], equalFn: (a: T, b: T) => boolean): T[];
173
175
 
174
- type Nullable<T> = T | null;
175
- type MayBe<T> = T | undefined;
176
+ /**
177
+ * interop module
178
+ */
179
+ type InteropModuleDefault<T> = T extends {
180
+ default: infer U;
181
+ } ? U : T;
182
+
176
183
  type AnyFn<T = any, R = any> = (...args: T[]) => R;
177
184
  type Arrayable<T> = T | T[];
178
- type Awaitable<T> = T | Promise<T>;
185
+ type Awaitable<T> = Promise<T> | T;
186
+ type MayBe<T> = T | undefined;
187
+ type Nullable<T> = T | null;
188
+ type PrimitiveType = bigint | boolean | number | string | symbol | null | undefined;
189
+ /**
190
+ * Prettify object type
191
+ */
179
192
  type Prettify<T> = {
180
193
  [K in keyof T]: T[K];
181
194
  } & {};
182
195
  type PrettifyV2<T> = Omit<T, never>;
183
- type PrimitiveType = number | bigint | string | boolean | symbol | null | undefined;
196
+ /**
197
+ * Overwrite some keys type
198
+ */
199
+ type Overwrite<T, U> = Pick<T, Exclude<keyof T, keyof U>> & U;
200
+ /**
201
+ * Resolve `boolean | Record<string, any>` to `Record<string, any>`
202
+ */
203
+ type ResolvedOptions<T> = T extends boolean ? never : NonNullable<T>;
184
204
 
185
205
  /**
186
206
  * Converts a value to an array.
@@ -227,7 +247,7 @@ declare function slash(input: string): string;
227
247
  /**
228
248
  * Remove leading whitespace from a template string
229
249
  * Empty lines at the beginning and end of the template string are also removed.
230
- * @param input template string
250
+ * @param input - template string
231
251
  *
232
252
  * @example
233
253
  *
@@ -267,4 +287,4 @@ interface SortObjectOptions {
267
287
  */
268
288
  declare function sortObject<T extends Record<string, any>>(obj: T, options?: SortObjectOptions): T;
269
289
 
270
- export { type AnyFn, type Arrayable, type Awaitable, type MayBe, NOOP, type NonEmptyString, type Nullable, type Prettify, type PrettifyV2, type PrimitiveType, type SortObjectOptions, type ThrottleDebounceOptions, type Whitespace, at, cAF, capitalize, chunk, clamp, days, debounce, ensurePrefix, ensureSuffix, flattenArrayable, getObjectType, hasOwn, hours, isArray, isArrayEqual, isBoolean, isBrowser, isEmptyString, isEmptyStringOrWhitespace, isFunction, isInteger, isNativePromise, isNil, isNull, isNumber, isNumbericString, isObject, isPromise, isRegExp, isSet, isString, isUndefined, isWhitespaceString, join, last, mergeArrayable, minutes, noop, omit, once, pick, rAF, seconds, slash, sortObject, throttle, toArray, unindent, unique, uniqueBy, waitFor, warnOnce, weeks };
290
+ export { type AnyFn, type Arrayable, type Awaitable, 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, days, debounce, ensurePrefix, ensureSuffix, flattenArrayable, getObjectType, hasOwn, hours, isArray, isArrayEqual, isBoolean, isBrowser, isEmptyString, isEmptyStringOrWhitespace, isFunction, isInteger, isNativePromise, isNil, isNonEmptyString, isNull, isNumber, isNumbericString, isObject, isPromise, isRegExp, isSet, isString, isUndefined, isWhitespaceString, join, last, mergeArrayable, minutes, noop, omit, once, pick, rAF, seconds, slash, sortObject, throttle, toArray, unindent, unique, uniqueBy, waitFor, warnOnce, weeks };
package/dist/index.js CHANGED
@@ -1,3 +1,81 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
18
+
19
+ // src/index.ts
20
+ var src_exports = {};
21
+ __export(src_exports, {
22
+ NOOP: () => NOOP,
23
+ at: () => at,
24
+ cAF: () => cAF,
25
+ capitalize: () => capitalize,
26
+ chunk: () => chunk,
27
+ clamp: () => clamp,
28
+ days: () => days,
29
+ debounce: () => debounce,
30
+ ensurePrefix: () => ensurePrefix,
31
+ ensureSuffix: () => ensureSuffix,
32
+ flattenArrayable: () => flattenArrayable,
33
+ getObjectType: () => getObjectType,
34
+ hasOwn: () => hasOwn,
35
+ hours: () => hours,
36
+ isArray: () => isArray,
37
+ isArrayEqual: () => isArrayEqual,
38
+ isBoolean: () => isBoolean,
39
+ isBrowser: () => isBrowser,
40
+ isEmptyString: () => isEmptyString,
41
+ isEmptyStringOrWhitespace: () => isEmptyStringOrWhitespace,
42
+ isFunction: () => isFunction,
43
+ isInteger: () => isInteger,
44
+ isNativePromise: () => isNativePromise,
45
+ isNil: () => isNil,
46
+ isNonEmptyString: () => isNonEmptyString,
47
+ isNull: () => isNull,
48
+ isNumber: () => isNumber,
49
+ isNumbericString: () => isNumbericString,
50
+ isObject: () => isObject,
51
+ isPromise: () => isPromise,
52
+ isRegExp: () => isRegExp,
53
+ isSet: () => isSet,
54
+ isString: () => isString,
55
+ isUndefined: () => isUndefined,
56
+ isWhitespaceString: () => isWhitespaceString,
57
+ join: () => join,
58
+ last: () => last,
59
+ mergeArrayable: () => mergeArrayable,
60
+ minutes: () => minutes,
61
+ noop: () => noop,
62
+ omit: () => omit,
63
+ once: () => once,
64
+ pick: () => pick,
65
+ rAF: () => rAF,
66
+ seconds: () => seconds,
67
+ slash: () => slash,
68
+ sortObject: () => sortObject,
69
+ throttle: () => throttle,
70
+ toArray: () => toArray,
71
+ unindent: () => unindent,
72
+ unique: () => unique,
73
+ uniqueBy: () => uniqueBy,
74
+ waitFor: () => waitFor,
75
+ warnOnce: () => warnOnce,
76
+ weeks: () => weeks
77
+ });
78
+
1
79
  // src/is/index.ts
2
80
  function getObjectType(value) {
3
81
  return Object.prototype.toString.call(value).slice(8, -1);
@@ -11,6 +89,9 @@ function isNumber(value) {
11
89
  function isEmptyString(value) {
12
90
  return isString(value) && value.length === 0;
13
91
  }
92
+ function isNonEmptyString(value) {
93
+ return isString(value) && value.length > 0;
94
+ }
14
95
  function isWhitespaceString(value) {
15
96
  return isString(value) && /^\s*$/.test(value);
16
97
  }
@@ -81,89 +162,19 @@ function once(func) {
81
162
  // src/env/isBrowser.ts
82
163
  var isBrowser = () => typeof document !== "undefined";
83
164
 
84
- // node_modules/.pnpm/scule@1.3.0/node_modules/scule/dist/index.mjs
85
- var NUMBER_CHAR_RE = /\d/;
86
- var STR_SPLITTERS = ["-", "_", "/", "."];
87
- function isUppercase(char = "") {
88
- if (NUMBER_CHAR_RE.test(char)) {
89
- return void 0;
90
- }
91
- return char !== char.toLowerCase();
92
- }
93
- function splitByCase(str, separators) {
94
- const splitters = separators ?? STR_SPLITTERS;
95
- const parts = [];
96
- if (!str || typeof str !== "string") {
97
- return parts;
98
- }
99
- let buff = "";
100
- let previousUpper;
101
- let previousSplitter;
102
- for (const char of str) {
103
- const isSplitter = splitters.includes(char);
104
- if (isSplitter === true) {
105
- parts.push(buff);
106
- buff = "";
107
- previousUpper = void 0;
108
- continue;
109
- }
110
- const isUpper = isUppercase(char);
111
- if (previousSplitter === false) {
112
- if (previousUpper === false && isUpper === true) {
113
- parts.push(buff);
114
- buff = char;
115
- previousUpper = isUpper;
116
- continue;
117
- }
118
- if (previousUpper === true && isUpper === false && buff.length > 1) {
119
- const lastChar = buff.at(-1);
120
- parts.push(buff.slice(0, Math.max(0, buff.length - 1)));
121
- buff = lastChar + char;
122
- previousUpper = isUpper;
123
- continue;
124
- }
125
- }
126
- buff += char;
127
- previousUpper = isUpper;
128
- previousSplitter = isSplitter;
129
- }
130
- parts.push(buff);
131
- return parts;
132
- }
133
- function upperFirst(str) {
134
- return str ? str[0].toUpperCase() + str.slice(1) : "";
135
- }
136
- function lowerFirst(str) {
137
- return str ? str[0].toLowerCase() + str.slice(1) : "";
138
- }
139
- function pascalCase(str, opts) {
140
- return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => upperFirst(opts?.normalize ? p.toLowerCase() : p)).join("") : "";
141
- }
142
- function camelCase(str, opts) {
143
- return lowerFirst(pascalCase(str || "", opts));
144
- }
145
- function kebabCase(str, joiner) {
146
- return str ? (Array.isArray(str) ? str : splitByCase(str)).map((p) => p.toLowerCase()).join(joiner ?? "-") : "";
147
- }
148
- function snakeCase(str) {
149
- return kebabCase(str || "", "_");
150
- }
151
- function flatCase(str) {
152
- return kebabCase(str || "", "");
153
- }
154
- function trainCase(str, opts) {
155
- return (Array.isArray(str) ? str : splitByCase(str)).filter(Boolean).map((p) => upperFirst(opts?.normalize ? p.toLowerCase() : p)).join("-");
156
- }
157
- var titleCaseExceptions = /^(a|an|and|as|at|but|by|for|if|in|is|nor|of|on|or|the|to|with)$/i;
158
- function titleCase(str, opts) {
159
- return (Array.isArray(str) ? str : splitByCase(str)).filter(Boolean).map(
160
- (p) => titleCaseExceptions.test(p) ? p.toLowerCase() : upperFirst(opts?.normalize ? p.toLowerCase() : p)
161
- ).join(" ");
162
- }
163
-
164
165
  // src/case.ts
166
+ var case_exports = {};
167
+ __export(case_exports, {
168
+ capitalize: () => capitalize
169
+ });
170
+ __reExport(case_exports, scule_star);
171
+ import { upperFirst } from "scule";
172
+ import * as scule_star from "scule";
165
173
  var capitalize = upperFirst;
166
174
 
175
+ // src/index.ts
176
+ __reExport(src_exports, case_exports);
177
+
167
178
  // src/misc/raf.ts
168
179
  var root = isBrowser() ? window : globalThis;
169
180
  var prev = Date.now();
@@ -432,7 +443,6 @@ export {
432
443
  NOOP,
433
444
  at,
434
445
  cAF,
435
- camelCase,
436
446
  capitalize,
437
447
  chunk,
438
448
  clamp,
@@ -440,7 +450,6 @@ export {
440
450
  debounce,
441
451
  ensurePrefix,
442
452
  ensureSuffix,
443
- flatCase,
444
453
  flattenArrayable,
445
454
  getObjectType,
446
455
  hasOwn,
@@ -455,6 +464,7 @@ export {
455
464
  isInteger,
456
465
  isNativePromise,
457
466
  isNil,
467
+ isNonEmptyString,
458
468
  isNull,
459
469
  isNumber,
460
470
  isNumbericString,
@@ -464,33 +474,24 @@ export {
464
474
  isSet,
465
475
  isString,
466
476
  isUndefined,
467
- isUppercase,
468
477
  isWhitespaceString,
469
478
  join,
470
- kebabCase,
471
479
  last,
472
- lowerFirst,
473
480
  mergeArrayable,
474
481
  minutes,
475
482
  noop,
476
483
  omit,
477
484
  once,
478
- pascalCase,
479
485
  pick,
480
486
  rAF,
481
487
  seconds,
482
488
  slash,
483
- snakeCase,
484
489
  sortObject,
485
- splitByCase,
486
490
  throttle,
487
- titleCase,
488
491
  toArray,
489
- trainCase,
490
492
  unindent,
491
493
  unique,
492
494
  uniqueBy,
493
- upperFirst,
494
495
  waitFor,
495
496
  warnOnce,
496
497
  weeks
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ntnyq/utils",
3
3
  "type": "module",
4
- "version": "0.3.0",
4
+ "version": "0.3.2",
5
5
  "description": "Common used utils.",
6
6
  "keywords": [
7
7
  "utils"
@@ -40,23 +40,22 @@
40
40
  "scule": "^1.3.0"
41
41
  },
42
42
  "devDependencies": {
43
- "@ntnyq/eslint-config": "^3.2.2",
44
- "@ntnyq/prettier-config": "^1.21.3",
45
- "@vitest/coverage-v8": "^2.1.5",
43
+ "@ntnyq/eslint-config": "^3.8.1",
44
+ "@ntnyq/prettier-config": "^1.22.0",
45
+ "@vitest/coverage-v8": "^2.1.8",
46
46
  "bumpp": "^9.8.1",
47
- "eslint": "^9.14.0",
48
- "husky": "^9.1.6",
47
+ "eslint": "^9.16.0",
48
+ "husky": "^9.1.7",
49
49
  "nano-staged": "^0.8.0",
50
50
  "npm-run-all2": "^7.0.1",
51
- "prettier": "^3.3.3",
51
+ "prettier": "^3.4.2",
52
52
  "tsup": "^8.3.5",
53
- "typescript": "^5.6.3",
54
- "vitest": "^2.1.5"
53
+ "typescript": "^5.7.2",
54
+ "vitest": "^2.1.8"
55
55
  },
56
56
  "engines": {
57
57
  "node": ">=18.18.0"
58
58
  },
59
- "prettier": "@ntnyq/prettier-config",
60
59
  "nano-staged": {
61
60
  "*.{js,ts,mjs,cjs,json,md,yml,yaml}": "eslint --fix"
62
61
  },