@bccampus/utils 0.2.0 → 0.2.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/chunk.cjs +9 -0
- package/dist/array/index.cjs +4 -0
- package/dist/date/index.cjs +8 -0
- package/dist/date/iso-date-time.cjs +256 -0
- package/dist/duration/add-durations.cjs +12 -0
- package/dist/duration/index.cjs +8 -0
- package/dist/duration/is-duration.cjs +7 -0
- package/dist/duration/to-number.cjs +14 -0
- package/dist/format/formatter.cjs +40 -0
- package/dist/format/index.cjs +13 -0
- package/dist/format/stringify.cjs +42 -0
- package/dist/format/template.cjs +35 -0
- package/dist/object/get.cjs +7 -0
- package/dist/object/index.cjs +12 -0
- package/dist/object/is-object.cjs +4 -0
- package/dist/object/omit.cjs +18 -0
- package/dist/object/pick.cjs +11 -0
- package/dist/object/set.cjs +14 -0
- package/dist/path/file-url-to-path.cjs +10 -0
- package/dist/path/index.cjs +6 -0
- package/dist/path/normalize.cjs +32 -0
- package/dist/set/difference.cjs +10 -0
- package/dist/set/index.cjs +12 -0
- package/dist/set/intersection.cjs +13 -0
- package/dist/set/is-superset.cjs +12 -0
- package/dist/set/symmetric-difference.cjs +14 -0
- package/dist/set/union.cjs +10 -0
- package/dist/string/capitalize.cjs +4 -0
- package/dist/string/index.cjs +14 -0
- package/dist/string/normalize.cjs +6 -0
- package/dist/string/pluralize/index.cjs +6 -0
- package/dist/string/pluralize/pluralize.cjs +210 -0
- package/dist/string/pluralize/rules/index.cjs +10 -0
- package/dist/string/pluralize/rules/irregular.cjs +62 -0
- package/dist/string/pluralize/rules/pluralization.cjs +39 -0
- package/dist/string/pluralize/rules/singularization.cjs +47 -0
- package/dist/string/pluralize/rules/uncountable.cjs +113 -0
- package/dist/string/pluralize/types.cjs +1 -0
- package/dist/string/slugify/index.cjs +2263 -0
- package/dist/string/strip-html-tags.cjs +7 -0
- package/dist/string/to-int.cjs +10 -0
- package/dist/string/to-sentence-case.cjs +8 -0
- package/dist/string/trim.cjs +11 -0
- package/dist/string/truncate.cjs +20 -0
- package/dist/value/index.cjs +4 -0
- package/dist/value/index.d.ts +1 -0
- package/dist/value/index.js +4 -0
- package/dist/value/is-empty.cjs +14 -0
- package/dist/value/is-empty.d.ts +17 -0
- package/dist/value/is-empty.js +14 -0
- package/package.json +26 -11
- package/src/format/index.ts +3 -3
- package/src/value/index.ts +1 -0
- package/src/value/is-empty.ts +31 -0
- package/vite.config.ts +75 -77
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
function stringToInt(value, fallback = 0) {
|
|
4
|
+
let returnValue = value;
|
|
5
|
+
if (typeof returnValue === "string")
|
|
6
|
+
returnValue = Number.parseInt(returnValue);
|
|
7
|
+
if (Number.isNaN(returnValue)) returnValue = fallback;
|
|
8
|
+
return returnValue;
|
|
9
|
+
}
|
|
10
|
+
exports.stringToInt = stringToInt;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const specialCharRegExp = /[\s-_.+]+/g;
|
|
4
|
+
const toSentenceCase = (s) => (s[0].toUpperCase() + s.slice(1).toLowerCase()).replace(
|
|
5
|
+
specialCharRegExp,
|
|
6
|
+
" "
|
|
7
|
+
);
|
|
8
|
+
exports.toSentenceCase = toSentenceCase;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
function trim(text, chars = " ") {
|
|
4
|
+
let start = 0;
|
|
5
|
+
let end = text.length;
|
|
6
|
+
if (!Array.isArray(chars)) chars = [chars];
|
|
7
|
+
while (start < end && chars.includes(text[start])) start += 1;
|
|
8
|
+
while (end > start && chars.includes(text[end - 1])) end -= 1;
|
|
9
|
+
return start > 0 || end < text.length ? text.substring(start, end) : text;
|
|
10
|
+
}
|
|
11
|
+
exports.trim = trim;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const defaultOptions = {
|
|
4
|
+
ending: "...",
|
|
5
|
+
maxlength: 100,
|
|
6
|
+
noWordBreak: false
|
|
7
|
+
};
|
|
8
|
+
function truncate(text, options) {
|
|
9
|
+
const conf = { ...defaultOptions, ...options };
|
|
10
|
+
text = text.trim();
|
|
11
|
+
if (conf.noWordBreak) {
|
|
12
|
+
const lastSpaceIndex = text.indexOf(" ", conf.maxlength);
|
|
13
|
+
if (lastSpaceIndex >= conf.maxlength)
|
|
14
|
+
return text.substring(0, lastSpaceIndex) + conf.ending;
|
|
15
|
+
} else if (text.length > conf.maxlength + conf.ending.length) {
|
|
16
|
+
return text.substring(0, conf.maxlength) + conf.ending;
|
|
17
|
+
}
|
|
18
|
+
return text;
|
|
19
|
+
}
|
|
20
|
+
exports.truncate = truncate;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './is-empty';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const isEmpty = (value) => {
|
|
4
|
+
if (value === void 0) return true;
|
|
5
|
+
if (value === null) return true;
|
|
6
|
+
if (typeof value === "string") return value.trim() === "";
|
|
7
|
+
if (typeof value === "object") {
|
|
8
|
+
if (Array.isArray(value) && value.length === 0) return true;
|
|
9
|
+
if (value instanceof Map || value instanceof Set) return value.size === 0;
|
|
10
|
+
return Object.keys(value).length === 0;
|
|
11
|
+
}
|
|
12
|
+
return false;
|
|
13
|
+
};
|
|
14
|
+
exports.isEmpty = isEmpty;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the value is `empty`
|
|
3
|
+
*
|
|
4
|
+
* returns `true`, if the value
|
|
5
|
+
*
|
|
6
|
+
* - `undefined`
|
|
7
|
+
* - `null`
|
|
8
|
+
* - `string` and there is no character in the string or all white space
|
|
9
|
+
* - `array` and there is no item in the array
|
|
10
|
+
* - `map` and there is no item in the map
|
|
11
|
+
* - `set` and there is no item in the set
|
|
12
|
+
* - `object` and there is no property in the object
|
|
13
|
+
*
|
|
14
|
+
* otherwise, false
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
export declare const isEmpty: (value: unknown) => boolean;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const isEmpty = (value) => {
|
|
2
|
+
if (value === void 0) return true;
|
|
3
|
+
if (value === null) return true;
|
|
4
|
+
if (typeof value === "string") return value.trim() === "";
|
|
5
|
+
if (typeof value === "object") {
|
|
6
|
+
if (Array.isArray(value) && value.length === 0) return true;
|
|
7
|
+
if (value instanceof Map || value instanceof Set) return value.size === 0;
|
|
8
|
+
return Object.keys(value).length === 0;
|
|
9
|
+
}
|
|
10
|
+
return false;
|
|
11
|
+
};
|
|
12
|
+
export {
|
|
13
|
+
isEmpty
|
|
14
|
+
};
|
package/package.json
CHANGED
|
@@ -1,49 +1,64 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bccampus/utils",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "BCcampus' utility box",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "UNLICENSED",
|
|
7
7
|
"exports": {
|
|
8
8
|
"./array": {
|
|
9
9
|
"types": "./dist/array/index.d.ts",
|
|
10
|
-
"import": "./dist/array/index.js"
|
|
10
|
+
"import": "./dist/array/index.js",
|
|
11
|
+
"require": "./dist/array/index.cjs"
|
|
11
12
|
},
|
|
12
13
|
"./date": {
|
|
13
14
|
"types": "./dist/date/index.d.ts",
|
|
14
|
-
"import": "./dist/date/index.js"
|
|
15
|
+
"import": "./dist/date/index.js",
|
|
16
|
+
"require": "./dist/date/index.cjs"
|
|
15
17
|
},
|
|
16
18
|
"./duration": {
|
|
17
19
|
"types": "./dist/duration/index.d.ts",
|
|
18
|
-
"import": "./dist/duration/index.js"
|
|
20
|
+
"import": "./dist/duration/index.js",
|
|
21
|
+
"require": "./dist/duration/index.cjs"
|
|
19
22
|
},
|
|
20
23
|
"./format": {
|
|
21
24
|
"types": "./dist/format/index.d.ts",
|
|
22
|
-
"import": "./dist/format/index.js"
|
|
25
|
+
"import": "./dist/format/index.js",
|
|
26
|
+
"require": "./dist/format/index.cjs"
|
|
23
27
|
},
|
|
24
28
|
"./object": {
|
|
25
29
|
"types": "./dist/object/index.d.ts",
|
|
26
|
-
"import": "./dist/object/index.js"
|
|
30
|
+
"import": "./dist/object/index.js",
|
|
31
|
+
"require": "./dist/object/index.cjs"
|
|
27
32
|
},
|
|
28
33
|
"./path": {
|
|
29
34
|
"types": "./dist/path/index.d.ts",
|
|
30
|
-
"import": "./dist/path/index.js"
|
|
35
|
+
"import": "./dist/path/index.js",
|
|
36
|
+
"require": "./dist/path/index.cjs"
|
|
31
37
|
},
|
|
32
38
|
"./set": {
|
|
33
39
|
"types": "./dist/set/index.d.ts",
|
|
34
|
-
"import": "./dist/set/index.js"
|
|
40
|
+
"import": "./dist/set/index.js",
|
|
41
|
+
"require": "./dist/set/index.cjs"
|
|
35
42
|
},
|
|
36
43
|
"./string": {
|
|
37
44
|
"types": "./dist/string/index.d.ts",
|
|
38
|
-
"import": "./dist/string/index.js"
|
|
45
|
+
"import": "./dist/string/index.js",
|
|
46
|
+
"require": "./dist/string/index.cjs"
|
|
39
47
|
},
|
|
40
48
|
"./string/pluralize": {
|
|
41
49
|
"types": "./dist/string/pluralize/index.d.ts",
|
|
42
|
-
"import": "./dist/string/pluralize/index.js"
|
|
50
|
+
"import": "./dist/string/pluralize/index.js",
|
|
51
|
+
"require": "./dist/string/pluralize/index.cjs"
|
|
43
52
|
},
|
|
44
53
|
"./string/slugify": {
|
|
45
54
|
"types": "./dist/string/slugify/index.d.ts",
|
|
46
|
-
"import": "./dist/string/slugify/index.js"
|
|
55
|
+
"import": "./dist/string/slugify/index.js",
|
|
56
|
+
"require": "./dist/string/slugify/index.cjs"
|
|
57
|
+
},
|
|
58
|
+
"./value": {
|
|
59
|
+
"types": "./dist/value/index.d.ts",
|
|
60
|
+
"import": "./dist/value/index.js",
|
|
61
|
+
"require": "./dist/value/index.cjs"
|
|
47
62
|
}
|
|
48
63
|
},
|
|
49
64
|
"packageManager": "yarn@4.15.0",
|
package/src/format/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from "./formatter";
|
|
2
|
-
export * from "./stringify";
|
|
3
|
-
export * from "./template";
|
|
1
|
+
export * from "./formatter";
|
|
2
|
+
export * from "./stringify";
|
|
3
|
+
export * from "./template";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./is-empty";
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks if the value is `empty`
|
|
3
|
+
*
|
|
4
|
+
* returns `true`, if the value
|
|
5
|
+
*
|
|
6
|
+
* - `undefined`
|
|
7
|
+
* - `null`
|
|
8
|
+
* - `string` and there is no character in the string or all white space
|
|
9
|
+
* - `array` and there is no item in the array
|
|
10
|
+
* - `map` and there is no item in the map
|
|
11
|
+
* - `set` and there is no item in the set
|
|
12
|
+
* - `object` and there is no property in the object
|
|
13
|
+
*
|
|
14
|
+
* otherwise, false
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
export const isEmpty = (value: unknown) => {
|
|
18
|
+
if (value === undefined) return true;
|
|
19
|
+
if (value === null) return true;
|
|
20
|
+
|
|
21
|
+
if (typeof value === "string") return value.trim() === "";
|
|
22
|
+
if (typeof value === "object") {
|
|
23
|
+
if (Array.isArray(value) && value.length === 0) return true;
|
|
24
|
+
|
|
25
|
+
if (value instanceof Map || value instanceof Set) return value.size === 0;
|
|
26
|
+
|
|
27
|
+
return Object.keys(value).length === 0;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return false;
|
|
31
|
+
};
|
package/vite.config.ts
CHANGED
|
@@ -1,77 +1,75 @@
|
|
|
1
|
-
import path from "node:path";
|
|
2
|
-
import { fileURLToPath } from "node:url";
|
|
3
|
-
import { globSync } from "tinyglobby";
|
|
4
|
-
import { defineConfig } from "vite";
|
|
5
|
-
import dts from "vite-plugin-dts";
|
|
6
|
-
import packageConfig from "./package.json";
|
|
7
|
-
import { writeFileSync } from "node:fs";
|
|
8
|
-
|
|
9
|
-
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
10
|
-
const outDir = "./dist";
|
|
11
|
-
|
|
12
|
-
const createEntries = () => {
|
|
13
|
-
const entries = new Map<string, string>();
|
|
14
|
-
const exports = new Map<
|
|
15
|
-
string,
|
|
16
|
-
{
|
|
17
|
-
types: string;
|
|
18
|
-
import: string;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
},
|
|
77
|
-
});
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import { globSync } from "tinyglobby";
|
|
4
|
+
import { defineConfig } from "vite";
|
|
5
|
+
import dts from "vite-plugin-dts";
|
|
6
|
+
import packageConfig from "./package.json";
|
|
7
|
+
import { writeFileSync } from "node:fs";
|
|
8
|
+
|
|
9
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
10
|
+
const outDir = "./dist";
|
|
11
|
+
|
|
12
|
+
const createEntries = () => {
|
|
13
|
+
const entries = new Map<string, string>();
|
|
14
|
+
const exports = new Map<
|
|
15
|
+
string,
|
|
16
|
+
{
|
|
17
|
+
types: string;
|
|
18
|
+
import: string;
|
|
19
|
+
require: string;
|
|
20
|
+
}
|
|
21
|
+
>();
|
|
22
|
+
|
|
23
|
+
const files = globSync("src/**/*.ts", {
|
|
24
|
+
cwd: __dirname,
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
for (const file of files) {
|
|
28
|
+
const filePath = file.split(".")[0].replace(/^src[/\\]/, "");
|
|
29
|
+
|
|
30
|
+
if (!filePath) {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const filePathParts = filePath.split("/");
|
|
35
|
+
if (filePathParts.at(-1) === "index" && filePathParts.length <= 3) {
|
|
36
|
+
const exportPath = filePathParts.length === 1 ? "." : `./${filePathParts.slice(0, -1).join("/")}`;
|
|
37
|
+
|
|
38
|
+
exports.set(exportPath, {
|
|
39
|
+
types: `${outDir}/${filePath}.d.ts`,
|
|
40
|
+
import: `${outDir}/${filePath}.js`,
|
|
41
|
+
require: `${outDir}/${filePath}.cjs`,
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
entries.set(filePath, fileURLToPath(new URL(file, import.meta.url)));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const _packageConfig = {
|
|
49
|
+
...packageConfig,
|
|
50
|
+
exports: Object.fromEntries(exports),
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
writeFileSync("./package.json", JSON.stringify(_packageConfig, null, 2), {
|
|
54
|
+
encoding: "utf-8",
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
return Object.fromEntries(entries);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export default defineConfig({
|
|
61
|
+
plugins: [dts({ tsconfigPath: "./tsconfig.lib.json" })],
|
|
62
|
+
resolve: {
|
|
63
|
+
alias: {
|
|
64
|
+
"@": path.resolve(__dirname, "./src"),
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
build: {
|
|
68
|
+
minify: false,
|
|
69
|
+
copyPublicDir: false,
|
|
70
|
+
lib: {
|
|
71
|
+
entry: createEntries(),
|
|
72
|
+
name: "utils",
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
});
|