Calling a library throws error in iPad

I am trying to get the basename of a note by calling a library “path” from a dataviewjs script, but I keep getting an error “ReferenceError: Can’t find variable: require”. This error only pops up in an iPad; it works on a desktop.

This is the script I placed under Extras/Scripts. I called the script from a dataviewjs block with dv.view(“pendingTaskDaily”).

const dailyNotesFolder = '"Calendar/Daily"';
const self = dv.current();
const path = require('path');


function isOlderThanThisDailyNote(t) {
	let basename = path.parse(t.header.path).name
	let mDailyDate = moment(self.file.name, 'YYYYMMDD', true);
	let mAnyTaskDate = moment(basename, 'YYYYMMDD', true);
	//  < 0 does not include pending task if they were created today
	//  <= 0 includes pending task if they were created today
	let isOlderNote = mAnyTaskDate.diff(mDailyDate) < 0
	// console.log(t.header.path)
	// console.log(basename, self.file.name)
	// console.log(mDailyDate)
	// console.log(mAnyTaskDate)
	return isOlderNote
}

// the task corresponds to the data of the note and is completed
dv.taskList(dv.pages(dailyNotesFolder).file.tasks
    .where(t => !t.completed)
    .where(t => t.text.length > 0)
    .where(t => isOlderThanThisDailyNote(t))
)

Is there a standard way of invoking a library like path from Obsidian?

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.