@tb-dev/utils 1.1.3 → 1.1.5
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 +32 -37
- package/dist/index.js +50 -0
- package/package.json +13 -15
- package/dist/index.mjs +0 -46
package/dist/index.cjs
CHANGED
|
@@ -1,52 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
5
3
|
function splitWhitespace(value) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
if (!value)
|
|
5
|
+
return [];
|
|
6
|
+
if (Array.isArray(value)) {
|
|
7
|
+
const array = value.map((i) => splitWhitespace(i));
|
|
8
|
+
return array.flat(Number.POSITIVE_INFINITY);
|
|
9
|
+
}
|
|
10
|
+
value = value.trim().split(/\s/);
|
|
11
|
+
return trimArray(value);
|
|
14
12
|
}
|
|
15
13
|
function toArray(item) {
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
const array = item ?? [];
|
|
15
|
+
return Array.isArray(array) ? array : [array];
|
|
18
16
|
}
|
|
19
17
|
function trimArray(array) {
|
|
20
|
-
|
|
18
|
+
return array.map((i) => i.trim()).filter(Boolean);
|
|
21
19
|
}
|
|
22
|
-
|
|
23
20
|
function isEmpty(value) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
21
|
+
if (Array.isArray(value) || typeof value === "string") {
|
|
22
|
+
return value.length === 0;
|
|
23
|
+
}
|
|
24
|
+
if (value instanceof Map || value instanceof Set) {
|
|
25
|
+
return value.size === 0;
|
|
26
|
+
}
|
|
27
|
+
return true;
|
|
31
28
|
}
|
|
32
29
|
function repeat(amount, fn) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
30
|
+
let n = Math.trunc(amount);
|
|
31
|
+
if (n < 1) {
|
|
32
|
+
n = 0;
|
|
33
|
+
} else if (n > Number.MAX_SAFE_INTEGER) {
|
|
34
|
+
n = Number.MAX_SAFE_INTEGER;
|
|
35
|
+
}
|
|
36
|
+
for (let i = 0; i < n; i++) {
|
|
37
|
+
fn(i);
|
|
38
|
+
}
|
|
43
39
|
}
|
|
44
40
|
function toPixel(value) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
41
|
+
if (typeof value === "string")
|
|
42
|
+
return value;
|
|
43
|
+
return `${value}px`;
|
|
48
44
|
}
|
|
49
|
-
|
|
50
45
|
exports.isEmpty = isEmpty;
|
|
51
46
|
exports.repeat = repeat;
|
|
52
47
|
exports.splitWhitespace = splitWhitespace;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
function isEmpty(value) {
|
|
19
|
+
if (Array.isArray(value) || typeof value === "string") {
|
|
20
|
+
return value.length === 0;
|
|
21
|
+
}
|
|
22
|
+
if (value instanceof Map || value instanceof Set) {
|
|
23
|
+
return value.size === 0;
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
function repeat(amount, fn) {
|
|
28
|
+
let n = Math.trunc(amount);
|
|
29
|
+
if (n < 1) {
|
|
30
|
+
n = 0;
|
|
31
|
+
} else if (n > Number.MAX_SAFE_INTEGER) {
|
|
32
|
+
n = Number.MAX_SAFE_INTEGER;
|
|
33
|
+
}
|
|
34
|
+
for (let i = 0; i < n; i++) {
|
|
35
|
+
fn(i);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function toPixel(value) {
|
|
39
|
+
if (typeof value === "string")
|
|
40
|
+
return value;
|
|
41
|
+
return `${value}px`;
|
|
42
|
+
}
|
|
43
|
+
export {
|
|
44
|
+
isEmpty,
|
|
45
|
+
repeat,
|
|
46
|
+
splitWhitespace,
|
|
47
|
+
toArray,
|
|
48
|
+
toPixel,
|
|
49
|
+
trimArray
|
|
50
|
+
};
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tb-dev/utils",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"description": "TypeScript utils",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"private": false,
|
|
8
|
-
"packageManager": "pnpm@8.14.
|
|
8
|
+
"packageManager": "pnpm@8.14.1",
|
|
9
9
|
"homepage": "https://tb.dev.br/utils/",
|
|
10
10
|
"author": {
|
|
11
11
|
"name": "Andrew Ferreira",
|
|
@@ -25,49 +25,47 @@
|
|
|
25
25
|
],
|
|
26
26
|
"lint-staged": {
|
|
27
27
|
"*.{?(c|m)@(j|t)s,css,vue,md,json}": "prettier --write",
|
|
28
|
-
"*.{?(c|m)@(j|t)s,vue}": "pnpm lint"
|
|
28
|
+
"*.{?(c|m)@(j|t)s,vue}": "pnpm run lint"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@tb-dev/utility-types": "^1.0.
|
|
31
|
+
"@tb-dev/utility-types": "^1.0.10"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@
|
|
35
|
-
"@
|
|
36
|
-
"@types/node": "^20.10.7",
|
|
34
|
+
"@tb-dev/eslint-config": "^1.6.2",
|
|
35
|
+
"@types/node": "^20.11.5",
|
|
37
36
|
"eslint": "^8.56.0",
|
|
38
37
|
"husky": "^8.0.3",
|
|
39
38
|
"lint-staged": "^15.2.0",
|
|
40
|
-
"prettier": "^3.
|
|
41
|
-
"rollup": "^4.9.4",
|
|
39
|
+
"prettier": "^3.2.4",
|
|
42
40
|
"taze": "^0.13.1",
|
|
43
41
|
"tslib": "^2.6.2",
|
|
44
42
|
"typedoc": "^0.25.7",
|
|
45
|
-
"typedoc-plugin-mdn-links": "^3.1.
|
|
43
|
+
"typedoc-plugin-mdn-links": "^3.1.12",
|
|
46
44
|
"typescript": "5.3.3",
|
|
47
45
|
"vite": "^5.0.11",
|
|
48
|
-
"vite-plugin-dts": "^3.7.
|
|
46
|
+
"vite-plugin-dts": "^3.7.1"
|
|
49
47
|
},
|
|
50
48
|
"files": [
|
|
51
49
|
"dist"
|
|
52
50
|
],
|
|
53
51
|
"main": "./dist/index.cjs",
|
|
54
|
-
"module": "./dist/index.
|
|
52
|
+
"module": "./dist/index.js",
|
|
55
53
|
"types": "./dist/index.d.ts",
|
|
56
54
|
"exports": {
|
|
57
55
|
".": {
|
|
58
56
|
"types": "./dist/index.d.ts",
|
|
59
|
-
"import": "./dist/index.
|
|
57
|
+
"import": "./dist/index.js",
|
|
60
58
|
"require": "./dist/index.cjs"
|
|
61
59
|
}
|
|
62
60
|
},
|
|
63
61
|
"scripts": {
|
|
64
|
-
"build": "
|
|
62
|
+
"build": "vite build",
|
|
65
63
|
"bump": "miho bump -k -a .",
|
|
66
64
|
"docs": "typedoc --plugin typedoc-plugin-mdn-links",
|
|
67
65
|
"format": "prettier . --write",
|
|
68
66
|
"format-check": "prettier . --check",
|
|
69
67
|
"lint": "eslint . --config eslint.config.js --cache",
|
|
70
|
-
"release": "
|
|
68
|
+
"release": "pnpm run build && pnpm run bump && pnpm publish",
|
|
71
69
|
"type-check": "tsc --noEmit"
|
|
72
70
|
}
|
|
73
71
|
}
|
package/dist/index.mjs
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
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
|
-
|
|
19
|
-
function isEmpty(value) {
|
|
20
|
-
if (Array.isArray(value) || typeof value === 'string') {
|
|
21
|
-
return value.length === 0;
|
|
22
|
-
}
|
|
23
|
-
if (value instanceof Map || value instanceof Set) {
|
|
24
|
-
return value.size === 0;
|
|
25
|
-
}
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
function repeat(amount, fn) {
|
|
29
|
-
let n = Math.trunc(amount);
|
|
30
|
-
if (n < 1) {
|
|
31
|
-
n = 0;
|
|
32
|
-
}
|
|
33
|
-
else if (n > Number.MAX_SAFE_INTEGER) {
|
|
34
|
-
n = Number.MAX_SAFE_INTEGER;
|
|
35
|
-
}
|
|
36
|
-
for (let i = 0; i < n; i++) {
|
|
37
|
-
fn(i);
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
function toPixel(value) {
|
|
41
|
-
if (typeof value === 'string')
|
|
42
|
-
return value;
|
|
43
|
-
return `${value}px`;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export { isEmpty, repeat, splitWhitespace, toArray, toPixel, trimArray };
|