Add URL friendy/slugged name as property to package icon objects (#1520)

* Add URL friendy/slug/file name as property to package icon objects

* Test new property

* Add 'name' property to examples in README

* Rename "name" property to "slug"
This commit is contained in:
Eric Cornelissen 2019-07-14 19:09:34 +01:00 committed by Johan Fagerberg
parent 986a9d6d59
commit 9ebc626ab5
4 changed files with 12 additions and 1 deletions

View File

@ -47,6 +47,7 @@ console.log(simpleIcons['Simple Icons']);
/*
{
title: 'Simple Icons',
slug: 'simpleicons',
hex: '111111',
source: 'https://simpleicons.org/',
svg: '<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">...</svg>',
@ -66,6 +67,7 @@ console.log(icon);
/*
{
title: 'Simple Icons',
slug: 'simpleicons',
hex: '111111',
source: 'https://simpleicons.org/',
svg: '<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">...</svg>',

View File

@ -20,7 +20,7 @@ function iconToKeyValue(icon) {
return `'${icon.title}':${iconToObject(icon)}`;
}
function iconToObject(icon) {
return `{title:'${icon.title}',svg:'${icon.svg}',get path(){return this.svg.match(/<path\\s+d="([^"]*)/)[1];},source:'${icon.source.replace(/'/g, "\\'")}',hex:'${icon.hex}'}`;
return `{title:'${icon.title}',slug:'${icon.slug}',svg:'${icon.svg}',get path(){return this.svg.match(/<path\\s+d="([^"]*)/)[1];},source:'${icon.source.replace(/'/g, "\\'")}',hex:'${icon.hex}'}`;
}
// 'main'
@ -28,6 +28,7 @@ const icons = [];
data.icons.forEach(icon => {
const filename = titleToFilename(icon.title);
icon.svg = fs.readFileSync(`${iconsDir}/${filename}.svg`, "utf8");
icon.slug = filename;
icons.push(icon)
// write the static .js file for the icon

View File

@ -26,4 +26,8 @@ icons.forEach(icon => {
expect(typeof subject.path).toBe('string');
expect(subject.path).toMatch(/[MmZzLlHhVvCcSsQqTtAa0-9-,.\s]/g);
});
test(`${icon.title} has a "slug"`, () => {
expect(typeof subject.slug).toBe('string');
});
});

View File

@ -25,4 +25,8 @@ icons.forEach(icon => {
expect(typeof subject.path).toBe('string');
expect(subject.path).toMatch(/^[MmZzLlHhVvCcSsQqTtAa0-9-,.\s]+$/g);
});
test(`${icon.title} has a "slug"`, () => {
expect(typeof subject.slug).toBe('string');
});
});