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 11:
 
// Convert the word ohm(s) or the html entity into the actual Ω symbol (Omega, not the actual ohm symbol Ω) and make sure it's 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');
 
// Convert various micro symbols into the actual micro symbol, make sure it's spaced
txt.value = txt.value.replace(/(\d)\s?(μ|μ|µ)(g|s|m|A|K|mol|cd|rad|sr|Hz|N|J|W|Pa|lm|lx|C|V|Ω|F|Wb|T|H|S|Bq|Gy|Sv|kat|°C|M)([\s,.;:\/)\(\\/)])/g, '$1 µ$3$4');
 
// Convert capital K to lowercase k in units
txt.value = txt.value.replace(/(\d)\s?K(g|s|m|A|K|mol|cd|rad|sr|Hz|N|J|W|Pa|lm|lx|C|V|Ω|F|Wb|T|H|S|Bq|Gy|Sv|kat|°C|M)([\s,.;:\/)\(\\/)])/g, '$1 k$2$3');
 
// Fix common spelling error
Line 23:
 
// Capitalize units correctly
txt.value = txt.value.replace(/(\d)\s?[-])(khz)([\s,.\/\)])/gi, '$1 kHz$3');
txt.value = txt.value.replace(/(\d)\s?(mhz)([\s,.\/\)])/gi, '$1 MHz$3');
txt.value = txt.value.replace(/(\d)\s?(ghz)([\s,.\/\)])/gi, '$1 GHz$3');
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)?(hz|HZ)([\s,.;:\/)\(\\/)])/g, '$1 $2Hz$4');
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)?(pa|PA)([\s,.;:\/)\(\\/)])/g, '$1 $2Pa$4');
 
// Fix kilometres
txt.value = txt.value.replace(/(\d)\s?[-])(kms)/gi, '$1 km');
txt.value = txt.value.replace(/(\d)\s?(km)/gi, '$1 km');
 
Line 49:
 
// Space before other units
txt.value = txt.value.replace(/(\d)\s?(cc)([\s,.;:\/)\(\\/)])/gi, '$1 cc$3');
txt.value = txt.value.replace(/(\d)\s?(mm)/gi, '$1 mm');
txt.value = txt.value.replace(/(\d)\s?(ml)/gi, '$1 ml');
Line 89:
 
// Give digital value a percent symbol '%' instead of word
txt.value = txt.value.replace(/(\d)[\s?-]per *?cent([^aei])/gi, '$1%$2');
 
// Add a space before dB or B
Line 98:
 
// Separate one for seconds since they give a lot of false positives like "1970s". Only difference is mandatory prefix.
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)([\s,.;:\/)\(\\/)])/g, '$1 $2$3$4');
 
// bps or b/s or bits/s --> bit/s