1.0.19 • Published 1 year ago

crud-suit v1.0.19

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

CRUD-suit

This package gives you a simple CRUD service for any initial development, or prototyping for web applications.

Package Features:

  1. Saving to LocalStorage.
  2. Synchronous, or asynchronous operation.
  3. Total changes Array - the package will record any action done by the service,
    and will give access to that Array of changes. Each action will be timestamped.
  4. Timestamp and updatedStamp.

How to use

npm install crud-suit
import CRUD from './node_modules/crud-suit/index.js'
const crudService = new CRUD([data | Array], [save to LocalStorage | boolean], [name of key in LocalStorage | string], [asynchronous CRUD | boolean])

Methods

  1. query - will return the data Array
    When calling this function, a timestamp key will be generated on each object in the Array.
crudService.query()
  1. getById - will take an _id and will return the object matching that _id
crudService.getById(entityId)
  1. remove - will take _id and splice it from the data Array. will return a success message.
crudService.remove(entityId)
  1. getEmptyItem - will return an empty item based on the first object in your data Array
crudService.getEmptyItem()
  1. add - will take a new data object, add it to the data Array with an _id,
    and will return the new object that was created with the _id.
    When calling this function, a timestamp key will be generated on the added object.
crudService.add(entity)
  1. update - will find an object inside the data Array and replace it with the new object.
    Will return the _id of updated item.
    When calling this function, an updatedStamp key will be created on each object in the Array.
crudService.update(entity)
  1. undoAction - will enable you to undo last actions based on snapShot of your data before any crud action.
    It will return the last snapShot of your data before the changes. This method will not save the snapShot Array to localStorage.
crudService.undoAction()
  1. getActivities - will keep a record of all actions done by the service and timestamp it. It will return an activities Array with objects describing the action.
crudService.getActivities()

Parameters

new CRUD([data | Array], [save to LocalStorage | boolean], [name of key in LocalStorage | string], [asynchronous CRUD | boolean])

First parameter - data | Array

How to insert your data

The CRUD class instance would take a data Array, containing object items as its first parameter.

In order to ensure all methods are working properly, do not insert your data with id key.
_id key for every object will be generated by the CRUD instance.

Second & third parameter - LocalStorage | boolean, key | String

working with LocalStorage

LocalStorage will store a Key-Value pair. In order to save your data to local storage, you will need two parameters. The first parameter is a boolean in order to determine whether the information

will be kept or not, to LocalStorage. The third parameter is a string to determine the key for the localStorage collection.

Fourth parameter - asynchronous | boolean

Working synchronously and asynchronously

This parameter will take a boolean value to determine whether your CRUD instance will
return a simple data format or a Promise based format.

1.0.19

1 year ago

1.0.18

1 year ago

1.0.17

1 year ago

1.0.16

1 year ago

1.0.15

1 year ago

1.0.14

2 years ago

1.0.13

2 years ago

1.0.12

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago