@tb-dev/utils 1.6.0 → 1.7.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/dist/array.cjs CHANGED
@@ -8,16 +8,6 @@ function upsert(array, item, predicate) {
8
8
  array[index] = item;
9
9
  }
10
10
  }
11
- function splitWhitespace(value) {
12
- if (!value)
13
- return [];
14
- if (Array.isArray(value)) {
15
- const array = value.map((i) => splitWhitespace(i));
16
- return array.flat(Number.POSITIVE_INFINITY);
17
- }
18
- value = value.trim().split(/\s/);
19
- return trimArray(value);
20
- }
21
11
  function toArray(item) {
22
12
  const array = item ?? [];
23
13
  return Array.isArray(array) ? array : [array];
@@ -25,7 +15,6 @@ function toArray(item) {
25
15
  function trimArray(array) {
26
16
  return array.map((i) => i.trim()).filter(Boolean);
27
17
  }
28
- exports.splitWhitespace = splitWhitespace;
29
18
  exports.toArray = toArray;
30
19
  exports.trimArray = trimArray;
31
20
  exports.upsert = upsert;
package/dist/array.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { MaybeArray, Nullish } from '@tb-dev/utility-types';
2
2
 
3
- export declare function upsert<T>(array: T[], item: T, predicate: (item: T) => boolean): void;
4
- export declare function splitWhitespace(value: Nullish<string | string[]>): string[];
3
+ /** Pushes an item to the array if it doesn't exist, otherwise updates it. */
4
+ export declare function upsert<T>(array: T[], item: T, predicate: (value: T) => boolean): void;
5
5
  export declare function toArray<T>(item?: Nullish<MaybeArray<T>>): T[];
6
6
  export declare function trimArray(array: string[]): string[];
package/dist/array.js CHANGED
@@ -6,16 +6,6 @@ function upsert(array, item, predicate) {
6
6
  array[index] = item;
7
7
  }
8
8
  }
9
- function splitWhitespace(value) {
10
- if (!value)
11
- return [];
12
- if (Array.isArray(value)) {
13
- const array = value.map((i) => splitWhitespace(i));
14
- return array.flat(Number.POSITIVE_INFINITY);
15
- }
16
- value = value.trim().split(/\s/);
17
- return trimArray(value);
18
- }
19
9
  function toArray(item) {
20
10
  const array = item ?? [];
21
11
  return Array.isArray(array) ? array : [array];
@@ -24,7 +14,6 @@ function trimArray(array) {
24
14
  return array.map((i) => i.trim()).filter(Boolean);
25
15
  }
26
16
  export {
27
- splitWhitespace,
28
17
  toArray,
29
18
  trimArray,
30
19
  upsert
package/dist/index.cjs CHANGED
@@ -3,6 +3,22 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const regex = require("./regex.cjs");
4
4
  const array = require("./array.cjs");
5
5
  const panic = require("./panic.cjs");
6
+ function splitWhitespace(value) {
7
+ if (!value)
8
+ return [];
9
+ if (Array.isArray(value)) {
10
+ const array2 = value.map((i) => splitWhitespace(i));
11
+ return array2.flat(Number.POSITIVE_INFINITY);
12
+ }
13
+ value = value.trim().split(/\s/);
14
+ return array.trimArray(value);
15
+ }
16
+ function flush() {
17
+ return new Promise((resolve) => void setTimeout(resolve, 0));
18
+ }
19
+ function sleep(ms) {
20
+ return new Promise((resolve) => void setTimeout(resolve, ms));
21
+ }
6
22
  function isEmpty(value) {
7
23
  if (isNullish(value)) {
8
24
  return true;
@@ -27,7 +43,6 @@ function toPixel(value) {
27
43
  return value;
28
44
  }
29
45
  exports.regex = regex.regex;
30
- exports.splitWhitespace = array.splitWhitespace;
31
46
  exports.toArray = array.toArray;
32
47
  exports.trimArray = array.trimArray;
33
48
  exports.upsert = array.upsert;
@@ -35,7 +50,10 @@ exports.panic = panic.panic;
35
50
  exports.todo = panic.todo;
36
51
  exports.unimplemented = panic.unimplemented;
37
52
  exports.unreachable = panic.unreachable;
53
+ exports.flush = flush;
38
54
  exports.isEmpty = isEmpty;
39
55
  exports.isNullish = isNullish;
40
56
  exports.noop = noop;
57
+ exports.sleep = sleep;
58
+ exports.splitWhitespace = splitWhitespace;
41
59
  exports.toPixel = toPixel;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  export * from './array';
2
2
  export * from './panic';
3
3
  export * from './regex';
4
+ export * from './string';
5
+ export * from './promise';
4
6
  /**
5
7
  * Checks if a value is empty.
6
8
  *
package/dist/index.js CHANGED
@@ -1,6 +1,23 @@
1
1
  import { regex } from "./regex.js";
2
- import { splitWhitespace, toArray, trimArray, upsert } from "./array.js";
2
+ import { trimArray } from "./array.js";
3
+ import { toArray, upsert } from "./array.js";
3
4
  import { panic, todo, unimplemented, unreachable } from "./panic.js";
5
+ function splitWhitespace(value) {
6
+ if (!value)
7
+ return [];
8
+ if (Array.isArray(value)) {
9
+ const array = value.map((i) => splitWhitespace(i));
10
+ return array.flat(Number.POSITIVE_INFINITY);
11
+ }
12
+ value = value.trim().split(/\s/);
13
+ return trimArray(value);
14
+ }
15
+ function flush() {
16
+ return new Promise((resolve) => void setTimeout(resolve, 0));
17
+ }
18
+ function sleep(ms) {
19
+ return new Promise((resolve) => void setTimeout(resolve, ms));
20
+ }
4
21
  function isEmpty(value) {
5
22
  if (isNullish(value)) {
6
23
  return true;
@@ -25,11 +42,13 @@ function toPixel(value) {
25
42
  return value;
26
43
  }
27
44
  export {
45
+ flush,
28
46
  isEmpty,
29
47
  isNullish,
30
48
  noop,
31
49
  panic,
32
50
  regex,
51
+ sleep,
33
52
  splitWhitespace,
34
53
  toArray,
35
54
  toPixel,
@@ -0,0 +1,2 @@
1
+ export declare function flush(): Promise<void>;
2
+ export declare function sleep(ms: number): Promise<void>;
@@ -0,0 +1,3 @@
1
+ import { Nullish } from '@tb-dev/utility-types';
2
+
3
+ export declare function splitWhitespace(value: Nullish<string | string[]>): string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tb-dev/utils",
3
- "version": "1.6.0",
3
+ "version": "1.7.0",
4
4
  "description": "TypeScript utils",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -30,18 +30,18 @@
30
30
  "@tb-dev/utility-types": "^1.2.7"
31
31
  },
32
32
  "devDependencies": {
33
- "@tb-dev/eslint-config": "^3.4.2",
34
- "@types/node": "^20.12.8",
33
+ "@tb-dev/eslint-config": "^3.5.1",
34
+ "@types/node": "^20.12.11",
35
35
  "eslint": "^8.57.0",
36
36
  "husky": "^9.0.11",
37
37
  "lint-staged": "^15.2.2",
38
38
  "prettier": "^3.2.5",
39
39
  "tslib": "^2.6.2",
40
40
  "typedoc": "^0.25.13",
41
- "typedoc-plugin-mdn-links": "^3.1.23",
41
+ "typedoc-plugin-mdn-links": "^3.1.24",
42
42
  "typescript": "^5.4.5",
43
43
  "vite": "^5.2.11",
44
- "vite-plugin-dts": "^3.9.0"
44
+ "vite-plugin-dts": "^3.9.1"
45
45
  },
46
46
  "files": [
47
47
  "dist"
@@ -65,10 +65,20 @@
65
65
  "import": "./dist/panic.js",
66
66
  "require": "./dist/panic.cjs"
67
67
  },
68
+ "./promise": {
69
+ "types": "./dist/promise.d.ts",
70
+ "import": "./dist/promise.js",
71
+ "require": "./dist/promise.cjs"
72
+ },
68
73
  "./regex": {
69
74
  "types": "./dist/regex.d.ts",
70
75
  "import": "./dist/regex.js",
71
76
  "require": "./dist/regex.cjs"
77
+ },
78
+ "./string": {
79
+ "types": "./dist/string.d.ts",
80
+ "import": "./dist/string.js",
81
+ "require": "./dist/string.cjs"
72
82
  }
73
83
  },
74
84
  "scripts": {
@@ -77,6 +87,7 @@
77
87
  "format": "prettier . --write",
78
88
  "format-check": "prettier . --check",
79
89
  "lint": "eslint . --config eslint.config.js --cache",
90
+ "lint-fix": "eslint . --config eslint.config.js --cache --fix",
80
91
  "release": "pnpm run build && pnpm publish",
81
92
  "type-check": "tsc --noEmit",
82
93
  "update": "miho update major -t"