From ca0e2ac72eead6afeaf5c98c65db96628964d7fb Mon Sep 17 00:00:00 2001 From: Jenil Gogari Date: Sat, 16 Sep 2017 16:49:58 -0400 Subject: [PATCH 1/6] add index.js file for npm make is possible to import all icons with the SVG content, see example.js for usage Discussion at https://github.com/simple-icons/simple-icons/pull/446 --- example.js | 11 +++++++++++ index.js | 13 +++++++++++++ package.json | 2 +- 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 example.js create mode 100644 index.js diff --git a/example.js b/example.js new file mode 100644 index 000000000..f4aeafeb6 --- /dev/null +++ b/example.js @@ -0,0 +1,11 @@ +const SimpleIcons = require('./'); + +console.log(SimpleIcons['500px'].svg); + +/* +{ title: '500px', + hex: '0099E5', + source: 'https://about.500px.com/press', + name: '500px', + svg: '...' } +*/ diff --git a/index.js b/index.js new file mode 100644 index 000000000..5d3fbb9cf --- /dev/null +++ b/index.js @@ -0,0 +1,13 @@ +const dataFile = './_data/simple-icons.json'; +const data = require(dataFile); +const fs = require('fs'); + +let Icons = {}; + +data.icons.forEach(i => { + i.name = i.title.toLowerCase().replace(/[^a-z0-9]/gim, ''); + i.svg = fs.readFileSync(`./icons/${i.name}.svg`, 'utf8'); + Icons[i.name] = i +}); + +module.exports = Icons; diff --git a/package.json b/package.json index ef951902c..4c2d01947 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", From 3a753611cedb7aadaafdd7a0e150e9f7a91bc1dc Mon Sep 17 00:00:00 2001 From: birjolaxew Date: Sun, 17 Sep 2017 03:48:02 +0200 Subject: [PATCH 2/6] Update index.js to use proper title->filename conversion --- index.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index 5d3fbb9cf..95ca27f3d 100644 --- a/index.js +++ b/index.js @@ -2,12 +2,14 @@ const dataFile = './_data/simple-icons.json'; const data = require(dataFile); const fs = require('fs'); -let Icons = {}; +const icons = {}; data.icons.forEach(i => { - i.name = i.title.toLowerCase().replace(/[^a-z0-9]/gim, ''); - i.svg = fs.readFileSync(`./icons/${i.name}.svg`, 'utf8'); - Icons[i.name] = 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; +module.exports = icons; From cc33d0c204974d24a732f34fb71437c06d6e4464 Mon Sep 17 00:00:00 2001 From: birjolaxew Date: Sun, 17 Sep 2017 03:49:13 +0200 Subject: [PATCH 3/6] Add index.js to .npmignore whitelist --- .npmignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.npmignore b/.npmignore index 6be3879e9..cffece27b 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 From 45ad431a436d909052b37d49584372c0e5a060ae Mon Sep 17 00:00:00 2001 From: birjolaxew Date: Sun, 17 Sep 2017 03:54:54 +0200 Subject: [PATCH 4/6] Update README for NPM publish --- README.md | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index c422f85bc..49d01be0a 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: + +``` +const simpleIcons = require('simple-icons'); + +console.log(simpleIcons['Google+']); + +/* +{ + title: 'Google+', + hex: 'DC4E41', + source: 'https://developers.google.com/+/branding-guidelines', + svg: '...' +} +*/ +``` From d1eaccc6d5e08d43f3365a4a3b19ce318d887494 Mon Sep 17 00:00:00 2001 From: birjolaxew Date: Sun, 17 Sep 2017 03:55:09 +0200 Subject: [PATCH 5/6] Remove example.js --- example.js | 11 ----------- 1 file changed, 11 deletions(-) delete mode 100644 example.js diff --git a/example.js b/example.js deleted file mode 100644 index f4aeafeb6..000000000 --- a/example.js +++ /dev/null @@ -1,11 +0,0 @@ -const SimpleIcons = require('./'); - -console.log(SimpleIcons['500px'].svg); - -/* -{ title: '500px', - hex: '0099E5', - source: 'https://about.500px.com/press', - name: '500px', - svg: '...' } -*/ From 1d342cb6e75e45ea95e307f4115a56345627a0ef Mon Sep 17 00:00:00 2001 From: birjolaxew Date: Sun, 17 Sep 2017 03:56:26 +0200 Subject: [PATCH 6/6] Specify language for syntax highlighting in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 49d01be0a..94c459641 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ $ npm install simple-icons The API can then be used as follows: -``` +```javascript const simpleIcons = require('simple-icons'); console.log(simpleIcons['Google+']);