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

js-mockdata-registry

v1.0.0

Published

JavaScript registry for mockdata

Downloads

20

Readme

js-mockdata-registry

JavaScript registry or mockdata

Purpose

The js-mockdata-registry is a small registry for mockdata objects that should be references within other mockdata objects.

Getting started

Simply add the js-mockdata-registry to your package.json file and use npm install for installation.

		"devDependencies": {
		    "js-mockdata-registry":        "~1.0.0"
		}

Once it is installed you can require the module.

		let mockdata = require('js-mockdata-registry')

Usage

This chapter explains the basic usage of the registry.

Mockdata interface

| Method | Description | | --- | --- | --- | | addObject (Object obj) | Adds the given object to the registry. The object must have the attribute mark with a unique value within the registry. The markis consumed in the registration process. An error is throw if either the attribute mark is not exisiting or if its value is not unique | | hasObject (String mark) : Boolean | Checks the registry if an object with the given mark exists| | getObject (String mark) | Reads the desired registry entry for the given mark. Throws an error if the given mark is not existing in the registry. | | removeObject (String mark) | Removes the desired registry entry for the given mark. Throws an error if the given mark is not existing in the registry. | | log (Number depth) | Outputs the current registry using node's util.inspect function. The depth is handed over to the inspect function. | | resolve (Object resultObj, Object obj, String attrib) | This function resolves an object reference to an registry entry. The originial obj won't be changed during resolve. Instead the resultObj will be altered. For more details see the examples. |

Example usage

/* in order to add objects we have to instanciate the registry */
let mockdata = require('js-mockdata-registry')

/* adding objects                                              */
mockdata.registry.addObject({
    mark: 'User.John',
    firstname: 'John',
    lastname: 'Doe'
})

/* reading objects                                             */
mockdata.registry.getObject('User.John')

/* resolving references                                        */
// define the new object with a objectRef to an existing mark
let project = {
	desc: 'first project',
    supervisor: { objectRef: 'User.John' }
}
// clone the base object
let resolvedProject = Object.assign({}, project)
// let the registry resolve the object reference 
mockdata.registry.resolve(resolvedProject, project, 'supervisor')