Module:Util/strings/split/Documentation/Spec: Difference between revisions

From Zelda Wiki, the Zelda encyclopedia
Jump to navigation Jump to search
(Created page with "local p = {} function p.Schemas() return { str = { type = "string", required = true, }, pattern = { type = "string", default = mw.dumpObject("%s*,%s*"), } } end function p.Documentation() return { desc = "A performant alternative to {{Scribunto Manual|lib=mw.text.split}}.", params = {"str", "pattern", "plain"}, returns = "A <code>table</code> of the split strings.", cases = { {...")
 
No edit summary
 
Line 17: Line 17:
return {
return {
desc = "A [[gphelp:Extension:Scribunto#mw.text.split is very slow|performant alternative]] to  {{Scribunto Manual|lib=mw.text.split}}.",
desc = "A [[gphelp:Extension:Scribunto#mw.text.split is very slow|performant alternative]] to  {{Scribunto Manual|lib=mw.text.split}}.",
params = {"str", "pattern", "plain"},
params = {"str", "pattern"},
returns = "A <code>table</code> of the split strings.",
returns = "A <code>table</code> of the split strings.",
cases = {
cases = {

Latest revision as of 21:17, 5 May 2024

Documentation for this module may be created at Module:Util/strings/split/Documentation/Spec/Documentation

local p = {}

function p.Schemas()
	return {
		str = {
			type = "string",
			required = true,
		},
		pattern = {
			type = "string",
			default = mw.dumpObject("%s*,%s*"),
		}
	}
end

function p.Documentation()
	return {
		desc = "A [[gphelp:Extension:Scribunto#mw.text.split is very slow|performant alternative]] to  {{Scribunto Manual|lib=mw.text.split}}.",
		params = {"str", "pattern"},
		returns = "A <code>table</code> of the split strings.",
		cases = {
			{
				args = {" foo,    bar,baz "},
				expect = {" foo", "bar", "baz "},
			},
			{
				args = {"foo bar baz", " "},
				expect = {"foo", "bar", "baz"},
			},
			{
				desc = "Support for Unicode strings",
				args = {"アイウエオ", ""},
				expect = {"ア","イ","ウ","エ","オ"},
			},
			{
				args = {"グタンバチの祠, インイサの祠"},
				expect = {"グタンバチの祠", "インイサの祠"},
			}
		}
	}
end

return p