JSFiddle - React, Tailwind, and code Playground

by lollero

JavaScript

run( ['22x221'] )



function run(argv) {
	
	var size = argv[0].split(/[\sx:,-]+/);
	
	var width = parseFloat( size[0] ) || false;
	var height = parseFloat( size[1] ) || false;
	var ratio = calcAspectRatio(width, height);

  if ( ratio ) {
  	ratio = width/ratio +':'+ height/ratio;
  }
 console.log( ratio )
	var result = {
		items: [
			{
				uid: "com.calculate.aspect.ratio.yay",
				title: "Current Ratio: " + ( ratio === false ? 'N/A' : ratio ),
				subtitle: "Input format: 100x100. Copy to clipboard with enter",
				arg: ratio
			}
		]
	};
	
	return JSON.stringify( result );
	
}

function calcAspectRatio(a, b) {
	if ( a === false || b === false )
		return false;
	else
		return (b == 0) ? a : calcAspectRatio(b, a%b);
}