mirror of
https://github.com/Mibew/simple-icons.git
synced 2025-05-02 00:56:42 +03:00
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:
parent
986a9d6d59
commit
9ebc626ab5
@ -47,6 +47,7 @@ console.log(simpleIcons['Simple Icons']);
|
|||||||
/*
|
/*
|
||||||
{
|
{
|
||||||
title: 'Simple Icons',
|
title: 'Simple Icons',
|
||||||
|
slug: 'simpleicons',
|
||||||
hex: '111111',
|
hex: '111111',
|
||||||
source: 'https://simpleicons.org/',
|
source: 'https://simpleicons.org/',
|
||||||
svg: '<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">...</svg>',
|
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',
|
title: 'Simple Icons',
|
||||||
|
slug: 'simpleicons',
|
||||||
hex: '111111',
|
hex: '111111',
|
||||||
source: 'https://simpleicons.org/',
|
source: 'https://simpleicons.org/',
|
||||||
svg: '<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">...</svg>',
|
svg: '<svg role="img" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">...</svg>',
|
||||||
|
@ -20,7 +20,7 @@ function iconToKeyValue(icon) {
|
|||||||
return `'${icon.title}':${iconToObject(icon)}`;
|
return `'${icon.title}':${iconToObject(icon)}`;
|
||||||
}
|
}
|
||||||
function 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'
|
// 'main'
|
||||||
@ -28,6 +28,7 @@ const icons = [];
|
|||||||
data.icons.forEach(icon => {
|
data.icons.forEach(icon => {
|
||||||
const filename = titleToFilename(icon.title);
|
const filename = titleToFilename(icon.title);
|
||||||
icon.svg = fs.readFileSync(`${iconsDir}/${filename}.svg`, "utf8");
|
icon.svg = fs.readFileSync(`${iconsDir}/${filename}.svg`, "utf8");
|
||||||
|
icon.slug = filename;
|
||||||
icons.push(icon)
|
icons.push(icon)
|
||||||
|
|
||||||
// write the static .js file for the icon
|
// write the static .js file for the icon
|
||||||
|
@ -26,4 +26,8 @@ icons.forEach(icon => {
|
|||||||
expect(typeof subject.path).toBe('string');
|
expect(typeof subject.path).toBe('string');
|
||||||
expect(subject.path).toMatch(/[MmZzLlHhVvCcSsQqTtAa0-9-,.\s]/g);
|
expect(subject.path).toMatch(/[MmZzLlHhVvCcSsQqTtAa0-9-,.\s]/g);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test(`${icon.title} has a "slug"`, () => {
|
||||||
|
expect(typeof subject.slug).toBe('string');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -25,4 +25,8 @@ icons.forEach(icon => {
|
|||||||
expect(typeof subject.path).toBe('string');
|
expect(typeof subject.path).toBe('string');
|
||||||
expect(subject.path).toMatch(/^[MmZzLlHhVvCcSsQqTtAa0-9-,.\s]+$/g);
|
expect(subject.path).toMatch(/^[MmZzLlHhVvCcSsQqTtAa0-9-,.\s]+$/g);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test(`${icon.title} has a "slug"`, () => {
|
||||||
|
expect(typeof subject.slug).toBe('string');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user