% These sourcemap declarations allow for .bib file oddities. Additionally, to comport with MLA expectations, they modify strings in publisher fields, drop unneeded parts of URLs, and look for patterns in a URL field to fill in missing eprint fields. If the choices here seem to do too much, use "style=mla-strict", which makes fewer accommodations and more exactly prints entries as they're defined in a given bibtex file.
\ProvidesFile{mla.bbx}[2022/02/22 v2.1a biblatex bibliography style]

\RequireBibliographyStyle{mla-strict}

\DeclareStyleSourcemap{ 
    \maps[datatype=bibtex]{
      \map[overwrite=true]{% Convert non-integer year field to addendum field
           \step[fieldsource=year, match=\regexp{[a-zA-Z]}, final]
		   \step[fieldsource=year, match=\regexp{(.+)}, final]
		   \step[fieldset=addendum, fieldvalue=\regexp{$1}]
		   \step[fieldset=year, null]
	  }
	  \map{% Convert unpublished booktitle to title, with entrysubtype "book"
	      \pertype{unpublished}
	        \step[notfield=title, final]
		    \step[fieldsource=booktitle, match=\regexp{(.+)}, final]
			\step[fieldset=title, fieldvalue=\regexp{$1}, final]
			\step[fieldset=booktitle, null]
			\step[fieldset=entrysubtype, fieldvalue={book}]
	  }
	  \map{% Add italics to app names for videos, movies, music, audio
	      \pertype{video}
		    \step[fieldsource=addendum, notmatch=\regexp{mkbibemph}, final]
		    \step[fieldsource=addendum, match=\regexp{(.+)\s+app$}, replace={\\mkbibemph\{$1\} app}]
	  }
	  \map{% Add italics to app names for videos, movies, music, audio
	      \pertype{movie}
		    \step[fieldsource=addendum, notmatch=\regexp{mkbibemph}, final]
		    \step[fieldsource=addendum, match=\regexp{(.+)\s+app$}, replace={\\mkbibemph\{$1\} app}]
	  }
	  \map{% Add italics to app names for videos, movies, music, audio
	      \pertype{music}
		    \step[fieldsource=addendum, notmatch=\regexp{mkbibemph}, final]
		    \step[fieldsource=addendum, match=\regexp{(.+)\s+app$}, replace={\\mkbibemph\{$1\} app}]
	  }
	  \map{% Add italics to app names for videos, movies, music, audio
	      \pertype{audio}
		    \step[fieldsource=addendum, notmatch=\regexp{mkbibemph}, final]
		    \step[fieldsource=addendum, match=\regexp{(.+)\s+app$}, replace={\\mkbibemph\{$1\} app}]
	  }
	  \map{% Add italics to app names for software
	      \pertype{software}
		    \step[fieldsource=maintitle, notmatch=\regexp{mkbibemph}, final]
		    \step[fieldsource=maintitle, match=\regexp{(.+)\s+app$}, replace={$1 \\mkbibemph\{app\}}]
	  }
	  \map{% Accommodate music albums defined simply
	      \pertype{music}
		    \step[notfield=title, final]
		    \step[fieldsource=booktitle, match=\regexp{(.+)}, final]
			\step[fieldset=title, fieldvalue=\regexp{$1}, final]
			\step[fieldset=booktitle, null]
			\step[fieldset=entrysubtype, fieldvalue={album}]
	  }
	  \map{% Fill in missing publisher for US patents
	      \pertype{patent}
	        \step[notfield=publisher, final]
		    \step[fieldsource=type, match=\regexp{patentus}, final]
			\step[fieldset=publisher, fieldvalue={United States Patent and Trademark Office}]
	  }
	  \map[overwrite=true]{% force consistent abbreviations for editions
           \step[fieldsource=edition, match={edition}, replace={ed.}]
	  }
	  \map[overwrite=true]{% drop unnecessary elements of company names ("and" suggests list)
           \step[fieldsource=publisher, match={and Company}, replace={}]
		   \step[fieldsource=publisher, match={and Co.}, replace={}]
	  }
      \map{% abbreviate and drop unneeded parts of publisher names
           \step[fieldsource=publisher, match={University Press}, replace={UP}]
           \step[fieldsource=publisher, match={University}, replace={U}]
           \step[fieldsource=publisher, match=\regexp{Press\b}, replace={P}]
		   \step[fieldsource=publisher, match=\regexp{Corporation|Corp.|Incorporated|Inc.|Limited|Ltd.}, replace={}]
		   % \step[fieldsource=url, match=\regexp{http(s)?://}, replace={}]
          }
      \map{% abbreviate and drop unneeded parts of institutions
           \step[fieldsource=institution, match={University}, replace={U}]
           \step[fieldsource=school, match={University}, replace={U}]
          }
      \map{% JSTOR url to eprint
		   \step[fieldsource=url, match={jstor.org}, final]
		   \step[fieldset=eprint, fieldvalue={JSTOR}]
		   % \step[fieldset=urldate, null]
          }
      \map{% Project Muse url to eprint
		   \step[fieldsource=url, match={muse.jhu.edu}, final]
		   \step[fieldset=eprint, fieldvalue={Project Muse}]
		   % \step[fieldset=urldate, null]
          }
      \map{% Adelaide eBooks url to eprint
		   \step[fieldsource=url, match={ebooks.adelaide.edu.au}, final]
		   \step[fieldset=eprint, origfieldval]
		   \step[fieldset=eprinttype, fieldvalue={adelaide}]
		   % \step[fieldset=urldate, null]
          }
      \map{% Google Books url to eprint
		   \step[fieldsource=url, match={books.google}, final]
		   \step[fieldset=eprint, fieldvalue={Google Books}]
		   % \step[fieldset=urldate, null]
          }
      \map{% EBSCO - Academic Search Complete url to eprint
		   \step[fieldsource=url, match={db=a9h}, final]
		   \step[fieldset=eprint, fieldvalue={Academic Search Complete}]
		   % \step[fieldset=urldate, null]
          }
      \map{% EBSCO - LexisNexis Academic url to eprint
		   \step[fieldsource=url, match={db=fdcaae48}, final]
		   \step[fieldset=eprint, fieldvalue={LexisNexis Academic}]
		   % \step[fieldset=urldate, null]
          }
      \map{% EBSCO - MLA Database url to eprint
		   \step[fieldsource=url, match={db=mzh}, final]
		   \step[fieldset=eprint, fieldvalue={MLA International Bibliography}]
		   % \step[fieldset=urldate, null]
          }
      \map{% USPTO url to eprint
		   \step[fieldsource=url, match={patft.uspto.gov}, final]
		   \step[fieldset=eprint, fieldvalue={USPTO Patent Full-Text and Image Database}]
          }
      \map{% DOI url to doi
           \step[fieldsource=url, match=\regexp{dx.doi.org/(.+)}, fieldtarget=doi]
           \step[fieldsource=doi, match=\regexp{http(s)?://dx.doi.org/(.+)}, replace=\regexp{$1}]
           \step[fieldsource=doi, match=\regexp{dx.doi.org/(.+)}, replace=\regexp{$1}]
          }
		   %       \map{% doi to url when eprinttype set and url empty
		   %            \step[notfield=url, final]
		   % \step[field=eprinttype, final]
		   % \step[field=doi, final]
		   %            \step[fieldsource=doi, fieldtarget=url]
		   %            \step[fieldsource=url, match=\regexp{(.+)}, replace=\regexp{https://doi.org/$1}]
		   %            \step[fieldset=doi, null]
		   %           }
      \map{ % remove isbns from Works Cited
           \step[fieldsource=isbn, final]
           \step[fieldset=isbn, null]
          }		  
      \map{ % remove url + urldate field from all entries that have a doi field
           \step[fieldsource=doi, final]
           \step[fieldset=url, null]
           \step[fieldset=urldate, null]
          }
      \map[overwrite]{ % clean url + urldate field from all entries that have a doi field
		   \step[fieldsource=url, match=\regexp{http(s)?://}, replace={}]
          }
    }      
}

\endinput
