-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new semicolon syntax for date interpolating
- Loading branch information
1 parent
46609c4
commit 84853ba
Showing
4 changed files
with
110 additions
and
269 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import parseNlpDate from "roamjs-components/date/parseNlpDate"; | ||
import * as chrono from "chrono-node"; | ||
|
||
const parseTextForDates = (str: string, reference_date?: Date) => { | ||
const str_with_pages_removed = str.replace(/\[+\[[^)]+\]+\] */g, ""); | ||
const date = chrono.parse(str_with_pages_removed, reference_date); | ||
// support parsing to return parse results | ||
// also solve the `of` bug | ||
// parseNlpDate(str_with_pages_removed, reference_date); | ||
|
||
if (date.length) { | ||
return date.reduce((prev, { text, index, start }) => { | ||
const roamDate = `[${text}]([[${window.roamAlphaAPI.util.dateToPageTitle( | ||
start.date() | ||
)}]])`; | ||
return `${prev.slice(0, index)}${roamDate}${prev.slice( | ||
index + text.length | ||
)}`; | ||
}, str); | ||
} else { | ||
return str; | ||
} | ||
}; | ||
|
||
export default parseTextForDates; |
Oops, something went wrong.