@tb-dev/utils 1.6.0 → 1.7.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/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,8 @@ 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
+ const string = require("./string.cjs");
7
+ const promise = require("./promise.cjs");
6
8
  function isEmpty(value) {
7
9
  if (isNullish(value)) {
8
10
  return true;
@@ -27,7 +29,6 @@ function toPixel(value) {
27
29
  return value;
28
30
  }
29
31
  exports.regex = regex.regex;
30
- exports.splitWhitespace = array.splitWhitespace;
31
32
  exports.toArray = array.toArray;
32
33
  exports.trimArray = array.trimArray;
33
34
  exports.upsert = array.upsert;
@@ -35,6 +36,9 @@ exports.panic = panic.panic;
35
36
  exports.todo = panic.todo;
36
37
  exports.unimplemented = panic.unimplemented;
37
38
  exports.unreachable = panic.unreachable;
39
+ exports.splitWhitespace = string.splitWhitespace;
40
+ exports.flush = promise.flush;
41
+ exports.sleep = promise.sleep;
38
42
  exports.isEmpty = isEmpty;
39
43
  exports.isNullish = isNullish;
40
44
  exports.noop = noop;
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,8 @@
1
1
  import { regex } from "./regex.js";
2
- import { splitWhitespace, toArray, trimArray, upsert } from "./array.js";
2
+ import { toArray, trimArray, upsert } from "./array.js";
3
3
  import { panic, todo, unimplemented, unreachable } from "./panic.js";
4
+ import { splitWhitespace } from "./string.js";
5
+ import { flush, sleep } from "./promise.js";
4
6
  function isEmpty(value) {
5
7
  if (isNullish(value)) {
6
8
  return true;
@@ -25,11 +27,13 @@ function toPixel(value) {
25
27
  return value;
26
28
  }
27
29
  export {
30
+ flush,
28
31
  isEmpty,
29
32
  isNullish,
30
33
  noop,
31
34
  panic,
32
35
  regex,
36
+ sleep,
33
37
  splitWhitespace,
34
38
  toArray,
35
39
  toPixel,
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ function flush() {
4
+ return new Promise((resolve) => void setTimeout(resolve, 0));
5
+ }
6
+ function sleep(ms) {
7
+ return new Promise((resolve) => void setTimeout(resolve, ms));
8
+ }
9
+ exports.flush = flush;
10
+ exports.sleep = sleep;
@@ -0,0 +1,2 @@
1
+ export declare function flush(): Promise<void>;
2
+ export declare function sleep(ms: number): Promise<void>;
@@ -0,0 +1,10 @@
1
+ function flush() {
2
+ return new Promise((resolve) => void setTimeout(resolve, 0));
3
+ }
4
+ function sleep(ms) {
5
+ return new Promise((resolve) => void setTimeout(resolve, ms));
6
+ }
7
+ export {
8
+ flush,
9
+ sleep
10
+ };
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const array = require("./array.cjs");
4
+ function splitWhitespace(value) {
5
+ if (!value)
6
+ return [];
7
+ if (Array.isArray(value)) {
8
+ const array2 = value.map((i) => splitWhitespace(i));
9
+ return array2.flat(Number.POSITIVE_INFINITY);
10
+ }
11
+ value = value.trim().split(/\s/);
12
+ return array.trimArray(value);
13
+ }
14
+ exports.splitWhitespace = splitWhitespace;
@@ -0,0 +1,3 @@
1
+ import { Nullish } from '@tb-dev/utility-types';
2
+
3
+ export declare function splitWhitespace(value: Nullish<string | string[]>): string[];
package/dist/string.js ADDED
@@ -0,0 +1,14 @@
1
+ import { trimArray } from "./array.js";
2
+ function splitWhitespace(value) {
3
+ if (!value)
4
+ return [];
5
+ if (Array.isArray(value)) {
6
+ const array = value.map((i) => splitWhitespace(i));
7
+ return array.flat(Number.POSITIVE_INFINITY);
8
+ }
9
+ value = value.trim().split(/\s/);
10
+ return trimArray(value);
11
+ }
12
+ export {
13
+ splitWhitespace
14
+ };
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.1",
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"