@taybart/corvid 0.0.6 → 0.0.7
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/dom.d.ts +1 -9
- package/dist/index.js +41 -39
- package/dist/network.d.ts +23 -11
- package/package.json +1 -1
package/dist/dom.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ type elOpts = {
|
|
|
16
16
|
};
|
|
17
17
|
export declare class el {
|
|
18
18
|
el: HTMLElement | null;
|
|
19
|
-
|
|
19
|
+
query: string;
|
|
20
20
|
constructor(opts: string | elOpts);
|
|
21
21
|
/*** get ***/
|
|
22
22
|
value(): string;
|
|
@@ -34,12 +34,4 @@ export declare class el {
|
|
|
34
34
|
listen(event: string, cb: (ev: Event) => void): this;
|
|
35
35
|
onClick(cb: (ev: Event) => void): this;
|
|
36
36
|
}
|
|
37
|
-
/*** url params ***/
|
|
38
|
-
export declare class params {
|
|
39
|
-
params: URLSearchParams;
|
|
40
|
-
constructor(p?: Object);
|
|
41
|
-
set(p: Object): this;
|
|
42
|
-
toString(): string;
|
|
43
|
-
static render(p: Object): string;
|
|
44
|
-
}
|
|
45
37
|
export {};
|
package/dist/index.js
CHANGED
|
@@ -24,7 +24,6 @@ var dom_namespaceObject = {};
|
|
|
24
24
|
__webpack_require__.r(dom_namespaceObject);
|
|
25
25
|
__webpack_require__.d(dom_namespaceObject, {
|
|
26
26
|
el: ()=>el,
|
|
27
|
-
params: ()=>dom_params,
|
|
28
27
|
ready: ()=>ready
|
|
29
28
|
});
|
|
30
29
|
var style_namespaceObject = {};
|
|
@@ -39,6 +38,7 @@ __webpack_require__.d(style_namespaceObject, {
|
|
|
39
38
|
var network_namespaceObject = {};
|
|
40
39
|
__webpack_require__.r(network_namespaceObject);
|
|
41
40
|
__webpack_require__.d(network_namespaceObject, {
|
|
41
|
+
params: ()=>network_params,
|
|
42
42
|
request: ()=>request
|
|
43
43
|
});
|
|
44
44
|
var local_storage_namespaceObject = {};
|
|
@@ -67,18 +67,18 @@ class el {
|
|
|
67
67
|
return '';
|
|
68
68
|
}
|
|
69
69
|
parent(parent) {
|
|
70
|
-
if (!this.el) throw new Error(`no element from
|
|
70
|
+
if (!this.el) throw new Error(`no element from query: ${this.query}`);
|
|
71
71
|
parent.appendChild(this.el);
|
|
72
72
|
return this;
|
|
73
73
|
}
|
|
74
74
|
child(ch) {
|
|
75
75
|
var _this_el;
|
|
76
|
-
if (!this.el) throw new Error(`no element from
|
|
76
|
+
if (!this.el) throw new Error(`no element from query: ${this.query}`);
|
|
77
77
|
null == (_this_el = this.el) || _this_el.appendChild(ch);
|
|
78
78
|
return this;
|
|
79
79
|
}
|
|
80
80
|
inner(content, { force = false, text = false } = {}) {
|
|
81
|
-
if (!this.el) throw new Error(`no element from
|
|
81
|
+
if (!this.el) throw new Error(`no element from query: ${this.query}`);
|
|
82
82
|
if (this.el instanceof HTMLIFrameElement && !force) this.el.src = content;
|
|
83
83
|
else if (this.el instanceof HTMLInputElement && !force) this.el.value = content;
|
|
84
84
|
else if (text) this.el.textContent = content;
|
|
@@ -101,17 +101,17 @@ class el {
|
|
|
101
101
|
return this;
|
|
102
102
|
}
|
|
103
103
|
addClass(className) {
|
|
104
|
-
if (!this.el) throw new Error(`no element from
|
|
104
|
+
if (!this.el) throw new Error(`no element from query: ${this.query}`);
|
|
105
105
|
this.el.classList.add(className);
|
|
106
106
|
return this;
|
|
107
107
|
}
|
|
108
108
|
removeClass(className) {
|
|
109
|
-
if (!this.el) throw new Error(`no element from
|
|
109
|
+
if (!this.el) throw new Error(`no element from query: ${this.query}`);
|
|
110
110
|
this.el.classList.remove(className);
|
|
111
111
|
return this;
|
|
112
112
|
}
|
|
113
113
|
listen(event, cb) {
|
|
114
|
-
if (!this.el) throw new Error(`no element from
|
|
114
|
+
if (!this.el) throw new Error(`no element from query: ${this.query}`);
|
|
115
115
|
this.el.addEventListener(event, cb);
|
|
116
116
|
return this;
|
|
117
117
|
}
|
|
@@ -120,45 +120,24 @@ class el {
|
|
|
120
120
|
}
|
|
121
121
|
constructor(opts){
|
|
122
122
|
_define_property(this, "el", void 0);
|
|
123
|
-
_define_property(this, "
|
|
123
|
+
_define_property(this, "query", void 0);
|
|
124
|
+
this.query = '';
|
|
124
125
|
if ('string' == typeof opts) {
|
|
125
|
-
this.
|
|
126
|
+
this.query = opts;
|
|
126
127
|
this.el = document.querySelector(opts);
|
|
127
128
|
return;
|
|
128
129
|
}
|
|
129
130
|
const { query, type, content, parent, create } = opts;
|
|
130
131
|
if (query) {
|
|
131
|
-
this.
|
|
132
|
+
this.query = query;
|
|
132
133
|
this.el = document.querySelector(query);
|
|
133
134
|
if (!this.el && type && create) this.el = document.createElement(type);
|
|
134
|
-
} else if (type)
|
|
135
|
-
|
|
136
|
-
this.el = document.createElement(type);
|
|
137
|
-
} else throw new Error('no query or type provided');
|
|
135
|
+
} else if (type) this.el = document.createElement(type);
|
|
136
|
+
else throw new Error('no query or type provided');
|
|
138
137
|
if (this.el && content) this.el.innerHTML = content;
|
|
139
138
|
if (this.el && parent) parent.appendChild(this.el);
|
|
140
139
|
}
|
|
141
140
|
}
|
|
142
|
-
class dom_params {
|
|
143
|
-
set(p) {
|
|
144
|
-
for (let [k, v] of Object.entries(p))this.params.set(k, v);
|
|
145
|
-
return this;
|
|
146
|
-
}
|
|
147
|
-
toString() {
|
|
148
|
-
return this.params.toString();
|
|
149
|
-
}
|
|
150
|
-
static render(p) {
|
|
151
|
-
const params = new URLSearchParams();
|
|
152
|
-
if (p) for (let [k, v] of Object.entries(p))params.set(k, v);
|
|
153
|
-
return params.toString();
|
|
154
|
-
}
|
|
155
|
-
constructor(p){
|
|
156
|
-
_define_property(this, "params", void 0);
|
|
157
|
-
this.params = new URLSearchParams();
|
|
158
|
-
if (p) for (let [k, v] of Object.entries(p))this.params.set(k, v);
|
|
159
|
-
return this;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
141
|
function cssVar(name) {
|
|
163
142
|
const style = window.getComputedStyle(document.body);
|
|
164
143
|
return style.getPropertyValue(name);
|
|
@@ -191,6 +170,26 @@ function network_define_property(obj, key, value) {
|
|
|
191
170
|
else obj[key] = value;
|
|
192
171
|
return obj;
|
|
193
172
|
}
|
|
173
|
+
class network_params {
|
|
174
|
+
set(p) {
|
|
175
|
+
for (let [k, v] of Object.entries(p))this.params.set(k, v);
|
|
176
|
+
return this;
|
|
177
|
+
}
|
|
178
|
+
toString() {
|
|
179
|
+
return this.params.toString();
|
|
180
|
+
}
|
|
181
|
+
static render(p) {
|
|
182
|
+
const params = new URLSearchParams();
|
|
183
|
+
if (p) for (let [k, v] of Object.entries(p))params.set(k, v);
|
|
184
|
+
return params.toString();
|
|
185
|
+
}
|
|
186
|
+
constructor(p){
|
|
187
|
+
network_define_property(this, "params", void 0);
|
|
188
|
+
this.params = new URLSearchParams();
|
|
189
|
+
if (p) for (let [k, v] of Object.entries(p))this.params.set(k, v);
|
|
190
|
+
return this;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
194
193
|
class request {
|
|
195
194
|
auth(token) {
|
|
196
195
|
this.opts.headers.Authorization = `Bearer ${token}`;
|
|
@@ -204,11 +203,14 @@ class request {
|
|
|
204
203
|
this.opts.body = body;
|
|
205
204
|
return this;
|
|
206
205
|
}
|
|
207
|
-
async do({ path,
|
|
206
|
+
async do({ path, override } = {}) {
|
|
208
207
|
if (this.opts.auth) this.opts.headers.Authorization = `Bearer ${this.opts.auth}`;
|
|
209
|
-
|
|
208
|
+
if (!override) override = {};
|
|
209
|
+
const body = override.body || this.opts.body;
|
|
210
210
|
let url = this.opts.url;
|
|
211
211
|
if (path) url = `${this.opts.url}${path}`;
|
|
212
|
+
const params = override.params || this.opts.params;
|
|
213
|
+
if (params) url = `${url}?${params.toString()}`;
|
|
212
214
|
const res = await fetch(url, {
|
|
213
215
|
method: this.opts.method,
|
|
214
216
|
headers: {
|
|
@@ -218,14 +220,14 @@ class request {
|
|
|
218
220
|
},
|
|
219
221
|
body: JSON.stringify(body)
|
|
220
222
|
});
|
|
221
|
-
const success =
|
|
223
|
+
const success = override.success || this.opts.success;
|
|
222
224
|
if (res.status !== success) {
|
|
223
225
|
const body = await res.json();
|
|
224
|
-
throw new Error(`bad response ${res.status} !== ${
|
|
226
|
+
throw new Error(`bad response ${res.status} !== ${success}, body: ${body}`);
|
|
225
227
|
}
|
|
226
228
|
return await res.json();
|
|
227
229
|
}
|
|
228
|
-
constructor(opts){
|
|
230
|
+
constructor(opts = {}){
|
|
229
231
|
network_define_property(this, "opts", void 0);
|
|
230
232
|
if (opts.type && 'json' !== opts.type) throw new Error('this class only provides json requests');
|
|
231
233
|
if (!opts.url) throw new Error('must provide url');
|
package/dist/network.d.ts
CHANGED
|
@@ -1,21 +1,33 @@
|
|
|
1
|
+
/*** url params ***/
|
|
2
|
+
export declare class params {
|
|
3
|
+
params: URLSearchParams;
|
|
4
|
+
constructor(p?: Object);
|
|
5
|
+
set(p: Object): this;
|
|
6
|
+
toString(): string;
|
|
7
|
+
static render(p: Object): string;
|
|
8
|
+
}
|
|
1
9
|
export type requestOpts = {
|
|
2
|
-
url
|
|
3
|
-
type
|
|
4
|
-
method
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
10
|
+
url?: string;
|
|
11
|
+
type?: 'json';
|
|
12
|
+
method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
13
|
+
params?: typeof params;
|
|
14
|
+
headers?: Record<string, string>;
|
|
15
|
+
auth?: string;
|
|
16
|
+
body?: Object;
|
|
17
|
+
success?: number;
|
|
9
18
|
};
|
|
10
19
|
export declare class request {
|
|
11
20
|
opts: requestOpts;
|
|
12
|
-
constructor(opts
|
|
21
|
+
constructor(opts?: requestOpts);
|
|
13
22
|
auth(token: string): this;
|
|
14
23
|
basicAuth(username: string, password: string): this;
|
|
15
24
|
body(body: Object): this;
|
|
16
|
-
do({ path,
|
|
25
|
+
do({ path, override, }?: {
|
|
17
26
|
path?: string;
|
|
18
|
-
|
|
19
|
-
|
|
27
|
+
override?: {
|
|
28
|
+
success?: number;
|
|
29
|
+
params?: any;
|
|
30
|
+
body?: Object;
|
|
31
|
+
};
|
|
20
32
|
}): Promise<any>;
|
|
21
33
|
}
|