How to use the caniuse-db/package.json.version function in caniuse-db

To help you get started, we’ve selected a few caniuse-db examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jonrohan / browserl.ist / routes / index.js View on Github external
"use strict";

const express = require("express");
const router = express.Router();
const browserslist = require("browserslist");
const bv = require("browserslist/package.json").version;
const cv = require("caniuse-db/package.json").version;
const caniuse = require("caniuse-db/data.json").agents;
const GA_ID = process.env.GA_ID;

let caniuseRegion;

function getCoverage(data, version) {
  const lastVersion = Object.keys(data).sort((a, b) => {
    return parseInt(b) - parseInt(a);
  })[0];
  // If specific version coverage is missing, fall back to "version zero"
  return data[version] !== undefined ? data[version] : data[lastVersion];
}

function getRegionCoverage(region, id, version) {
  if (!caniuseRegion) {
    caniuseRegion = require(`caniuse-db/region-usage-json/${region}.json`);