From ca0e2ac72eead6afeaf5c98c65db96628964d7fb Mon Sep 17 00:00:00 2001 From: Jenil Gogari Date: Sat, 16 Sep 2017 16:49:58 -0400 Subject: [PATCH] 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",