Socket
Book a DemoInstallSign in
Socket

contact-service

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

contact-service

A simple array based service layer for address book apps

latest
Source
npmnpm
Version
2.1.2
Version published
Maintainers
1
Created
Source

A simple array based service layer for address book apps

Installing:

npm install --save contact-service

Using:

var service = require("contact-service");
var c = service.getById(13);
console.log(c);

Currently avaiable member functions:

  • getAll() --> returns all existing contacts
  • getById(id) --> returns the corresponding contact or null if not found
  • addNew(contact) --> adds the contact to the existing list of contcts with a new id
  • update(contact) --> searches with the given contact's id and replaces the existing contact
  • delete(id) --> searches with the given contact's id and deletes the same

Get all contacts:

var contacts = service.getAll();
contacts.forEach(c=>{
	console.log(c);
});

Adding a new contact:

(Mandatory fields - first_name, last_name, email, phone, dob and city)

var contact = { 
	first_name: 'Vinod',
	last_name: 'Kumar',
	email: 'vinod@vinod.co',
	phone: '9731424784',
	dob: '1974-01-20',
	city: 'Bangalore' 
};

contact = service.addNew(contact);
console.log(contact);	

Deleting a contact with id:

var id = 3;
var contact = service.delete(id);
console.log(`deleted: ${JSON.stringify(contact)}`);

Updating an existing contact (based on id):

(Mandatory fields - id, first_name, last_name, email, phone, dob and city)

var contact = { 
	id: 3,
	first_name: 'Vinod',
	last_name: 'Kumar',
	email: 'kumar@vinod.co',
	phone: '9731424784',
	dob: '1974-01-20',
	city: 'Bangalore' 
};

contact = service.update(contact);
console.log(`updated contact: ${JSON.stringify(contact)}`);

Keywords

contact

FAQs

Package last updated on 06 May 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts