Skip to content

Commit 203fc1f

Browse files
committed
initial commit
0 parents  commit 203fc1f

File tree

7 files changed

+150
-0
lines changed

7 files changed

+150
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) Andy Axton
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
## CSS Properties and Values
2+
A JSON list of CSS properties and their values. Some of the values represent value types, such as color and length. Most results contain initial and inherit.
3+
4+
### Installation
5+
```bash
6+
npm install css-properties-values --save
7+
```
8+
9+
### Usage
10+
```javascript
11+
var cssProps = require('css-properties-values');
12+
// output
13+
// [
14+
// {
15+
// property: "color",
16+
// values: ["color", "initial", "inherit"]
17+
// },
18+
// ...
19+
// ]
20+
```
21+
22+
### Building
23+
```bash
24+
npm install
25+
npm run build
26+
```

build.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
'use strict';
2+
3+
const fs = require('fs');
4+
const cheerio = require('cheerio');
5+
const got = require('got');
6+
const each = require('async-each');
7+
8+
const parentUrl = 'http://www.w3schools.com/cssref/';
9+
const childUrl = (url) => `${parentUrl}${url}`;
10+
const results = [];
11+
12+
const getPropValues = (url) => {
13+
return new Promise((resolve, reject) => {
14+
got(childUrl(url))
15+
.then(response => {
16+
let $child = cheerio.load(response.body);
17+
let $rows = $child('.w3-table-all tr');
18+
let results = [];
19+
20+
$rows.each((i, row) => {
21+
if (i > 0) {
22+
let $cols = $child(row).find('td');
23+
let value = $cols.eq(0).text();
24+
results.push(value);
25+
}
26+
});
27+
resolve(results);
28+
})
29+
.catch(reject);
30+
});
31+
};
32+
33+
const saveResults = () => {
34+
fs.writeFile('css-properties-values.json', JSON.stringify(results));
35+
}
36+
37+
got(parentUrl)
38+
.then(response => {
39+
let $parent = cheerio.load(response.body);
40+
let $rows = $parent('.w3-table-all tr');
41+
42+
each($rows.toArray(), (row, next) => {
43+
let $cols = $parent(row).find('td');
44+
let property = $cols.eq(0).text();
45+
let childUrl = $parent(row).find('a').attr('href');
46+
47+
// no prop, skip
48+
if (!property.length) {
49+
next();
50+
} else {
51+
if (childUrl) {
52+
// get values of property
53+
getPropValues(childUrl)
54+
.then((values) => {
55+
results.push({
56+
property,
57+
values
58+
});
59+
next();
60+
})
61+
.catch((err) => console.log(err));
62+
} else {
63+
// no values, push anyways
64+
results.push({
65+
property,
66+
values: null
67+
});
68+
next();
69+
}
70+
}
71+
}, saveResults);
72+
})
73+
.catch(error => {
74+
console.log(error.response.body);
75+
});

css-properties-values.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./css-properties-values');

package.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "css-properties-values",
3+
"version": "1.0.0",
4+
"description": "list of css properties and their values",
5+
"website": "https://github.com/a-axton/css-properties-values",
6+
"repository": {
7+
"type": "git",
8+
"url": "https://github.com/a-axton/css-properties-values.git"
9+
},
10+
"bugs": {
11+
"url": "https://github.com/a-axton/css-properties-values/issues"
12+
},
13+
"main": "index.js",
14+
"scripts": {
15+
"test": "echo \"Error: no test specified\" && exit 1",
16+
"build": "node build.js"
17+
},
18+
"author": "Andy Axton",
19+
"license": "MIT",
20+
"devDependencies": {
21+
"async-each": "^1.0.0",
22+
"cheerio": "^0.19.0",
23+
"got": "^6.0.0"
24+
}
25+
}

0 commit comments

Comments
 (0)