Created
August 29, 2018 16:01
-
-
Save samdenty/72b29483131bf9c13977fce758b57b26 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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