agenda-organizer

1.0.11 • Public • Published

Cortex Agenda Organizer

Instalation

Before installing, download and install Node.js. Node.js 8.9 or higher is required.

Since installation is done, use npm install command: :

$ npm i agenda-organizer -S

Now you are able to use this module. see a sample below.

const agenda = require('agenda-organizer');

const newAgenda = [
    {
        callNumber: 'item1',
        position: 0,
    },
    {
        callNumber: 'item2',
        position: 5,
    },
    {
        callNumber: 'item3',
        position: 2,
    },
];

const organizedAgenda = agenda.organize(newAgenda, 'position');

console.log(organizedAgenda);
/*
[
    {
        callNumber: 'item1',
        position: 0,
    },
    {
        callNumber: 'item3',
        position: 1,
    },
    {
        callNumber: 'item2',
        position: 2,
    },
]
*/

References

organizer(agenda, field, [fieldTicket])

This method is used to organize itens in array based on an object attribute

parameter description
agenda Contains a list of objects
field Attribute used to organize the itens in the list

Example:

const agenda = require('agenda-organizer');

const newAgenda = [
    {
        callNumber: 'item1',
        position: 0,
    },
    {
        callNumber: 'item2',
        position: 5,
    },
    {
        callNumber: 'item3',
        position: 2,
    },
];

const organizedAgenda = agenda.organize(newAgenda, 'position');

console.log(organizedAgenda);
/*
[
    {
        callNumber: 'item1',
        position: 0,
    },
    {
        callNumber: 'item3',
        position: 1,
    },
    {
        callNumber: 'item2',
        position: 2,
    },
]
*/

The organize method will throw an error when two objects have same positon.

To avoid this you can flag wich ticket would be priorized by pass the callNumber as paramenter on organizer.

See example below:

const agenda = require('agenda-organizer');

const newAgenda = [
    {
        callNumber: 'item1',
        position: 0,
    },
    {
        callNumber: 'item2',
        position: 5,
    },
    {
        callNumber: 'item3',
        position: 2,
    },
    {
        callNumber: 'item4',
        position: 0,
    },
];

const organizedAgenda = agenda.organize(newAgenda, 'position', 'item4');

console.log(organizedAgenda);
/*
[
    {
        callNumber: 'item4',
        position: 0,
    },
    {
        callNumber: 'item1',
        position: 1,
    },
    {
        callNumber: 'item3',
        position: 2,
    },
    {
        callNumber: 'item2',
        position: 3,
    },
]
*/

exists(agenda, id, field = 'callNumber')

Use this method to validade if an object exist in agenda.

parameter Description
agenda Contains a list of objects
id the value to be searched on object
field The callNumber of the attribute that will be used on the search. Default value is callNumber
const agenda = require('agenda-organizer');

const newAgenda = [
    {
        callNumber: 'item1',
        position: 0,
    },
    {
        callNumber: 'item2',
        position: 5,
    },
    {
        callNumber: 'item3',
        position: 2,
    },
];

const organizedAgenda = agenda.exists(newAgenda, 'item1', 'callNumber');

console.log(organizedAgenda); // true

const organizedAgenda = agenda.exists(newAgenda, 'item10', 'callNumber');

console.log(organizedAgenda); // false

reject(agenda, ticket, organizeBy, field = 'callNumber')

This method is used to remove itens in agenda.

parameter Description
agenda Contains a list of objects
ticket The object to be removed
organizedBy The field that function will use to reorganize
field The callNumber of the attribute that will be used on the search. Default value is callNumber
const agenda = require('agenda-organizer');

const newAgenda = [
    {
        callNumber: 'item1',
        position: 0,
    },
    {
        callNumber: 'item2',
        position: 5,
    },
    {
        callNumber: 'item3',
        position: 2,
    },
];

const organizedAgenda = agenda.reject(
    newAgenda, 
    {
        callNumber: 'item1',
        position: 0,
    },
    'position',
    'callNumber');

console.log(organizedAgenda);
/*
[
    {
        callNumber: 'item3',
        position: 0,
    },
    {
        callNumber: 'item2',
        position: 1,
    },
]
*/

Readme

Keywords

Package Sidebar

Install

npm i agenda-organizer

Weekly Downloads

0

Version

1.0.11

License

ISC

Unpacked Size

10.2 kB

Total Files

4

Last publish

Collaborators

  • alohasquad