@alanscodelog/utils
    Preparing search index...

    Function readable

    • Returns an array in human readable format (with an oxford comma if there are 3 or more elements).

      By default nested arrays and objects are turned into: [...], {...}, [] or {} depending on if they're empty or not. Functions are turned into [name] function or anonymous function if they have no name. Class instances are turned into [name] instance. Classes themselves can't be differentiated from functions so the function format is used.

      If you need some custom behavior for some elements, see the stringify option.

      readable(["a"]) // a
      readable(["a", "b"]) // a and b
      readable(["a", "b", "c"]) // a, b, and b
      readable(["a", "b", [b], {c: "c"}, [], {}]) // a, b, [...], {...}, [] and {}

      Parameters

      • arr: any[]
      • __namedParameters: { conjunction?: string; stringify?: (el: any) => any } = {}
        • Optionalconjunction?: string

          How to join the last two elements.

        • Optionalstringify?: (el: any) => any

          Optional function to control how elements are stringified. You are free to still return objects, etc. from this function and only stringify what you need. The returned values will still be passed through the default stringify function.

          readable(["a", "b", new Animal()], {stringify: (el) => el instance of Animal ? "Animal" : el}) // a, b, and Animal
          

      Returns string