Create proper spacing for string formatting within an AngularJS modal

I am working with a popup that displays output as one string with spaces and newline characters. Each line is concatenated to the previous line, allowing for individual adjustments.

Test1                        :  Success :    200
Test2              :  Success :    200
Test3                  :  Success :    200
Test4                :  Success :    200
Test5                  :  Success  :    404
Test6           :  Success  :    401

Given that I have multiple popups and tests for each one, I am looking for a way to format the strings with proper indents. Desired output:

Test1               :  Success :    200
Test2               :  Success :    200
Test3               :  Success :    200
Test4               :  Success :    200
Test5               :  Success :    404
Test6               :  Success :    401

Answer №1

My recommended approach would be:

To start, utilize the \n delimiter to split your string into an array of individual lines. Then, further split each line using the : character while also utilizing the trim function to eliminate any excess spaces.

Lastly, reassemble the split elements, making sure to append extra space to the first element before joining them all back together.

let inputValue = "Test1                        :  Success :    200\nTest2              :  Success :    200\nTest3                  :  Success :    200\nTest4                :  Success :    200\nTest5                  :  Success  :    404\nTest6           :  Success  :    401"


let inputArray = inputValue.split("\n")

let result = inputArray.map(function(line) {
  let tempArr = line.split(":")
  return tempArr.map(s => s.trim())
})

let finalOutput = result.map(function(subArray) {
  subArray[0] = subArray[0] + "            "
  return subArray.join(" : ")
})

console.log(finalOutput)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

A guide on displaying a JSON object using the ng-repeat directive

Looking to create a dynamic treeview menu with angularJS? Wondering how to achieve the desired results using a controller ($scope.results) and JSON data? Check out the code snippet below for an example of how to structure your treeview: <ul> < ...

AngularJS ng-repeat along with jQuery Mobile

I am attempting to utilize ng-repeat in combination with jQuery mobile checkboxes. While the checkboxes appear correctly, they do not become checked when clicked. Could someone provide guidance on how to effectively use ng-repeat with jQuery mobile checkb ...

Cannot populate Kendo Menu with images due to dataSource imageUrl not recognizing the content

I have integrated Kendo controls into my application, specifically a Menu control with a datasource in my controller. Currently, I am passing the relative path of URL for imageUrl. However, as the application has grown, there are multiple calls being made ...

http-proxy-middleware - serving static content

I am currently working on integrating my static landing page with an express.js app (using react.js for the single page application). For my landing page, I have set up a proxy using http-proxy-middleware. Here is what my server.js file for the static pag ...

Offspring maintain a certain position within the larger framework of their parent on a

When resizing the parent wrap container, how can I ensure that the pin (red dot) on the image maintains its relative position? To see the issue, resize the wrap container. #wrap{ position: absolute; width: 100%; height: 100%; top: 0; l ...

Using jQuery's .load() method to load a PHP file can result in an exponential increase in XHR finished loading time with each subsequent load

There seems to be an issue with my code using .load() to load a PHP page into a div whenever the navbar or link is clicked. After multiple clicks, I noticed that the "XHR finished loading" increases exponentially and it appears that the same PHP file is be ...

Leverage access tokens in React.js frontend application

After successfully creating an authentication API using Nodejs, Expressjs, MongoDB, and JWT, I am now working on a small frontend application with React-js specifically for Sign-up and Sign-in functionalities. While I have managed to integrate the Sign-up ...

Escaping an equal sign in JavaScript when using PHP

I am currently working on the following code snippet: print "<TR><TD>".$data->pass_name."</TD><TD><span id='credit'>".$data->credit_left."</span></TD><TD><input type='button' val ...

The data stored in LocalStorage disappears when the page is refreshed

I'm facing an issue with the getItem method in my localStorage within my React Form. I have added an onChange attribute: <div className = 'InputForm' onChange={save_data}> I have found the setItem function to save the data. Here is ...

How can I take a screenshot from the client side and save it on the server side using PHP?

Currently, I am exploring the possibility of screen capturing at the client side. It appears that the "imagegrabscreen()" function can only capture screens on the server side. After some research, I discovered a new function that allows for screen capture ...

Impressive javascript - extract file from formData and forward it

Presented here is my API handler code. // Retrieve data. const form = formidable({ multiples: true }); form.parse(request, async (err: any, fields: any, files: any) => { if (!drupal) { return response.status(500).send('Empty ...

Substitute regular expressions with several occurrences by their respective capture groups

I am attempting to use JavaScript to extract only the link text from a string and remove the href tags. The expected behavior is as shown below: <a href='www.google.com'>google</a>, <a href='www.bing.com'>bing</a> ...

Does v-if cause the jquery clock picker to malfunction?

Here is my unique div where the clockpicker library functions correctly. <div class="input-group clockpicker"> <input type="text" class="form-control" value="18:00"> <span class="input-group-addon"> <span class ...

Navigate through the DOM to return an image

I have a question about clicking on the image '.escape' and passing back the source of the image '.myimg2' when clicked. Here is my attempt at accomplishing this task: I understand that it involves traversing the DOM, but I am not very ...

Encountered an issue while implementing the post function in the REST API

Every time I attempt to utilize the post function for my express rest API, I encounter errors like the following. events.js:85 throw er; // Unhandled 'error' event ^ error: column "newuser" does not exist at Connection.parseE (/Use ...

JavaScript issue: "No relay configuration found" error specifically occurs in Internet Explorer versions 7 and 8

Encountering issues with loading JavaScript only on specific pages in Internet Explorer. Safari, Firefox, and Chrome render the page correctly. Debugging revealed the following errors: 1) No relay set (used as window.postMessage targetOrigin), cannot send ...

AngularJS UI router allows for the creation of sticky states, where each state maintains its own instance of the controller even when

Currently, I am in the process of developing a CMS with a tabular structure using AngularJS. The main functionality is to allow users to open and edit multiple articles within tabs. Each article is handled by the articleController and has different URL par ...

How to Implement Custom Colors for Individual Tabs in AngularJS Material Design's md-tabs

Is it possible to customize the background colors of individual tabs in md-tabs? Currently, the default setting is no color, as demonstrated in the tabs demo. I attempted to use <md-tabs background-color="green">, but unfortunately, it did not produ ...

Leveraging angular.extend() with controllers and function overrides

Currently, I am working with Angular 1.4.8 and attempting to expand a controller. The original controller and the expanding controller are quite similar, but there is a specific function that I aim to replace in the extending controller. angular.module(&a ...

The absence of jasmine-node assertions in promises goes unnoticed

Everything seems to be running smoothly with the code below, except for the assertion part. Whenever I run the test using Jasmine, it reports 0 assertions. Is there a way to include my assertions within promises so they are recognized? it("should open sav ...