mirror of
https://github.com/lucide-icons/lucide.git
synced 2026-02-24 06:49:39 +01:00
* init new react package project * setup react package * Fix config for build * update package * Fix build * update package * fix package.json * refactor and cleanup * bumb beta version * fix regex * bump version * Add hashing * Add tests * bump version * Add peer dependecies * Add docs * Add readme link
52 lines
1.2 KiB
JavaScript
52 lines
1.2 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] = [
|
|
'svg',
|
|
{
|
|
...(options.camelizeAttrs ? camelizeAttrs(DEFAULT_ATTRS) : DEFAULT_ATTRS),
|
|
},
|
|
children,
|
|
];
|
|
});
|
|
|
|
return iconNodes;
|
|
};
|