Resolve file from import.meta.url in acepad/petit-node.
npm install @acepad/hereNOTE: This package is supporsed to work in acepad, not a regular node envronment.
Resolve import.meta.url in acepad/petit-node.
petit-node provides modules via BlobURL, @acepad/here determines original file from the BlobURL.
- filePath(bloburl:string)
- Get file path correspond to bloburl.
- bloburl normally should be import.meta.url
- dirPath(bloburl:string)
- Get directory path that points parent directory of filePath(bloburl)
- siblingPath(bloburl:string, relative_path:string)
- Get file path that points relative_path from dirPath(bloburl)
- file(bloburl:string)
- Get File object correspond to bloburl.
- bloburl normally should be import.meta.url
- dir(bloburl:string)
- Get File object that points parent directory of file(bloburl)
- sibling(bloburl:string, relative_path:string)
- Get File object that points relative_path from dir(bloburl)
- Launch acepad.
- Press F2 (create new script)
- Type below, and press F5.
~~~js
#!run
import {file} from "@acepad/here";
export function main(){
// get File object for this file itself.
const f=file(import.meta.url);
let x=0;// increases by pressing F5
const text_content=f.text();
const new_content=text_content.replace(/x=\d+/,x=${x+1});
f.text(new_content);
}
~~~