User:Bobblewik/monobook.js/unitformatter.js: Difference between revisions

Content deleted Content added
Bobblewik (talk | contribs)
mNo edit summary
Bobblewik (talk | contribs)
mNo edit summary
Line 12:
txt.value = txt.value.replace(/°\s?(celsius)/gi, '°C');
txt.value = txt.value.replace(/(\d)\s?(°[CF])/g, '$1 $2');
 
//Fix Celsius spelling errors
txt.value = txt.value.replace(/celsius/gi, 'Celsius');
txt.value = txt.value.replace(/celcius/gi, 'Celsius');
Line 22 ⟶ 23:
txt.value = txt.value.replace(/³/g, '³');
 
// kilowattsohm
// Convert the word ohm(s) or the html entity into the actual Ω symbol (Omega, not the actual ohm symbol Ω) and make sure it is spaced
txt.value = txt.value.replace(/(\d)\s?(Y|Z|E|P|T|G|M|k|K|h|da|d|c|m|µ|μ|µ|n|p|f|a|z|y)?\s?(Ω|ohm|Ohm)s?([\s,.;:\)\(\\/)])/g, '$1 $2Ω$4');
 
Line 37 ⟶ 38:
txt.value = txt.value.replace(/(\d)\-(Y|Z|E|P|T|G|M|k|K|h|da|d|c|m|µ|μ|µ|n|p|f|a|z|y)?hz/gi, '$1 $2Hz');
 
//metre: space before 'm' only when lower case
// Fix kilometres
txt.value = txt.value.replace(/(\d)\s?kms?m([\s,.;:\)\(\\/)]W)/gig, '$1 kmm$2');
txt.value = txt.value.replace(/(\d)\-kms?m([\s,.;:\)\(\\/)]W)/gig, '$1 kmm$2');
txt.value = txt.value.replace(/(\d) kms?([\s,.;:\)\(\\/)])/gi, '$1 km$2');
 
// kilometre
txt.value = txt.value.replace(/(\d)\s?mkms?(\W)/ggi, '$1 mkm$2');
txt.value = txt.value.replace(/(\d)\s-kms?m(\w?\W)/ggi, '$1 mkm$2');
txt.value = txt.value.replace(/(\d) kms?([\s,.;:\)\(\\/)]W)/gi, '$1 km$2');
// square feetkilometre
txt.value = txt.value.replace(/(\d)\s?sq\.?\s?kms?/gi, '$1 km²');
txt.value = txt.value.replace(/sq\.?\s?kms?/gi, 'km²');
Line 47 ⟶ 52:
txt.value = txt.value.replace(/m²\.\)/gi, 'm²)');
 
// Standardise kilometreskilometre per hour
txt.value = txt.value.replace(/km\/hr/gi, 'km/h');
txt.value = txt.value.replace(/kph/gi, 'km/h');
Line 57 ⟶ 62:
txt.value = txt.value.replace(/(\d) km\/h/gi, '$1 km/h');
 
// Standardisecubic 'per second'centimetre
txt.value = txt.value.replace(/(\d)\s?shpcm(\W)/gi, '$1 shpcm$2');
txt.value = txt.value.replace(/(\d)\-rpms?cc(\W)/gi, '$1 rpmcc$2');
txt.value = txt.value.replace(/(\d)\-cc([\s,.;:\)\(\\/)]W)/gi, '$1 cc$2');
 
// millilitre
//txt.value = txt.value.replace(/(\d)\s?ml([\s,.;:\)\(\\/)]W)/g, '$1 ml$2');
//txt.value = txt.value.replace(/(\d)\-ml([\s,.;:\)\(\\/)]W)/g, '$1 ml$2');
 
// footper poundssecond
txt.value = txt.value.replace(/(\d)\s?ft\/second/gi, '$1 ft/s');
txt.value = txt.value.replace(/(\d)\s?ft\/sec(\W)/gi, '$1 ft/s$2');
txt.value = txt.value.replace(/(\d)\s?m\/second/gi, '$1 m/s');
txt.value = txt.value.replace(/(\d)\s?m\/sec(\W)/gi, '$1 m/s$2');
txt.value = txt.value.replace(/(\d)\s?km\/sec(\W)/gi, '$1 km/s$2');
 
// kilogram
// Space before horsepower symbol
txt.value = txt.value.replace(/(\d)\s?hpkg(\W)/gi, '$1 hpkg$2');
txt.value = txt.value.replace(/(\d)\s?bhp-kg(\W)/gi, '$1 bhpkg$2');
txt.value = txt.value.replace(/(\d)\s?shp/gi, '$1 shp');
 
// Spacenewton before unitsmetre
//txt.value = txt.value.replace(/(\d)\s?cc([\s,.;:\)\(\\/)]N•m)/gi, '$1 cc$2N·m');
 
txt.value = txt.value.replace(/(\d)\-cc([\s,.;:\)\(\\/)])/gi, '$1 cc$2');
// kilowatt
txt.value = txt.value.replace(/(\d)\s?ft([\s,.;:\)\(\\/)])/gi, '$1 ft$2');
txt.value = txt.value.replace(/(\d)\-ft([\s,.;:\)\?kW(\\/)]W)/gig, '$1 ftkW$2');
txt.value = txt.value.replace(/(\d)\s?rpm-kW(\W)/gig, '$1 rpmkW$2');
txt.value = txt.value.replace(/(\d)\-rpm/gi, '$1 rpm');
txt.value = txt.value.replace(/(\d)\s?kg([\s,.;:\)\(\\/)])/gi, '$1 kg$2');
txt.value = txt.value.replace(/(\d)\-kg([\s,.;:\)\(\\/)])/gi, '$1 kg$2');
//space before 'm' only when lower case
txt.value = txt.value.replace(/(\d)\s?m([\s,.;:\)\(\\/)])/g, '$1 m$2');
txt.value = txt.value.replace(/(\d)\-m([\s,.;:\)\(\\/)])/g, '$1 m$2');
//txt.value = txt.value.replace(/(\d)\s?ml([\s,.;:\)\(\\/)])/g, '$1 ml$2');
//txt.value = txt.value.replace(/(\d)\-ml([\s,.;:\)\(\\/)])/g, '$1 ml$2');
txt.value = txt.value.replace(/(\d)\s?m(\W)/g, '$1 m$2');
txt.value = txt.value.replace(/(\d)\s?m(\w?\W)/g, '$1 m$2');
 
// milesmile per hour
txt.value = txt.value.replace(/m\.p\.h\./gi, 'mph');
txt.value = txt.value.replace(/mph([\s,.;:\)\(\\/)])/gi, 'mph$1');
Line 92 ⟶ 95:
txt.value = txt.value.replace(/(\d)\-mph/gi, '$1 mph');
 
// poundspound weight
txt.value = txt.value.replace(/(\d)\s?lbs?/gi, '$1 lb');
txt.value = txt.value.replace(/(\d\+?)\s?lbs?/gi, '$1 lb');
Line 98 ⟶ 101:
txt.value = txt.value.replace(/(\d)\s?(\[\[lbs\]\])/gi, '$1 \[\[Pound (mass)|lb\]\]');
 
// newtonfoot metresand inch
//txt.value = txt.value.replace(/(N•m)/gi, 'N·m');
 
// kilowatts
txt.value = txt.value.replace(/(\d)\s?kW([\s,.;:\)\(\\/)])/g, '$1 kW$2');
txt.value = txt.value.replace(/(\d)\-kW([\s,.;:\)\(\\/)])/g, '$1 kW$2');
 
// foot pounds
txt.value = txt.value.replace(/ft[ -.·•\/]lb[fs]/gi, 'ft·lbf');
txt.value = txt.value.replace(/ft[ -.·•\/]lbf/gi, 'ft·lbf');
txt.value = txt.value.replace(/ft[ -.·•\/]lbff/gi, 'ft·lbf');
txt.value = txt.value.replace(/ft[ -.·•\/]lb\s/gi, 'ft·lbf ');
//the next two suspended until solution is found for wing loading (i.e. pounds per square foot)
//txt.value = txt.value.replace(/lb[fs][ -.•\/]ft/gi, 'ft·lbf');
//txt.value = txt.value.replace(/lb[ -.•\/]ft/gi, 'ft·lbf');
 
// feet and inches
txt.value = txt.value.replace(/([^;°h][^;°h]\s)(\d{1,4})\s?['’]\s?(\d{1,2})\s?["”][^NESW]/g, '$1$2 ft $3 in');
txt.value = txt.value.replace(/([\(\|]\d{1,4})\s?['’]\s?(\d{1,2})\s?["”][^NESW]/g, '$1 ft $2 in');
txt.value = txt.value.replace(/(\d)\s?ft\s(\d{1,2})\s?in/gi, '$1 ft $2 in');
txt.value = txt.value.replace(/(\d)\s?ft([\s,.;:\)\(\\/)]W)/gi, '$1 ft$2');
// square feet
txt.value = txt.value.replace(/sq(\.?d)\s?-ft?(\W)/gi, 'sq$1 ft$2');
txt.value = txt.value.replace(/ft\.\)/gi, 'ft)');
 
// yardssquare foot
txt.value = txt.value.replace(/(sq\d)\-kg([.?\s,.;:\)\?ft?(\\/)]W)/gi, '$1sq kgft$2');
 
// yard
txt.value = txt.value.replace(/(\d)\s?yds(\W)/gi, '$1 yd$2');
txt.value = txt.value.replace(/(\d) yds(\W)/gi, '$1 yd$2');
txt.value = txt.value.replace(/sq\.?\s?yds?/gi, 'sq yd');
txt.value = txt.value.replace(/yd\.\)/gi, 'yd)');
 
// square mile
//txt.value = txt.value.replace(/(N•m)sq\.?\s?mi/gi, 'N·msq mi');
 
// foot pound
txt.value = txt.value.replace(/ft[ -.·•\/]lb[fs]/gi, 'ft·lbf');
txt.value = txt.value.replace(/ft[ -.·•\/]lbf/gi, 'ft·lbf');
txt.value = txt.value.replace(/ft[ -.·•\/]lbff/gi, 'ft·lbf');
txt.value = txt.value.replace(/ft[ -.·•\/]lb\s/gi, 'ft·lbf ');
//the next two suspended until solution is found for wing loading (i.e. pounds per square foot)
//txt.value = txt.value.replace(/lb[fs][ -.•\/]ft/gi, 'ft·lbf');
//txt.value = txt.value.replace(/lb[ -.•\/]ft/gi, 'ft·lbf');
 
// Give digital value a percent symbol '%' instead of word
Line 132 ⟶ 134:
txt.value = txt.value.replace(/(\d)\-per ?cent([^aei])/gi, '$1%$2');
 
// Add a space before dBknot
txt.value = txt.value.replace(/(\d)\s?kts(dB)\bW)/ggi, '$1 knots$2');
txt.value = txt.value.replace(/(\d)\s?kWknt([\s,.;:\)\(\\/)]W)/ggi, '$1 kWknots$2');
 
// Space before horsepower symbol
// Add a space before several units that were missed before
//txt.value = txt.value.replace(/(\d)\s?hp(G|M|k|K|h|da|d|c|m|µ|n)?(g|m|Hz|N|\W|Pa|V|Ω|F|)([\s,.;:\)\(\\/)])/ggi, '$1 hp$2$3$4');
txt.value = txt.value.replace(/(\d)\-kW([\s,.;:\)\(\\?bhp/)])/ggi, '$1 kW$2bhp');
txt.value = txt.value.replace(/(\d)\s?shp/gi, '$1 shp');
 
// rpm
txt.value = txt.value.replace(/(\d)\s?rpm/gi, '$1 rpm');
txt.value = txt.value.replace(/(\d)\-m([\s,.;:\)\(\\rpm/)])/ggi, '$1 m$2rpm');
 
// decibel
txt.value = txt.value.replace(/(\d)\s?m([\s,.;:\dB)\(\\/)])b/g, '$1 m$2');
 
// bps or b/s or bits/s -->per bit/ssecond
txt.value = txt.value.replace(/([KkMmGg])(bps|bits?\/s|b\/s)/g, '$1bit/s');
txt.value = txt.value.replace(/(\d)\s?(bps)/gi, '$1 bit/s');
 
// Bps or byte/s or bytes/s -->per B/ssecond
txt.value = txt.value.replace(/([KkMmGg])(Bps|bytes?\/s)/g, ' $1B/s');
 
// Make capitalization correctof prefix with bits and bytes
txt.value = txt.value.replace(/K(bit|B)\/s/g, 'k$1/s');
txt.value = txt.value.replace(/m(bit|B)\/s/g, 'M$1/s');
txt.value = txt.value.replace(/g(bit|B)\/s/g, 'G$1/s');
 
// Ensure space iswith bits and usedbytes
txt.value = txt.value.replace(/(\d)\s?(k|M|G)(bit|B)/g, '$1 $2$3');
 
// Common error with bits and bytes
txt.value = txt.value.replace(/mibi(bit|byte)/g, 'mebi$1');