@tb-dev/utils 1.1.0 → 1.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/dist/index.cjs CHANGED
@@ -2,6 +2,24 @@
2
2
 
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
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 toArray(item) {
16
+ const array = item ?? [];
17
+ return Array.isArray(array) ? array : [array];
18
+ }
19
+ function trimArray(array) {
20
+ return array.map((i) => i.trim()).filter(Boolean);
21
+ }
22
+
5
23
  function isEmpty(value) {
6
24
  if (Array.isArray(value) || typeof value === 'string') {
7
25
  return value.length === 0;
@@ -23,10 +41,6 @@ function repeat(amount, fn) {
23
41
  fn(i);
24
42
  }
25
43
  }
26
- function toArray(item) {
27
- const array = item ?? [];
28
- return Array.isArray(array) ? array : [array];
29
- }
30
44
  function toPixel(value) {
31
45
  if (typeof value === 'string')
32
46
  return value;
@@ -35,5 +49,7 @@ function toPixel(value) {
35
49
 
36
50
  exports.isEmpty = isEmpty;
37
51
  exports.repeat = repeat;
52
+ exports.splitWhitespace = splitWhitespace;
38
53
  exports.toArray = toArray;
39
54
  exports.toPixel = toPixel;
55
+ exports.trimArray = trimArray;
package/dist/index.d.ts CHANGED
@@ -11,8 +11,12 @@ export declare function isEmpty<K, V>(value?: Nullish<Map<K, V>>): boolean;
11
11
 
12
12
  export declare function repeat(amount: number, fn: (current: number) => void): void;
13
13
 
14
+ export declare function splitWhitespace(value: Nullish<string | string[]>): string[];
15
+
14
16
  export declare function toArray<T>(item?: Nullish<MaybeArray<T>>): T[];
15
17
 
16
18
  export declare function toPixel(value: string | number): string;
17
19
 
20
+ export declare function trimArray(array: string[]): string[];
21
+
18
22
  export { }
package/dist/index.mjs CHANGED
@@ -1,3 +1,21 @@
1
+ function splitWhitespace(value) {
2
+ if (!value)
3
+ return [];
4
+ if (Array.isArray(value)) {
5
+ const array = value.map((i) => splitWhitespace(i));
6
+ return array.flat(Number.POSITIVE_INFINITY);
7
+ }
8
+ value = value.trim().split(/\s/);
9
+ return trimArray(value);
10
+ }
11
+ function toArray(item) {
12
+ const array = item ?? [];
13
+ return Array.isArray(array) ? array : [array];
14
+ }
15
+ function trimArray(array) {
16
+ return array.map((i) => i.trim()).filter(Boolean);
17
+ }
18
+
1
19
  function isEmpty(value) {
2
20
  if (Array.isArray(value) || typeof value === 'string') {
3
21
  return value.length === 0;
@@ -19,14 +37,10 @@ function repeat(amount, fn) {
19
37
  fn(i);
20
38
  }
21
39
  }
22
- function toArray(item) {
23
- const array = item ?? [];
24
- return Array.isArray(array) ? array : [array];
25
- }
26
40
  function toPixel(value) {
27
41
  if (typeof value === 'string')
28
42
  return value;
29
43
  return `${value}px`;
30
44
  }
31
45
 
32
- export { isEmpty, repeat, toArray, toPixel };
46
+ export { isEmpty, repeat, splitWhitespace, toArray, toPixel, trimArray };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tb-dev/utils",
3
- "version": "1.1.0",
3
+ "version": "1.1.3",
4
4
  "description": "TypeScript utils",
5
5
  "license": "MIT",
6
6
  "type": "module",