Skip to content

Commit

Permalink
fix: move titleize to helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
cfabianski committed May 7, 2019
1 parent 9ebd0b4 commit 1eef4c0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
8 changes: 2 additions & 6 deletions src/components/SecuritySchemes/SecuritySchemes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { SecuritySchemesModel } from '../../services/models';

import { H2, MiddlePanel, Row, Section, ShareLink } from '../../common-elements';
import { OpenAPISecurityScheme } from '../../types';
import { titleize } from '../../utils/helpers';
import { Markdown } from '../Markdown/Markdown';
import { StyledMarkdownBlock } from '../Markdown/styled.elements';

Expand Down Expand Up @@ -84,12 +85,7 @@ export class SecurityDefs extends React.PureComponent<SecurityDefsProps> {
</tr>
{scheme.apiKey ? (
<tr>
<th>
{' '}
{(scheme.apiKey.in || '').charAt(0).toUpperCase() +
(scheme.apiKey.in || '').slice(1)}{' '}
parameter name:
</th>
<th> {titleize(scheme.apiKey.in || '')} parameter name:</th>
<td> {scheme.apiKey.name} </td>
</tr>
) : scheme.http ? (
Expand Down
8 changes: 7 additions & 1 deletion src/utils/__tests__/helpers.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import slugify from 'slugify';
import { mapWithLast, appendToMdHeading, mergeObjects, safeSlugify } from '../helpers';
import { appendToMdHeading, mapWithLast, mergeObjects, safeSlugify, titleize } from '../helpers';

describe('Utils', () => {
describe('helpers', () => {
Expand Down Expand Up @@ -68,5 +68,11 @@ describe('Utils', () => {
expect(mergeObjects({}, obj1, obj2)).toEqual({ a: ['C'], b: ['D'] });
});
});

describe('titleize', () => {
test('should return the string with the first letter capitalized', () => {
expect(titleize('my title')).toEqual('My title');
});
});
});
});
4 changes: 4 additions & 0 deletions src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,7 @@ export function resolveUrl(url: string, to: string) {
export function getBasePath(serverUrl: string): string {
return new URL(serverUrl).pathname;
}

export function titleize(text: string) {
return text.charAt(0).toUpperCase() + text.slice(1);
}

0 comments on commit 1eef4c0

Please sign in to comment.