Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

data-engine

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

data-engine

Data engine is small data management lib for some sort and filter.

  • 2.0.0-rc.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

DATA ENGINE PREVIEW

Simple data engine, to provide sort and filter. It can work with custom dataset.

DATA-ENGINE

Create new data-engine

    const engine = new DataEngine();
    const engine2 = new DataEngine(data);
    const engine3 = new DataEngine(data, 'primary key');
    const engine4 = new DataEngine(data, 'primary key', sortFunction);

Set data

    engine.setData(data);

Updating filters

    // will return filtered and sorted data
    const filteredData = engine.update(filter, filter2, filter3);

Updating sort

    const sorted = engine.sortBy('new name');

Note: when you call update sort with same key it will automatically reverse array;

removing filters

    const filteredData = engine.removerFilter('name of filter', filter);

Clearing filters

    const filteredData = engine.clearFilters();

Clearing sort

    const filteredData = engine.clearSort();

Resorting

    const filteredData = engine.sortData();

Getting data

    const filteredData = engine.getData();

Note: Data engine should have same functions from sort and filter that are mentioned below.

FILTER-VALUE

Creating new filter value

const filter = new FilterValue('name');
const filter2 = new FilterValue('name', 'Criteria');
const filter3 = new FilterValue('name', 'Criteria', 'type');

Updating filter value

    filter.Name = 'New Name';
    filter.Value = /New value/i;
    filter.Type = 'regex';

Removing type

    filter.removeType();

Getting values

    const name = filter.Name;
    const value = filter.Value;

Possible value types

  • boolean
  • function
  • array
  • regexp
  • date
  • string
  • number
  • range **

** Note: range can only contains string, number or date

Static type values

  • number
  • string
  • regexp
  • boolean

When static type is set, it will try to parse value as this type!

WARNING

Note: Filter value using prototype changes which are dangerous.

Note: When you using regexp please use FilterValue.regexEscape('Some regular expression')

FILTER

Creating new filter

const filterEngine = new Filter(data);

Updating data

    filterEngine.setData(newData);

Adding and updating filters

    const filteredData = filterEngine.update(filter, filter2, filter3 /*Add as many as you need*/);

Removing filters

    const filteredData = filterEngine.removeFilter(filter, 'name' /*As many as you need*/);

Clearing filters

    const filteredData = filterEngine.clearFilters();

Getting data

    const filteredData = filterEngine.getFilteredData();

SORT

Creating new Sort

    const sort = new Sort(data);
    const sort2 = new Sort(data, 'Primary key');
    const sort3 = new Sort(data, 'Primary key', CustomSortFunction);
    // Data = Array of some json objects, primary key = fallback name for sort when data of same key have same value, CustomSortFunction = Custom function which will be called when you call sortBy

Updating data

    // this line will return data as is.
    const data = sort.updateData(newData);
    // This line will resort data.
    const data2 = sort.updateData(newData, true);

Updating criteria

    sort.setSortFunction(CustomFunction);
    sort.setPrimaryKey('new key');

Removing criteria

    sort.removePrimaryKey();
    sort.setDefaultSort();

Sorting data

    const data = sort.sortBy('name');

Getting data

    const data = sort.getData();

Resorting data

    const data = sort.justSort();

WHAT NEXT

Add promise like for big data!

Test all usecases

Set filter-value manually

Keywords

FAQs

Package last updated on 07 Feb 2018

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc