@taybart/corvid 0.1.6 → 0.1.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 CHANGED
@@ -21,7 +21,7 @@ type elOpts = {
21
21
  query?: string;
22
22
  type?: string;
23
23
  content?: any;
24
- class?: string;
24
+ class?: string | string[];
25
25
  style?: Object;
26
26
  id?: string;
27
27
  parent?: HTMLElement | el;
@@ -46,8 +46,8 @@ export declare class el {
46
46
  /*** Style ***/
47
47
  style(update: Object | string, stringify?: boolean): this | undefined;
48
48
  hasClass(className: string): boolean;
49
- addClass(className: string): this;
50
- removeClass(className: string): this;
49
+ addClass(className: string | string[]): this;
50
+ removeClass(className: string | string[]): this;
51
51
  /*** Templates ***/
52
52
  render(vars?: {}): string;
53
53
  appendTemplate(template: el, vars: any): void;
package/dist/index.js CHANGED
@@ -345,12 +345,14 @@ class dom_el {
345
345
  }
346
346
  addClass(className) {
347
347
  if (!this.el) throw new Error(`no element from query: ${this.query}`);
348
- this.el.classList.add(className);
348
+ if ('string' == typeof className) this.el.classList.add(className);
349
+ else for (const sc of className)this.el.classList.add(sc);
349
350
  return this;
350
351
  }
351
352
  removeClass(className) {
352
353
  if (!this.el) throw new Error(`no element from query: ${this.query}`);
353
- this.el.classList.remove(className);
354
+ if ('string' == typeof className) this.el.classList.remove(className);
355
+ else for (const sc of className)this.el.classList.remove(sc);
354
356
  return this;
355
357
  }
356
358
  render(vars = {}) {
@@ -379,6 +381,7 @@ class dom_el {
379
381
  }
380
382
  removeListeners(event) {
381
383
  if (!this.el) throw new Error(`no element from query: ${this.query}`);
384
+ if (!this.listeners[event]) return this;
382
385
  for (const cb of this.listeners[event])this.el.removeEventListener(event, cb);
383
386
  this.listeners[event] = [];
384
387
  return this;
@@ -418,7 +421,8 @@ class dom_el {
418
421
  this.log.debug(`setting id: ${id}`);
419
422
  this.el.id = id;
420
423
  }
421
- if (styleClass) this.el.classList.add(styleClass);
424
+ if (styleClass) if ('string' == typeof styleClass) this.el.classList.add(styleClass);
425
+ else for (const sc of styleClass)this.el.classList.add(sc);
422
426
  if (style) this.style(style);
423
427
  if (content) {
424
428
  this.log.debug(`setting content: ${content}`);
@@ -483,14 +487,16 @@ class request {
483
487
  this.opts.body = body;
484
488
  return this;
485
489
  }
486
- async do({ path, override } = {}) {
490
+ async do({ path, params: passedParams, override } = {}) {
487
491
  if (this.opts.auth) this.opts.headers.Authorization = `Bearer ${this.opts.auth}`;
488
492
  if (!override) override = {};
489
493
  const body = override.body || this.opts.body;
490
494
  let url = this.opts.url;
491
495
  if (path) url = `${this.opts.url}${path}`;
492
- const params = override.params || this.opts.params;
493
- if (params) url = `${url}?${params.toString()}`;
496
+ let reqParams;
497
+ if (override.params || this.opts.params) reqParams = new network_params(override.params || this.opts.params);
498
+ if (passedParams) reqParams = reqParams ? new network_params(reqParams).set(passedParams) : new network_params(passedParams);
499
+ if (reqParams) url = `${url}?${reqParams.toString()}`;
494
500
  this.log.debug(`${this.opts.method} ${url}`);
495
501
  const res = await fetch(url, {
496
502
  method: this.opts.method,
package/dist/network.d.ts CHANGED
@@ -12,7 +12,7 @@ export type requestOpts = {
12
12
  url?: string;
13
13
  type?: 'json';
14
14
  method?: 'GET' | 'POST' | 'PUT' | 'DELETE';
15
- params?: typeof params;
15
+ params?: Object | params;
16
16
  headers?: Record<string, string>;
17
17
  auth?: string;
18
18
  body?: Object;
@@ -26,11 +26,12 @@ export declare class request {
26
26
  auth(token: string): this;
27
27
  basicAuth(username: string, password: string): this;
28
28
  body(body: Object): this;
29
- do({ path, override, }?: {
29
+ do({ path, params: passedParams, override, }?: {
30
30
  path?: string;
31
+ params?: Object;
31
32
  override?: {
32
33
  success?: number;
33
- params?: any;
34
+ params?: Object;
34
35
  body?: Object;
35
36
  };
36
37
  }): Promise<any>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taybart/corvid",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "exports": {