-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(addClassesToSVGElement): allow function as param (svg#1966)
Updates the interface for addClassesToSVGElement to match prefixIds, where we'll accept Array<string|function> instead of just a string.
- Loading branch information
Showing
3 changed files
with
47 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { optimize } from '../../lib/svgo.js'; | ||
|
||
test('should accept function as className parameter', () => { | ||
const svg = `<svg xmlns="http://www.w3.org/2000/svg"/>`; | ||
|
||
expect( | ||
optimize(svg, { | ||
path: 'uwu.svg', | ||
plugins: [ | ||
{ | ||
name: 'addClassesToSVGElement', | ||
params: { | ||
classNames: [ | ||
'icon', | ||
(_, info) => `icon__${info?.path?.split('.')[0]}`, | ||
], | ||
}, | ||
}, | ||
], | ||
}).data, | ||
).toBe(`<svg xmlns="http://www.w3.org/2000/svg" class="icon icon__uwu"/>`); | ||
|
||
expect( | ||
optimize(svg, { | ||
path: 'uwu.svg', | ||
plugins: [ | ||
{ | ||
name: 'addClassesToSVGElement', | ||
params: { | ||
className: (_, info) => `icon__${info?.path?.split('.')[0]}`, | ||
}, | ||
}, | ||
], | ||
}).data, | ||
).toBe(`<svg xmlns="http://www.w3.org/2000/svg" class="icon__uwu"/>`); | ||
}); |