mirror of
https://github.com/lucide-icons/lucide.git
synced 2025-12-16 23:27:41 +01:00
* add configs
* Add vue components
* Add documentation
* add alpha release version
* improve npm ignore files
* add tests
* Make style and class attrs work
* 📦 bump version
* Add Icon suffix for component names
* bump version
* Add icon component example
* remove space
* improvements package.json
* update tests
* update workflow
54 lines
1.3 KiB
JavaScript
54 lines
1.3 KiB
JavaScript
/* eslint-disable import/no-extraneous-dependencies */
|
|
import { parseDOM } from 'htmlparser2';
|
|
import DEFAULT_ATTRS from './default-attrs.json';
|
|
import { toCamelCase, hash } from '../helpers';
|
|
|
|
const camelizeAttrs = attrs =>
|
|
Object.keys(attrs).reduce((newAttrs, attr) => {
|
|
const attrKey = toCamelCase(attr);
|
|
|
|
newAttrs[attrKey] = attrs[attr];
|
|
return newAttrs;
|
|
}, {});
|
|
|
|
export default (iconsObject, options) => {
|
|
const iconNodes = {};
|
|
|
|
Object.keys(iconsObject).forEach(icon => {
|
|
const svgString = iconsObject[icon];
|
|
const dom = parseDOM(svgString);
|
|
|
|
const children = dom.map(element => {
|
|
if (options.renderUniqueKey) {
|
|
const hashSource = {
|
|
name: element.name,
|
|
...element.attribs,
|
|
};
|
|
|
|
const uniqueKey = hash(JSON.stringify(hashSource));
|
|
|
|
element.attribs.key = uniqueKey;
|
|
}
|
|
|
|
return [
|
|
element.name,
|
|
{
|
|
...(options.camelizeAttrs ? camelizeAttrs(element.attribs) : element.attribs),
|
|
},
|
|
];
|
|
});
|
|
|
|
iconNodes[icon] = !options.noDefaultAttrs
|
|
? [
|
|
'svg',
|
|
{
|
|
...(options.camelizeAttrs ? camelizeAttrs(DEFAULT_ATTRS) : DEFAULT_ATTRS),
|
|
},
|
|
children,
|
|
]
|
|
: children;
|
|
});
|
|
|
|
return iconNodes;
|
|
};
|