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

ranture

v1.0.0

Published

custom random loops and declaratively structured mock object creations

Downloads

1

Readme

Ranture is a library to create custom structured mock data in seconds. When I made mock data, biggest difficulty was about random lengthed arrays. Ranture can set up a random iterations with one sentence, hierarchical structures, nested arrays, etc. It uses property names as arguments to have a cleaner syntax:

import { ranture, random, RantureArray } from "./ranture.js"


let pets = ['cat', 'dog', 'fish']
let places = ['europe', 'asia', 'america', 'africa', 'australia', 'antarctica']

pets = new RantureArray(...pets)
places = new RantureArray(...places)

let mock = ranture({
	"pets from 7 to 22 step 7 salt 5 ": lifespan => ({
		pet: pets.single,
		lifespan,
		found: places.min(1).max(4)
	})
})

console.log(JSON.stringify(mock, 0, 2))

Pets with lifespans from little to much.

The first word before space is actual property's name. Followed by key value fashioned arguments:

Loop Keywords

  • from iterator starts from this
  • min iterator starts from a random number greater than (>=) this
  • to iterator goes up to this
  • max iterator goes up to a random number less than (<=) this
  • salt maximum ± random number to add to the iterator every run
  • step every iteration iterator increased by this value

RantureArray

  • .single returns a random element
  • .shuffled returns its shuflled version
  • .repeatable returns its shuffled version that can has duplicates
  • .sample(n) returns a sample from it with n numbers of elements
  • .min(n) returns random sample with length greater than n
  • .max(n) returns random sample with length less than n

To use .min(a) and .max(b) both, you should write them in .min(a).max(b) fashion since .max(b) may return an array with length lower than a but .min(a) leaves a mark for .max(b) if they're in row.

Result of the code snippet above (every run will probably be different)

{
  "pets": [
    {
      "pet": "cat",
      "lifespan": 8,
      "found": [
        "asia"
      ]
    },
    {
      "pet": "dog",
      "lifespan": 17,
      "found": [
        "africa"
      ]
    },
    {
      "pet": "dog",
      "lifespan": 22,
      "found": [
        "australia",
        "europe",
      ]
    }
  ]
}