fix(striker-ui-api): replace empty function with call in join

main
Tsu-ba-me 2 years ago
parent ca7288cbdd
commit bbb0fa503e
  1. 24
      striker-ui-api/src/lib/join.ts

@ -2,29 +2,25 @@ import call from './call';
const join: JoinFunction = (
elements,
{
beforeReturn,
elementWrapper = '',
onEach = (element: string) => element,
separator = '',
} = {},
{ beforeReturn, elementWrapper = '', onEach, separator = '' } = {},
) => {
const joinSeparator = `${elementWrapper}${separator}${elementWrapper}`;
const toReturn =
elements instanceof Array && elements.length > 0
? `${elementWrapper}${elements
.slice(1)
.reduce<string>(
(previous, element) =>
`${previous}${joinSeparator}${onEach(element)}`,
elements[0],
)}${elementWrapper}`
? `${elementWrapper}${elements.slice(1).reduce<string>(
(previous, element) =>
`${previous}${joinSeparator}${call<string>(onEach, {
notCallableReturn: element,
parameters: [element],
})}`,
elements[0],
)}${elementWrapper}`
: undefined;
return call<string | undefined>(beforeReturn, {
parameters: [toReturn],
notCallableReturn: toReturn,
parameters: [toReturn],
});
};

Loading…
Cancel
Save