@lordicon/web 1.0.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/src/utils.ts ADDED
@@ -0,0 +1,100 @@
1
+ /**
2
+ * Deep clone value.
3
+ * @param value Value to clone.
4
+ */
5
+ export function deepClone<T = any>(value: T): T {
6
+ return structuredClone(value);
7
+ }
8
+
9
+ /**
10
+ * Checks if value is null or undefined.
11
+ * @param value Value to check.
12
+ * @returns True if value is null or undefined, false otherwise.
13
+ */
14
+ export function isNil(value: any) {
15
+ return value === null || value === undefined;
16
+ }
17
+
18
+ /**
19
+ * Checks if value is object like.
20
+ * @param value Value to check.
21
+ * @returns True if value is object like, false otherwise.
22
+ */
23
+ export function isObjectLike(value: any): value is object {
24
+ return value !== null && typeof value === "object";
25
+ }
26
+
27
+ /**
28
+ * Checks if path is a direct property of object.
29
+ * @param object Object to check.
30
+ * @param path Path to check.
31
+ */
32
+ export function has<T>(object: T, path: string | string[]): boolean {
33
+ const newPath = Array.isArray(path) ? path : path.split(".");
34
+ let current: any = object;
35
+
36
+ for (const key of newPath) {
37
+ if (!isObjectLike(current)) {
38
+ return false;
39
+ }
40
+
41
+ if (!(key in current)) {
42
+ return false;
43
+ }
44
+
45
+ current = (current as any)[key];
46
+ }
47
+
48
+ return true;
49
+ }
50
+
51
+ /**
52
+ * Retrieves the value at the given path from the object.
53
+ * Returns defaultValue if the path does not exist.
54
+ * @param object Object to get value from.
55
+ * @param path Property path as a dot-separated string or array of keys.
56
+ * @param defaultValue Value to return if the path does not exist.
57
+ * @returns Value at the given path or defaultValue.
58
+ */
59
+ export function get<T>(
60
+ object: T,
61
+ path: string | string[],
62
+ defaultValue?: any,
63
+ ): any {
64
+ const newPath = Array.isArray(path) ? path : path.split(".");
65
+ let current: any = object;
66
+
67
+ for (const key of newPath) {
68
+ if (!isObjectLike(current)) {
69
+ return defaultValue;
70
+ }
71
+
72
+ if (!(key in current)) {
73
+ return defaultValue;
74
+ }
75
+
76
+ current = (current as any)[key];
77
+ }
78
+
79
+ return current === undefined ? defaultValue : current;
80
+ }
81
+
82
+ /**
83
+ * Update object value on path.
84
+ * @param object Object to update.
85
+ * @param path Path to the value.
86
+ * @param value New value to set.
87
+ */
88
+ export function set(object: any, path: string | string[], value: any) {
89
+ let current = object;
90
+
91
+ const newPath = Array.isArray(path) ? path : path.split(".");
92
+
93
+ for (let i = 0; i < newPath.length; ++i) {
94
+ if (i === newPath.length - 1) {
95
+ current[newPath[i]] = value;
96
+ } else {
97
+ current = current[newPath[i]];
98
+ }
99
+ }
100
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,25 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "useDefineForClassFields": true,
5
+ "module": "ESNext",
6
+ "lib": ["ES2020", "DOM", "DOM.Iterable"],
7
+ "skipLibCheck": true,
8
+
9
+ /* Bundler mode */
10
+ "moduleResolution": "Bundler",
11
+ "allowImportingTsExtensions": true,
12
+ "isolatedModules": true,
13
+ "moduleDetection": "force",
14
+ "noEmit": true,
15
+
16
+ /* Linting */
17
+ "strict": true,
18
+ "noUnusedLocals": true,
19
+ "noUnusedParameters": true,
20
+ "noFallthroughCasesInSwitch": true,
21
+ "noUncheckedSideEffectImports": true
22
+ },
23
+ "include": ["./typings/**/*.d.ts", "./src/**/*.ts"],
24
+ "exclude": ["node_modules", "dist"]
25
+ }
@@ -0,0 +1,14 @@
1
+ import { defineConfig } from 'vite';
2
+
3
+ export default defineConfig({
4
+ build: {
5
+ rollupOptions: {
6
+ input: 'examples/index.html',
7
+ },
8
+ },
9
+ server: {
10
+ host: '0.0.0.0',
11
+ port: 8080,
12
+ },
13
+ root: 'examples',
14
+ });
package/vite.config.ts ADDED
@@ -0,0 +1,25 @@
1
+ import { resolve } from 'path';
2
+ import { defineConfig } from 'vite';
3
+ import dts from 'vite-plugin-dts';
4
+
5
+ export default defineConfig({
6
+ plugins: [
7
+ dts({
8
+ rollupTypes: true,
9
+ }),
10
+ ],
11
+ build: {
12
+ target: 'es2015',
13
+ lib: {
14
+ formats: ['es'],
15
+ fileName: () => 'index.js',
16
+ entry: resolve(__dirname, 'src', 'index.ts'),
17
+ },
18
+ rollupOptions: {
19
+ output: {
20
+ inlineDynamicImports: true,
21
+ },
22
+ },
23
+ emptyOutDir: true,
24
+ }
25
+ });