stringPascalCase (#1168)
This commit is contained in:
@@ -6,13 +6,13 @@ import { stringCamelCase } from '.';
|
||||
describe('stringCamelCase', (): void => {
|
||||
it('works correctly', (): void => {
|
||||
expect(
|
||||
stringCamelCase('Snake_case')
|
||||
).toBe('snakeCase');
|
||||
stringCamelCase('Snake_case-Something spaced')
|
||||
).toBe('snakeCaseSomethingSpaced');
|
||||
});
|
||||
|
||||
it('works correctly for String (class', (): void => {
|
||||
expect(
|
||||
stringCamelCase(String('Snake_case'))
|
||||
).toBe('snakeCase');
|
||||
stringCamelCase(String('Foo_bar-baz---test'))
|
||||
).toBe('fooBarBazTest');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
export { stringCamelCase } from './camelCase';
|
||||
export { stringLowerFirst } from './lowerFirst';
|
||||
export { stringPascalCase } from './pascalCase';
|
||||
export { stringShorten } from './shorten';
|
||||
export { stringToHex } from './toHex';
|
||||
export { stringToU8a } from './toU8a';
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { stringPascalCase } from '.';
|
||||
|
||||
describe('stringPascalCase', (): void => {
|
||||
it('works correctly', (): void => {
|
||||
expect(
|
||||
stringPascalCase('Snake_case-something spaced')
|
||||
).toBe('SnakeCaseSomethingSpaced');
|
||||
});
|
||||
|
||||
it('works correctly for String (class)', (): void => {
|
||||
expect(
|
||||
stringPascalCase(String('foo_bar-baz'))
|
||||
).toBe('FooBarBaz');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
// Copyright 2017-2021 @polkadot/util authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import camelcase from 'camelcase';
|
||||
|
||||
/**
|
||||
* @name stringPascalCase
|
||||
* @summary Convert a dash/dot/underscore/space separated string/String to PascalCase
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
export function stringPascalCase (value: string | String): string {
|
||||
return camelcase(value.toString(), { pascalCase: true });
|
||||
}
|
||||
Reference in New Issue
Block a user