From 1eef4c0eb8ba51997e47fca6c3a1914341b733ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Fabianski?= Date: Tue, 7 May 2019 17:59:06 +0200 Subject: [PATCH] fix: move titleize to helpers --- src/components/SecuritySchemes/SecuritySchemes.tsx | 8 ++------ src/utils/__tests__/helpers.test.ts | 8 +++++++- src/utils/helpers.ts | 4 ++++ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/components/SecuritySchemes/SecuritySchemes.tsx b/src/components/SecuritySchemes/SecuritySchemes.tsx index d7c62602..fc5f3bc0 100644 --- a/src/components/SecuritySchemes/SecuritySchemes.tsx +++ b/src/components/SecuritySchemes/SecuritySchemes.tsx @@ -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'; @@ -84,12 +85,7 @@ export class SecurityDefs extends React.PureComponent { {scheme.apiKey ? ( - - {' '} - {(scheme.apiKey.in || '').charAt(0).toUpperCase() + - (scheme.apiKey.in || '').slice(1)}{' '} - parameter name: - + {titleize(scheme.apiKey.in || '')} parameter name: {scheme.apiKey.name} ) : scheme.http ? ( diff --git a/src/utils/__tests__/helpers.test.ts b/src/utils/__tests__/helpers.test.ts index e73d4367..e638ac12 100644 --- a/src/utils/__tests__/helpers.test.ts +++ b/src/utils/__tests__/helpers.test.ts @@ -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', () => { @@ -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'); + }); + }); }); }); diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index 699d3da5..92c955e3 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -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); +}