@ntnyq/utils 0.1.0 → 0.1.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 +94 -5
- package/dist/index.d.cts +61 -3
- package/dist/index.d.ts +61 -3
- package/dist/index.js +79 -5
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -20,17 +20,31 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var src_exports = {};
|
|
22
22
|
__export(src_exports, {
|
|
23
|
+
NOOP: () => NOOP,
|
|
23
24
|
cAF: () => cAF,
|
|
24
25
|
camelCase: () => camelCase,
|
|
25
26
|
capitalize: () => capitalize,
|
|
26
27
|
days: () => days,
|
|
27
28
|
flatCase: () => flatCase,
|
|
29
|
+
getObjectType: () => getObjectType,
|
|
28
30
|
hours: () => hours,
|
|
31
|
+
isArray: () => isArray,
|
|
32
|
+
isBoolean: () => isBoolean,
|
|
29
33
|
isBrowser: () => isBrowser,
|
|
34
|
+
isFunction: () => isFunction,
|
|
35
|
+
isInteger: () => isInteger,
|
|
36
|
+
isNativePromise: () => isNativePromise,
|
|
37
|
+
isNull: () => isNull,
|
|
38
|
+
isNumber: () => isNumber,
|
|
39
|
+
isPromise: () => isPromise,
|
|
40
|
+
isString: () => isString,
|
|
41
|
+
isUndefined: () => isUndefined,
|
|
30
42
|
isUppercase: () => isUppercase,
|
|
43
|
+
join: () => join,
|
|
31
44
|
kebabCase: () => kebabCase,
|
|
32
45
|
lowerFirst: () => lowerFirst,
|
|
33
46
|
minutes: () => minutes,
|
|
47
|
+
noop: () => noop,
|
|
34
48
|
pascalCase: () => pascalCase,
|
|
35
49
|
rAF: () => rAF,
|
|
36
50
|
seconds: () => seconds,
|
|
@@ -40,6 +54,7 @@ __export(src_exports, {
|
|
|
40
54
|
toArray: () => toArray,
|
|
41
55
|
trainCase: () => trainCase,
|
|
42
56
|
unique: () => unique,
|
|
57
|
+
uniqueBy: () => uniqueBy,
|
|
43
58
|
upperFirst: () => upperFirst,
|
|
44
59
|
waitFor: () => waitFor,
|
|
45
60
|
warnOnce: () => warnOnce,
|
|
@@ -47,6 +62,49 @@ __export(src_exports, {
|
|
|
47
62
|
});
|
|
48
63
|
module.exports = __toCommonJS(src_exports);
|
|
49
64
|
|
|
65
|
+
// src/is/index.ts
|
|
66
|
+
function getObjectType(value) {
|
|
67
|
+
return Object.prototype.toString.call(value).slice(8, -1);
|
|
68
|
+
}
|
|
69
|
+
function isString(value) {
|
|
70
|
+
return typeof value === "string";
|
|
71
|
+
}
|
|
72
|
+
function isNumber(value) {
|
|
73
|
+
return typeof value === "number";
|
|
74
|
+
}
|
|
75
|
+
function isInteger(value) {
|
|
76
|
+
return Number.isInteger(value);
|
|
77
|
+
}
|
|
78
|
+
function isBoolean(value) {
|
|
79
|
+
return typeof value === "boolean";
|
|
80
|
+
}
|
|
81
|
+
function isFunction(value) {
|
|
82
|
+
return typeof value === "function";
|
|
83
|
+
}
|
|
84
|
+
function isArray(value) {
|
|
85
|
+
return Array.isArray(value);
|
|
86
|
+
}
|
|
87
|
+
function isUndefined(value) {
|
|
88
|
+
return value === void 0;
|
|
89
|
+
}
|
|
90
|
+
function isNull(value) {
|
|
91
|
+
return value === null;
|
|
92
|
+
}
|
|
93
|
+
function isNativePromise(value) {
|
|
94
|
+
return getObjectType(value) === "Promise";
|
|
95
|
+
}
|
|
96
|
+
function hasPromiseApi(value) {
|
|
97
|
+
return isFunction(value?.then) && isFunction(value?.catch);
|
|
98
|
+
}
|
|
99
|
+
function isPromise(value) {
|
|
100
|
+
return isNativePromise(value) || hasPromiseApi(value);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// src/fn/noop.ts
|
|
104
|
+
var noop = () => {
|
|
105
|
+
};
|
|
106
|
+
var NOOP = noop;
|
|
107
|
+
|
|
50
108
|
// src/env/isBrowser.ts
|
|
51
109
|
var isBrowser = () => typeof document !== "undefined";
|
|
52
110
|
|
|
@@ -190,28 +248,58 @@ var warnOnce = (message) => {
|
|
|
190
248
|
};
|
|
191
249
|
|
|
192
250
|
// src/array/unique.ts
|
|
193
|
-
function unique(
|
|
194
|
-
return Array.from(new Set(
|
|
251
|
+
function unique(array) {
|
|
252
|
+
return Array.from(new Set(array));
|
|
253
|
+
}
|
|
254
|
+
function uniqueBy(array, equalFn) {
|
|
255
|
+
return array.reduce((acc, cur) => {
|
|
256
|
+
const idx = acc.findIndex((item) => equalFn(item, cur));
|
|
257
|
+
if (idx === -1) {
|
|
258
|
+
acc.push(cur);
|
|
259
|
+
}
|
|
260
|
+
return acc;
|
|
261
|
+
}, []);
|
|
195
262
|
}
|
|
196
263
|
|
|
197
264
|
// src/array/toArray.ts
|
|
198
|
-
function toArray(
|
|
199
|
-
|
|
200
|
-
return Array.isArray(
|
|
265
|
+
function toArray(array) {
|
|
266
|
+
array = array ?? [];
|
|
267
|
+
return Array.isArray(array) ? array : [array];
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// src/string/join.ts
|
|
271
|
+
function join(array, options = {}) {
|
|
272
|
+
const { separator = "" } = options;
|
|
273
|
+
if (!Array.isArray(array) || !array.length) return "";
|
|
274
|
+
return array.filter((v) => Boolean(v) || v === 0).join(separator);
|
|
201
275
|
}
|
|
202
276
|
// Annotate the CommonJS export names for ESM import in node:
|
|
203
277
|
0 && (module.exports = {
|
|
278
|
+
NOOP,
|
|
204
279
|
cAF,
|
|
205
280
|
camelCase,
|
|
206
281
|
capitalize,
|
|
207
282
|
days,
|
|
208
283
|
flatCase,
|
|
284
|
+
getObjectType,
|
|
209
285
|
hours,
|
|
286
|
+
isArray,
|
|
287
|
+
isBoolean,
|
|
210
288
|
isBrowser,
|
|
289
|
+
isFunction,
|
|
290
|
+
isInteger,
|
|
291
|
+
isNativePromise,
|
|
292
|
+
isNull,
|
|
293
|
+
isNumber,
|
|
294
|
+
isPromise,
|
|
295
|
+
isString,
|
|
296
|
+
isUndefined,
|
|
211
297
|
isUppercase,
|
|
298
|
+
join,
|
|
212
299
|
kebabCase,
|
|
213
300
|
lowerFirst,
|
|
214
301
|
minutes,
|
|
302
|
+
noop,
|
|
215
303
|
pascalCase,
|
|
216
304
|
rAF,
|
|
217
305
|
seconds,
|
|
@@ -221,6 +309,7 @@ function toArray(val) {
|
|
|
221
309
|
toArray,
|
|
222
310
|
trainCase,
|
|
223
311
|
unique,
|
|
312
|
+
uniqueBy,
|
|
224
313
|
upperFirst,
|
|
225
314
|
waitFor,
|
|
226
315
|
warnOnce,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
import { upperFirst } from 'scule';
|
|
2
2
|
export * from 'scule';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @file is utils
|
|
6
|
+
* @category is
|
|
7
|
+
* @copyright {@link https://github.com/sindresorhus/is}
|
|
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 isInteger(value: unknown): value is number;
|
|
13
|
+
declare function isBoolean(value: unknown): value is boolean;
|
|
14
|
+
declare function isFunction(value: unknown): value is Function;
|
|
15
|
+
declare function isArray(value: unknown): value is unknown[];
|
|
16
|
+
declare function isUndefined(value: unknown): value is undefined;
|
|
17
|
+
declare function isNull(value: unknown): value is null;
|
|
18
|
+
declare function isNativePromise<T = unknown>(value: unknown): value is Promise<T>;
|
|
19
|
+
declare function isPromise<T = unknown>(value: unknown): value is Promise<T>;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A function that does nothing.
|
|
23
|
+
*/
|
|
24
|
+
declare const noop: () => void;
|
|
25
|
+
/**
|
|
26
|
+
* Alias of {@link noop}.
|
|
27
|
+
*/
|
|
28
|
+
declare const NOOP: () => void;
|
|
29
|
+
|
|
4
30
|
/**
|
|
5
31
|
* @file env.ts
|
|
6
32
|
*/
|
|
@@ -65,7 +91,19 @@ declare function waitFor(ms: number): Promise<unknown>;
|
|
|
65
91
|
|
|
66
92
|
declare const warnOnce: (message: string) => void;
|
|
67
93
|
|
|
68
|
-
|
|
94
|
+
/**
|
|
95
|
+
* Returns a new array with unique values.
|
|
96
|
+
* @param array - The array to process.
|
|
97
|
+
* @returns The new array.
|
|
98
|
+
*/
|
|
99
|
+
declare function unique<T>(array: T[]): T[];
|
|
100
|
+
/**
|
|
101
|
+
* Returns a new array with unique values.
|
|
102
|
+
* @param array - The array to process.
|
|
103
|
+
* @param equalFn - The function to compare values.
|
|
104
|
+
* @returns The new array.
|
|
105
|
+
*/
|
|
106
|
+
declare function uniqueBy<T>(array: T[], equalFn: (a: T, b: T) => boolean): T[];
|
|
69
107
|
|
|
70
108
|
type Nullable<T> = T | null;
|
|
71
109
|
type MayBe<T> = T | undefined;
|
|
@@ -74,6 +112,26 @@ type Arrayable<T> = T | T[];
|
|
|
74
112
|
type Awaitable<T> = T | Promise<T>;
|
|
75
113
|
type Prettify<T> = Omit<T, never>;
|
|
76
114
|
|
|
77
|
-
|
|
115
|
+
/**
|
|
116
|
+
* Converts a value to an array.
|
|
117
|
+
* @param array - The value to convert.
|
|
118
|
+
* @returns The array.
|
|
119
|
+
*/
|
|
120
|
+
declare function toArray<T>(array?: Nullable<Arrayable<T>>): T[];
|
|
121
|
+
|
|
122
|
+
type JoinableValue = string | number | null | undefined;
|
|
123
|
+
interface JoinOptions {
|
|
124
|
+
/**
|
|
125
|
+
* @default '''
|
|
126
|
+
*/
|
|
127
|
+
separator?: string;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Joins an array of strings or numbers into a single string.
|
|
131
|
+
* @param array - An array of strings or numbers.
|
|
132
|
+
* @param options - An object of options.
|
|
133
|
+
* @returns A string.
|
|
134
|
+
*/
|
|
135
|
+
declare function join(array: JoinableValue[], options?: JoinOptions): string;
|
|
78
136
|
|
|
79
|
-
export { type AnyFn, type Arrayable, type Awaitable, type MayBe, type Nullable, type Prettify, cAF, capitalize, days, hours, isBrowser, minutes, rAF, seconds, toArray, unique, waitFor, warnOnce, weeks };
|
|
137
|
+
export { type AnyFn, type Arrayable, type Awaitable, type MayBe, NOOP, type Nullable, type Prettify, cAF, capitalize, days, getObjectType, hours, isArray, isBoolean, isBrowser, isFunction, isInteger, isNativePromise, isNull, isNumber, isPromise, isString, isUndefined, join, minutes, noop, rAF, seconds, toArray, unique, uniqueBy, waitFor, warnOnce, weeks };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
import { upperFirst } from 'scule';
|
|
2
2
|
export * from 'scule';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* @file is utils
|
|
6
|
+
* @category is
|
|
7
|
+
* @copyright {@link https://github.com/sindresorhus/is}
|
|
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 isInteger(value: unknown): value is number;
|
|
13
|
+
declare function isBoolean(value: unknown): value is boolean;
|
|
14
|
+
declare function isFunction(value: unknown): value is Function;
|
|
15
|
+
declare function isArray(value: unknown): value is unknown[];
|
|
16
|
+
declare function isUndefined(value: unknown): value is undefined;
|
|
17
|
+
declare function isNull(value: unknown): value is null;
|
|
18
|
+
declare function isNativePromise<T = unknown>(value: unknown): value is Promise<T>;
|
|
19
|
+
declare function isPromise<T = unknown>(value: unknown): value is Promise<T>;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A function that does nothing.
|
|
23
|
+
*/
|
|
24
|
+
declare const noop: () => void;
|
|
25
|
+
/**
|
|
26
|
+
* Alias of {@link noop}.
|
|
27
|
+
*/
|
|
28
|
+
declare const NOOP: () => void;
|
|
29
|
+
|
|
4
30
|
/**
|
|
5
31
|
* @file env.ts
|
|
6
32
|
*/
|
|
@@ -65,7 +91,19 @@ declare function waitFor(ms: number): Promise<unknown>;
|
|
|
65
91
|
|
|
66
92
|
declare const warnOnce: (message: string) => void;
|
|
67
93
|
|
|
68
|
-
|
|
94
|
+
/**
|
|
95
|
+
* Returns a new array with unique values.
|
|
96
|
+
* @param array - The array to process.
|
|
97
|
+
* @returns The new array.
|
|
98
|
+
*/
|
|
99
|
+
declare function unique<T>(array: T[]): T[];
|
|
100
|
+
/**
|
|
101
|
+
* Returns a new array with unique values.
|
|
102
|
+
* @param array - The array to process.
|
|
103
|
+
* @param equalFn - The function to compare values.
|
|
104
|
+
* @returns The new array.
|
|
105
|
+
*/
|
|
106
|
+
declare function uniqueBy<T>(array: T[], equalFn: (a: T, b: T) => boolean): T[];
|
|
69
107
|
|
|
70
108
|
type Nullable<T> = T | null;
|
|
71
109
|
type MayBe<T> = T | undefined;
|
|
@@ -74,6 +112,26 @@ type Arrayable<T> = T | T[];
|
|
|
74
112
|
type Awaitable<T> = T | Promise<T>;
|
|
75
113
|
type Prettify<T> = Omit<T, never>;
|
|
76
114
|
|
|
77
|
-
|
|
115
|
+
/**
|
|
116
|
+
* Converts a value to an array.
|
|
117
|
+
* @param array - The value to convert.
|
|
118
|
+
* @returns The array.
|
|
119
|
+
*/
|
|
120
|
+
declare function toArray<T>(array?: Nullable<Arrayable<T>>): T[];
|
|
121
|
+
|
|
122
|
+
type JoinableValue = string | number | null | undefined;
|
|
123
|
+
interface JoinOptions {
|
|
124
|
+
/**
|
|
125
|
+
* @default '''
|
|
126
|
+
*/
|
|
127
|
+
separator?: string;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Joins an array of strings or numbers into a single string.
|
|
131
|
+
* @param array - An array of strings or numbers.
|
|
132
|
+
* @param options - An object of options.
|
|
133
|
+
* @returns A string.
|
|
134
|
+
*/
|
|
135
|
+
declare function join(array: JoinableValue[], options?: JoinOptions): string;
|
|
78
136
|
|
|
79
|
-
export { type AnyFn, type Arrayable, type Awaitable, type MayBe, type Nullable, type Prettify, cAF, capitalize, days, hours, isBrowser, minutes, rAF, seconds, toArray, unique, waitFor, warnOnce, weeks };
|
|
137
|
+
export { type AnyFn, type Arrayable, type Awaitable, type MayBe, NOOP, type Nullable, type Prettify, cAF, capitalize, days, getObjectType, hours, isArray, isBoolean, isBrowser, isFunction, isInteger, isNativePromise, isNull, isNumber, isPromise, isString, isUndefined, join, minutes, noop, rAF, seconds, toArray, unique, uniqueBy, waitFor, warnOnce, weeks };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,46 @@
|
|
|
1
|
+
// src/is/index.ts
|
|
2
|
+
function getObjectType(value) {
|
|
3
|
+
return Object.prototype.toString.call(value).slice(8, -1);
|
|
4
|
+
}
|
|
5
|
+
function isString(value) {
|
|
6
|
+
return typeof value === "string";
|
|
7
|
+
}
|
|
8
|
+
function isNumber(value) {
|
|
9
|
+
return typeof value === "number";
|
|
10
|
+
}
|
|
11
|
+
function isInteger(value) {
|
|
12
|
+
return Number.isInteger(value);
|
|
13
|
+
}
|
|
14
|
+
function isBoolean(value) {
|
|
15
|
+
return typeof value === "boolean";
|
|
16
|
+
}
|
|
17
|
+
function isFunction(value) {
|
|
18
|
+
return typeof value === "function";
|
|
19
|
+
}
|
|
20
|
+
function isArray(value) {
|
|
21
|
+
return Array.isArray(value);
|
|
22
|
+
}
|
|
23
|
+
function isUndefined(value) {
|
|
24
|
+
return value === void 0;
|
|
25
|
+
}
|
|
26
|
+
function isNull(value) {
|
|
27
|
+
return value === null;
|
|
28
|
+
}
|
|
29
|
+
function isNativePromise(value) {
|
|
30
|
+
return getObjectType(value) === "Promise";
|
|
31
|
+
}
|
|
32
|
+
function hasPromiseApi(value) {
|
|
33
|
+
return isFunction(value?.then) && isFunction(value?.catch);
|
|
34
|
+
}
|
|
35
|
+
function isPromise(value) {
|
|
36
|
+
return isNativePromise(value) || hasPromiseApi(value);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// src/fn/noop.ts
|
|
40
|
+
var noop = () => {
|
|
41
|
+
};
|
|
42
|
+
var NOOP = noop;
|
|
43
|
+
|
|
1
44
|
// src/env/isBrowser.ts
|
|
2
45
|
var isBrowser = () => typeof document !== "undefined";
|
|
3
46
|
|
|
@@ -141,27 +184,57 @@ var warnOnce = (message) => {
|
|
|
141
184
|
};
|
|
142
185
|
|
|
143
186
|
// src/array/unique.ts
|
|
144
|
-
function unique(
|
|
145
|
-
return Array.from(new Set(
|
|
187
|
+
function unique(array) {
|
|
188
|
+
return Array.from(new Set(array));
|
|
189
|
+
}
|
|
190
|
+
function uniqueBy(array, equalFn) {
|
|
191
|
+
return array.reduce((acc, cur) => {
|
|
192
|
+
const idx = acc.findIndex((item) => equalFn(item, cur));
|
|
193
|
+
if (idx === -1) {
|
|
194
|
+
acc.push(cur);
|
|
195
|
+
}
|
|
196
|
+
return acc;
|
|
197
|
+
}, []);
|
|
146
198
|
}
|
|
147
199
|
|
|
148
200
|
// src/array/toArray.ts
|
|
149
|
-
function toArray(
|
|
150
|
-
|
|
151
|
-
return Array.isArray(
|
|
201
|
+
function toArray(array) {
|
|
202
|
+
array = array ?? [];
|
|
203
|
+
return Array.isArray(array) ? array : [array];
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// src/string/join.ts
|
|
207
|
+
function join(array, options = {}) {
|
|
208
|
+
const { separator = "" } = options;
|
|
209
|
+
if (!Array.isArray(array) || !array.length) return "";
|
|
210
|
+
return array.filter((v) => Boolean(v) || v === 0).join(separator);
|
|
152
211
|
}
|
|
153
212
|
export {
|
|
213
|
+
NOOP,
|
|
154
214
|
cAF,
|
|
155
215
|
camelCase,
|
|
156
216
|
capitalize,
|
|
157
217
|
days,
|
|
158
218
|
flatCase,
|
|
219
|
+
getObjectType,
|
|
159
220
|
hours,
|
|
221
|
+
isArray,
|
|
222
|
+
isBoolean,
|
|
160
223
|
isBrowser,
|
|
224
|
+
isFunction,
|
|
225
|
+
isInteger,
|
|
226
|
+
isNativePromise,
|
|
227
|
+
isNull,
|
|
228
|
+
isNumber,
|
|
229
|
+
isPromise,
|
|
230
|
+
isString,
|
|
231
|
+
isUndefined,
|
|
161
232
|
isUppercase,
|
|
233
|
+
join,
|
|
162
234
|
kebabCase,
|
|
163
235
|
lowerFirst,
|
|
164
236
|
minutes,
|
|
237
|
+
noop,
|
|
165
238
|
pascalCase,
|
|
166
239
|
rAF,
|
|
167
240
|
seconds,
|
|
@@ -171,6 +244,7 @@ export {
|
|
|
171
244
|
toArray,
|
|
172
245
|
trainCase,
|
|
173
246
|
unique,
|
|
247
|
+
uniqueBy,
|
|
174
248
|
upperFirst,
|
|
175
249
|
waitFor,
|
|
176
250
|
warnOnce,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ntnyq/utils",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.2",
|
|
5
5
|
"description": "Common used utils.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"utils"
|
|
@@ -40,15 +40,15 @@
|
|
|
40
40
|
"scule": "^1.3.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@ntnyq/eslint-config": "^3.0.0-beta.
|
|
43
|
+
"@ntnyq/eslint-config": "^3.0.0-beta.17",
|
|
44
44
|
"@ntnyq/prettier-config": "^1.21.3",
|
|
45
45
|
"@vitest/coverage-v8": "^2.1.1",
|
|
46
|
-
"bumpp": "^9.
|
|
47
|
-
"eslint": "^9.
|
|
46
|
+
"bumpp": "^9.6.1",
|
|
47
|
+
"eslint": "^9.11.1",
|
|
48
48
|
"husky": "^9.1.6",
|
|
49
49
|
"nano-staged": "^0.8.0",
|
|
50
50
|
"npm-run-all2": "^6.2.3",
|
|
51
|
-
"pnpm": "^9.
|
|
51
|
+
"pnpm": "^9.11.0",
|
|
52
52
|
"prettier": "^3.3.3",
|
|
53
53
|
"tsup": "^8.3.0",
|
|
54
54
|
"typescript": "^5.6.2",
|