pax_global_header00006660000000000000000000000064131023172250014506gustar00rootroot0000000000000052 comment=851c1a3034dd18f7013bd059f364fd8a7797dbcd caniuse-api-2.0.0/000077500000000000000000000000001310231722500137035ustar00rootroot00000000000000caniuse-api-2.0.0/.editorconfig000066400000000000000000000003371310231722500163630ustar00rootroot00000000000000root = true [*] insert_final_newline = true charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.js] indent_style = space indent_size = 2 [*.md] trim_trailing_whitespace = false indent_size = 4 caniuse-api-2.0.0/.gitignore000066400000000000000000000000541310231722500156720ustar00rootroot00000000000000node_modules npm-debug.log dist features.js caniuse-api-2.0.0/.jshintrc000066400000000000000000000004161310231722500155310ustar00rootroot00000000000000{ "browser": true, "node": true, "esnext": true, "asi": true, "devel": true, "nonbsp": true, "indent": 2, "maxlen": 120, "laxcomma": true, "boss": true, "eqeqeq": false, "eqnull": true, "quotmark": "double", "undef": true, "unused": true } caniuse-api-2.0.0/.travis.yml000066400000000000000000000002111310231722500160060ustar00rootroot00000000000000# http://blog.travis-ci.com/2014-12-17-faster-builds-with-container-based-infrastructure/ sudo: false language: node_js node_js: stable caniuse-api-2.0.0/CHANGELOG.md000066400000000000000000000043041310231722500155150ustar00rootroot00000000000000# 2.0.0 - 2017-05-03 - Changed: we now use caniuse-lite instead if caniuse-db ([#59](https://github.com/Nyalab/caniuse-api/pull/59)) # 1.6.1 - 2017-04-07 - Added: export the feature list ([#48](https://github.com/Nyalab/caniuse-api/pull/48)) # 1.5.3 - 2017-02-01 - Removed unused dependency ([#54](https://github.com/Nyalab/caniuse-api/pull/54) - @wtgtybhertgeghgtwtg) # 1.5.2 - 2016-09-05 - Fixed: no more generation `postinstall` hook ``\o/``. ([#47](https://github.com/Nyalab/caniuse-api/pull/47) - @alexisvincent) # 1.5.1 - 2016-08-06 - Fixed: Do not fail when browserslist gives a browser that caniuse-api doesn't know about ([#45](https://github.com/Nyalab/caniuse-api/pull/45) - @onigoetz) # 1.5.0 - 2016-06-01 - Added: JSPM support with explicit file extensions ([#40](https://github.com/Nyalab/caniuse-api/issues/40)) - Upgraded: dependecies (lodash.memoize, lodash.uniq, shelljs, babel-tape-runner, tape, tap-spec) - Upgraded: ask travis to only test node stable - Upgraded: some tests fixed, some tests added # 1.4.1 - 2015-10-18 - Fixed: `generator.js` was missing # 1.4.0 - 2015-10-18 - Upgraded: browserlist 1.x - Upgraded: shelljs 0.5.x - Added: output to notify if generation has been made or not (related to [#25](https://github.com/Nyalab/caniuse-api/issues/25)) # 1.3.2 - 2015-06-23 - Fixed: lodash.uniq dep ([#31](https://github.com/Nyalab/caniuse-api/issues/31)) # 1.3.1 - 2015-03-31 - Fixed: Windows support # 1.3.0 - 2015-03-30 - Added: better exception messages - Added: full browserify compatibility (by avoiding dynamic require) # 1.2.2 - 2015-02-06 - Fixed: postinstall hook for Windows # 1.2.1 - 2015-02-04 - Changed: Allow in browser usage by avoiding `require.resolve` and using a generated json instead or reading a directory ([#20](https://github.com/Nyalab/caniuse-api/pull/20)] # 1.2.0 [YANKED] # 1.1.0 - 2015-02-03 - Fixed: usage of caniuse-db outside the package itself - Changed: upgrade to browserslist 0.2.x # 1.0.0 - 2014-12-16 - Added: package is now automatically tested by [Travis-CI](https://travis-ci.org/Nyalab/caniuse-api) # 0.1.0 - 2014-12-15 - Changed: complete API changes, released as `caniuse-api` package # 0.0.1 - 2014-12-09 ✨Initial release caniuse-api-2.0.0/LICENSE000066400000000000000000000020741310231722500147130ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2014 Sébastien Balayn Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. caniuse-api-2.0.0/README.md000066400000000000000000000051541310231722500151670ustar00rootroot00000000000000# caniuse-api [![Build Status](https://travis-ci.org/Nyalab/caniuse-api.svg?branch=master)](https://travis-ci.org/Nyalab/caniuse-api) [![Build status](https://ci.appveyor.com/api/projects/status/6j3na522bv3bxfa5/branch/master?svg=true)](https://ci.appveyor.com/project/MoOx/caniuse-api/branch/master) request the caniuse data to check browsers compatibilities ## Installation ```console $ npm install caniuse-api --save ``` ## Usage ```js const caniuse = require('caniuse-api') caniuse.getSupport('border-radius') caniuse.isSupported('border-radius', 'ie 8, ie 9') caniuse.setBrowserScope('> 5%, last 1 version') caniuse.getSupport('border-radius') // ... ``` ## API #### `caniuse.getSupport(feature)` _ask since which browsers versions a feature is available_ * `y`: Since which browser version the feature is available * `n`: Up to which browser version the feature is unavailable * `a`: Up to which browser version the feature is partially supported * `X`: Up to which browser version the feature is prefixed ```js caniuse.getSupport('border-radius', true) /* [ safari: { y: 3.1, x: 4 }, opera: { n: 10, y: 10.5 }, ios_saf: { y: 3.2, x: 3.2 }, ie_mob: { y: 10 }, ie: { n: 8, y: 9 }, firefox: { a: 2, x: 3.6, y: 3 }, chrome: { y: 4, x: 4 }, and_chr: { y: 39 } ] */ ``` #### `caniuse.isSupported(feature, browsers)` _ask if a feature is supported by some browsers_ ```js caniuse.isSupported('border-radius', 'ie 8, ie 9') // false caniuse.isSupported('border-radius', 'ie 9') // true ``` #### `caniuse.find(query)` _search for a caniuse feature name_ Ex: ```js caniuse.find('radius') // ['border-radius'] caniuse.find('nothingness') // [] caniuse.find('css3') /* [ 'css3-boxsizing', 'css3-colors', 'css3-cursors-newer', 'css3-cursors', 'css3-tabsize' ] */ ``` #### `caniuse.getLatestStableBrowsers()` _get the current version for each browser_ ```js caniuse.getLatestStableBrowsers() /* [ 'safari 8', 'opera 26', 'ios_saf 8.1', 'ie_mob 11', 'ie 11', 'firefox 33', 'chrome 39' ] */ ``` #### `caniuse.getBrowserScope()` _returns a list of browsers currently used for the scope of operations_ ```js caniuse.getBrowserScope() /* [ 'safari', 'opera', 'op_mini', 'ios_saf', 'ie_mob', 'ie', 'firefox', 'chrome', 'android', 'and_uc', 'and_chr' ] */ ``` #### `caniuse.setBrowserScope(browserscope)` _if you do not like the default browser scope, you can set it globally by using this method_ * browserscope should be a 'autoprefixer' formatted string ```js caniuse.setBrowserScope('> 5%, last 2 versions, Firefox ESR, Opera 12.1') ``` --- ## [Changelog](CHANGELOG.md) ## [License](LICENSE) caniuse-api-2.0.0/appveyor.yml000066400000000000000000000004741310231722500163000ustar00rootroot00000000000000# http://www.appveyor.com/docs/appveyor-yml environment: matrix: - nodejs_version: 0.12 version: "{build}" build: off deploy: off install: - ps: Install-Product node $env:nodejs_version - npm install test_script: - node --version - npm --version - ps: "npm test # PowerShell" - cmd: "npm test" caniuse-api-2.0.0/package.json000066400000000000000000000020331310231722500161670ustar00rootroot00000000000000{ "name": "caniuse-api", "version": "2.0.0", "description": "request the caniuse data to check browsers compatibilities", "repository": "https://github.com/nyalab/caniuse-api.git", "keywords": [ "caniuse", "browserslist" ], "authors": [ "nyalab", "MoOx" ], "license": "MIT", "main": "dist/index.js", "files": [ "dist" ], "dependencies": { "browserslist": "^2.0.0", "caniuse-lite": "^1.0.0", "lodash.memoize": "^4.1.2", "lodash.uniq": "^4.5.0" }, "devDependencies": { "babel-cli": "^6.22.2", "babel-eslint": "^5.0.0", "babel-preset-latest": "^6.22.0", "babel-tape-runner": "^2.0.1", "jshint": "^2.5.10", "npmpub": "^3.1.0", "tap-spec": "^4.1.1", "tape": "^4.6.0" }, "scripts": { "build": "babel src --out-dir dist", "lint": "jshint src", "prepublish": "npm run build", "test": "npm run lint && babel-tape-runner test/*.js | tap-spec", "release": "npmpub" }, "babel": { "presets": [ "babel-preset-latest" ] } } caniuse-api-2.0.0/src/000077500000000000000000000000001310231722500144725ustar00rootroot00000000000000caniuse-api-2.0.0/src/index.js000066400000000000000000000034721310231722500161450ustar00rootroot00000000000000import memoize from "lodash.memoize" import browserslist from "browserslist" import {features, feature as featureUnpack} from "caniuse-lite" import {contains, parseCaniuseData, cleanBrowsersList} from "./utils" const featuresList = Object.keys(features) let browsers function setBrowserScope(browserList) { browsers = cleanBrowsersList(browserList) } function getBrowserScope() { return browsers } const parse = memoize(parseCaniuseData, function(feat, browsers) { return feat.title + browsers }) function getSupport(query) { let feature try { feature = featureUnpack(features[query]) } catch(e) { let res = find(query) if (res.length === 1) return getSupport(res[0]) throw new ReferenceError(`Please provide a proper feature name. Cannot find ${query}`) } return parse(feature, browsers) } function isSupported(feature, browsers) { let data try { data = featureUnpack(features[feature]) } catch(e) { let res = find(feature) if (res.length === 1) { data = features[res[0]] } else { throw new ReferenceError(`Please provide a proper feature name. Cannot find ${feature}`) } } return browserslist(browsers) .map((browser) => browser.split(" ")) .every((browser) => data.stats[browser[0]] && data.stats[browser[0]][browser[1]] === "y") } function find(query) { if (typeof query !== "string") { throw new TypeError("The `query` parameter should be a string.") } if (~featuresList.indexOf(query)) { // exact match return query } return featuresList.filter((file) => contains(file, query)) } function getLatestStableBrowsers() { return browserslist.queries.lastVersions.select(1) } setBrowserScope() export { featuresList as features, getSupport, isSupported, find, getLatestStableBrowsers, setBrowserScope, getBrowserScope } caniuse-api-2.0.0/src/utils.js000066400000000000000000000023701310231722500161720ustar00rootroot00000000000000import uniq from "lodash.uniq" import browserslist from "browserslist" export function contains(str, substr) { return !!~str.indexOf(substr) } export function parseCaniuseData(feature, browsers) { var support = {} var letters var letter browsers.forEach(function(browser) { support[browser] = {} for (var info in feature.stats[browser]) { letters = feature.stats[browser][info].split(" ") info = parseFloat(info.split("-")[0]) //if info is a range, take the left if (isNaN(info)) continue for (var i = 0; i < letters.length ; i++) { letter = letters[i] if (letter === "y"){ // min support asked, need to find the min value if (typeof support[browser][letter] === "undefined" || info < support[browser][letter]) { support[browser][letter] = info } } else { // any other support, need to find the max value if (typeof support[browser][letter] === "undefined" || info > support[browser][letter]) { support[browser][letter] = info } } } } }) return support } export function cleanBrowsersList(browserList) { return uniq(browserslist(browserList).map((browser) => browser.split(" ")[0])) } caniuse-api-2.0.0/test/000077500000000000000000000000001310231722500146625ustar00rootroot00000000000000caniuse-api-2.0.0/test/index.js000066400000000000000000000053501310231722500163320ustar00rootroot00000000000000import test from "tape" import browserslist from "browserslist" import {feature} from "caniuse-lite" import * as caniuse from "../src/index" import {cleanBrowsersList} from "../src/utils" test("browserscope tests", (t) => { const defaultBrowserslist = cleanBrowsersList() t.deepEqual(caniuse.getBrowserScope().sort(), defaultBrowserslist.sort(), "default browser scope is browserslists one") caniuse.setBrowserScope(browserslist("Firefox 4, Opera 12.1")) t.deepEqual(caniuse.getBrowserScope().sort(), ["firefox", "opera"].sort(), "browser scope update does really update") t.end() }) test("features test", (t) => { t.ok(Array.isArray(caniuse.features), "a feature list is exported") t.ok(caniuse.features.length > 0, "the feature list is not empty") t.end() }) test("find tests", (t) => { t.deepEqual(caniuse.find("radius"), ["border-radius"], "`find` should find border-radius") t.deepEqual(caniuse.find("canaillou"), [], "non-existent property should return an empty array") t.ok(caniuse.find("border").length, "generic property name should return several results") t.throws(() => caniuse.find(null), "not a string should throw an exception") t.end() }) test("getLatestStableBrowsers tests", (t) => { t.ok(caniuse.getLatestStableBrowsers().length, "it should return an array of results") t.ok(caniuse.getLatestStableBrowsers().every((browser) => browser.match(/[A-z_]+ ([0-9\.\-]+|all)/)), "every entry is correctly formed") t.end() }) test("isSupported tests", (t) => { t.ok(caniuse.isSupported("border-radius", "ie 9"), "border-radius is supported on ie 9") t.notOk(caniuse.isSupported("border-radius", "ie 8"), "border-radius is not supported on ie 8") t.throws(() => caniuse.isSupported("canaillou", "chrome 37"),"throws if silly thing are asked") t.end() }) // If for some reason the caniuse-db is not the same in browserslist and in caniuse-api // browserslist could return browsers that caniuse-api doesn't know about and crashes test("isSupported test with browsers caniuse doesn't know", (t) => { browserslist.data.notabrowser = { name: 'notabrowser', versions: ['1'], released: ['1'] }; browserslist.versionAliases.notabrowser = {} t.notOk(caniuse.isSupported("border-radius", "notabrowser 1"), "do not throw on non existing data") delete browserslist.data.notabrowser delete browserslist.versionAliases.notabrowser t.end() }) test("getSupport tests", (t) => { caniuse.setBrowserScope() const borderRadiusFeature = feature(require('caniuse-lite/data/features/border-radius')) const support = caniuse.getSupport("border-radius") t.ok(support.safari.y, "border-radius support is ok on some safari") t.throws(() => caniuse.getSupport("canaillou"),"throws if silly thing are asked") t.end() }) caniuse-api-2.0.0/test/utils.js000066400000000000000000000026511310231722500163640ustar00rootroot00000000000000import test from "tape" import browserslist from "browserslist" import uniq from "lodash.uniq" import {feature} from "caniuse-lite" import {contains, parseCaniuseData, cleanBrowsersList} from "../src/utils" test("contains should work", (t) => { t.is(contains("abc", "a"), true, "abc contains b") t.isNot(contains("abc", "d"), true, "abc does not contain with d") t.is(contains("abc", ""), true, "contains empty string is true") t.end() }) test("parseCaniuseData should work", (t) => { const browsers = cleanBrowsersList() const borderRadiusFeature = feature(require('caniuse-lite/data/features/border-radius')) const parsed = parseCaniuseData(borderRadiusFeature, browsers) t.ok(parsed.safari.y, "border-radius support is ok on some safari") t.ok(parsed.firefox.y, "border-radius support is ok on some firefox") t.ok(parsed.chrome.y, "border-radius support is ok on some chrome") t.deepEqual(parseCaniuseData(borderRadiusFeature, []), [], "passing an empty browser list returns an empty array") t.end() }) test("cleanBrowsersList should work", (t) => { const dirtyList = ["firefox 4", "firefox 3.6", "opera 12.1", "ie 8", "ie 9", "chrome 37"] const cleanList = ["firefox", "opera", "ie", "chrome"] t.deepEqual(cleanBrowsersList(dirtyList).sort(), cleanList.sort(), "remove version numbers and deduplicate the list") t.deepEqual(cleanBrowsersList([]), [], "giving empty array returns empty array") t.end() })