Add stringLowerFirst, stringUpperFirst, stringCamelCase (#219)

* Add stringLowerFirst

* Add stringUpperFirst

* Change test description

* Add camelcase

* Add header
This commit is contained in:
Amaury Martiny
2018-09-28 13:38:36 +02:00
committed by Jaco Greeff
parent a634fe380c
commit 9a6a02ce46
8 changed files with 220 additions and 10 deletions
+7
View File
@@ -0,0 +1,7 @@
// Copyright 2017-2018 @polkadot/util authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import * as stringCamelCase from 'camelcase';
export default stringCamelCase;
+7 -1
View File
@@ -2,11 +2,17 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import stringCamelCase from './camelCase';
import stringLowerFirst from './lowerFirst';
import stringShorten from './shorten';
import stringUpperFirst from './upperFirst';
/**
* @summary Utility methods to convert to work with `string` values
*/
export {
stringShorten
stringCamelCase,
stringLowerFirst,
stringShorten,
stringUpperFirst
};
@@ -0,0 +1,31 @@
// Copyright 2017-2018 @polkadot/util authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import { stringLowerFirst } from './index';
describe('stringLowerFirst', () => {
it("lowers the first letter if it's a capital letter", () => {
expect(
stringLowerFirst('ABC')
).toBe('aBC');
});
it("lowers the first letter if it's a lowercase letter", () => {
expect(
stringLowerFirst('abc')
).toBe('abc');
});
it('returns undefined as undefined', () => {
expect(
stringLowerFirst()
).toBe(undefined);
});
it('returns null as null', () => {
expect(
stringLowerFirst(null)
).toBe(null);
});
});
+25
View File
@@ -0,0 +1,25 @@
// Copyright 2017-2018 @polkadot/util authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import isNull from '../is/null';
import isUndefined from '../is/undefined';
/**
* @name stringLowerFirst
* @signature stringLowerFirst (_value: string): string
* @summary Lowercase the first letter of a string
* @description
* Lowercase the first letter of a string
* @example
* import { stringLowerFirst } from '@polkadot/util';
*
* stringLowerFirst('ABC'); // => 'aBC'
*/
export default function stringLowerFirst (_value: string): string {
if (isNull(_value) || isUndefined(_value)) {
return _value;
}
return _value.charAt(0).toLowerCase() + _value.slice(1);
}
@@ -0,0 +1,31 @@
// Copyright 2017-2018 @polkadot/util authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import { stringUpperFirst } from '.';
describe('stringUpperFirst', () => {
it("uppers the first letter if it's a capital letter", () => {
expect(
stringUpperFirst('ABC')
).toBe('ABC');
});
it("uppers the first letter if it's a lowercase letter", () => {
expect(
stringUpperFirst('abc')
).toBe('Abc');
});
it('returns undefined as undefined', () => {
expect(
stringUpperFirst()
).toBe(undefined);
});
it('returns null as null', () => {
expect(
stringUpperFirst(null)
).toBe(null);
});
});
+25
View File
@@ -0,0 +1,25 @@
// Copyright 2017-2018 @polkadot/util authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import isNull from '../is/null';
import isUndefined from '../is/undefined';
/**
* @name stringUpperFirst
* @signature stringUpperFirst (_value: string): string
* @summary Lowercase the first letter of a string
* @description
* Lowercase the first letter of a string
* @example
* import { stringUpperFirst } from '@polkadot/util';
*
* stringUpperFirst('abc'); // => 'Abc'
*/
export default function stringUpperFirst (_value: string): string {
if (isNull(_value) || isUndefined(_value)) {
return _value;
}
return _value.charAt(0).toUpperCase() + _value.slice(1);
}