browser: import caniuse jsonp data
[sheet.git] / tools / convert-caniuse.pl
index 7006b18f99b371dbaef57005a524e6c6da214b11..f013baf17ee0de04768e49854e00d40399bd7f19 100755 (executable)
@@ -11,15 +11,18 @@ local $/;  # slurp
 my $source = readline;
 
 for ($source) { # cleanup
+       s/\A\(// and s/\);?\s*\Z//;  # empty callback
+       next if /^\{/;  # valid json
+
        # convert seperate variables to hash keys
-       s/\A/{/;
-       s/^caniuse\.(\w+) /"$1":/gm;
+       s/\A/{\n/;
+       s/^caniuse\.(\w+) *= */"$1":/gm;
        s/;$/,/gm;
        s/,\s*\Z/\n}/;
        # fractions not supported by barekey
-       s/(?<=[,{]) (\d*\.\d) (?=:')/"$1"/gx;
+       s/(?<=[,{\n]) (\d*\.\d) (?=:['"])/"$1"/gx;
        # escapes not supported in singlequote
-       s{'((?:[^\\']+|\\.)*)'}{
+       s{: *\K'((?:[^\\']+|\\.)*)'}{
                my $_ = $1;
                s/"/\\"/g;
                s/\\'/'/g;
@@ -42,6 +45,6 @@ convert-caniuse - Turn Javascript data into an equivalent Perl structure
 
 =head1 SYNOPSIS
 
-       curl http://caniuse.com/js/data.js |
+       curl http://caniuse.com/jsonp.php |
        tools/convert-caniuse.pl > browser-support.inc.pl