home / github / issue_comments

Menu
  • Search all tables
  • GraphQL API

issue_comments: 752750551

This data as json

html_url issue_url id node_id user created_at updated_at author_association body reactions issue performed_via_github_app
https://github.com/simonw/datasette/issues/983#issuecomment-752750551 https://api.github.com/repos/simonw/datasette/issues/983 752750551 MDEyOklzc3VlQ29tbWVudDc1Mjc1MDU1MQ== 9599 2020-12-30T20:36:38Z 2020-12-30T20:37:48Z OWNER

This version minifies to 702 characters: ```javascript window.datasette = window.datasette || {}; window.datasette.plugins = (() => { var registry = {}; var definitions = {}; var stringify = JSON.stringify;

function extractParameters(fn) {
    var match = /\((.*)\)/.exec(fn.toString());
    if (match && match[1].trim()) {
        return match[1].split(',').map(s => s.trim());
    } else {
        return [];
    }
}

function isSubSet(a, b) {
    return a.every(parameter => b.includes(parameter))
}

return {
    _registry: registry,
    define: (hook, parameters) => {
        definitions[hook] = parameters || [];
    },
    register: (hook, fn, parameters) => {
        parameters = parameters || extractParameters(fn);
        if (!definitions[hook]) {
            throw '"' + hook + '" is not a defined hook';
        }
        /* Check parameters is a subset of definitions[hook] */
        var validParameters = definitions[hook];
        if (!isSubSet(parameters, validParameters)) {
            throw '"' + hook + '" valid args are ' + stringify(validParameters);
        }
        if (!registry[hook]) {
            registry[hook] = [];
        }
        registry[hook].push([fn, parameters]);
    },

    call: (hook, args) => {
        args = args || {};
        if (!definitions[hook]) {
            throw '"' + hook + '" hook is not defined';
        }
        if (!isSubSet(Object.keys(args), definitions[hook])) {
            throw '"' + hook + '" valid args: ' + stringify(definitions[hook]);
        }

        var implementations = registry[hook] || [];
        var results = [];
        implementations.forEach(([fn, parameters]) => {
            /* Call with the correct arguments */
            var callWith = parameters.map(parameter => args[parameter]);
            var result = fn.apply(fn, callWith);
            if (result) {
                results.push(result);
            }
        });
        return results;
    }       
};

})(); ``` Or 701 characters using https://skalman.github.io/UglifyJS-online/

{
    "total_count": 0,
    "+1": 0,
    "-1": 0,
    "laugh": 0,
    "hooray": 0,
    "confused": 0,
    "heart": 0,
    "rocket": 0,
    "eyes": 0
}
712260429  
Powered by Datasette · Queries took 0.901ms · About: github-to-sqlite