@tb-dev/utils 7.0.13 → 7.0.14

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.
Files changed (2) hide show
  1. package/dist/index.js +16 -20
  2. package/package.json +7 -8
package/dist/index.js CHANGED
@@ -2,23 +2,30 @@ function toArray(item) {
2
2
  const array = item ?? [];
3
3
  return Array.isArray(array) ? array : [array];
4
4
  }
5
+
5
6
  function trimArray(array, options = {}) {
6
7
  const _array = array.map((it) => it.trim());
7
8
  return options.allowEmpty ? _array : _array.filter(Boolean);
8
9
  }
10
+
9
11
  function upsert(array, item, predicate) {
10
- const index = array.findIndex(predicate ?? ((value) => value === item));
12
+ const index = array.findIndex(
13
+ predicate ?? ((value) => value === item)
14
+ );
11
15
  if (index === -1) {
12
16
  array.push(item);
13
17
  } else {
14
18
  array[index] = item;
15
19
  }
16
20
  }
21
+
17
22
  const noop = () => {
18
23
  };
24
+
19
25
  function isNil(value) {
20
26
  return value === void 0 || value === null;
21
27
  }
28
+
22
29
  function panic(...args) {
23
30
  throw new Error(args.join(" "));
24
31
  }
@@ -38,6 +45,7 @@ function format(base, args) {
38
45
  }
39
46
  return message;
40
47
  }
48
+
41
49
  function unwrap(value, message = "`unwrap` called with a nil value") {
42
50
  return isNil(value) ? panic(message) : value;
43
51
  }
@@ -47,9 +55,11 @@ function unwrapOr(value, other) {
47
55
  function unwrapOrElse(value, fn) {
48
56
  return isNil(value) ? fn() : value;
49
57
  }
58
+
50
59
  function flushPromises() {
51
60
  return new Promise((resolve) => void setTimeout(resolve, 0));
52
61
  }
62
+
53
63
  class PromiseSet {
54
64
  promises = /* @__PURE__ */ new Set();
55
65
  chain(promise) {
@@ -72,9 +82,11 @@ class PromiseSet {
72
82
  return set;
73
83
  }
74
84
  }
85
+
75
86
  function sleep(ms) {
76
87
  return new Promise((resolve) => void setTimeout(resolve, ms));
77
88
  }
89
+
78
90
  function splitWhitespace(value, options = {}) {
79
91
  if (value) {
80
92
  if (Array.isArray(value)) {
@@ -86,26 +98,10 @@ function splitWhitespace(value, options = {}) {
86
98
  }
87
99
  return [];
88
100
  }
101
+
89
102
  function toPixel(value) {
90
103
  if (typeof value === "number") return `${value}px`;
91
104
  return value;
92
105
  }
93
- export {
94
- PromiseSet,
95
- flushPromises,
96
- isNil,
97
- noop,
98
- panic,
99
- sleep,
100
- splitWhitespace,
101
- toArray,
102
- toPixel,
103
- todo,
104
- trimArray,
105
- unimplemented,
106
- unreachable,
107
- unwrap,
108
- unwrapOr,
109
- unwrapOrElse,
110
- upsert
111
- };
106
+
107
+ export { PromiseSet, flushPromises, isNil, noop, panic, sleep, splitWhitespace, toArray, toPixel, todo, trimArray, unimplemented, unreachable, unwrap, unwrapOr, unwrapOrElse, upsert };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tb-dev/utils",
3
- "version": "7.0.13",
3
+ "version": "7.0.14",
4
4
  "description": "TypeScript utils",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -24,16 +24,15 @@
24
24
  "typescript"
25
25
  ],
26
26
  "devDependencies": {
27
- "@tb-dev/eslint-config": "^8.0.7",
28
- "@types/node": "^24.3.0",
27
+ "@tb-dev/eslint-config": "^8.0.8",
28
+ "@types/node": "^24.3.1",
29
29
  "@vitest/ui": "^3.2.4",
30
30
  "eslint": "^9.34.0",
31
- "prettier": "^3.6.2",
32
31
  "tslib": "^2.8.1",
33
- "typedoc": "^0.28.10",
34
- "typedoc-plugin-mdn-links": "^5.0.8",
32
+ "typedoc": "^0.28.12",
33
+ "typedoc-plugin-mdn-links": "^5.0.9",
35
34
  "typescript": "^5.9.2",
36
- "vite": "^7.1.3",
35
+ "vite": "^7.1.4",
37
36
  "vite-plugin-dts": "^4.5.4",
38
37
  "vitest": "^3.2.4"
39
38
  },
@@ -51,7 +50,7 @@
51
50
  "scripts": {
52
51
  "build": "vite build",
53
52
  "docs": "typedoc --plugin typedoc-plugin-mdn-links",
54
- "format": "prettier . --write",
53
+ "format": "dprint fmt",
55
54
  "lint": "eslint . --config eslint.config.js",
56
55
  "release": "pwsh scripts/publish.ps1",
57
56
  "test": "vitest",