Skip to content

Commit

Permalink
app things: bug: never returns today, make when+list required return …
Browse files Browse the repository at this point in the history
…with "" replacing omit, -triage and tags, s/delims/delim in setting, unpack return statement for readability
  • Loading branch information
jimmy-zhening-luo committed Jul 5, 2024
1 parent d5fd734 commit 1f0384e
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 94 deletions.
210 changes: 127 additions & 83 deletions src/Things.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,94 +19,138 @@ namespace Things {
const {
app: {
tag,
delims,
},
user: {
triage,
lists,
delim,
},
user: { lists },
} = this;

return input
.split(
delims
.item,
)
.reverse()
.map(
item =>
item
.trim(),
)
.map(
(item): ThingsItem => {
const lines = item
.split(
delims
.line,
);
const lastTaggedLine = [...lines]
.reverse()
.find(
line =>
line
.includes(
tag,
),
) ?? null;
const isTagged = lastTaggedLine !== null;
const iLastTag =
lastTaggedLine === null
? null
: lastTaggedLine
.lastIndexOf(
tag,
) as Positive<fint>;
const lastTag =
lastTaggedLine === null
|| iLastTag === null
if (
delim
.item
.length < 1
|| delim
.line
.length < 1
|| tag
.length < 1
)
throw new TypeError(
`setting: empty tag or delim`,
);
else if (
delim
.item === delim
.line
)
throw new SyntaxError(
`setting: identical delim for 'item' and 'line'`,
);
else if (
tag === delim
.line
)
throw new SyntaxError(
`setting: tag is identical to delim 'line'`,
);
else {
const items = input
.split(
delim
.item,
)
.reverse()
.map(
item =>
item
.trim()
.split(
delim
.line,
)
.map(
line =>
line
.trim(),
)
.filter(
line =>
line
.length > 0,
)
.join(
delim
.line,
),
);

return items
.map(
(item): ThingsItem => {
const tagIndex = item
.lastIndexOf(
tag,
);
const tagent = tagIndex < 0
? null
: lastTaggedLine.length === iLastTag + 1
? null
: (
lastTaggedLine[
iLastTag + 1
] ?? ""
)
.toLowerCase();
const flags: Pick<
ThingsItem,
| "when"
| "list"
> =
!isTagged
? {}
: lastTag === null
|| lastTag.length < 1
? { when: "today" }
: {
list: lists[
lastTag
] ?? "",
};
: item
.slice(
tagIndex,
tagIndex + 1,
);
const [
when,
list,
] = tagent === null
? [
"",
"",
]
: tagent
.length < 1
|| tagent === delim
.line
|| !(tagent in lists)
|| (
lists[
tagent
]
?? ""
)
.length < 1
? [
"today",
"",
]
: [
"",
lists[
tagent
] as unknown as string,
];
const lines = item
.split(
delim
.line,
);

return {
title: encodeURI(
lines
.shift() ?? "",
),
notes: encodeURI(
lines
.join(
delims
.line,
),
),
triage,
...flags,
};
},
);
return {
title: encodeURI(
lines
.shift() ?? "",
),
notes: encodeURI(
lines
.join(
delim
.line,
),
),
when,

Check failure on line 148 in src/Things.ts

View workflow job for this annotation

GitHub Actions / Build/Publish (dev)

Type 'string' is not assignable to type '"" | "today" | "someday"'.
list,
};
},
);
}
}
}
}
Expand Down
11 changes: 2 additions & 9 deletions src/apps/interface/output/things/ThingsItem.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,11 @@ declare type ThingsItem =
& Field<
| "title"
| "notes"
| "triage"
| "list"
,
| "list"
>
& List<
"tags"
,
true
>
& {
when?:
when:
| ""
| "today"
| "someday"
;
Expand Down
3 changes: 1 addition & 2 deletions src/apps/interface/setting/things/ThingsSetting.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
declare type ThingsSetting = {
app: {
tag: string;
delims: Field<
delim: Field<
| "item"
| "line"
>;
};
user: {
triage: string;
lists: FieldTable;
};
};

0 comments on commit 1f0384e

Please sign in to comment.