mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-12-29 16:16:02 +00:00
wrap tool and testCases, then updated index file
This commit is contained in:
27
src/pages/list/wrap/service.ts
Normal file
27
src/pages/list/wrap/service.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
export type SplitOperatorType = 'symbol' | 'regex';
|
||||
|
||||
function wrap(array: string[], left: string, right: string): string[] {
|
||||
return array.map((element) => left + element + right);
|
||||
}
|
||||
|
||||
export function wrapList(
|
||||
splitOperatorType: SplitOperatorType,
|
||||
input: string,
|
||||
splitSeparator: string,
|
||||
joinSeparator: string,
|
||||
left: string = '',
|
||||
right: string = ''
|
||||
): string {
|
||||
let array: string[];
|
||||
let wrappedArray: string[];
|
||||
switch (splitOperatorType) {
|
||||
case 'symbol':
|
||||
array = input.split(splitSeparator);
|
||||
break;
|
||||
case 'regex':
|
||||
array = input.split(new RegExp(splitSeparator));
|
||||
break;
|
||||
}
|
||||
wrappedArray = wrap(array, left, right);
|
||||
return wrappedArray.join(joinSeparator);
|
||||
}
|
||||
Reference in New Issue
Block a user