1
0
mirror of https://github.com/thangisme/notes.git synced 2024-11-19 10:05:55 -05:00
notes/node_modules/doiuse
Patrick Marsceill b7b0d0d7bf
Initial commit
2017-03-09 13:16:08 -05:00
..
data Initial commit 2017-03-09 13:16:08 -05:00
lib Initial commit 2017-03-09 13:16:08 -05:00
node_modules Initial commit 2017-03-09 13:16:08 -05:00
test Initial commit 2017-03-09 13:16:08 -05:00
.npmignore Initial commit 2017-03-09 13:16:08 -05:00
.travis.yml Initial commit 2017-03-09 13:16:08 -05:00
CHANGELOG Initial commit 2017-03-09 13:16:08 -05:00
cli.js Initial commit 2017-03-09 13:16:08 -05:00
CONTRIBUTING.md Initial commit 2017-03-09 13:16:08 -05:00
LICENSE Initial commit 2017-03-09 13:16:08 -05:00
package.json Initial commit 2017-03-09 13:16:08 -05:00
README.md Initial commit 2017-03-09 13:16:08 -05:00
stream.js Initial commit 2017-03-09 13:16:08 -05:00

Build Status

doiuse

Lint CSS for browser support against caniuse database.

Install

npm install -g doiuse

Developing

git clone git@github.com:anandthakker/doiuse.git
cd doiuse
npm install
npm run babel

That last step transpiles the ES6 from src/ to ES5 in lib/. Already happens as a pretest step for npm test.

Usage Examples

Command Line

doiuse --browsers "ie >= 9, > 1%, last 2 versions" main.css
# or
cat main.css | doiuse --browsers "ie >= 9, > 1%, last 2 versions"

Sample output:

/projects/website/main.css:5:3: CSS3 Box-sizing not supported by: IE (8,9,10,11), Chrome (36,37,38), Safari (8,7.1), Opera (24,25), iOS Safari (8,7.1,8.1), Android Browser (4.1,4.4,4.4.4), IE Mobile (10,11)
/projects/website/main.css:6:3: CSS3 Box-sizing not supported by: IE (8,9,10,11), Chrome (36,37,38), Safari (8,7.1), Opera (24,25), iOS Safari (8,7.1,8.1), Android Browser (4.1,4.4,4.4.4), IE Mobile (10,11)
/projects/website/main.css:8:3: CSS user-select: none not supported by: IE (8,9)
/projects/website/main.css:9:3: CSS user-select: none not supported by: IE (8,9)
/projects/website/main.css:10:3: CSS user-select: none not supported by: IE (8,9)
/projects/website/main.css:11:3: CSS user-select: none not supported by: IE (8,9)
/projects/website/main.css:12:3: CSS user-select: none not supported by: IE (8,9)
/projects/website/main.css:13:3: Pointer events not supported by: IE (8,9,10), Firefox (32,33), Chrome (36,37,38), Safari (8,7.1), Opera (24,25), iOS Safari (8,7.1,8.1), Android Browser (4.1,4.4,4.4.4), IE Mobile (10)
/projects/website/main.css:14:3: Pointer events not supported by: IE (8,9,10), Firefox (32,33), Chrome (36,37,38), Safari (8,7.1), Opera (24,25), iOS Safari (8,7.1,8.1), Android Browser (4.1,4.4,4.4.4), IE Mobile (10)
/projects/website/main.css:32:3: CSS3 Transforms not supported by: IE (8)

Use --json to get output as (newline-delimited) JSON objects.

JS

var postcss = require('postcss');
var doiuse = require('doiuse');

postcss(doiuse({
  browsers:['ie >= 6', '> 1%'],
  ignore: ['rem'], // an optional array of features to ignore
  ignoreFiles: ['**/normalize.css'], // an optional array of file globs to match against original source file path, to ignore
  onFeatureUsage: function(usageInfo) {
    console.log(usageInfo.message);
  }
})).process("a { background-size: cover; }")

Gulp

var gulp = require('gulp')
var postcss = require('postcss')
var doiuse = require('doiuse')

gulp.src(src, { cwd: process.cwd() })
.pipe(gulp.postcss([
  doiuse({
    browsers: [
      'ie >= 8',
      '> 1%'
    ],
    ignore: ['rem'], // an optional array of features to ignore
    ignoreFiles: ['**/normalize.css'], // an optional array of file globs to match against original source file path, to ignore
    onFeatureUsage: function (usageInfo) {
      console.log(usageInfo.message)
    }
  })
]))

How it works

In particular, the approach to detecting features usage is currently quite naive.

Refer to the data in /data/features.js.

  • If a feature in that dataset only specifies properties, we just use those properties for regex/substring matches against the properties used in the input CSS.
  • If a feature also specifies values, then we also require that the associated value matches one of those values.

API Details:

As a transform stream

var doiuse = require('doiuse/stream');

process.stdin
  .pipe(doiuse({ browsers: ['ie >= 8', '> 1%'], ignore: ['rem'] }))
  .on('data', function (usageInfo) {
    console.log(JSON.stringify(usageInfo))
  })

Yields UsageInfo objects as described below.

As a postcss plugin

postcss(doiuse(opts)).process(css), where opts is:

{
  browsers: ['ie >= 8', '> 1%'], // an autoprefixer-like array of browsers.
  ignore: ['rem'], // an optional array of features to ignore
  ignoreFiles: ['**/normalize.css'], // an optional array of file globs to match against original source file path, to ignore
  onFeatureUsage: function(usageInfo) { } // a callback for usages of features not supported by the selected browsers
}

And usageInfo looks like this:

{
  message: '<input source>: line <l>, col <c> - CSS3 Gradients not supported by: IE (8)'
  feature: 'css-gradients', //slug identifying a caniuse-db feature
  featureData:{
    title: 'CSS Gradients',
    missing: "IE (8)" // string of browsers missing support for this feature.
    missingData: {
      // map of browser -> version -> (lack of)support code
      ie: { '8': 'n' }
    },
    caniuseData: { // data from caniuse-db/features-json/[feature].json }
  },
  usage: {} //the postcss node where that feature is being used.
}
Called once for each usage of each css feature not supported by the selected
browsers.

Ignoring file-specific rules:

For disabling some checks you can use just-in-place comments

/* doiuse-disable */

Disables checks of all features

/* doiuse-disable feature */

Disables checks of specified feature(s) (can be comma separated list)

/* doiuse-enable */

Re-enables checks of all features

/* doiuse-enable feature */

Enables checks of specified feature(s) (can be comma separated list)

  • for following lines in file

Contributing

doiuse is an OPEN Open Source Project. This means that:

Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project.

License

MIT

NOTE: Many of the files in test/cases are from autoprefixer-core, Copyright 2013 Andrey Sitnik andrey@sitnik.ru. Please see https://github.com/postcss/autoprefixer-core.