libphonenumber js validating numbers from excel file - javascript

I have a parsed list/array of phone numbers and i would like to check each one if "isNumberValid()".
i tried some stuff but i guess im missing something important because im a begginer..
How would i do this in javascript there is no documentation for js.

Related

How to convert CSV to TCSV file in python

A buddy of mine is trying to convert a CSV file full of data into something called a tcsv file for use with a service he is developing.
I could barely find anything on TCSV files except for here This seems to describe what makes a TCSV file.
So my question is, would I be able to use python, (or JS, as in the example) in order to convert a csv to tcsv file? Is this something I can do with code? If someone could explain what a tcsv file is and how it's used that would help, thank you!
Tell your buddy the whole point of .csv files is that they are unstructured apart from the commas separating fields and the newlines demarcating new records.
A clue to how useful the .tscv file extension may be at some future point in time is in the title given by the person on github (your link) experimenting with them: "Simpler, streamable, more compact, easier to read, gzip friendlier than JSON. Hopefully..."
If your buddy insists on a more human-readable form of data he can transform them pretty easily into xml, or even JSON, and he'll very likely have more joy than following that github post's apparently aborted experiment.
That tcsv stuff doesn't look easier to read than well-formatted JSON to me. Though xml seems to win hands-down if written with readability in mind.
See http://json.org/example.html.

Fetching URLs with JS from file?

Simple question from a noob :). The line below is from a javascript im trying to understand. The script is fetching data from a csv file to build a table based on a price slider. This line is the url that makes the visitor go to a specific website (a button i a table cell). My question is: What kind of file is in the /links/ directory and what exactly does '+line[6]+' mean?
content+='<td><a href="http://www.exampel.com/links/'+line[6]+'"
In a browser, the url looks like this (example): http://www.exampel.com/links/comapanyA
Without the actual file, I don't think it is discernible what exact type of file it is.
But, I can answer the "what exactly does '+line[6]+' mean?":
The plus signs on either side are string concatenation. So you are adding the results of "line[6]" to the url string.
"line[6]" is an array, with the sixth element being called by the index number "6".

Converting Excel Data to a Chart in HTML dynamically

Is it possible to be able to upload an excel document with varying ranges of data, and have that data dynamically displayed in a basic form of chart(bar, pie, etc.) on our company website.
After doing some research I figured the only two possible ways to maybe do something like this is to use a very complicated macro in VBA or a Javascript parser to read the data and display it then. The data that will eventually go in here will have sensitive information so I cannot use google charts or anything like that.
This problem has to be divided into two parts.
One -part is to gather and process the information needed to display the chart.
Second - This is the easiest, a way to display a chart in HTML. For this, you can use www.c3js.org javascript library to display the chart in HTML.
Regarding part one, it depends in which technology is built your website.
For example, If it is in php, you will need to find a library in php, which can read and parse excel files.
Then you have to create a service in your website, where the data is going to be provided. For example,
www.yourcompany.com/provideChartData.php
You can format the response as json format.
Once you have solved that, you only have to call the service from your page, and the data will be dynamically displayed. You can call it using jquery library for javascript ($.post("www.yourcompany.com/provideChartData.php",function (data) { code to display chart ....}))
There is no real easy way to do this that I have found. I have had to manually parse these things in the past but there are some libraries out there for node that might help you.
https://www.npmjs.com/package/node-xlsx
You can also export form excel as CSV. When you do this, me sure to set the custom separator to something other than ',' and you should be fine to import it into a large array and get the data/charts you need.
https://github.com/wdavidw/node-csv
Hope that helps.

Using HTML within a JSON Object

I'm working on an FAQ type project using AngularJS. I have a number of questions and answers I need to import into the page and thought it would be a good idea to use a service/directive to load the content in dynamically from JSON.
The text strings are quite unwieldily (639+ characters) and the overall hesitation I have is adding HTML into the JSON object to format the text (Line breaks etc).
Is pulling HTML from JSON considered bad practice practice, and is there a better way to solve this? I'd prefer to avoid using multiple templates but it's starting to seem like a better approach.
Thanks
If you're using AngularJS and already have a build step, html2js could help you with turning HTML templates into JS, which can then be concat'd and minified.
You could try parsing the incoming JSON before sending it to the page and just adding in a <br /> everywhere you run into a \n. That way the JSON is more universally usable if you ever decide you want to port the data to another medium.

Parse CSV from URL into Array using Javascript

I'm relatively new to javascript but I want to get some data from a csv file that is saved online and gets updated each hour.
The data should be displayed on a table later on but I have some problems with saving it to an array. The csv file is comma seperated, has 9 columns, over 6000 rows and is a long string of text, so no linebreaks. The first row contains usernames and each username with special characters is conclosed with quotation marks.
I've tried several codes over the past few days, but none worked. Can I parse a online CSV file into an array at all? Is there an alternative like with SQL or saving the file to my server?
Remember: The file gets updated each hour..
NOTE: There are not really problems with the codes I've found, all of these were tested by others and seemed to work. But only for local files, not actual URLs!
You can use this https://code.google.com/p/jquery-csv/ plugin and it is possible to convert multi-line csv into 2D-array using $.csv.toArrays(csv) or to an object using $.csv.toObjects(csv). Check this post or this one for more info
$.ajax({
url: "urlto/filename.csv",
success: function (data) {
var arr = $.csvtoArray(data);
_oncomplete(arr);
},
dataType: "text",
});
_oncomplete: function (arr) {
//Your array here
}
You can have a look at papaparse for a solid and full-featured CSV parsing library.
setInterval javascript function lets you update the data every hour, in case you decide to develop this part on the client.
Is there an alternative like with SQL or saving the file to my server?
Yes there are alternatives, the right architecture depends on your use case. How many visitors will go to your web page and view the results, how critical your application is, how reliable the data source is, etc. If you're not sure about these you should talk to a web developer with more experience around these questions.
You may want to parse the CSV file every hour on the server and store a copy of the data there, to serve to your visitors. This way, if the upstream data source is unavailable, you still have a copy of the data from the past.
P.S.:
I've tried several codes over the past few days, but none worked
stackOverflow is about this: getting help about specific problems in your code, rather than asking general questions (answer to those can be found easily using a search engine).

Categories