@ntnyq/utils 0.1.0 → 0.1.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.cjs +34 -5
- package/dist/index.d.cts +44 -3
- package/dist/index.d.ts +44 -3
- package/dist/index.js +30 -5
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -20,6 +20,7 @@ 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,
|
|
@@ -28,9 +29,11 @@ __export(src_exports, {
|
|
|
28
29
|
hours: () => hours,
|
|
29
30
|
isBrowser: () => isBrowser,
|
|
30
31
|
isUppercase: () => isUppercase,
|
|
32
|
+
join: () => join,
|
|
31
33
|
kebabCase: () => kebabCase,
|
|
32
34
|
lowerFirst: () => lowerFirst,
|
|
33
35
|
minutes: () => minutes,
|
|
36
|
+
noop: () => noop,
|
|
34
37
|
pascalCase: () => pascalCase,
|
|
35
38
|
rAF: () => rAF,
|
|
36
39
|
seconds: () => seconds,
|
|
@@ -40,6 +43,7 @@ __export(src_exports, {
|
|
|
40
43
|
toArray: () => toArray,
|
|
41
44
|
trainCase: () => trainCase,
|
|
42
45
|
unique: () => unique,
|
|
46
|
+
uniqueBy: () => uniqueBy,
|
|
43
47
|
upperFirst: () => upperFirst,
|
|
44
48
|
waitFor: () => waitFor,
|
|
45
49
|
warnOnce: () => warnOnce,
|
|
@@ -47,6 +51,11 @@ __export(src_exports, {
|
|
|
47
51
|
});
|
|
48
52
|
module.exports = __toCommonJS(src_exports);
|
|
49
53
|
|
|
54
|
+
// src/fn/noop.ts
|
|
55
|
+
var noop = () => {
|
|
56
|
+
};
|
|
57
|
+
var NOOP = noop;
|
|
58
|
+
|
|
50
59
|
// src/env/isBrowser.ts
|
|
51
60
|
var isBrowser = () => typeof document !== "undefined";
|
|
52
61
|
|
|
@@ -190,17 +199,34 @@ var warnOnce = (message) => {
|
|
|
190
199
|
};
|
|
191
200
|
|
|
192
201
|
// src/array/unique.ts
|
|
193
|
-
function unique(
|
|
194
|
-
return Array.from(new Set(
|
|
202
|
+
function unique(array) {
|
|
203
|
+
return Array.from(new Set(array));
|
|
204
|
+
}
|
|
205
|
+
function uniqueBy(array, equalFn) {
|
|
206
|
+
return array.reduce((acc, cur) => {
|
|
207
|
+
const idx = acc.findIndex((item) => equalFn(item, cur));
|
|
208
|
+
if (idx === -1) {
|
|
209
|
+
acc.push(cur);
|
|
210
|
+
}
|
|
211
|
+
return acc;
|
|
212
|
+
}, []);
|
|
195
213
|
}
|
|
196
214
|
|
|
197
215
|
// src/array/toArray.ts
|
|
198
|
-
function toArray(
|
|
199
|
-
|
|
200
|
-
return Array.isArray(
|
|
216
|
+
function toArray(array) {
|
|
217
|
+
array = array ?? [];
|
|
218
|
+
return Array.isArray(array) ? array : [array];
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// src/string/join.ts
|
|
222
|
+
function join(array, options = {}) {
|
|
223
|
+
const { separator = "" } = options;
|
|
224
|
+
if (!Array.isArray(array) || !array.length) return "";
|
|
225
|
+
return array.filter((v) => Boolean(v) || v === 0).join(separator);
|
|
201
226
|
}
|
|
202
227
|
// Annotate the CommonJS export names for ESM import in node:
|
|
203
228
|
0 && (module.exports = {
|
|
229
|
+
NOOP,
|
|
204
230
|
cAF,
|
|
205
231
|
camelCase,
|
|
206
232
|
capitalize,
|
|
@@ -209,9 +235,11 @@ function toArray(val) {
|
|
|
209
235
|
hours,
|
|
210
236
|
isBrowser,
|
|
211
237
|
isUppercase,
|
|
238
|
+
join,
|
|
212
239
|
kebabCase,
|
|
213
240
|
lowerFirst,
|
|
214
241
|
minutes,
|
|
242
|
+
noop,
|
|
215
243
|
pascalCase,
|
|
216
244
|
rAF,
|
|
217
245
|
seconds,
|
|
@@ -221,6 +249,7 @@ function toArray(val) {
|
|
|
221
249
|
toArray,
|
|
222
250
|
trainCase,
|
|
223
251
|
unique,
|
|
252
|
+
uniqueBy,
|
|
224
253
|
upperFirst,
|
|
225
254
|
waitFor,
|
|
226
255
|
warnOnce,
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { upperFirst } from 'scule';
|
|
2
2
|
export * from 'scule';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* A function that does nothing.
|
|
6
|
+
*/
|
|
7
|
+
declare const noop: () => void;
|
|
8
|
+
/**
|
|
9
|
+
* Alias of {@link noop}.
|
|
10
|
+
*/
|
|
11
|
+
declare const NOOP: () => void;
|
|
12
|
+
|
|
4
13
|
/**
|
|
5
14
|
* @file env.ts
|
|
6
15
|
*/
|
|
@@ -65,7 +74,19 @@ declare function waitFor(ms: number): Promise<unknown>;
|
|
|
65
74
|
|
|
66
75
|
declare const warnOnce: (message: string) => void;
|
|
67
76
|
|
|
68
|
-
|
|
77
|
+
/**
|
|
78
|
+
* Returns a new array with unique values.
|
|
79
|
+
* @param array - The array to process.
|
|
80
|
+
* @returns The new array.
|
|
81
|
+
*/
|
|
82
|
+
declare function unique<T>(array: T[]): T[];
|
|
83
|
+
/**
|
|
84
|
+
* Returns a new array with unique values.
|
|
85
|
+
* @param array - The array to process.
|
|
86
|
+
* @param equalFn - The function to compare values.
|
|
87
|
+
* @returns The new array.
|
|
88
|
+
*/
|
|
89
|
+
declare function uniqueBy<T>(array: T[], equalFn: (a: T, b: T) => boolean): T[];
|
|
69
90
|
|
|
70
91
|
type Nullable<T> = T | null;
|
|
71
92
|
type MayBe<T> = T | undefined;
|
|
@@ -74,6 +95,26 @@ type Arrayable<T> = T | T[];
|
|
|
74
95
|
type Awaitable<T> = T | Promise<T>;
|
|
75
96
|
type Prettify<T> = Omit<T, never>;
|
|
76
97
|
|
|
77
|
-
|
|
98
|
+
/**
|
|
99
|
+
* Converts a value to an array.
|
|
100
|
+
* @param array - The value to convert.
|
|
101
|
+
* @returns The array.
|
|
102
|
+
*/
|
|
103
|
+
declare function toArray<T>(array?: Nullable<Arrayable<T>>): T[];
|
|
104
|
+
|
|
105
|
+
type JoinableValue = string | number | null | undefined;
|
|
106
|
+
interface JoinOptions {
|
|
107
|
+
/**
|
|
108
|
+
* @default '''
|
|
109
|
+
*/
|
|
110
|
+
separator?: string;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Joins an array of strings or numbers into a single string.
|
|
114
|
+
* @param array - An array of strings or numbers.
|
|
115
|
+
* @param options - An object of options.
|
|
116
|
+
* @returns A string.
|
|
117
|
+
*/
|
|
118
|
+
declare function join(array: JoinableValue[], options?: JoinOptions): string;
|
|
78
119
|
|
|
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 };
|
|
120
|
+
export { type AnyFn, type Arrayable, type Awaitable, type MayBe, NOOP, type Nullable, type Prettify, cAF, capitalize, days, hours, isBrowser, join, minutes, noop, rAF, seconds, toArray, unique, uniqueBy, waitFor, warnOnce, weeks };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { upperFirst } from 'scule';
|
|
2
2
|
export * from 'scule';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* A function that does nothing.
|
|
6
|
+
*/
|
|
7
|
+
declare const noop: () => void;
|
|
8
|
+
/**
|
|
9
|
+
* Alias of {@link noop}.
|
|
10
|
+
*/
|
|
11
|
+
declare const NOOP: () => void;
|
|
12
|
+
|
|
4
13
|
/**
|
|
5
14
|
* @file env.ts
|
|
6
15
|
*/
|
|
@@ -65,7 +74,19 @@ declare function waitFor(ms: number): Promise<unknown>;
|
|
|
65
74
|
|
|
66
75
|
declare const warnOnce: (message: string) => void;
|
|
67
76
|
|
|
68
|
-
|
|
77
|
+
/**
|
|
78
|
+
* Returns a new array with unique values.
|
|
79
|
+
* @param array - The array to process.
|
|
80
|
+
* @returns The new array.
|
|
81
|
+
*/
|
|
82
|
+
declare function unique<T>(array: T[]): T[];
|
|
83
|
+
/**
|
|
84
|
+
* Returns a new array with unique values.
|
|
85
|
+
* @param array - The array to process.
|
|
86
|
+
* @param equalFn - The function to compare values.
|
|
87
|
+
* @returns The new array.
|
|
88
|
+
*/
|
|
89
|
+
declare function uniqueBy<T>(array: T[], equalFn: (a: T, b: T) => boolean): T[];
|
|
69
90
|
|
|
70
91
|
type Nullable<T> = T | null;
|
|
71
92
|
type MayBe<T> = T | undefined;
|
|
@@ -74,6 +95,26 @@ type Arrayable<T> = T | T[];
|
|
|
74
95
|
type Awaitable<T> = T | Promise<T>;
|
|
75
96
|
type Prettify<T> = Omit<T, never>;
|
|
76
97
|
|
|
77
|
-
|
|
98
|
+
/**
|
|
99
|
+
* Converts a value to an array.
|
|
100
|
+
* @param array - The value to convert.
|
|
101
|
+
* @returns The array.
|
|
102
|
+
*/
|
|
103
|
+
declare function toArray<T>(array?: Nullable<Arrayable<T>>): T[];
|
|
104
|
+
|
|
105
|
+
type JoinableValue = string | number | null | undefined;
|
|
106
|
+
interface JoinOptions {
|
|
107
|
+
/**
|
|
108
|
+
* @default '''
|
|
109
|
+
*/
|
|
110
|
+
separator?: string;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Joins an array of strings or numbers into a single string.
|
|
114
|
+
* @param array - An array of strings or numbers.
|
|
115
|
+
* @param options - An object of options.
|
|
116
|
+
* @returns A string.
|
|
117
|
+
*/
|
|
118
|
+
declare function join(array: JoinableValue[], options?: JoinOptions): string;
|
|
78
119
|
|
|
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 };
|
|
120
|
+
export { type AnyFn, type Arrayable, type Awaitable, type MayBe, NOOP, type Nullable, type Prettify, cAF, capitalize, days, hours, isBrowser, join, minutes, noop, rAF, seconds, toArray, unique, uniqueBy, waitFor, warnOnce, weeks };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
// src/fn/noop.ts
|
|
2
|
+
var noop = () => {
|
|
3
|
+
};
|
|
4
|
+
var NOOP = noop;
|
|
5
|
+
|
|
1
6
|
// src/env/isBrowser.ts
|
|
2
7
|
var isBrowser = () => typeof document !== "undefined";
|
|
3
8
|
|
|
@@ -141,16 +146,33 @@ var warnOnce = (message) => {
|
|
|
141
146
|
};
|
|
142
147
|
|
|
143
148
|
// src/array/unique.ts
|
|
144
|
-
function unique(
|
|
145
|
-
return Array.from(new Set(
|
|
149
|
+
function unique(array) {
|
|
150
|
+
return Array.from(new Set(array));
|
|
151
|
+
}
|
|
152
|
+
function uniqueBy(array, equalFn) {
|
|
153
|
+
return array.reduce((acc, cur) => {
|
|
154
|
+
const idx = acc.findIndex((item) => equalFn(item, cur));
|
|
155
|
+
if (idx === -1) {
|
|
156
|
+
acc.push(cur);
|
|
157
|
+
}
|
|
158
|
+
return acc;
|
|
159
|
+
}, []);
|
|
146
160
|
}
|
|
147
161
|
|
|
148
162
|
// src/array/toArray.ts
|
|
149
|
-
function toArray(
|
|
150
|
-
|
|
151
|
-
return Array.isArray(
|
|
163
|
+
function toArray(array) {
|
|
164
|
+
array = array ?? [];
|
|
165
|
+
return Array.isArray(array) ? array : [array];
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// src/string/join.ts
|
|
169
|
+
function join(array, options = {}) {
|
|
170
|
+
const { separator = "" } = options;
|
|
171
|
+
if (!Array.isArray(array) || !array.length) return "";
|
|
172
|
+
return array.filter((v) => Boolean(v) || v === 0).join(separator);
|
|
152
173
|
}
|
|
153
174
|
export {
|
|
175
|
+
NOOP,
|
|
154
176
|
cAF,
|
|
155
177
|
camelCase,
|
|
156
178
|
capitalize,
|
|
@@ -159,9 +181,11 @@ export {
|
|
|
159
181
|
hours,
|
|
160
182
|
isBrowser,
|
|
161
183
|
isUppercase,
|
|
184
|
+
join,
|
|
162
185
|
kebabCase,
|
|
163
186
|
lowerFirst,
|
|
164
187
|
minutes,
|
|
188
|
+
noop,
|
|
165
189
|
pascalCase,
|
|
166
190
|
rAF,
|
|
167
191
|
seconds,
|
|
@@ -171,6 +195,7 @@ export {
|
|
|
171
195
|
toArray,
|
|
172
196
|
trainCase,
|
|
173
197
|
unique,
|
|
198
|
+
uniqueBy,
|
|
174
199
|
upperFirst,
|
|
175
200
|
waitFor,
|
|
176
201
|
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.1",
|
|
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
46
|
"bumpp": "^9.5.2",
|
|
47
|
-
"eslint": "^9.
|
|
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",
|