Generate fake data that don't change [closed] - javascript

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
I'm creating a temporary GraphQL backend, that should serve mocked data.
E.g. I need ~500 objects of the model Person (with firstName, lastName, email, country, etc), where the properties shouldn't change on each request.
Is there any library where it's possible to get fake data always created in the same order?

You can easily create your custom JSON with https://next.json-generator.com/ which allows using internal scripts for data generation
Here is an example of generating a list of names: https://next.json-generator.com/Vk95XL5mv

Not sure if this is exactly what you want, but I discovered this site: https://crudpi.io/ this weekend, you can mock some data in a JSON file and use it for your API. I guess that it's limited to 100 objects or something, but if you need the same data, you can copy it 5 times I guess. Hope it helps!
I wish that I could write this as a comment but I don't have enough reputation yet.

Here's an API. https://uinames.com/api/?amount=500
You should easily just create a script, add the data you got from this to a temp-database.

You can use a generator like https://randomuser.me/
Make a loop to create your object then keep the result in a file to ensure the data will be the same.
You can get an exemple here : https://gist.github.com/Yexan/cb8b79390e01272a4912fb4d6773ee1a
I used https://randomuser.me/api/?results=500

Related

await of multiple server responses [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have data to get from server, but in one response i can get only N rows (but i need all of it, account can have 10N, or 1000N of rows), and amount of rows is unknown before i get first response (wich contains amount of N's), my logic is depend on this data, wich means i need to wait load and only then do my stuff, i see 3 ways:
Loop / recursion with async: false, but i cant use this, cause app policy
sth like setInterval(handler, 500) and flag is loading ended
i send first request and depend on data getted creatring promises to get other parts, await all of it and then do my stuff
But i hope in modern js we have some better ways to solve problems like this
Use Promise.all(). It's modern and made just for promises (asyncs/awaits as well).

Best way to parse URL in ES6 [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I've seen some legendary questions about the topic like that: how to parse a url .
But years passed and things changed. The answers from questions that I can find is out of date.
I don't want to parse URL via regexp or some hack like creating HTML node as a parse helper. I want some flexible method that returns an object with all required data from the URL.
I believe that there are some new built-in methods to do it or new revolutionary amaizing and simple ES6 libraries for that purpose.
Can you please advice something like that?
I think you are looking for web api's URL() constructor like this:
const myTestURLString = "https://www.youtube.com:8080/watch?v=YaXXXXkt0Y&id=123";
const myURLObj = new URL(myTestURLString );
console.log(myURLObj.protocol);
console.log(myURLObj.host);
console.log(myURLObj.hostname);
console.log(myURLObj.pathname);
console.log(myURLObj.search);
console.log(myURLObj.searchParams.get('v'));
console.log(myURLObj.searchParams.get('id'));
ES6 is part of the language specification, not any particular framework for JavaScript. Therefore, you're not going to find things like URL.parse() in the language.
The APIs you're looking for are part of the host for your application, such as the browser or Node.js. In browser, there is a URL interface: https://developer.mozilla.org/en-US/docs/Web/API/URL

How to email a parsed JSON using a script [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a script that gets and parses a JSON, I want to email the JSON values directly from the script when the page loads. I already have everything set up but do not know the best approach about doing this. I usually use forms to send information but this is a little different.
I am not looking for someone to hold my hand and show me how, I just want to know the different options and I can figure it out myself.
I don't think there is any native javascript functionality for sending emails. I would use a service like https://www.emailjs.com/ or the Gmail javascript API if it was totally necessary to do this from javascript.
If you want to automatically send an email using plain javascript from the browser, you can't. You'll have to setup node & use something like nodemailer:
https://nodemailer.com/
If this isn't the case, you can use window.open and pass the email data in this way. It will open the default email client on your computer & pre fill an email with the parsed information. Like so:
window.open('mailto:your#email.com?subject=your_subj&body='+YOUR_JSON_HERE);
Make sure your passing json and not a javascript object. If you're passing a js object it will return [object object]. If this is the case you'll need to stringify the js object, like so:
JSON.stringify(JS_OBJ)

Need to get country, state , city and area on entering pincode value in Node.js [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
I am developing a web application using nodeJs and ejs. I need to update country, state , city and area automatically depending on the pin-code(zip-code) entered. Is there any package available in node js or any other method available to acheive this?
I found this package useful & for some reason felt this is easy to use :
zipcodes
Had a simple get API with a path param & response looks like this :
You can use cities to lookup cities based on zipcodes or GPS coordinates. It will return you json as below.
{
zipcode: "07946",
state_abbr: "NJ",
latitude: "40.672823",
longitude: "-74.52011",
city: "Millington",
state: "New Jersey"
}
This package will be only searchable for US. For all countries, you can import data from geonames.org using this package to database. (Only MySQL supported for now)
That package also won't have updated data, but so far, that's the best I've seen before.

PHP Get Values from a URL using GET[] [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I am trying to develop products filters for an online store I am working on. An example of what I mean is http://www.riverisland.com/men/just-arrived. I have managed to get a JavaScript to populate the URL when the sizes are clicked on but failed to get them remove value from URL when unchecked.
My main question here is this. Assuming I have my URL as:
http://127.0.0.1/shop/dresses/?s=1&s=2&s=3
How do I get my PHP to extract the values from the URL?
How do I format a SQL query to search the values gotten from the URL using any sample query?
An easier solution is this.
Format your URL like http://127.0.0.1/shop/dresses/?s=1,2,3 as suggested by #Andrey.Popov. Then do the below.
if(isset($_GET['s']) && !empty($_GET['s']))
{
$e = sanitizeFunction($_GET['s']);
$d=explode(',',$e);
}
$d now has all your $_GET['s'] values.
That's the easier way I have figured out and it works!
In order to benefit from $_GET and other superglobals you have to follow the rules explained at Variables From External Sources. Since you've chosen to have several parameters with the same name and they do not contain properly paired square brackets you're basically on your own. The manual steps you must reproduce include:
Extract the raw query string from $_SERVER['QUERY_STRING'], e.g.:
$query_string = filter_input(INPUT_SERVER, 'QUERY_STRING');
Parse out the string. As far as I know, there aren't built-in functions that do exactly this so I'd either google for a good third-party library or write a simple parser with regular expressions or good old explode().
Decode the URL-encoded values with urldecode()

Categories