Skip to content

Commit

Permalink
fix(core): added undefined check for pascal util (#1025)
Browse files Browse the repository at this point in the history
  • Loading branch information
YBijen authored Nov 8, 2023
1 parent 313c8b0 commit e7dc399
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
44 changes: 28 additions & 16 deletions packages/core/src/utils/case.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, expect, it } from 'vitest';
import { pascal } from './case';
import { camel, pascal } from './case';
import { kebab } from './case';

describe('pascal case testing', () => {
Expand All @@ -26,23 +26,35 @@ describe('pascal case testing', () => {
it('should handle some casing edge cases', () => {
expect(pascal('foo_bar_API')).toBe('FooBarAPI');
});

it('should handle empty values', () => {
expect(pascal('')).toBe('');
expect(pascal(undefined)).toBe('');
});
});

describe('camel case testing', () => {
it('should handle empty values', () => {
expect(camel('')).toBe('');
expect(camel(undefined)).toBe('');
});
});

describe('kebab-case a few examples', () => {
//fix #937, issue #936, results in kebab routine being potentially called
//on a string **repeatedly**.
//Do some basic kebab case checks
//Additionally, test that the kebab routine is Idempotent
[
['Pet', 'pet'],
['pet', 'pet'],
['PetTag', 'pet-tag'],
['pet-tag', 'pet-tag'],
['PetTagWithFourWords', 'pet-tag-with-four-words'],
['pet-tag-with-four-words', 'pet-tag-with-four-words'],
].forEach(([input, expected]) => {
it(`should process ${input} to ${expected}`, () => {
expect(kebab(input)).toBe(expected);
});
//fix #937, issue #936, results in kebab routine being potentially called
//on a string **repeatedly**.
//Do some basic kebab case checks
//Additionally, test that the kebab routine is Idempotent
[
['Pet', 'pet'],
['pet', 'pet'],
['PetTag', 'pet-tag'],
['pet-tag', 'pet-tag'],
['PetTagWithFourWords', 'pet-tag-with-four-words'],
['pet-tag-with-four-words', 'pet-tag-with-four-words'],
].forEach(([input, expected]) => {
it(`should process ${input} to ${expected}`, () => {
expect(kebab(input)).toBe(expected);
});
});
});
2 changes: 1 addition & 1 deletion packages/core/src/utils/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export const pascal = (s: string) => {
s = low.call(s);
}

const pascalString = (s.match(/[a-zA-Z0-9]+/g) || [])
const pascalString = (s?.match(/[a-zA-Z0-9]+/g) || [])
.map((w) => w.charAt(0).toUpperCase() + w.slice(1))
.join('');

Expand Down

0 comments on commit e7dc399

Please sign in to comment.