checklist-js

1.2.3 • Public • Published

checklist-js

A simple checklist for when you need to keep track of things presistetly

Installation

npm install checklist-js

Usage

import Checklist from 'checklist-js'

const shoppingList = [ 
  '🥚 eggs', 
  '🥩 ham', 
  '🧀 cheese', 
  '🍎 apple', 
  '🥦 broccoli' 
];

// create a checklist
const checklist = new Checklist(shopping_lits);

let eggs = await fetch('https://emojipedia.org/egg/');
// check eggs
if(eggs) checklist.check('🥚 eggs');

let ham = await fetch('https://emojipedia.org/ham/');
// check ham
if(ham) checklist.check('🥩 ham');

checklist.next() // '🧀 cheese'

checklist.next() // '🍎 apple'

// uncheck 🥚 eggs
checklist.uncheck('🥚 eggs')

/* 🥚 eggs ? */
checklist.isChecked('🥚 eggs') // false

/* 🥩 ham ? */
checklist.isChecked('🥚 eggs') // true

/*[ 
  '🥚 eggs', 
  '🧀 cheese',
  '🍎 apple',
  '🥦 broccoli',
]*/
checklist.getMissingValues();
checklist.missingLeft(); // 4

/*[ 
  '🥩 ham',
]*/
checklist.getCheckedValues()
checklist.valuesDone() // 1

/* check if all the values have been checked */
checklist.isDone() // false
checklist.isNotDone() // true

/*
false : 🥚 eggs 
true : 🥩 ham
false : 🧀 cheese
false : 🍎 apple
false : 🥦 broccoli
*/
checklist.log()

// delete the checklist in the files system
checklist.delete()

while loop usage

while(checklist.isNotDone()){
  // get the next missing value on the checklist
  let value  = checklist.next()
  // perform some operation 
  let result = await fetch('https://emojipedia.org/');
  // check the value if successful
  if(result) checklist.check(value);
}

// delete the checklist in the files system
if(checklist.isDone())
  checklist.delete()

Permenance

you can recover the same checklist by creating it again with the same values

const checklist = new Checklist([ 
  '🥚 eggs', 
  '🥩 ham',  
  '🥦 broccoli' 
]);

// check
checklist.check('🥚 eggs');
checklist.check('🥩 ham');

/*
true : 🥚 eggs 
true : 🥩 ham
false : 🥦 broccoli
*/
checklist.log()
/* after crash or diffrent file*/
const checklist = new Checklist([ 
  '🥚 eggs', 
  '🥩 ham',  
  '🥦 broccoli' 
]);

/*
true : 🥚 eggs 
true : 🥩 ham
false : 🥦 broccoli
*/
checklist.log()

the order values does not matter when recovering the checklist

/* after crash or diffrent file*/
const checklist = new Checklist([ 
  '🥦 broccoli' 
  '🥩 ham',
  '🥚 eggs', 
]);

/*
false : 🥦 broccoli 
true : 🥩 ham
true : 🥚 eggs
*/
checklist.log()

pass the name options to make it the checklist unique

let shoppingList = [ 
  '🥦 broccoli' 
  '🥩 ham',
  '🥚 eggs', 
];

const bobs_checklist = new Checklist(
  shoppingList, { name: 'bobs shoppinglist' } 
);
bobs_checklist.check(['🥩 ham', '🥚 eggs'])

const alices_checklist = new Checklist(
  shoppingList, { name: 'alices shoppinglist' } 
);
alices_checklist.check('🥦 broccoli')

recover the checklist with the name option

/* after crash or diffrent file*/
const bobs_checklist = 
  new Checklist(null, { name: 'bobs shoppinglist' });
  
/*
false : 🥦 broccoli 
true : 🥩 ham
true : 🥚 eggs
*/
bobs_checklist.log()

const alices_checklist = 
  new Checklist(null, { name: 'alices shoppinglist' });
  
/*
false : 🥦 broccoli 
true : 🥩 ham
true : 🥚 eggs
*/
bobs_checklist.log()

pass the path where to make the filesystem

  new Checklist([], { 
    name: 'my_checklist',
    path: process.cwd()
  });
  

Recalculate missing values on Check

sometime when you are working with multiple concurrent processes you don't want the completion of one process to alter the order you would get the missing vlaue

this can lead to a missing values being drawn twice after a check.

There is also the senario where you have too many values and doing recalc on every check will take too long

For this senarios you can set the option recalc_on_check to false

pass the path where to make the filesystem

  new Checklist([], { 
    recalc_on_check: false
  });
  

Adding, Removing and Checking multiple values

// add 🥓 bacon
checklist.add('🥓 bacon')
// or 
checklist.add(['🍞 Bread', '🍆 Eggplant', '🥛 Milk'])

// remove 🥚 eggs
checklist.remove('🥚 eggs')
// or 
checklist.remove(['🥩 ham', '🥓 bacon', '🍞 Bread', '🥛 Milk'])

// check 🧀 cheese
checklist.check('🧀 cheese')
// or 
checklist.check([ '🍆 Eggplant', '🍎 apple' , '🥦 broccoli'])

// uncheck 🧀 cheese
checklist.unchek('🧀 cheese')
// or 
checklist.uncheck([ '🍆 Eggplant', '🍎 apple' , '🥦 broccoli'])

OPTIONS

All options

new Checklist( valus, {
        name, // name of the checklist to save

        path, // path to save the checklist at

        recalc_on_check, // recalcuate the missing values on check
        
        save_every_check, // save the checklist every n checks

        enqueue, // if false, do not add missing values to the end of the list

        shuffle, // if true, shuffle the values before checking

        save // if false, Checklist has not presistense. it does not save to disk, default true
        })

Package Sidebar

Install

npm i checklist-js

Weekly Downloads

13

Version

1.2.3

License

ISC

Unpacked Size

35.1 kB

Total Files

13

Last publish

Collaborators

  • gorantopic