Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

doiuse

Package Overview
Dependencies
Maintainers
4
Versions
57
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

doiuse - npm Package Compare versions

Comparing version 4.1.0 to 4.2.0

20

CHANGELOG.md
# Changelog
## Unreleased
...
## 4.2.0
2018-09-27
* Detect use of 'initial', 'unset', and 'revert' keywords [\#93](https://github.com/anandthakker/doiuse/pull/93)
* Improve css-sel2 detection performance [\#88](https://github.com/anandthakker/doiuse/pull/88)
* Remove lodash dependency [\#94](https://github.com/anandthakker/doiuse/pull/94)
* Upgrade browserslist (4.1.1), caniuse-lite (1.0.30000887)
## 4.1.0
2018-03-23
* Upgrade browserslist (3.1.1) and caniuse-lite (1.0.30000810) [\#85](https://github.com/anandthakker/doiuse/pull/85)

@@ -8,5 +22,7 @@ * Update font-unicode-range [\#80](https://github.com/anandthakker/doiuse/pull/80)

* Upgrade browserslist (3.2.1) and caniuse-lite (1.0.30000819)
* Drop node 4 support
## 4.0.0
2017-10-09
* **Breaking:** No longer throws an error for unrecognised node types [\#75](https://github.com/anandthakker/doiuse/pull/75)

@@ -16,2 +32,3 @@

2017-08-24
* Fix config not found due to missing parameter

@@ -21,2 +38,3 @@

2017-05-15
* Remove Node.js 0.12 support

@@ -31,2 +49,3 @@ * Use PostCSS 6

2015-10-16
* Use PostCSS 'warn' API, add feature id in reported results

@@ -36,2 +55,3 @@

2015-10-13
* **Breaking:** Add option to ignore rules

@@ -38,0 +58,0 @@ * clean up README, add Gulp example

32

cli.js
#!/usr/bin/env node
var FILE_NOT_FOUND = 'ENOENT'
const FILE_NOT_FOUND = 'ENOENT'
var fs = require('fs')
var ldjson = require('ldjson-stream')
var through = require('through2')
var browserslist = require('browserslist')
var path = require('path')
var _ = require('lodash')
const fs = require('fs')
const ldjson = require('ldjson-stream')
const through = require('through2')
const browserslist = require('browserslist')
const path = require('path')
var formatBrowserName = require('./lib/util').formatBrowserName
var doiuse = require('./stream')
const formatBrowserName = require('./lib/util').formatBrowserName
const doiuse = require('./stream')
var yargs = require('yargs')
const yargs = require('yargs')
.usage('Lint your CSS for browser support.')

@@ -57,11 +56,13 @@ .example('cat FILE | $0 -b "ios >= 6"', '')

// Config file reading
// Config file reading
if (argv.config) {
try {
var fileData = fs.readFileSync(path.resolve(argv.config), 'utf8')
var config = JSON.parse(fileData)
_.forEach(_.keys(config), function (key) {
const fileData = fs.readFileSync(path.resolve(argv.config), 'utf8')
const config = JSON.parse(fileData)
Object.keys(config).forEach(key => {
var value = config[key]
if (key === 'browsers') {
if (_.isArray(value)) value = value.join(',')
if (value instanceof Array) value = value.join(',')
}

@@ -79,2 +80,3 @@

argv.ignore = argv.ignore.split(',').map(function (s) { return s.trim() })
// Informational output

@@ -81,0 +83,0 @@ if (argv.l) { argv.v = ++argv.verbose }

@@ -7,7 +7,12 @@ var list = require('postcss/lib/list')

}
function matchOutsideOfBrackets (pat) {
if (pat instanceof RegExp) {
pat = pat.source
function matchOutsideOfBrackets(pat) {
if (!(pat instanceof RegExp)) {
throw new TypeError('matchOutsideOfBrackets expects a RegExp')
}
return new RegExp('^(' + pats.brackets + '?' + pats.nobrackets + '*)*' + pat)
var fullPat = new RegExp(
'^(' + pats.brackets + '?' + pats.nobrackets + '*)*' + pat.source
)
return function match(str) {
return pat.test(str) && fullPat.test(str)
}
}

@@ -395,3 +400,15 @@

values: ['image-set']
},
'css-initial-value': {
properties: [''],
values: ['initial']
},
'css-unset-value': {
properties: [''],
values: ['unset']
},
'css-revert-value': {
properties: [''],
values: ['revert']
}
}

@@ -1,20 +0,24 @@

// Generated by CoffeeScript 2.0.0-beta8
var browserslist = require('browserslist');
var _ = require('lodash');
module.exports = class BrowserSelection {
const browserslist = require('browserslist');
class BrowserSelection {
constructor(query, from) {
this.browsersRequest = query;
this._list = browserslist(this.browsersRequest, from ? { path: from } : {}).map(s => s.split(' '));
this._list = browserslist(this.browsersRequest, from ? { path: from } : {}).map(browser => browser.split(' '));
}
test(browser, version) {
version = version.split('-');
if (version.length === 1) version.push(version[0]);
return _.find(this._list, ([b, v]) => {
return b === browser && v >= version[0] && v <= version[1];
});
const versions = version.split('-');
if (versions.length === 1) {
versions.push(versions[0]);
}
return this._list.find(([b, v]) => b === browser && v >= versions[0] && v <= versions[1]);
}
list() {
return this._list.slice();
}
};
}
module.exports = BrowserSelection;

@@ -1,3 +0,2 @@

var _ = require('lodash');
var features = require('../data/features');
const features = require('../data/features');

@@ -15,3 +14,3 @@ const PLUGIN_OPTION_COMMENT = 'doiuse-';

return function find(searchfor) {
if (searchfor instanceof RegExp) return searchfor.test(str);else if (_.isFunction(searchfor)) return searchfor(str);else return str && str.indexOf(searchfor) >= 0;
if (searchfor instanceof RegExp) return searchfor.test(str);else if (typeof searchfor === 'function') return searchfor(str);else return str && str.indexOf(searchfor) >= 0;
};

@@ -46,5 +45,12 @@ }

*/
module.exports = class Detector {
class Detector {
constructor(featureList) {
this.features = _.pick(features, featureList);
this.features = featureList.reduce((result, feature) => {
if (features[feature]) {
result[feature] = features[feature];
}
return result;
}, {});
this.ignore = [];

@@ -96,3 +102,3 @@ }

if (_.startsWith(text, PLUGIN_OPTION_COMMENT)) {
if (text.startsWith(PLUGIN_OPTION_COMMENT)) {
const option = text.split(' ', 1)[0];

@@ -104,5 +110,9 @@ const value = text.replace(option, '').trim();

if (value === '') {
this.ignore = _.keysIn(this.features);
this.ignore = Object.keys(this.features);
} else {
this.ignore = _.uniq([...this.ignore, ...value.split(',').map(feat => feat.trim())]);
value.split(',').map(feat => feat.trim()).forEach(feat => {
if (this.ignore.indexOf(feat) < 0) {
this.ignore.push(feat);
}
});
}

@@ -114,3 +124,4 @@ break;

} else {
this.ignore = _.without(this.ignore, ...value.split(',').map(feat => feat.trim()));
const without = value.split(',').map(feat => feat.trim());
this.ignore = this.ignore.filter(i => without.indexOf(i) < 0);
}

@@ -147,2 +158,4 @@ break;

}
};
}
module.exports = Detector;

@@ -1,15 +0,16 @@

let _ = require('lodash');
let missingSupport = require('./missing-support');
let Detector = require('./detect-feature-use');
let Multimatch = require('multimatch');
const multimatch = require('multimatch');
const missingSupport = require('./missing-support');
const Detector = require('./detect-feature-use');
function doiuse(options) {
let { browsers: browserQuery, onFeatureUsage, ignore: ignoreOptions, ignoreFiles } = options;
const { browsers: browserQuery, onFeatureUsage, ignore: ignoreOptions, ignoreFiles } = options;
return {
info(opts = {}) {
let { browsers, features } = missingSupport(browserQuery, opts.from);
const { browsers, features } = missingSupport(browserQuery, opts.from);
return {
browsers: browsers,
features: features
browsers,
features
};

@@ -23,4 +24,6 @@ },

}
let { features } = missingSupport(browserQuery, from);
let detector = new Detector(_.keys(features));
let detector = new Detector(Object.keys(features));
return detector.process(css, function ({ feature, usage, ignore }) {

@@ -30,2 +33,3 @@ if (ignore && ignore.indexOf(feature) !== -1) {

}
if (ignoreOptions && ignoreOptions.indexOf(feature) !== -1) {

@@ -35,3 +39,3 @@ return;

if (ignoreFiles && Multimatch(usage.source.input.from, ignoreFiles).length > 0) {
if (ignoreFiles && multimatch(usage.source.input.from, ignoreFiles).length > 0) {
return;

@@ -38,0 +42,0 @@ }

@@ -1,43 +0,43 @@

let features = require('../data/features');
let BrowserSelection = require('./browsers');
let _ = require('lodash');
let formatBrowserName = require('./util').formatBrowserName;
const caniuse = require('caniuse-lite');
let caniuse = require('caniuse-lite');
const features = require('../data/features');
const BrowserSelection = require('./browsers');
const formatBrowserName = require('./util').formatBrowserName;
function filterStats(browsers, stats) {
return _.reduce(stats, function (resultStats, versionData, browser) {
// filter only versions of selected browsers that don't fully support this feature
const feature = _.reduce(versionData, function (result, support, ver) {
const selected = browsers.test(browser, ver);
if (selected) {
// check if browser is NOT fully (i.e., don't have 'y' in their stats) supported
if (!/(^|\s)y($|\s)/.test(support)) {
// when it's not partially supported ('a'), it's missing
const testprop = /(^|\s)a($|\s)/.test(support) ? 'partial' : 'missing';
if (!result[testprop]) {
result[testprop] = {};
}
result[testprop][selected[1]] = support;
const filterStats = (browsers, stats) => Object.keys(stats).reduce((result, browser) => {
const versions = stats[browser];
const feature = Object.keys(versions).reduce((feat, version) => {
const support = versions[version];
const selected = browsers.test(browser, version);
if (selected) {
// check if browser is NOT fully (i.e., don't have 'y' in their stats) supported
if (!/(^|\s)y($|\s)/.test(support)) {
// when it's not partially supported ('a'), it's missing
const type = /(^|\s)a($|\s)/.test(support) ? 'partial' : 'missing';
if (!feat[type]) {
feat[type] = {};
}
feat[type][selected[1]] = support;
}
return result;
}, { missing: {}, partial: {} });
}
if (_.keys(feature.missing).length !== 0) {
resultStats.missing[browser] = feature.missing;
}
if (_.keys(feature.partial).length !== 0) {
resultStats.partial[browser] = feature.partial;
}
return resultStats;
return feat;
}, { missing: {}, partial: {} });
}
function lackingBrowsers(browserStats) {
return _.reduce(browserStats, function (res, versions, browser) {
res.push(formatBrowserName(browser, _.keys(versions)));
return res;
}, []).join(', ');
}
if (Object.keys(feature.missing).length !== 0) {
result.missing[browser] = feature.missing;
}
if (Object.keys(feature.partial).length !== 0) {
result.partial[browser] = feature.partial;
}
return result;
}, { missing: {}, partial: {} });
const lackingBrowsers = browserStats => Object.keys(browserStats).map(browser => formatBrowserName(browser, Object.keys(browserStats[browser]))).join(', ');
/**

@@ -73,3 +73,3 @@ * Get data on CSS features not supported by the given autoprefixer-like

*/
function missing(browserRequest, from) {
function missingSupport(browserRequest, from) {
const browsers = new BrowserSelection(browserRequest, from);

@@ -109,2 +109,2 @@ let result = {};

module.exports = missing;
module.exports = missingSupport;
{
"name": "doiuse",
"version": "4.1.0",
"version": "4.2.0",
"description": "Lint CSS for browser support against caniuse database",

@@ -27,4 +27,4 @@ "main": "lib/doiuse.js",

"dependencies": {
"browserslist": "^3.2.1",
"caniuse-lite": "^1.0.30000819",
"browserslist": "^4.1.1",
"caniuse-lite": "^1.0.30000887",
"css-rule-stream": "^1.1.0",

@@ -34,16 +34,15 @@ "duplexer2": "0.0.2",

"ldjson-stream": "^1.2.1",
"lodash": "^4.0.0",
"multimatch": "^2.0.0",
"postcss": "^6.0.1",
"source-map": "^0.5.6",
"through2": "^0.6.3",
"yargs": "^8.0.1"
"postcss": "^7.0.4",
"source-map": "^0.7.3",
"through2": "^2.0.3",
"yargs": "^12.0.2"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"eslint": "^4.19.1",
"mock-fs": "^4.3.0",
"postcss-import": "^10.0.0",
"standard": "^11.0.1",
"tape": "^4.0.0"
"eslint": "^5.6.0",
"mock-fs": "^4.7.0",
"postcss-import": "^12.0.0",
"standard": "^12.0.1",
"tape": "^4.9.1"
},

@@ -50,0 +49,0 @@ "standard": {

[![Build Status](https://travis-ci.org/anandthakker/doiuse.svg?branch=master)](https://travis-ci.org/anandthakker/doiuse)
doiuse
======
# doiuse
Lint CSS for browser support against caniuse database.
Lint CSS for browser support against [Can I use](http://caniuse.com) database.
# Install
## Install

@@ -14,16 +13,6 @@ ```sh

# Developing
```sh
git clone git@github.com:anandthakker/doiuse.git
cd doiuse
npm install
npm run babel
```
## Usage Examples
That last step transpiles the ES6 from src/ to ES5 in lib/. Already happens as a `pretest` step for `npm test`.
### Command Line
# Usage Examples
## Command Line
```bash

@@ -35,3 +24,2 @@ doiuse --browsers "ie >= 9, > 1%, last 2 versions" main.css

**Sample output:**

@@ -53,4 +41,4 @@ ```

### JS
## JS
```javascript

@@ -70,3 +58,3 @@ var postcss = require('postcss');

## Gulp
### Gulp

@@ -94,3 +82,4 @@ ```javascript

# How it works
## How it works
In particular, the approach to detecting features usage is currently quite naive.

@@ -105,5 +94,6 @@

# API Details:
## API Details
## As a transform stream
### As a transform stream
```javascript

@@ -121,4 +111,4 @@ var doiuse = require('doiuse/stream');

### As a postcss plugin
## As a postcss plugin
`postcss(doiuse(opts)).process(css)`, where `opts` is:

@@ -138,7 +128,7 @@ ```javascript

{
message: '<input source>: line <l>, col <c> - CSS3 Gradients not supported by: IE (8)'
feature: 'css-gradients', //slug identifying a caniuse-db feature
featureData:{
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.
missing: "IE (8)", // string of browsers missing support for this feature.
missingData: {

@@ -153,24 +143,33 @@ // map of browser -> version -> (lack of)support code

```
Called once for each usage of each css feature not supported by the selected
browsers.
## Ignoring file-specific rules:
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](#features-list)_
##### `/* doiuse-disable feature */`
Disables checks of _specified [feature(s)](#features-list)_ (can be comma separated list)
##### `/* doiuse-enable */`
Re-enables checks of _all [features](#features-list)_
##### `/* doiuse-enable feature */`
Enables checks of _specified [feature(s)](#features-list)_ (can be comma separated list)
- for following lines in file
# [Contributing](CONTRIBUTING.md)
## [Contributing](CONTRIBUTING.md)
doiuse is an [OPEN Open Source](http://openopensource.org/) Project. This means that:
doiuse is an [OPEN Open Source](http://openopensource.org/) Project.
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.
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
## License

@@ -177,0 +176,0 @@ MIT

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc