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

ngx-crud-mocks

v0.1.4

Published

Crud Mocks Library for Angular using Mockaroo API

Downloads

42

Readme

NgxMocks

This library generates fake information for a crud model schema. Fake information is gotten from Mockaroo Api and it's saved in the browser's localStorage like a objects list. NgxMocks allows pushing, editting and deleting objects from list.

Install and Setup

Use npm package manager and execute following command:

npm install ngx-crud-mocks --save-dev

First, import ngx-crud-mocks module in your main module. You must configure mockaroo api key in forRoot method.The forRoot static method is a convention that provides and configures services at the same time, in this case apiMockaroo value will be injected inside library. If you use a SharedModule that you import in multiple other feature modules, you can export the NgxCrudMocksModule to make sure you don't have to import it in every module.

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    ...
    NgxCrudMocksModule.forRoot({
      apiMockaroo: 'yourMockarooApiKey' //You must register in mockaroo and get it Api Key.
    })
    ...
  ],
  exports: [NgxCrudMocksModule]
 
})
export class SharedModule { }

Then, in your component configure a provider like this example:

import { Component, OnInit } from '@angular/core';
import { NgxCrudMocksService, CrudService } from 'ngx-crud-mocks';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
  providers:[{provide: CrudService, useClass: NgxCrudMocksService}]
})
export class AppComponent implements OnInit {
  ...
}  

CrudService is an abstract injectable with the most common crud methods.

  • save(model: any) - (Can create and update. If model has an id field this method update information)
  • search(start: number, limit: number, searchParams?: any)
  • getById(id: number)
  • deleteById(id: number)
  • getNumTotal(searchParams?: any)

If you have a same structure in your real service (Real means when a service consuming API REST) you can connect and disconnect changing useClass value between yourRealservice or NgxCrudMocksService.

Next, you must configure mockFormat and localstorage keyName using setConfigMock method in the component's constructor. Only mockFormat is mandatory, localstorage keyName is optional.

import { Component, OnInit } from '@angular/core';
import { NgxCrudMocksService, CrudService } from 'ngx-crud-mocks';
import { mockFormat } from './exampleMock';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
  providers:[{provide: CrudService, useClass: NgxCrudMocksService}]
})
export class AppComponent implements OnInit {
  constructor(private service: CrudService){
    this.service.setConfigMock(mockFormat, "yourLocalStorageKeyName");
  }

}  

Finally, mockFormat is a json array of field specifications according crud method. For instance for Book model:


    interface Book{
        id: number;
        name: string;
        price: string;
        image: string;

    }

You can create this mockFormat:

export let mockFormat = [

	// Complete in this file specific features for mock types - More information in https://www.mockaroo.com/api/docs
 
	{
			name: 'id',
			type: 'Number',
			min: 1,
      max: 1000,
      decimals: 0,
	},
 
	{
			name: 'name',
			type: 'Movie Title',// Simulate book names :)
	},
 
	{
			name: 'price',
			type: 'Money',
			min:	1000,
      max:	200000,
      symbol:	'$'
	},

	{
		name: 'image',
		type: 'Dummy Image URL',
		minHeight:	200,
		maxHeight:	200,
		minWidth:	200,
		maxWidth:	200,
		format: 'png'

	}
 
]

For more details go to Mockaroo Api.

Thanks

2018