@tb-dev/utils 5.1.1 → 5.1.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/package.json +10 -12
- package/dist/index.cjs +0 -124
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tb-dev/utils",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.3",
|
|
4
4
|
"description": "TypeScript utils",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -23,39 +23,37 @@
|
|
|
23
23
|
"typescript"
|
|
24
24
|
],
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@tb-dev/eslint-config": "^6.
|
|
26
|
+
"@tb-dev/eslint-config": "^6.6.1",
|
|
27
27
|
"@types/node": "^22.13.10",
|
|
28
|
-
"@vitest/ui": "^3.0.
|
|
28
|
+
"@vitest/ui": "^3.0.9",
|
|
29
29
|
"eslint": "^9.22.0",
|
|
30
30
|
"prettier": "^3.5.3",
|
|
31
31
|
"tslib": "^2.8.1",
|
|
32
|
-
"typedoc": "^0.
|
|
32
|
+
"typedoc": "^0.28.1",
|
|
33
33
|
"typedoc-plugin-mdn-links": "^5.0.1",
|
|
34
34
|
"typescript": "^5.8.2",
|
|
35
|
-
"vite": "^6.2.
|
|
35
|
+
"vite": "^6.2.2",
|
|
36
36
|
"vite-plugin-dts": "^4.5.3",
|
|
37
|
-
"vitest": "^3.0.
|
|
37
|
+
"vitest": "^3.0.9"
|
|
38
38
|
},
|
|
39
39
|
"files": [
|
|
40
40
|
"dist"
|
|
41
41
|
],
|
|
42
|
-
"main": "./dist/index.
|
|
43
|
-
"module": "./dist/index.js",
|
|
42
|
+
"main": "./dist/index.js",
|
|
44
43
|
"types": "./dist/index.d.ts",
|
|
45
44
|
"exports": {
|
|
46
45
|
".": {
|
|
47
46
|
"types": "./dist/index.d.ts",
|
|
48
|
-
"import": "./dist/index.js"
|
|
49
|
-
"require": "./dist/index.cjs"
|
|
47
|
+
"import": "./dist/index.js"
|
|
50
48
|
}
|
|
51
49
|
},
|
|
52
50
|
"scripts": {
|
|
53
51
|
"build": "vite build",
|
|
54
52
|
"docs": "typedoc --plugin typedoc-plugin-mdn-links",
|
|
55
53
|
"format": "prettier . --write",
|
|
56
|
-
"lint": "eslint . --config eslint.config.js
|
|
54
|
+
"lint": "eslint . --config eslint.config.js",
|
|
57
55
|
"lint-fix": "eslint . --config eslint.config.js --fix",
|
|
58
|
-
"release": "
|
|
56
|
+
"release": "pwsh scripts/publish.ps1",
|
|
59
57
|
"test": "vitest",
|
|
60
58
|
"type-check": "tsc --noEmit",
|
|
61
59
|
"update": "miho update major -t"
|
package/dist/index.cjs
DELETED
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
4
|
-
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
5
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
6
|
-
const float = /^\d+(?:\.(\d+))?$/;
|
|
7
|
-
const regex = {
|
|
8
|
-
float
|
|
9
|
-
};
|
|
10
|
-
function isNil(value) {
|
|
11
|
-
return value === void 0 || value === null;
|
|
12
|
-
}
|
|
13
|
-
const isNullish = isNil;
|
|
14
|
-
function upsert(array, item, predicate) {
|
|
15
|
-
const index = array.findIndex(predicate ?? ((value) => value === item));
|
|
16
|
-
if (index === -1) {
|
|
17
|
-
array.push(item);
|
|
18
|
-
} else {
|
|
19
|
-
array[index] = item;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
function toArray(item) {
|
|
23
|
-
const array = item ?? [];
|
|
24
|
-
return Array.isArray(array) ? array : [array];
|
|
25
|
-
}
|
|
26
|
-
function trimArray(array, options = {}) {
|
|
27
|
-
const _array = array.map((it) => it.trim());
|
|
28
|
-
return options.allowEmpty ? _array : _array.filter(Boolean);
|
|
29
|
-
}
|
|
30
|
-
function panic(...args) {
|
|
31
|
-
throw new Error(args.join(" "));
|
|
32
|
-
}
|
|
33
|
-
function todo(...args) {
|
|
34
|
-
panic(format("not yet implemented", args));
|
|
35
|
-
}
|
|
36
|
-
function unimplemented(...args) {
|
|
37
|
-
panic(format("not implemented", args));
|
|
38
|
-
}
|
|
39
|
-
function unreachable(...args) {
|
|
40
|
-
panic(format("unreachable", args));
|
|
41
|
-
}
|
|
42
|
-
function format(base, args) {
|
|
43
|
-
let message = base;
|
|
44
|
-
if (args.length > 0) {
|
|
45
|
-
message = `${message}: ${args.join(" ")}`;
|
|
46
|
-
}
|
|
47
|
-
return message;
|
|
48
|
-
}
|
|
49
|
-
function splitWhitespace(value, options = {}) {
|
|
50
|
-
if (!value) return [];
|
|
51
|
-
if (Array.isArray(value)) {
|
|
52
|
-
const array = value.map((it) => splitWhitespace(it, options));
|
|
53
|
-
return array.flat(Number.POSITIVE_INFINITY);
|
|
54
|
-
}
|
|
55
|
-
value = value.trim().split(/\s/);
|
|
56
|
-
return trimArray(value, options);
|
|
57
|
-
}
|
|
58
|
-
function sleep(ms) {
|
|
59
|
-
return new Promise((resolve) => void setTimeout(resolve, ms));
|
|
60
|
-
}
|
|
61
|
-
function flushPromises() {
|
|
62
|
-
return new Promise((resolve) => void setTimeout(resolve, 0));
|
|
63
|
-
}
|
|
64
|
-
class PromiseSet {
|
|
65
|
-
constructor() {
|
|
66
|
-
__publicField(this, "promises", /* @__PURE__ */ new Set());
|
|
67
|
-
}
|
|
68
|
-
chain(promise) {
|
|
69
|
-
this.promises.add(promise);
|
|
70
|
-
return this;
|
|
71
|
-
}
|
|
72
|
-
async join() {
|
|
73
|
-
await Promise.all(this.promises);
|
|
74
|
-
this.promises.clear();
|
|
75
|
-
}
|
|
76
|
-
async joinFlushed() {
|
|
77
|
-
await this.join();
|
|
78
|
-
await flushPromises();
|
|
79
|
-
}
|
|
80
|
-
static from(promises) {
|
|
81
|
-
const set = new PromiseSet();
|
|
82
|
-
for (const promise of promises) {
|
|
83
|
-
set.promises.add(promise);
|
|
84
|
-
}
|
|
85
|
-
return set;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
const noop = () => {
|
|
89
|
-
};
|
|
90
|
-
function isEmpty(value) {
|
|
91
|
-
if (isNullish(value)) {
|
|
92
|
-
return true;
|
|
93
|
-
}
|
|
94
|
-
if (Array.isArray(value) || typeof value === "string") {
|
|
95
|
-
return value.length === 0;
|
|
96
|
-
}
|
|
97
|
-
if (value instanceof Map || value instanceof Set) {
|
|
98
|
-
return value.size === 0;
|
|
99
|
-
}
|
|
100
|
-
return false;
|
|
101
|
-
}
|
|
102
|
-
function toPixel(value) {
|
|
103
|
-
if (typeof value === "number" || typeof value === "string" && regex.float.test(value)) {
|
|
104
|
-
return `${value}px`;
|
|
105
|
-
}
|
|
106
|
-
return value;
|
|
107
|
-
}
|
|
108
|
-
exports.PromiseSet = PromiseSet;
|
|
109
|
-
exports.flushPromises = flushPromises;
|
|
110
|
-
exports.isEmpty = isEmpty;
|
|
111
|
-
exports.isNil = isNil;
|
|
112
|
-
exports.isNullish = isNullish;
|
|
113
|
-
exports.noop = noop;
|
|
114
|
-
exports.panic = panic;
|
|
115
|
-
exports.regex = regex;
|
|
116
|
-
exports.sleep = sleep;
|
|
117
|
-
exports.splitWhitespace = splitWhitespace;
|
|
118
|
-
exports.toArray = toArray;
|
|
119
|
-
exports.toPixel = toPixel;
|
|
120
|
-
exports.todo = todo;
|
|
121
|
-
exports.trimArray = trimArray;
|
|
122
|
-
exports.unimplemented = unimplemented;
|
|
123
|
-
exports.unreachable = unreachable;
|
|
124
|
-
exports.upsert = upsert;
|