Files
pages/static/js/home-command-parser.js
T
Anya Tokugawa b4792bb175
Build and publish container images / images (push) Successful in 16m37s
Add task capture, work reports, daily digests and private contacts
2026-11-01 22:28:16 +09:00

15 lines
2.0 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
(function(root){'use strict';function parse(input){
const tokens=[];let value='',quote='',escaped=false,started=false;
for(const ch of input.trim()){if(escaped){value+=ch;escaped=false;started=true;continue;}if(ch==='\\'){escaped=true;continue;}if(quote){if(ch===quote)quote='';else value+=ch;continue;}if(ch==='"'||ch==="'"){quote=ch;started=true;continue;}if(/\s/.test(ch)){if(started){tokens.push(value);value='';started=false;}}else{value+=ch;started=true;}}
if(quote||escaped)throw Error('Unclosed quote / 引用符を閉じてください');if(started)tokens.push(value);
if(tokens[0]?.toLowerCase()!=='add'||!['task','cal'].includes(tokens[1]?.toLowerCase()))throw Error('add task / add cal');
const kind=tokens[1].toLowerCase(),options={},title=[],allowed=kind==='task'?['project','cost','due','start','review','planned','complexity']:['calendar','from','to'];
for(const token of tokens.slice(2)){const m=token.match(/^([a-z]+):(.*)$/i);if(!m){title.push(token);continue;}const key=m[1].toLowerCase();if(!allowed.includes(key)||Object.hasOwn(options,key)||!m[2])throw Error('Invalid option / オプションを確認:'+key);options[key]=m[2];}
if(!title.join(' ').trim())throw Error('Title required / 件名を入力してください');
if(options.cost){const m=options.cost.match(/^(\d+(?:\.\d+)?)(h|m)$/);if(!m)throw Error('cost:2h / cost:30m');options.estimate_minutes=Number(m[1])*(m[2]==='h'?60:1);if(!Number.isInteger(options.estimate_minutes)||options.estimate_minutes>10080)throw Error('Invalid cost / 工数を確認してください');}
for(const k of ['due','start','review','planned'])if(options[k]&&!/^\d{4}-\d{2}-\d{2}$/.test(options[k]))throw Error(k+':YYYY-MM-DD');
if(options.complexity&&!/^[1-5]$/.test(options.complexity))throw Error('complexity:1–5');
if(kind==='cal'&&(!options.from||!options.to))throw Error('from:YYYY-MM-DDTHH:mm to:YYYY-MM-DDTHH:mm');
return {kind,title:title.join(' '),options};
}root.PagesWikiHomeCommand={parse};if(typeof module!=='undefined')module.exports={parse};})(globalThis);