From 6588971ead5664aa881588da7081300da8a8355d Mon Sep 17 00:00:00 2001 From: Karsa Date: Tue, 8 Oct 2024 10:36:35 +0200 Subject: [PATCH] fix(site): use the same camel/pascal same conversion as when releasing packages (#2509) --- .../theme/components/icons/CopyCodeButton.vue | 76 +++++++++---------- docs/icons/[name].md | 7 +- packages/shared/src/utils.ts | 15 +++- 3 files changed, 53 insertions(+), 45 deletions(-) diff --git a/docs/.vitepress/theme/components/icons/CopyCodeButton.vue b/docs/.vitepress/theme/components/icons/CopyCodeButton.vue index 9c806dd76..a58fcf4f5 100644 --- a/docs/.vitepress/theme/components/icons/CopyCodeButton.vue +++ b/docs/.vitepress/theme/components/icons/CopyCodeButton.vue @@ -1,98 +1,98 @@ @@ -106,11 +106,11 @@ function copyAngular() { data-confetti-text="Copied!" :popoverPosition="popoverPosition" :options="[ - { text: 'Copy JSX' , onClick: copyJSX }, - { text: 'Copy Component Name' , onClick: copyComponentName }, - { text: 'Copy Vue' , onClick: copyVue }, - { text: 'Copy Svelte' , onClick: copyJSX }, - { text: 'Copy Angular' , onClick: copyAngular }, + { text: 'Copy JSX', onClick: copyJSX }, + { text: 'Copy Component Name', onClick: copyComponentName }, + { text: 'Copy Vue', onClick: copyVue }, + { text: 'Copy Svelte', onClick: copyJSX }, + { text: 'Copy Angular', onClick: copyAngular }, ]" /> diff --git a/docs/icons/[name].md b/docs/icons/[name].md index 9406e93bb..f69e966c3 100644 --- a/docs/icons/[name].md +++ b/docs/icons/[name].md @@ -18,9 +18,8 @@ import RelatedIcons from '~/.vitepress/theme/components/icons/RelatedIcons.vue' import CodeGroup from '~/.vitepress/theme/components/base/CodeGroup.vue' import Badge from '~/.vitepress/theme/components/base/Badge.vue' import Label from '~/.vitepress/theme/components/base/Label.vue' -import VPButton from 'vitepress/dist/client/theme-default/components/VPButton.vue'; import { data } from './codeExamples.data' -import { camelCase, startCase } from 'lodash-es' +import { toCamelCase, toPascalCase } from '@lucide/shared' import { satisfies } from 'semver' const { params } = useData() @@ -31,8 +30,8 @@ const tabs = computed(() => data.codeExamples?.map( const codeExample = computed(() => data.codeExamples?.map( (codeExample) => { - const pascalCaseName = startCase(camelCase( params.value.name)).replace(/\s/g, '') - const camelCaseName = camelCase(params.value.name) + const pascalCaseName = toPascalCase( params.value.name) + const camelCaseName = toCamelCase(params.value.name) return codeExample.code .replace(/\$(?:<[^>]+>)*PascalCase/g, pascalCaseName) diff --git a/packages/shared/src/utils.ts b/packages/shared/src/utils.ts index f068a5714..6a0db486a 100644 --- a/packages/shared/src/utils.ts +++ b/packages/shared/src/utils.ts @@ -9,6 +9,17 @@ import { CamelToPascal } from './utility-types'; export const toKebabCase = (string: string) => string.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase(); +/** + * Converts string to camel case + * + * @param {string} string + * @returns {string} A camelized string + */ +export const toCamelCase = (string: T) => + string.replace(/^([A-Z])|[\s-_]+(\w)/g, (match, p1, p2) => + p2 ? p2.toUpperCase() : p1.toLowerCase(), + ); + /** * Converts string to pascal case * @@ -16,9 +27,7 @@ export const toKebabCase = (string: string) => * @returns {string} A pascalized string */ export const toPascalCase = (string: T): CamelToPascal => { - const camelCase = string.replace(/^([A-Z])|[\s-_]+(\w)/g, (match, p1, p2) => - p2 ? p2.toUpperCase() : p1.toLowerCase(), - ); + const camelCase = toCamelCase(string); return (camelCase.charAt(0).toUpperCase() + camelCase.slice(1)) as CamelToPascal; };