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-array-generator

v1.1.1

Published

Generates dummyArray based on the provided template and repetition settings 🌱

Downloads

21

Readme

Dummy Array Generator

Generate custom dummy arrays effortlessly with dummy-array-generator. This package is designed to help developers create repetitive dummy components efficiently, particularly when working with modern JavaScript frameworks like React and Next.js.

With dummy-array-generator, you can streamline your development workflow by generating the dummy data you need with ease. You can even create dummy arrays using specific templates, allowing you to tailor the data structure to fit your exact needs.

  • ⚠️ Note: Currently a work in progress 🌱

Installation

$ npm i dummy-array-generator
$ npm install dummy-array-generator

$ pnpm add dummy-array-generator

Quick Usage

1) String

import { genDummy } from "dummy-array-generator";

const testDummy = genDummy({ template: "this test is {i}", time: 3 });

// returns [ 'this test is 1', 'this test is 2', 'this test is 3' ]

2) Object

import { genDummy } from "dummy-array-generator";

const userDummy = genDummy({
  template: `{name:'Lee', age:{i}, location:'Seoul'}`,
  time: 3,
  type: "object",
});

// returns
// [
//  { name: 'Lee', age: 1, location: 'Seoul' },
//  { name: 'Lee', age: 2, location: 'Seoul' },
//  { name: 'Lee', age: 3, location: 'Seoul' }
// ]

3) Template Variables

  • Each variable in a template is replaced with specific data. The data is selected randomly from predefined lists.
{i}, {animal}, {insect}, {country},
{dessert}, {drink}, {food}, {fruit}, {nature},
{sport}, {transportation}, {vegetable}, {weather}
const promotionDummyTemplate = genDummy({
  template: `{food} is on the sale for \${i}`,
  time: 5,
});

// returns
// [
//   'Roasted Sweet Potato is on the sale for $1',
//   'Shallow Pan of Food is on the sale for $2',
//   'Pancakes is on the sale for $3',
//   'Pizza is on the sale for $4',
//   'Taco is on the sale for $5'
// ]

const dummyWeatherInfo = genDummy({
  template: `{weather:{weather}, location: {country}}`,
  time: 4,
  type: "object",
});

// returns
// [
//   {
//     weather: "Sun",
//     location: "South Korea",
//   },
//  {
//     "weather": "Rainbow",
//     "location": "Spain"
//  },
//   {
//     weather: "Cloud with Lightning",
//     location: "Morocco",
//   },
//   {
//     weather: "Snowflake",
//     location: "Canada",
//   },
// ];

A File Generator with CLI

$ npm run dummy-export

$ pnpm dummy-export
  • It allows users to create files with specific content and formats directly from the command line.

It currently supports two types of arrays: strings and objects

The dummy-array file is generated in the src/generated folder, and this part will be improved soon.

1) String

🟢 Welcome to dummy-array-generator 🌱
? Export the dummy array as a file ? yes
? Type of the array : string
? Name of the array : fakeArticle
? Enter your template article :{i}
? Enter repeat count : 7
? Define your file name : fakeArticle
? Type of your file : .js
✅ The file has been successfully created.
// src/generated/fakeArticle.js
export const fakeArticle = [
  "article 1",
  "article 2",
  "article 3",
  ..."article 7",
];

2) Object

🟢 Welcome to dummy-array-generator 🌱
? Export the dummy array as a file ? yes
? Type of the array : object
? Name of the array : fakeUser
? Enter the key of the object : userId
? Enter the value of the object : user {i}
? Enter repeat count : 13
? Define your file name : fakeUser
? Type of your file : .js
✅ The file has been successfully created.
// src/generated/fakeUser.js
export const fakeUser = [
  { userId: "user 1" },
  { userId: "user 2" },
  ...{ userId: "user 13" },
];

Custom File Path Configuration

  • By default, generated files are created in the ./src/generated directory. However, you can customize the output directory by modifying the dummy.config.json file.
  • To set a custom output directory, specify the desired path in the outputDirectory field of your dummy.config.json file. Here’s an example configuration:
// dummy.config.json
{
  "file": {
    "outputDirectory": "./src/generated"
  }
}