Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
chain-able-deps / src / util / concat.ts
Size: Mime:
import curry from '../fp/curry'
import toString from '../cast/toString'
import concatArray from '../array/concat'
import { isString } from '../is'

export interface Concat<Type = any> extends Function {
  (a: string, b: string): string
  (a: Type[], b: Type[]): Type[]
  (a: string, b: Type[]): Type[]
  (a: Type[], b: string): Type[]
  (a: Type[] | string, b: Type[] | string): Type[] | string
}

/**
 * @name concat
 * @alias concatAny
 * @since 5.0.0-beta.6
 *
 * @curried 2
 * @see array/concat
 *
 * @param a
 * @param b
 * @return y
 */
const concat = <Type = any>(
  a: Type[] | string,
  b: Type[] | string
): Type[] | string => {
  if (isString(a)) {
    if (isString(b)) {
      return a + b
    } else {
      return a + toString(b)
    }
  } else {
    return concatArray<Type[]>(a as Type[], b as Type[]) as Type[]
  }
}

export default curry(2, concat) as Concat