npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

todo-parser

v0.2.0

Published

todo.txt to js object parser

Downloads

5

Readme

Build Status Quality Gate Code Coverage

todo.txt parser

Converts todo.txt files into javascript objects

Install

Install via npm:

npm i --save todo-parser

Usage

Right now you can parse todo.txt files and strings to js objects. The other way is right now not possible but coming soon!

Single line parser

To parse a single todo.txt task line like this one:

'(A) 2017-10-03 Write great readme @todo-parser +github'

into its javscript object representation you can use the Parser class:

const Parser = require('todo-parser').Parser;

let parser = new Parser();

let taskObject = parser.parse('(A) 2017-10-03 Write great readme @todo-parser +github');

Out comes a taskObject looking like this:

{
    original: '(A) test message @todo-parser +github',
    priority: 'A',
    creationDate: Date('2017-10-03'),
    completionDate: null,
    description: 'test message',
    context: [ 'github' ],
    project: [ 'todo-parser' ],
    done: false
}

File parser

To go nuts and parse a complete todo.txt file into an array of todo objects there is the FileParser class. In contrary to the Parser it works asynchronious and takes two arguments:

  1. The file path to the todo.txt file
  2. The callback to execute after parsing the file or an error occured
const FileParser = require('todo-parser').FileParser;

let parser = new FileParser();

parser.parse('/home/someone/todos/myTodos.txt', function (err, data) {
    if (err) {
        //do something with the error
    }
    //do something with the todo task list data
});

Custom parser

The package comes with a bunch of default parser for the standard todo.txt format. If you want to parse additional attributes like the popular due:2017-10-12 you can register your own parsing methods.
The method you provide will get passed the a data object you can modify and extend. It also contains the todo line to parse and looks like this:

{
    original: '(A) test message @todo-parser +github',
    residue: ' test message  ',
    priority: 'A',
    creationDate: Date('2017-10-03'),
    completionDate: null,
    description: 'test message',
    context: [ 'github' ],
    project: [ 'todo-parser' ],
    done: false
}

The data.original attribute contains the complete todo.txt line.
In the residue attribute a subset is stored from which all parsed attributes are removed. After all todo.txt parts are parsed it will be used as the description, so if you don't want your special attribute to appear in the todo description, remove it from the residue ;) .

To add a custom method to the Parser you can pass it via the #register() method.

So if you want to parse out the due:2017-10-12 lines for example, you can register following method to the parser:

let dueDateParser = function (data) {
    let match = data.original.match(/due:([0-9]{4}-[0-9]{2}-[0-9]{2})/)
    if (match !== null) {
        data.dueDate = new Date(match[1])
        data.residue = data.residue.override(match[1], '')
    }
}
parser.register(dueDateParser)
let data = parser.parse('(A) 2017-10-01 Something to do due:2017-10-30')
let expected = new Date('2017-10-30')
assert.equal(data.dueDate.getDate(), expected.getDate())

Override default parser

If you don't like the way todo-parser parses the default values you can override the standard parser with your own methods. I wouldn't like that but I give you the opportunity to do it so I shouldn't moan about it ;)

So if you want to do this blasphemy you can register your own method with the parser.override(name, method) function.

There are 7 default parser:

  • done
  • priority
  • creationDate
  • completionDate
  • context
  • project
  • description

The override method takes two arguments:

  1. The name of the default parser to override
  2. The method to use instead
let yourOwnPriorityParser = function (data) {
    //do something
}
parser.override('priority', yourOwnPriorityParser)