npm install checklist-js
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(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()
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()
/* after crash or diffrent file*/
const checklist = new Checklist([
'π₯¦ broccoli'
'π₯© ham',
'π₯ eggs',
]);
/*
false : π₯¦ broccoli
true : π₯© ham
true : π₯ eggs
*/
checklist.log()
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')
/* 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()
new Checklist([], {
name: 'my_checklist',
path: process.cwd()
});
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
There is also the senario where you have too many values and doing recalc on every check will take too long
new Checklist([], {
recalc_on_check: false
});
// 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'])
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
})