add tr method

This commit is contained in:
Pine Mizune
2017-02-21 03:04:30 +09:00
parent 755fad105c
commit e9a122097f
2 changed files with 23 additions and 0 deletions
+6
View File
@@ -80,6 +80,8 @@ declare namespace v {
reverseGrapheme(subject?: string): string;
slugify(subject?: string): string;
splice(subject?: string, start?: number, deleteCount?: number, toAdd?: string): string;
tr(subject?: string, from?: string, to?: string): string;
tr(subject?: string, from?: { [key: string]: string }): string;
trim(subject?: string, whitespace?: string): string;
trimLeft(subject?: string, whitespace?: string): string;
trimRight(subject?: string, whitespace?: string): string;
@@ -177,6 +179,8 @@ declare namespace v {
reverseGrapheme(): Chain;
slugify(): Chain;
splice(start?: number, deleteCount?: number, toAdd?: string): Chain;
tr(from?: string, to?: string): Chain;
tr(from?: { [key: string]: string }): Chain;
trim(whitespace?: string): Chain;
trimLeft(whitespace?: string): Chain;
trimRight(whitespace?: string): Chain;
@@ -270,6 +274,8 @@ declare namespace v {
reverseGrapheme(): ExplicitChain<string>;
slugify(): ExplicitChain<string>;
splice(start?: number, deleteCount?: number, toAdd?: string): ExplicitChain<string>;
tr(from?: string, to?: string): ExplicitChain<string>;
tr(from?: { [key: string]: string }): ExplicitChain<string>;
trim(whitespace?: string): ExplicitChain<string>;
trimLeft(whitespace?: string): ExplicitChain<string>;
trimRight(whitespace?: string): ExplicitChain<string>;
+17
View File
@@ -214,6 +214,23 @@ str = v.splice('new year', 0);
str = v.splice('new year', 0, 4);
str = v.splice('new year', 0, 3, 'happy');
str = v.tr();
str = v.tr('hello', 'el', 'ip');
str = v.tr('Yes. The fire rises.', {
'Yes': 'Awesome',
'fire': 'flame'
})
str = v('hello').tr('el', 'ip').value();
str = v('Yes. The fire rises.').tr({
'Yes': 'Awesome',
'fire': 'flame'
}).value();
str = v.chain('hello').tr('el', 'ip').value();
str = v.chain('Yes. The fire rises.').tr({
'Yes': 'Awesome',
'fire': 'flame'
}).value();
str = v.trim();
str = v.trim(' Mother nature ');
str = v.trim('--Earth--', '-');