capitalize

说明

将指定的字符串的首字母大写, 剩下为小写

源码

用法

capitalize.test.ts
1
import { capitalize } from "../../utility/string/capitalize";
2
3
describe('capitalize tests...', () => {
4
test('capitalize should return the origin text when receive an empty string', () => {
5
const received = '';
6
const expected = '';
7
8
const result = capitalize(received);
9
10
expect(result).toBe(expected);
11
});
12
13
test('capitalize should return the converted string correctly', () => {
14
const received = ['ZHAO', 'duan'];
15
const expected = ['Zhao', 'Duan'];
16
17
const result = received.map((v) => {
18
return capitalize(v);
19
});
20
21
result.forEach((v, i) => {
22
expect(v).toBe(expected[i]);
23
});
24
});
25
26
test('capitalize should return the converted string when receive a text contains special characters', () => {
27
const received = ['_DDZY', '___&*duanzhaoYANg'];
28
const expected = ['_Ddzy', '___&*Duanzhaoyang'];
29
30
const result = received.map((v) => {
31
return capitalize(v);
32
});
33
34
result.forEach((v, i) => {
35
expect(v).toBe(expected[i]);
36
});
37
});
38
});
Copied!
最近更新 1yr ago
复制链接