MCPcopy Create free account
hub / github.com/Acode-Foundation/Acode / safe

Function safe

src/utils/Url.js:122–138  ·  view source on GitHub ↗

* Make url safe by encoding url components * @param {string} url * @returns {string}

(url)

Source from the content-addressed store, hash-verified

120 * @returns {string}
121 */
122 safe(url) {
123 let { url: uri, query } = this.parse(url);
124 url = uri;
125 const protocol = (this.PROTOCOL_PATTERN.exec(url) || [])[0] || "";
126 if (protocol) url = url.replace(new RegExp("^" + protocol), "");
127 const parts = url.split("/").map((part, i) => {
128 if (i === 0) return part;
129 return fixedEncodeURIComponent(part);
130 });
131 return protocol + parts.join("/") + query;
132
133 function fixedEncodeURIComponent(str) {
134 return encodeURIComponent(str).replace(/[!'()*]/g, function (c) {
135 return "%" + c.charCodeAt(0).toString(16);
136 });
137 }
138 },
139 /**
140 * Gets pathname from url eg. gets '/foo/bar' from 'ftp://myhost.com/foo/bar'
141 * @param {string} url

Callers

nothing calls this directly

Calls 2

fixedEncodeURIComponentFunction · 0.85
execMethod · 0.65

Tested by

no test coverage detected