Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/fathym_common/src/src.deps.ts>joinToString

The Fathym Reference Architecture provides the common foundation for applications built in Typescript.
Go to Latest
function joinToString
import { joinToString } from "https://deno.land/x/fathym_common@v0.0.143/src/src.deps.ts";

Transforms the elements in the given array to strings using the given selector. Joins the produced strings into one using the given separator and applying the given prefix and suffix to the whole string afterwards. If the array could be huge, you can specify a non-negative value of limit, in which case only the first limit elements will be appended, followed by the truncated string. Returns the resulting string.

Examples

Example 1

import { joinToString } from "https://deno.land/std@0.224.0/collections/join_to_string.ts";
import { assertEquals } from "https://deno.land/std@0.224.0/assert/assert_equals.ts";

const users = [
  { name: "Kim" },
  { name: "Anna" },
  { name: "Tim" },
];

const message = joinToString(users, (it) => it.name, {
  suffix: " are winners",
  prefix: "result: ",
  separator: " and ",
  limit: 1,
  truncated: "others",
});

assertEquals(message, "result: Kim and others are winners");

Parameters

array: Iterable<T>
selector: (el: T) => string
optional
unnamed 2: Readonly<JoinToStringOptions> = [UNSUPPORTED]

Returns

string