diff --git a/.npmignore b/.npmignore index 6be3879e..cffece27 100644 --- a/.npmignore +++ b/.npmignore @@ -5,4 +5,5 @@ !icons/ !package.json !README.md -!LICENSE.md \ No newline at end of file +!LICENSE.md +!index.js diff --git a/README.md b/README.md index c422f85b..94c45964 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,32 @@ # Simple Icons -Free SVG icons for popular brands, started by [Dan Leech](https://twitter.com/bathtype). [See them all on one page at **simpleicons.org**](https://simpleicons.org). Contributions, corrections & requests can be made on GitHub. +Free SVG icons for popular brands, started by [Dan Leech](https://twitter.com/bathtype). [See them all on one page at **simpleicons.org**](https://simpleicons.org). Contributions, corrections & requests can be made on GitHub. -## To do +## Usage -- [ ] Analytics tracking for icon clicks -- [ ] New README.md +Icons can be downloaded as SVGs directly from [our website](https://simpleicons.org/) - simply click the icon you want, and the download should start automatically. + +### Node Usage + +The icons are also available through our npm package. To install, simply run: + +``` +$ npm install simple-icons +``` + +The API can then be used as follows: + +```javascript +const simpleIcons = require('simple-icons'); + +console.log(simpleIcons['Google+']); + +/* +{ + title: 'Google+', + hex: 'DC4E41', + source: 'https://developers.google.com/+/branding-guidelines', + svg: '...' +} +*/ +``` diff --git a/index.js b/index.js new file mode 100644 index 00000000..95ca27f3 --- /dev/null +++ b/index.js @@ -0,0 +1,15 @@ +const dataFile = './_data/simple-icons.json'; +const data = require(dataFile); +const fs = require('fs'); + +const icons = {}; + +data.icons.forEach(i => { + const filename = i.title.toLowerCase() + .replace(/\+/g, "plus") + .replace(/[ .\-!’]/g, ''); + i.svg = fs.readFileSync(`./icons/${filename}.svg`, 'utf8'); + icons[i.title] = i +}); + +module.exports = icons; diff --git a/package.json b/package.json index ef951902..4c2d0194 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,7 @@ "svg", "icons" ], - "main": "_data/simple-icons.json", + "main": "index.js", "repository": "git@github.com:danleech/simple-icons.git", "author": "Dan Leech", "license": "CCO",