Skip to content

Commit

Permalink
add a new export: feature list
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyalab committed Sep 14, 2016
1 parent 14c7433 commit 6a6771f
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@
"dist"
],
"dependencies": {
"browserslist": "^1.0.1",
"caniuse-db": "^1.0.30000346",
"lodash.memoize": "^4.1.0",
"lodash.uniq": "^4.3.0",
"shelljs": "^0.7.0"
"browserslist": "^1.3.6",
"caniuse-db": "^1.0.30000529",
"lodash.memoize": "^4.1.2",
"lodash.uniq": "^4.5.0",
"shelljs": "^0.7.4"
},
"devDependencies": {
"babel": "^4.7.16",
"babel-tape-runner": "^1.3.1",
"jshint": "^2.5.10",
"jshint": "^2.9.3",
"npmpub": "^3.1.0",
"tap-spec": "^4.1.1",
"tape": "^4.5.1"
"tape": "^4.6.0"
},
"scripts": {
"build": "babel src --out-dir dist",
Expand Down
16 changes: 11 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import {contains, parseCaniuseData, cleanBrowsersList} from "./utils"
import db from "caniuse-db/data.json"

const features = db.data

const featuresList = Object.keys(features)


var browsers
let browsers
function setBrowserScope(browserList) {
browsers = cleanBrowsersList(browserList)
}
Expand All @@ -18,7 +16,7 @@ function getBrowserScope() {
return browsers
}

var parse = memoize(parseCaniuseData, function(feature, browsers) {
const parse = memoize(parseCaniuseData, function(feature, browsers) {
return feature.title + browsers
})

Expand Down Expand Up @@ -70,4 +68,12 @@ function getLatestStableBrowsers() {

setBrowserScope()

export {getSupport, isSupported, find, getLatestStableBrowsers, setBrowserScope, getBrowserScope}
export {
featuresList as features,
getSupport,
isSupported,
find,
getLatestStableBrowsers,
setBrowserScope,
getBrowserScope
}
9 changes: 7 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ test("browserscope tests", (t) => {
t.end()
})

test("features test", (t) => {
t.ok(Array.isArray(caniuse.features), "a feature list is exported")
t.ok(caniuse.features.length > 0, "the feature list is not empty")
t.end()
})

test("find tests", (t) => {
t.deepEqual(caniuse.find("radius"), ["border-radius"], "`find` should find border-radius")
t.deepEqual(caniuse.find("canaillou"), [], "non-existent property should return an empty array")
Expand Down Expand Up @@ -58,7 +64,7 @@ test("getSupport tests", (t) => {
let borderRadiusSupport = {
safari: { y: 3.1, x: 4, '#1': 6.1 },
opera: { n: 10, y: 10.5 },
op_mini: {},
op_mini: { n: 5 },
ios_saf: { y: 3.2, x: 3.2 },
ie_mob: { y: 10 },
edge: { y: 12 },
Expand All @@ -69,7 +75,6 @@ test("getSupport tests", (t) => {
and_uc: { y: 9.9 },
// workaround for https://github.com/Nyalab/caniuse-api/issues/19
and_chr: { y: parseInt(Object.keys(borderRadiusFeature.stats.and_chr).filter(v => borderRadiusFeature.stats.and_chr[v] === "y").pop()) },
samsung: { y: 4 }
}

t.deepEqual(caniuse.getSupport("border-radius"), borderRadiusSupport, "border-radius support is ok")
Expand Down
3 changes: 1 addition & 2 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test("parseCaniuseData should work", (t) => {
let correctSupport = {
safari: { y: 3.1, x: 4, '#1': 6.1 },
opera: { n: 10, y: 10.5 },
op_mini: { },
op_mini: { n: 5 },
ios_saf: { y: 3.2, x: 3.2 },
ie_mob: { y: 10 },
ie: { n: 8, y: 9 },
Expand All @@ -28,7 +28,6 @@ test("parseCaniuseData should work", (t) => {
and_uc: { y: 9.9 },
// workaround for https://github.com/Nyalab/caniuse-api/issues/19
and_chr: { y: parseInt(Object.keys(borderRadiusFeature.stats.and_chr).filter(v => borderRadiusFeature.stats.and_chr[v] === "y").pop()) },
samsung: { y: 4 }
}

t.deepEqual(parseCaniuseData(borderRadiusFeature, browsers), correctSupport, "border-radius support is correct")
Expand Down

0 comments on commit 6a6771f

Please sign in to comment.