@taybart/corvid 0.1.21 → 0.1.22

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/index.js CHANGED
@@ -61,6 +61,7 @@ var local_storage_namespaceObject = {};
61
61
  __webpack_require__.r(local_storage_namespaceObject);
62
62
  __webpack_require__.d(local_storage_namespaceObject, {
63
63
  clear: ()=>clear,
64
+ default: ()=>local_storage,
64
65
  get: ()=>get,
65
66
  getJSON: ()=>getJSON,
66
67
  listen: ()=>listen,
@@ -778,4 +779,13 @@ function unlisten(key, cb) {
778
779
  function clear(key) {
779
780
  localStorage.removeItem(key);
780
781
  }
782
+ const local_storage = {
783
+ get,
784
+ getJSON,
785
+ set,
786
+ update: local_storage_update,
787
+ listen,
788
+ unlisten,
789
+ clear
790
+ };
781
791
  export { clipboard, dom_namespaceObject as dom, genID, utils_logLevel as logLevel, logger, local_storage_namespaceObject as ls, network_namespaceObject as network, strings_namespaceObject as strings, style_namespaceObject as style };
@@ -13,3 +13,13 @@ export declare function unlisten(key: string, cb: (update: {
13
13
  value: any;
14
14
  }) => void | el): void;
15
15
  export declare function clear(key: string): void;
16
+ declare const _default_1: {
17
+ get: typeof get;
18
+ getJSON: typeof getJSON;
19
+ set: typeof set;
20
+ update: typeof update;
21
+ listen: typeof listen;
22
+ unlisten: typeof unlisten;
23
+ clear: typeof clear;
24
+ };
25
+ export default _default_1;
package/dist/ls.js CHANGED
@@ -333,4 +333,13 @@ function unlisten(key, cb) {
333
333
  function clear(key) {
334
334
  localStorage.removeItem(key);
335
335
  }
336
- export { clear, get, getJSON, listen, set, setObj, unlisten, local_storage_update as update };
336
+ const local_storage = {
337
+ get,
338
+ getJSON,
339
+ set,
340
+ update: local_storage_update,
341
+ listen,
342
+ unlisten,
343
+ clear
344
+ };
345
+ export { clear, local_storage as default, get, getJSON, listen, set, setObj, unlisten, local_storage_update as update };
package/dist/utils.js ADDED
@@ -0,0 +1,95 @@
1
+ function _define_property(obj, key, value) {
2
+ if (key in obj) Object.defineProperty(obj, key, {
3
+ value: value,
4
+ enumerable: true,
5
+ configurable: true,
6
+ writable: true
7
+ });
8
+ else obj[key] = value;
9
+ return obj;
10
+ }
11
+ function genID(len = 15, alphabet = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz') {
12
+ return [
13
+ ...crypto.getRandomValues(new Uint8Array(len))
14
+ ].map((value)=>alphabet[Math.floor(value / 255 * alphabet.length)]).join('');
15
+ }
16
+ const clipboard = {
17
+ check () {
18
+ if (!navigator.clipboard) throw new Error('Clipboard API not supported, or context is not https');
19
+ },
20
+ async copy (text) {
21
+ this.check();
22
+ await navigator.clipboard.writeText(text);
23
+ },
24
+ async copyArbitrary (data) {
25
+ this.check();
26
+ await navigator.clipboard.write(data);
27
+ },
28
+ async read () {
29
+ this.check();
30
+ return await navigator.clipboard.readText();
31
+ },
32
+ async readArbitrary () {
33
+ this.check();
34
+ return await navigator.clipboard.read();
35
+ },
36
+ listen (query, cb) {
37
+ let el;
38
+ el = 'string' == typeof query ? document.querySelector(query) : query;
39
+ if (!el) throw new Error(`no element from query: ${query}`);
40
+ el.addEventListener('copy', (ev)=>{
41
+ const cbEv = ev;
42
+ const selection = document.getSelection();
43
+ if (selection) {
44
+ const text = selection.toString();
45
+ if (text && cbEv.clipboardData) cbEv.clipboardData.setData('text/plain', cb(text));
46
+ }
47
+ });
48
+ }
49
+ };
50
+ var utils_logLevel = /*#__PURE__*/ function(logLevel) {
51
+ logLevel[logLevel["none"] = -1] = "none";
52
+ logLevel[logLevel["error"] = 0] = "error";
53
+ logLevel[logLevel["warn"] = 1] = "warn";
54
+ logLevel[logLevel["info"] = 2] = "info";
55
+ logLevel[logLevel["debug"] = 3] = "debug";
56
+ logLevel[logLevel["trace"] = 4] = "trace";
57
+ return logLevel;
58
+ }({});
59
+ class logger {
60
+ error(...args) {
61
+ if (this.level >= 0) console.error(`[corvid] ${this.prefix}`, ...args);
62
+ }
63
+ warn(...args) {
64
+ if (this.level >= 1) console.warn(`[corvid] ${this.prefix}`, ...args);
65
+ }
66
+ info(...args) {
67
+ if (this.level >= 2) console.info(`[corvid] ${this.prefix}`, ...args);
68
+ }
69
+ debug(...args) {
70
+ if (this.level >= 3) console.debug(`[corvid] ${this.prefix}`, ...args);
71
+ }
72
+ trace(...args) {
73
+ if (this.level >= 4) console.trace(`[corvid] ${this.prefix}`, ...args);
74
+ }
75
+ log(...args) {
76
+ console.log(`[corvid] ${this.prefix}`, ...args);
77
+ }
78
+ constructor(level = 2, prefix){
79
+ _define_property(this, "level", void 0);
80
+ _define_property(this, "prefix", void 0);
81
+ this.level = level;
82
+ this.prefix = prefix ? `(${prefix}):` : ':';
83
+ if (-1 === this.level) [
84
+ 'error',
85
+ 'warn',
86
+ 'info',
87
+ 'debug',
88
+ 'trace',
89
+ 'log'
90
+ ].forEach((methodName)=>{
91
+ this[methodName] = ()=>{};
92
+ });
93
+ }
94
+ }
95
+ export { clipboard, genID, utils_logLevel as logLevel, logger };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taybart/corvid",
3
- "version": "0.1.21",
3
+ "version": "0.1.22",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "exports": {
@@ -16,8 +16,8 @@
16
16
  "types": "./dist/style.d.ts",
17
17
  "import": "./dist/style.js"
18
18
  },
19
- "./local_storage": {
20
- "types": "./dist/ls.d.ts",
19
+ "./ls": {
20
+ "types": "./dist/local_storage.d.ts",
21
21
  "import": "./dist/ls.js"
22
22
  },
23
23
  "./network": {
@@ -25,8 +25,12 @@
25
25
  "import": "./dist/network.js"
26
26
  },
27
27
  "./qr": {
28
- "types": "./dist/qr.d.ts",
28
+ "types": "./dist/qr/index.d.ts",
29
29
  "import": "./dist/qr.js"
30
+ },
31
+ "./utils": {
32
+ "types": "./dist/utils.d.ts",
33
+ "import": "./dist/utils.js"
30
34
  }
31
35
  },
32
36
  "module": "./dist/index.js",