@taybart/corvid 0.0.7 → 0.1.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/README.md CHANGED
@@ -1 +1,6 @@
1
1
  # Corvid
2
+
3
+ fear the crow
4
+
5
+
6
+ ![crowtein_2](https://github.com/user-attachments/assets/b3bbf267-d7b0-4116-80a5-b932b409a111)
@@ -0,0 +1,8 @@
1
+ export declare class EncryptionHelper {
2
+ private iv?;
3
+ private aesKey?;
4
+ private encryptionKey?;
5
+ constructor(publicKey: string);
6
+ encrypt(plaintext: string): Promise<string>;
7
+ key(): Promise<string>;
8
+ }
package/dist/dom.d.ts CHANGED
@@ -1,36 +1,50 @@
1
+ import { logger } from './utils';
1
2
  /****************
2
3
  * DOM *
3
4
  ***************/
4
5
  /*** window ***/
5
6
  /**
6
- * onDomContentLoaded
7
+ * onDomContentLoaded callback
7
8
  */
8
9
  export declare function ready(cb: () => void): void;
10
+ export declare function onKey(key: string, cb: (ev: {
11
+ ctrl: boolean;
12
+ alt: boolean;
13
+ meta: boolean;
14
+ shift: boolean;
15
+ }) => void): void;
9
16
  /*** element ***/
10
17
  type elOpts = {
18
+ element?: HTMLElement;
11
19
  query?: string;
12
20
  type?: string;
13
21
  content?: any;
14
- parent?: HTMLElement;
15
- create?: boolean;
22
+ class?: string;
23
+ style?: Object;
24
+ id?: string;
25
+ parent?: HTMLElement | el;
16
26
  };
17
27
  export declare class el {
18
28
  el: HTMLElement | null;
19
29
  query: string;
20
- constructor(opts: string | elOpts);
21
- /*** get ***/
22
- value(): string;
23
- /*** set ***/
24
- parent(parent: HTMLElement): this;
25
- child(ch: HTMLElement): this;
26
- inner(content: any, { force, text }?: {
27
- force?: boolean;
30
+ log: logger;
31
+ constructor(opts: HTMLElement | string | elOpts, verbose?: boolean);
32
+ /*** dom manipulation ***/
33
+ value(update?: string): string | el;
34
+ parent(parent: HTMLElement | el): this;
35
+ appendChild(ch: HTMLElement | el): this;
36
+ child(ch: HTMLElement | el): this;
37
+ empty(): this;
38
+ content(content: any, { text }?: {
28
39
  text?: boolean;
29
40
  }): this;
30
41
  src(url: string): this;
42
+ /*** Style ***/
31
43
  style(style: Object | string): this;
32
44
  addClass(className: string): this;
33
45
  removeClass(className: string): this;
46
+ /*** Events ***/
47
+ on(event: string, cb: (ev: Event) => void): this;
34
48
  listen(event: string, cb: (ev: Event) => void): this;
35
49
  onClick(cb: (ev: Event) => void): this;
36
50
  }
package/dist/index.js CHANGED
@@ -23,7 +23,8 @@ var __webpack_require__ = {};
23
23
  var dom_namespaceObject = {};
24
24
  __webpack_require__.r(dom_namespaceObject);
25
25
  __webpack_require__.d(dom_namespaceObject, {
26
- el: ()=>el,
26
+ el: ()=>dom_el,
27
+ onKey: ()=>onKey,
27
28
  ready: ()=>ready
28
29
  });
29
30
  var style_namespaceObject = {};
@@ -39,7 +40,9 @@ var network_namespaceObject = {};
39
40
  __webpack_require__.r(network_namespaceObject);
40
41
  __webpack_require__.d(network_namespaceObject, {
41
42
  params: ()=>network_params,
42
- request: ()=>request
43
+ refresh: ()=>refresh,
44
+ request: ()=>request,
45
+ ws: ()=>ws
43
46
  });
44
47
  var local_storage_namespaceObject = {};
45
48
  __webpack_require__.r(local_storage_namespaceObject);
@@ -48,6 +51,9 @@ __webpack_require__.d(local_storage_namespaceObject, {
48
51
  listen: ()=>listen,
49
52
  set: ()=>set
50
53
  });
54
+ function toKebab(str) {
55
+ return str.replace(/[A-Z]+(?![a-z])|[A-Z]/g, (s, ofs)=>(ofs ? '-' : '') + s.toLowerCase());
56
+ }
51
57
  function _define_property(obj, key, value) {
52
58
  if (key in obj) Object.defineProperty(obj, key, {
53
59
  value: value,
@@ -58,12 +64,119 @@ function _define_property(obj, key, value) {
58
64
  else obj[key] = value;
59
65
  return obj;
60
66
  }
67
+ function genID(len = 15, alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz') {
68
+ return [
69
+ ...crypto.getRandomValues(new Uint8Array(len))
70
+ ].map((value)=>alphabet[Math.floor(value / 255 * alphabet.length)]).join('');
71
+ }
72
+ const clipboard = {
73
+ async copy (text) {
74
+ await navigator.clipboard.writeText(text);
75
+ },
76
+ async copyArbitrary (data) {
77
+ await navigator.clipboard.write(data);
78
+ },
79
+ async read () {
80
+ return await navigator.clipboard.readText();
81
+ },
82
+ async readArbitrary () {
83
+ return await navigator.clipboard.read();
84
+ },
85
+ listen (query, cb) {
86
+ let el;
87
+ el = 'string' == typeof query ? document.querySelector(query) : query;
88
+ if (!el) throw new Error(`no element from query: ${query}`);
89
+ el.addEventListener('copy', (ev)=>{
90
+ const cbEv = ev;
91
+ const selection = document.getSelection();
92
+ if (selection) {
93
+ const text = selection.toString();
94
+ if (text && cbEv.clipboardData) cbEv.clipboardData.setData('text/plain', cb(text));
95
+ }
96
+ });
97
+ }
98
+ };
99
+ var utils_logLevel = /*#__PURE__*/ function(logLevel) {
100
+ logLevel[logLevel["none"] = -1] = "none";
101
+ logLevel[logLevel["error"] = 0] = "error";
102
+ logLevel[logLevel["warn"] = 1] = "warn";
103
+ logLevel[logLevel["info"] = 2] = "info";
104
+ logLevel[logLevel["debug"] = 3] = "debug";
105
+ logLevel[logLevel["trace"] = 4] = "trace";
106
+ return logLevel;
107
+ }({});
108
+ class logger {
109
+ error(...args) {
110
+ if (this.level >= 0) console.error(`[corvid] ${this.prefix}`, ...args);
111
+ }
112
+ warn(...args) {
113
+ if (this.level >= 1) console.warn(`[corvid] ${this.prefix}`, ...args);
114
+ }
115
+ info(...args) {
116
+ if (this.level >= 2) console.info(`[corvid] ${this.prefix}`, ...args);
117
+ }
118
+ debug(...args) {
119
+ if (this.level >= 3) console.debug(`[corvid] ${this.prefix}`, ...args);
120
+ }
121
+ trace(...args) {
122
+ if (this.level >= 4) console.trace(`[corvid] ${this.prefix}`, ...args);
123
+ }
124
+ log(...args) {
125
+ console.log(`[corvid] ${this.prefix}`, ...args);
126
+ }
127
+ constructor(level = 2, prefix){
128
+ _define_property(this, "level", void 0);
129
+ _define_property(this, "prefix", void 0);
130
+ this.level = level;
131
+ this.prefix = prefix ? `(${prefix}):` : ':';
132
+ if (-1 === this.level) {
133
+ const methodsToMock = [
134
+ 'error',
135
+ 'warn',
136
+ 'info',
137
+ 'debug',
138
+ 'trace',
139
+ 'log'
140
+ ];
141
+ methodsToMock.forEach((methodName)=>{
142
+ this[methodName] = ()=>{};
143
+ });
144
+ }
145
+ }
146
+ }
147
+ function dom_define_property(obj, key, value) {
148
+ if (key in obj) Object.defineProperty(obj, key, {
149
+ value: value,
150
+ enumerable: true,
151
+ configurable: true,
152
+ writable: true
153
+ });
154
+ else obj[key] = value;
155
+ return obj;
156
+ }
61
157
  function ready(cb) {
62
158
  window.addEventListener('DOMContentLoaded', cb);
63
159
  }
64
- class el {
65
- value() {
66
- if (this.el && this.el instanceof HTMLInputElement) return this.el.value;
160
+ function onKey(key, cb) {
161
+ window.addEventListener('keydown', (ev)=>{
162
+ if (ev.key === key) cb({
163
+ ctrl: ev.ctrlKey,
164
+ alt: ev.altKey,
165
+ meta: ev.metaKey,
166
+ shift: ev.shiftKey
167
+ });
168
+ });
169
+ }
170
+ class dom_el {
171
+ value(update) {
172
+ if (!this.el) throw new Error(`no element from query: ${this.query}`);
173
+ if (update) {
174
+ if ('value' in this.el) this.el.value = update;
175
+ if ('src' in this.el) this.el.src = update;
176
+ return this;
177
+ }
178
+ if ('value' in this.el) return this.el.value;
179
+ this.log.warn(`element (${this.query}) does not contain value, returning empty string`);
67
180
  return '';
68
181
  }
69
182
  parent(parent) {
@@ -71,22 +184,27 @@ class el {
71
184
  parent.appendChild(this.el);
72
185
  return this;
73
186
  }
187
+ appendChild(ch) {
188
+ return this.child(ch);
189
+ }
74
190
  child(ch) {
75
- var _this_el;
76
191
  if (!this.el) throw new Error(`no element from query: ${this.query}`);
77
- null == (_this_el = this.el) || _this_el.appendChild(ch);
192
+ if (ch instanceof dom_el) this.el.appendChild(ch.el);
193
+ else this.el.appendChild(ch);
194
+ return this;
195
+ }
196
+ empty() {
197
+ if (this.el) this.el.innerHTML = '';
78
198
  return this;
79
199
  }
80
- inner(content, { force = false, text = false } = {}) {
200
+ content(content, { text = false } = {}) {
81
201
  if (!this.el) throw new Error(`no element from query: ${this.query}`);
82
- if (this.el instanceof HTMLIFrameElement && !force) this.el.src = content;
83
- else if (this.el instanceof HTMLInputElement && !force) this.el.value = content;
84
- else if (text) this.el.textContent = content;
202
+ if (text) this.el.textContent = content;
85
203
  else this.el.innerHTML = content;
86
204
  return this;
87
205
  }
88
206
  src(url) {
89
- if (this.el instanceof HTMLIFrameElement || this.el instanceof HTMLImageElement) this.el.src = url;
207
+ if (this.el && 'src' in this.el) this.el.src = url;
90
208
  return this;
91
209
  }
92
210
  style(style) {
@@ -94,7 +212,7 @@ class el {
94
212
  if ('string' == typeof style) this.el.style = style;
95
213
  else if ('object' == typeof style) {
96
214
  let s = '';
97
- Object.entries(style).forEach(([k, v])=>s += `${k}:${v};`);
215
+ Object.entries(style).forEach(([k, v])=>s += `${toKebab(k)}:${v};`);
98
216
  this.el.style = s;
99
217
  }
100
218
  }
@@ -110,32 +228,56 @@ class el {
110
228
  this.el.classList.remove(className);
111
229
  return this;
112
230
  }
113
- listen(event, cb) {
231
+ on(event, cb) {
114
232
  if (!this.el) throw new Error(`no element from query: ${this.query}`);
115
233
  this.el.addEventListener(event, cb);
116
234
  return this;
117
235
  }
236
+ listen(event, cb) {
237
+ return this.on(event, cb);
238
+ }
118
239
  onClick(cb) {
119
- return this.listen('click', cb);
240
+ return this.on('click', cb);
120
241
  }
121
- constructor(opts){
122
- _define_property(this, "el", void 0);
123
- _define_property(this, "query", void 0);
124
- this.query = '';
242
+ constructor(opts, verbose = false){
243
+ dom_define_property(this, "el", void 0);
244
+ dom_define_property(this, "query", '');
245
+ dom_define_property(this, "log", void 0);
246
+ this.log = new logger(verbose ? utils_logLevel.debug : utils_logLevel.none, 'element');
125
247
  if ('string' == typeof opts) {
126
248
  this.query = opts;
127
249
  this.el = document.querySelector(opts);
128
250
  return;
129
251
  }
130
- const { query, type, content, parent, create } = opts;
252
+ const { query, element, type, class: styleClass, style, id, content, parent } = opts;
131
253
  if (query) {
254
+ this.log.debug(`using query: ${query}`);
132
255
  this.query = query;
133
256
  this.el = document.querySelector(query);
134
- if (!this.el && type && create) this.el = document.createElement(type);
135
- } else if (type) this.el = document.createElement(type);
136
- else throw new Error('no query or type provided');
137
- if (this.el && content) this.el.innerHTML = content;
138
- if (this.el && parent) parent.appendChild(this.el);
257
+ if (!this.el) throw new Error(`no element from query: ${query}`);
258
+ } else if (element) {
259
+ this.log.debug(`using existing element: ${element}`);
260
+ this.el = element;
261
+ } else if (type) {
262
+ this.log.debug(`creating element: ${type}`);
263
+ this.el = document.createElement(type);
264
+ } else throw new Error('no query or type provided');
265
+ if (this.el) {
266
+ if (id) {
267
+ this.log.debug(`setting id: ${id}`);
268
+ this.el.id = id;
269
+ }
270
+ if (styleClass) this.el.classList.add(styleClass);
271
+ if (style) this.style(style);
272
+ if (content) {
273
+ this.log.debug(`setting content: ${content}`);
274
+ this.el.innerHTML = content;
275
+ }
276
+ if (parent) {
277
+ this.log.debug("adding to parent");
278
+ parent.appendChild(this.el);
279
+ }
280
+ }
139
281
  }
140
282
  }
141
283
  function cssVar(name) {
@@ -192,11 +334,15 @@ class network_params {
192
334
  }
193
335
  class request {
194
336
  auth(token) {
195
- this.opts.headers.Authorization = `Bearer ${token}`;
337
+ const header = `Bearer ${token}`;
338
+ this.log.debug(`adding auth token header ${header}`);
339
+ this.opts.headers.Authorization = header;
196
340
  return this;
197
341
  }
198
342
  basicAuth(username, password) {
199
- this.opts.headers.Authorization = 'Basic ' + btoa(username + ':' + password);
343
+ const header = `Basic ${btoa(`${username}:${password}`)}`;
344
+ this.log.debug(`adding basic auth header ${header}`);
345
+ this.opts.headers.Authorization = header;
200
346
  return this;
201
347
  }
202
348
  body(body) {
@@ -211,8 +357,10 @@ class request {
211
357
  if (path) url = `${this.opts.url}${path}`;
212
358
  const params = override.params || this.opts.params;
213
359
  if (params) url = `${url}?${params.toString()}`;
360
+ this.log.debug(`${this.opts.method} ${url}`);
214
361
  const res = await fetch(url, {
215
362
  method: this.opts.method,
363
+ credentials: this.opts.credentials,
216
364
  headers: {
217
365
  accept: 'application/json',
218
366
  'content-type': 'application/json',
@@ -227,14 +375,109 @@ class request {
227
375
  }
228
376
  return await res.json();
229
377
  }
230
- constructor(opts = {}){
378
+ constructor(opts = {}, verbose = false){
231
379
  network_define_property(this, "opts", void 0);
380
+ network_define_property(this, "log", void 0);
381
+ this.log = new logger(verbose ? utils_logLevel.debug : utils_logLevel.none, 'request');
232
382
  if (opts.type && 'json' !== opts.type) throw new Error('this class only provides json requests');
233
383
  if (!opts.url) throw new Error('must provide url');
234
384
  this.opts = opts;
235
385
  if (!this.opts.success) this.opts.success = 200;
236
386
  if (!this.opts.method) this.opts.method = 'GET';
237
387
  if (!this.opts.headers) this.opts.headers = {};
388
+ if (!this.opts.credentials) this.opts.credentials = 'omit';
389
+ this.log.debug(`with options: ${JSON.stringify(this.opts)}`);
390
+ }
391
+ }
392
+ class ws {
393
+ setup() {
394
+ this.recursion_level += 1;
395
+ this.ws = new WebSocket(this.url);
396
+ this.backoff = 100;
397
+ this.ws.addEventListener('open', ()=>{
398
+ const rl = this.recursion_level;
399
+ this.log.debug(`on open: reconnected (${rl})`);
400
+ this.is_connected = true;
401
+ for(let key in this.event_listeners)this.event_listeners[key].forEach((cb)=>{
402
+ this.log.debug(`adding listener (${rl}): ${key}`);
403
+ this.ws.addEventListener(key, cb);
404
+ });
405
+ });
406
+ this.ws.addEventListener('close', ()=>{
407
+ this.log.debug('connection closed');
408
+ this.is_connected = false;
409
+ this.backoff = Math.min(2 * this.backoff, this.max_timeout);
410
+ this.log.debug('backoff: ' + this.backoff);
411
+ setTimeout(()=>{
412
+ if (this.should_reconnect) {
413
+ this.ws = null;
414
+ this.setup();
415
+ }
416
+ }, this.backoff + 50 * Math.random());
417
+ });
418
+ }
419
+ send(data) {
420
+ if (!this.is_connected || !this.ws) throw new Error('not connected');
421
+ this.ws.send(data);
422
+ }
423
+ onMessage(cb) {
424
+ if (!this.ws) throw new Error('ws is null');
425
+ if (!this.event_listeners.message) this.event_listeners.message = [];
426
+ this.event_listeners.message.push((e)=>{
427
+ const rl = this.recursion_level;
428
+ this.log.debug(`message(${rl}): ${e.data}`);
429
+ cb(e.data);
430
+ });
431
+ this.ws.addEventListener('message', (e)=>{
432
+ const rl = this.recursion_level;
433
+ this.log.debug(`message(${rl}): ${e.data}`);
434
+ cb(e.data);
435
+ });
436
+ }
437
+ on(event, cb) {
438
+ if (!this.ws) throw new Error('ws is null');
439
+ if (!this.event_listeners[event]) this.event_listeners[event] = [];
440
+ this.event_listeners[event].push(cb);
441
+ this.ws.addEventListener(event, cb);
442
+ }
443
+ close() {
444
+ if (!this.is_connected || !this.ws) return;
445
+ this.should_reconnect = false;
446
+ this.ws.close();
447
+ }
448
+ constructor(url, verbose = false){
449
+ network_define_property(this, "url", void 0);
450
+ network_define_property(this, "ws", void 0);
451
+ network_define_property(this, "backoff", 50);
452
+ network_define_property(this, "max_timeout", 10000);
453
+ network_define_property(this, "should_reconnect", true);
454
+ network_define_property(this, "is_connected", false);
455
+ network_define_property(this, "recursion_level", 0);
456
+ network_define_property(this, "log", void 0);
457
+ network_define_property(this, "event_listeners", {});
458
+ this.url = url;
459
+ this.ws = null;
460
+ this.log = new logger(verbose ? utils_logLevel.debug : utils_logLevel.none, 'websocket');
461
+ this.setup();
462
+ }
463
+ }
464
+ class refresh {
465
+ listen() {
466
+ const socket = new ws(this.url);
467
+ if (socket) {
468
+ socket.on('open', ()=>{
469
+ if (this.should_reload) location.reload();
470
+ });
471
+ socket.on('close', ()=>{
472
+ this.should_reload = true;
473
+ setTimeout(this.listen, 500);
474
+ });
475
+ }
476
+ }
477
+ constructor(url){
478
+ network_define_property(this, "url", void 0);
479
+ network_define_property(this, "should_reload", false);
480
+ this.url = url;
238
481
  }
239
482
  }
240
483
  function get(key) {
@@ -255,57 +498,16 @@ function set(key, value, broadcast = false) {
255
498
  }
256
499
  function listen(key, cb) {
257
500
  document.addEventListener('@corvid/ls-update', (ev)=>{
258
- if (ev.detail.key === key || '*' === key) cb({
259
- key: ev.detail.key,
260
- value: ev.detail.value
261
- });
262
- });
263
- }
264
- function bytesToHuman(bytes, options = {}) {
265
- const { useSI = false, decimals = 2, includeUnits = true, targetUnit = null } = options;
266
- const unit = useSI ? 1000 : 1024;
267
- const units = useSI ? [
268
- 'B',
269
- 'kB',
270
- 'MB',
271
- 'GB',
272
- 'TB',
273
- 'PB',
274
- 'EB',
275
- 'ZB',
276
- 'YB'
277
- ] : [
278
- 'B',
279
- 'KiB',
280
- 'MiB',
281
- 'GiB',
282
- 'TiB',
283
- 'PiB',
284
- 'EiB',
285
- 'ZiB',
286
- 'YiB'
287
- ];
288
- if (null === targetUnit) {
289
- let val = parseInt(bytes, 10);
290
- if (Math.abs(val) < unit) return `${bytes} B`;
291
- let u = 0;
292
- while(Math.abs(val) >= unit && u < units.length - 1){
293
- val /= unit;
294
- u++;
501
+ if (ev.detail.key === key || '*' === key) {
502
+ if (cb instanceof dom_el) {
503
+ if (ev.detail.key === key) cb.content(ev.detail.value);
504
+ return;
505
+ }
506
+ cb({
507
+ key: ev.detail.key,
508
+ value: ev.detail.value
509
+ });
295
510
  }
296
- if (includeUnits) return `${val.toFixed(decimals)} ${units[u]}`;
297
- return `${val.toFixed(decimals)}`;
298
- }
299
- const targetUnitIndex = units.indexOf(targetUnit);
300
- if (-1 === targetUnitIndex) throw new Error(`Invalid unit: ${targetUnit}. Valid units are: ${units.join(', ')}`);
301
- let val = parseInt(bytes, 10);
302
- for(let i = 0; i < targetUnitIndex; i++)val /= unit;
303
- if (includeUnits) return `${val.toFixed(decimals)} ${targetUnit}`;
304
- return `${val.toFixed(decimals)}`;
305
- }
306
- function genID(len = 15, alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz') {
307
- return [
308
- ...crypto.getRandomValues(new Uint8Array(len))
309
- ].map((value)=>alphabet[Math.floor(value / 255 * alphabet.length)]).join('');
511
+ });
310
512
  }
311
- export { bytesToHuman, dom_namespaceObject as dom, genID, local_storage_namespaceObject as ls, network_namespaceObject as network, style_namespaceObject as style };
513
+ export { clipboard, dom_namespaceObject as dom, genID, utils_logLevel as logLevel, logger, local_storage_namespaceObject as ls, network_namespaceObject as network, style_namespaceObject as style };
@@ -1,6 +1,7 @@
1
+ import { el } from './dom';
1
2
  export declare function get(key: string): any;
2
3
  export declare function set(key: string, value: any, broadcast?: boolean): void;
3
4
  export declare function listen(key: string, cb: (update: {
4
5
  key: string;
5
6
  value: any;
6
- }) => void): void;
7
+ }) => void | el): void;
package/dist/network.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { logger } from './utils';
1
2
  /*** url params ***/
2
3
  export declare class params {
3
4
  params: URLSearchParams;
@@ -6,6 +7,7 @@ export declare class params {
6
7
  toString(): string;
7
8
  static render(p: Object): string;
8
9
  }
10
+ /*** http request ***/
9
11
  export type requestOpts = {
10
12
  url?: string;
11
13
  type?: 'json';
@@ -15,10 +17,12 @@ export type requestOpts = {
15
17
  auth?: string;
16
18
  body?: Object;
17
19
  success?: number;
20
+ credentials?: RequestCredentials;
18
21
  };
19
22
  export declare class request {
20
23
  opts: requestOpts;
21
- constructor(opts?: requestOpts);
24
+ log: logger;
25
+ constructor(opts?: requestOpts, verbose?: boolean);
22
26
  auth(token: string): this;
23
27
  basicAuth(username: string, password: string): this;
24
28
  body(body: Object): this;
@@ -31,3 +35,29 @@ export declare class request {
31
35
  };
32
36
  }): Promise<any>;
33
37
  }
38
+ /*** websocket ***/
39
+ export declare class ws {
40
+ url: string;
41
+ ws: WebSocket | null;
42
+ backoff: number;
43
+ max_timeout: number;
44
+ should_reconnect: boolean;
45
+ is_connected: boolean;
46
+ recursion_level: number;
47
+ log: logger;
48
+ event_listeners: Record<string, Array<(data: any) => void>>;
49
+ constructor(url: string, verbose?: boolean);
50
+ setup(): void;
51
+ send(data: any): void;
52
+ onMessage(cb: (data: any) => void): void;
53
+ on(event: string, cb: (data: any) => void): void;
54
+ close(): void;
55
+ }
56
+ /*** refresh ***/
57
+ export declare class refresh {
58
+ url: string;
59
+ should_reload: boolean;
60
+ constructor(url: string);
61
+ listen(): void;
62
+ }
63
+ /*** server sent events ***/
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Converts bytes to a human-readable string representation
3
+ *
4
+ * @param bytes - The number of bytes to convert
5
+ * @param options - Optional configuration
6
+ * @param options.useSI - If true, use SI units (KB, MB, GB) with powers of 1000
7
+ * If false, use binary units (KiB, MiB, GiB) with powers of 1024
8
+ * @param options.decimals - Number of decimal places to include (default: 2)
9
+ * @return Human-readable representation (e.g., "4.2 MB" or "3.7 GiB")
10
+ */
11
+ export type bytesOptions = {
12
+ useSI?: boolean;
13
+ decimals?: number;
14
+ includeUnits?: boolean;
15
+ targetUnit?: string;
16
+ };
17
+ export declare function bytesToHuman(bytes: string, options?: bytesOptions): string;
18
+ export declare function toKebab(str: string): string;
package/dist/utils.d.ts CHANGED
@@ -1,23 +1,6 @@
1
1
  /***************
2
2
  * Utils *
3
3
  **************/
4
- /**
5
- * Converts bytes to a human-readable string representation
6
- *
7
- * @param bytes - The number of bytes to convert
8
- * @param options - Optional configuration
9
- * @param options.useSI - If true, use SI units (KB, MB, GB) with powers of 1000
10
- * If false, use binary units (KiB, MiB, GiB) with powers of 1024
11
- * @param options.decimals - Number of decimal places to include (default: 2)
12
- * @return Human-readable representation (e.g., "4.2 MB" or "3.7 GiB")
13
- */
14
- export type bytesOptions = {
15
- useSI?: boolean;
16
- decimals?: number;
17
- includeUnits?: boolean;
18
- targetUnit?: string;
19
- };
20
- export declare function bytesToHuman(bytes: string, options?: bytesOptions): string;
21
4
  /**
22
5
  * Generates a random id of length len using provided alphabet
23
6
  * @param len - The length of the string to generate
@@ -25,3 +8,32 @@ export declare function bytesToHuman(bytes: string, options?: bytesOptions): str
25
8
  * @return A new random id
26
9
  */
27
10
  export declare function genID(len?: number, alphabet?: string): string;
11
+ /**
12
+ * Clipboard helper because i can't remember the funciton names
13
+ */
14
+ export declare const clipboard: {
15
+ copy(text: string): Promise<void>;
16
+ copyArbitrary(data: any): Promise<void>;
17
+ read(): Promise<string>;
18
+ readArbitrary(): Promise<any>;
19
+ listen(query: string | HTMLElement, cb: (contents: string) => string): void;
20
+ };
21
+ export declare enum logLevel {
22
+ none = -1,
23
+ error = 0,
24
+ warn = 1,
25
+ info = 2,
26
+ debug = 3,
27
+ trace = 4
28
+ }
29
+ export declare class logger {
30
+ level: logLevel;
31
+ prefix: string;
32
+ constructor(level?: logLevel, prefix?: string);
33
+ error(...args: any[]): void;
34
+ warn(...args: any[]): void;
35
+ info(...args: any[]): void;
36
+ debug(...args: any[]): void;
37
+ trace(...args: any[]): void;
38
+ log(...args: any[]): void;
39
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taybart/corvid",
3
- "version": "0.0.7",
3
+ "version": "0.1.0",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "exports": {