1.11.0 • Published 11 months ago

@codexcentral/flatten-texts v1.11.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
11 months ago

flatten-texts

Function to allows you to flatten an array of texts into a single array of texts and by double break lines.

Installation

npm install @codexcentral/flatten-texts

Usage

1. Importing

import { flattenText, IFlattenText } from "@codexcentral/flatten-texts";

2. Call the functions

Example 1

interface CustomMessage {
  id: string;
  text: string;
}

const messageResponse: IFlattenText<CustomMessage[]> = {
  content: '[{"id": "1", "text": "Hola"}, {"id": "2", "text": "Mundo"}]',
};

const messages = flattenText < CustomMessage > messageResponse;
console.log(messages);

// Output
/*
[
  { "text": { "id": "1", "text": 'Hola' } },
  { "text": { "id": "2", "text": 'Mundo' } }
]
*/

Example 2

const messageResponse = {
  content: '["Estoy aquí para ayudarte.", "¿Puedo hacer algo por ti?"]',
};
const messages = flattenText(messageResponse);
console.log(messages);

// Output
/*
[
  { "text": 'Estoy aquí para ayudarte.' },
  { "text": '¿Puedo hacer algo por ti?' }
]
*/

Example 3

const messageResponse = {
  content: "Estoy aquí para ayudarte.\n\n¿Puedo hacer algo por ti?",
};
const messages = flattenText(messageResponse);
console.log(messages);

// Output
/*
[
  { "text": 'Estoy aquí para ayudarte.' },
  { "text": '¿Puedo hacer algo por ti?' }
]
*/

Attributes...

AttributeTypeMandatory
contentstringtrue

Credits

These code was written by Roberto Silva Z.