mirror of
https://github.com/simple-icons/simple-icons.git
synced 2024-11-16 00:59:07 +02:00
Remove get-by-title from NPM package API (#4920)
This commit is contained in:
parent
860ab3874d
commit
c66b8bc2f3
@ -34,12 +34,7 @@ function escape(value) {
|
|||||||
return value.replace(/(?<!\\)'/g, "\\'");
|
return value.replace(/(?<!\\)'/g, "\\'");
|
||||||
}
|
}
|
||||||
function iconToKeyValue(icon) {
|
function iconToKeyValue(icon) {
|
||||||
let iconName = escape(icon.title);
|
return `'${icon.slug}':${iconToObject(icon)}`;
|
||||||
if (icon.slug !== titleToSlug(icon.title)) {
|
|
||||||
iconName = icon.slug;
|
|
||||||
}
|
|
||||||
|
|
||||||
return `'${iconName}':${iconToObject(icon)}`;
|
|
||||||
}
|
}
|
||||||
function licenseToObject(license) {
|
function licenseToObject(license) {
|
||||||
if (license === undefined) {
|
if (license === undefined) {
|
||||||
|
@ -3,23 +3,8 @@ var icons = {%s};
|
|||||||
Object.defineProperty(icons, "get", {
|
Object.defineProperty(icons, "get", {
|
||||||
enumerable: false,
|
enumerable: false,
|
||||||
value: function(targetName) {
|
value: function(targetName) {
|
||||||
if (icons[targetName]) {
|
|
||||||
return icons[targetName];
|
return icons[targetName];
|
||||||
}
|
}
|
||||||
var normalizedName = targetName.toLowerCase();
|
|
||||||
for (var iconName in icons) {
|
|
||||||
var icon = icons[iconName];
|
|
||||||
if (icon.slug === normalizedName) {
|
|
||||||
return icon;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (var iconName in icons) {
|
|
||||||
var icon = icons[iconName];
|
|
||||||
if (icon.title.toLowerCase() === normalizedName) {
|
|
||||||
return icon;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = icons;
|
module.exports = icons;
|
||||||
|
@ -3,8 +3,8 @@ const simpleIcons = require('../index.js');
|
|||||||
const { getIconSlug } = require("../scripts/utils.js");
|
const { getIconSlug } = require("../scripts/utils.js");
|
||||||
|
|
||||||
icons.forEach(icon => {
|
icons.forEach(icon => {
|
||||||
const name = icon.slug || icon.title;
|
const slug = getIconSlug(icon);
|
||||||
const subject = simpleIcons[name];
|
const subject = simpleIcons[slug];
|
||||||
|
|
||||||
test(`${icon.title} has the correct "title"`, () => {
|
test(`${icon.title} has the correct "title"`, () => {
|
||||||
expect(typeof subject.title).toBe('string');
|
expect(typeof subject.title).toBe('string');
|
||||||
@ -13,7 +13,7 @@ icons.forEach(icon => {
|
|||||||
|
|
||||||
test(`${icon.title} has the correct "slug"`, () => {
|
test(`${icon.title} has the correct "slug"`, () => {
|
||||||
expect(typeof subject.slug).toBe('string');
|
expect(typeof subject.slug).toBe('string');
|
||||||
expect(subject.slug).toEqual(getIconSlug(icon));
|
expect(subject.slug).toEqual(slug);
|
||||||
});
|
});
|
||||||
|
|
||||||
test(`${icon.title} has the correct "hex" value`, () => {
|
test(`${icon.title} has the correct "hex" value`, () => {
|
||||||
@ -59,21 +59,8 @@ icons.forEach(icon => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// NOTE: Icons with custom slugs have a custom slug because their title is
|
|
||||||
// already taken, so they should not be findable by their title.
|
|
||||||
if (icon.slug === undefined) {
|
|
||||||
test(`${icon.title} can be found by it's title`, () => {
|
|
||||||
const found = simpleIcons.get(icon.title);
|
|
||||||
expect(found).toBeDefined();
|
|
||||||
expect(found.title).toEqual(icon.title);
|
|
||||||
expect(found.hex).toEqual(icon.hex);
|
|
||||||
expect(found.source).toEqual(icon.source);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
test(`${icon.title} can be found by it's slug`, () => {
|
test(`${icon.title} can be found by it's slug`, () => {
|
||||||
const name = getIconSlug(icon);
|
const found = simpleIcons.get(slug);
|
||||||
const found = simpleIcons.get(name);
|
|
||||||
expect(found).toBeDefined();
|
expect(found).toBeDefined();
|
||||||
expect(found.title).toEqual(icon.title);
|
expect(found.title).toEqual(icon.title);
|
||||||
expect(found.hex).toEqual(icon.hex);
|
expect(found.hex).toEqual(icon.hex);
|
||||||
|
Loading…
Reference in New Issue
Block a user