1.0.11 • Published 2 years ago

agenda-organizer v1.0.11

Weekly downloads
3
License
ISC
Repository
github
Last release
2 years ago

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

parameterdescription
agendaContains a list of objects
fieldAttribute 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.

parameterDescription
agendaContains a list of objects
idthe value to be searched on object
fieldThe 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.

parameterDescription
agendaContains a list of objects
ticketThe object to be removed
organizedByThe field that function will use to reorganize
fieldThe 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,
    },
]
*/
1.1.0

2 years ago

1.0.9

2 years ago

1.0.11

2 years ago

1.0.10

2 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

5 years ago