mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
feat(icons): setup icons package (#536)
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
export function pascalCase(str: string): string {
|
||||
return str.replace(/[-_](.)/g, (_, c) => c.toUpperCase()).replace(/^(.)/, (_, c) => c.toUpperCase());
|
||||
}
|
||||
|
||||
export function camelCase(str: string): string {
|
||||
return pascalCase(str).replace(/^(.)/, (_, c) => c.toLowerCase());
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export * from './casing';
|
||||
@@ -0,0 +1,44 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { camelCase, pascalCase } from '../casing';
|
||||
|
||||
describe('casing', () => {
|
||||
describe('pascalCase', () => {
|
||||
it('converts simple strings', () => {
|
||||
expect(pascalCase('hello')).toBe('Hello');
|
||||
});
|
||||
|
||||
it('converts kebab-case', () => {
|
||||
expect(pascalCase('hello-world')).toBe('HelloWorld');
|
||||
});
|
||||
|
||||
it('converts snake_case', () => {
|
||||
expect(pascalCase('hello_world')).toBe('HelloWorld');
|
||||
});
|
||||
|
||||
it('converts mixed case', () => {
|
||||
expect(pascalCase('hello-World')).toBe('HelloWorld');
|
||||
});
|
||||
|
||||
it('handles already pascal case', () => {
|
||||
expect(pascalCase('HelloWorld')).toBe('HelloWorld');
|
||||
});
|
||||
});
|
||||
|
||||
describe('camelCase', () => {
|
||||
it('converts simple strings', () => {
|
||||
expect(camelCase('hello')).toBe('hello');
|
||||
});
|
||||
|
||||
it('converts pascal case', () => {
|
||||
expect(camelCase('HelloWorld')).toBe('helloWorld');
|
||||
});
|
||||
|
||||
it('converts kebab-case', () => {
|
||||
expect(camelCase('hello-world')).toBe('helloWorld');
|
||||
});
|
||||
|
||||
it('converts snake_case', () => {
|
||||
expect(camelCase('hello_world')).toBe('helloWorld');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* A (very basic) utility to merge class names and make them a little easier to read.
|
||||
* Aims to replicate the API of popular libraries like `clsx` and `classnames` but with a much simpler implementation.
|
||||
* This is not intended to be a full replacement for those libraries, but it should be sufficient for our use case.
|
||||
* It also allows us to avoid adding an additional dependency to our packages.
|
||||
* @param classes - An array of class names, which can be strings or undefined. Undefined values will be filtered out.
|
||||
* @returns A single string of class names, separated by spaces.
|
||||
*/
|
||||
export function cn(...classes: (string | undefined)[]): string {
|
||||
return classes.filter(Boolean).join(' ');
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
export * from './cn';
|
||||
@@ -0,0 +1,32 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { cn } from '../cn';
|
||||
|
||||
describe('cn', () => {
|
||||
it('returns an empty string for no arguments', () => {
|
||||
expect(cn()).toBe('');
|
||||
});
|
||||
|
||||
it('returns a single class name', () => {
|
||||
expect(cn('foo')).toBe('foo');
|
||||
});
|
||||
|
||||
it('joins multiple class names with a space', () => {
|
||||
expect(cn('foo', 'bar', 'baz')).toBe('foo bar baz');
|
||||
});
|
||||
|
||||
it('filters out undefined values', () => {
|
||||
expect(cn('foo', undefined, 'bar')).toBe('foo bar');
|
||||
});
|
||||
|
||||
it('handles all undefined values', () => {
|
||||
expect(cn(undefined, undefined)).toBe('');
|
||||
});
|
||||
|
||||
it('filters out empty strings', () => {
|
||||
expect(cn('foo', '', 'bar')).toBe('foo bar');
|
||||
});
|
||||
|
||||
it('preserves class names with multiple words', () => {
|
||||
expect(cn('foo bar', 'baz')).toBe('foo bar baz');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user