@codexcentral/flatten-texts
TypeScript icon, indicating that this package has built-in type declarations

1.9.0 • Public • Published

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: number;
  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...

Attribute Type Mandatory
content string true

Credits

These code was written by Roberto Silva Z.

Package Sidebar

Install

npm i @codexcentral/flatten-texts

Weekly Downloads

3

Version

1.9.0

License

Apache-2.0

Unpacked Size

25.8 kB

Total Files

19

Last publish

Collaborators

  • roberto.silva