mirror of
https://github.com/lucide-icons/lucide.git
synced 2026-11-13 13:48:26 +00:00
* Add useIconComponent, lucide-react * Add concept useIconComponent * add useIconComponents to packages * Add icon component * Add icon component * Add tests for react packages * Reset changes in icons * Add types * Add support for Icon components in Lucide Vue Next * update tests * Update tests * Enable Svelte component * Fix lucide-react-native tests * Update Solid package * update snapshots * Add docs * add docs * Update tests * Formatting * Formatting * Update package lock * Remove `useIconComponent` * Update guides * Update exports preact and solid package * Formatting * Format createIcons.ts * Add lucide lab repo link in docs
38 lines
1.0 KiB
TypeScript
38 lines
1.0 KiB
TypeScript
import { CamelToPascal } from './utility-types';
|
|
|
|
/**
|
|
* Converts string to kebab case
|
|
*
|
|
* @param {string} string
|
|
* @returns {string} A kebabized string
|
|
*/
|
|
export const toKebabCase = (string: string) =>
|
|
string.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
|
|
|
|
/**
|
|
* Converts string to pascal case
|
|
*
|
|
* @param {string} string
|
|
* @returns {string} A pascalized string
|
|
*/
|
|
export const toPascalCase = <T extends string>(string: T): CamelToPascal<T> => {
|
|
const camelCase = string.replace(/^([A-Z])|[\s-_]+(\w)/g, (match, p1, p2) =>
|
|
p2 ? p2.toUpperCase() : p1.toLowerCase(),
|
|
);
|
|
|
|
return (camelCase.charAt(0).toUpperCase() + camelCase.slice(1)) as CamelToPascal<T>;
|
|
};
|
|
|
|
/**
|
|
* Merges classes into a single string
|
|
*
|
|
* @param {array} classes
|
|
* @returns {string} A string of classes
|
|
*/
|
|
export const mergeClasses = <ClassType = string | undefined | null>(...classes: ClassType[]) =>
|
|
classes
|
|
.filter((className, index, array) => {
|
|
return Boolean(className) && array.indexOf(className) === index;
|
|
})
|
|
.join(' ');
|