contact-service

2.1.2 • Public • Published

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)}`);

Package Sidebar

Install

npm i contact-service

Weekly Downloads

1

Version

2.1.2

License

MIT

Last publish

Collaborators

  • kayartayavinod