@ryupold/vode 0.9.3 → 0.9.4
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/.github/workflows/npm-publish.yml +24 -23
- package/LICENSE +21 -21
- package/README.md +126 -126
- package/index.ts +3 -5
- package/package.json +6 -3
- package/src/html.ts +37 -37
- package/src/vode-tags.ts +206 -206
- package/src/vode.ts +693 -693
- package/tsconfig.json +30 -28
- package/index.js +0 -6
- package/src/api-call.ts +0 -116
- package/src/helpers.ts +0 -44
- package/src/style.ts +0 -17
package/tsconfig.json
CHANGED
|
@@ -1,29 +1,31 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "es2024",
|
|
4
|
-
"module": "preserve",
|
|
5
|
-
"moduleResolution": "bundler",
|
|
6
|
-
"rootDir": ".",
|
|
7
|
-
"composite": true,
|
|
8
|
-
"declarationMap": true,
|
|
9
|
-
"removeComments": true,
|
|
10
|
-
"declaration": true,
|
|
11
|
-
"inlineSourceMap": true,
|
|
12
|
-
"strict": true,
|
|
13
|
-
"allowSyntheticDefaultImports": true,
|
|
14
|
-
"strictBindCallApply": true,
|
|
15
|
-
"strictFunctionTypes": true,
|
|
16
|
-
"strictPropertyInitialization": true,
|
|
17
|
-
"strictNullChecks": true,
|
|
18
|
-
"allowJs": false,
|
|
19
|
-
"skipLibCheck": true,
|
|
20
|
-
"noImplicitReturns": true,
|
|
21
|
-
"noFallthroughCasesInSwitch": true,
|
|
22
|
-
"downlevelIteration": true,
|
|
23
|
-
"isolatedModules": true
|
|
24
|
-
},
|
|
25
|
-
"include": [
|
|
26
|
-
"./index.ts",
|
|
27
|
-
"./src
|
|
28
|
-
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2024",
|
|
4
|
+
"module": "preserve",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"rootDir": ".",
|
|
7
|
+
"composite": true,
|
|
8
|
+
"declarationMap": true,
|
|
9
|
+
"removeComments": true,
|
|
10
|
+
"declaration": true,
|
|
11
|
+
"inlineSourceMap": true,
|
|
12
|
+
"strict": true,
|
|
13
|
+
"allowSyntheticDefaultImports": true,
|
|
14
|
+
"strictBindCallApply": true,
|
|
15
|
+
"strictFunctionTypes": true,
|
|
16
|
+
"strictPropertyInitialization": true,
|
|
17
|
+
"strictNullChecks": true,
|
|
18
|
+
"allowJs": false,
|
|
19
|
+
"skipLibCheck": true,
|
|
20
|
+
"noImplicitReturns": true,
|
|
21
|
+
"noFallthroughCasesInSwitch": true,
|
|
22
|
+
"downlevelIteration": true,
|
|
23
|
+
"isolatedModules": true
|
|
24
|
+
},
|
|
25
|
+
"include": [
|
|
26
|
+
"./index.ts",
|
|
27
|
+
"./src/vode.ts",
|
|
28
|
+
"./src/vode-tags.ts",
|
|
29
|
+
"./src/html.ts",
|
|
30
|
+
]
|
|
29
31
|
}
|
package/index.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export * from "./src/vode.js";
|
|
2
|
-
export * from "./src/vode-tags.js";
|
|
3
|
-
export * from "./src/api-call.js";
|
|
4
|
-
export * from "./src/html.js";
|
|
5
|
-
export * from "./src/helpers.js";
|
|
6
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyJpbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSxjQUFjLGVBQWUsQ0FBQztBQUM5QixjQUFjLG9CQUFvQixDQUFDO0FBQ25DLGNBQWMsbUJBQW1CLENBQUM7QUFDbEMsY0FBYyxlQUFlLENBQUM7QUFDOUIsY0FBYyxrQkFBa0IsQ0FBQyJ9
|
package/src/api-call.ts
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import { Dispatch, Effect } from "./vode.js";
|
|
2
|
-
|
|
3
|
-
export const aborted = new Error("aborted");
|
|
4
|
-
|
|
5
|
-
export const metricDefaults = () => ({
|
|
6
|
-
metrics: {
|
|
7
|
-
requestCount: 0,
|
|
8
|
-
download: 0,
|
|
9
|
-
upload: 0,
|
|
10
|
-
},
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Make HTTP Request
|
|
16
|
-
* @param {ApiCallOptions} options
|
|
17
|
-
* @param {Dispatch?} dispatch
|
|
18
|
-
* @returns {Promise<any>} promise wrapping the http request resolving in the response if status < 400, otherwise rejecting with the response
|
|
19
|
-
*/
|
|
20
|
-
export function httpRequest<S extends object | unknown>(options: {
|
|
21
|
-
url: string,
|
|
22
|
-
method: string,
|
|
23
|
-
headers?: Record<string, string>,
|
|
24
|
-
data?: any,
|
|
25
|
-
timeout?: number,
|
|
26
|
-
withCredentials?: boolean,
|
|
27
|
-
metrics?: {
|
|
28
|
-
requestCount: number,
|
|
29
|
-
download: number,
|
|
30
|
-
upload: number,
|
|
31
|
-
},
|
|
32
|
-
}, dispatch?: {
|
|
33
|
-
patch: Dispatch<S>,
|
|
34
|
-
action?: Effect<S>,
|
|
35
|
-
abortAction?: Effect<S>,
|
|
36
|
-
errAction?: Effect<S>,
|
|
37
|
-
progressAction?: Effect<S>,
|
|
38
|
-
uploadProgressAction?: Effect<S>
|
|
39
|
-
}): Promise<any> & { abort: () => void } {
|
|
40
|
-
const xhr = new XMLHttpRequest();
|
|
41
|
-
const promise = new Promise((resolve, reject) => {
|
|
42
|
-
if (!options.metrics) options.metrics = metricDefaults().metrics;
|
|
43
|
-
if (options.metrics) options.metrics.requestCount++;
|
|
44
|
-
|
|
45
|
-
xhr.withCredentials = options.withCredentials === undefined || options.withCredentials;
|
|
46
|
-
if (options.timeout) xhr.timeout = options.timeout;
|
|
47
|
-
|
|
48
|
-
xhr.addEventListener("timeout", (err) => {
|
|
49
|
-
reject(err || new Error("timeout"));
|
|
50
|
-
if (dispatch?.errAction) {
|
|
51
|
-
dispatch.patch([dispatch.errAction, err]);
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
if (dispatch?.uploadProgressAction) {
|
|
56
|
-
xhr.upload.addEventListener("progress", (event) => {
|
|
57
|
-
if (event.lengthComputable) {
|
|
58
|
-
if (options.metrics && event.loaded) options.metrics.upload += event.loaded;
|
|
59
|
-
dispatch.patch([dispatch.uploadProgressAction,
|
|
60
|
-
{ loaded: event.loaded, total: event.total }]);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if (dispatch?.progressAction) {
|
|
66
|
-
xhr.addEventListener("progress", (event) => {
|
|
67
|
-
console.log("progress", event);
|
|
68
|
-
if (event.lengthComputable) {
|
|
69
|
-
if (options.metrics && event.loaded) options.metrics.download += event.loaded;
|
|
70
|
-
dispatch.patch([dispatch.progressAction, event]);
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
xhr.addEventListener("loadend", (e: ProgressEvent<XMLHttpRequestEventTarget>) => {
|
|
76
|
-
if (xhr.readyState === 4) {
|
|
77
|
-
if (options.metrics && (e.loaded)) {
|
|
78
|
-
options.metrics.download += e.loaded;
|
|
79
|
-
}
|
|
80
|
-
if (xhr.status < 400) {
|
|
81
|
-
resolve(xhr.response);
|
|
82
|
-
dispatch?.action && dispatch.patch(<Effect<S>>[dispatch.action, xhr.response]);
|
|
83
|
-
}
|
|
84
|
-
else {
|
|
85
|
-
reject({ status: xhr.status, statusText: xhr.statusText, response: xhr.response });
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
xhr.addEventListener("abort", () => {
|
|
93
|
-
reject(aborted);
|
|
94
|
-
if (dispatch?.abortAction) {
|
|
95
|
-
dispatch.patch([dispatch.abortAction, aborted]);
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
xhr.addEventListener("error", (err) => {
|
|
100
|
-
reject(err);
|
|
101
|
-
if (dispatch?.errAction) {
|
|
102
|
-
dispatch.patch([dispatch.errAction, err]);
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
xhr.open(options.method, options.url, true);
|
|
107
|
-
if (options.headers) {
|
|
108
|
-
for (const key in options.headers) {
|
|
109
|
-
xhr.setRequestHeader(key, options.headers[key]);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
xhr.send(options.data);
|
|
113
|
-
});
|
|
114
|
-
(<any>promise).abort = () => xhr.abort();
|
|
115
|
-
return <any>promise;
|
|
116
|
-
}
|
package/src/helpers.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { DeepPartial } from "./vode.js";
|
|
2
|
-
|
|
3
|
-
type KeyPath<ObjectType extends object> =
|
|
4
|
-
{ [Key in keyof ObjectType & (string | number)]: ObjectType[Key] extends object
|
|
5
|
-
? `${Key}` | `${Key}.${KeyPath<ObjectType[Key]>}`
|
|
6
|
-
: `${Key}`
|
|
7
|
-
}[keyof ObjectType & (string | number)];
|
|
8
|
-
|
|
9
|
-
/** put a value deep inside an object addressed by a key path (creating necessary structure on the way). if target is null, a new object is created */
|
|
10
|
-
export function put<O extends object | unknown>(keyPath: O extends object ? KeyPath<O> : string, value: any = undefined, target: DeepPartial<O> | null = null) {
|
|
11
|
-
if (!target) target = {} as O as any;
|
|
12
|
-
|
|
13
|
-
const keys = keyPath.split('.');
|
|
14
|
-
if (keys.length > 1) {
|
|
15
|
-
let i = 0;
|
|
16
|
-
let raw = (<any>target)[keys[i]];
|
|
17
|
-
if (raw === undefined) {
|
|
18
|
-
(<any>target)[keys[i]] = raw = {};
|
|
19
|
-
}
|
|
20
|
-
for (i = 1; i < keys.length - 1; i++) {
|
|
21
|
-
const p = raw;
|
|
22
|
-
raw = raw[keys[i]];
|
|
23
|
-
if (raw === undefined) {
|
|
24
|
-
raw = {};
|
|
25
|
-
p[keys[i]] = raw;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
if (keys[i] === undefined) console.log(keyPath);
|
|
29
|
-
raw[keys[i]] = value;
|
|
30
|
-
} else {
|
|
31
|
-
(<any>target)[keys[0]] = value;
|
|
32
|
-
}
|
|
33
|
-
return target
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/** get a value deep inside an object by its key path */
|
|
37
|
-
export function get<O extends object | unknown>(keyPath: O extends object ? KeyPath<O> : string, source: DeepPartial<O>) {
|
|
38
|
-
const keys = keyPath.split('.');
|
|
39
|
-
let raw = source ? (<any>source)[keys[0]] : undefined;
|
|
40
|
-
for (let i = 1; i < keys.length && !!raw; i++) {
|
|
41
|
-
raw = raw[keys[i]];
|
|
42
|
-
}
|
|
43
|
-
return raw;
|
|
44
|
-
}
|
package/src/style.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { StyleProp } from "./vode.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
function generateCSS(style: StyleProp) {
|
|
5
|
-
let css = '';
|
|
6
|
-
for (const key in style) {
|
|
7
|
-
const value = style[key];
|
|
8
|
-
//transform camelCase to kebab-case
|
|
9
|
-
const kebab = key.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2').toLowerCase();
|
|
10
|
-
css += `${kebab}:${value};`;
|
|
11
|
-
}
|
|
12
|
-
return css;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function keyToKebab(key: string) : string {
|
|
16
|
-
return key.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2').toLowerCase();
|
|
17
|
-
}
|