@tspro/ts-utils-lib 1.6.0 → 1.8.0
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/CHANGELOG.md +8 -0
- package/README.md +6 -0
- package/dist/index.d.mts +14 -3
- package/dist/index.d.ts +14 -3
- package/dist/index.js +13 -5
- package/dist/index.mjs +13 -5
- package/package.json +9 -2
package/CHANGELOG.md
CHANGED
package/README.md
ADDED
package/dist/index.d.mts
CHANGED
|
@@ -217,9 +217,11 @@ declare function calcNormal(x1: number, y1: number, x2: number, y2: number): {
|
|
|
217
217
|
ny: number;
|
|
218
218
|
};
|
|
219
219
|
declare function sum(arr: number[]): number;
|
|
220
|
+
declare function cmp(a: number, b: number): -1 | 0 | 1;
|
|
220
221
|
|
|
221
222
|
declare const index$3_calcNormal: typeof calcNormal;
|
|
222
223
|
declare const index$3_clamp: typeof clamp;
|
|
224
|
+
declare const index$3_cmp: typeof cmp;
|
|
223
225
|
declare const index$3_interpolateCoord: typeof interpolateCoord;
|
|
224
226
|
declare const index$3_interpolateY: typeof interpolateY;
|
|
225
227
|
declare const index$3_isInteger: typeof isInteger;
|
|
@@ -229,14 +231,23 @@ declare const index$3_romanize: typeof romanize;
|
|
|
229
231
|
declare const index$3_sum: typeof sum;
|
|
230
232
|
declare const index$3_toOrdinalNumber: typeof toOrdinalNumber;
|
|
231
233
|
declare namespace index$3 {
|
|
232
|
-
export { index$3_calcNormal as calcNormal, index$3_clamp as clamp, index$3_interpolateCoord as interpolateCoord, index$3_interpolateY as interpolateY, index$3_isInteger as isInteger, index$3_linearToDecibels as linearToDecibels, index$3_mod as mod, index$3_romanize as romanize, index$3_sum as sum, index$3_toOrdinalNumber as toOrdinalNumber };
|
|
234
|
+
export { index$3_calcNormal as calcNormal, index$3_clamp as clamp, index$3_cmp as cmp, index$3_interpolateCoord as interpolateCoord, index$3_interpolateY as interpolateY, index$3_isInteger as isInteger, index$3_linearToDecibels as linearToDecibels, index$3_mod as mod, index$3_romanize as romanize, index$3_sum as sum, index$3_toOrdinalNumber as toOrdinalNumber };
|
|
233
235
|
}
|
|
234
236
|
|
|
235
|
-
declare function isObject(
|
|
237
|
+
declare function isObject(obj: unknown): obj is Record<string, unknown>;
|
|
238
|
+
/**
|
|
239
|
+
* <pre>
|
|
240
|
+
* Usage:
|
|
241
|
+
* hasProperties(obj, ["a", "b"]); // Gives type Record<string, unknown>
|
|
242
|
+
* hasProperties(obj, ["a", "b"] as const); // Gives type Record<"a" | "b", unknown>
|
|
243
|
+
* </pre>
|
|
244
|
+
*/
|
|
245
|
+
declare function hasProperties<T extends readonly string[]>(obj: unknown, props: T | string[]): obj is Record<T[number], unknown>;
|
|
236
246
|
|
|
247
|
+
declare const index$2_hasProperties: typeof hasProperties;
|
|
237
248
|
declare const index$2_isObject: typeof isObject;
|
|
238
249
|
declare namespace index$2 {
|
|
239
|
-
export { index$2_isObject as isObject };
|
|
250
|
+
export { index$2_hasProperties as hasProperties, index$2_isObject as isObject };
|
|
240
251
|
}
|
|
241
252
|
|
|
242
253
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -217,9 +217,11 @@ declare function calcNormal(x1: number, y1: number, x2: number, y2: number): {
|
|
|
217
217
|
ny: number;
|
|
218
218
|
};
|
|
219
219
|
declare function sum(arr: number[]): number;
|
|
220
|
+
declare function cmp(a: number, b: number): -1 | 0 | 1;
|
|
220
221
|
|
|
221
222
|
declare const index$3_calcNormal: typeof calcNormal;
|
|
222
223
|
declare const index$3_clamp: typeof clamp;
|
|
224
|
+
declare const index$3_cmp: typeof cmp;
|
|
223
225
|
declare const index$3_interpolateCoord: typeof interpolateCoord;
|
|
224
226
|
declare const index$3_interpolateY: typeof interpolateY;
|
|
225
227
|
declare const index$3_isInteger: typeof isInteger;
|
|
@@ -229,14 +231,23 @@ declare const index$3_romanize: typeof romanize;
|
|
|
229
231
|
declare const index$3_sum: typeof sum;
|
|
230
232
|
declare const index$3_toOrdinalNumber: typeof toOrdinalNumber;
|
|
231
233
|
declare namespace index$3 {
|
|
232
|
-
export { index$3_calcNormal as calcNormal, index$3_clamp as clamp, index$3_interpolateCoord as interpolateCoord, index$3_interpolateY as interpolateY, index$3_isInteger as isInteger, index$3_linearToDecibels as linearToDecibels, index$3_mod as mod, index$3_romanize as romanize, index$3_sum as sum, index$3_toOrdinalNumber as toOrdinalNumber };
|
|
234
|
+
export { index$3_calcNormal as calcNormal, index$3_clamp as clamp, index$3_cmp as cmp, index$3_interpolateCoord as interpolateCoord, index$3_interpolateY as interpolateY, index$3_isInteger as isInteger, index$3_linearToDecibels as linearToDecibels, index$3_mod as mod, index$3_romanize as romanize, index$3_sum as sum, index$3_toOrdinalNumber as toOrdinalNumber };
|
|
233
235
|
}
|
|
234
236
|
|
|
235
|
-
declare function isObject(
|
|
237
|
+
declare function isObject(obj: unknown): obj is Record<string, unknown>;
|
|
238
|
+
/**
|
|
239
|
+
* <pre>
|
|
240
|
+
* Usage:
|
|
241
|
+
* hasProperties(obj, ["a", "b"]); // Gives type Record<string, unknown>
|
|
242
|
+
* hasProperties(obj, ["a", "b"] as const); // Gives type Record<"a" | "b", unknown>
|
|
243
|
+
* </pre>
|
|
244
|
+
*/
|
|
245
|
+
declare function hasProperties<T extends readonly string[]>(obj: unknown, props: T | string[]): obj is Record<T[number], unknown>;
|
|
236
246
|
|
|
247
|
+
declare const index$2_hasProperties: typeof hasProperties;
|
|
237
248
|
declare const index$2_isObject: typeof isObject;
|
|
238
249
|
declare namespace index$2 {
|
|
239
|
-
export { index$2_isObject as isObject };
|
|
250
|
+
export { index$2_hasProperties as hasProperties, index$2_isObject as isObject };
|
|
240
251
|
}
|
|
241
252
|
|
|
242
253
|
/**
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* TsUtilsLib v1.
|
|
1
|
+
/* TsUtilsLib v1.8.0 | (c) 2023 PahkaSoft | Licensed under the MIT License */
|
|
2
2
|
"use strict";
|
|
3
3
|
var __defProp = Object.defineProperty;
|
|
4
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -69,6 +69,7 @@ var math_exports = {};
|
|
|
69
69
|
__export(math_exports, {
|
|
70
70
|
calcNormal: () => calcNormal,
|
|
71
71
|
clamp: () => clamp,
|
|
72
|
+
cmp: () => cmp,
|
|
72
73
|
interpolateCoord: () => interpolateCoord,
|
|
73
74
|
interpolateY: () => interpolateY,
|
|
74
75
|
isInteger: () => isInteger,
|
|
@@ -181,6 +182,9 @@ function calcNormal(x1, y1, x2, y2) {
|
|
|
181
182
|
function sum(arr) {
|
|
182
183
|
return arr.reduce((prev, cur) => cur + prev, 0);
|
|
183
184
|
}
|
|
185
|
+
function cmp(a, b) {
|
|
186
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
187
|
+
}
|
|
184
188
|
|
|
185
189
|
// src/utils/arr/index.ts
|
|
186
190
|
function isArray(a) {
|
|
@@ -195,8 +199,8 @@ function duplicate(a) {
|
|
|
195
199
|
function removeDuplicates(a) {
|
|
196
200
|
return a.filter((item, pos, arr) => arr.indexOf(item) === pos);
|
|
197
201
|
}
|
|
198
|
-
function removeDuplicatesCmp(arr,
|
|
199
|
-
return arr.filter((t1, index, self) => index === self.findIndex((t2) =>
|
|
202
|
+
function removeDuplicatesCmp(arr, cmp2) {
|
|
203
|
+
return arr.filter((t1, index, self) => index === self.findIndex((t2) => cmp2(t1, t2)));
|
|
200
204
|
}
|
|
201
205
|
function fillArray(fillValue, fillCount) {
|
|
202
206
|
if (!isInteger(fillCount) || fillCount < 0) {
|
|
@@ -871,10 +875,14 @@ function getMapKeys(map) {
|
|
|
871
875
|
// src/utils/obj/index.ts
|
|
872
876
|
var obj_exports = {};
|
|
873
877
|
__export(obj_exports, {
|
|
878
|
+
hasProperties: () => hasProperties,
|
|
874
879
|
isObject: () => isObject2
|
|
875
880
|
});
|
|
876
|
-
function isObject2(
|
|
877
|
-
return typeof
|
|
881
|
+
function isObject2(obj) {
|
|
882
|
+
return typeof obj === "object" && obj !== null && !isArray(obj);
|
|
883
|
+
}
|
|
884
|
+
function hasProperties(obj, props) {
|
|
885
|
+
return isObject2(obj) && props.every((p) => p in obj);
|
|
878
886
|
}
|
|
879
887
|
|
|
880
888
|
// src/utils/str/index.ts
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* TsUtilsLib v1.
|
|
1
|
+
/* TsUtilsLib v1.8.0 | (c) 2023 PahkaSoft | Licensed under the MIT License */
|
|
2
2
|
var __defProp = Object.defineProperty;
|
|
3
3
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
4
|
var __export = (target, all) => {
|
|
@@ -42,6 +42,7 @@ var math_exports = {};
|
|
|
42
42
|
__export(math_exports, {
|
|
43
43
|
calcNormal: () => calcNormal,
|
|
44
44
|
clamp: () => clamp,
|
|
45
|
+
cmp: () => cmp,
|
|
45
46
|
interpolateCoord: () => interpolateCoord,
|
|
46
47
|
interpolateY: () => interpolateY,
|
|
47
48
|
isInteger: () => isInteger,
|
|
@@ -154,6 +155,9 @@ function calcNormal(x1, y1, x2, y2) {
|
|
|
154
155
|
function sum(arr) {
|
|
155
156
|
return arr.reduce((prev, cur) => cur + prev, 0);
|
|
156
157
|
}
|
|
158
|
+
function cmp(a, b) {
|
|
159
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
160
|
+
}
|
|
157
161
|
|
|
158
162
|
// src/utils/arr/index.ts
|
|
159
163
|
function isArray(a) {
|
|
@@ -168,8 +172,8 @@ function duplicate(a) {
|
|
|
168
172
|
function removeDuplicates(a) {
|
|
169
173
|
return a.filter((item, pos, arr) => arr.indexOf(item) === pos);
|
|
170
174
|
}
|
|
171
|
-
function removeDuplicatesCmp(arr,
|
|
172
|
-
return arr.filter((t1, index, self) => index === self.findIndex((t2) =>
|
|
175
|
+
function removeDuplicatesCmp(arr, cmp2) {
|
|
176
|
+
return arr.filter((t1, index, self) => index === self.findIndex((t2) => cmp2(t1, t2)));
|
|
173
177
|
}
|
|
174
178
|
function fillArray(fillValue, fillCount) {
|
|
175
179
|
if (!isInteger(fillCount) || fillCount < 0) {
|
|
@@ -844,10 +848,14 @@ function getMapKeys(map) {
|
|
|
844
848
|
// src/utils/obj/index.ts
|
|
845
849
|
var obj_exports = {};
|
|
846
850
|
__export(obj_exports, {
|
|
851
|
+
hasProperties: () => hasProperties,
|
|
847
852
|
isObject: () => isObject2
|
|
848
853
|
});
|
|
849
|
-
function isObject2(
|
|
850
|
-
return typeof
|
|
854
|
+
function isObject2(obj) {
|
|
855
|
+
return typeof obj === "object" && obj !== null && !isArray(obj);
|
|
856
|
+
}
|
|
857
|
+
function hasProperties(obj, props) {
|
|
858
|
+
return isObject2(obj) && props.every((p) => p in obj);
|
|
851
859
|
}
|
|
852
860
|
|
|
853
861
|
// src/utils/str/index.ts
|
package/package.json
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tspro/ts-utils-lib",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"author": "PahkaSoft",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"private": false,
|
|
7
|
-
"
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/pahkasoft/ts-utils-lib.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/pahkasoft/ts-utils-lib/issues/new/choose"
|
|
13
|
+
},
|
|
14
|
+
"description": "Useful library of typescript classes, modules and functions.",
|
|
8
15
|
"types": "dist/index.d.ts",
|
|
9
16
|
"main": "dist/index.js",
|
|
10
17
|
"module": "dist/index.mjs",
|