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

ect-random-data

v1.18.1

Published

Trying to think about new user, contact or customer data can be tricky, so here's a simple library to make some of the job a little easier. This library offers random first and last names, and currently a random date of birth from 1/1/1970 onwards.

Downloads

38

Readme

ECT Random Data

This library was generated with Angular CLI version 18.0.0.

Description

Trying to think about new user, contact or customer data can be tricky, so here's a simple library to make some of the job a little easier.

Usage

First add the EctRandomDataService service and the EctNgLinqService to your Modules' or AppComponent's Providers list.

As an example, if we want to create a UserRecordFetchService service class to create a random list of User records, this is what we do.

First, let's define a User interface under a models folder, calling the file users.models.ts:

export interface IUser {
  id: number;
  firstName: string;
  lastName: string;
  age: number;
  dob: Date;
  connected: Date,
  assets: number;
}

Then to get a create a service class to mock between 100 and 250 records, we use the following:

import { Injectable } from '@angular/core';

import { EctNgLinqService } from 'ect-ng-linq';
import { EctRandomDataService } from 'ect-random-data';

import { IUser, User } from './../models/users.models';

@Injectable()
export class UserRecordFetchService {

  private usersList = this.ngLinqService.createNgLinq<IUser>();

  constructor(private randomDataService: EctRandomDataService, private ngLinqService: EctNgLinqService) { }

  populateUserRecords(): void {
    const recordCount = this.randomDataService.getRandomNumberBetweenTwoValues(100, 250);

    for(let ii = 1; ii <= recordCount; ii++) {
      const userRecord = new User();
      userRecord.id = ii;
      userRecord.firstName = this.randomDataService.getAnyFirstName();
      userRecord.lastName = this.randomDataService.getLastName();
      userRecord.dob = this.randomDataService.getDateOfBirth();
      userRecord.age = this.randomDataService.getAgeFromDate(userRecord.dob);
      const hours = this.randomDataService.getRandomNumberBetweenTwoValues(8, 21);
      const minutes = this.randomDataService.getRandomNumberBetweenTwoValues(0, 59);
      const seconds = this.randomDataService.getRandomNumberBetweenTwoValues(0, 59);
      const day = this.randomDataService.getRandomNumberBetweenTwoValues(1, 28);
      const month = this.randomDataService.getRandomNumberBetweenTwoValues(1, 12);
      const year = this.randomDataService.getRandomNumberBetweenTwoValues(2010, 2022);
      userRecord.connected = new Date(year, month, day, hours, minutes, seconds);
      userRecord.assets = this.randomDataService.getRandomNumberBetweenTwoValues(100, 1000000) / this.randomDataService.getRandomNumberBetweenTwoValues(11, 29);

      this.usersList.add(userRecord);
    }
  }

  getUserRecords(): NgLinqArray<IUser> {
    return this.usersList;
  }
}

In the above class we have to import the NgLinqService service dependency and then the EctRandomData service, before we do anything else.

The populateUserRecords sets a recordCount variable to hold a random number between 100 and 250.

The loop then iterates between 1 and recordCount creating a new User record, setting it's properties to use random data, before adding the user record to the userList array.

Functions

The following functions are available from the IEctRandomDataService interface:

  • getRandomNumberBetweenTwoValues: Get a random number between 2 whole numbers.

  • getGirlFirstNames: Get a list of girl names.

  • getBoyFirstNames: Get a list of boy names.

  • getAllFirstNames: Get a list of first names, regardless of gender.

  • getLastNames: Get a list of last names.

  • getAnyFirstName: Get a random first name, regardless of gender.

  • getGirlFirstName: Get a random first name for a girl.

  • getBoyFirstName: Get a random first name for a boy.

  • getLastName: Get a random last name.

  • isBoyName: Determine whether a name is for a boy. If false, then it's a girl's name.

  • getDateOfBirth: Get a date of birth from 1970-01-01 onwards.

  • getAgeFromDate: Get the age from a date. Assumes a date from 1970-01-01 onwards.

Dependencies

This library does use, and therefore depends on the ECT NgLinq library. More details can be found here: (https://www.npmjs.com/package/ect-ng-linq)

Cost

If you find some benefit from using this package, please consider the time it took to put this together, and why not buy me a coffee? Goodness only knows that most of us would not function without coffee. All donations very much welcomed: (https://www.buymeacoffee.com/exoduscloudtech)

Further help

To get more help on the this ECT Random Data, please visit (https://angular-grid.net/free/ect-random-data)