Registry / testing / doiuse2

doiuse2

JSON →
library6.0.0jsnpmunverified

Lint CSS for browser support against the caniuse database. Version 6.0.0 is current stable, released on npm. It integrates as a PostCSS plugin, CLI tool, and transform stream. Differentiators: uses actual caniuse data, supports ignore lists by feature or file globs, outputs human-readable or JSON messages, and works with Stylelint. Alternatives like Autoprefixer add prefixes rather than warn on unsupported features.

npm install doiuse2
INSTALL
IMPORT
SIG · DOIUSE2
D
doiuse2
testingjavascriptv6.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

DoIUse
import DoIUse from 'doiuse/lib/DoIUse.js'
const DoIUse = require('doiuse').DoIUse
Module uses ESM exports. CommonJS require('doiuse') returns the PostCSS plugin function, not the class.
doiuse (stream)
import doiuse from 'doiuse/stream'
const doiuse = require('doiuse/stream')
Stream entry point available from 'doiuse/stream'. CommonJS require is also supported.
doiuse (CLI)
npx doiuse --browsers "ie >= 9" main.css
doiuse --browsers ie >= 9 main.css without quotes
CLI expects quoted browser string; unquoted may split on spaces.

Demonstrates using doiuse2 as a PostCSS plugin to check CSS against browser support, with ignore options and event handler.

import postcss from 'postcss'; import DoIUse from 'doiuse/lib/DoIUse.js'; const css = 'a { background-size: cover; }'; postcss([ new DoIUse({ browsers: ['ie >= 6', '> 1%'], ignore: ['rem'], ignoreFiles: ['**/normalize.css'], onFeatureUsage: (info) => { console.log(info.message); } }) ]).process(css).then(result => { console.log('Done'); });
Debug
Known issues
breakingMigration from v1 to v2 changed the API from a function to a class. 'browsers' option now accepts an array instead of string.
fix
Use new DoIUse({ browsers: ['ie >= 9'] }) instead of doiuse({ browsers: 'ie >= 9' }).
affects: >=2.0.0
breakingIn v5+, the package was renamed from 'doiuse' to 'doiuse2' on npm due to original maintainer conflict. Import paths changed to 'doiuse2/lib/DoIUse.js'.
fix
Install 'doiuse2' and update imports to 'doiuse2/...'.
affects: >=5.0.0
deprecatedThe CLI option --browsers is deprecated in favor of project .browserslistrc file.
fix
Create a .browserslistrc in your project root instead of passing --browsers.
affects: >=4.0.0
gotchaWhen using CommonJS, require('doiuse') returns the plugin function, not a constructor. Using new with require will throw.
fix
Use var doiuse = require('doiuse'); /* no new */
affects: >=1.0.0
gotchaThe ignore option only works with feature names from data/features.js (e.g., 'rem'), not CSS properties.
fix
Check the features list at https://github.com/clshortfuse/doiuse2/blob/master/data/features.js for valid ignore values.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'doiuse/lib/DoIUse.js'
Using old package name 'doiuse' instead of 'doiuse2' after version 5.
fix
npm install doiuse2 and import from 'doiuse2/lib/DoIUse.js'.
TypeError: doiuse is not a constructor
Using require('doiuse') then trying to instantiate with 'new' or as class.
fix
Use require('doiuse') directly as a function: postcss([doiuse(opts)]).
Cannot read property 'some' of undefined
Empty or missing browsers option.
fix
Supply browsers option (array of strings) or a .browserslistrc file.
No data found for feature: rem
The 'ignore' list contains an invalid feature name.
fix
Refer to the features list in data/features.js for valid names.
Upgrade
Version history
6.0.0latest on npm
Audit
Dependencies
postcssoptionalpeer dependency for PostCSS plugin usage
caniuse-literequiredprovides browser support data from caniuse
Agent activity
9 hits · last 30 days
node
8
Resources
doiuse2 — npm install doiuse2 · libregistry