Giter Club home page Giter Club logo

caniuse-api's Introduction

caniuse-api Build Status Build status

request the caniuse data to check browsers compatibilities

Installation

$ yarn add caniuse-api

Usage

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
caniuse.getSupport('border-radius', true)
/*
{ and_chr: { y: 67 },
  and_ff: { y: 60 },
  and_qq: { y: 1.2 },
  and_uc: { y: 11.8 },
  android: { y: 2.1, x: 2.1 },
  baidu: { y: 7.12 },
  chrome: { y: 4, x: 4 },
  edge: { y: 12 },
  firefox: { a: 2, x: 3.6, y: 3 },
  ie: { n: 8, y: 9 },
  ie_mob: { y: 10 },
  ios_saf: { y: 3.2, x: 3.2 },
  op_mini: {},
  op_mob: { n: 10, y: 11 },
  opera: { n: 10, y: 10.5 },
  safari: { y: 3.1, x: 4 },
  samsung: { y: 4 } }
*/

caniuse.isSupported(feature, browsers)

ask if a feature is supported by some browsers

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:

caniuse.find('radius') // ['border-radius']
caniuse.find('nothingness') // []
caniuse.find('css3')
/*
[ 'css3-attr',
  'css3-boxsizing',
  'css3-colors',
  'css3-cursors-grab',
  'css3-cursors-newer',
  'css3-cursors',
  'css3-tabsize' ]
*/

caniuse.getLatestStableBrowsers()

get the current version for each browser

caniuse.getLatestStableBrowsers()
/*
[ 'and_chr 67',
  'and_ff 60',
  'and_qq 1.2',
  'and_uc 11.8',
  'android 67',
  'baidu 7.12',
  'bb 10',
  'chrome 67',
  'edge 17',
  'firefox 61',
  'ie 11',
  'ie_mob 11',
  'ios_saf 11.3-11.4',
  'op_mini all',
  'op_mob 46',
  'opera 53',
  'safari 11.1',
  'samsung 7.2' ]
*/

caniuse.getBrowserScope()

returns a list of browsers currently used for the scope of operations

caniuse.getBrowserScope()
/*
[ 'and_chr',
  'and_ff',
  'and_qq',
  'and_uc',
  'android',
  'baidu',
  'chrome',
  'edge',
  'firefox',
  'ie',
  'ie_mob',
  'ios_saf',
  'op_mini',
  'op_mob',
  'opera',
  'safari',
  'samsung' ]
*/

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
caniuse.setBrowserScope('> 5%, last 2 versions, Firefox ESR, Opera 12.1')

caniuse-api's People

Contributors

alexisvincent avatar amilajack avatar ben-eb avatar josephrexme avatar le0nik avatar moox avatar nyalab avatar onigoetz avatar ooflorent avatar tiagocpontesp avatar wtgtybhertgeghgtwtg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

caniuse-api's Issues

Issue if project folder have spaces in the path

Attempting to install [email protected] on CentOS Linux release 7.2.1511 (Core)
. I was successful yesterday (don't know how), but am now failing due to [email protected].

Using react 0.14.3 but believe material-ui attempts to upgrade to 0.14.7

Looking for suggestions

npm ERR! Linux 3.10.0-327.10.1.el7.x86_64
npm ERR! argv "/usr/bin/node" "/bin/npm" "install"
npm ERR! node v4.4.0
npm ERR! npm v2.14.20
npm ERR! code ELIFECYCLE

npm ERR! [email protected] postinstall: node generator.js
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] postinstall script 'node generator.js'.
npm ERR! This is most likely a problem with the caniuse-api package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node generator.js
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs caniuse-api
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!
npm ERR! npm owner ls caniuse-api
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! /var/lib/jenkins/jobs/Arches - Development - Front/workspace/node_modules/npm-debug.log

[email protected] postinstall /var/lib/jenkins/jobs/Arches - Development - Front/workspace/node_modules/material-ui/node_modules/inline-style-prefixer/node_modules/caniuse-api
node generator.js

module.js:327
throw err;
^

Error: Cannot find module '/var/lib/jenkins/jobs/Arches'
at Function.Module._resolveFilename (module.js:325:15)
at Function.Module._load (module.js:276:25)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
at node.js:968:3
shell.js: internal error
Error: Command failed: "/usr/bin/node" /var/lib/jenkins/jobs/Arches - Development - Front/workspace/node_modules/material-ui/node_modules/inline-style-prefixer/node_modules/caniuse-api/shelljs_61861a524f0a7dc03ee0
at checkExecSyncError (child_process.js:464:13)
at Object.execSync (child_process.js:504:13)
at execSync (/var/lib/jenkins/jobs/Arches - Development - Front/workspace/node_modules/material-ui/node_modules/inline-style-prefixer/node_modules/caniuse-api/node_modules/shelljs/src/exec.js:81:11)
at _exec (/var/lib/jenkins/jobs/Arches - Development - Front/workspace/node_modules/material-ui/node_modules/inline-style-prefixer/node_modules/caniuse-api/node_modules/shelljs/src/exec.js:214:12)
at /var/lib/jenkins/jobs/Arches - Development - Front/workspace/node_modules/material-ui/node_modules/inline-style-prefixer/node_modules/caniuse-api/node_modules/shelljs/src/common.js:182:23
at Object. (/var/lib/jenkins/jobs/Arches - Development - Front/workspace/node_modules/material-ui/node_modules/inline-style-prefixer/node_modules/caniuse-api/generator.js:4:3)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)

Silent fail on postInstall

The postInstall scripts seems to never be executed.
it fails leaving stderout with

> [email protected] postinstall d:\E-Ressources\WebApps\www\node_modul
es\gulp-cssnext\node_modules\cssnext\node_modules\caniuse-api
> node -e "require('shelljs/global');if(test('-d', 'dist'))exec('node
dist/generate-features.js')"

d1b2d11#commitcomment-10753523

Windows build errors

This module does not build on windows. There is an issue with the use of path.join where windows inserts backslashes. This then makes the require calls in features.js throw.

If you are ok with it I can submit a pull request to fix.

allow in browser usage

it might sound silly, according to the database weight, but it would be nice to replace require.resolve usage by a json generation to avoid the readDir.
Probably hooked in the postinstall to have a json that match the installed db (so no prepublish since the json might be outdated according to the caniuse-db (hello semver)).
Also hooked in the "pretest" and it should be good.
Well it's almost done. I'll take a look to that tomorrow morning if nobody had done that before me.

1.6.0 is listed as an available version but does not exist in npm

Per npm view it appears that on 4-6 version 1.6.0 was published ... but the next day 1.6.1 was published, and version 1.6.0 was unpublished or something? Even though the version exists in npm view it is no longer in the tree of available tgzs, so I'm making a guess here. (https://registry.npmjs.org/caniuse-api)

Problem is ... this causes yarn to blow up, because someone somewhere listed 1.6.0 as a valid dependency. I imagine you unpublished it for good reason (horrible problems or something), but would you mind publishing 1.6.1 again as 1.6.0 or something? I know the "right" thing would be to find the package and have them update their dependencies to be correct, but this should also be done (unpublishing is bad news).

Usage of caniuse-db instead of caniuse-lite ?

Hey, thanks for making this handy tool.
Seems like the few css values I used it for are not included in caniuse-lite.

Would it be possible to be able to choose either you want to use caniuse-lite or caniuse-db, that would be nice :)

Thanks.

BrowserslistError: Unknown version 66 of android

I just upgraded my version of browserslist to 3.2.8, and now I have this error in my tests:

Error {
    browserslist: true,
    message: 'Unknown version 66 of android',
    name: 'BrowserslistError',
  }

  Function.select (node_modules/caniuse-api/node_modules/browserslist/index.js:622:17)
  node_modules/caniuse-api/node_modules/browserslist/index.js:151:33
  resolve (node_modules/caniuse-api/node_modules/browserslist/index.js:132:18)
  browserslist (node_modules/caniuse-api/node_modules/browserslist/index.js:224:16)
  Object.isSupported (node_modules/caniuse-api/dist/index.js:62:37)
  module.exports (dist/main.js:49:34)

from this code:

const browsers = browserslist(options.browsers);
let isFallbackNeeded = !caniuse.isSupported("css-grid", browsers);

This already happened before. I think it is due to the browserslist version used by caniuse-api being out of date, possibly because of the package-lock.json file: https://github.com/Nyalab/caniuse-api/blob/master/package-lock.json#L862

If I rollback to the same version of browserslist, the problem is gone. But I would like to be up to date if possible. Do you know how to always use the latest version of browserslist by caniuse-api ?

Update lodash.uniq?

Current lodash.uniq version is 3.1.0 now, it has fewer deps and one fourth the size.

Get data by location

Is it possible to get returned information after entering a specific location/region (e.g. USA, North America, United Kingdom, etc.) rather than just using the default Global?

Postinstall error?

I run npm install in my node Docker container and I get this in the output logs:

> [email protected] postinstall /var/www/node_modules/caniuse-api
> node generator.js



The command '/bin/sh -c npm install' returned a non-zero code: 1

Mind you, I don't explicitly depend on this package. I have no idea which package is responsible for downloading it.

Is there a way of figuring out what's going on? I am no npm expert by any means so any options that could show me more details are more than welcome.

FYI

npm info using [email protected]
npm info using [email protected]

Cannot find module './src/common' only in npm version 2

I recently changed npm version from 3 to 2 in order to use google app engine.
I could successfully install packages when i was using npm3, but after i changed to npm2, this error happens. I don't use this package directly. It is installed via dependencies of postcss-cssnext.

I think it's related to the way npm installs packages. I heard that npm3 differently installs its packages than npm2.

> [email protected] postinstall C:\Users\ZeroCho\WebstormProjects\zerocho-home\node_modules\caniuse-api
> node generator.js

module.js:338
    throw err;
    ^

Error: Cannot find module './src/common'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:286:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (C:\Users\ZeroCho\WebstormProjects\zerocho-home\node_modules\shelljs\shell.js:9:14)
    at Module._compile (module.js:434:26)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)

and the strange thing is, after failing npm install, I tried to run that command again, then it succeeded. First install always fails and second install succeeds.

How to setup?

How to install and setup this package? Is there external packages there need to be installed? as far I can see the require issn't a part of javascript.

is there a step by step how to set up a full working basic site using this package?

well-supported subset

Some properties fall into a subset called well-supported (encountered this while searching for "width" with the api)

How exactly can I target those considering that the well-supported subset might change in time?

Migrate to caniuse-lite.

Hi @Nyalab!

I've been working on an unofficial way to consume caniuse support data that is intended for modules, whereas the official dataset is intended for people. So I dropped a lot of keys that Autoprefixer & Browserslist don't use and then compacted the rest of the data. The end result weighs around 7 times less than the official database as of this writing, and the only downside is a slight performance hit when the data is restored into a caniuse format. We optimised for size, not speed, but I think we can perhaps improve this further in the future. For now the dataset is as close to caniuse-db as possible, for easy migration.

So I think it's important to use a single source of truth for the support data, and as I am starting to make much more use of caniuse-api I'd like to update the module to use caniuse-lite too.

My only reservation about the migration is that you are using the title key from each feature. I'd like to know if that can be dropped so that we can keep caniuse-lite as lean as possible. But I would like some input from caniuse-api users, on whether they think this is necessary or not. I'm open to any feedback! 😄

Copying in users of this module/caniuse data: @agauniyal, @una, @schiehll, @sylvainpolletvillard, @MoOx, @bebraw & @ai.

Thanks!

find a better api

import * as caniuse from 'caniuse-api'
caniuse.isSupported(feature, browsers)
caniuse.getSupport(feature)
caniuse.find(query)
caniuse.currentBrowsers()

Remove the generation step

It was used to provide compat for browserify, but this cause more problem than it solves.
Removing this will fix #29 #32 #36 #39 #40.

And bundler like webpack might be able to handle the dynamic require.

postInstall step not running with JSPM

Hey,

I saw another issue on this -- I'm encountering the same problem.

I install cssnext via jspm: jspm install npm:cssnext. It installs without error, but when I try to leverage cssnext I encounter an error stating that features.js does not exist.

If I navigate to the caniuse-api directory and run node generator.js the file is generated successfully and all is well.

Node v5.3.0
NPM v3.5.3
Windows 10 x64

Support user agent string

It would be nice to be able to check in the current runtime if some property is supported by passing the navigator.userAgent.

getSupport does not recognize basic props

I have tried the getSupport(feature) and get reply like this.
For instance asking for animation-delay:

Support for animation-delay:
Error: Please provide a proper feature name. Cannot find animation-delay

or background-color:

Support for background-color:
Error: Please provide a proper feature name. Cannot find background-color

Both examples works fine if you search for them on caniuse.com

1.6.0 is no longer found in registry

Our build starting failing this morning because we could not yarn install 1.6.0 of caniuse-api. Has this been removed from the public registry?

caniuse-api-1 6 0-not-found

Cannot find module '../features.json'

$ jake compile --trace
� Compiling common...

� Compiling full...

� Compiling mobile...

[18:52:44] Using gulpfile ~/projects/desktop/gulpfile.js
[18:52:44] Starting 'mobile:clean'...
[18:52:44] Finished 'mobile:clean' after 4.54 ms
[18:52:44] Starting 'mobile:static'...
[18:52:44] Using gulpfile ~/projects/desktop/gulpfile.js
[18:52:44] Starting 'full:clean'...
[18:52:44] Starting 'mobile:styles'...
[18:52:44] Finished 'full:clean' after 3.5 ms
[18:52:44] Starting 'full:static'...
[18:52:44] Using gulpfile ~/projects/desktop/gulpfile.js
[18:52:44] Starting 'common:clean'...
[18:52:44] Starting 'full:styles'...
[18:52:44] Finished 'common:clean' after 18 ms
[18:52:44] Starting 'common:static'...
[18:52:44] Starting 'common:styles'...
[18:52:44] 'mobile:styles' errored after 163 ms
[18:52:44] Error: Cannot find module '../features.json'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/home/kslimani/projects/desktop/node_modules/gulp-cssnext/node_modules/cssnext/node_modules/caniuse-api/dist/index.js:10:16)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
[18:52:44] 'full:styles' errored after 160 ms
[18:52:44] Error: Cannot find module '../features.json'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/home/kslimani/projects/desktop/node_modules/gulp-cssnext/node_modules/cssnext/node_modules/caniuse-api/dist/index.js:10:16)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
[18:52:44] Finished 'full:static' after 188 ms
jake aborted.
Error: Process exited with error.
    at api.fail (/usr/lib/node_modules/jake/lib/api.js:336:18)
    at null.<anonymous> (/usr/lib/node_modules/jake/lib/utils/index.js:136:9)
    at emit (events.js:98:17)
    at ChildProcess.<anonymous> (/usr/lib/node_modules/jake/lib/utils/index.js:219:20)
    at ChildProcess.emit (events.js:98:17)
    at Process.ChildProcess._handle.onexit (child_process.js:810:12)
[18:52:44] 'common:styles' errored after 176 ms
[18:52:44] Error: Cannot find module '../features.json'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/home/kslimani/projects/desktop/node_modules/gulp-cssnext/node_modules/cssnext/node_modules/caniuse-api/dist/index.js:10:16)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
kslimani@df3:~/projects/desktop (master)$ [18:52:44] Finished 'mobile:static' after 236 ms
[18:52:44] Finished 'common:static' after 287 ms

more readable results for getSupport()

'y', 'n', 'x', 'a' are neither usable, nor readable enough

the lib needs to provide something better like:

[
  ie: {
    notavailableSince: number, // really needed? (sometimes 0, null, wat)
    notavailableUntil: number,
    availableSince: number,
    availableUntil: number, // really needed? (technically max version of browser)
    prefixedSince: number,
    prefixedUntil: number,
    partiallySince: number,
    partiallyUntil: number,
    unprefixedSince: number,
    unprefixedUntil: number // really needed? (technically max version of browser)
  },
  ....
]

is this a good idea to provide all properties, even il you can process data to recalculate it on the project side ?

which ones do you find useful ?

Docker problems

So I realize that it is very vague but this module is causing me so many problems in trying to install with docker. It always seems to hang when it runs the generator.js and then crashes the process. Unfortunately I can't seem to get the error log out either. I saw there was another issue that mentioned the generator being a problem before, so I don't know if it's related or not.

I'm using the latest version of docker with node 4.2.2 and I'm running it on AWS free-tier.

latest version of caniuse break current test

The diff for border-radius get support test now have a difference for safari: { '#1': 6.1, x: 4, y: 3.1 }.
Note the #1 added. I take a quick look into recent caniuse db update and saw this diff Fyrd/caniuse@44dc9c2

Do you just want me to add this for the test ?
Maybe we should make test simpler (no deep equal) and just test keys to avoid testing data (we don't need to test data right?)

Windows command fails postinstall

Hi,

Got a Weird Error when running

npm install -g caniuse-api

The install appears to go OK until it runs postinstall where it results in:

npm http 200 https://registry.npmjs.org/lodash.istypedarray/-/lodash.istypedarray-3.0.2.tgz

> [email protected] postinstall C:\[REMOVED]\src\node_modules\caniuse-api
> node -e "require('shelljs/global');if(test('-d', 'dist'))exec('node dist/generate-features.js')"


[eval]:1
"require('shelljs/global');if(test('-d',
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Unexpected token ILLEGAL
    at Object.<anonymous> ([eval]-wrapper:6:22)
    at Module._compile (module.js:456:26)
    at evalScript (node.js:532:25)
    at startup (node.js:80:7)
    at node.js:901:3
unbuild [email protected]
npm ERR! weird error 8
npm ERR! not ok code 0

Hence the weird error :)

The funny thing is this runs fine within node itself. For example running the command straight from the command line works without any issue:

C:\[REMOVED]\src> node -e "require('shelljs/global');if(test('-d', 'dist'))exec('node dist/generate-features.js')"

I've included the relative position in the current working directory so you can see where I am running 'npm install' from.

Any help would be appreciated.

Get latest stable browsers function throws an exception

const caniuse = require('caniuse-api')
caniuse.getLatestStableBrowsers();
TypeError: Cannot read property 'lastVersions' of undefined
    at Object.getLatestStableBrowsers (node_modules/caniuse-api/dist/index.js:85:41)
    at Context.<anonymous> (test/test.js:14:13)
caniuse-lite: "1.0.30000830"
caniuse-api: "2.0.0"
browserslist: "2.11.3"

CSS 2.1 properties (well-supported subset)

Can anyone tell why query isn't working for some well-known properties like background-color and width. The code below produces output as: Uncaught TypeError: Cannot read property 'title' of undefined.

const caniuse = require('caniuse-api');
console.log(caniuse.getSupport('background-color'));

I've a plugin that uses caniuse-api and would like to support these css properties too - agauniyal/vscode-caniuse#1 (comment). Are there any plans to support them in future?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.