Skip to content

Commit

Permalink
Merge pull request #299 from dzhuang/warn_underscore
Browse files Browse the repository at this point in the history
Warn user when using "_" instead of "-" in iconNames
closes #298
  • Loading branch information
dzhuang authored Jun 10, 2023
2 parents 6df7aa1 + e2d8c22 commit 9559170
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/providers/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,20 @@ export abstract class ProviderConstructor implements ProviderInterface {
}

private validateIconMeta(iconName: SubsetItem): MetaData {
if (typeof this.allMetaData[iconName] === 'undefined')
if (typeof this.allMetaData[iconName] === 'undefined') {
if (iconName.includes('_')) {
const alterIconName = iconName.replace(/_/g, '-');
if ('undefined' !== typeof this.allMetaData[alterIconName]) {
throw new WarningError(
`"${iconName}" does not exists in metadata available, ` +
`do you mean "${alterIconName}" instead?`
);
}
}
throw new WarningError(
`"${iconName}" does not exists in metadata available.`
);
}

const metaData: MetaData = this.normalizeIconMeta(iconName);

Expand Down
25 changes: 25 additions & 0 deletions tests/combine.mocha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,31 @@ describe('General tests', () => {
);
});

it('should not work for iconName with "_" instead of "-" as separator', (done) => {
// The first will log: do you mean "arrow-left" instead?
// the second will log: "icon_does_not_exists" does not exists in metadata available
const mdi = new MdiProvider(['arrow_left', 'icon_does_not_exists']);

generateCombinedSubsetFont(
{
subset: [mdi],
},
done,

// this should generate nothing, we simply check if the css is generated.
{
cssFileNames: [
{
names: {
nonExist: [COMBINED_CSS_NAME, DEFAULT_COMBINE_FILE_NAME],
},
extensions: { exist: [] },
},
],
}
);
});

it('should not work for mdi when icons not exist were input multiple times', (done) => {
const mdi = new MdiProvider([
'icon-does-not-exists',
Expand Down

0 comments on commit 9559170

Please sign in to comment.