npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dummy-users-json

v1.0.2

Published

A library to get dummy-users-json data

Downloads

27

Readme

dummy-users-json

npm version

🎉 Generate dummy user data with ease! dummy-users-json is a lightweight npm package that provides functions to generate dummy user data in JSON format. Perfect for testing and prototyping applications without the need for real user data.

Installation

To install dummy-users-json, use npm or yarn:

npm install dummy-users-json

or

yarn add dummy-users-json

Usage in Node js Applications

import { generateUniqueUsers } from "dummy-users-json";

// Define the function
async function fetchUsers() {
  try {
    const users = await generateUniqueUsers(10);
    return users;
  } catch (error) {
    console.error("Error:", error);
    return []; // Optionally return an empty array or handle the error
  }
}

// Call the function and store the returned value in a variable
const fetchedUsers = await fetchUsers();

// Log the fetched users to the console
console.log(fetchedUsers);

Usage in React Applications

import { generateUniqueUsers } from "dummy-users-json";
import { useEffect, useState } from "react";

function App() {
  const [users, setUsers] = useState();

  // Use below for TypeScript,instead of above useState
  /*
  interface User {
    id: number;
    fname: string;
    lname: string;
    email: string;
    job: string;
  }
  const [users, setUsers] = useState<User[] | undefined>();
  */

  useEffect(() => {
    const fetchUsers = async () => {
      try {
        const data = await generateUniqueUsers(1);
        setUsers(data);
      } catch (error) {
        console.error("Error fetching user data:", error);
        setUsers([]);
      }
    };

    fetchUsers();
  }, []);

  return (
    <div>
      <ul>
        {users
          ? users?.length > 0
            ? users.map((user) => (
                <li key={user.id}>
                  <h1>
                    {user.fname}&nbsp; {user.lname}
                  </h1>
                  <p>{user.email}</p>
                  <h3 style={{ textTransform: "capitalize" }}>{user.job}</h3>
                </li>
              ))
            : "No Data Available"
          : "Loading..."}
      </ul>
    </div>
  );
}

export default App;

Example Output

[
  {
    "id": 0,
    "fname": "John",
    "lname": "Doe",
    "email": "[email protected]",
    "job": "Software Engineer"
  },
  {
    "id": 1,
    "fname": "Jane",
    "lname": "Smith",
    "email": "[email protected]",
    "job": "Data Analyst"
  }
  // More users...
]

API

generateUsers(count: number, delay(OPTIONAL): number): User[]

Generates an array of dummy users.

  • count: The number of users to generate.
  • delay: (OPTIONAL) defaults to 1000 ms, specifies the delay in milliseconds for simulating data fetching timing.

Returns an array of user objects.

User Object

  • id: Unique identifier for the user.
  • fname: First name of the user.
  • lname: Last name of the user.
  • email: Email address of the user (generated from first name and last name).
  • job: Job title of the user (randomly selected from a predefined list).

Comparison Table

| Features | dummy-users-json | Other Tools | | ---------------- | ---------------- | ----------- | | Ease of Use | ✅ | ❌ | | Offline Usage | ✅ | ❌ | | Unique Results | 300 | Varies | | TypeScript Ready | ✅ | Varies |

Additional Information

  • This package can generate up to 300 unique results.
  • No internet connection is required to fetch data; it mocks API calls due to its asynchronous nature.
  • Developed in TypeScript, enabling auto-suggestion features.

License

This project is licensed under the MIT License - see the LICENSE file for details.