Skip to content

Instantly share code, notes, and snippets.

@samdenty
Created August 29, 2018 16:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samdenty/72b29483131bf9c13977fce758b57b26 to your computer and use it in GitHub Desktop.
Save samdenty/72b29483131bf9c13977fce758b57b26 to your computer and use it in GitHub Desktop.
(function getCompletions(type) {
let object;
if (type === "string") object = new String("");
else if (type === "number") object = new Number(0);
else if (type === "bigint") object = Object(BigInt(0));
else if (type === "boolean") object = new Boolean(false);
else object = this;
const result = [];
try {
for (let o = object; o; o = Object.getPrototypeOf(o)) {
if (
(type === "array" || type === "typedarray") &&
o === object &&
o.length > 9999
)
continue;
const group = { items: [], __proto__: null };
try {
if (typeof o === "object" && o.constructor && o.constructor.name)
group.title = o.constructor.name;
} catch (ee) { }
result[result.length] = group;
const names = Object.getOwnPropertyNames(o);
const isArray = Array.isArray(o);
for (let i = 0; i < names.length && group.items.length < 10000; ++i) {
if (isArray && /^[0-9]/.test(names[i])) continue;
group.items[group.items.length] = names[i];
}
}
} catch (e) { }
return result;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment