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

test-data-utils

v2.4.3

Published

Generating data for testing on the frontend

Downloads

88

Readme

test-data-utils

A robust and lightweight data generation library for automating the preparation of test data for frontend unit testing.

Features

  • Fastest UUID generation
  • Numeric value generation within a specified range
  • Random string generation with custom char set and requested lengths
  • Person name generation with options for gender, type, length, and language
  • Generation of meaningful strings based on a real of prefixes, words, and suffixes
  • Support for English and Russian languages

Documentation

Functions

The functionality of the library is implemented using the following functions available to the user:

  1. generateUUID(strinctRandom?: boolean) -- the function is used to generate unique identifiers (UUID). In the case of non-strict randomisation, an end-to-end counter is used, converted into a hexadecimal number format string, which is then added to the base UUID. When a certain number is reached, the counter is reset.
  2. generateNumber(opts: Partial<NumberOpts>) -- a function that returns a random number in a given interval between the minimum and maximum minimum and maximum. If the maximum is less than the minimum, an error is generated.
  3. generateString(opts: Partial<StringOpts>) -- the function returns a string of random characters of the specified length from a user-defined character set or the default English alphabet. character set defined by the user or from the default English alphabet.
  4. generatePerson(opts?: Partial<PartNameOpts>) -- the function generates a random first, last or patronymic name depending on the provided parameters such as length, gender and desired case (for Russian).
  5. generateMeaningfulString(opts?: Partial<MeaningfulStringOpts>)-- based on the prefix trees (tries) for English and Russian languages, the function generates a random meaningful string of a given length, which may include the words or their combinations with delimiters.

Types

type NumberOpts = {
    min: number
    max: number
}
type StringOpts = {
    charSet: string[] | string
    length: number
}
type PartNameOpts = {
    gender: 'male' | 'female'
    type: 'name' | 'surname' | 'patronymic'
    length: 'small' | 'medium' | 'large' | 'extra_large'
    language: Language
    padej: Case
}
type MeaningfulStringOpts = {
    length: number
    separator: string
    language: Language
}
type Language = 'en' | 'ru'
type Case = 'nominative' | 'genitive' | 'dative' | 'accusative' | 'instrumental' | 'prepositional'

Installation

npm
npm i -D test-data-utils
yarn
yarn add --dev test-data-utils
bun
bun add --dev test-data-utils
pnpm
pnpm i --dev test-data-utils

import

via import:
import {
    generateMeaningfulString,
    generateNumber,
    generatePerson,
    generateString,
    generateUUID
} from 'test-data-utils'
via require():
const {
    generateMeaningfulString,
    generateNumber,
    generatePerson,
    generateString,
    generateUUID
} = require('test-data-utils')

Usage example

UUID Generation
import { generateUUID } from 'test-data-utils'


for (let i = 0; i < 1000; i++) {
    console.log(generateUUID())
}
/** Output:
 *  000f-ffff-ffff-ffff-ffffffffffff
 *  001f-ffff-ffff-ffff-ffffffffffff
 *  002f-ffff-ffff-ffff-ffffffffffff
 *  003f-ffff-ffff-ffff-ffffffffffff
 *  004f-ffff-ffff-ffff-ffffffffffff
 *  005f-ffff-ffff-ffff-ffffffffffff
 *  006f-ffff-ffff-ffff-ffffffffffff
 *  007f-ffff-ffff-ffff-ffffffffffff
 *  008f-ffff-ffff-ffff-ffffffffffff
 *  ...
 *  ...
 *  ...
 *  3dff-ffff-ffff-ffff-ffffffffffff
 *  3e0f-ffff-ffff-ffff-ffffffffffff
 *  3e1f-ffff-ffff-ffff-ffffffffffff
 *  3e2f-ffff-ffff-ffff-ffffffffffff
 *  3e3f-ffff-ffff-ffff-ffffffffffff
 *  3e4f-ffff-ffff-ffff-ffffffffffff
 *  3e5f-ffff-ffff-ffff-ffffffffffff
 *  3e6f-ffff-ffff-ffff-ffffffffffff
 *  3e7f-ffff-ffff-ffff-ffffffffffff
 */
Number Generation
import { generateNumber } from 'test-data-utils'


const stubNumberOpts = {
    min: 0,
    max: 100
}

console.log(generateNumber(stubNumberOpts))
// Output: 85
String Generation
import { generateString } from 'test-data-utils'


const stubStringOpts = {
    charSet: 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',
    length: 1000
}

console.log(generateString(stubStringOpts))
// Output: 3fwTMjhxjcWddMBu4LDVaWeyxuBao2SNgcLJvL8flhJSNZyhFjriruPVLDSL45BHs29iXETmjCi86orscQBhPUBLCN0MVg0rgBqH8RDitLOqUPRE8i7jDaBA01V8xaiSsTGB3opgg80Xs8dMjsKpK09G2LWlmXnJjqacvgVoJI4H3hnbf3bfRm3US0PaaOEJLHMWtMnBt28NfNfhdGXY6cR34LqPJocJ1Fva1AWy5kPcecLXLIhRIT5HmlShZggJLrBwNSBOm5j6oEbalUT4SfQFwTaAv7KePEFkv8tmiRacP9V61bYDAtFFCKAJQlU2d5e59FAzX6XkTfjrKtlVBBrO576tcn3qXCWe1naElj2WG0Myk8tq8rft0L5rqGey5n3tQAmFWxmG5mMyS1UhpIAKrpsA58R3lrMpxvVdpia2bJGAGz8YfJa4zmyto9XgBADvQpRDNApggd9Twqt3ND5hvW8ibDzftZJzJYnRi8npAqoNDfd6hTZ2mbOogtJqJg4PduoaNPwE0KZm8RrOjUNUgIj5HaJ3CSQdmXgV68NzcIoXGaGaYvhP3MJY8Tg2ZVolJZiUvHN28hDjjRhLK6uIBFWEDAnOxQ1o0VFl1S6zsGEgYo5K7Vqq4oLg820fUdZe5j0QLA3Ffh7BgvGHL7uyG84mp8Uev4qtvFyBvL8ChQaBy1ThIkootGlSEZ6bvtfhXNjhkOSqfF8Lfpe3WvC6ImBYeJKYv1MtfjQsVCgZO7AkNC1FS0nYsCrbPc6r72HXmpONvR0hrE9lYAfVcZIv1YtDMrlpFR5MSLgZAOtIRjdJec9U64xG6qdgFyJkYbaaFPYpUpRzftWTFmm1V4paYYRj2Dk18sN8W7uVMdC5XMOv7L1e8D8GbavcWYqoGdSZeaUdsVXydTMYapHhMBuv1lEP8CADD6Ju7qz8iSr3OpoASVU1ig2f4JHhvPNEdhBjmv8z2oKoHyx2sbeUo0gDlxNopiYv8SVb2y9y
Person Generation
import { generatePerson } from 'test-data-utils'


const stubPartNameOpts = {
    gender: 'female',
    type: 'name',
    language: 'en'
} as const
const stubPartNameRuOpts = {
    gender: 'male',
    type: 'surname',
    language: 'ru'
} as const

console.log(generatePerson(stubPartNameOpts))
console.log(generatePerson(stubPartNameRuOpts))
/** Output:
 *  Olivia
 *  Соколов
 */
Meaningful String Generation
import { generateMeaningfulString } from 'test-data-utils'

const stubMeaningfulStringOpts = {
    length: 17,
    separator: ' ',
    language: 'en'
} as const
const stubMeaningfulRuStringOpts = {
    length: 30,
    separator: ' ',
    language: 'ru'
} as const

console.log(generateMeaningfulString(stubMeaningfulStringOpts))
console.log(generateMeaningfulString(stubMeaningfulRuStringOpts))
/** Output:
 *  trans transquince
 *  раз разт разтыква разтыквачик
 */