Skip to content

Instantly share code, notes, and snippets.

View jtfell's full-sized avatar

Julian Fell jtfell

View GitHub Profile

Keybase proof

I hereby claim:

  • I am jtfell on github.
  • I am jtfell (https://keybase.io/jtfell) on keybase.
  • I have a public key ASDgcNU_Bf-9CwPZNlSSVwZ8jc5tJTOfuU7TPut4LgD05Ao

To claim this, I am signing this object:

@jtfell
jtfell / test-result.json
Created January 2, 2018 04:30
Sample Test Result Data
{
"numFailedTests": 0,
"numPassedTests": 3,
"numPendingTests": 0,
"startTime": 1514867328411,
"success": false,
"sovereignty": "eu",
"environment": "master",
"testExecutions": [
{
var $ = require('jquery');
var DOMAIN = 'example-domain.com';
function guid() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
}
function bin2guid(num) {
@jtfell
jtfell / test.js
Last active November 8, 2016 09:36
var fs = require('fs');
var analyse = require('../src/index.js');
var css = fs.readFileSync('./test/basic.css', 'utf8');
analyse(css);
// Prints:
// { ratio: 1.4999140493583407, fit: 0.9999999752384222 }
function calculateRatio(xs) {
var uniqueSizes = xs.sort().filter(onlyUnique);
return exponentialRegression(uniqueSizes);
}
function onlyUnique(value, index, self) {
return self.indexOf(value) === index;
}
function findFontSizeDecl(root) {
var vals = [];
// Iterate over font-size declarations
root.walkDecls(/font-size/, function(decl) {
vals.push(convertToEm(decl.value));
});
return vals;
};
var postcss = require('postcss');
module.exports = function(css) {
var root = postcss.parse(css);
// 1. Parse the AST and collect all font-size declarations
var properties = findFontSizeDecl(root);
// 2. Calculate the ratio used and the quality of the fit
var results = calculateRatio(properties);