MCPcopy Create free account
hub / github.com/bigskysoftware/_hyperscript / resolve

Method resolve

www/js/_hyperscript.js:6092–6125  ·  view source on GitHub ↗
(ctx, { root, from, to, re, count })

Source from the content-addressed store, hash-verified

6090 }
6091 }
6092 resolve(ctx, { root, from, to, re, count }) {
6093 if (root == null) {
6094 ctx.result = root;
6095 return this.findNext(ctx);
6096 }
6097 if (this.variant === "first") {
6098 ctx.result = root.slice(0, count);
6099 } else if (this.variant === "last") {
6100 ctx.result = root.slice(-count);
6101 } else if (this.variant === "random") {
6102 if (count == null) {
6103 ctx.result = root[Math.floor(Math.random() * root.length)];
6104 } else {
6105 var copy = Array.from(root);
6106 var result = [];
6107 for (var i = 0; i < count && copy.length > 0; i++) {
6108 var idx = Math.floor(Math.random() * copy.length);
6109 result.push(copy.splice(idx, 1)[0]);
6110 }
6111 ctx.result = result;
6112 }
6113 } else if (this.variant === "range") {
6114 if (this.range.toEnd) to = root.length;
6115 if (!this.range.includeStart) from++;
6116 if (this.range.includeEnd) to++;
6117 if (to == null) to = from + 1;
6118 ctx.result = root.slice(from, to);
6119 } else if (this.variant === "match") {
6120 ctx.result = new RegExp(re, this.flags).exec(root);
6121 } else {
6122 ctx.result = new RegExpIterable(re, this.flags, root);
6123 }
6124 return this.findNext(ctx);
6125 }
6126 };
6127 var FetchCommand = class _FetchCommand extends Command {
6128 static keyword = "fetch";

Callers

nothing calls this directly

Calls 1

findNextMethod · 0.45

Tested by

no test coverage detected