Module:Storm categories

From Thetacola Wiki
Revision as of 00:22, 15 August 2022 by Thetacola (talk | contribs) (1 revision imported)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

This template is used to control a multitude of tropical cyclone-related templates: {{storm colour}}, {{storm name}}, {{storm sortkey}}, and {{storm icon}}. It acts as a centralized location for storm categories to avoid discrepancies between templates, allowing for the same ID to be used across all related templates.

Data is located in the following submodules:

Usage[edit source]

This module exports three functions for templates: p.color, p.name, p.sortkey, and p.icon. It also provides p._color, p._name, p._sortkey, and p._icon for use in other modules.

All input IDs are case-insensitive, and all non-alphanumeric characters are stripped.

Color[edit source]

Provides the color of the given tropical cyclone category code. This comes in the format of their raw hexadecimal code. This function is available as a template at {{storm colour}}.

Code Output
<span style="padding:4px;border:1px solid black;background-color:#{{#invoke:Storm categories|color|depression}}">depression</span> depression

Name[edit source]

Provides the name of the given tropical cyclone category code. A optional basin argument can be provided as the second argument in order to slightly tweak the name of the category, if the given category definition supports it. This function is available as a template at {{storm name}}.

Code Interpreted Output
ID Basin
{{#invoke:Storm categories|name|severe}} severe (default) Severe tropical storm
{{#invoke:Storm categories|name|spr - cYcL -s TorM}} sprcyclstorm (default) Super cyclonic storm
{{#invoke:Storm categories|name|cat5}} cat5 (default) Category 5-equivalent tropical cyclone
{{#invoke:Storm categories|name|cat5|WPac}} cat5 wpac Category 5-equivalent super typhoon

Sortkey[edit source]

The sortkey is a number that aids in sorting categories. Using the sortkey, it is possible to automatically sort a table of tropical cyclones given their category code. Due to the ambiguous nature of sortkeys, tables may be sorted incorrectly if values from other basins were used. For categories that span multiple basins, however, (e.g. depression and storm) they are given the lowest possible sortkeys in order to achieve maximum compatibility.

This sortkey is used in {{storm sortkey}} and {{Tropical cyclone season effects (cyclone)}}, a subtemplate of {{Tropical cyclone season effects}}.

The sortkey format is as follows. Note that not all values between the given ranges were used. The arrangement of these were determined by their positions in the {{Storm colour}} template.

Basin Sortkey range
Global (unused) 90000 to 99999
Atl/EPac/SAtl 80000 to 89999
WPac 60000 to 69999
Nio 50000 to 59999
Aus/Fiji 40000 to 49999
SWio 30000 to 39999
Historical 20000 to 29999
Global 0 to 9999

A demonstration of a sortable table using these sortkeys can be found below. Note that it does not use categories outside of its own basin (in this case, the Atl/EPac/SAtl basin) and the global range.

Category Sortkey Code
cat3 80,030 {{#invoke:Storm categories|sortkey|cat3}}
cat1 80,010 {{#invoke:Storm categories|sortkey|cat1}}
cat5 80,050 {{#invoke:Storm categories|sortkey|cat5}}
cat4 80,040 {{#invoke:Storm categories|sortkey|cat4}}
depression 90 {{#invoke:Storm categories|sortkey|depression}}
cat2 80,020 {{#invoke:Storm categories|sortkey|cat2}}
Sorting table which uses different basins
Category Sortkey Code
typhoon 60,010 {{#invoke:Storm categories|sortkey|typhoon}}
potential 25 {{#invoke:Storm categories|sortkey|potential}}
cat5 80,050 {{#invoke:Storm categories|sortkey|cat5}}
svrcyclstorm 50,008 {{#invoke:Storm categories|sortkey|svrcyclstorm}}
unknown 0 {{#invoke:Storm categories|sortkey|unknown}}
supertyphoon 80,045 {{#invoke:Storm categories|sortkey|supertyphoon}}
niodepression 50,001 {{#invoke:Storm categories|sortkey|niodepression}}

Icon[edit source]

Icons exist for some Storm categories for presentation purposes. This function is available as a template at {{storm icon}}. p.icon will return wikitext of an image or formatted text.

Full list of available values[edit source]

The following table is generated by invoking the demo function of this module. Some IDs are only available as colors or icons because they existed as parameters on old non-module template implementations and cannot be feasibly aliased to a specific tropical cyclone category.

It will show any color errors, including colors which aren't compliant with the minimal Web Content Accessibility Guidelines 2.0 AA color standards (see MOS:COLOR for more information).

Legend

  1. 1.0 1.1 Overriden from original color (  #5ebaff)
  2. 2.0 2.1 Overriden from original icon (File:Severe tropical storm icon.png)
  3. 3.0 3.1 3.2 Overriden from original icon (TC)
IconIDNameColorSortkey
BasinNameBasinSortkey
File:Aus 1 icon.pngaus1Category 1 tropical cyclone#00faf4Aus/Fiji40006
File:Aus 2 icon.pngaus2Category 2 tropical cyclone#B4FDA8Aus/Fiji40008
File:Aus 3 icon.pngaus3Category 3 severe tropical cyclone#FFD821Aus/Fiji40010
File:Aus 4 icon.pngaus4Category 4 severe tropical cyclone#FF6060[W 1]Aus/Fiji40013
File:Aus 5 icon.pngaus5Category 5 severe tropical cyclone#C464D9[W 1]Aus/Fiji40015
TCbeaufort0Calm (Force 0)#FFFFFFGlobal1500
TCbeaufort1Light Air (Force 1)#757575[W 1][W 2]Global1510
TCbeaufort10Storm (Force 10)#AAFD9CGlobal1600
TCbeaufort11Violent Storm (Force 11)#D6FFA4Global1610
TCbeaufort12Hurricane-force (Force 12)#FFFCD1Global1620
TCbeaufort2Light Breeze (Force 2)#909090[W 1]Global1520
TCbeaufort3Gentle Breeze (Force 3)#B7B7B7[W 1]Global1530
TCbeaufort4Moderate Breeze (Force 4)#D2D2D2Global1540
TCbeaufort5Fresh Breeze (Force 5)#F1F1F1Global1550
TCbeaufort6Strong Breeze (Force 6)#007FCE[W 1][W 2]Global1560
TCbeaufort7Near Gale (Force 7)#46A1FF[W 1]Global1570
TCbeaufort8Gale (Force 8)#5EDBF8Global1580
TCbeaufort9Strong Gale (Force 9)#3BFDFDGlobal1590
File:Category 1 hurricane icon.pngcat1atlCategory 1 hurricane#fff795Atl/EPac/SAtl80010
defaultCategory 1-equivalent tropical cyclone
epacCategory 1 hurricane
satlCategory 1 hurricane
wpacCategory 1-equivalent typhoon
File:Category 2 hurricane icon.pngcat2atlCategory 2 hurricane#ffd821Atl/EPac/SAtl80020
defaultCategory 2-equivalent tropical cyclone
epacCategory 2 hurricane
satlCategory 2 hurricane
wpacCategory 2-equivalent typhoon
File:Category 3 hurricane icon.pngcat3atlCategory 3 hurricane#ff8f20[W 1]Atl/EPac/SAtl80030
defaultCategory 3-equivalent tropical cyclone
epacCategory 3 hurricane
satlCategory 3 hurricane
wpacCategory 3-equivalent typhoon
File:Category 4 hurricane icon.pngcat4atlCategory 4 hurricane#ff6060[W 1]Atl/EPac/SAtl80040
defaultCategory 4-equivalent tropical cyclone
epacCategory 4 hurricane
satlCategory 4 hurricane
wpacCategory 4-equivalent typhoon
File:Category 5 hurricane icon.pngcat5atlCategory 5 hurricane#c464d9[W 1]Atl/EPac/SAtl80050
defaultCategory 5-equivalent tropical cyclone
epacCategory 5 hurricane
satlCategory 5 hurricane
wpacCategory 5-equivalent super typhoon
File:Cyclonic storm icon.pngcsCyclonic storm#00faf4NIO50006
File:Cyclonic storm icon.pngcyclstormCyclonic storm#00faf4NIO50006
File:Tropical Depression.pngdTropical depression#80ccff[1]Global90
File:Deep depression icon.pngddDeep depression#5ebaff[W 1]NIO50002
File:Deep depression icon.pngdeepdepressionDeep depression#5ebaff[W 1]NIO50002
File:Tropical Depression.pngdepressionTropical depression#5ebaff[W 1]Global90
File:Disturbance icon.pngdiTropical disturbance#72a9cd[W 1]Global80
File:Disturbance icon.pngdisturbanceTropical disturbance#72a9cd[W 1]Global80
File:Ef-scale0.pngef0EF0 tornado#00faf4Global1000
File:Ef-scale1.pngef1EF1 tornado#FFF795Global1010
File:Ef-scale2.pngef2EF2 tornado#FFD821Global1020
File:Ef-scale3.pngef3EF3 tornado#FF8F20[W 1]Global1030
File:Ef-scale4.pngef4EF4 tornado#ff6060[W 1]Global1040
File:Ef-scale5.pngef5EF5 tornado#C464D9[W 1]Global1050
File:Ef-scaleU.pngefuEFU tornado#ccccccGlobal1001
File:Extremely severe cyclonic storm icon.pngescsExtremely severe cyclonic storm#ff6060[W 1]NIO50015
File:Extremely severe cyclonic storm icon.pngesvrcyclstormExtremely severe cyclonic storm#ff6060[W 1]NIO50015
File:Extratropical cyclone icon.pngetExtratropical cyclone#ccccccGlobal50
File:Extratropical cyclone icon.pngexExtratropical cyclone#ccccccGlobal50
File:Extratropical cyclone icon.pngextratropicalExtratropical cyclone#ccccccGlobal50
TCf0Calm (Force 0)#FFFFFFGlobal1500
TCf1Light Air (Force 1)#757575[W 1][W 2]Global1510
TCf10Storm (Force 10)#AAFD9CGlobal1600
TCf11Violent Storm (Force 11)#D6FFA4Global1610
TCf12Hurricane-force (Force 12)#FFFCD1Global1620
TCf2Light Breeze (Force 2)#909090[W 1]Global1520
TCf3Gentle Breeze (Force 3)#B7B7B7[W 1]Global1530
TCf4Moderate Breeze (Force 4)#D2D2D2Global1540
TCf5Fresh Breeze (Force 5)#F1F1F1Global1550
TCf6Strong Breeze (Force 6)#007FCE[W 1][W 2]Global1560
TCf7Near Gale (Force 7)#46A1FF[W 1]Global1570
TCf8Gale (Force 8)#5EDBF8Global1580
TCf9Strong Gale (Force 9)#3BFDFDGlobal1590
File:Aus 1 icon.pngfiji1Category 1 tropical cyclone#00faf4Aus/Fiji40006
File:Aus 2 icon.pngfiji2Category 2 tropical cyclone#B4FDA8Aus/Fiji40008
File:Aus 3 icon.pngfiji3Category 3 severe tropical cyclone#FFD821Aus/Fiji40010
File:Aus 4 icon.pngfiji4Category 4 severe tropical cyclone#FF6060[W 1]Aus/Fiji40013
File:Aus 5 icon.pngfiji5Category 5 severe tropical cyclone#C464D9[W 1]Aus/Fiji40015
File:Intense tropical cyclone icon.pngintenseIntense tropical cyclone#FF6060[W 1]SWIO30008
File:Intense tropical cyclone icon.pngitcIntense tropical cyclone#FF6060[W 1]SWIO30008
File:Land depression icon.pnglandLand depression#72a9cd[W 1]NIO50000
File:Land depression icon.pnglanddepressionLand depression#72a9cd[W 1]NIO50000
File:Land depression icon.pngldLand depression#72a9cd[W 1]NIO50000
File:Tropical Low.pnglowTropical low#5ebaff[W 1]Aus/Fiji40002
File:Monsoon Depression icon.pngmdMonsoon depression#5ebaff[W 1]Global30
TCmoddepressionModerate tropical depression#5ebaff[W 1]Global95
File:Monsoon Depression icon.pngmonsoondepressionMonsoon depression#5ebaff[W 1]Global30
File:Moderate tropical storm icon.pngmstormModerate tropical storm#00faf4SWIO30004
File:Moderate tropical storm icon.pngmtsModerate tropical storm#00faf4SWIO30004
File:Moderate tropical storm icon.pngmtstormModerate tropical storm#00faf4Global105
File:Cyclonic storm icon.pngniocycloneCyclonic storm#00faf4NIO50006
File:Depression icon.pngniodepressionDepression#72a9cd[W 1]NIO50001
File:Land depression icon.pngniolandLand depression#72a9cd[W 1]NIO50000
File:Tropical Depression.pngnwpdepressionTropical depression#5ebaff[W 1]Global90
File:Severe tropical storm icon.pngnwpsevereSevere tropical storm#b4fda8Global120
File:Tropical storm icon.pngnwpstormTropical storm#00faf4Global100
File:Depression icon.pngodOverland depression#5ebaff[W 1]Global60
File:Depression icon.pngoverlandOverland depression#5ebaff[W 1]Global60
File:Depression icon.pngoverlanddepressionOverland depression#5ebaff[W 1]Global60
File:Post tropical cyclone icon.pngpostPost-tropical depression#ccccccGlobal70
File:Post tropical cyclone icon.pngposttropicalPost-tropical depression#ccccccGlobal70
File:Potential tropical cyclone icon.pngpotentialPotential tropical cyclone#72a9cd[W 1]Global25
File:Potential tropical cyclone icon.pngpotentialtropicalcyclonePotential tropical cyclone#72a9cd[W 1]Global25
File:Potential tropical cyclone icon.pngptPotential tropical cyclone#72a9cd[W 1]Global25
File:Remnant low icon.pngremnantPost-tropical depression#ccccccGlobal70
File:Remnant low icon.pngremnantlowPost-tropical depression#ccccccGlobal70
File:Remnant low icon.pngrlPost-tropical depression#ccccccGlobal70
File:RsiC0.pngrsi0Category 0 "Nuisance"#ccccccAtl/EPac/SAtl80100
File:RsiC1.pngrsi1Category 1 "Notable"#FFF795Atl/EPac/SAtl80110
File:RsiC2.pngrsi2Category 2 "Minor"#FFD821Atl/EPac/SAtl80120
File:RsiC3.pngrsi3Category 3 "Major"#FF8F20[W 1]Atl/EPac/SAtl80130
File:RsiC4.pngrsi4Category 4 "Crippling"#FF6060[W 1]Atl/EPac/SAtl80140
File:RsiC5.pngrsi5Category 5 "Extreme"#C464D9[W 1]Atl/EPac/SAtl80150
File:RsiC4.pngrsicripplingCategory 4 "Crippling"#FF6060[W 1]Atl/EPac/SAtl80140
File:RsiC5.pngrsiextremeCategory 5 "Extreme"#C464D9[W 1]Atl/EPac/SAtl80150
File:RsiC3.pngrsimajorCategory 3 "Major"#FF8F20[W 1]Atl/EPac/SAtl80130
File:RsiC2.pngrsiminorCategory 2 "Minor"#FFD821Atl/EPac/SAtl80120
File:RsiC1.pngrsinotableCategory 1 "Notable"#FFF795Atl/EPac/SAtl80110
File:RsiC0.pngrsinuisanceCategory 0 "Nuisance"#ccccccAtl/EPac/SAtl80100
File:Severe cyclonic storm icon.pngscsSevere cyclonic storm#b4fda8NIO50008
File:Subtropical Depression icon.pngsdSubtropical depression#5ebaff[W 1]Global62
File:Severe tropical storm icon.pngsevereSevere tropical storm#b4fda8Global120
TCseveredepSevere tropical depression#5ebaff[W 1]Global120
File:Severe tropical storm icon.pngseveretsSevere tropical storm#b4fda8Global120
File:Tropical Depression.pngshdepressionTropical depression#5ebaff[W 1]Global90
TCshem1Tropical cyclone#00faf4Historical20008
TCshem2Tropical cyclone#ccffffHistorical20008
TCshem3Tropical cyclone#FFD821SWIO30006
TCshem4Tropical cyclone#ffc140Historical20008
TCshem5Severe tropical cyclone#ff6060[W 1]Historical20010
File:Tropical Depression.pngshemdepressionTropical depression#5ebaff[W 1]Global90
TCshemsvrtcSevere tropical cyclone#ffe775Historical20020
TCshemtcTropical cyclone#FFD821SWIO30006
File:Tropical Depression.pngspdepressionTropical depression#5ebaff[W 1]Global90
File:Super cyclonic storm icon.pngsprcyclstormSuper cyclonic storm#c464d9[W 1]NIO50020
File:Subtropical storm icon.pngssSubtropical storm#00faf4Global65
File:Tropical storm icon.pngstormTropical storm#00faf4Global100
File:Severe tropical storm icon.pngstrongSevere tropical storm#b4fda8Global120
File:Severe tropical storm icon.pngstsSevere tropical storm#b4fda8Global120
TCstyCategory 4 super typhoon#c464d9[W 1]Atl/EPac/SAtl80045
TCstyphoonSupertyphoon#C464D9[W 1]WPAC60050
File:Moderate tropical storm icon.pngsubModerate tropical storm#00faf4SWIO30004
File:Subtropical Depression icon.pngsubdepressionSubtropical depression#5ebaff[W 1]Global62
File:Disturbance icon.pngsubdisturbanceSubtropical disturbance#72a9cd[W 1]Global55
TCsublowSubtropical low#5ebaff[W 1]Aus/Fiji40000
File:Subtropical storm icon.pngsubtropicalSubtropical storm#00faf4Global65
TCsubtropicalcycloneSubtropical cyclone#00faf4Global70
File:Super cyclonic storm icon.pngsucsSuper cyclonic storm#c464d9[W 1]NIO50020
TCsupertyphoonCategory 4 super typhoon#c464d9[W 1]Atl/EPac/SAtl80045
File:Severe cyclonic storm icon.pngsvrcyclstormSevere cyclonic storm#b4fda8NIO50008
TCsvtyphoonSevere typhoon#FF6060[W 1]WPAC60015
File:Tropical Depression.pngswiodepressionTropical depression#5ebaff[W 1]Global90
File:Disturbance icon.pngswiodisturbanceTropical disturbance#72a9cd[W 1]Global80
File:Severe tropical storm south icon.png[2]swiostsSevere tropical storm#b4fda8Global120
File:SWIO tropical cyclone icon.png[3]swiotcTropical cyclone#FFD821SWIO30006
File:Subtropical Depression icon.pngswsubdepSubtropical depression#5ebaff[W 1]Global62
File:SWIO tropical cyclone icon.png[3]tcTropical cyclone#FFD821SWIO30006
File:Tropical Depression.pngtdTropical depression#5ebaff[W 1]Global90
File:Disturbance icon.pngtdistTropical disturbance#72a9cd[W 1]Global80
File:Tropical Low.pngtlTropical low#5ebaff[W 1]Aus/Fiji40002
TCtropicalcycloneTropical cyclone#FFD821SWIO30006
File:Tropical storm icon.pngtsTropical storm#00faf4Global100
File:Typhoon icon.pngtyTyphoon#FFD821WPAC60010
File:Typhoon icon.pngtyphoonTyphoon#FFD821WPAC60010
?unknownUnknown strength tropical cyclone#c0c0c0Global0
File:Very intense tropical cyclone icon.pngvintenseVery intense tropical cyclone#C464D9[W 1]SWIO30010
File:Very intense tropical cyclone icon.pngvitcVery intense tropical cyclone#C464D9[W 1]SWIO30010
TCvityViolent typhoon#C464D9[W 1]WPAC60030
TCvityphoonViolent typhoon#C464D9[W 1]WPAC60030
File:Very severe cyclonic storm icon.pngvscsVery severe cyclonic storm#ffd821NIO50010
TCvstyVery strong typhoon#FF6060[W 1]WPAC60020
TCvstyphoonVery strong typhoon#FF6060[W 1]WPAC60020
File:Very severe cyclonic storm icon.pngvsvrcyclstormVery severe cyclonic storm#ffd821NIO50010
File:RsiC0.pngwssi0No impacts#ccccccAtl/EPac/SAtl80200
File:RsiC1.pngwssi1Limited impacts#80ccffAtl/EPac/SAtl80210
File:RsiC2.pngwssi2Minor impacts#ffc140Atl/EPac/SAtl80220
File:RsiC3.pngwssi3Moderate impacts#ff8f20[W 1]Atl/EPac/SAtl80230
File:RsiC4.pngwssi4Major impacts#ff6060[W 1]Atl/EPac/SAtl80240
File:RsiC5.pngwssi5Extreme impacts#cf75ff[W 1]Atl/EPac/SAtl80250
File:RsiC5.pngwssiextremeExtreme impacts#cf75ff[W 1]Atl/EPac/SAtl80250
File:RsiC1.pngwssilimitedLimited impacts#80ccffAtl/EPac/SAtl80210
File:RsiC4.pngwssimajorMajor impacts#ff6060[W 1]Atl/EPac/SAtl80240
File:RsiC2.pngwssiminorMinor impacts#ffc140Atl/EPac/SAtl80220
File:RsiC3.pngwssimoderateModerate impacts#ff8f20[W 1]Atl/EPac/SAtl80230
File:RsiC0.pngwssinoneNo impacts#ccccccAtl/EPac/SAtl80200
File:Disturbed weather icon.pngzodwZone of disturbed weather#72A9CD[W 1]SWIO30000
File:Category 1 hurricane icon.png1not available#fff795not available
File:Category 2 hurricane icon.png2not available#ffd821not available
File:Category 3 hurricane icon.png3not available#ff8f20[W 1]not available
File:Category 4 hurricane icon.png4not available#ff6060[W 1]not available
File:Category 5 hurricane icon.png5not available#c464d9[W 1]not available
File:Aus 1 icon.pnga1not available#00faf4not available
File:Aus 2 icon.pnga2not available#B4FDA8not available
File:Aus 3 icon.pnga3not available#FFD821not available
File:Aus 4 icon.pnga4not available#FF6060[W 1]not available
File:Aus 5 icon.pnga5not available#C464D9[W 1]not available
File:Extratropical storm icon.pnget2not available
File:Extratropical storm icon.pngex2not available
File:Extratropical storm icon.pngextratropical2not available
File:Severe tropical storm south icon.pngstssnot available

Warnings

This table contains warnings than should be addressed. Please note that some warnings cannot be fully addressed without changes that would require consensus.

  1. 1.00 1.01 1.02 1.03 1.04 1.05 1.06 1.07 1.08 1.09 1.10 1.11 1.12 1.13 1.14 1.15 1.16 1.17 1.18 1.19 1.20 1.21 1.22 1.23 1.24 1.25 1.26 1.27 1.28 1.29 1.30 1.31 1.32 1.33 1.34 1.35 1.36 1.37 1.38 1.39 1.40 1.41 1.42 1.43 1.44 1.45 1.46 1.47 1.48 1.49 1.50 1.51 1.52 1.53 1.54 1.55 1.56 1.57 1.58 1.59 1.60 1.61 1.62 1.63 1.64 1.65 1.66 1.67 1.68 1.69 1.70 1.71 1.72 1.73 1.74 1.75 1.76 1.77 1.78 1.79 1.80 1.81 1.82 1.83 1.84 1.85 1.86 1.87 1.88 1.89 1.90 This color has contrast issues with links (not WCAG 2.0 AA-compatible). It should not be used in conjunction with a link.
  2. 2.0 2.1 2.2 2.3 2.4 This color has contrast issues with visited links (not WCAG 2.0 AA-compatible with #0b0080). It should not be used in conjunction with a visited link.

local categoryData = require("Module:Storm categories/categories")
local colors = require("Module:Storm categories/colors").colors
local icons = require("Module:Storm categories/icons").icons
local cats = categoryData.cats
local defaultCategory = categoryData.defaultCategory
local p = {}

function p.color(frame)
	return p._color(frame.args[1] or frame:getParent().args[1], false)
end

function p.name(frame)
	return p._name(
		frame.args[1] or frame:getParent().args[1],
		frame.args[2] or frame:getParent().args[2],
		false
	)
end

function p.sortkey(frame)
	return p._sortkey(frame.args[1] or frame:getParent().args[1], false)
end

function p.icon(frame)
	return p._icon(frame.args[1] or frame:getParent().args[1], false)
end

function p._color(colorCode, nullIfMissing)
	-- This looks confusing, but it's actually nested ternaries (for nil checks)
	local color = (colorCode ~= nil and string.len(colorCode) ~= 0) and 
		string.gsub(string.lower(colorCode), "[^%w]", "")
		or defaultCategory
		
	return colors[color] or ((cats[color] or (
		nullIfMissing
		and { color = nil }
		or cats[defaultCategory]
	)).color)
end

function p._name(category, basin, nullIfMissing)
	local name_def = (cats[
		(category ~= nil and string.len(category) ~= 0) and 
			string.gsub(string.lower(category), "[^%w]", "")
			or defaultCategory
	] or cats[defaultCategory]).name
	return type(name_def) == "table" and 
		(
			name_def[string.lower(basin or "default")]
			or name_def["default"]
			or (nullIfMissing and nil or error("No default name for basin-based category name."))
		) 
		or name_def
end

function p._sortkey(category, nullIfMissing)
	-- This looks confusing, but it's actually nested ternaries (for nil checks)
	return (cats[
		(category ~= nil and string.len(category) ~= 0) and 
			string.gsub(string.lower(category), "[^%w]", "")
			or defaultCategory
	] or (nullIfMissing and { sortkey = nil } or cats[defaultCategory])).sortkey
end

function p._icon(iconCode, nullIfMissing)
	-- This looks confusing, but it's actually nested ternaries (for nil checks)
	local icon = (iconCode ~= nil and string.len(iconCode) ~= 0) and 
		string.gsub(string.lower(iconCode), "[^%w]", "")
		or defaultCategory
		
	return icons[icon] or (cats[icon] ~= nil and (
		cats[icon].icon or cats["tropicalcyclone"].icon
	) or (nullIfMissing and nil or cats[defaultCategory].icon))
end

function p.demo(frame)
	return require("Module:Storm categories/demo").demo(frame)
end

return p