Files
common/packages/util/src/string/lowerFirst.ts
T
Jaco 391ab49b8f Adjust camelCase with simplified version (#1230)
* Adjust camelCase with simplified version

* Adjust count

* Adjust

* readability

* Ascii-only

* single-line callbacks

* CHANGELOG

* Dedupe string{Lower, Upper}First

* replacer -> fn
2021-11-22 16:12:29 +02:00

44 lines
1.0 KiB
TypeScript

// Copyright 2017-2021 @polkadot/util authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { AnyString } from '../types';
function converter (fn: (value: string) => string): (value?: AnyString | null) => string {
return (value?: AnyString | null): string =>
value
? fn(value[0]) + value.slice(1)
: '';
}
/**
* @name stringLowerFirst
* @summary Lowercase the first letter of a string
* @description
* Lowercase the first letter of a string
* @example
* <BR>
*
* ```javascript
* import { stringLowerFirst } from '@polkadot/util';
*
* stringLowerFirst('ABC'); // => 'aBC'
* ```
*/
export const stringLowerFirst = converter((s) => s.toLowerCase());
/**
* @name stringUpperFirst
* @summary Uppercase the first letter of a string
* @description
* Lowercase the first letter of a string
* @example
* <BR>
*
* ```javascript
* import { stringUpperFirst } from '@polkadot/util';
*
* stringUpperFirst('abc'); // => 'Abc'
* ```
*/
export const stringUpperFirst = converter((s) => s.toUpperCase());