Added logging, changed some directory structure

This commit is contained in:
2018-01-13 21:33:40 -05:00
parent f079a5f067
commit 8e72ffb917
73656 changed files with 35284 additions and 53718 deletions

View File

@@ -0,0 +1,79 @@
# 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

View File

@@ -0,0 +1,21 @@
The 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.

View File

@@ -0,0 +1,129 @@
# 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)

View File

@@ -0,0 +1,99 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getBrowserScope = exports.setBrowserScope = exports.getLatestStableBrowsers = exports.find = exports.isSupported = exports.getSupport = exports.features = undefined;
var _lodash = require("lodash.memoize");
var _lodash2 = _interopRequireDefault(_lodash);
var _browserslist = require("browserslist");
var _browserslist2 = _interopRequireDefault(_browserslist);
var _utils = require("./utils");
var _data = require("caniuse-db/data.json");
var _data2 = _interopRequireDefault(_data);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var features = _data2.default.data;
var featuresList = Object.keys(features);
var browsers = void 0;
function setBrowserScope(browserList) {
browsers = (0, _utils.cleanBrowsersList)(browserList);
}
function getBrowserScope() {
return browsers;
}
var parse = (0, _lodash2.default)(_utils.parseCaniuseData, function (feature, browsers) {
return feature.title + browsers;
});
function getSupport(query) {
var feature = void 0;
try {
feature = features[query];
} catch (e) {
var 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) {
var data = void 0;
try {
data = features[feature];
} catch (e) {
var 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 (0, _browserslist2.default)(browsers).map(function (browser) {
return browser.split(" ");
}).every(function (browser) {
return 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(function (file) {
return (0, _utils.contains)(file, query);
});
}
function getLatestStableBrowsers() {
return _browserslist2.default.queries.lastVersions.select(1);
}
setBrowserScope();
exports.features = featuresList;
exports.getSupport = getSupport;
exports.isSupported = isSupported;
exports.find = find;
exports.getLatestStableBrowsers = getLatestStableBrowsers;
exports.setBrowserScope = setBrowserScope;
exports.getBrowserScope = getBrowserScope;

View File

@@ -0,0 +1,59 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.contains = contains;
exports.parseCaniuseData = parseCaniuseData;
exports.cleanBrowsersList = cleanBrowsersList;
var _lodash = require("lodash.uniq");
var _lodash2 = _interopRequireDefault(_lodash);
var _browserslist = require("browserslist");
var _browserslist2 = _interopRequireDefault(_browserslist);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function contains(str, substr) {
return !!~str.indexOf(substr);
}
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;
}
function cleanBrowsersList(browserList) {
return (0, _lodash2.default)((0, _browserslist2.default)(browserList).map(function (browser) {
return browser.split(" ")[0];
}));
}

View File

@@ -0,0 +1,82 @@
{
"_args": [
[
"caniuse-api@1.6.1",
"C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project"
]
],
"_from": "caniuse-api@1.6.1",
"_id": "caniuse-api@1.6.1",
"_inBundle": false,
"_integrity": "sha1-tTTnxzTE+B7F++isoq0kNUuWLGw=",
"_location": "/css-loader/caniuse-api",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "caniuse-api@1.6.1",
"name": "caniuse-api",
"escapedName": "caniuse-api",
"rawSpec": "1.6.1",
"saveSpec": null,
"fetchSpec": "1.6.1"
},
"_requiredBy": [
"/css-loader/postcss-merge-rules"
],
"_resolved": "https://registry.npmjs.org/caniuse-api/-/caniuse-api-1.6.1.tgz",
"_spec": "1.6.1",
"_where": "C:\\Users\\deranjer\\go\\src\\github.com\\deranjer\\goTorrent\\torrent-project",
"authors": [
"nyalab",
"MoOx"
],
"babel": {
"presets": [
"babel-preset-latest"
]
},
"bugs": {
"url": "https://github.com/nyalab/caniuse-api/issues"
},
"dependencies": {
"browserslist": "^1.3.6",
"caniuse-db": "^1.0.30000529",
"lodash.memoize": "^4.1.2",
"lodash.uniq": "^4.5.0"
},
"description": "request the caniuse data to check browsers compatibilities",
"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"
},
"files": [
"dist"
],
"homepage": "https://github.com/nyalab/caniuse-api#readme",
"keywords": [
"caniuse",
"browserslist"
],
"license": "MIT",
"main": "dist/index.js",
"name": "caniuse-api",
"repository": {
"type": "git",
"url": "git+https://github.com/nyalab/caniuse-api.git"
},
"scripts": {
"build": "babel src --out-dir dist",
"lint": "jshint src",
"prepublish": "npm run build",
"release": "npmpub",
"test": "npm run lint && babel-tape-runner test/*.js | tap-spec"
},
"version": "1.6.1"
}