MCPcopy Create free account
hub / github.com/arfct/itty-bitty / constructor

Method constructor

docs/bitty.js:42–77  ·  view source on GitHub ↗

* @constructor * @param {URL} url - data url

(url)

Source from the content-addressed store, hash-verified

40 * @param {URL} url - data url
41 */
42 constructor(url) {
43 this.initString = url;
44
45 var colon = url.substring(0,15).indexOf(":");
46 if ( colon != -1) {
47 this.scheme = url.substring(0,colon);
48 if (schemeMappings[this.scheme]) {
49 url = `data:${schemeMappings[this.scheme]},${url}`
50 }
51 } else {
52 if (url.charAt(0) == "?") {
53 this.editable = true;
54 url = url.substring(1);
55 }
56
57 this.dataPrefix = HEAD_TAGS_EXTENDED();
58 // todo: gzip starts with 0x1f8b
59 let encoding = url.startsWith("XQA") ? bitty.LZMA_MARKER : bitty.GZIP_MARKER;
60 url = `data:text/html;charset=utf-8;format=${encoding};base64,${url}`;
61 }
62
63 let match = url.match(dataUrlRE);
64
65 this.params = {};
66
67 if (match) {
68 let info = match.groups;
69 Object.assign(this, info);
70 this.params = info.params ? JSON.parse('{"' + decodeURI(info.params?.substring(1)).replace(/"/g, '\\"').replace(/;/g, '","').replace(/=/g,'":"') + '"}') : {};
71 }
72 if (this.encoding) {
73 this.data = this.data.replace(/=/g,"");
74 } else {
75 this.data = decodeURIComponent(this.data);
76 }
77 }
78
79 get href() {
80 let urlString = "data:";

Callers

nothing calls this directly

Calls 2

HEAD_TAGS_EXTENDEDFunction · 0.85
parseMethod · 0.80

Tested by

no test coverage detected