Code Monkey home page Code Monkey logo

crud-package's Introduction

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 un _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 not return any data.
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 un _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 not return any data.
    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.

crud-package's People

Contributors

tal0311 avatar

Stargazers

Gal Ben Ami avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.