Skip to content

Commit

Permalink
Merge branch 'master' into fix-issue-with-query-enabled-reactivity
Browse files Browse the repository at this point in the history
  • Loading branch information
anymaniax authored Sep 28, 2023
2 parents 6373b56 + 71e1b00 commit bda607c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 17 deletions.
28 changes: 28 additions & 0 deletions packages/core/src/utils/case.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { describe, expect, it } from 'vitest';
import { pascal } from './case';

describe('pascal case testing', () => {
it('should convert to pascal case', () => {
expect(pascal('PascalCase')).toBe('PascalCase');
expect(pascal('camelCase')).toBe('CamelCase');
expect(pascal('kebab-case')).toBe('KebabCase');
expect(pascal('snake_case')).toBe('SnakeCase');
expect(pascal('point.case')).toBe('PointCase');
expect(pascal('UPPER_CASE')).toBe('UpperCase');
expect(pascal('DrUn-k_CaSE')).toBe('DrUnKCaSE');
});

it('should convert to pascal case with underscore', () => {
expect(pascal('_camelCase')).toBe('_CamelCase');
expect(pascal('_kebab-case')).toBe('_KebabCase');
});

it('should convert to pascal case when more complex input is given', () => {
expect(pascal('camelCase_')).toBe('CamelCase');
expect(pascal('more complex input')).toBe('MoreComplexInput');
});

it('should handle some casing edge cases', () => {
expect(pascal('foo_bar_API')).toBe('FooBarAPI');
});
});
30 changes: 13 additions & 17 deletions packages/core/src/utils/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,11 @@ const deapostrophe = (s: string) => {
const up = String.prototype.toUpperCase;
const low = String.prototype.toLowerCase;

const fill = (s: string, fillWith?: string, isDeapostrophe = false) => {
if (fillWith != null) {
s = s.replace(regexps.fill, function (m, next) {
return next ? fillWith + next : '';
});
}
const fill = (s: string, fillWith: string, isDeapostrophe = false) => {
s = s.replace(regexps.fill, function (m, next) {
return next ? fillWith + next : '';
});

if (isDeapostrophe) {
s = deapostrophe(s);
}
Expand Down Expand Up @@ -92,16 +91,13 @@ const lower = (s: string, fillWith: string, isDeapostrophe: boolean) => {
export const pascal = (s: string) => {
const isStartWithUnderscore = s?.startsWith('_');

const pascalString = fill(
prep(s, false, true).replace(
regexps.pascal,
(m: string, border: string, letter: string) => {
return up.call(letter);
},
),
'',
true,
);
if (regexps.upper.test(s)) {
s = low.call(s);
}

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

return isStartWithUnderscore ? `_${pascalString}` : pascalString;
};
Expand All @@ -122,7 +118,7 @@ export const kebab = (s: string) => {

export const upper = (
s: string,
fillWith?: string,
fillWith: string,
isDeapostrophe?: boolean,
) => {
return fill(
Expand Down

0 comments on commit bda607c

Please sign in to comment.