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

toss-me-a

v1.0.1

Published

Tiny and simple package to mock data

Downloads

3

Readme

toss-me-a npm version

Created by David Briglio

This is a quick and simple standalone data mocking package. Provide the method with the structure of the object / type you would like mocked and the resulting amount to mock.

Install

npm:

npm i toss-me-a

yarn:

yarn add toss-me-a

Usage

This package exports a default method tossMeA. Provide this method an object to mock, and a count of how many to return (default 1 if omitted).

Argument structure

| Type | Options | Example | Description | | -------- | ---------------------------------- | ------------------------------------ | ---------------------------------------------------------------------------------------------------- | | string | 'string-[length]-[formatted]' | 'string-15-f' | Get a string of specified length with optional spacing formatting f (default 10, non-formatted) | | number | 'number-[min]-[max]' | 'number-0-50' | Get an integer number between min/max values (default 0-100) | | boolean | N/A | 'boolean' | Get a boolean value | | date | 'date-[start epoch]-[end epoch]' | 'date-1604102400000-1635638400000' | Get a random date between a start and end date (epoch) (default is between epoch 0 and current date) | | array | ['[type]', [amount]] | ['string', 5] | Get an array containing the amount of type provided | | function | N/A | () => generateId() | Provide a funciton as the value to perform the function and return the value to the resulting object | | object | N/A | {aString: 'string'} | Provide an object of the same mock structure to recursively create mock data |

Sample

import tossMeA from 'toss-me-a'

tossMeA(
  {
    // Provide a function to be executed and the value returned into the mock data
    id: () => generateAnId(),
    // Anything provided that is not a string|function|object will be included as is
    aConst: 15,
    // Use a function to provide a constant value to the mock data
    anotherConst: () => 'always-this-string',
    aString: 'string',
    aStringLength15: 'string-15',
    // String 100 characters long with spacing
    aStringFormatted: 'string-100-f',
    // Get a date between epoch 0 and current date
    aDate: 'date',
    // Get a date between Oct-31-2020 and Oct-31-2021
    aSpecificDate: 'date-1604102400000-1635638400000',
    // Array of type
    arrayOfStrings: ['string', 4],
    aNumber: 'number-0-5',
    aBoolean: 'boolean',
    category: {
      // Nested object recursively generates data
      anotherString: 'string',
      anotherObject: {
        anotherArray: ['number-0-10', 3]
      }
    }
  },
  10 // How many of these objects to return
)

License

MIT (See license file)