User:Erutuon/scripts/GadgetsDefinitionParser.js

Hello, you have come here looking for the meaning of the word User:Erutuon/scripts/GadgetsDefinitionParser.js. In DICTIOUS you will not only get to know all the dictionary meanings for the word User:Erutuon/scripts/GadgetsDefinitionParser.js, but we will also tell you about its etymology, its characteristics and you will know how to say User:Erutuon/scripts/GadgetsDefinitionParser.js in singular and plural. Everything you need to know about the word User:Erutuon/scripts/GadgetsDefinitionParser.js you have here. The definition of the word User:Erutuon/scripts/GadgetsDefinitionParser.js will help you to be more precise and correct when speaking or writing your texts. Knowing the definition ofUser:Erutuon/scripts/GadgetsDefinitionParser.js, as well as those of other words, enriches your vocabulary and provides you with more and better linguistic resources.
// Could use this in the gadgets-definition script to grab list of dependencies
// and then generate an explanation of how to copy the gadget to your userspace
// and make changes, with mw.loader.using(dependencies, function() { /* gadget text here */ });
// or mw.loader.using(dependencies, function() { importScript("the userspace page where you put your copy of the gadget"); });.
new mw.Api()
	.get({
		"action": "expandtemplates",
		"title": "MediaWiki:Gadgets-definition",
		"prop": "wikitext",
		"text": "{{MediaWiki:Gadgets-definition}}"
	})
	.then(obj => obj.expandtemplates.wikitext
		.split("\n")
		.filter(line => line.startsWith("*"))
		.map(line => {
			const splitTrim = (list, sep) => list.split(sep).map(s => s.trim());
			const  = splitTrim(line.replace(/^\*\s*/, ""), "[");
			const  = splitTrim(rest, "]");
			const optionObj = {};
			for (const option of splitTrim(options, "|")) {
				const keyValue = splitTrim(option, "=");
				const value = keyValue;
				if (value) {
					const key = keyValue;
					// See ].
					// "type" and "supportsUrlLoad" have single values,
					// while others have an array with comma separators.
					optionObj =
						key === "type" || key === "supportsUrlLoad" ?
						value :
						splitTrim(value);
				} else {
					optionObj] = true;
				}
			}
			return {
				name,
				options: optionObj,
				pages: pages.split("|").filter(page => page.trim() !== "").map(page => "MediaWiki:Gadget-" + page)
			};
		}))
		// .then(console.log).fail(console.error)
		;