Skip to content

Instantly share code, notes, and snippets.

@tomgidden
Created January 16, 2019 02:51
Show Gist options
  • Save tomgidden/3b5889bb93f10c3652cf589f030d7dd0 to your computer and use it in GitHub Desktop.
Save tomgidden/3b5889bb93f10c3652cf589f030d7dd0 to your computer and use it in GitHub Desktop.
//var size = jQuery('dt:contains("Size")').next().text();
//var count = jQuery('dt:contains("Sheet Count")').next().text();
//var price = jQuery('div.product-price span').text();
function paperSize(name)
{
var cleanname = name.replace(/\W+/, '').toLowerCase();
var m, alpha, i;
if ( (m = cleanname.match(/^\s*([abc])(\d)\s*$/) ) ) {
alpha = ({
'a': 1.189207115002721,
'b': 1.414213562373095,
'c': 1.29683955465101})[m[1]];
i = m[2];
return (alpha * Math.pow(2, -(i+1)/2) * alpha * Math.pow(2, -i/2));
}
else {
var others = {
'letter': 0.216*0.279,
'legal': 0.216*0.356,
'tabloid': 0.279*0.432,
'ledger': 0.432*0.279,
'halfletter': 0.140*0.216,
'juniorlegal': 0.127*0.203
}
if ( undefined !== others[cleanname] )
return others[cleanname];
}
return null;
}
console.log(paperSize('A5'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment