Functional Weave
Code in Python

todo.parse-tags@1.0.0

README.md

1,001 bytes · view raw

# todo.parse-tags

Reads a tags box as a person types it into the tags a todo stores:
`#Home, work  errands` is `["home", "work", "errands"]`.

- **Separators:** every run of ASCII whitespace (space, tab, CR, LF, VT, FF)
  or commas ends one tag and starts the next. So `home office` is two tags;
  type `home-office` for one. Semicolons and other punctuation are not
  separators: they end up as hyphens inside the slug (`a;b` is `a-b`).
- **Each piece** then goes through todo.normalise-tags: leading `#`s dropped,
  lower-case slug form (`Café` is `cafe`), pieces that come out empty
  (`#`, `日本`) dropped, and repeats removed, keeping the first position.
- Only ASCII whitespace separates, so every language splits the same way
  (Python's `\s` and JavaScript's `\s` disagree on Unicode spaces).

It never throws and does not enforce the limits (10 tags, 30 characters):
todo.item's `validateDraft` reports those, so the form can say what is wrong
instead of silently cutting what was typed.