MCPcopy
hub / github.com/arfct/itty-bitty / m

Function m

docs/render/recipe.js:253–284  ·  view source on GitHub ↗
(selector, ...args)

Source from the content-addressed store, hash-verified

251}
252
253const m = (selector, ...args) => {
254 var attrs = (args[0] && typeof args[0] === 'object' && !Array.isArray(args[0]) && !(args[0] instanceof HTMLElement)) ? args.shift() : {};
255
256 let classes = selector.split(".");
257 if (classes.length > 0) selector = classes.shift();
258 if (classes.length) attrs.className = classes.join(" ")
259
260 let id = selector.split("#");
261 if (id.length > 0) selector = id.shift();
262 if (id.length) attrs.id = id[0];
263
264 var node = document.createElement(selector.length > 0 ? selector : "div");
265 for (let prop in attrs) {
266 if (attrs.hasOwnProperty(prop) && attrs[prop] != undefined) {
267 if (prop.indexOf("data-") == 0) {
268 let dataProp = prop.substring(5).replace(/-([a-z])/g, function(g) { return g[1].toUpperCase(); });
269 node.dataset[dataProp] = attrs[prop];
270 } else {
271 node[prop] = attrs[prop];
272 }
273 }
274 }
275
276 const append = (child) => {
277 if (Array.isArray(child)) return child.forEach(append);
278 if (typeof child == "string") child = document.createTextNode(child);
279 if (child) node.appendChild(child);
280 };
281 args.forEach(append);
282
283 return node;
284};
285
286function clean(html) {
287 if (!html) return;

Callers 3

ingredientElFunction · 0.70
renderFunction · 0.70
renderInstructionsFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected